Skip to content

Commit aaa1c68

Browse files
committed
refactor: drop Vue 2 support (#5636)
1 parent 10d056b commit aaa1c68

File tree

17 files changed

+20
-221
lines changed

17 files changed

+20
-221
lines changed

extensions/vscode/schemas/vue-tsconfig.schema.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"default": "auto",
99
"enum": [
1010
"auto",
11-
2,
12-
2.7,
1311
3,
1412
3.3,
1513
3.5,

packages/language-core/lib/codegen/globalTypes.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { VueCompilerOptions } from '../types';
2-
import { getSlotsPropertyName } from '../utils/shared';
32

43
export function getGlobalTypesFileName(options: VueCompilerOptions) {
54
return [
@@ -69,7 +68,7 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
6968
type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
7069
__ctx?: {
7170
attrs?: any;
72-
slots?: T extends { ${getSlotsPropertyName(target)}: infer Slots } ? Slots : Record<string, any>;
71+
slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>;
7372
emit?: T extends { $emit: infer Emit } ? Emit : {};
7473
props?: ${fnPropsType};
7574
expose?: (exposed: T) => void;
@@ -157,11 +156,7 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
157156
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
158157
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
159158
T extends new (...args: any) => any ? __VLS_FunctionalComponent<K>
160-
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>${
161-
target === 2.7
162-
? `: T extends import('${lib}').AsyncComponent ? (props: {}, ctx?: any) => any`
163-
: ``
164-
}
159+
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
165160
: T extends (...args: any) => any ? T
166161
: __VLS_FunctionalComponent<{}>;
167162
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];

packages/language-core/lib/codegen/localTypes.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { VueCompilerOptions } from '../types';
2-
import { getSlotsPropertyName } from '../utils/shared';
32
import { endOfLine } from './utils';
43

54
export function getLocalTypesGenerator(vueCompilerOptions: VueCompilerOptions) {
@@ -35,8 +34,11 @@ type __VLS_WithDefaults<P, D> = {
3534
`
3635
type __VLS_WithSlots<T, S> = T & {
3736
new(): {
38-
${getSlotsPropertyName(vueCompilerOptions.target)}: S;
39-
${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
37+
$slots: S;${
38+
vueCompilerOptions.jsxSlots
39+
? `\n $props: ${PropsChildren.name}<S>;`
40+
: ''
41+
}
4042
}
4143
};
4244
`.trimStart(),

packages/language-core/lib/codegen/script/index.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
55
import type { Code, Sfc, VueCompilerOptions } from '../../types';
66
import { codeFeatures } from '../codeFeatures';
77
import type { TemplateCodegenContext } from '../template/context';
8-
import { endOfLine, generateSfcBlockSection, newLine } from '../utils';
8+
import { generateSfcBlockSection, newLine } from '../utils';
99
import { generateComponentSelf } from './componentSelf';
1010
import { createScriptCodegenContext, type ScriptCodegenContext } from './context';
1111
import { generateScriptSetup, generateScriptSetupImports } from './scriptSetup';
@@ -51,7 +51,7 @@ function* generateScript(
5151
yield* generateScriptSetupImports(options.sfc.scriptSetup, options.scriptSetupRanges);
5252
}
5353
if (options.sfc.script && options.scriptRanges) {
54-
const { exportDefault, classBlockEnd } = options.scriptRanges;
54+
const { exportDefault } = options.scriptRanges;
5555
const isExportRawObject = exportDefault
5656
&& options.sfc.script.content[exportDefault.expression.start] === '{';
5757
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
@@ -107,24 +107,6 @@ function* generateScript(
107107
codeFeatures.all,
108108
);
109109
}
110-
else if (classBlockEnd !== undefined) {
111-
if (options.vueCompilerOptions.skipTemplateCodegen) {
112-
yield generateSfcBlockSection(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures.all);
113-
}
114-
else {
115-
yield generateSfcBlockSection(options.sfc.script, 0, classBlockEnd, codeFeatures.all);
116-
yield `__VLS_template = () => {${newLine}`;
117-
const templateCodegenCtx = yield* generateTemplate(options, ctx);
118-
yield* generateComponentSelf(options, ctx, templateCodegenCtx);
119-
yield `}${endOfLine}`;
120-
yield generateSfcBlockSection(
121-
options.sfc.script,
122-
classBlockEnd,
123-
options.sfc.script.content.length,
124-
codeFeatures.all,
125-
);
126-
}
127-
}
128110
else {
129111
yield generateSfcBlockSection(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures.all);
130112
yield* generateScriptSectionPartiallyEnding(

packages/language-core/lib/codegen/script/scriptSetup.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,9 @@ function* generateComponentProps(
435435
yield `type __VLS_BuiltInPublicProps = ${
436436
options.vueCompilerOptions.target >= 3.4
437437
? `import('${options.vueCompilerOptions.lib}').PublicProps`
438-
: options.vueCompilerOptions.target >= 3
439-
? `import('${options.vueCompilerOptions.lib}').VNodeProps`
438+
: `import('${options.vueCompilerOptions.lib}').VNodeProps`
440439
+ ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
441440
+ ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`
442-
: `globalThis.JSX.IntrinsicAttributes`
443441
}`;
444442
yield endOfLine;
445443

packages/language-core/lib/codegen/template/element.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as CompilerDOM from '@vue/compiler-dom';
22
import { camelize, capitalize } from '@vue/shared';
33
import type { Code, VueCodeInformation } from '../../types';
4-
import { getElementTagOffsets, getSlotsPropertyName, hyphenateTag } from '../../utils/shared';
4+
import { getElementTagOffsets, hyphenateTag } from '../../utils/shared';
55
import { codeFeatures } from '../codeFeatures';
66
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
77
import { endOfLine, identifierRegex, newLine, normalizeAttributeValue } from '../utils';
@@ -132,9 +132,7 @@ export function* generateComponent(
132132
getCanonicalComponentName(node.tag)
133133
}', __VLS_LocalComponents, `;
134134
if (options.selfComponentName && possibleOriginalNames.includes(options.selfComponentName)) {
135-
yield `typeof __VLS_self & (new () => { `
136-
+ getSlotsPropertyName(options.vueCompilerOptions.target)
137-
+ `: __VLS_Slots }), `;
135+
yield `typeof __VLS_self & (new () => { $slots: __VLS_Slots }), `;
138136
}
139137
else {
140138
yield `void, `;

packages/language-core/lib/codegen/template/elementProps.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,7 @@ export function* generateElementProps(
186186
}
187187
}
188188
else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
189-
if (
190-
options.vueCompilerOptions.dataAttributes.some(pattern => isMatch(prop.name, pattern))
191-
// Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom` always adds it (#3881)
192-
|| (
193-
options.vueCompilerOptions.target < 3
194-
&& prop.name === 'persisted'
195-
&& node.tag.toLowerCase() === 'transition'
196-
)
197-
) {
189+
if (options.vueCompilerOptions.dataAttributes.some(pattern => isMatch(prop.name, pattern))) {
198190
continue;
199191
}
200192

@@ -423,5 +415,5 @@ function getModelPropName(node: CompilerDOM.ElementNode, vueCompilerOptions: Vue
423415
}
424416
}
425417

426-
return vueCompilerOptions.target < 3 ? 'value' : 'modelValue';
418+
return 'modelValue';
427419
}

packages/language-core/lib/codegen/template/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as CompilerDOM from '@vue/compiler-dom';
22
import type * as ts from 'typescript';
33
import type { Code, Sfc, VueCompilerOptions } from '../../types';
4-
import { getSlotsPropertyName } from '../../utils/shared';
54
import { codeFeatures } from '../codeFeatures';
65
import { endOfLine, newLine } from '../utils';
76
import { wrapWith } from '../utils/wrapWith';
@@ -57,9 +56,8 @@ function* generateTemplate(
5756
ctx.addLocalVariable(options.propsAssignName);
5857
}
5958

60-
const slotsPropertyName = getSlotsPropertyName(options.vueCompilerOptions.target);
6159
if (options.vueCompilerOptions.inferTemplateDollarSlots) {
62-
ctx.dollarVars.add(slotsPropertyName);
60+
ctx.dollarVars.add('$slots');
6361
}
6462
if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
6563
ctx.dollarVars.add('$attrs');
@@ -79,7 +77,7 @@ function* generateTemplate(
7977
yield* ctx.generateHoistVariables();
8078

8179
const speicalTypes = [
82-
[slotsPropertyName, yield* generateSlots(options, ctx)],
80+
['$slots', yield* generateSlots(options, ctx)],
8381
['$attrs', yield* generateInheritedAttrs(options, ctx)],
8482
['$refs', yield* generateTemplateRefs(options, ctx)],
8583
['$el', yield* generateRootEl(ctx)],

packages/language-core/lib/compilerOptions.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,7 @@ export function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTempla
293293
],
294294
dataAttributes: [],
295295
htmlAttributes: ['aria-*'],
296-
optionsWrapper: target >= 2.7
297-
? [`(await import('${lib}')).defineComponent(`, `)`]
298-
: [`(await import('${lib}')).default.extend(`, `)`],
296+
optionsWrapper: [`(await import('${lib}')).defineComponent(`, `)`],
299297
macros: {
300298
defineProps: ['defineProps'],
301299
defineSlots: ['defineSlots'],

packages/language-core/lib/languagePlugin.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as CompilerDOM from '@vue/compiler-dom';
55
import type * as ts from 'typescript';
66
import { createPlugins } from './plugins';
77
import type { VueCompilerOptions, VueLanguagePlugin, VueLanguagePluginReturn } from './types';
8-
import * as CompilerVue2 from './utils/vue2TemplateCompiler';
98
import { VueVirtualCode } from './virtualFile/vueFile';
109

1110
const fileRegistries: {
@@ -56,12 +55,7 @@ export function createVueLanguagePlugin<T>(
5655
): LanguagePlugin<T, VueVirtualCode> {
5756
const pluginContext: Parameters<VueLanguagePlugin>[0] = {
5857
modules: {
59-
'@vue/compiler-dom': vueCompilerOptions.target < 3
60-
? {
61-
...CompilerDOM,
62-
compile: CompilerVue2.compile,
63-
}
64-
: CompilerDOM,
58+
'@vue/compiler-dom': CompilerDOM,
6559
typescript: ts,
6660
},
6761
compilerOptions,

0 commit comments

Comments
 (0)