<p>{{ i }}</p>
`,
{
- useWith: false
+ prefixIdentifiers: true
}
)
console.log(code)
// runtime helpers; otherwise will grab the helpers from global `Vue`.
// default: false
mode?: 'module' | 'function'
- useWith?: boolean
+ prefixIdentifiers?: boolean
// Filename for source map generation.
filename?: string
}
ast: RootNode,
{
mode = 'function',
- useWith = true,
+ prefixIdentifiers = false,
filename = `template.vue.html`
}: CodegenOptions
): CodegenContext {
const context: CodegenContext = {
mode,
- useWith,
+ prefixIdentifiers,
filename,
source: ast.loc.source,
code: ``,
options: CodegenOptions = {}
): CodegenResult {
const context = createCodegenContext(ast, options)
- const { mode, push, useWith, indent, deindent, newline } = context
+ const { mode, push, prefixIdentifiers, indent, deindent, newline } = context
const imports = ast.imports.join(', ')
if (mode === 'function') {
// generate const declarations for helpers
})
newline()
}
- if (useWith) {
+ if (!prefixIdentifiers) {
push(`with (this) {`)
indent()
}
push(`return `)
genChildren(ast.children, context)
- if (useWith) {
+ if (!prefixIdentifiers) {
deindent()
push(`}`)
}
X_V_BIND_NO_EXPRESSION,
// generic errors
- X_STRIP_WITH_NOT_SUPPORTED
+ X_PREFIX_ID_NOT_SUPPORTED
}
export const errorMessages: { [code: number]: string } = {
[ErrorCodes.X_FOR_MALFORMED_EXPRESSION]: `v-for has invalid expression`,
// generic errors
- [ErrorCodes.X_STRIP_WITH_NOT_SUPPORTED]: `useWith: false is not supported in this build of compiler because it is optimized for payload size.`
+ [ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED]: `"prefixIdentifiers" option is not supported in this build of compiler because it is optimized for payload size.`
}
options: CompilerOptions = {}
): CodegenResult {
const ast = isString(template) ? parse(template, options) : template
- const useWith = __BROWSER__ || options.useWith !== false
+ const prefixIdentifiers = !__BROWSER__ && options.prefixIdentifiers === true
- if (__BROWSER__ && options.useWith === false) {
+ if (__BROWSER__ && options.prefixIdentifiers === false) {
;(options.onError || defaultOnError)(
- createCompilerError(ErrorCodes.X_STRIP_WITH_NOT_SUPPORTED)
+ createCompilerError(ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED)
)
}
transform(ast, {
...options,
- useWith,
+ prefixIdentifiers,
nodeTransforms: [
transformIf,
transformFor,
- ...(useWith ? [] : [expressionTransform]),
+ ...(prefixIdentifiers ? [expressionTransform] : []),
prepareElementForCodegen,
...(options.nodeTransforms || []) // user transforms
],
export interface TransformOptions {
nodeTransforms?: NodeTransform[]
directiveTransforms?: { [name: string]: DirectiveTransform }
- useWith?: boolean
+ prefixIdentifiers?: boolean
onError?: (error: CompilerError) => void
}
function createTransformContext(
root: RootNode,
{
- useWith = true,
+ prefixIdentifiers = false,
nodeTransforms = [],
directiveTransforms = {},
onError = defaultOnError
imports: new Set(),
statements: [],
identifiers: {},
- useWith,
+ prefixIdentifiers,
nodeTransforms,
directiveTransforms,
onError,
RHS.trim(),
source.indexOf(RHS, LHS.length),
context,
- !context.useWith
+ context.prefixIdentifiers
),
value: undefined,
key: undefined,
export const transformIf = createStructuralDirectiveTransform(
/^(if|else|else-if)$/,
(node, dir, context) => {
- if (!__BROWSER__ && !context.useWith && dir.exp) {
+ if (!__BROWSER__ && context.prefixIdentifiers && dir.exp) {
processExpression(dir.exp, context)
}
if (dir.name === 'if') {