Skip to content

Commit d5ef828

Browse files
committed
Merge branch 'master' into pr/5933
2 parents f5aa199 + e76cf2e commit d5ef828

File tree

16 files changed

+448
-390
lines changed

16 files changed

+448
-390
lines changed

extensions/vscode/languages/vue-language-configuration.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"onEnterRules": [
4545
{
4646
"beforeText": {
47-
"pattern": "<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr))([_:\\w][_:\\w-.\\d]*)(?:(?:[^'\"/>]|\"[^\"]*\"|'[^']*')*?(?!\\/)>)[^<]*$",
47+
"pattern": "<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr|script|style))([_:\\w][_:\\w-.\\d]*)(?:(?:[^'\"/>]|\"[^\"]*\"|'[^']*')*?(?!\\/)>)[^<]*$",
4848
"flags": "i"
4949
},
5050
"afterText": { "pattern": "^<\\/([_:\\w][_:\\w-.\\d]*)\\s*>", "flags": "i" },
@@ -54,7 +54,7 @@
5454
},
5555
{
5656
"beforeText": {
57-
"pattern": "<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr))([_:\\w][_:\\w-.\\d]*)(?:(?:[^'\"/>]|\"[^\"]*\"|'[^']*')*?(?!\\/)>)[^<]*$",
57+
"pattern": "<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr|script|style))([_:\\w][_:\\w-.\\d]*)(?:(?:[^'\"/>]|\"[^\"]*\"|'[^']*')*?(?!\\/)>)[^<]*$",
5858
"flags": "i"
5959
},
6060
"action": {
@@ -63,7 +63,7 @@
6363
}
6464
],
6565
"indentationRules": {
66-
"increaseIndentPattern": "<(?!\\?|(?:area|base|br|col|frame|hr|html|img|input|keygen|link|menuitem|meta|param|source|track|wbr)\\b|[^>]*\\/>)([-_\\.A-Za-z0-9]+)(?=\\s|>)\\b[^>]*>(?!.*<\\/\\1>)|<!--(?!.*-->)|\\{[^}\"']*$",
66+
"increaseIndentPattern": "<(?!\\?|(?:area|base|br|col|frame|hr|html|img|input|keygen|link|menuitem|meta|param|source|track|wbr|script|style)\\b|[^>]*\\/>)([-_\\.A-Za-z0-9]+)(?=\\s|>)\\b[^>]*>(?!.*<\\/\\1>)|<!--(?!.*-->)|\\{[^}\"']*$",
6767
"decreaseIndentPattern": "^\\s*(<\\/(?!html)[-_\\.A-Za-z0-9]+\\b[^>]*>|-->|\\})"
6868
}
6969
}

extensions/vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@
491491
"@vue/typescript-plugin": "workspace:*",
492492
"laplacenoma": "latest",
493493
"reactive-vscode": "^0.4.1",
494-
"rolldown": "1.0.0-beta.56",
494+
"rolldown": "1.0.0-beta.60",
495495
"vscode-ext-gen": "latest",
496496
"vscode-tmlanguage-snapshot": "latest"
497497
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"lint:fix": "npm run lint -- --fix"
1212
},
1313
"devDependencies": {
14-
"@tsslint/cli": "3.0.0-alpha.0",
15-
"@tsslint/config": "3.0.0-alpha.0",
16-
"@tsslint/eslint": "3.0.0-alpha.0",
14+
"@tsslint/cli": "3.0.0",
15+
"@tsslint/compat-eslint": "3.0.0",
16+
"@tsslint/config": "3.0.0",
1717
"@typescript-eslint/eslint-plugin": "latest",
1818
"@typescript/native-preview": "latest",
1919
"dprint": "latest",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ function* generateModels(
472472
yield* codes;
473473
}
474474
yield `}${endOfLine}`;
475-
yield `const ${names.modelEmit} = defineEmits<${names.ModelEmit}>()${endOfLine}`;
475+
476+
// avoid `defineModel<...>()` to prevent JS AST issues
477+
yield `let ${names.modelEmit}!: __VLS_ShortEmits<${names.ModelEmit}>${endOfLine}`;
476478
}
477479

