feat(compiler): expression prefixing + v-for scope analysis

This commit is contained in:
Evan You
2019-09-23 13:25:18 -04:00
parent b04be6a561
commit e57cb51066
8 changed files with 209 additions and 97 deletions

View File

@@ -8,7 +8,8 @@ import { transformFor } from './transforms/vFor'
import { prepareElementForCodegen } from './transforms/element'
import { transformOn } from './transforms/vOn'
import { transformBind } from './transforms/vBind'
import { rewriteExpression } from './transforms/expression'
import { expressionTransform } from './transforms/expression'
import { defaultOnError, createCompilerError, ErrorCodes } from './errors'
export type CompilerOptions = ParserOptions & TransformOptions & CodegenOptions
@@ -17,13 +18,21 @@ export function compile(
options: CompilerOptions = {}
): CodegenResult {
const ast = isString(template) ? parse(template, options) : template
const useWith = __BROWSER__ || options.useWith !== false
if (__BROWSER__ && options.useWith === false) {
;(options.onError || defaultOnError)(
createCompilerError(ErrorCodes.X_STRIP_WITH_NOT_SUPPORTED)
)
}
transform(ast, {
...options,
useWith,
nodeTransforms: [
...(!__BROWSER__ && options.useWith === false ? [rewriteExpression] : []),
transformIf,
transformFor,
...(useWith ? [] : [expressionTransform]),
prepareElementForCodegen,
...(options.nodeTransforms || []) // user transforms
],