wip: more tests passing

This commit is contained in:
Evan You 2023-11-18 10:49:29 +08:00
parent e05ba29555
commit c4e50e46bb
11 changed files with 48 additions and 113 deletions

View File

@ -249,9 +249,9 @@ exports[`compiler: parse > self closing multiple tag 1`] = `
"imports": [], "imports": [],
"loc": { "loc": {
"end": { "end": {
"column": 1, "column": 37,
"line": 1, "line": 2,
"offset": 0, "offset": 73,
}, },
"start": { "start": {
"column": 1, "column": 1,
@ -450,9 +450,9 @@ exports[`compiler: parse > valid html 1`] = `
"imports": [], "imports": [],
"loc": { "loc": {
"end": { "end": {
"column": 1, "column": 7,
"line": 1, "line": 4,
"offset": 0, "offset": 123,
}, },
"start": { "start": {
"column": 1, "column": 1,

View File

@ -22,7 +22,7 @@ return function render(_ctx, _cache, $props, $setup, $data, $options) {
onClick: () => { onClick: () => {
for (let i = 0; i < _ctx.list.length; i++) { for (let i = 0; i < _ctx.list.length; i++) {
_ctx.log(i) _ctx.log(i)
} }
} }
}, null, 8 /* PROPS */, [\\"onClick\\"])) }, null, 8 /* PROPS */, [\\"onClick\\"]))
}" }"
@ -36,7 +36,7 @@ return function render(_ctx, _cache, $props, $setup, $data, $options) {
onClick: () => { onClick: () => {
for (const x in _ctx.list) { for (const x in _ctx.list) {
_ctx.log(x) _ctx.log(x)
} }
} }
}, null, 8 /* PROPS */, [\\"onClick\\"])) }, null, 8 /* PROPS */, [\\"onClick\\"]))
}" }"
@ -50,7 +50,7 @@ return function render(_ctx, _cache, $props, $setup, $data, $options) {
onClick: () => { onClick: () => {
for (const x of _ctx.list) { for (const x of _ctx.list) {
_ctx.log(x) _ctx.log(x)
} }
} }
}, null, 8 /* PROPS */, [\\"onClick\\"])) }, null, 8 /* PROPS */, [\\"onClick\\"]))
}" }"

View File

@ -1195,25 +1195,13 @@ describe('compiler: element transform', () => {
}) })
}) })
// TODO remove in 3.4 test('is casting', () => {
test('v-is', () => { const { node, root } = parseWithBind(`<div is="vue:foo" />`)
const { node, root } = parseWithBind(`<div v-is="'foo'" />`) expect(root.helpers).toContain(RESOLVE_COMPONENT)
expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT)
expect(node).toMatchObject({ expect(node).toMatchObject({
tag: { type: NodeTypes.VNODE_CALL,
callee: RESOLVE_DYNAMIC_COMPONENT, tag: '_component_foo'
arguments: [
{
type: NodeTypes.SIMPLE_EXPRESSION,
content: `'foo'`,
isStatic: false
}
]
},
// should skip v-is runtime check
directives: undefined
}) })
expect('v-is="component-name" has been deprecated').toHaveBeenWarned()
}) })
// #3934 // #3934

View File