478480
function* generateModelProp(

packages/language-core/lib/compilerOptions.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,27 @@ export class CompilerOptionsResolver {
152152
}
153153
break;
154154
case 'plugins':
155-
this.plugins = (options.plugins ?? [])
156-
.flatMap<VueLanguagePlugin>((pluginPath: string) => {
157-
try {
158-
const resolve = (require as NodeJS.Require | undefined)?.resolve;
159-
const resolvedPath = resolve?.(pluginPath, { paths: [rootDir] });
160-
if (resolvedPath) {
161-
const plugin = require(resolvedPath);
162-
plugin.__moduleName = pluginPath;
163-
return plugin;
164-
}
165-
else {
166-
console.warn('[Vue] Load plugin failed:', pluginPath);
155+
for (let raw of options.plugins ?? []) {
156+
raw = typeof raw === 'string' ? { name: raw } : raw;
157+
try {
158+
const resolve = (require as NodeJS.Require | undefined)?.resolve;
159+
const resolvedPath = resolve?.(raw.name, { paths: [rootDir] });
160+
if (resolvedPath) {
161+
const plugin = require(resolvedPath);
162+
const plugins = Array.isArray(plugin) ? plugin : [plugin];
163+
for (const plugin of plugins) {
164+
plugin.__moduleConfig = raw;
165+
this.plugins.push(plugin);
167166
}
168167
}
169-
catch (error) {
170-
console.warn('[Vue] Resolve plugin path failed:', pluginPath, error);
168+
else {
169+
console.warn('[Vue] Load plugin failed:', raw.name);
171170
}
172-
return [];
173-
});
171+
}
172+
catch (error) {
173+
console.warn('[Vue] Resolve plugin path failed:', raw.name, error);
174+
}
175+
}
174176
break;
175177
default:
176178
// @ts-expect-error

packages/language-core/lib/plugins.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ export function createPlugins(pluginContext: Parameters<VueLanguagePlugin>[0]) {
3838
const pluginInstances = plugins
3939
.flatMap(plugin => {
4040
try {
41-
const instance = plugin(pluginContext);
42-
const moduleName = (plugin as any).__moduleName;
41+
const moduleConfig = (plugin as any).__moduleConfig ?? {};
42+
const instance = plugin({ ...pluginContext, ...moduleConfig });
4343
if (Array.isArray(instance)) {
4444
for (let i = 0; i < instance.length; i++) {
45-
instance[i]!.name ??= `${moduleName} (${i})`;
45+
instance[i]!.name ??= `${moduleConfig.name} (${i})`;
4646
}
4747
}
4848
else {
49-
instance.name ??= moduleName;
49+
instance.name ??= moduleConfig.name;
5050
}
5151
return instance;
5252
}

packages/language-core/lib/types.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ export { VueEmbeddedCode };
1212
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
1313
strictTemplates?: boolean;
1414
target?: 'auto' | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
15-
plugins?: string[];
15+
plugins?: RawPlugin[];
1616
};
1717

18+
export type RawPlugin =
19+
| string
20+
| Record<string, any> & {
21+
name: string;
22+
};
23+
1824
export interface VueCodeInformation extends CodeInformation {
1925
__importCompletion?: boolean;
2026
__combineToken?: symbol;
@@ -108,14 +114,16 @@ export interface VueLanguagePluginReturn {
108114
resolveEmbeddedCode?(fileName: string, sfc: Sfc, embeddedFile: VueEmbeddedCode): void;
109115
}
110116

111-
export type VueLanguagePlugin = (ctx: {
112-
modules: {
113-
typescript: typeof ts;
114-
'@vue/compiler-dom': typeof CompilerDOM;
115-
};
116-
compilerOptions: ts.CompilerOptions;
117-
vueCompilerOptions: VueCompilerOptions;
118-
}) => VueLanguagePluginReturn | VueLanguagePluginReturn[];
117+
export type VueLanguagePlugin = (
118+
ctx: Record<string, any> & {
119+
modules: {
120+
typescript: typeof ts;
121+
'@vue/compiler-dom': typeof CompilerDOM;
122+
};
123+
compilerOptions: ts.CompilerOptions;
124+
vueCompilerOptions: VueCompilerOptions;
125+
},
126+
) => VueLanguagePluginReturn | VueLanguagePluginReturn[];
119127

120128
export interface SfcBlock {
121129
name: string;

packages/language-core/types/template-helpers.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ declare global {
9393
) => any;
9494
}
9595
>;
96+
type __VLS_ShortEmits<E extends Record<string, any[]>> = __VLS_UnionToIntersection<
97+
{ [K in keyof E]: (event: K, ...args: E[K]) => void }[keyof E]
98+
>;
9699
type __VLS_ShortEmitsToObject<E> = E extends Record<string, any[]> ? { [K in keyof E]: (...args: E[K]) => any }
97100
: E;
98101
type __VLS_ResolveEmits<

packages/tsc/tests/__snapshots__/dts.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ exports[`Input: generic/component.vue, Output: generic/component.vue.d.ts 1`] =
186186
foo: number;
187187
}) => any;
188188
};
189-
emit: ((e: "bar", data: number) => void) & ((evt: "update:title", value: string) => void);
189+
emit: ((e: "bar", data: number) => void) & ((event: "update:title", value: string) => void);
190190
}>) => import("vue").VNode & {
191191
__ctx?: Awaited<typeof __VLS_setup>;
192192
};
@@ -221,7 +221,7 @@ exports[`Input: generic/custom-extension-component.cext, Output: generic/custom-
221221
foo: number;
222222
}) => any;
223223
};
224-
emit: ((e: "bar", data: number) => void) & ((evt: "update:title", value: string) => void);
224+
emit: ((e: "bar", data: number) => void) & ((event: "update:title", value: string) => void);
225225
}>) => import("vue").VNode & {
226226
__ctx?: Awaited<typeof __VLS_setup>;
227227
};

packages/typescript-plugin/lib/common.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function preprocessLanguageService(
3030

3131
languageService.getQuickInfoAtPosition = (fileName, position, ...rests) => {
3232
const result = getQuickInfoAtPosition(fileName, position, ...rests);
33-
if (!result) {
33+
if (!result || result.tags?.length) {
3434
return result;
3535
}
3636
const language = getLanguage();
@@ -69,10 +69,7 @@ export function preprocessLanguageService(
6969
);
7070
if (codegen?.getSetupExposed().has(variableName)) {
7171
const extraInfo = getQuickInfoAtPosition(fileName, generateRange2[0], ...rests);
72-
if (extraInfo) {
73-
result.tags ??= [];
74-
result.tags.push(...extraInfo.tags ?? []);
75-
}
72+
result.tags = extraInfo?.tags;
7673
}
7774
}
7875
}

0 commit comments

Comments
 (0)