Skip to content

Commit 89edf0d

Browse files
ktsnhaoqunjiang
authored andcommitted
fix(cli): avoid assertion error when vue.config.js includes assignment expression (#2770)
1 parent a09407d commit 89edf0d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/@vue/cli/lib/util/__tests__/extendJSConfig.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,21 @@ module.exports = config`
6161
module.exports = config`
6262
)
6363
})
64+
65+
test(`with extra assignment expression`, () => {
66+
const value = {
67+
foo: true
68+
}
69+
const source =
70+
`process.env.VUE_APP_TEST = 'test'
71+
module.exports = {
72+
bar: 123
73+
}`
74+
expect(extend(value, source)).toMatch(
75+
`process.env.VUE_APP_TEST = 'test'
76+
module.exports = {
77+
bar: 123,
78+
foo: true
79+
}`
80+
)
81+
})

packages/@vue/cli/lib/util/extendJSConfig.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = function extendJSConfig (value, source) {
77
const ast = recast.parse(source)
88

99
recast.types.visit(ast, {
10-
visitAssignmentExpression ({ node }) {
10+
visitAssignmentExpression (path) {
11+
const { node } = path
1112
if (
1213
node.left.type === 'MemberExpression' &&
1314
node.left.object.name === 'module' &&
@@ -21,6 +22,7 @@ module.exports = function extendJSConfig (value, source) {
2122
}
2223
return false
2324
}
25+
this.traverse(path)
2426
}
2527
})
2628

0 commit comments

Comments
 (0)