Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-core): use keywords instead of semicolons to separate script sections #5217

Merged
merged 9 commits into from
Feb 27, 2025
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
15 changes: 9 additions & 6 deletions packages/language-core/lib/codegen/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,15 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
}
else {
yield generateSfcBlockSection(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures.all);
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
}
}
else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
yield* generateScriptSetup(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
}

if (options.sfc.script) {
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
}
if (options.sfc.scriptSetup) {
yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue', ';');
}

if (!ctx.generatedTemplate) {
Expand All @@ -148,8 +146,13 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
return ctx;
}

export function* generateScriptSectionPartiallyEnding(source: string, end: number, mark: string): Generator<Code> {
yield `;`;
export function* generateScriptSectionPartiallyEnding(
source: string,
end: number,
mark: string,
delimiter = 'debugger'
): Generator<Code> {
yield delimiter;
yield ['', source, end, codeFeatures.verification];
yield `/* PartiallyEnd: ${mark} */${newLine}`;
}
11 changes: 2 additions & 9 deletions packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,8 @@ export function* generateScriptSetup(
): Generator<Code> {
if (scriptSetup.generic) {
if (!options.scriptRanges?.exportDefault) {
if (options.sfc.scriptSetup) {
// #4569
yield [
'',
'scriptSetup',
options.sfc.scriptSetup.content.length,
codeFeatures.verification,
];
}
// #4569
yield ['', 'scriptSetup', 0, codeFeatures.verification];
yield `export default `;
}
yield `(`;
Expand Down