@vue/language-core 3.0.1 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEv
14
14
  }
15
15
  function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
16
16
  const fnPropsType = `(T extends { $props: infer Props } ? Props : {})${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
17
- let text = ``;
17
+ let text = `// @ts-nocheck\nexport {};\n`;
18
18
  if (target < 3.5) {
19
19
  text += `
20
20
  ; declare module '${lib}' {
@@ -68,14 +68,6 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
68
68
  expose?: (exposed: T) => void,
69
69
  }
70
70
  };
71
- type __VLS_NormalizeSlotReturns<S, R = NonNullable<S> extends (...args: any) => infer K ? K : any> = R extends any[] ? {
72
- [K in keyof R]: R[K] extends infer V
73
- ? V extends Element ? V
74
- : V extends new (...args: any) => infer R ? ReturnType<__VLS_FunctionalComponent<R>>
75
- : V extends (...args: any) => infer R ? R
76
- : any
77
- : never
78
- } : R;
79
71
  type __VLS_IsFunction<T, K> = K extends keyof T
80
72
  ? __VLS_IsAny<T[K]> extends false
81
73
  ? unknown extends T[K]
@@ -143,7 +135,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
143
135
  index: number,
144
136
  ][];
145
137
  function __VLS_getSlotParameters<S, D extends S>(slot: S, decl?: D):
146
- __VLS_PickNotAny<NonNullable<D>, (...args: any) => any> extends (...args: infer P) => any ? P : any[];
138
+ D extends (...args: infer P) => any ? P : any[];
147
139
  function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective
148
140
  ? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
149
141
  : T extends (...args: any) => any
@@ -6,6 +6,7 @@ exports.generateEmitsOption = generateEmitsOption;
6
6
  exports.generatePropsOption = generatePropsOption;
7
7
  const codeFeatures_1 = require("../codeFeatures");
8
8
  const utils_1 = require("../utils");
9
+ const merge_1 = require("../utils/merge");
9
10
  function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
10
11
  if (options.sfc.script && options.scriptRanges?.exportDefault
11
12
  && options.scriptRanges.exportDefault.expression.start !== options.scriptRanges.exportDefault.args.start) {
@@ -17,14 +18,21 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
17
18
  yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
18
19
  }
19
20
  yield `setup() {${utils_1.newLine}`;
20
- yield `return {${utils_1.newLine}`;
21
+ const returns = [];
21
22
  if (ctx.bypassDefineComponent) {
23
+ yield* `const __VLS_returns = {${utils_1.newLine}`;
22
24
  yield* generateComponentSetupReturns(scriptSetupRanges);
25
+ yield `}${utils_1.endOfLine}`;
26
+ returns.push(`typeof __VLS_returns`);
23
27
  }
24
28
  if (scriptSetupRanges.defineExpose) {
25
- yield `...__VLS_exposed,${utils_1.newLine}`;
29
+ returns.push(`typeof __VLS_exposed`);
30
+ }
31
+ if (returns.length) {
32
+ yield `return {} as `;
33
+ yield* (0, merge_1.generateIntersectMerge)(returns);
34
+ yield utils_1.endOfLine;
26
35
  }
27
- yield `}${utils_1.endOfLine}`;
28
36
  yield `},${utils_1.newLine}`;
29
37
  if (!ctx.bypassDefineComponent) {
30
38
  const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
@@ -60,135 +68,79 @@ function* generateComponentSetupReturns(scriptSetupRanges) {
60
68
  }
61
69
  }
62
70
  function* generateEmitsOption(options, scriptSetupRanges) {
63
- const codes = [];
71
+ const optionCodes = [];
72
+ const typeOptionCodes = [];
64
73
  if (scriptSetupRanges.defineModel.length) {
65
- codes.push({
66
- optionExp: `{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`,
67
- typeOptionType: `__VLS_ModelEmit`,
68
- });
74
+ optionCodes.push(`{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`);
75
+ typeOptionCodes.push(`__VLS_ModelEmit`);
69
76
  }
70
77
  if (scriptSetupRanges.defineEmits) {
71
78
  const { name, typeArg, hasUnionTypeArg } = scriptSetupRanges.defineEmits;
72
- codes.push({
73
- optionExp: `{} as __VLS_NormalizeEmits<typeof ${name ?? '__VLS_emit'}>`,
74
- typeOptionType: typeArg && !hasUnionTypeArg
75
- ? `__VLS_Emit`
76
- : undefined,
77
- });
78
- }
79
- if (options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionType)) {
80
- if (codes.length === 1) {
81
- yield `__typeEmits: {} as `;
82
- yield codes[0].typeOptionType;
83
- yield `,${utils_1.newLine}`;
79
+ optionCodes.push(`{} as __VLS_NormalizeEmits<typeof ${name ?? '__VLS_emit'}>`);
80
+ if (typeArg && !hasUnionTypeArg) {
81
+ typeOptionCodes.push(`__VLS_Emit`);
84
82
  }
85
- else if (codes.length >= 2) {
86
- yield `__typeEmits: {} as `;
87
- yield codes[0].typeOptionType;
88
- for (let i = 1; i < codes.length; i++) {
89
- yield ` & `;
90
- yield codes[i].typeOptionType;
91
- }
92
- yield `,${utils_1.newLine}`;
83
+ else {
84
+ typeOptionCodes.length = 0;
93
85
  }
94
86
  }
95
- else if (codes.every(code => code.optionExp)) {
96
- if (codes.length === 1) {
97
- yield `emits: `;
98
- yield codes[0].optionExp;
99
- yield `,${utils_1.newLine}`;
100
- }
101
- else if (codes.length >= 2) {
102
- yield `emits: {${utils_1.newLine}`;
103
- for (const code of codes) {
104
- yield `...`;
105
- yield code.optionExp;
106
- yield `,${utils_1.newLine}`;
107
- }
108
- yield `},${utils_1.newLine}`;
109
- }
87
+ if (options.vueCompilerOptions.target >= 3.5 && typeOptionCodes.length) {
88
+ yield `__typeEmits: {} as `;
89
+ yield* (0, merge_1.generateIntersectMerge)(typeOptionCodes);
90
+ yield `,${utils_1.newLine}`;
91
+ }
92
+ else if (optionCodes.length) {
93
+ yield `emits: `;
94
+ yield* (0, merge_1.generateSpreadMerge)(optionCodes);
95
+ yield `,${utils_1.newLine}`;
110
96
  }
111
97
  }
112
98
  function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption, inheritAttrs) {
113
- const codes = [];
114
- if (ctx.generatedPropsType) {
115
- if (options.vueCompilerOptions.target >= 3.6) {
116
- codes.push({
117
- optionExp: '{}',
118
- typeOptionExp: `{} as __VLS_PublicProps`,
119
- });
120
- }
121
- else {
122
- codes.push({
123
- optionExp: [
124
- `{} as `,
125
- scriptSetupRanges.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
126
- `${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`,
127
- scriptSetupRanges.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
128
- ].join(''),
129
- typeOptionExp: `{} as __VLS_PublicProps`,
130
- });
131
- }
132
- }
133
- if (scriptSetupRanges.defineProps?.arg) {
134
- const { arg } = scriptSetupRanges.defineProps;
135
- codes.push({
136
- optionExp: (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation),
137
- typeOptionExp: undefined,
138
- });
139
- }
99
+ const getOptionCodes = [];
100
+ const typeOptionCodes = [];
140
101
  if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
141
102
  let attrsType = `Partial<__VLS_InheritedAttrs>`;
142
103
  if (hasEmitsOption) {
143
104
  attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
144
105
  }
145
- const propsType = `__VLS_PickNotAny<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
146
- const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`;
147
- codes.unshift({
148
- optionExp: codes.length
149
- ? `{} as ${optionType}`
150
- // workaround for https://github.com/vuejs/core/pull/7419
151
- : `{} as keyof ${propsType} extends never ? never: ${optionType}`,
152
- typeOptionExp: `{} as ${attrsType}`,
106
+ getOptionCodes.push(() => {
107
+ const propsType = `__VLS_PickNotAny<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
108
+ const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`;
109
+ return `{} as ${optionType}`;
153
110
  });
111
+ typeOptionCodes.push(`{} as ${attrsType}`);
112
+ }
113
+ if (ctx.generatedPropsType) {
114
+ if (options.vueCompilerOptions.target < 3.6) {
115
+ getOptionCodes.push(() => {
116
+ const propsType = `${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`;
117
+ return `{} as ` + (scriptSetupRanges.withDefaults?.arg
118
+ ? `${ctx.localTypes.WithDefaults}<${propsType}, typeof __VLS_withDefaultsArg>`
119
+ : propsType);
120
+ });
121
+ }
122
+ typeOptionCodes.push(`{} as __VLS_PublicProps`);
154
123
  }
155
- const useTypeOption = options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionExp);
156
- const useOption = !useTypeOption || scriptSetupRanges.withDefaults;
124
+ if (scriptSetupRanges.defineProps?.arg) {
125
+ const { arg } = scriptSetupRanges.defineProps;
126
+ getOptionCodes.push(() => (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation));
127
+ typeOptionCodes.length = 0;
128
+ }
129
+ const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionCodes.length;
130
+ const useOption = (!useTypeOption || scriptSetupRanges.withDefaults) && getOptionCodes.length;
157
131
  if (useTypeOption) {
158
132
  if (options.vueCompilerOptions.target >= 3.6
159
133
  && scriptSetupRanges.withDefaults?.arg) {
160
134
  yield `__defaults: __VLS_withDefaultsArg,${utils_1.newLine}`;
161
135
  }
162
- if (codes.length === 1) {
163
- yield `__typeProps: `;
164
- yield codes[0].typeOptionExp;
165
- yield `,${utils_1.newLine}`;
166
- }
167
- else if (codes.length >= 2) {
168
- yield `__typeProps: {${utils_1.newLine}`;
169
- for (const { typeOptionExp } of codes) {
170
- yield `...`;
171
- yield typeOptionExp;
172
- yield `,${utils_1.newLine}`;
173
- }
174
- yield `},${utils_1.newLine}`;
175
- }
136
+ yield `__typeProps: `;
137
+ yield* (0, merge_1.generateSpreadMerge)(typeOptionCodes);
138
+ yield `,${utils_1.newLine}`;
176
139
  }
177
140
  if (useOption) {
178
- if (codes.length === 1) {
179
- yield `props: `;
180
- yield codes[0].optionExp;
181
- yield `,${utils_1.newLine}`;
182
- }
183
- else if (codes.length >= 2) {
184
- yield `props: {${utils_1.newLine}`;
185
- for (const { optionExp } of codes) {
186
- yield `...`;
187
- yield optionExp;
188
- yield `,${utils_1.newLine}`;
189
- }
190
- yield `},${utils_1.newLine}`;
191
- }
141
+ yield `props: `;
142
+ yield* (0, merge_1.generateSpreadMerge)(getOptionCodes.map(fn => fn()));
143
+ yield `,${utils_1.newLine}`;
192
144
  }
193
145
  }
194
146
  //# sourceMappingURL=component.js.map
@@ -18,7 +18,6 @@ export interface ScriptCodegenOptions {
18
18
  } | undefined;
19
19
  destructuredPropNames: Set<string>;
20
20
  templateRefNames: Set<string>;
21
- appendGlobalTypes: boolean;
22
21
  }
23
22
  export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
24
23
  export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
@@ -4,7 +4,6 @@ exports.generateScript = generateScript;
4
4
  exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
5
5
  const path = require("path-browserify");
6
6
  const codeFeatures_1 = require("../codeFeatures");
7
- const globalTypes_1 = require("../globalTypes");
8
7
  const utils_1 = require("../utils");
9
8
  const componentSelf_1 = require("./componentSelf");
10
9
  const context_1 = require("./context");
@@ -13,22 +12,7 @@ const src_1 = require("./src");
13
12
  const template_1 = require("./template");
14
13
  function* generateScript(options) {
15
14
  const ctx = (0, context_1.createScriptCodegenContext)(options);
16
- if (options.vueCompilerOptions.__setupedGlobalTypes) {
17
- const globalTypes = options.vueCompilerOptions.__setupedGlobalTypes;
18
- if (typeof globalTypes === 'object') {
19
- let relativePath = path.relative(path.dirname(options.fileName), globalTypes.absolutePath);
20
- if (relativePath !== globalTypes.absolutePath && !relativePath.startsWith('./') && !relativePath.startsWith('../')) {
21
- relativePath = './' + relativePath;
22
- }
23
- yield `/// <reference types="${relativePath}" />${utils_1.newLine}`;
24
- }
25
- else {
26
- yield `/// <reference types=".vue-global-types/${(0, globalTypes_1.getGlobalTypesFileName)(options.vueCompilerOptions)}" />${utils_1.newLine}`;
27
- }
28
- }
29
- else {
30
- yield `/// <reference path="./__VLS_fake.d.ts" />`;
31
- }
15
+ yield* generateGlobalTypesPath(options);
32
16
  if (options.sfc.script?.src) {
33
17
  yield* (0, src_1.generateSrc)(options.sfc.script.src);
34
18
  }
@@ -106,14 +90,29 @@ function* generateScript(options) {
106
90
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
107
91
  }
108
92
  yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
109
- if (options.appendGlobalTypes) {
110
- yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions);
111
- }
112
93
  if (options.sfc.scriptSetup) {
113
94
  yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, codeFeatures_1.codeFeatures.verification];
114
95
  }
115
96
  return ctx;
116
97
  }
