Skip to content

Commit a1855c6

Browse files
fix: compatible with TS 5.1.3 (#3277)
1 parent 35a8b15 commit a1855c6

File tree

4 files changed

+42
-75
lines changed

4 files changed

+42
-75
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"devDependencies": {
2424
"@types/node": "latest",
2525
"@volar/language-service": "1.7.4",
26-
"typescript": "~5.0.4",
26+
"typescript": "latest",
2727
"vite": "latest",
2828
"vitest": "latest"
2929
},

packages/vue-language-core/src/generators/template.ts

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -912,9 +912,11 @@ export function generate(
912912
{
913913
...capabilitiesPresets.attrReference,
914914
rename: {
915+
// @click-outside -> onClickOutside
915916
normalize(newName) {
916917
return camelize('on-' + newName);
917918
},
919+
// onClickOutside -> @click-outside
918920
apply(newName) {
919921
const hName = hyphenate(newName);
920922
if (hyphenate(newName).startsWith('on-')) {
@@ -1137,15 +1139,15 @@ export function generate(
11371139
continue;
11381140
}
11391141

1140-
const isStatic = !prop.arg || (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic);
1141-
const propName = isStatic
1142+
let camelized = false;
1143+
1144+
if (
1145+
(!prop.arg || (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)) // isStatic
11421146
&& hyphenate(attrNameText) === attrNameText
11431147
&& !vueCompilerOptions.htmlAttributes.some(pattern => minimatch(attrNameText!, pattern))
1144-
? camelize(attrNameText)
1145-
: attrNameText;
1146-
1147-
if (vueCompilerOptions.strictTemplates) {
1148-
attrNameText = propName;
1148+
) {
1149+
attrNameText = camelize(attrNameText);
1150+
camelized = true;
11491151
}
11501152

11511153
// camelize name
@@ -1168,14 +1170,14 @@ export function generate(
11681170
else if (prop.exp?.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
11691171
codes.push(
11701172
...createObjectPropertyCode([
1171-
propName,
1173+
attrNameText,
11721174
'template',
11731175
[prop.arg.loc.start.offset, prop.arg.loc.start.offset + attrNameText.length], // patch style attr,
11741176
{
11751177
...caps_attr,
11761178
rename: {
11771179
normalize: camelize,
1178-
apply: getRenameApply(attrNameText),
1180+
apply: camelized ? hyphenate : noEditApply,
11791181
},
11801182
},
11811183
], (prop.loc as any).name_2 ?? ((prop.loc as any).name_2 = {})),
@@ -1184,14 +1186,14 @@ export function generate(
11841186
else {
11851187
codes.push(
11861188
...createObjectPropertyCode([
1187-
propName,
1189+
attrNameText,
11881190
'template',
11891191
[prop.arg.loc.start.offset, prop.arg.loc.end.offset],
11901192
{
11911193
...caps_attr,
11921194
rename: {
11931195
normalize: camelize,
1194-
apply: getRenameApply(attrNameText),
1196+
apply: camelized ? hyphenate : noEditApply,
11951197
},
11961198
},
11971199
], (prop.loc as any).name_2 ?? ((prop.loc as any).name_2 = {})),
@@ -1230,41 +1232,6 @@ export function generate(
12301232
caps_diagnosticOnly,
12311233
]);
12321234
codes.push(', ');
1233-
// original name
1234-
if (prop.arg && attrNameText !== propName) {
1235-
codes.push(
1236-
...createObjectPropertyCode([
1237-
attrNameText,
1238-
'template',
1239-
[prop.arg.loc.start.offset, prop.arg.loc.end.offset],
1240-
{
1241-
...caps_attr,
1242-
rename: {
1243-
normalize: camelize,
1244-
apply: getRenameApply(attrNameText),
1245-
},
1246-
},
1247-
], (prop.loc as any).name_1 ?? ((prop.loc as any).name_1 = {}))
1248-
);
1249-
codes.push(': (');
1250-
if (prop.exp) {
1251-
codes.push(
1252-
...createInterpolationCode(
1253-
prop.exp.loc.source,
1254-
prop.exp.loc,
1255-
undefined,
1256-
undefined,
1257-
'(',
1258-
')',
1259-
),
1260-
);
1261-
}
1262-
else {
1263-
codes.push('undefined');
1264-
}
1265-
codes.push(')');
1266-
codes.push(', ');
1267-
}
12681235
}
12691236
else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
12701237

packages/vue-language-core/src/utils/directorySharedTypes.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ export function getTypesCode(vueCompilerOptions: VueCompilerOptions) {
77
return `
88
// @ts-nocheck
99
10-
type __VLS_IntrinsicElements = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.IntrinsicElements & {}, __VLS_PickNotAny<JSX.IntrinsicElements, Record<string, any>>>;
11-
type __VLS_Element = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.Element & {}, JSX.Element>;
10+
type __VLS_IntrinsicElements = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.IntrinsicElements, __VLS_PickNotAny<JSX.IntrinsicElements, Record<string, any>>>;
11+
type __VLS_Element = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.Element, JSX.Element>;
1212
1313
type __VLS_IsAny<T> = boolean extends (T extends never ? true : false) ? true : false;
14-
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
14+
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A & {}> extends true ? B : A; // & {} for https://github.com/microsoft/TypeScript/issues/54630
1515
1616
type __VLS_Prettify<T> = {
1717
[K in keyof T]: T[K];
1818
} & {};
1919
2020
type __VLS_GlobalComponents =
21-
__VLS_PickNotAny<import('vue').GlobalComponents & {}, {}>
22-
& __VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents & {}, {}>
23-
& __VLS_PickNotAny<import('@vue/runtime-dom').GlobalComponents & {}, {}>
21+
__VLS_PickNotAny<import('vue').GlobalComponents, {}>
22+
& __VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>
23+
& __VLS_PickNotAny<import('@vue/runtime-dom').GlobalComponents, {}>
2424
& Pick<typeof import('${vueCompilerOptions.lib}'),
2525
'Transition'
2626
| 'TransitionGroup'

pnpm-lock.yaml

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)