]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: more tests passing
authorEvan You <yyx990803@gmail.com>
Sat, 18 Nov 2023 02:49:29 +0000 (10:49 +0800)
committerEvan You <yyx990803@gmail.com>
Sat, 25 Nov 2023 08:18:29 +0000 (16:18 +0800)
packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap
packages/compiler-core/__tests__/transforms/__snapshots__/transformExpressions.spec.ts.snap
packages/compiler-core/__tests__/transforms/transformElement.spec.ts
packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts
packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts
packages/compiler-core/__tests__/transforms/vSlot.spec.ts
packages/compiler-core/src/parser/Tokenizer.ts
packages/compiler-core/src/parser/index.ts
packages/compiler-core/src/transforms/transformElement.ts
packages/compiler-core/src/transforms/vFor.ts
packages/compiler-dom/__tests__/parse.spec.ts

index bc94557de722fdb78aa155359441b5b69c57b758..8493e6232fa761d1dd796934fc4696aaab84c6b4 100644 (file)
@@ -249,9 +249,9 @@ exports[`compiler: parse > self closing multiple tag 1`] = `
   "imports": [],
   "loc": {
     "end": {
-      "column": 1,
-      "line": 1,
-      "offset": 0,
+      "column": 37,
+      "line": 2,
+      "offset": 73,
     },
     "start": {
       "column": 1,
@@ -450,9 +450,9 @@ exports[`compiler: parse > valid html 1`] = `
   "imports": [],
   "loc": {
     "end": {
-      "column": 1,
-      "line": 1,
-      "offset": 0,
+      "column": 7,
+      "line": 4,
+      "offset": 123,
     },
     "start": {
       "column": 1,
index 434ebcbcf2f4af3d3fe52ff6e6e0cb4a5ce77c88..7df7d8babe959776c0cba94d1bf225523982f091 100644 (file)
@@ -22,7 +22,7 @@ return function render(_ctx, _cache, $props, $setup, $data, $options) {
     onClick: () => {
           for (let i = 0; i < _ctx.list.length; i++) {
             _ctx.log(i)
-          }         
+          }
         }
   }, null, 8 /* PROPS */, [\\"onClick\\"]))
 }"
@@ -36,7 +36,7 @@ return function render(_ctx, _cache, $props, $setup, $data, $options) {
     onClick: () => {
           for (const x in _ctx.list) {
             _ctx.log(x)
-          }         
+          }
         }
   }, null, 8 /* PROPS */, [\\"onClick\\"]))
 }"
@@ -50,7 +50,7 @@ return function render(_ctx, _cache, $props, $setup, $data, $options) {
     onClick: () => {
           for (const x of _ctx.list) {
             _ctx.log(x)
-          }         
+          }
         }
   }, null, 8 /* PROPS */, [\\"onClick\\"]))
 }"
index 97559369d8a7307df2e4bd7d0ac5c56528d6a039..f08b9f22e8b9f5908fc8e0c439ab29cf271c6bff 100644 (file)
@@ -1195,25 +1195,13 @@ describe('compiler: element transform', () => {
       })
     })
 
