refactor: opt-in
This commit is contained in:
parent
1c89b42aaf
commit
308c7f01dc
File diff suppressed because it is too large
Load Diff
|
@ -446,16 +446,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
closeTagLoc: {
|
|
||||||
start: { offset: 12, line: 1, column: 13 },
|
|
||||||
end: { offset: 15, line: 1, column: 16 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [],
|
props: [],
|
||||||
|
@ -486,16 +476,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
closeTagLoc: {
|
|
||||||
start: { offset: 7, line: 1, column: 8 },
|
|
||||||
end: { offset: 10, line: 1, column: 11 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [],
|
props: [],
|
||||||
|
@ -516,11 +496,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [],
|
props: [],
|
||||||
|
@ -544,11 +519,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'img',
|
tag: 'img',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'img',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [],
|
props: [],
|
||||||
|
@ -571,11 +541,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'img',
|
tag: 'img',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'img',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [],
|
props: [],
|
||||||
|
@ -763,16 +728,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
closeTagLoc: {
|
|
||||||
start: { offset: 10, line: 1, column: 11 },
|
|
||||||
end: { offset: 13, line: 1, column: 14 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [
|
props: [
|
||||||
|
@ -810,16 +765,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
closeTagLoc: {
|
|
||||||
start: { offset: 13, line: 1, column: 14 },
|
|
||||||
end: { offset: 16, line: 1, column: 17 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [
|
props: [
|
||||||
|
@ -865,16 +810,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
closeTagLoc: {
|
|
||||||
start: { offset: 13, line: 1, column: 14 },
|
|
||||||
end: { offset: 16, line: 1, column: 17 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [
|
props: [
|
||||||
|
@ -920,16 +855,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
closeTagLoc: {
|
|
||||||
start: { offset: 15, line: 1, column: 16 },
|
|
||||||
end: { offset: 18, line: 1, column: 19 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [
|
props: [
|
||||||
|
@ -975,16 +900,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
closeTagLoc: {
|
|
||||||
start: { offset: 15, line: 1, column: 16 },
|
|
||||||
end: { offset: 18, line: 1, column: 19 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [
|
props: [
|
||||||
|
@ -1030,16 +945,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
closeTagLoc: {
|
|
||||||
start: { offset: 13, line: 1, column: 14 },
|
|
||||||
end: { offset: 16, line: 1, column: 17 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [
|
props: [
|
||||||
|
@ -1168,16 +1073,6 @@ describe('compiler: parse', () => {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
ns: Namespaces.HTML,
|
ns: Namespaces.HTML,
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { offset: 1, line: 1, column: 2 },
|
|
||||||
end: { offset: 4, line: 1, column: 5 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
closeTagLoc: {
|
|
||||||
start: { offset: 37, line: 1, column: 38 },
|
|
||||||
end: { offset: 40, line: 1, column: 41 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
props: [
|
props: [
|
||||||
|
@ -1283,11 +1178,6 @@ describe('compiler: parse', () => {
|
||||||
|
|
||||||
expect(element).toStrictEqual({
|
expect(element).toStrictEqual({
|
||||||
children: [],
|
children: [],
|
||||||
closeTagLoc: {
|
|
||||||
start: { column: 6, line: 3, offset: 25 },
|
|
||||||
end: { column: 9, line: 3, offset: 28 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
loc: {
|
loc: {
|
||||||
start: { column: 1, line: 1, offset: 0 },
|
start: { column: 1, line: 1, offset: 0 },
|
||||||
|
@ -1321,11 +1211,6 @@ describe('compiler: parse', () => {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
tagLoc: {
|
|
||||||
start: { column: 2, line: 1, offset: 1 },
|
|
||||||
end: { column: 5, line: 1, offset: 4 },
|
|
||||||
source: 'div',
|
|
||||||
},
|
|
||||||
tagType: ElementTypes.ELEMENT,
|
tagType: ElementTypes.ELEMENT,
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
})
|
})
|
||||||
|
|
|
@ -130,7 +130,7 @@ export interface BaseElementNode extends Node {
|
||||||
type: NodeTypes.ELEMENT
|
type: NodeTypes.ELEMENT
|
||||||
ns: Namespace
|
ns: Namespace
|
||||||
tag: string
|
tag: string
|
||||||
tagLoc: SourceLocation
|
openTagLoc?: SourceLocation
|
||||||
closeTagLoc?: SourceLocation
|
closeTagLoc?: SourceLocation
|
||||||
tagType: ElementTypes
|
tagType: ElementTypes
|
||||||
props: Array<AttributeNode | DirectiveNode>
|
props: Array<AttributeNode | DirectiveNode>
|
||||||
|
|
|
@ -97,6 +97,11 @@ export interface ParserOptions
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
prefixIdentifiers?: boolean
|
prefixIdentifiers?: boolean
|
||||||
|
/**
|
||||||
|
* Whether to calculate the location of open tag and close tag of each node.
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
tagLocations?: boolean
|
||||||
/**
|
/**
|
||||||
* A list of parser plugins to enable for `@babel/parser`, which is used to
|
* A list of parser plugins to enable for `@babel/parser`, which is used to
|
||||||
* parse expressions in bindings and interpolations.
|
* parse expressions in bindings and interpolations.
|
||||||
|
|
|
@ -78,6 +78,7 @@ export const defaultParserOptions: MergedParserOptions = {
|
||||||
onWarn: defaultOnWarn,
|
onWarn: defaultOnWarn,
|
||||||
comments: __DEV__,
|
comments: __DEV__,
|
||||||
prefixIdentifiers: false,
|
prefixIdentifiers: false,
|
||||||
|
tagLocations: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentOptions: MergedParserOptions = defaultParserOptions
|
let currentOptions: MergedParserOptions = defaultParserOptions
|
||||||
|
@ -140,13 +141,15 @@ const tokenizer = new Tokenizer(stack, {
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
tag: name,
|
tag: name,
|
||||||
ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
|
ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
|
||||||
tagLoc: getLoc(start, end),
|
|
||||||
tagType: ElementTypes.ELEMENT, // will be refined on tag close
|
tagType: ElementTypes.ELEMENT, // will be refined on tag close
|
||||||
props: [],
|
props: [],
|
||||||
children: [],
|
children: [],
|
||||||
loc: getLoc(start - 1, end),
|
loc: getLoc(start - 1, end),
|
||||||
codegenNode: undefined,
|
codegenNode: undefined,
|
||||||
}
|
}
|
||||||
|
if (currentOptions.tagLocations) {
|
||||||
|
currentOpenTag.openTagLoc = getLoc(start, end)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onopentagend(end) {
|
onopentagend(end) {
|
||||||
|
@ -166,7 +169,7 @@ const tokenizer = new Tokenizer(stack, {
|
||||||
}
|
}
|
||||||
for (let j = 0; j <= i; j++) {
|
for (let j = 0; j <= i; j++) {
|
||||||
const el = stack.shift()!
|
const el = stack.shift()!
|
||||||
if (j === i) {
|
if (j === i && currentOptions.tagLocations) {
|
||||||
el.closeTagLoc = getLoc(start, end)
|
el.closeTagLoc = getLoc(start, end)
|
||||||
}
|
}
|
||||||
onCloseTag(el, end, j < i)
|
onCloseTag(el, end, j < i)
|
||||||
|
@ -492,7 +495,7 @@ const tokenizer = new Tokenizer(stack, {
|
||||||
|
|
||||||
// This regex doesn't cover the case if key or index aliases have destructuring,
|
// This regex doesn't cover the case if key or index aliases have destructuring,
|
||||||
// but those do not make sense in the first place, so this works in practice.
|
// but those do not make sense in the first place, so this works in practice.
|
||||||
const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
|
const forIteratorRE = /,([^,}\]]*)(?:,([^,}\]]*))?$/
|
||||||
const stripParensRE = /^\(|\)$/g
|
const stripParensRE = /^\(|\)$/g
|
||||||
|
|
||||||
function parseForExpression(
|
function parseForExpression(
|
||||||
|
|
Loading…
Reference in New Issue