Skip to content

Commit

Permalink
fix(v-model): allow multiline expressions (fix vuejs#1218)
Browse files Browse the repository at this point in the history
prettier breaks long/deeply nested expression attributes in new lines
(prettier/prettier#5384) but this breaks the
compiler
  • Loading branch information
Gunther Konig committed May 21, 2020
1 parent 2b2beb9 commit 03d3f93
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/compiler-core/src/utils.ts
Expand Up @@ -83,7 +83,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 = /^\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\[[^\]]+\])*\s*$/
export const isMemberExpression = (path: string): boolean =>
memberExpRE.test(path)

Expand Down
Expand Up @@ -215,3 +215,23 @@ return function render(_ctx, _cache) {
}
}"
`;

exports[`compiler: transform v-model simple expression with multiline 1`] = `
"const _Vue = Vue
return function render(_ctx, _cache) {
with (_ctx) {
const { vModelText: _vModelText, createVNode: _createVNode, withDirectives: _withDirectives, openBlock: _openBlock, createBlock: _createBlock } = _Vue
return _withDirectives((_openBlock(), _createBlock(\\"input\\", {
\\"onUpdate:modelValue\\": $event => (
model
= $event)
}, null, 8 /* PROPS */, [\\"onUpdate:modelValue\\"])), [
[_vModelText,
model
]
])
}
}"
`;
7 changes: 7 additions & 0 deletions packages/compiler-dom/__tests__/transforms/vModel.spec.ts
Expand Up @@ -35,6 +35,13 @@ describe('compiler: transform v-model', () => {
expect(generate(root).code).toMatchSnapshot()
})

test('simple expression with multiline', () => {
const root = transformWithModel('<input v-model="\n model \n" />')

expect(root.helpers).toContain(V_MODEL_TEXT)
expect(generate(root).code).toMatchSnapshot()
})

test('simple expression for input (text)', () => {
const root = transformWithModel('<input type="text" v-model="model" />')

Expand Down

0 comments on commit 03d3f93

Please sign in to comment.