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": [],
"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,

View 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\\"]))
}"

View 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

View 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`)

View 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,

View 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,

View 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
}
}

View 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

View 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) {

View 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)

View 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 }
}
})
})