Skip to content

Commit 1903df4

Browse files
committed
rename ASTElement node.conditions -> node.ifConditions, avoid mutating it during codegen (close vuejs#4317)
1 parent 16e3dae commit 1903df4

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

flow/compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ declare type ASTElement = {
9898
ifProcessed?: boolean;
9999
elseif?: string;
100100
else?: true;
101-
conditions?: ASTIfConditions;
101+
ifConditions?: ASTIfConditions;
102102

103103
for?: string;
104104
forProcessed?: boolean;

src/compiler/codegen/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function genOnce (el: ASTElement): string {
112112

113113
function genIf (el: any): string {
114114
el.ifProcessed = true // avoid recursion
115-
return genIfConditions(el.conditions)
115+
return genIfConditions(el.ifConditions.slice())
116116
}
117117

118118
function genIfConditions (conditions: ASTIfConditions): string {
@@ -127,7 +127,7 @@ function genIfConditions (conditions: ASTIfConditions): string {
127127
return `${genTernaryExp(condition.block)}`
128128
}
129129

130-
// v-if with v-once shuold generate code like (a)?_m(0):_m(1)
130+
// v-if with v-once should generate code like (a)?_m(0):_m(1)
131131
function genTernaryExp (el) {
132132
return el.once ? genOnce(el) : genElement(el)
133133
}

src/compiler/optimizer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ function markStaticRoots (node: ASTNode, isInFor: boolean) {
8080
markStaticRoots(node.children[i], isInFor || !!node.for)
8181
}
8282
}
83-
if (node.conditions) {
84-
walkThroughConditionsBlocks(node.conditions, isInFor)
83+
if (node.ifConditions) {
84+
walkThroughConditionsBlocks(node.ifConditions, isInFor)
8585
}
8686
}
8787
}

src/compiler/parser/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,10 @@ function processIfConditions (el, parent) {
353353
}
354354

355355
function addIfCondition (el, condition) {
356-
if (!el.conditions) {
357-
el.conditions = []
356+
if (!el.ifConditions) {
357+
el.ifConditions = []
358358
}
359-
el.conditions.push(condition)
359+
el.ifConditions.push(condition)
360360
}
361361

362362
function processOnce (el) {

test/unit/modules/compiler/optimizer.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('optimizer', () => {
6666
optimize(ast, baseOptions)
6767
expect(ast.static).toBe(false)
6868
expect(ast.children[0].static).toBe(false)
69-
expect(ast.children[0].conditions[1].block.static).toBeUndefined()
69+
expect(ast.children[0].ifConditions[1].block.static).toBeUndefined()
7070
})
7171

7272
it('v-pre directive', () => {
@@ -228,13 +228,13 @@ describe('optimizer', () => {
228228
</div>
229229
`, baseOptions)
230230
optimize(ast, baseOptions)
231-
expect(ast.conditions[1].block.children[0].children[0].conditions[1].block.staticRoot).toBe(false)
232-
expect(ast.conditions[1].block.children[0].children[0].conditions[1].block.staticInFor).toBe(true)
231+
expect(ast.ifConditions[1].block.children[0].children[0].ifConditions[1].block.staticRoot).toBe(false)
232+
expect(ast.ifConditions[1].block.children[0].children[0].ifConditions[1].block.staticInFor).toBe(true)
233233

234-
expect(ast.conditions[1].block.children[0].children[0].conditions[2].block.staticRoot).toBe(false)
235-
expect(ast.conditions[1].block.children[0].children[0].conditions[2].block.staticInFor).toBe(true)
234+
expect(ast.ifConditions[1].block.children[0].children[0].ifConditions[2].block.staticRoot).toBe(false)
235+
expect(ast.ifConditions[1].block.children[0].children[0].ifConditions[2].block.staticInFor).toBe(true)
236236

237-
expect(ast.conditions[2].block.children[0].children[0].conditions[1].block.staticRoot).toBe(false)
238-
expect(ast.conditions[2].block.children[0].children[0].conditions[1].block.staticInFor).toBe(true)
237+
expect(ast.ifConditions[2].block.children[0].children[0].ifConditions[1].block.staticRoot).toBe(false)
238+
expect(ast.ifConditions[2].block.children[0].children[0].ifConditions[1].block.staticInFor).toBe(true)
239239
})
240240
})

test/unit/modules/compiler/parser.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('parser', () => {
129129
<p v-else></p>
130130
`, baseOptions)
131131
expect(ast.tag).toBe('div')
132-
expect(ast.conditions[1].block.tag).toBe('p')
132+
expect(ast.ifConditions[1].block.tag).toBe('p')
133133
})
134134

135135
it('generate correct ast for 3 or more root elements with v-if and v-else on separate lines', () => {
@@ -139,9 +139,9 @@ describe('parser', () => {
139139
<p v-else></p>
140140
`, baseOptions)
141141
expect(ast.tag).toBe('div')
142-
expect(ast.conditions[0].block.tag).toBe('div')
143-
expect(ast.conditions[1].block.tag).toBe('span')
144-
expect(ast.conditions[2].block.tag).toBe('p')
142+
expect(ast.ifConditions[0].block.tag).toBe('div')
143+
expect(ast.ifConditions[1].block.tag).toBe('span')
144+
expect(ast.ifConditions[2].block.tag).toBe('p')
145145

146146
const astMore = parse(`
147147
<div v-if="1"></div>
@@ -151,11 +151,11 @@ describe('parser', () => {
151151
<p v-else></p>
152152
`, baseOptions)
153153
expect(astMore.tag).toBe('div')
154-
expect(astMore.conditions[0].block.tag).toBe('div')
155-
expect(astMore.conditions[1].block.tag).toBe('span')
156-
expect(astMore.conditions[2].block.tag).toBe('div')
157-
expect(astMore.conditions[3].block.tag).toBe('span')
158-
expect(astMore.conditions[4].block.tag).toBe('p')
154+
expect(astMore.ifConditions[0].block.tag).toBe('div')
155+
expect(astMore.ifConditions[1].block.tag).toBe('span')
156+
expect(astMore.ifConditions[2].block.tag).toBe('div')
157+
expect(astMore.ifConditions[3].block.tag).toBe('span')
158+
expect(astMore.ifConditions[4].block.tag).toBe('p')
159159
})
160160

161161
it('warn 2 root elements with v-if', () => {
@@ -267,13 +267,13 @@ describe('parser', () => {
267267
it('v-if directive syntax', () => {
268268
const ast = parse('<p v-if="show">hello world</p>', baseOptions)
269269
expect(ast.if).toBe('show')
270-
expect(ast.conditions[0].exp).toBe('show')
270+
expect(ast.ifConditions[0].exp).toBe('show')
271271
})
272272

273273
it('v-else-if directive syntax', () => {
274274
const ast = parse('<div><p v-if="show">hello</p><span v-else-if="2">elseif</span><p v-else>world</p></div>', baseOptions)
275275
const ifAst = ast.children[0]
276-
const conditionsAst = ifAst.conditions
276+
const conditionsAst = ifAst.ifConditions
277277
expect(conditionsAst.length).toBe(3)
278278
expect(conditionsAst[1].block.children[0].text).toBe('elseif')
279279
expect(conditionsAst[1].block.parent).toBe(ast)
@@ -284,7 +284,7 @@ describe('parser', () => {
284284
it('v-else directive syntax', () => {
285285
const ast = parse('<div><p v-if="show">hello</p><p v-else>world</p></div>', baseOptions)
286286
const ifAst = ast.children[0]
287-
const conditionsAst = ifAst.conditions
287+
const conditionsAst = ifAst.ifConditions
288288
expect(conditionsAst.length).toBe(2)
289289
expect(conditionsAst[1].block.children[0].text).toBe('world')
290290
expect(conditionsAst[1].block.parent).toBe(ast)

0 commit comments

Comments
 (0)