Skip to content

Commit 6d2a1cb

Browse files
authored
fix(compiler-core): fix multiline member expression check (#2436)
fix #2426
1 parent 288c764 commit 6d2a1cb

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

packages/compiler-core/__tests__/transforms/__snapshots__/vModel.spec.ts.snap

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ return function render(_ctx, _cache) {
3535
3636
return (_openBlock(), _createBlock(\\"input\\", {
3737
modelValue:
38-
model
38+
model
39+
.
40+
foo
3941
,
4042
\\"onUpdate:modelValue\\": $event => (
41-
model
43+
model
44+
.
45+
foo
4246
= $event)
4347
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]))
4448
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ describe('compiler: transform v-model', () => {
115115
expect(generate(root, { mode: 'module' }).code).toMatchSnapshot()
116116
})
117117

118+
// #2426
118119
test('simple expression (with multilines)', () => {
119-
const root = parseWithVModel('<input v-model="\n model \n" />')
120+
const root = parseWithVModel('<input v-model="\n model\n.\nfoo \n" />')
120121
const node = root.children[0] as ElementNode
121122
const props = ((node.codegenNode as VNodeCall).props as ObjectExpression)
122123
.properties
@@ -127,7 +128,7 @@ describe('compiler: transform v-model', () => {
127128
isStatic: true
128129
},
129130
value: {
130-
content: '\n model \n',
131+
content: '\n model\n.\nfoo \n',
131132
isStatic: false
132133
}
133134
})
@@ -141,7 +142,7 @@ describe('compiler: transform v-model', () => {
141142
children: [
142143
'$event => (',
143144
{
144-
content: '\n model \n',
145+
content: '\n model\n.\nfoo \n',
145146
isStatic: false
146147
},
147148
' = $event)'

packages/compiler-core/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const nonIdentifierRE = /^\d|[^\$\w]/
5656
export const isSimpleIdentifier = (name: string): boolean =>
5757
!nonIdentifierRE.test(name)
5858

59-
const memberExpRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\[[^\]]+\])*$/
59+
const memberExpRE = /^[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*|\[[^\]]+\])*$/
6060
export const isMemberExpression = (path: string): boolean => {
6161
if (!path) return false
6262
return memberExpRE.test(path.trim())

0 commit comments

Comments
 (0)