8000 refactor: drop Vue 2 support by KazariEX · Pull Request #5365 · vuejs/language-tools · GitHub
[go: up one dir, main page]

Skip to content

refactor: drop Vue 2 support #5365

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

Merged
merged 4 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: drop class component support
  • Loading branch information
KazariEX committed May 16, 2025
commit c025ad2c780e9c5d9fb7990e4363284d321ad4bb
1 change: 0 additions & 1 deletion packages/component-meta/lib/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,6 @@ function readTsComponentDefaultProps(
return component;
}
// export default defineComponent({ ... })
// export default Vue.extend({ ... })
else if (ts.isCallExpression(component)) {
if (component.arguments.length) {
const arg = component.arguments[0];
Expand Down
17 changes: 2 additions & 15 deletions packages/language-core/lib/codegen/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Code, Sfc, VueCompilerOptions } from '../../types';
import { codeFeatures } from '../codeFeatures';
import { generateGlobalTypes, getGlobalTypesFileName } from '../globalTypes';
import type { TemplateCodegenContext } from '../template/context';
import { endOfLine, generateSfcBlockSection, newLine } from '../utils';
import { generateSfcBlockSection, newLine } from '../utils';
import { generateComponentSelf } from './componentSelf';
import { createScriptCodegenContext, type ScriptCodegenContext } from './context';
import { generateScriptSetup, generateScriptSetupImports } from './scriptSetup';
Expand Down Expand Up @@ -55,7 +55,7 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
yield* generateScriptSetupImports(options.sfc.scriptSetup, options.scriptSetupRanges);
}
if (options.sfc.script && options.scriptRanges) {
const { exportDefault, classBlockEnd } = options.scriptRanges;
const { exportDefault } = options.scriptRanges;
const isExportRawObject = exportDefault
&& options.sfc.script.content[exportDefault.expression.start] === '{';
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
Expand Down Expand Up @@ -96,19 +96,6 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
yield options.vueCompilerOptions.optionsWrapper[1];
yield generateSfcBlockSection(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures.all);
}
else if (classBlockEnd !== undefined) {
if (options.vueCompilerOptions.skipTemplateCodegen) {
yield generateSfcBlockSection(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures.all);
}
else {
yield generateSfcBlockSection(options.sfc.script, 0, classBlockEnd, codeFeatures.all);
yield `__VLS_template = () => {${newLine}`;
const templateCodegenCtx = yield* generateTemplate(options, ctx);
yield* generateComponentSelf(options, ctx, templateCodegenCtx);
yield `}${endOfLine}`;
yield generateSfcBlockSection(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures.all);
}
}
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');
Expand Down
18 changes: 4 additions & 14 deletions packages/language-core/lib/parsers/scriptRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import { parseBindingRanges } from './scriptSetupRanges';

export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> { }

export function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean, withNode: boolean) {
export function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean) {

let exportDefault: (TextRange & {
expression: TextRange,
args: TextRange,
argsNode: ts.ObjectLiteralExpression | undefined,
argsNode: ts.ObjectLiteralExpression,
componentsOption: TextRange | undefined,
componentsOptionNode: ts.ObjectLiteralExpression | undefined,
directivesOption: TextRange | undefined,
nameOption: TextRange | undefined,
inheritAttrsOption: string | undefined,
}) | undefined;
let classBlockEnd: number | undefined;

const bindings = hasScriptSetup ? parseBindingRanges(ts, ast) : [];

Expand Down Expand Up @@ -66,28 +65,19 @@ export function parseScriptRanges(ts: typeof import('typescript'), ast: ts.Sourc
..._getStartEnd(raw),
expression: _getStartEnd(node.expression),
args: _getStartEnd(obj),
argsNode: withNode ? obj : undefined,
argsNode: obj,
componentsOption: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
componentsOptionNode: withNode ? componentsOptionNode : undefined,
componentsOptionNode: componentsOptionNode,
directivesOption: directivesOptionNode ? _getStartEnd(directivesOptionNode) : undefined,
nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
inheritAttrsOption,
};
}
}

if (
ts.isClassDeclaration(raw)
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.DefaultKeyword)
) {
classBlockEnd = raw.end - 1;
}
});

return {
exportDefault,
classBlockEnd,
bindings,
};

Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/plugins/vue-tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function createTsx(

const getScriptRanges = computed(() =>
sfc.script && validLangs.has(sfc.script.lang)
? parseScriptRanges(ts, sfc.script.ast, !!sfc.scriptSetup, false)
? parseScriptRanges(ts, sfc.script.ast, !!sfc.scriptSetup)
: undefined
);

Expand Down
7 changes: 0 additions & 7 deletions test-workspace/tsc/passedFixtures/vue3/#4841/main.vue

This file was deleted.

9 changes: 0 additions & 9 deletions test-workspace/tsc/passedFixtures/vue3/#997/main.vue

This file was deleted.

This file was deleted.

0