98
+ function* generateGlobalTypesPath(options) {
99
+ const globalTypesPath = options.vueCompilerOptions.globalTypesPath(options.fileName);
100
+ if (!globalTypesPath) {
101
+ yield `/* placeholder */${utils_1.newLine}`;
102
+ }
103
+ else if (path.isAbsolute(globalTypesPath)) {
104
+ let relativePath = path.relative(path.dirname(options.fileName), globalTypesPath);
105
+ if (relativePath !== globalTypesPath
106
+ && !relativePath.startsWith('./')
107
+ && !relativePath.startsWith('../')) {
108
+ relativePath = './' + relativePath;
109
+ }
110
+ yield `/// <reference types="${relativePath}" />${utils_1.newLine}`;
111
+ }
112
+ else {
113
+ yield `/// <reference types="${globalTypesPath}" />${utils_1.newLine}`;
114
+ }
115
+ }
117
116
  function* generateScriptSectionPartiallyEnding(source, end, mark, delimiter = 'debugger') {
118
117
  yield delimiter;
119
118
  yield ['', source, end, codeFeatures_1.codeFeatures.verification];
@@ -11,6 +11,7 @@ const context_1 = require("../template/context");
11
11
  const interpolation_1 = require("../template/interpolation");
12
12
  const styleScopedClasses_1 = require("../template/styleScopedClasses");
13
13
  const utils_1 = require("../utils");
14
+ const merge_1 = require("../utils/merge");
14
15
  function* generateTemplate(options, ctx) {
15
16
  ctx.generatedTemplate = true;
16
17
  const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)({
@@ -33,19 +34,8 @@ function* generateTemplateCtx(options) {
33
34
  exps.push(`{} as __VLS_StyleModules`);
34
35
  }
35
36
  yield `const __VLS_ctx = `;
36
- if (exps.length === 1) {
37
- yield exps[0];
38
- yield `${utils_1.endOfLine}`;
39
- }
40
- else {
41
- yield `{${utils_1.newLine}`;
42
- for (const exp of exps) {
43
- yield `...`;
44
- yield exp;
45
- yield `,${utils_1.newLine}`;
46
- }
47
- yield `}${utils_1.endOfLine}`;
48
- }
37
+ yield* (0, merge_1.generateSpreadMerge)(exps);
38
+ yield utils_1.endOfLine;
49
39
  }
50
40
  function* generateTemplateElements() {
51
41
  yield `let __VLS_elements!: __VLS_IntrinsicElements${utils_1.endOfLine}`;
@@ -65,10 +55,7 @@ function* generateTemplateComponents(options) {
65
55
  types.push(`typeof __VLS_componentsOption`);
66
56
  }
67
57
  yield `type __VLS_LocalComponents =`;
68
- for (const type of types) {
69
- yield ` & `;
70
- yield type;
71
- }
58
+ yield* (0, merge_1.generateIntersectMerge)(types);
72
59
  yield utils_1.endOfLine;
73
60
  yield `let __VLS_components!: __VLS_LocalComponents & __VLS_GlobalComponents${utils_1.endOfLine}`;
74
61
  }
@@ -87,10 +74,7 @@ function* generateTemplateDirectives(options) {
87
74
  types.push(`__VLS_ResolveDirectives<typeof __VLS_directivesOption>`);
88
75
  }
89
76
  yield `type __VLS_LocalDirectives =`;
90
- for (const type of types) {
91
- yield ` & `;
92
- yield type;
93
- }
77
+ yield* (0, merge_1.generateIntersectMerge)(types);
94
78
  yield utils_1.endOfLine;
95
79
  yield `let __VLS_directives!: __VLS_LocalDirectives & __VLS_GlobalDirectives${utils_1.endOfLine}`;
96
80
  }
@@ -163,7 +163,6 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
163
163
  }[]>;
