Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/language-core/lib/codegen/template/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { endOfLine, identifierRegex, newLine } from '../utils';
import { endBoundary, startBoundary } from '../utils/boundary';
import { generateCamelized } from '../utils/camelized';
import type { TemplateCodegenContext } from './context';
import { generateElementChildren } from './elementChildren';
import { generateElementDirectives } from './elementDirectives';
import { generateElementEvents } from './elementEvents';
import { type FailedPropExpression, generateElementProps } from './elementProps';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { generatePropertyAccess } from './propertyAccess';
import { collectStyleScopedClassReferences } from './styleScopedClasses';
import { generateTemplateChild } from './templateChild';
import { generateVSlot } from './vSlot';

const colonReg = /:/g;
Expand Down Expand Up @@ -344,7 +344,9 @@ export function* generateElement(

const { currentComponent } = ctx;
ctx.currentComponent = undefined;
yield* generateElementChildren(options, ctx, node.children);
for (const child of node.children) {
yield* generateTemplateChild(options, ctx, child);
}
ctx.currentComponent = currentComponent;
}

Expand Down
99 changes: 0 additions & 99 deletions packages/language-core/lib/codegen/template/elementChildren.ts

This file was deleted.

6 changes: 4 additions & 2 deletions packages/language-core/lib/codegen/template/slotOutlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { createVBindShorthandInlayHintInfo } from '../inlayHints';
import { endOfLine, newLine } from '../utils';
import { endBoundary, startBoundary } from '../utils/boundary';
import type { TemplateCodegenContext } from './context';
import { generateElementChildren } from './elementChildren';
import { generateElementProps, generatePropExp } from './elementProps';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { generatePropertyAccess } from './propertyAccess';
import { generateTemplateChild } from './templateChild';

export function* generateSlotOutlet(
options: TemplateCodegenOptions,
Expand Down Expand Up @@ -148,5 +148,7 @@ export function* generateSlotOutlet(
});
}
}
yield* generateElementChildren(options, ctx, node.children);
for (const child of node.children) {
yield* generateTemplateChild(options, ctx, child);
}
}
76 changes: 5 additions & 71 deletions packages/language-core/lib/codegen/template/templateChild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,18 @@ import { codeFeatures } from '../codeFeatures';
import { endOfLine } from '../utils';
import type { TemplateCodegenContext } from './context';
import { generateComponent, generateElement } from './element';
import { generateElementChildren } from './elementChildren';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { generateSlotOutlet } from './slotOutlet';
import { generateVFor } from './vFor';
import { generateVIf } from './vIf';
import { generateVSlot } from './vSlot';

// @ts-ignore
const transformContext: CompilerDOM.TransformContext = {
onError: () => {},
helperString: str => str.toString(),
replaceNode: () => {},
cacheHandlers: false,
prefixIdentifiers: false,
scopes: {
vFor: 0,
vOnce: 0,
vPre: 0,
vSlot: 0,
},
expressionPlugins: ['typescript'],
};

