mirror of https://github.com/vuejs/core.git
refactor(compiler-vapor): remove loc in IR
This commit is contained in:
parent
2bc107a7a7
commit
4062c6805a
|
@ -4,7 +4,6 @@ import type {
|
||||||
DirectiveNode,
|
DirectiveNode,
|
||||||
RootNode,
|
RootNode,
|
||||||
SimpleExpressionNode,
|
SimpleExpressionNode,
|
||||||
SourceLocation,
|
|
||||||
TemplateChildNode,
|
TemplateChildNode,
|
||||||
} from '@vue/compiler-dom'
|
} from '@vue/compiler-dom'
|
||||||
import type { Prettify } from '@vue/shared'
|
import type { Prettify } from '@vue/shared'
|
||||||
|
@ -37,7 +36,6 @@ export enum IRNodeTypes {
|
||||||
|
|
||||||
export interface BaseIRNode {
|
export interface BaseIRNode {
|
||||||
type: IRNodeTypes
|
type: IRNodeTypes
|
||||||
loc: SourceLocation
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type VaporHelper = keyof typeof import('@vue/runtime-vapor')
|
export type VaporHelper = keyof typeof import('@vue/runtime-vapor')
|
||||||
|
|
|
@ -197,12 +197,10 @@ function createRootContext(
|
||||||
templateNode = {
|
templateNode = {
|
||||||
type: IRNodeTypes.TEMPLATE_FACTORY,
|
type: IRNodeTypes.TEMPLATE_FACTORY,
|
||||||
template: this.template,
|
template: this.template,
|
||||||
loc: node.loc,
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
templateNode = {
|
templateNode = {
|
||||||
type: IRNodeTypes.FRAGMENT_FACTORY,
|
type: IRNodeTypes.FRAGMENT_FACTORY,
|
||||||
loc: node.loc,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root.template.push(templateNode)
|
root.template.push(templateNode)
|
||||||
|
@ -243,7 +241,6 @@ export function transform(
|
||||||
type: IRNodeTypes.ROOT,
|
type: IRNodeTypes.ROOT,
|
||||||
node: root,
|
node: root,
|
||||||
source: root.source,
|
source: root.source,
|
||||||
loc: root.loc,
|
|
||||||
template: [],
|
template: [],
|
||||||
templateIndex: -1,
|
templateIndex: -1,
|
||||||
dynamic: extend(genDefaultDynamic(), {
|
dynamic: extend(genDefaultDynamic(), {
|
||||||
|
@ -327,34 +324,32 @@ function transformChildren(ctx: TransformContext<RootNode | ElementNode>) {
|
||||||
processDynamicChildren(ctx)
|
processDynamicChildren(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
function processDynamicChildren(ctx: TransformContext<RootNode | ElementNode>) {
|
function processDynamicChildren(
|
||||||
const { node } = ctx
|
context: TransformContext<RootNode | ElementNode>,
|
||||||
|
) {
|
||||||
let prevChildren: IRDynamicInfo[] = []
|
let prevChildren: IRDynamicInfo[] = []
|
||||||
let hasStatic = false
|
let hasStatic = false
|
||||||
|
|
||||||
for (const [index, child] of ctx.dynamic.children.entries()) {
|
for (const [index, child] of context.dynamic.children.entries()) {
|
||||||
if (!child || !(child.flags & DynamicFlag.INSERT)) {
|
if (!child || !(child.flags & DynamicFlag.INSERT)) {
|
||||||
if (prevChildren.length) {
|
if (prevChildren.length) {
|
||||||
if (hasStatic) {
|
if (hasStatic) {
|
||||||
ctx.childrenTemplate[index - prevChildren.length] = `<!>`
|
context.childrenTemplate[index - prevChildren.length] = `<!>`
|
||||||
|
|
||||||
prevChildren[0].flags -= DynamicFlag.NON_TEMPLATE
|
prevChildren[0].flags -= DynamicFlag.NON_TEMPLATE
|
||||||
const anchor = (prevChildren[0].anchor = ctx.increaseId())
|
const anchor = (prevChildren[0].anchor = context.increaseId())
|
||||||
|
|
||||||
ctx.registerOperation({
|
context.registerOperation({
|
||||||
type: IRNodeTypes.INSERT_NODE,
|
type: IRNodeTypes.INSERT_NODE,
|
||||||
loc: node.loc,
|
|
||||||
element: prevChildren.map(child => child.id!),
|
element: prevChildren.map(child => child.id!),
|
||||||
parent: ctx.reference(),
|
parent: context.reference(),
|
||||||
anchor,
|
anchor,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ctx.registerOperation({
|
context.registerOperation({
|
||||||
type: IRNodeTypes.PREPEND_NODE,
|
type: IRNodeTypes.PREPEND_NODE,
|
||||||
loc: node.loc,
|
|
||||||
elements: prevChildren.map(child => child.id!),
|
elements: prevChildren.map(child => child.id!),
|
||||||
parent: ctx.reference(),
|
parent: context.reference(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -365,12 +360,11 @@ function processDynamicChildren(ctx: TransformContext<RootNode | ElementNode>) {
|
||||||
|
|
||||||
prevChildren.push(child)
|
prevChildren.push(child)
|
||||||
|
|
||||||
if (index === ctx.dynamic.children.length - 1) {
|
if (index === context.dynamic.children.length - 1) {
|
||||||
ctx.registerOperation({
|
context.registerOperation({
|
||||||
type: IRNodeTypes.APPEND_NODE,
|
type: IRNodeTypes.APPEND_NODE,
|
||||||
loc: node.loc,
|
|
||||||
elements: prevChildren.map(child => child.id!),
|
elements: prevChildren.map(child => child.id!),
|
||||||
parent: ctx.reference(),
|
parent: context.reference(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ function transformProp(
|
||||||
node: ElementNode,
|
node: ElementNode,
|
||||||
context: TransformContext<ElementNode>,
|
context: TransformContext<ElementNode>,
|
||||||
): void {
|
): void {
|
||||||
const { name, loc } = prop
|
const { name } = prop
|
||||||
if (isReservedProp(name)) return
|
if (isReservedProp(name)) return
|
||||||
|
|
||||||
if (prop.type === NodeTypes.ATTRIBUTE) {
|
if (prop.type === NodeTypes.ATTRIBUTE) {
|
||||||
|
@ -76,7 +76,6 @@ function transformProp(
|
||||||
type: IRNodeTypes.WITH_DIRECTIVE,
|
type: IRNodeTypes.WITH_DIRECTIVE,
|
||||||
element: context.reference(),
|
element: context.reference(),
|
||||||
dir: prop,
|
dir: prop,
|
||||||
loc,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ export const transformInterpolation: NodeTransform = (node, ctx) => {
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: IRNodeTypes.SET_TEXT,
|
type: IRNodeTypes.SET_TEXT,
|
||||||
loc: node.loc,
|
|
||||||
element: parentId,
|
element: parentId,
|
||||||
value: expr,
|
value: expr,
|
||||||
},
|
},
|
||||||
|
@ -30,7 +29,6 @@ export const transformInterpolation: NodeTransform = (node, ctx) => {
|
||||||
ctx.dynamic.flags |= DynamicFlag.INSERT | DynamicFlag.NON_TEMPLATE
|
ctx.dynamic.flags |= DynamicFlag.INSERT | DynamicFlag.NON_TEMPLATE
|
||||||
ctx.registerOperation({
|
ctx.registerOperation({
|
||||||
type: IRNodeTypes.CREATE_TEXT_NODE,
|
type: IRNodeTypes.CREATE_TEXT_NODE,
|
||||||
loc: node.loc,
|
|
||||||
id,
|
id,
|
||||||
})
|
})
|
||||||
ctx.registerEffect(
|
ctx.registerEffect(
|
||||||
|
@ -38,7 +36,6 @@ export const transformInterpolation: NodeTransform = (node, ctx) => {
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: IRNodeTypes.SET_TEXT,
|
type: IRNodeTypes.SET_TEXT,
|
||||||
loc: node.loc,
|
|
||||||
element: id,
|
element: id,
|
||||||
value: expr,
|
value: expr,
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,6 +26,5 @@ export const transformRef: NodeTransform = (node, context) => {
|
||||||
type: IRNodeTypes.SET_REF,
|
type: IRNodeTypes.SET_REF,
|
||||||
element: context.reference(),
|
element: context.reference(),
|
||||||
value,
|
value,
|
||||||
loc: dir.loc,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,6 @@ export const transformVBind: DirectiveTransform = (dir, node, context) => {
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: IRNodeTypes.SET_PROP,
|
type: IRNodeTypes.SET_PROP,
|
||||||
loc: dir.loc,
|
|
||||||
element: context.reference(),
|
element: context.reference(),
|
||||||
key: arg,
|
key: arg,
|
||||||
value: exp,
|
value: exp,
|
||||||
|
|
|
@ -50,7 +50,6 @@ export function processFor(
|
||||||
const id = context.reference()
|
const id = context.reference()
|
||||||
const render: BlockFunctionIRNode = {
|
const render: BlockFunctionIRNode = {
|
||||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||||
loc: node.loc,
|
|
||||||
node,
|
node,
|
||||||
templateIndex: -1,
|
templateIndex: -1,
|
||||||
dynamic: extend(genDefaultDynamic(), {
|
dynamic: extend(genDefaultDynamic(), {
|
||||||
|
@ -69,7 +68,6 @@ export function processFor(
|
||||||
context.registerOperation({
|
context.registerOperation({
|
||||||
type: IRNodeTypes.FOR,
|
type: IRNodeTypes.FOR,
|
||||||
id,
|
id,
|
||||||
loc: dir.loc,
|
|
||||||
source: source as SimpleExpressionNode,
|
source: source as SimpleExpressionNode,
|
||||||
value: value as SimpleExpressionNode | undefined,
|
value: value as SimpleExpressionNode | undefined,
|
||||||
key: key as SimpleExpressionNode | undefined,
|
key: key as SimpleExpressionNode | undefined,
|
||||||
|
|
|
@ -21,7 +21,6 @@ export const transformVHtml: DirectiveTransform = (dir, node, context) => {
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: IRNodeTypes.SET_HTML,
|
type: IRNodeTypes.SET_HTML,
|
||||||
loc: dir.loc,
|
|
||||||
element: context.reference(),
|
element: context.reference(),
|
||||||
value: exp || '""',
|
value: exp || '""',
|
||||||
},
|
},
|
||||||
|
|
|
@ -51,7 +51,6 @@ export function processIf(
|
||||||
context.registerOperation({
|
context.registerOperation({
|
||||||
type: IRNodeTypes.IF,
|
type: IRNodeTypes.IF,
|
||||||
id,
|
id,
|
||||||
loc: dir.loc,
|
|
||||||
condition: dir.exp!,
|
condition: dir.exp!,
|
||||||
positive: branch,
|
positive: branch,
|
||||||
})
|
})
|
||||||
|
@ -130,7 +129,6 @@ export function processIf(
|
||||||
lastIfNode.negative = {
|
lastIfNode.negative = {
|
||||||
type: IRNodeTypes.IF,
|
type: IRNodeTypes.IF,
|
||||||
id: -1,
|
id: -1,
|
||||||
loc: dir.loc,
|
|
||||||
condition: dir.exp!,
|
condition: dir.exp!,
|
||||||
positive: branch,
|
positive: branch,
|
||||||
}
|
}
|
||||||
|
@ -148,7 +146,6 @@ export function createIfBranch(
|
||||||
|
|
||||||
const branch: BlockFunctionIRNode = {
|
const branch: BlockFunctionIRNode = {
|
||||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||||
loc: node.loc,
|
|
||||||
node,
|
node,
|
||||||
templateIndex: -1,
|
templateIndex: -1,
|
||||||
dynamic: extend(genDefaultDynamic(), {
|
dynamic: extend(genDefaultDynamic(), {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import type { DirectiveTransform } from '../transform'
|
||||||
import { IRNodeTypes, type VaporHelper } from '../ir'
|
import { IRNodeTypes, type VaporHelper } from '../ir'
|
||||||
|
|
||||||
export const transformVModel: DirectiveTransform = (dir, node, context) => {
|
export const transformVModel: DirectiveTransform = (dir, node, context) => {
|
||||||
const { exp, arg, loc } = dir
|
const { exp, arg } = dir
|
||||||
if (!exp) {
|
if (!exp) {
|
||||||
context.options.onError(
|
context.options.onError(
|
||||||
createCompilerError(ErrorCodes.X_V_MODEL_NO_EXPRESSION, dir.loc),
|
createCompilerError(ErrorCodes.X_V_MODEL_NO_EXPRESSION, dir.loc),
|
||||||
|
@ -140,7 +140,6 @@ export const transformVModel: DirectiveTransform = (dir, node, context) => {
|
||||||
key: (arg && arg.isStatic ? arg.content : arg) || 'modelValue',
|
key: (arg && arg.isStatic ? arg.content : arg) || 'modelValue',
|
||||||
value: exp,
|
value: exp,
|
||||||
isComponent,
|
isComponent,
|
||||||
loc: loc,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (runtimeDirective)
|
if (runtimeDirective)
|
||||||
|
@ -148,7 +147,6 @@ export const transformVModel: DirectiveTransform = (dir, node, context) => {
|
||||||
type: IRNodeTypes.WITH_DIRECTIVE,
|
type: IRNodeTypes.WITH_DIRECTIVE,
|
||||||
element: context.reference(),
|
element: context.reference(),
|
||||||
dir,
|
dir,
|
||||||
loc,
|
|
||||||
builtin: runtimeDirective,
|
builtin: runtimeDirective,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,6 @@ export const transformVOn: DirectiveTransform = (dir, node, context) => {
|
||||||
|
|
||||||
const operation: SetEventIRNode = {
|
const operation: SetEventIRNode = {
|
||||||
type: IRNodeTypes.SET_EVENT,
|
type: IRNodeTypes.SET_EVENT,
|
||||||
loc,
|
|
||||||
element: context.reference(),
|
element: context.reference(),
|
||||||
key: arg,
|
key: arg,
|
||||||
value: exp,
|
value: exp,
|
||||||
|
|
|
@ -14,6 +14,5 @@ export const transformVShow: DirectiveTransform = (dir, node, context) => {
|
||||||
type: IRNodeTypes.WITH_DIRECTIVE,
|
type: IRNodeTypes.WITH_DIRECTIVE,
|
||||||
element: context.reference(),
|
element: context.reference(),
|
||||||
dir,
|
dir,
|
||||||
loc,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ export const transformVText: DirectiveTransform = (dir, node, context) => {
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: IRNodeTypes.SET_TEXT,
|
type: IRNodeTypes.SET_TEXT,
|
||||||
loc: dir.loc,
|
|
||||||
element: context.reference(),
|
element: context.reference(),
|
||||||
value: exp || '""',
|
value: exp || '""',
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue