"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 27,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 28,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 29,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 35,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 34,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 36,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 35,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 27,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 26,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 28,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 27,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 39,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 50,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 32,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 29,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 28,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 45,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 39,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 34,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 12,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 13,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 25,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 30,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 13,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 14,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 15,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 22,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 16,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 33,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 29,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 16,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 15,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 19,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 20,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 18,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 23,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 24,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 25,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 23,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 24,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 25,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 24,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 22,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 37,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 3,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 16,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 25,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 26,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 41,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 26,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 25,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 31,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 27,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 28,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 39,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 38,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 37,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 25,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 26,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 27,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 26,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 30,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 53,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 20,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 32,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 40,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 35,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 31,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 30,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 29,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 30,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 41,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 41,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 41,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 42,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 42,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 45,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 45,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 42,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 35,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 42,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 29,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 37,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 31,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 30,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 25,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 34,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 28,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 34,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 28,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 16,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 27,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 2,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 3,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 2,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 7,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 4,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 5,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 8,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 37,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
"type": 1,
},
],
+ "imports": Array [],
"loc": Object {
"end": Object {
"column": 7,
"offset": 0,
},
},
+ "statements": Array [],
"type": 0,
}
`;
export interface RootNode extends Node {
type: NodeTypes.ROOT
children: ChildNode[]
+ imports: string[]
+ statements: string[]
}
export interface ElementNode extends Node {
import { SourceMapGenerator, RawSourceMap } from 'source-map'
import { advancePositionWithMutation, assert } from './utils'
import { isString, isArray } from '@vue/shared'
-import { RENDER_LIST_HELPER } from './transforms/vFor'
+import { RENDER_LIST } from './runtimeConstants'
type CodegenNode = ChildNode | JSChildNode
column: number
offset: number
indentLevel: number
- imports: Set<string>
- knownIdentifiers: Set<string>
map?: SourceMapGenerator
push(code: string, node?: CodegenNode): void
indent(): void
line: 1,
offset: 0,
indentLevel: 0,
- imports: new Set(),
- knownIdentifiers: new Set(),
// lazy require source-map implementation, only in non-browser builds!
map: __BROWSER__
options: CodegenOptions = {}
): CodegenResult {
const context = createCodegenContext(ast, options)
- // TODO handle different output for module mode and IIFE mode
const { mode, push, useWith, indent, deindent } = context
+ const imports = ast.imports.join(', ')
if (mode === 'function') {
- // TODO generate const declarations for helpers
+ // generate const declarations for helpers
+ if (imports) {
+ push(`const { ${imports} } = Vue\n\n`)
+ }
push(`return `)
} else {
- // TODO generate import statements for helpers
+ // generate import statements for helpers
+ if (imports) {
+ push(`import { ${imports} } from 'vue'\n\n`)
+ }
push(`export default `)
}
push(`function render() {`)
+ // generate asset resolution statements
+ ast.statements.forEach(s => push(s + `\n`))
if (useWith) {
indent()
push(`with (this) {`)
function genFor(node: ForNode, context: CodegenContext) {
const { push } = context
const { source, keyAlias, valueAlias, objectIndexAlias, children } = node
- push(`${RENDER_LIST_HELPER}(`, node)
+ push(`${RENDER_LIST}(`, node)
genExpression(source, context)
push(`, (`)
if (valueAlias) {
return {
type: NodeTypes.ROOT,
children: parseChildren(context, TextModes.DATA, []),
+ imports: [],
+ statements: [],
loc: getSelection(context, start)
}
}
--- /dev/null
+// Name mapping constants for runtime helpers that need to be imported in
+// generated code. Make sure these are correctly exported in the runtime!
+export const CREATE_ELEMENT = `h`
+export const RESOLVE_COMPONENT = `resolveComponent`
+export const RESOLVE_DIRECTIVE = `resolveDirective`
+export const APPLY_DIRECTIVES = `applyDirectives`
+export const RENDER_LIST = `renderList`
+export const CAPITALIZE = `capitalize`
}
export interface TransformContext extends Required<TransformOptions> {
+ imports: Set<string>
+ statements: string[]
+ identifiers: { [name: string]: true }
parent: ParentNode
ancestors: ParentNode[]
childIndex: number
onNodeRemoved: () => void
}
-export function transform(root: RootNode, options: TransformOptions) {
- const context = createTransformContext(root, options)
- traverseChildren(root, context)
-}
-
function createTransformContext(
root: RootNode,
options: TransformOptions
): TransformContext {
const context: TransformContext = {
+ imports: new Set(),
+ statements: [],
+ identifiers: {},
nodeTransforms: options.nodeTransforms || [],
directiveTransforms: options.directiveTransforms || {},
onError: options.onError || defaultOnError,
return context
}
+export function transform(root: RootNode, options: TransformOptions) {
+ const context = createTransformContext(root, options)
+ traverseChildren(root, context)
+ root.imports = [...context.imports]
+ root.statements = context.statements
+}
+
export function traverseChildren(
parent: ParentNode,
context: TransformContext
) {
+ // ancestors and identifiers need to be cached here since they may get
+ // replaced during a child's traversal
const ancestors = context.ancestors.concat(parent)
+ const identifiers = context.identifiers
let i = 0
const nodeRemoved = () => {
i--
context.ancestors = ancestors
context.childIndex = i
context.onNodeRemoved = nodeRemoved
+ context.identifiers = identifiers
traverseNode((context.currentNode = parent.children[i]), context)
}
}
} from '../ast'
import { isArray } from '@vue/shared'
import { createCompilerError, ErrorCodes } from '../errors'
+import {
+ CREATE_ELEMENT,
+ APPLY_DIRECTIVES,
+ RESOLVE_DIRECTIVE,
+ RESOLVE_COMPONENT
+} from '../runtimeConstants'
+
+const toValidId = (str: string): string => str.replace(/[^\w]/g, '')
// generate a JavaScript AST for this element's codegen
export const prepareElementForCodegen: NodeTransform = (node, context) => {
const hasProps = node.props.length > 0
const hasChildren = node.children.length > 0
let runtimeDirectives: DirectiveNode[] | undefined
+ let componentIdentifier: string | undefined
if (isComponent) {
- // TODO inject import for `resolveComponent`
- // TODO inject statement for resolving component
+ context.imports.add(RESOLVE_COMPONENT)
+ componentIdentifier = `_component_${toValidId(node.tag)}`
+ context.statements.push(
+ `const ${componentIdentifier} = ${RESOLVE_COMPONENT}(${JSON.stringify(
+ node.tag
+ )})`
+ )
}
const args: CallExpression['arguments'] = [
- // TODO inject resolveComponent dep to root
- isComponent ? node.tag : `"${node.tag}"`
+ isComponent ? componentIdentifier! : `"${node.tag}"`
]
// props
if (hasProps) {
}
const { loc } = node
- // TODO inject import for `h`
- const vnode = createCallExpression(`h`, args, loc)
+ context.imports.add(CREATE_ELEMENT)
+ const vnode = createCallExpression(CREATE_ELEMENT, args, loc)
if (runtimeDirectives && runtimeDirectives.length) {
- // TODO inject import for `applyDirectives`
+ context.imports.add(APPLY_DIRECTIVES)
node.codegenNode = createCallExpression(
- `applyDirectives`,
+ APPLY_DIRECTIVES,
[
vnode,
createArrayExpression(
dir: DirectiveNode,
context: TransformContext
): ArrayExpression {
- // TODO inject import for `resolveDirective`
- // TODO inject statement for resolving directive
- const dirArgs: ArrayExpression['elements'] = [dir.name]
+ // inject import for `resolveDirective`
+ context.imports.add(RESOLVE_DIRECTIVE)
+ // inject statement for resolving directive
+ const dirIdentifier = `_directive_${toValidId(dir.name)}`
+ context.statements.push(
+ `const ${dirIdentifier} = _${RESOLVE_DIRECTIVE}(${JSON.stringify(
+ dir.name
+ )})`
+ )
+ const dirArgs: ArrayExpression['elements'] = [dirIdentifier]
const { loc } = dir
if (dir.exp) dirArgs.push(dir.exp)
if (dir.arg) dirArgs.push(dir.arg)
import { NodeTypes, ExpressionNode, createExpression } from '../ast'
import { createCompilerError, ErrorCodes } from '../errors'
import { getInnerRange } from '../utils'
+import { RENDER_LIST } from '../runtimeConstants'
const forAliasRE = /([\s\S]*?)(?:(?<=\))|\s+)(?:in|of)\s+([\s\S]*)/
const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
const stripParensRE = /^\(|\)$/g
-export const RENDER_LIST_HELPER = `renderList`
-
export const transformFor = createStructuralDirectiveTransform(
'for',
(node, dir, context) => {
if (dir.exp) {
- // TODO inject helper import
+ context.imports.add(RENDER_LIST)
const aliases = parseAliasExpressions(dir.exp.content)
if (aliases) {
import { DirectiveTransform } from '../transform'
import { createObjectProperty, createExpression } from '../ast'
import { capitalize } from '@vue/shared'
+import { CAPITALIZE } from '../runtimeConstants'
// v-on without arg is handled directly in ./element.ts due to it affecting
// codegen for the entire props object. This transform here is only for v-on
const arg = dir.arg!
const eventName = arg.isStatic
? createExpression(`on${capitalize(arg.content)}`, true, arg.loc)
- : // TODO inject capitalize helper
- createExpression(`'on' + capitalize(${arg.content})`, false, arg.loc)
+ : createExpression(`'on' + ${CAPITALIZE}(${arg.content})`, false, arg.loc)
// TODO .once modifier handling since it is platform agnostic
// other modifiers are handled in compiler-dom
return {
export { applyDirectives } from './directives'
export { resolveComponent, resolveDirective } from './helpers/resolveAssets'
export { renderList } from './helpers/renderList'
+export { capitalize } from '@vue/shared'
// Internal, for integration with runtime compiler
export { registerRuntimeCompiler } from './component'