164
164
  currentComponent: {
165
165
  ctxVar: string;
166
- childTypes: string[];
167
166
  used: boolean;
168
167
  } | undefined;
169
168
  singleRootElTypes: string[];
@@ -35,10 +35,8 @@ function* generateComponent(options, ctx, node) {
35
35
  const componentVNodeVar = ctx.getInternalVariable();
36
36
  const componentCtxVar = ctx.getInternalVariable();
37
37
  const isComponentTag = node.tag.toLowerCase() === 'component';
38
- ctx.currentComponent?.childTypes.push(`typeof ${componentVNodeVar}`);
39
38
  ctx.currentComponent = {
40
39
  ctxVar: componentCtxVar,
41
- childTypes: [],
42
40
  used: false,
43
41
  };
44
42
  let props = node.props;
@@ -98,7 +96,7 @@ function* generateComponent(options, ctx, node) {
98
96
  }
99
97
  yield `)${utils_1.endOfLine}`;
100
98
  }
101
- else if (!isComponentTag) {
99
+ else {
102
100
  yield `const ${componentOriginalVar} = ({} as __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `;
103
101
  if (options.selfComponentName && possibleOriginalNames.includes(options.selfComponentName)) {
104
102
  yield `typeof __VLS_self & (new () => { `
@@ -137,9 +135,6 @@ function* generateComponent(options, ctx, node) {
137
135
  yield `${utils_1.endOfLine}`;
138
136
  }
139
137
  }
140
- else {
141
- yield `const ${componentOriginalVar} = {} as any${utils_1.endOfLine}`;
142
- }
143
138
  yield `// @ts-ignore${utils_1.newLine}`;
144
139
  yield `const ${componentFunctionalVar} = __VLS_asFunctionalComponent(${componentOriginalVar}, new ${componentOriginalVar}({${utils_1.newLine}`;
145
140
  yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, false);
@@ -199,7 +194,6 @@ function* generateElement(options, ctx, node) {
199
194
  ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
200
195
  : undefined;
201
196
  const failedPropExps = [];
202
- ctx.currentComponent?.childTypes.push(`__VLS_NativeElements['${node.tag}']`);
203
197
  yield `__VLS_asFunctionalElement(__VLS_elements`;
204
198
  yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
205
199
  if (endTagOffset !== undefined) {
@@ -4,8 +4,8 @@ exports.generateElementProps = generateElementProps;
4
4
  exports.generatePropExp = generatePropExp;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
6
  const shared_1 = require("@vue/shared");
7
- const minimatch_1 = require("minimatch");
8
7
  const muggle_string_1 = require("muggle-string");
8
+ const picomatch_1 = require("picomatch");
9
9
  const shared_2 = require("../../utils/shared");
10
10
  const codeFeatures_1 = require("../codeFeatures");
11
11
  const inlayHints_1 = require("../inlayHints");
@@ -65,7 +65,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
65
65
  propName = getModelPropName(node, options.vueCompilerOptions);
66
66
  }
67
67
  if (propName === undefined
68
- || options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))) {
68
+ || options.vueCompilerOptions.dataAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern))) {
69
69
  if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
70
70
  failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
71
71
  }
@@ -111,7 +111,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
111
111
  }
112
112
  }
113
113
  else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
114
- if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))
114
+ if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, picomatch_1.isMatch)(prop.name, pattern))
115
115
  // Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom` always adds it (#3881)
