Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler-core): v-model multilines exp #2426 #2436

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ return function render(_ctx, _cache) {

return (_openBlock(), _createBlock(\\"input\\", {
modelValue:
model
model
.
foo
,
\\"onUpdate:modelValue\\": $event => (
model
model
.
foo
= $event)
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]))
}
Expand Down
7 changes: 4 additions & 3 deletions packages/compiler-core/__tests__/transforms/vModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ describe('compiler: transform v-model', () => {
expect(generate(root, { mode: 'module' }).code).toMatchSnapshot()
})

// #2426
test('simple expression (with multilines)', () => {
const root = parseWithVModel('<input v-model="\n model \n" />')
const root = parseWithVModel('<input v-model="\n model\n.\nfoo \n" />')
const node = root.children[0] as ElementNode
const props = ((node.codegenNode as VNodeCall).props as ObjectExpression)
.properties
Expand All @@ -127,7 +128,7 @@ describe('compiler: transform v-model', () => {
isStatic: true
},
value: {
content: '\n model \n',
content: '\n model\n.\nfoo \n',
isStatic: false
}
})
Expand All @@ -141,7 +142,7 @@ describe('compiler: transform v-model', () => {
children: [
'$event => (',
{
content: '\n model \n',
content: '\n model\n.\nfoo \n',
isStatic: false
},
' = $event)'
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const nonIdentifierRE = /^\d|[^\$\w]/
export const isSimpleIdentifier = (name: string): boolean =>
!nonIdentifierRE.test(name)

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