-    // TODO remove in 3.4
-    test('v-is', () => {
-      const { node, root } = parseWithBind(`<div v-is="'foo'" />`)
-      expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT)
+    test('is casting', () => {
+      const { node, root } = parseWithBind(`<div is="vue:foo" />`)
+      expect(root.helpers).toContain(RESOLVE_COMPONENT)
       expect(node).toMatchObject({
-        tag: {
-          callee: RESOLVE_DYNAMIC_COMPONENT,
-          arguments: [
-            {
-              type: NodeTypes.SIMPLE_EXPRESSION,
-              content: `'foo'`,
-              isStatic: false
-            }
-          ]
-        },
-        // should skip v-is runtime check
-        directives: undefined
+        type: NodeTypes.VNODE_CALL,
+        tag: '_component_foo'
       })
-      expect('v-is="component-name" has been deprecated').toHaveBeenWarned()
     })
 
     // #3934
index 16229113656112940beca1809c2d7c2468ad4adb..0d18c1bebe5258f63d3c607451c8f9021f15ae97 100644 (file)
@@ -128,51 +128,24 @@ describe('compiler: expression transform', () => {
         {
           content: `_ctx.foo`,
           loc: {
-            source: `foo`,
-            start: {
-              offset: 3,
-              line: 1,
-              column: 4
-            },
-            end: {
-              offset: 6,
-              line: 1,
-              column: 7
-            }
+            start: { offset: 3, line: 1, column: 4 },
+            end: { offset: 6, line: 1, column: 7 }
           }
         },
         `(`,
         {
           content: `_ctx.baz`,
           loc: {
-            source: `baz`,
-            start: {
-              offset: 7,
-              line: 1,
-              column: 8
-            },
-            end: {
-              offset: 10,
-              line: 1,
-              column: 11
-            }
+            start: { offset: 7, line: 1, column: 8 },
+            end: { offset: 10, line: 1, column: 11 }
           }
         },
         ` + 1, { key: `,
         {
           content: `_ctx.kuz`,
           loc: {
-            source: `kuz`,
-            start: {
-              offset: 23,
-              line: 1,
-              column: 24
-            },
-            end: {
-              offset: 26,
-              line: 1,
-              column: 27
-            }
+            start: { offset: 23, line: 1, column: 24 },
+            end: { offset: 26, line: 1, column: 27 }
           }
         },
         ` })`
@@ -539,7 +512,7 @@ describe('compiler: expression transform', () => {
         `<div @click="() => {
           for (const x in list) {
             log(x)
-          }         
+          }
         }"/>`
       )
       expect(code).not.toMatch(`_ctx.x`)
@@ -551,7 +524,7 @@ describe('compiler: expression transform', () => {
         `<div @click="() => {
           for (const x of list) {
             log(x)
-          }         
+          }
         }"/>`
       )
       expect(code).not.toMatch(`_ctx.x`)
@@ -563,7 +536,7 @@ describe('compiler: expression transform', () => {
         `<div @click="() => {
           for (let i = 0; i < list.length; i++) {
             log(i)
-          }         
+          }
         }"/>`
       )
       expect(code).not.toMatch(`_ctx.i`)
index 72753d5237fc16ddf8e85bb3bfee6acafa13a4b4..f9fa9d211723c44c3826fac5fa7912258bff7dc4 100644 (file)
@@ -376,7 +376,6 @@ describe('compiler: transform <slot> outlets', () => {
     expect(onError.mock.calls[0][0]).toMatchObject({
       code: ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
       loc: {
-        source: `v-foo`,
         start: {
           offset: index,
           line: 1,
index bb3d9d2cfa3ad46bc7d51f9e46fa799c2a853ce8..03ce2fa610e4a789f78e673652251fd604715043 100644 (file)
@@ -850,7 +850,6 @@ describe('compiler: transform component slots', () => {
       expect(onError.mock.calls[0][0]).toMatchObject({
         code: ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN,
         loc: {
-          source: `bar`,
           start: {
             offset: index,
             line: 1,
@@ -873,7 +872,6 @@ describe('compiler: transform component slots', () => {
       expect(onError.mock.calls[0][0]).toMatchObject({
         code: ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES,
         loc: {
-          source: `#foo`,
           start: {
             offset: index,
             line: 1,
@@ -896,7 +894,6 @@ describe('compiler: transform component slots', () => {
       expect(onError.mock.calls[0][0]).toMatchObject({
         code: ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE,
         loc: {
-          source: `#foo`,
           start: {
             offset: index,
             line: 1,
@@ -919,7 +916,6 @@ describe('compiler: transform component slots', () => {
       expect(onError.mock.calls[0][0]).toMatchObject({
         code: ErrorCodes.X_V_SLOT_MISPLACED,
         loc: {
-          source: `v-slot`,
           start: {
             offset: index,
             line: 1,
index 72a6de00cefee4872cf8299620b45baaee65b698..b1e9874185c54e24f580e45a7011c5d438ba9540 100644 (file)
@@ -294,7 +294,7 @@ export default class Tokenizer {
       }
       this.state = State.Interpolation
       this.sectionStart = this.index
-      this.index += this.delimiterOpen.length
+      this.index += this.delimiterOpen.length - 1
     }
   }
 
index 746b55fc69717a7f216ed176489f33a49d439eb9..b51fd4f616bac0647086e1149987e3c737763420 100644 (file)
@@ -283,7 +283,7 @@ const tokenizer = new Tokenizer(stack, {
                 ? getLoc(currentAttrStartIndex, currentAttrEndIndex)
                 : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
           }
-        } else if (currentAttrValue) {
+        } else {
           // directive
           currentProp.rawExp = currentAttrValue
           currentProp.exp = createSimpleExpression(
@@ -715,6 +715,7 @@ export function baseParse(input: string, options?: ParserOptions): RootNode {
 
   const root = (currentRoot = createRoot([], input))
   tokenizer.parse(currentInput)
+  root.loc = getLoc(0, input.length)
   root.children = condenseWhitespace(root.children)
   currentRoot = null
   return root
index 1d4d2f1f134ef0874f13badee0ac801c7e9ea2c4..03ccceb410150e96ef8bccdbbd3a371b32cdfac2 100644 (file)
@@ -53,7 +53,6 @@ import {
   findProp,
   isCoreComponent,
   isStaticArgOf,
-  findDir,
   isStaticExp
 } from '../utils'
 import { buildSlots } from './vSlot'
@@ -283,19 +282,6 @@ export function resolveComponentType(
     }
   }
 
-  // 1.5 v-is (TODO: remove in 3.4)
-  const isDir = !isExplicitDynamic && findDir(node, 'is')
-  if (isDir && isDir.exp) {
-    if (__DEV__) {
-      context.onWarn(
-        createCompilerError(ErrorCodes.DEPRECATION_V_IS, isDir.loc)
-      )
-    }
-    return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
-      isDir.exp
-    ])
-  }
-
   // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
   const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag)
   if (builtIn) {
index 89340a6aa3283af4348c400409081a5adfe39b4b..51962b2faa1c47cd9ad1132e5f9248f5dcf33ffc 100644 (file)
@@ -329,6 +329,13 @@ export function finalizeForParseResult(
         true
       )
     }
+    if (result.value) {
+      result.value = processExpression(
+        result.value as SimpleExpressionNode,
+        context,
+        true
+      )
+    }
   }
   if (__DEV__ && __BROWSER__) {
     validateBrowserExpression(result.source as SimpleExpressionNode, context)
index 736ea729fc4a67e3bc12d7937238984503373400..ed75b211a975e67e1b3b54c14aa94868d4d61ee1 100644 (file)
@@ -26,13 +26,12 @@ describe('DOM parser', () => {
         content: 'some<div>text</div>and<!--comment-->',
         loc: {
           start: { offset: 10, line: 1, column: 11 },
-          end: { offset: 46, line: 1, column: 47 },
-          source: 'some<div>text</div>and<!--comment-->'
+          end: { offset: 46, line: 1, column: 47 }
         }
       })
     })
 
-    test('textarea handles character references', () => {
+    test('textarea handles entities', () => {
       const ast = parse('<textarea>&amp;</textarea>', parserOptions)
       const element = ast.children[0] as ElementNode
       const text = element.children[0] as TextNode
@@ -42,8 +41,7 @@ describe('DOM parser', () => {
         content: '&',
         loc: {
           start: { offset: 10, line: 1, column: 11 },
-          end: { offset: 15, line: 1, column: 16 },
-          source: '&amp;'
+          end: { offset: 15, line: 1, column: 16 }
         }
       })
     })
@@ -77,8 +75,7 @@ describe('DOM parser', () => {
         content: 'some<div>text</div>and<!--comment-->',
         loc: {
           start: { offset: 7, line: 1, column: 8 },
-          end: { offset: 43, line: 1, column: 44 },
-          source: 'some<div>text</div>and<!--comment-->'
+          end: { offset: 43, line: 1, column: 44 }
         }
       })
     })
@@ -93,8 +90,7 @@ describe('DOM parser', () => {
         content: '&amp;',
         loc: {
           start: { offset: 7, line: 1, column: 8 },
-          end: { offset: 12, line: 1, column: 13 },
-          source: '&amp;'
+          end: { offset: 12, line: 1, column: 13 }
         }
       })
     })
@@ -108,8 +104,7 @@ describe('DOM parser', () => {
         content: 'some text',
         loc: {
           start: { offset: 14, line: 1, column: 15 },
-          end: { offset: 23, line: 1, column: 24 },
-          source: 'some text'
+          end: { offset: 23, line: 1, column: 24 }
         }
       })
     })
@@ -180,8 +175,7 @@ describe('DOM parser', () => {
         content: '&ersand;',
         loc: {
           start: { offset: 0, line: 1, column: 1 },
-          end: { offset: 11, line: 1, column: 12 },
-          source: '&ampersand;'
+          end: { offset: 11, line: 1, column: 12 }
         }
       })
     })
@@ -202,8 +196,7 @@ describe('DOM parser', () => {
         content: '&ampersand;',
         loc: {
           start: { offset: 7, line: 1, column: 8 },
-          end: { offset: 20, line: 1, column: 21 },
-          source: '"&ampersand;"'
+          end: { offset: 20, line: 1, column: 21 }
         }
       })
       expect(text2).toStrictEqual({
@@ -211,8 +204,7 @@ describe('DOM parser', () => {
         content: '&ersand;',
         loc: {
           start: { offset: 23, line: 1, column: 24 },
-          end: { offset: 37, line: 1, column: 38 },
-          source: '"&amp;ersand;"'
+          end: { offset: 37, line: 1, column: 38 }
         }
       })
       expect(text3).toStrictEqual({
@@ -220,8 +212,7 @@ describe('DOM parser', () => {
         content: '&!',
         loc: {
           start: { offset: 40, line: 1, column: 41 },
-          end: { offset: 47, line: 1, column: 48 },
-          source: '"&amp!"'
+          end: { offset: 47, line: 1, column: 48 }
         }
       })
     })
@@ -235,8 +226,7 @@ describe('DOM parser', () => {
         content: '†',
         loc: {
           start: { offset: 0, line: 1, column: 1 },
-          end: { offset: 6, line: 1, column: 7 },
-          source: '&#x86;'
+          end: { offset: 6, line: 1, column: 7 }
         }
       })
     })
@@ -257,14 +247,12 @@ describe('DOM parser', () => {
           constType: ConstantTypes.NOT_CONSTANT,
           loc: {
             start: { offset: 8, line: 1, column: 9 },
-            end: { offset: 16, line: 1, column: 17 },
-            source: 'a &lt; b'
+            end: { offset: 16, line: 1, column: 17 }
           }
         },
         loc: {
           start: { offset: 5, line: 1, column: 6 },
-          end: { offset: 19, line: 1, column: 20 },
-          source: '{{ a &lt; b }}'
+          end: { offset: 19, line: 1, column: 20 }
         }
       })
     })
@@ -281,12 +269,10 @@ describe('DOM parser', () => {
         tag: 'img',
         tagType: ElementTypes.ELEMENT,
         props: [],
-        isSelfClosing: false,
         children: [],
         loc: {
           start: { offset: 0, line: 1, column: 1 },
-          end: { offset: 5, line: 1, column: 6 },
-          source: '<img>'
+          end: { offset: 5, line: 1, column: 6 }
         },
         codegenNode: undefined
       })
@@ -335,8 +321,7 @@ describe('DOM parser', () => {
         content: 'hello</textarea</textarea0>',
         loc: {
           start: { offset: 10, line: 1, column: 11 },
-          end: { offset: 37, line: 1, column: 38 },
-          source: 'hello</textarea</textarea0>'
+          end: { offset: 37, line: 1, column: 38 }
         }
       })
     })