Skip to content

Commit

Permalink
fix: adapter new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Aug 31, 2024
1 parent 526c605 commit 396b911
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
19 changes: 7 additions & 12 deletions packages/language-core/lib/codegen/template/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ export function* generateComponent(
yield endOfLine;
}

const refName = yield* generateVScope(options, ctx, node, props);
const [refName, offset] = yield* generateVScope(options, ctx, node, props);
if (refName) {
const varName = ctx.getInternalVariable();
options.templateRefNames.set(refName, varName);
options.templateRefNames.set(refName, [varName, offset]);
ctx.usedComponentCtxVars.add(var_defineComponentCtx);

yield `// @ts-ignore${newLine}`;
Expand Down Expand Up @@ -332,9 +332,9 @@ export function* generateElement(
yield endOfLine;
}

const refName = yield* generateVScope(options, ctx, node, node.props);
const [refName, offset] = yield* generateVScope(options, ctx, node, node.props);
if (refName) {
options.templateRefNames.set(refName, `__VLS_intrinsicElements['${node.tag}']`);
options.templateRefNames.set(refName, [`__VLS_intrinsicElements['${node.tag}']`, offset]);
}

const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot') as CompilerDOM.DirectiveNode;
Expand Down Expand Up @@ -385,14 +385,14 @@ function* generateVScope(
}

yield* generateElementDirectives(options, ctx, node);
const refName = yield* generateReferencesForElements(options, ctx, node); // <el ref="foo" />
const [refName, offset] = yield* generateReferencesForElements(options, ctx, node); // <el ref="foo" />
yield* generateReferencesForScopedCssClasses(options, ctx, node);

if (inScope) {
yield `}${newLine}`;
ctx.blockConditions.length = originalConditionsNum;
}
return refName;
return [refName, offset];
}

export function getCanonicalComponentName(tagText: string) {
Expand Down Expand Up @@ -566,12 +566,7 @@ function* generateReferencesForElements(
ctx.accessExternalVariable(content, startOffset);
}

const refName = CompilerDOM.toValidAssetId(prop.value.content, '_VLS_refs' as any);
options.templateRefNames.set(
prop.value.content,
[refName, prop.value.loc.start.offset + 1]
);
return refName;
return [content, startOffset];
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions packages/language-core/lib/codegen/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface TemplateCodegenOptions {
scriptSetupBindingNames: Set<string>;
scriptSetupImportComponentNames: Set<string>;
edited: boolean;
templateRefNames: Map<string, [validId: string, offset: number]>;
templateRefNames: Map<string, [varName: string, offset: number]>;
hasDefineSlots?: boolean;
slotsAssignName?: string;
propsAssignName?: string;
Expand Down Expand Up @@ -59,8 +59,13 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co

function* generateRefs(): Generator<Code> {
yield `const __VLS_refs = {${newLine}`;
for (const [name, [validId]] of options.templateRefNames) {
yield `'${name}': ${validId}!,${newLine}`;
for (const [name, [varName, offset]] of options.templateRefNames) {
yield* generateStringLiteralKey(
name,
offset,
ctx.codeFeatures.navigationAndCompletion
)
yield `: ${varName}!,${newLine}`;
}
yield `}${endOfLine}`;
yield `declare var $refs: typeof __VLS_refs${endOfLine}`;
Expand Down

0 comments on commit 396b911

Please sign in to comment.