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