116
116
  || (options.vueCompilerOptions.target < 3
117
117
  && prop.name === 'persisted'
@@ -218,7 +218,7 @@ function getShouldCamelize(options, prop, propName) {
218
218
  || !prop.arg
219
219
  || (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))
220
220
  && (0, shared_2.hyphenateAttr)(propName) === propName
221
- && !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
221
+ && !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern));
222
222
  }
223
223
  function getPropsCodeInfo(ctx, strictPropsCheck) {
224
224
  return ctx.resolveCodeFeatures({
@@ -58,10 +58,10 @@ function* generateSlots(options, ctx) {
58
58
  for (const slot of ctx.slots) {
59
59
  yield `${utils_1.newLine}& { `;
60
60
  if (slot.name && slot.offset !== undefined) {
61
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.withoutHighlightAndCompletion);
61
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.navigation);
62
62
  }
63
63
  else {
64
- yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
64
+ yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.navigation, `default`);
65
65
  }
66
66
  yield `?: (props: typeof ${slot.propsVar}) => any }`;
67
67
  }
@@ -70,7 +70,7 @@ function* forEachInterpolationSegment(ts, inlineTsAsts, destructuredPropNames, t
70
70
  });
71
71
  }
72
72
  };
73
- ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb, ctx));
73
+ ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb, ctx, [], true));
74
74
  }
75
75
  ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
76
76
  if (ctxVars.length) {
@@ -122,7 +122,7 @@ function* generateVar(templateRefNames, ctx, code, offset, curVar) {
122
122
  yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
123
123
  }
124
124
  }
125
- function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true) {
125
+ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars, isRoot = false) {
126
126
  if (ts.isIdentifier(node)) {
127
127
  cb(node, false);
128
128
  }
@@ -130,51 +130,55 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
130
130
  cb(node.name, true);
131
131
  }
132
132
  else if (ts.isPropertyAccessExpression(node)) {
133
- walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars, false);
133
+ walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars);
134
134
  }
135
135
  else if (ts.isVariableDeclaration(node)) {
136
- (0, utils_1.collectVars)(ts, node.name, ast, blockVars);
137
- for (const varName of blockVars) {
138
- ctx.addLocalVariable(varName);
136
+ const bindingNames = (0, utils_1.collectBindingNames)(ts, node.name, ast);
137
+ for (const name of bindingNames) {
138
+ ctx.addLocalVariable(name);
139
+ blockVars.push(name);
139
140
  }
140
141
  if (node.initializer) {
141
- walkIdentifiers(ts, node.initializer, ast, cb, ctx, blockVars, false);
142
+ walkIdentifiers(ts, node.initializer, ast, cb, ctx, blockVars);
142
143
  }
143
144
  }
144
145
  else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
145
- processFunction(ts, node, ast, cb, ctx);
146
+ walkIdentifiersInFunction(ts, node, ast, cb, ctx);
146
147
  }
147
148
  else if (ts.isObjectLiteralExpression(node)) {
148
149
  for (const prop of node.properties) {
149
150
  if (ts.isPropertyAssignment(prop)) {
150
151
  // fix https://github.com/vuejs/language-tools/issues/1176
151
152
  if (ts.isComputedPropertyName(prop.name)) {
152
- walkIdentifiers(ts, prop.name.expression, ast, cb, ctx, blockVars, false);
153
+ walkIdentifiers(ts, prop.name.expression, ast, cb, ctx, blockVars);
153
154
  }
154
- walkIdentifiers(ts, prop.initializer, ast, cb, ctx, blockVars, false);
155
- } // fix https://github.com/vuejs/language-tools/issues/1156
155
+ walkIdentifiers(ts, prop.initializer, ast, cb, ctx, blockVars);
156
+ }
157
+ // fix https://github.com/vuejs/language-tools/issues/1156
156
158
  else if (ts.isShorthandPropertyAssignment(prop)) {
157
- walkIdentifiers(ts, prop, ast, cb, ctx, blockVars, false);
158
- } // fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
159
+ walkIdentifiers(ts, prop, ast, cb, ctx, blockVars);
160
+ }
161
+ // fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
159
162
  else if (ts.isSpreadAssignment(prop)) {
160
163
  // TODO: cannot report "Spread types may only be created from object types.ts(2698)"
161
- walkIdentifiers(ts, prop.expression, ast, cb, ctx, blockVars, false);
162
- } // fix https://github.com/vuejs/language-tools/issues/4604
164
+ walkIdentifiers(ts, prop.expression, ast, cb, ctx, blockVars);
165
+ }
166
+ // fix https://github.com/vuejs/language-tools/issues/4604
163
167
  else if (ts.isFunctionLike(prop) && prop.body) {
164
- processFunction(ts, prop, ast, cb, ctx);
168
+ walkIdentifiersInFunction(ts, prop, ast, cb, ctx);
165
169
  }
166
170
  }
167
171
  }