export function* generateTemplateChild(
options: TemplateCodegenOptions,
ctx: TemplateCodegenContext,
node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode,
enterNode: boolean = true,
enterNode = true,
): Generator<Code> {
if (enterNode && !ctx.enter(node)) {
return;
Expand All @@ -48,14 +31,12 @@ export function* generateTemplateChild(
for (const item of collectSingleRootNodes(options, node.children)) {
ctx.singleRootNodes.add(item);
}
yield* generateElementChildren(options, ctx, node.children);
for (const child of node.children) {
yield* generateTemplateChild(options, ctx, child);
}
}
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
const vForNode = getVForNode(node);
if (vForNode) {
yield* generateVFor(options, ctx, vForNode);
}
else if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
yield* generateSlotOutlet(options, ctx, node);
}
else {
Expand Down Expand Up @@ -159,53 +140,6 @@ function* collectSingleRootNodes(
}
}

// TODO: track https://github.com/vuejs/vue-next/issues/3498
export function getVForNode(node: CompilerDOM.ElementNode) {
const forDirective = node.props.find(
(prop): prop is CompilerDOM.DirectiveNode =>
prop.type === CompilerDOM.NodeTypes.DIRECTIVE
&& prop.name === 'for',
);
if (forDirective) {
let forNode: CompilerDOM.ForNode | undefined;
CompilerDOM.processFor(node, forDirective, transformContext, _forNode => {
forNode = { ..._forNode };
return undefined;
});
if (forNode) {
forNode.children = [{
...node,
props: node.props.filter(prop => prop !== forDirective),
}];
return forNode;
}
}
}

export function getVIfNode(node: CompilerDOM.ElementNode) {
const ifDirective = node.props.find(
(prop): prop is CompilerDOM.DirectiveNode =>
prop.type === CompilerDOM.NodeTypes.DIRECTIVE
&& prop.name === 'if',
);
if (ifDirective) {
let ifNode: CompilerDOM.IfNode | undefined;
CompilerDOM.processIf(node, ifDirective, transformContext, _ifNode => {
ifNode = { ..._ifNode };
return undefined;
});
if (ifNode) {
for (const branch of ifNode.branches) {
branch.children = [{
...node,
props: node.props.filter(prop => prop !== ifDirective),
}];
}
return ifNode;
}
}
}

export function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string) {
let start = node.content.loc.start.offset;
let end = node.content.loc.end.offset;
Expand Down
6 changes: 4 additions & 2 deletions packages/language-core/lib/codegen/template/vFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { collectBindingNames } from '../../utils/collectBindings';
import { codeFeatures } from '../codeFeatures';
import { endOfLine, getTypeScriptAST, newLine } from '../utils';
import type { TemplateCodegenContext } from './context';
import { generateElementChildren } from './elementChildren';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { generateTemplateChild } from './templateChild';

export function* generateVFor(
options: TemplateCodegenOptions,
Expand Down Expand Up @@ -82,7 +82,9 @@ export function* generateVFor(

const { inVFor } = ctx;
ctx.inVFor = true;
yield* generateElementChildren(options, ctx, node.children, isFragment);
for (const child of node.children) {
yield* generateTemplateChild(options, ctx, child, isFragment);
}
ctx.inVFor = inVFor;

yield* endScope();
Expand Down
6 changes: 4 additions & 2 deletions packages/language-core/lib/codegen/template/vIf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { Code } from '../../types';
import { codeFeatures } from '../codeFeatures';
import { newLine } from '../utils';
import type { TemplateCodegenContext } from './context';
import { generateElementChildren } from './elementChildren';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { generateTemplateChild } from './templateChild';

export function* generateVIf(
options: TemplateCodegenOptions,
Expand Down Expand Up @@ -52,7 +52,9 @@ export function* generateVIf(
}

yield `{${newLine}`;
yield* generateElementChildren(options, ctx, branch.children, i !== 0 || isFragment);
for (const child of branch.children) {
yield* generateTemplateChild(options, ctx, child, i !== 0 || isFragment);
}
yield `}${newLine}`;

if (addedBlockCondition) {
Expand Down
6 changes: 4 additions & 2 deletions packages/language-core/lib/codegen/template/vSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { codeFeatures } from '../codeFeatures';
import { endOfLine, getTypeScriptAST, newLine } from '../utils';
import { endBoundary, startBoundary } from '../utils/boundary';
import type { TemplateCodegenContext } from './context';
import { generateElementChildren } from './elementChildren';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { generateObjectProperty } from './objectProperty';
import { generateTemplateChild } from './templateChild';

export function* generateVSlot(
options: TemplateCodegenOptions,
Expand Down Expand Up @@ -66,7 +66,9 @@ export function* generateVSlot(
yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
ctx.declare(...collectBindingNames(options.ts, slotAst, slotAst));
}
yield* generateElementChildren(options, ctx, node.children);
for (const child of node.children) {
yield* generateTemplateChild(options, ctx, child);
}
yield* endScope();

if (slotDir) {
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/compilerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class CompilerOptionsResolver {
...defaults.fallthroughComponentNames,
...this.options.fallthroughComponentNames ?? [],
].map(hyphenateTag),
// https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
// https://github.com/vuejs/core/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings
experimentalModelPropName: Object.fromEntries(
Object.entries(
Expand Down
2 changes: 2 additions & 0 deletions packages/language-core/lib/virtualCode/ir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { computed, setActiveSub } from 'alien-signals';
import type * as ts from 'typescript';
import type { Sfc, SfcBlock, SfcBlockAttr, VueLanguagePluginReturn } from '../types';
import { computedArray, computedItems } from '../utils/signals';
import { normalizeTemplateAST } from './normalize';

export function useIR(
ts: typeof import('typescript'),
Expand Down Expand Up @@ -275,6 +276,7 @@ export function useIR(
try {
const result = plugin.compileSFCTemplate?.(base.lang, base.content, options);
if (result) {
normalizeTemplateAST(result.ast);
return {
snapshot: getUntrackedSnapshot(),
template: base.content,
Expand Down
Loading
Loading