@ -128,51 +128,24 @@ describe('compiler: expression transform', () => {
{ {
content: `_ctx.foo`, content: `_ctx.foo`,
loc: { loc: {
source: `foo`, start: { offset: 3, line: 1, column: 4 },
start: { end: { offset: 6, line: 1, column: 7 }
offset: 3,
line: 1,
column: 4
},
end: {
offset: 6,
line: 1,
column: 7
}
} }
}, },
`(`, `(`,
{ {
content: `_ctx.baz`, content: `_ctx.baz`,
loc: { loc: {
source: `baz`, start: { offset: 7, line: 1, column: 8 },
start: { end: { offset: 10, line: 1, column: 11 }
offset: 7,
line: 1,
column: 8
},
end: {
offset: 10,
line: 1,
column: 11
}
} }
}, },
` + 1, { key: `, ` + 1, { key: `,
{ {
content: `_ctx.kuz`, content: `_ctx.kuz`,
loc: { loc: {
source: `kuz`, start: { offset: 23, line: 1, column: 24 },
start: { end: { offset: 26, line: 1, column: 27 }
offset: 23,
line: 1,
column: 24
},
end: {
offset: 26,
line: 1,
column: 27
}
} }
}, },
` })` ` })`
@ -539,7 +512,7 @@ describe('compiler: expression transform', () => {
`<div @click="() => { `<div @click="() => {
for (const x in list) { for (const x in list) {
log(x) log(x)
} }
}"/>` }"/>`
) )
expect(code).not.toMatch(`_ctx.x`) expect(code).not.toMatch(`_ctx.x`)
@ -551,7 +524,7 @@ describe('compiler: expression transform', () => {
`<div @click="() => { `<div @click="() => {
for (const x of list) { for (const x of list) {
log(x) log(x)
} }
}"/>` }"/>`
) )
expect(code).not.toMatch(`_ctx.x`) expect(code).not.toMatch(`_ctx.x`)
@ -563,7 +536,7 @@ describe('compiler: expression transform', () => {
`<div @click="() => { `<div @click="() => {
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
log(i) log(i)
} }
}"/>` }"/>`
) )
expect(code).not.toMatch(`_ctx.i`) expect(code).not.toMatch(`_ctx.i`)

View File

@ -376,7 +376,6 @@ describe('compiler: transform <slot> outlets', () => {
expect(onError.mock.calls[0][0]).toMatchObject({ expect(onError.mock.calls[0][0]).toMatchObject({
code: ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET, code: ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
loc: { loc: {
source: `v-foo`,
start: { start: {
offset: index, offset: index,
line: 1, line: 1,

View File

@ -850,7 +850,6 @@ describe('compiler: transform component slots', () => {
expect(onError.mock.calls[0][0]).toMatchObject({ expect(onError.mock.calls[0][0]).toMatchObject({
code: ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN, code: ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN,
loc: { loc: {
source: `bar`,
start: { start: {
offset: index, offset: index,
line: 1, line: 1,
@ -873,7 +872,6 @@ describe('compiler: transform component slots', () => {
expect(onError.mock.calls[0][0]).toMatchObject({ expect(onError.mock.calls[0][0]).toMatchObject({
code: ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES, code: ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES,
loc: { loc: {
source: `#foo`,
start: { start: {
offset: index, offset: index,
line: 1, line: 1,
@ -896,7 +894,6 @@ describe('compiler: transform component slots', () => {
expect(onError.mock.calls[0][0]).toMatchObject({ expect(onError.mock.calls[0][0]).toMatchObject({
code: ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, code: ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE,
loc: { loc: {
source: `#foo`,
start: { start: {
offset: index, offset: index,
line: 1, line: 1,
@ -919,7 +916,6 @@ describe('compiler: transform component slots', () => {
expect(onError.mock.calls[0][0]).toMatchObject({ expect(onError.mock.calls[0][0]).toMatchObject({
code: ErrorCodes.X_V_SLOT_MISPLACED, code: ErrorCodes.X_V_SLOT_MISPLACED,
loc: { loc: {
source: `v-slot`,
start: { start: {
offset: index, offset: index,
line: 1, line: 1,

View File

@ -294,7 +294,7 @@ export default class Tokenizer {
} }
this.state = State.Interpolation this.state = State.Interpolation
this.sectionStart = this.index this.sectionStart = this.index
this.index += this.delimiterOpen.length this.index += this.delimiterOpen.length - 1
} }
} }

View File

@ -283,7 +283,7 @@ const tokenizer = new Tokenizer(stack, {
? getLoc(currentAttrStartIndex, currentAttrEndIndex) ? getLoc(currentAttrStartIndex, currentAttrEndIndex)
: getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
} }
} else if (currentAttrValue) { } else {
// directive // directive
currentProp.rawExp = currentAttrValue currentProp.rawExp = currentAttrValue
currentProp.exp = createSimpleExpression( currentProp.exp = createSimpleExpression(
@ -715,6 +715,7 @@ export function baseParse(input: string, options?: ParserOptions): RootNode {
const root = (currentRoot = createRoot([], input)) const root = (currentRoot = createRoot([], input))
tokenizer.parse(currentInput) tokenizer.parse(currentInput)
root.loc = getLoc(0, input.length)
root.children = condenseWhitespace(root.children) root.children = condenseWhitespace(root.children)
currentRoot = null currentRoot = null
return root return root

View File

@ -53,7 +53,6 @@ import {
findProp, findProp,
isCoreComponent, isCoreComponent,
isStaticArgOf, isStaticArgOf,
findDir,
isStaticExp isStaticExp
} from '../utils' } from '../utils'
import { buildSlots } from './vSlot' 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...) // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag) const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag)
if (builtIn) { if (builtIn) {

View File

@ -329,6 +329,13 @@ export function finalizeForParseResult(
true true
) )
} }
if (result.value) {
result.value = processExpression(
result.value as SimpleExpressionNode,
context,
true
)
}
} }
if (__DEV__ && __BROWSER__) { if (__DEV__ && __BROWSER__) {
validateBrowserExpression(result.source as SimpleExpressionNode, context) validateBrowserExpression(result.source as SimpleExpressionNode, context)

View File

@ -26,13 +26,12 @@ describe('DOM parser', () => {
content: 'some<div>text</div>and<!--comment-->', content: 'some<div>text</div>and<!--comment-->',
loc: { loc: {
start: { offset: 10, line: 1, column: 11 }, start: { offset: 10, line: 1, column: 11 },
end: { offset: 46, line: 1, column: 47 }, end: { offset: 46, line: 1, column: 47 }
source: 'some<div>text</div>and<!--comment-->'
} }
}) })
}) })
test('textarea handles character references', () => { test('textarea handles entities', () => {
const ast = parse('<textarea>&amp;</textarea>', parserOptions) const ast = parse('<textarea>&amp;</textarea>', parserOptions)
const element = ast.children[0] as ElementNode const element = ast.children[0] as ElementNode
const text = element.children[0] as TextNode const text = element.children[0] as TextNode
@ -42,8 +41,7 @@ describe('DOM parser', () => {
content: '&', content: '&',
loc: { loc: {
start: { offset: 10, line: 1, column: 11 }, start: { offset: 10, line: 1, column: 11 },
end: { offset: 15, line: 1, column: 16 }, end: { offset: 15, line: 1, column: 16 }
source: '&amp;'
} }
}) })
}) })
@ -77,8 +75,7 @@ describe('DOM parser', () => {
content: 'some<div>text</div>and<!--comment-->', content: 'some<div>text</div>and<!--comment-->',
loc: { loc: {
start: { offset: 7, line: 1, column: 8 }, start: { offset: 7, line: 1, column: 8 },
end: { offset: 43, line: 1, column: 44 }, end: { offset: 43, line: 1, column: 44 }
source: 'some<div>text</div>and<!--comment-->'
} }
}) })
}) })
@ -93,8 +90,7 @@ describe('DOM parser', () => {
content: '&amp;', content: '&amp;',
loc: { loc: {
start: { offset: 7, line: 1, column: 8 }, start: { offset: 7, line: 1, column: 8 },
end: { offset: 12, line: 1, column: 13 }, end: { offset: 12, line: 1, column: 13 }
source: '&amp;'
} }
}) })
}) })
@ -108,8 +104,7 @@ describe('DOM parser', () => {
content: 'some text', content: 'some text',
loc: { loc: {
start: { offset: 14, line: 1, column: 15 }, start: { offset: 14, line: 1, column: 15 },
end: { offset: 23, line: 1, column: 24 }, end: { offset: 23, line: 1, column: 24 }
source: 'some text'
} }
}) })
}) })
@ -180,8 +175,7 @@ describe('DOM parser', () => {
content: '&ersand;', content: '&ersand;',
loc: { loc: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 11, line: 1, column: 12 }, end: { offset: 11, line: 1, column: 12 }
source: '&ampersand;'
} }
}) })
}) })
@ -202,8 +196,7 @@ describe('DOM parser', () => {
content: '&ampersand;', content: '&ampersand;',
loc: { loc: {
start: { offset: 7, line: 1, column: 8 }, start: { offset: 7, line: 1, column: 8 },
end: { offset: 20, line: 1, column: 21 }, end: { offset: 20, line: 1, column: 21 }
source: '"&ampersand;"'
} }
}) })
expect(text2).toStrictEqual({ expect(text2).toStrictEqual({
@ -211,8 +204,7 @@ describe('DOM parser', () => {
content: '&ersand;', content: '&ersand;',
loc: { loc: {
start: { offset: 23, line: 1, column: 24 }, start: { offset: 23, line: 1, column: 24 },
end: { offset: 37, line: 1, column: 38 }, end: { offset: 37, line: 1, column: 38 }
source: '"&amp;ersand;"'
} }
}) })
expect(text3).toStrictEqual({ expect(text3).toStrictEqual({
@ -220,8 +212,7 @@ describe('DOM parser', () => {
content: '&!', content: '&!',
loc: { loc: {
start: { offset: 40, line: 1, column: 41 }, start: { offset: 40, line: 1, column: 41 },
end: { offset: 47, line: 1, column: 48 }, end: { offset: 47, line: 1, column: 48 }
source: '"&amp!"'
} }
}) })
}) })
@ -235,8 +226,7 @@ describe('DOM parser', () => {
content: '†', content: '†',
loc: { loc: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 6, line: 1, column: 7 }, end: { offset: 6, line: 1, column: 7 }
source: '&#x86;'
} }
}) })
}) })
@ -257,14 +247,12 @@ describe('DOM parser', () => {
constType: ConstantTypes.NOT_CONSTANT, constType: ConstantTypes.NOT_CONSTANT,
loc: { loc: {
start: { offset: 8, line: 1, column: 9 }, start: { offset: 8, line: 1, column: 9 },
end: { offset: 16, line: 1, column: 17 }, end: { offset: 16, line: 1, column: 17 }
source: 'a &lt; b'
} }
}, },
loc: { loc: {
start: { offset: 5, line: 1, column: 6 }, start: { offset: 5, line: 1, column: 6 },
end: { offset: 19, line: 1, column: 20 }, end: { offset: 19, line: 1, column: 20 }
source: '{{ a &lt; b }}'
} }
}) })
}) })
@ -281,12 +269,10 @@ describe('DOM parser', () => {
tag: 'img', tag: 'img',
tagType: ElementTypes.ELEMENT, tagType: ElementTypes.ELEMENT,
props: [], props: [],
isSelfClosing: false,
children: [], children: [],
loc: { loc: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 5, line: 1, column: 6 }, end: { offset: 5, line: 1, column: 6 }
source: '<img>'
}, },
codegenNode: undefined codegenNode: undefined
}) })
@ -335,8 +321,7 @@ describe('DOM parser', () => {
content: 'hello</textarea</textarea0>', content: 'hello</textarea</textarea0>',
loc: { loc: {
start: { offset: 10, line: 1, column: 11 }, start: { offset: 10, line: 1, column: 11 },
end: { offset: 37, line: 1, column: 38 }, end: { offset: 37, line: 1, column: 38 }
source: 'hello</textarea</textarea0>'
} }
}) })
}) })