168
- else if (ts.isTypeReferenceNode(node)) {
169
- // fix https://github.com/vuejs/language-tools/issues/1422
170
- ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
172
+ // fix https://github.com/vuejs/language-tools/issues/1422
173
+ else if (ts.isTypeNode(node)) {
174
+ walkIdentifiersInTypeNode(ts, node, cb);
171
175
  }
172
176
  else {
173
177
  const _blockVars = blockVars;
174
178
  if (ts.isBlock(node)) {
175
179
  blockVars = [];
176
180
  }
177
- ts.forEachChild(node, node => walkIdentifiers(ts, node, ast, cb, ctx, blockVars, false));
181
+ ts.forEachChild(node, node => walkIdentifiers(ts, node, ast, cb, ctx, blockVars));
178
182
  if (ts.isBlock(node)) {
179
183
  for (const varName of blockVars) {
180
184
  ctx.removeLocalVariable(varName);
@@ -188,30 +192,34 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
188
192
  }
189
193
  }
190
194
  }
191
- function processFunction(ts, node, ast, cb, ctx) {
195
+ function walkIdentifiersInFunction(ts, node, ast, cb, ctx) {
192
196
  const functionArgs = [];
193
197
  for (const param of node.parameters) {
194
- (0, utils_1.collectVars)(ts, param.name, ast, functionArgs);
198
+ functionArgs.push(...(0, utils_1.collectBindingNames)(ts, param.name, ast));
195
199
  if (param.type) {
196
- walkIdentifiers(ts, param.type, ast, cb, ctx);
200
+ walkIdentifiersInTypeNode(ts, param.type, cb);
197
201
  }
198
202
  }
199
203
  for (const varName of functionArgs) {
200
204
  ctx.addLocalVariable(varName);
201
205
  }
202
206
  if (node.body) {
203
- walkIdentifiers(ts, node.body, ast, cb, ctx);
207
+ walkIdentifiers(ts, node.body, ast, cb, ctx, [], true);
204
208
  }
205
209
  for (const varName of functionArgs) {
206
210
  ctx.removeLocalVariable(varName);
207
211
  }
208
212
  }
209
- function walkIdentifiersInTypeReference(ts, node, cb) {
210
- if (ts.isTypeQueryNode(node) && ts.isIdentifier(node.exprName)) {
211
- cb(node.exprName, false);
213
+ function walkIdentifiersInTypeNode(ts, node, cb) {
214
+ if (ts.isTypeQueryNode(node)) {
215
+ let id = node.exprName;
216
+ while (!ts.isIdentifier(id)) {
217
+ id = id.left;
218
+ }
219
+ cb(id, false);
212
220
  }
213
221
  else {
214
- ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
222
+ ts.forEachChild(node, node => walkIdentifiersInTypeNode(ts, node, cb));
215
223
  }
216
224
  }
217
225
  function shouldIdentifierSkipped(ctx, text, destructuredPropNames) {
@@ -13,7 +13,7 @@ function* generateVFor(options, ctx, node) {
13
13
  yield `for (const [`;
14
14
  if (leftExpressionRange && leftExpressionText) {
15
15
  const collectAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `const [${leftExpressionText}]`);
16
- (0, utils_1.collectVars)(options.ts, collectAst, collectAst, forBlockVars);
16
+ forBlockVars.push(...(0, utils_1.collectBindingNames)(options.ts, collectAst, collectAst));
17
17
  yield [
18
18
  leftExpressionText,
19
19
  'template',
@@ -35,7 +35,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
35
35
  }
36
36
  if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
37
37
  const slotAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `(${slotDir.exp.content}) => {}`);
38
- (0, utils_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
38
+ slotBlockVars.push(...(0, utils_1.collectBindingNames)(options.ts, slotAst, slotAst));
39
39
  yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
40
40
  }
41
41
  for (const varName of slotBlockVars) {
@@ -45,11 +45,6 @@ function* generateVSlot(options, ctx, node, slotDir) {
45
45
  for (const varName of slotBlockVars) {
46
46
  ctx.removeLocalVariable(varName);
47
47
  }
48
- if (options.vueCompilerOptions.strictSlotChildren && node.children.length) {
49
- yield `(): __VLS_NormalizeSlotReturns<typeof ${slotVar}> => (`;
50
- yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, `{} as [`, ...ctx.currentComponent.childTypes.map(name => `${name}, `), `]`);
51
- yield `)${utils_1.endOfLine}`;
52
- }
53
48
  if (slotDir) {
54
49
  let isStatic = true;
55
50
  if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
@@ -103,7 +98,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
103
98
  nextStart = end;
104
99
  }
105
100
  yield chunk(nextStart, expression.equalsGreaterThanToken.pos - 1);
106
- yield `] = __VLS_getSlotParameters(${slotVar}`;
101
+ yield `] = __VLS_getSlotParameters(${slotVar}!`;
107
102
  if (types.some(t => t)) {
108
103
  yield `, `;
109
104
  yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_: `, type, `, `] : `_, `), `) => [] as any`);
@@ -5,7 +5,7 @@ export declare const newLine = "\n";
5
5
  export declare const endOfLine = ";\n";
6
6
  export declare const combineLastMapping: VueCodeInformation;
7
7
  export declare const identifierRegex: RegExp;
8
- export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[]): string[];
8
+ export declare function collectBindingNames(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string[];
9
9
  export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
10
10
  id: ts.Identifier;
11
11
  isRest: boolean;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.identifierRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
4
- exports.collectVars = collectVars;
4
+ exports.collectBindingNames = collectBindingNames;
5
5
  exports.collectIdentifiers = collectIdentifiers;
6
6
  exports.normalizeAttributeValue = normalizeAttributeValue;
7
7
  exports.createTsAst = createTsAst;
@@ -11,12 +11,8 @@ exports.newLine = `\n`;
11
11
  exports.endOfLine = `;${exports.newLine}`;
12
12
  exports.combineLastMapping = { __combineOffset: 1 };
13
13
  exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
14
- function collectVars(ts, node, ast, results = []) {
15
- const identifiers = collectIdentifiers(ts, node, []);
16
- for (const { id } of identifiers) {
17
- results.push((0, shared_1.getNodeText)(ts, id, ast));
18
- }
19
- return results;
14
+ function collectBindingNames(ts, node, ast) {
15
+ return collectIdentifiers(ts, node).map(({ id }) => (0, shared_1.getNodeText)(ts, id, ast));
20
16
  }
21
17
  function collectIdentifiers(ts, node, results = [], isRest = false, initializer = undefined) {
22
18
  if (ts.isIdentifier(node)) {
@@ -0,0 +1,3 @@
1
+ import type { Code } from '../../types';
2
+ export declare function generateIntersectMerge(codes: Code[]): Generator<Code>;
3
+ export declare function generateSpreadMerge(codes: Code[]): Generator<Code>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateIntersectMerge = generateIntersectMerge;
4
+ exports.generateSpreadMerge = generateSpreadMerge;
5
+ const index_1 = require("./index");
6
+ function* generateIntersectMerge(codes) {
7
+ yield codes[0];
8
+ for (let i = 1; i < codes.length; i++) {
9
+ yield ` & `;
10
+ yield codes[i];
11
+ }
12
+ }
13
+ function* generateSpreadMerge(codes) {
14
+ if (codes.length === 1) {
15
+ yield codes[0];
16
+ }
17
+ else {
18
+ yield `{${index_1.newLine}`;
19
+ for (const code of codes) {
20
+ yield `...`;
21
+ yield code;
22
+ yield `,${index_1.newLine}`;
23
+ }
24
+ yield `}`;
25
+ }
26
+ }
27
+ //# sourceMappingURL=merge.js.map
@@ -147,7 +147,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
147
147
  };
148
148
  if (ts.isVariableDeclaration(parent) && ts.isObjectBindingPattern(parent.name)) {
149
149
  defineProps.destructured = new Map();
150
- const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name, []);
150
+ const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name);
151
151
  for (const { id, isRest, initializer } of identifiers) {
152
152
  const name = _getNodeText(id);
153
153
  if (isRest) {
@@ -343,7 +343,8 @@ function findBindingVars(ts, left, ast) {
343
343
  function worker(node) {
344
344
  if (ts.isIdentifier(node)) {
345
345
  vars.push((0, shared_1.getStartEnd)(ts, node, ast));
346
- } // { ? } = ...
346
+ }
347
+ // { ? } = ...
347
348
  // [ ? ] = ...
348
349
  else if (ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node)) {
349
350
  for (const property of node.elements) {
@@ -351,13 +352,16 @@ function findBindingVars(ts, left, ast) {
351
352
  worker(property.name);
352
353
  }
353
354
  }
354
- } // { foo: ? } = ...
355
+ }
356
+ // { foo: ? } = ...
355
357
  else if (ts.isPropertyAssignment(node)) {
356
358
  worker(node.initializer);
357
- } // { foo } = ...
359
+ }
360
+ // { foo } = ...
358
361
  else if (ts.isShorthandPropertyAssignment(node)) {
359
362
  vars.push((0, shared_1.getStartEnd)(ts, node.name, ast));
360
- } // { ...? } = ...
363
+ }
364
+ // { ...? } = ...
361
365
  // [ ...? ] = ...
362
366
  else if (ts.isSpreadAssignment(node) || ts.isSpreadElement(node)) {
363
367
  worker(node.expression);
@@ -53,7 +53,8 @@ const plugin = ({ vueCompilerOptions }) => {
53
53
  type: 'style',
54
54
  lang,
55
55
  });
56
- } // ignore `<script src="...">`
56
+ }
57
+ // ignore `<script src="...">`
57
58
  else if (tag === 'script' && !attrs.includes('src=')) {
58
59
  let type = attrs.includes('type=') ? 'scriptSetup' : 'script';
59
60
  sfc.descriptor[type] = {
@@ -9,9 +9,9 @@ const codeblockReg = /(`{3,})[\s\S]+?\1/g;
9
9
  const inlineCodeblockReg = /`[^\n`]+?`/g;
10
10
  const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
11
11
  const scriptSetupReg = /\\<[\s\S]+?>\n?/g;
12
- const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
13
12
  const angleBracketReg = /<\S*:\S*>/g;
14
13
  const linkReg = /\[[\s\S]*?\]\([\s\S]*?\)/g;
14
+ const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
15
15
  const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
16
16
  const plugin = ({ vueCompilerOptions }) => {
17
17
  return {
@@ -40,42 +40,35 @@ const plugin = ({ vueCompilerOptions }) => {
40
40
  // # \<script setup>
41
41
  .replace(scriptSetupReg, match => ' '.repeat(match.length))
42
42
  // <<< https://vitepress.dev/guide/markdown#import-code-snippets
43
- .replace(codeSnippetImportReg, match => ' '.repeat(match.length));
44
- const codes = [];
45
- for (const match of content.matchAll(sfcBlockReg)) {
46
- if (match.index !== undefined) {
47
- const matchText = match[0];
48
- codes.push([matchText, undefined, match.index]);
49
- codes.push('\n\n');
50
- content = content.slice(0, match.index) + ' '.repeat(matchText.length)
51
- + content.slice(match.index + matchText.length);
52
- }
53
- }
54
- content = content
43
+ .replace(codeSnippetImportReg, match => ' '.repeat(match.length))
55
44
  // angle bracket: <http://foo.com>
56
45
  .replace(angleBracketReg, match => ' '.repeat(match.length))
57
46
  // [foo](http://foo.com)
58
47
  .replace(linkReg, match => ' '.repeat(match.length));
48
+ const codes = [];
49
+ for (const match of content.matchAll(sfcBlockReg)) {
50
+ const matchText = match[0];
51
+ codes.push([matchText, undefined, match.index]);
52
+ codes.push('\n\n');
53
+ content = content.slice(0, match.index) + ' '.repeat(matchText.length)
54
+ + content.slice(match.index + matchText.length);
55
+ }
59
56
  codes.push('<template>\n');
60
57
  codes.push([content, undefined, 0]);
61
58
  codes.push('\n</template>');
62
- const file2VueSourceMap = (0, language_core_1.defaultMapperFactory)((0, buildMappings_1.buildMappings)(codes));
59
+ const mappings = (0, buildMappings_1.buildMappings)(codes);
60
+ const mapper = new language_core_1.SourceMap(mappings);
63
61
  const sfc = (0, parseSfc_1.parse)((0, muggle_string_1.toString)(codes));
64
- if (sfc.descriptor.template) {
65
- sfc.descriptor.template.lang = 'md';
66
- transformRange(sfc.descriptor.template);
67
- }
68
- if (sfc.descriptor.script) {
69
- transformRange(sfc.descriptor.script);
70
- }
71
- if (sfc.descriptor.scriptSetup) {
72
- transformRange(sfc.descriptor.scriptSetup);
73
- }
74
- for (const style of sfc.descriptor.styles) {
75
- transformRange(style);
76
- }
77
- for (const customBlock of sfc.descriptor.customBlocks) {
78
- transformRange(customBlock);
62
+ for (const block of [
63
+ sfc.descriptor.template,
64
+ sfc.descriptor.script,
65
+ sfc.descriptor.scriptSetup,
66
+ ...sfc.descriptor.styles,
67
+ ...sfc.descriptor.customBlocks,
68
+ ]) {
69
+ if (block) {
70
+ transformRange(block);
71
+ }
79
72
  }
80
73
  return sfc;
81
74
  function transformRange(block) {
@@ -84,11 +77,11 @@ const plugin = ({ vueCompilerOptions }) => {
84
77
  const endOffset = end.offset;
85
78
  start.offset = -1;
86
79
  end.offset = -1;
87
- for (const [offset] of file2VueSourceMap.toSourceLocation(startOffset)) {
80
+ for (const [offset] of mapper.toSourceLocation(startOffset)) {
88
81
  start.offset = offset;
89
82
  break;
90
83
  }
91
- for (const [offset] of file2VueSourceMap.toSourceLocation(endOffset)) {
84
+ for (const [offset] of mapper.toSourceLocation(endOffset)) {
92
85
  end.offset = offset;
93
86
  break;
94
87
  }
@@ -199,7 +199,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
199
199
  }[]>;
200
200
  currentComponent: {
201
201
  ctxVar: string;
202
- childTypes: string[];
203
202
  used: boolean;
204
203
  } | undefined;
205
204
  singleRootElTypes: string[];
@@ -14,7 +14,6 @@ const ts_1 = require("../utils/ts");
14
14
  exports.tsCodegen = new WeakMap();
15
15
  const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
16
16
  const plugin = ctx => {
17
- let appendedGlobalTypes = false;
18
17
  return {
19
18
  version: 2.1,
20
19
  requiredCompilerOptions: [
@@ -40,18 +39,13 @@ const plugin = ctx => {
40
39
  };
41
40
  function useCodegen(fileName, sfc) {
42
41
  if (!exports.tsCodegen.has(sfc)) {
43
- let appendGlobalTypes = false;
44
- if (!ctx.vueCompilerOptions.__setupedGlobalTypes && !appendedGlobalTypes) {
45
- appendGlobalTypes = true;
46
- appendedGlobalTypes = true;
47
- }
48
- exports.tsCodegen.set(sfc, createTsx(fileName, sfc, ctx, appendGlobalTypes));
42
+ exports.tsCodegen.set(sfc, createTsx(fileName, sfc, ctx));
49
43
  }
50
44
  return exports.tsCodegen.get(sfc);
51
45
  }
52
46
  };
53
47
  exports.default = plugin;
54
- function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
48
+ function createTsx(fileName, sfc, ctx) {
55
49
  const ts = ctx.modules.typescript;
56
50
  const getRawLang = (0, alien_signals_1.computed)(() => {
57
51
  if (sfc.script && sfc.scriptSetup) {
@@ -191,7 +185,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
191
185
  templateCodegen: getGeneratedTemplate(),
192
186
  destructuredPropNames: getSetupDestructuredPropNames(),
193
187
  templateRefNames: getSetupTemplateRefNames(),
194
- appendGlobalTypes,
195
188
  });
196
189
  let current = codegen.next();
197
190
  while (!current.done) {
package/lib/types.d.ts CHANGED
@@ -6,9 +6,10 @@ import type * as ts from 'typescript';
6
6
  import type { VueEmbeddedCode } from './virtualFile/embeddedFile';
7
7
  export type { SFCParseResult } from '@vue/compiler-sfc';
8
8
  export { VueEmbeddedCode };
9
- export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
9
+ export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'globalTypesPath' | 'plugins'>> & {
10
10
  strictTemplates?: boolean;
11
11
  target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
12
+ globalTypesPath?: string;
12
13
  plugins?: string[];
13
14
  };
14
15
  export interface VueCodeInformation extends CodeInformation {
@@ -19,11 +20,11 @@ export type Code = Segment<VueCodeInformation>;
19
20
  export interface VueCompilerOptions {
20
21
  target: number;
21
22
  lib: string;
23
+ globalTypesPath: (fileName: string) => string | undefined;
22
24
  extensions: string[];
23
25
  vitePressExtensions: string[];
24
26
  petiteVueExtensions: string[];
25
27
  jsxSlots: boolean;
26
- strictSlotChildren: boolean;
27
28
  strictVModel: boolean;
28
29
  strictCssModules: boolean;
29
30
  checkUnknownProps: boolean;
@@ -61,9 +62,6 @@ export interface VueCompilerOptions {
61
62
  };
62
63
  plugins: VueLanguagePlugin[];
63
64
  experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
64
- __setupedGlobalTypes?: true | {
65
- absolutePath: string;
66
- };
67
65
  }
68
66
  export declare const validVersions: readonly [2, 2.1];
69
67
  export type VueLanguagePluginReturn = {
package/lib/utils/ts.d.ts CHANGED
@@ -5,18 +5,19 @@ export type ParsedCommandLine = ts.ParsedCommandLine & {
5
5
  };
6
6
  export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost & {
7
7
  writeFile?(path: string, data: string): void;
8
- }, rootDir: string, json: any, configFileName?: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
9
- export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
8
+ }, rootDir: string, json: any, configFileName?: string): ParsedCommandLine;
9
+ export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string): ParsedCommandLine;
10
10
  export declare class CompilerOptionsResolver {
11
- options: Omit<RawVueCompilerOptions, 'target' | 'plugin'>;
12
- fallbackTarget: number | undefined;
11
+ fileExists?: ((path: string) => boolean) | undefined;
12
+ configRoots: Set<string>;
13
+ options: Omit<RawVueCompilerOptions, 'target' | 'globalTypesPath' | 'plugins'>;
13
14
  target: number | undefined;
15
+ globalTypesPath: string | undefined;
14
16
  plugins: VueLanguagePlugin[];
17
+ constructor(fileExists?: ((path: string) => boolean) | undefined);
15
18
  addConfig(options: RawVueCompilerOptions, rootDir: string): void;
16
19
  build(defaults?: VueCompilerOptions): VueCompilerOptions;
20
+ private findNodeModulesRoot;
17
21
  }
18
22
  export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
19
- export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
20
- fileExists(path: string): boolean;
21
- writeFile?(path: string, data: string): void;
22
- }): VueCompilerOptions['__setupedGlobalTypes'];
23
+ export declare function writeGlobalTypes(vueOptions: VueCompilerOptions, writeFile: (fileName: string, data: string) => void): void;
package/lib/utils/ts.js CHANGED
@@ -4,16 +4,16 @@ exports.CompilerOptionsResolver = void 0;
4
4
  exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
5
5
  exports.createParsedCommandLine = createParsedCommandLine;
6
6
  exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
7
- exports.setupGlobalTypes = setupGlobalTypes;
7
+ exports.writeGlobalTypes = writeGlobalTypes;
8
8
  const shared_1 = require("@vue/shared");
9
9
  const path_browserify_1 = require("path-browserify");
10
10
  const globalTypes_1 = require("../codegen/globalTypes");
11
11
  const languagePlugin_1 = require("../languagePlugin");
12
12
  const shared_2 = require("./shared");
13
- function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json', skipGlobalTypesSetup = false) {
13
+ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json') {
14
14
  const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
15
15
  ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName);
16
- const resolver = new CompilerOptionsResolver();
16
+ const resolver = new CompilerOptionsResolver(parseConfigHost.fileExists);
17
17
  for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
18
18
  try {
19
19
  const configFile = ts.readJsonConfigFile(extendPath, proxyHost.host.readFile);
@@ -23,13 +23,9 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, confi
23
23
  }
24
24
  catch { }
25
25
  }
26
+ // ensure the rootDir is added to the config roots
27
+ resolver.addConfig({}, rootDir);
26
28
  const resolvedVueOptions = resolver.build();
27
- if (skipGlobalTypesSetup) {
28
- resolvedVueOptions.__setupedGlobalTypes = true;
29
- }
30
- else {
31
- resolvedVueOptions.__setupedGlobalTypes = setupGlobalTypes(rootDir, resolvedVueOptions, parseConfigHost);
32
- }
33
29
  const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
34
30
  .map(extension => ({
35
31
  extension: extension.slice(1),
@@ -45,12 +41,13 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, confi
45
41
  vueOptions: resolvedVueOptions,
46
42
  };
47
43
  }
48
- function createParsedCommandLine(ts, parseConfigHost, tsConfigPath, skipGlobalTypesSetup = false) {
44
+ function createParsedCommandLine(ts, parseConfigHost, tsConfigPath) {
49
45
  try {
46
+ const rootDir = path_browserify_1.posix.dirname(tsConfigPath);
50
47
  const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
51
48
  const config = ts.readJsonConfigFile(tsConfigPath, proxyHost.host.readFile);
52
- ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path_browserify_1.posix.dirname(tsConfigPath), {}, tsConfigPath);
53
- const resolver = new CompilerOptionsResolver();
49
+ ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, rootDir, {}, tsConfigPath);
50
+ const resolver = new CompilerOptionsResolver(parseConfigHost.fileExists);
54
51
  for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
55
52
  try {
56
53
  const configFile = ts.readJsonConfigFile(extendPath, proxyHost.host.readFile);
@@ -61,12 +58,6 @@ function createParsedCommandLine(ts, parseConfigHost, tsConfigPath, skipGlobalTy
61
58
  catch { }
62
59
  }
63
60
  const resolvedVueOptions = resolver.build();
64
- if (skipGlobalTypesSetup) {
65
- resolvedVueOptions.__setupedGlobalTypes = true;
66
- }
67
- else {
68
- resolvedVueOptions.__setupedGlobalTypes = setupGlobalTypes(path_browserify_1.posix.dirname(tsConfigPath), resolvedVueOptions, parseConfigHost);
69
- }
70
61
  const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path_browserify_1.posix.dirname(tsConfigPath), {}, tsConfigPath, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
71
62
  .map(extension => ({
72
63
  extension: extension.slice(1),
@@ -113,20 +104,27 @@ function proxyParseConfigHostForExtendConfigPaths(parseConfigHost) {
113
104
  };
114
105
  }
115
106
  class CompilerOptionsResolver {
116
- constructor() {
107
+ constructor(fileExists) {
108
+ this.fileExists = fileExists;
109
+ this.configRoots = new Set();
117
110
  this.options = {};
118
111
  this.plugins = [];
119
112
  }
120
113
  addConfig(options, rootDir) {
114
+ this.configRoots.add(rootDir);
121
115
  for (const key in options) {
122
116
  switch (key) {
123
117
  case 'target':
124
- const target = options.target;
125
- if (typeof target === 'string') {
118
+ if (options[key] === 'auto') {
126
119
  this.target = findVueVersion(rootDir);
127
120
  }
128
121
  else {
129
- this.target = target;
122
+ this.target = options[key];
123
+ }
124
+ break;
125
+ case 'globalTypesPath':
126
+ if (options[key] !== undefined) {
127
+ this.globalTypesPath = path_browserify_1.posix.join(rootDir, options[key]);
130
128
  }
131
129
  break;
132
130
  case 'plugins':
@@ -155,14 +153,13 @@ class CompilerOptionsResolver {
155
153
  break;
156
154
  }
157
155
  }
158
- if (this.target === undefined) {
159
- this.fallbackTarget = findVueVersion(rootDir);
156
+ if (options.target === undefined) {
157
+ this.target ??= findVueVersion(rootDir);
160
158
  }
161
159
  }
162
160
  build(defaults) {
163
- const target = this.target ?? this.fallbackTarget;
164
- defaults ??= getDefaultCompilerOptions(target, this.options.lib, this.options.strictTemplates);
165
- return {
161
+ defaults ??= getDefaultCompilerOptions(this.target, this.options.lib, this.options.strictTemplates);
162
+ const resolvedOptions = {
166
163
  ...defaults,
167
164
  ...this.options,
168
165
  plugins: this.plugins,
@@ -182,6 +179,35 @@ class CompilerOptionsResolver {
182
179
  // https://vuejs.org/guide/essentials/forms.html#form-input-bindings
183
180
  experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
184
181
  };
182
+ if (this.fileExists && this.globalTypesPath === undefined) {
183
+ const fileDirToGlobalTypesPath = new Map();
184
+ resolvedOptions.globalTypesPath = fileName => {
185
+ const fileDir = path_browserify_1.posix.dirname(fileName);
186
+ if (fileDirToGlobalTypesPath.has(fileDir)) {
187
+ return fileDirToGlobalTypesPath.get(fileDir);
188
+ }
189
+ const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
190
+ const result = root
191
+ ? path_browserify_1.posix.join(root, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions))
192
+ : undefined;
193
+ fileDirToGlobalTypesPath.set(fileDir, result);
194
+ return result;
195
+ };
196
+ }
197
+ else {
198
+ resolvedOptions.globalTypesPath = () => this.globalTypesPath;
199
+ }
200
+ return resolvedOptions;
201
+ }
202
+ findNodeModulesRoot(dir, lib) {
203
+ while (!this.fileExists(path_browserify_1.posix.join(dir, 'node_modules', lib, 'package.json'))) {
204
+ const parentDir = path_browserify_1.posix.dirname(dir);
205
+ if (dir === parentDir) {
206
+ return;
207
+ }
208
+ dir = parentDir;
209
+ }
210
+ return dir;
185
211
  }
186
212
  }
187
213
  exports.CompilerOptionsResolver = CompilerOptionsResolver;
@@ -213,11 +239,11 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
213
239
  return {
214
240
  target,
215
241
  lib,
242
+ globalTypesPath: () => undefined,
216
243
  extensions: ['.vue'],
217
244
  vitePressExtensions: [],
218
245
  petiteVueExtensions: [],
219
246
  jsxSlots: false,
220
- strictSlotChildren: strictTemplates,
221
247
  strictVModel: strictTemplates,
222
248
  strictCssModules: false,
223
249
  checkUnknownProps: strictTemplates,
@@ -273,24 +299,19 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
273
299
  },
274
300
  };
275
301
  }
276
- function setupGlobalTypes(rootDir, vueOptions, host) {
277
- if (!host.writeFile) {
302
+ function writeGlobalTypes(vueOptions, writeFile) {
303
+ const originalFn = vueOptions.globalTypesPath;
304
+ if (!originalFn) {
278
305
  return;
279
306
  }
280
- try {
281
- let dir = rootDir;
282
- while (!host.fileExists(path_browserify_1.posix.join(dir, 'node_modules', vueOptions.lib, 'package.json'))) {
283
- const parentDir = path_browserify_1.posix.dirname(dir);
284
- if (dir === parentDir) {
285
- throw 0;
286
- }
287
- dir = parentDir;
307
+ const writed = new Set();
308
+ vueOptions.globalTypesPath = (fileName) => {
309
+ const result = originalFn(fileName);
310
+ if (result && !writed.has(result)) {
311
+ writed.add(result);
312
+ writeFile(result, (0, globalTypes_1.generateGlobalTypes)(vueOptions));
288
313
  }
289
- const globalTypesPath = path_browserify_1.posix.join(dir, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(vueOptions));
290
- const globalTypesContents = `// @ts-nocheck\nexport {};\n` + (0, globalTypes_1.generateGlobalTypes)(vueOptions);
291
- host.writeFile(globalTypesPath, globalTypesContents);
292
- return { absolutePath: globalTypesPath };
293
- }
294
- catch { }
314
+ return result;
315
+ };
295
316
  }
296
317
  //# sourceMappingURL=ts.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,19 +13,20 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "2.4.17",
16
+ "@volar/language-core": "2.4.20",
17
17
  "@vue/compiler-dom": "^3.5.0",
18
18
  "@vue/compiler-vue2": "^2.7.16",
19
19
  "@vue/shared": "^3.5.0",
20
20
  "alien-signals": "^2.0.5",
21
- "minimatch": "^10.0.1",
22
21
  "muggle-string": "^0.4.1",
23
- "path-browserify": "^1.0.1"
22
+ "path-browserify": "^1.0.1",
23
+ "picomatch": "^4.0.2"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "^22.10.4",
27
27
  "@types/path-browserify": "^1.0.1",
28
- "@volar/typescript": "2.4.17",
28
+ "@types/picomatch": "^4.0.0",
29
+ "@volar/typescript": "2.4.20",
29
30
  "@vue/compiler-sfc": "^3.5.0"
30
31
  },
31
32
  "peerDependencies": {
@@ -36,5 +37,5 @@
36
37
  "optional": true
37
38
  }
38
39
  },
39
- "gitHead": "43884409838dfdce44de51f6622926ac6ddd7318"
40
+ "gitHead": "129f30ff8d8d976abf0431063be5c6c4cf88f0fd"
40
41
  }