Skip to content

Commit 88e5e96

Browse files
committed
refactor: useWith -> prefixIdentifiers
1 parent e57cb51 commit 88e5e96

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

packages/compiler-core/__tests__/transforms/expression.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test(`should work`, async () => {
99
<p>{{ i }}</p>
1010
`,
1111
{
12-
useWith: false
12+
prefixIdentifiers: true
1313
}
1414
)
1515
console.log(code)

packages/compiler-core/src/codegen.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface CodegenOptions {
2626
// runtime helpers; otherwise will grab the helpers from global `Vue`.
2727
// default: false
2828
mode?: 'module' | 'function'
29-
useWith?: boolean
29+
prefixIdentifiers?: boolean
3030
// Filename for source map generation.
3131
filename?: string
3232
}
@@ -54,13 +54,13 @@ function createCodegenContext(
5454
ast: RootNode,
5555
{
5656
mode = 'function',
57-
useWith = true,
57+
prefixIdentifiers = false,
5858
filename = `template.vue.html`
5959
}: CodegenOptions
6060
): CodegenContext {
6161
const context: CodegenContext = {
6262
mode,
63-
useWith,
63+
prefixIdentifiers,
6464
filename,
6565
source: ast.loc.source,
6666
code: ``,
@@ -119,7 +119,7 @@ export function generate(
119119
options: CodegenOptions = {}
120120
): CodegenResult {
121121
const context = createCodegenContext(ast, options)
122-
const { mode, push, useWith, indent, deindent, newline } = context
122+
const { mode, push, prefixIdentifiers, indent, deindent, newline } = context
123123
const imports = ast.imports.join(', ')
124124
if (mode === 'function') {
125125
// generate const declarations for helpers
@@ -144,13 +144,13 @@ export function generate(
144144
})
145145
newline()
146146
}
147-
if (useWith) {
147+
if (!prefixIdentifiers) {
148148
push(`with (this) {`)
149149
indent()
150150
}
151151
push(`return `)
152152
genChildren(ast.children, context)
153-
if (useWith) {
153+
if (!prefixIdentifiers) {
154154
deindent()
155155
push(`}`)
156156
}

packages/compiler-core/src/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const enum ErrorCodes {
6969
X_V_BIND_NO_EXPRESSION,
7070

7171
// generic errors
72-
X_STRIP_WITH_NOT_SUPPORTED
72+
X_PREFIX_ID_NOT_SUPPORTED
7373
}
7474

7575
export const errorMessages: { [code: number]: string } = {
@@ -135,5 +135,5 @@ export const errorMessages: { [code: number]: string } = {
135135
[ErrorCodes.X_FOR_MALFORMED_EXPRESSION]: `v-for has invalid expression`,
136136

137137
// generic errors
138-
[ErrorCodes.X_STRIP_WITH_NOT_SUPPORTED]: `useWith: false is not supported in this build of compiler because it is optimized for payload size.`
138+
[ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED]: `"prefixIdentifiers" option is not supported in this build of compiler because it is optimized for payload size.`
139139
}

packages/compiler-core/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ export function compile(
1818
options: CompilerOptions = {}
1919
): CodegenResult {
2020
const ast = isString(template) ? parse(template, options) : template
21-
const useWith = __BROWSER__ || options.useWith !== false
21+
const prefixIdentifiers = !__BROWSER__ && options.prefixIdentifiers === true
2222

23-
if (__BROWSER__ && options.useWith === false) {
23+
if (__BROWSER__ && options.prefixIdentifiers === false) {
2424
;(options.onError || defaultOnError)(
25-
createCompilerError(ErrorCodes.X_STRIP_WITH_NOT_SUPPORTED)
25+
createCompilerError(ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED)
2626
)
2727
}
2828

2929
transform(ast, {
3030
...options,
31-
useWith,
31+
prefixIdentifiers,
3232
nodeTransforms: [
3333
transformIf,
3434
transformFor,
35-
...(useWith ? [] : [expressionTransform]),
35+
...(prefixIdentifiers ? [expressionTransform] : []),
3636
prepareElementForCodegen,
3737
...(options.nodeTransforms || []) // user transforms
3838
],

packages/compiler-core/src/transform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export type StructuralDirectiveTransform = (
4343
export interface TransformOptions {
4444
nodeTransforms?: NodeTransform[]
4545
directiveTransforms?: { [name: string]: DirectiveTransform }
46-
useWith?: boolean
46+
prefixIdentifiers?: boolean
4747
onError?: (error: CompilerError) => void
4848
}
4949

@@ -65,7 +65,7 @@ export interface TransformContext extends Required<TransformOptions> {
6565
function createTransformContext(
6666
root: RootNode,
6767
{
68-
useWith = true,
68+
prefixIdentifiers = false,
6969
nodeTransforms = [],
7070
directiveTransforms = {},
7171
onError = defaultOnError
@@ -75,7 +75,7 @@ function createTransformContext(
7575
imports: new Set(),
7676
statements: [],
7777
identifiers: {},
78-
useWith,
78+
prefixIdentifiers,
7979
nodeTransforms,
8080
directiveTransforms,
8181
onError,

packages/compiler-core/src/transforms/vFor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function parseForExpression(
8787
RHS.trim(),
8888
source.indexOf(RHS, LHS.length),
8989
context,
90-
!context.useWith
90+
context.prefixIdentifiers
9191
),
9292
value: undefined,
9393
key: undefined,

packages/compiler-core/src/transforms/vIf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { processExpression } from './expression'
1515
export const transformIf = createStructuralDirectiveTransform(
1616
/^(if|else|else-if)$/,
1717
(node, dir, context) => {
18-
if (!__BROWSER__ && !context.useWith && dir.exp) {
18+
if (!__BROWSER__ && context.prefixIdentifiers && dir.exp) {
1919
processExpression(dir.exp, context)
2020
}
2121
if (dir.name === 'if') {

0 commit comments

Comments
 (0)