Skip to content

Commit

Permalink
refactor(types): mark internal API exports and exclude from d.ts
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Internal APIs are now excluded from type decalrations.
  • Loading branch information
yyx990803 committed Apr 30, 2020
1 parent a5bb1d0 commit c9bf7de
Show file tree
Hide file tree
Showing 28 changed files with 209 additions and 96 deletions.
2 changes: 1 addition & 1 deletion packages/compiler-core/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
}
}
4 changes: 2 additions & 2 deletions packages/compiler-dom/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
}
}
}
4 changes: 2 additions & 2 deletions packages/compiler-sfc/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
}
}
}
4 changes: 2 additions & 2 deletions packages/compiler-ssr/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
}
}
}
2 changes: 1 addition & 1 deletion packages/reactivity/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/runtime-core/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
}
}
6 changes: 5 additions & 1 deletion packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,11 @@ type CompileFunction = (

let compile: CompileFunction | undefined

// exported method uses any to avoid d.ts relying on the compiler types.
/**
* For runtime-dom to register the compiler.
* Note the exported method uses any to avoid d.ts relying on the compiler types.
* @internal
*/
export function registerRuntimeCompiler(_compile: any) {
compile = _compile
}
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime-core/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export type DirectiveArguments = Array<
| [Directive, any, string, DirectiveModifiers]
>

/**
* Adds directives to a VNode.
* @internal
*/
export function withDirectives<T extends VNode>(

This comment has been minimized.

Copy link
@CyberAP

CyberAP May 2, 2020

Contributor

Are we supposed to still use this API in user render functions?

This comment has been minimized.

Copy link
@yyx990803

yyx990803 May 2, 2020

Author Member

In render functions you can use onVnodeXXX hooks directly, which is more straightforward most of the time.

This comment has been minimized.

Copy link
@yyx990803

yyx990803 May 2, 2020

Author Member

But yeah I think this should still be exposed in case of trying to use 3rd party directives.

vnode: T,
directives: DirectiveArguments
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime-core/src/helpers/createSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ interface CompiledSlotDescriptor {
fn: Slot
}

/**
* Compiler runtime helper for creating dynamic slots object
* @internal
*/
export function createSlots(
slots: Record<string, Slot>,
dynamicSlots: (
Expand Down
25 changes: 20 additions & 5 deletions packages/runtime-core/src/helpers/renderList.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
import { VNodeChild } from '../vnode'
import { isArray, isString, isObject } from '@vue/shared'

// v-for string
/**
* v-for string
* @internal
*/
export function renderList(
source: string,
renderItem: (value: string, index: number) => VNodeChild
): VNodeChild[]

// v-for number
/**
* v-for number
* @internal
*/
export function renderList(
source: number,
renderItem: (value: number, index: number) => VNodeChild
): VNodeChild[]

// v-for array
/**
* v-for array
* @internal
*/
export function renderList<T>(
source: T[],
renderItem: (value: T, index: number) => VNodeChild
): VNodeChild[]

// v-for iterable
/**
* v-for iterable
* @internal
*/
export function renderList<T>(
source: Iterable<T>,
renderItem: (value: T, index: number) => VNodeChild
): VNodeChild[]

// v-for object
/**
* v-for object
* @internal
*/
export function renderList<T>(
source: T,
renderItem: <K extends keyof T>(
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime-core/src/helpers/renderSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {
import { PatchFlags } from '@vue/shared'
import { warn } from '../warning'

/**
* Compiler runtime helper for rendering <slot/>
* @internal
*/
export function renderSlot(
slots: Slots,
name: string,
Expand Down
9 changes: 9 additions & 0 deletions packages/runtime-core/src/helpers/resolveAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import { warn } from '../warning'
const COMPONENTS = 'components'
const DIRECTIVES = 'directives'

/**
* @internal
*/
export function resolveComponent(name: string): Component | string | undefined {
return resolveAsset(COMPONENTS, name) || name
}

export const NULL_DYNAMIC_COMPONENT = Symbol()

/**
* @internal
*/
export function resolveDynamicComponent(
component: unknown
): Component | string | typeof NULL_DYNAMIC_COMPONENT {
Expand All @@ -29,6 +35,9 @@ export function resolveDynamicComponent(
}
}

/**
* @internal
*/
export function resolveDirective(name: string): Directive | undefined {
return resolveAsset(DIRECTIVES, name)
}
Expand Down
9 changes: 9 additions & 0 deletions packages/runtime-core/src/helpers/scopeId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ import { withCtx } from './withRenderContext'
export let currentScopeId: string | null = null
const scopeIdStack: string[] = []

/**
* @internal
*/
export function pushScopeId(id: string) {
scopeIdStack.push((currentScopeId = id))
}

/**
* @internal
*/
export function popScopeId() {
scopeIdStack.pop()
currentScopeId = scopeIdStack[scopeIdStack.length - 1] || null
}

/**
* @internal
*/
export function withScopeId(id: string): <T extends Function>(fn: T) => T {
return ((fn: Function) =>
withCtx(function(this: any) {
Expand Down
5 changes: 4 additions & 1 deletion packages/runtime-core/src/helpers/toHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { isObject } from '@vue/shared'
import { warn } from '../warning'

// For prefixing keys in v-on="obj" with "on"
/**
* For prefixing keys in v-on="obj" with "on"
* @internal
*/
export function toHandlers(obj: Record<string, any>): Record<string, any> {
const ret: Record<string, any> = {}
if (__DEV__ && !isObject(obj)) {
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime-core/src/helpers/withRenderContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
} from '../componentRenderUtils'
import { ComponentInternalInstance } from '../component'

/**
* Wrap a slot function to memoize current rendering instance
* @internal
*/
export function withCtx(
fn: Slot,
ctx: ComponentInternalInstance | null = currentRenderingInstance
Expand Down
114 changes: 61 additions & 53 deletions packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ export { useCSSModule } from './helpers/useCssModule'
// SSR context
export { useSSRContext, ssrContextKey } from './helpers/useSsrContext'

// Internal API ----------------------------------------------------------------
// Custom Renderer API ---------------------------------------------------------

// For custom renderers
export { createRenderer, createHydrationRenderer } from './renderer'
export { queuePostFlushCb } from './scheduler'
export { warn } from './warning'
Expand All @@ -92,57 +91,6 @@ export {
setTransitionHooks
} from './components/BaseTransition'

// For compiler generated code
// should sync with '@vue/compiler-core/src/runtimeConstants.ts'
export { withCtx } from './helpers/withRenderContext'
export { withDirectives } from './directives'
export {
resolveComponent,
resolveDirective,
resolveDynamicComponent
} from './helpers/resolveAssets'
export { renderList } from './helpers/renderList'
export { toHandlers } from './helpers/toHandlers'
export { renderSlot } from './helpers/renderSlot'
export { createSlots } from './helpers/createSlots'
export { pushScopeId, popScopeId, withScopeId } from './helpers/scopeId'
export {
setBlockTracking,
createTextVNode,
createCommentVNode,
createStaticVNode
} from './vnode'
export { toDisplayString, camelize } from '@vue/shared'

// For integration with runtime compiler
export { registerRuntimeCompiler } from './component'

// For test-utils
export { transformVNodeArgs } from './vnode'

// SSR -------------------------------------------------------------------------

import { createComponentInstance, setupComponent } from './component'
import {
renderComponentRoot,
setCurrentRenderingInstance
} from './componentRenderUtils'
import { isVNode, normalizeVNode } from './vnode'
import { normalizeSuspenseChildren } from './components/Suspense'

// SSR utils are only exposed in cjs builds.
const _ssrUtils = {
createComponentInstance,
setupComponent,
renderComponentRoot,
setCurrentRenderingInstance,
isVNode,
normalizeVNode,
normalizeSuspenseChildren
}

export const ssrUtils = (__NODE_JS__ ? _ssrUtils : null) as typeof _ssrUtils

// Types -----------------------------------------------------------------------

export {
Expand Down Expand Up @@ -233,3 +181,63 @@ export {
AsyncComponentLoader
} from './apiAsyncComponent'
export { HMRRuntime } from './hmr'

// Internal API ----------------------------------------------------------------

// **IMPORTANT** Internal APIs may change without notice between versions and
// user code should avoid relying on them.

// For compiler generated code
// should sync with '@vue/compiler-core/src/runtimeConstants.ts'
export { withCtx } from './helpers/withRenderContext'
export { withDirectives } from './directives'
export {
resolveComponent,
resolveDirective,
resolveDynamicComponent
} from './helpers/resolveAssets'
export { renderList } from './helpers/renderList'
export { toHandlers } from './helpers/toHandlers'
export { renderSlot } from './helpers/renderSlot'
export { createSlots } from './helpers/createSlots'
export { pushScopeId, popScopeId, withScopeId } from './helpers/scopeId'
export {
setBlockTracking,
createTextVNode,
createCommentVNode,
createStaticVNode
} from './vnode'
export { toDisplayString, camelize } from '@vue/shared'
// For integration with runtime compiler
export { registerRuntimeCompiler } from './component'

This comment has been minimized.

Copy link
@msaelices

msaelices May 3, 2020

@yyx990803 why is this excluded from the .d.ts declarations? We are using it for the new nativescript-vue-next which has a TS codebase. Is there any workaround?

This comment has been minimized.

Copy link
@msaelices

msaelices May 3, 2020

See #1109 for more context of the issue. Thanks in advance.

// For test-utils
export { transformVNodeArgs } from './vnode'

// SSR -------------------------------------------------------------------------

// **IMPORTANT** These APIs are exposed solely for @vue/server-renderer and may
// change without notice between versions. User code should never rely on them.

import { createComponentInstance, setupComponent } from './component'
import {
renderComponentRoot,
setCurrentRenderingInstance
} from './componentRenderUtils'
import { isVNode, normalizeVNode } from './vnode'
import { normalizeSuspenseChildren } from './components/Suspense'

const _ssrUtils = {
createComponentInstance,
setupComponent,
renderComponentRoot,
setCurrentRenderingInstance,
isVNode,
normalizeVNode,
normalizeSuspenseChildren
}

/**
* SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
* @internal
*/
export const ssrUtils = (__NODE_JS__ ? _ssrUtils : null) as typeof _ssrUtils
Loading

0 comments on commit c9bf7de

Please sign in to comment.