From: Evan You Date: Sat, 18 Nov 2023 02:49:29 +0000 (+0800) Subject: wip: more tests passing X-Git-Tag: v3.4.0-alpha.2~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4e50e46bbf11576351fa48d167fb8e6acc8191c;p=thirdparty%2Fvuejs%2Fcore.git wip: more tests passing --- diff --git a/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap index bc94557de7..8493e6232f 100644 --- a/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap @@ -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, diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/transformExpressions.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/transformExpressions.spec.ts.snap index 434ebcbcf2..7df7d8babe 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/transformExpressions.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/transformExpressions.spec.ts.snap @@ -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\\"])) }" diff --git a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts index 97559369d8..f08b9f22e8 100644 --- a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts @@ -1195,25 +1195,13 @@ describe('compiler: element transform', () => { }) }) - // TODO remove in 3.4 - test('v-is', () => { - const { node, root } = parseWithBind(`
`) - expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT) + test('is casting', () => { + const { node, root } = parseWithBind(`
`) + 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 diff --git a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts index 1622911365..0d18c1bebe 100644 --- a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts @@ -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', () => { `
` ) expect(code).not.toMatch(`_ctx.x`) @@ -551,7 +524,7 @@ describe('compiler: expression transform', () => { `
` ) expect(code).not.toMatch(`_ctx.x`) @@ -563,7 +536,7 @@ describe('compiler: expression transform', () => { `
` ) expect(code).not.toMatch(`_ctx.i`) diff --git a/packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts b/packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts index 72753d5237..f9fa9d2117 100644 --- a/packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts @@ -376,7 +376,6 @@ describe('compiler: transform 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, diff --git a/packages/compiler-core/__tests__/transforms/vSlot.spec.ts b/packages/compiler-core/__tests__/transforms/vSlot.spec.ts index bb3d9d2cfa..03ce2fa610 100644 --- a/packages/compiler-core/__tests__/transforms/vSlot.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vSlot.spec.ts @@ -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, diff --git a/packages/compiler-core/src/parser/Tokenizer.ts b/packages/compiler-core/src/parser/Tokenizer.ts index 72a6de00ce..b1e9874185 100644 --- a/packages/compiler-core/src/parser/Tokenizer.ts +++ b/packages/compiler-core/src/parser/Tokenizer.ts @@ -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 } } diff --git a/packages/compiler-core/src/parser/index.ts b/packages/compiler-core/src/parser/index.ts index 746b55fc69..b51fd4f616 100644 --- a/packages/compiler-core/src/parser/index.ts +++ b/packages/compiler-core/src/parser/index.ts @@ -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 diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts index 1d4d2f1f13..03ccceb410 100644 --- a/packages/compiler-core/src/transforms/transformElement.ts +++ b/packages/compiler-core/src/transforms/transformElement.ts @@ -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) { diff --git a/packages/compiler-core/src/transforms/vFor.ts b/packages/compiler-core/src/transforms/vFor.ts index 89340a6aa3..51962b2faa 100644 --- a/packages/compiler-core/src/transforms/vFor.ts +++ b/packages/compiler-core/src/transforms/vFor.ts @@ -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) diff --git a/packages/compiler-dom/__tests__/parse.spec.ts b/packages/compiler-dom/__tests__/parse.spec.ts index 736ea729fc..ed75b211a9 100644 --- a/packages/compiler-dom/__tests__/parse.spec.ts +++ b/packages/compiler-dom/__tests__/parse.spec.ts @@ -26,13 +26,12 @@ describe('DOM parser', () => { content: 'some
text
and', loc: { start: { offset: 10, line: 1, column: 11 }, - end: { offset: 46, line: 1, column: 47 }, - source: 'some
text
and' + end: { offset: 46, line: 1, column: 47 } } }) }) - test('textarea handles character references', () => { + test('textarea handles entities', () => { const ast = parse('', 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: '&' + end: { offset: 15, line: 1, column: 16 } } }) }) @@ -77,8 +75,7 @@ describe('DOM parser', () => { content: 'some
text
and', loc: { start: { offset: 7, line: 1, column: 8 }, - end: { offset: 43, line: 1, column: 44 }, - source: 'some
text
and' + end: { offset: 43, line: 1, column: 44 } } }) }) @@ -93,8 +90,7 @@ describe('DOM parser', () => { content: '&', loc: { start: { offset: 7, line: 1, column: 8 }, - end: { offset: 12, line: 1, column: 13 }, - source: '&' + 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: '&ersand;' + end: { offset: 11, line: 1, column: 12 } } }) }) @@ -202,8 +196,7 @@ describe('DOM parser', () => { content: '&ersand;', loc: { start: { offset: 7, line: 1, column: 8 }, - end: { offset: 20, line: 1, column: 21 }, - source: '"&ersand;"' + 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: '"&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: '"&!"' + 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: '†' + 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 < 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 < 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: '' + end: { offset: 5, line: 1, column: 6 } }, codegenNode: undefined }) @@ -335,8 +321,7 @@ describe('DOM parser', () => { content: 'hello', loc: { start: { offset: 10, line: 1, column: 11 }, - end: { offset: 37, line: 1, column: 38 }, - source: 'hello' + end: { offset: 37, line: 1, column: 38 } } }) })