]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): fix multiline member expression check (#2436)
authorHunter <kltan69@gmail.com>
Tue, 20 Oct 2020 13:31:08 +0000 (21:31 +0800)
committerGitHub <noreply@github.com>
Tue, 20 Oct 2020 13:31:08 +0000 (09:31 -0400)
fix #2426

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

index cdbe3c3eefa9c72aa4d8687d3df31e297393fd9f..bef1bd699b7980faa8361f42ef4f26afefda3eea 100644 (file)
@@ -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\\"]))
   }
index 42f9c6052b2c6034050b17198e6770477ec8f753..119624cda8ca71be4921745c82e157dbbf79787f 100644 (file)
@@ -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
@@ -127,7 +128,7 @@ describe('compiler: transform v-model', () => {
         isStatic: true
       },
       value: {
-        content: '\n model \n',
+        content: '\n model\n.\nfoo \n',
         isStatic: false
       }
     })
@@ -141,7 +142,7 @@ describe('compiler: transform v-model', () => {
         children: [
           '$event => (',
           {
-            content: '\n model \n',
+            content: '\n model\n.\nfoo \n',
             isStatic: false
           },
           ' = $event)'
index efc97f5d4c4bd1ff5f091385bc4444764f82878e..107bb0f6c1426014f473dbbf1ca8e806a6a799ed 100644 (file)
@@ -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())