@vue/language-core 3.0.2 → 3.0.4

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.
Files changed (39) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/codegen/codeFeatures.d.ts +15 -0
  4. package/lib/codegen/codeFeatures.js +20 -0
  5. package/lib/codegen/globalTypes.d.ts +2 -2
  6. package/lib/codegen/globalTypes.js +27 -32
  7. package/lib/codegen/script/component.js +23 -32
  8. package/lib/codegen/script/index.js +19 -18
  9. package/lib/codegen/script/scriptSetup.js +3 -4
  10. package/lib/codegen/script/template.js +5 -21
  11. package/lib/codegen/template/context.d.ts +3 -1
  12. package/lib/codegen/template/element.js +7 -12
  13. package/lib/codegen/template/elementEvents.d.ts +1 -1
  14. package/lib/codegen/template/elementEvents.js +11 -6
  15. package/lib/codegen/template/elementProps.js +4 -11
  16. package/lib/codegen/template/interpolation.js +3 -2
  17. package/lib/codegen/template/vFor.js +2 -1
  18. package/lib/codegen/template/vSlot.js +2 -6
  19. package/lib/codegen/tenp.d.ts +1 -0
  20. package/lib/codegen/tenp.js +3 -0
  21. package/lib/codegen/utils/index.d.ts +0 -10
  22. package/lib/codegen/utils/index.js +0 -27
  23. package/lib/codegen/utils/merge.d.ts +3 -0
  24. package/lib/codegen/utils/merge.js +27 -0
  25. package/lib/parsers/scriptSetupRanges.d.ts +0 -1
  26. package/lib/parsers/scriptSetupRanges.js +4 -40
  27. package/lib/plugins/file-css.d.ts +3 -0
  28. package/lib/plugins/file-css.js +57 -0
  29. package/lib/plugins/vue-root-tags.js +2 -9
  30. package/lib/plugins/vue-style-css.d.ts +3 -0
  31. package/lib/plugins/vue-style-css.js +62 -0
  32. package/lib/plugins/vue-tsx.d.ts +5 -2
  33. package/lib/plugins/vue-tsx.js +2 -1
  34. package/lib/types.d.ts +3 -3
  35. package/lib/utils/collectBindings.d.ts +12 -0
  36. package/lib/utils/collectBindings.js +29 -0
  37. package/lib/utils/ts.d.ts +3 -1
  38. package/lib/utils/ts.js +44 -15
  39. package/package.json +4 -4
package/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export * from './lib/codegen/globalTypes';
2
2
  export * from './lib/codegen/template';
3
- export * from './lib/codegen/utils';
4
3
  export * from './lib/languagePlugin';
5
4
  export * from './lib/parsers/scriptSetupRanges';
6
5
  export * from './lib/plugins';
7
6
  export * from './lib/types';
7
+ export * from './lib/utils/collectBindings';
8
8
  export * from './lib/utils/parseSfc';
9
9
  export * from './lib/utils/shared';
10
10
  export * from './lib/utils/ts';
package/index.js CHANGED
@@ -17,11 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.tsCodegen = void 0;
18
18
  __exportStar(require("./lib/codegen/globalTypes"), exports);
19
19
  __exportStar(require("./lib/codegen/template"), exports);
20
- __exportStar(require("./lib/codegen/utils"), exports);
21
20
  __exportStar(require("./lib/languagePlugin"), exports);
22
21
  __exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
23
22
  __exportStar(require("./lib/plugins"), exports);
24
23
  __exportStar(require("./lib/types"), exports);
24
+ __exportStar(require("./lib/utils/collectBindings"), exports);
25
25
  __exportStar(require("./lib/utils/parseSfc"), exports);
26
26
  __exportStar(require("./lib/utils/shared"), exports);
27
27
  __exportStar(require("./lib/utils/ts"), exports);
@@ -87,6 +87,21 @@ declare const raw: {
87
87
  navigation: true;
88
88
  completion: true;
89
89
  };
90
+ doNotReportTs2339AndTs2551: {
91
+ verification: {
92
+ shouldReport: (_source: string | undefined, code: string | number | undefined) => boolean;
93
+ };
94
+ };
95
+ doNotReportTs2353AndTs2561: {
96
+ verification: {
97
+ shouldReport: (_source: string | undefined, code: string | number | undefined) => boolean;
98
+ };
99
+ };
100
+ doNotReportTs6133: {
101
+ verification: {
102
+ shouldReport: (_source: string | undefined, code: string | number | undefined) => boolean;
103
+ };
104
+ };
90
105
  };
91
106
  export declare const codeFeatures: { [K in keyof typeof raw]: VueCodeInformation; };
92
107
  export {};
@@ -73,6 +73,26 @@ const raw = {
73
73
  navigation: true,
74
74
  completion: true,
75
75
  },
76
+ doNotReportTs2339AndTs2551: {
77
+ verification: {
78
+ // https://typescript.tv/errors/#ts2339
79
+ // https://typescript.tv/errors/#ts2551
80
+ shouldReport: (_source, code) => String(code) !== '2339' && String(code) !== '2551',
81
+ },
82
+ },
83
+ doNotReportTs2353AndTs2561: {
84
+ verification: {
85
+ // https://typescript.tv/errors/#ts2353
86
+ // https://typescript.tv/errors/#ts2561
87
+ shouldReport: (_source, code) => String(code) !== '2353' && String(code) !== '2561',
88
+ },
89
+ },
90
+ doNotReportTs6133: {
91
+ verification: {
92
+ // https://typescript.tv/errors/#ts6133
93
+ shouldReport: (_source, code) => String(code) !== '6133',
94
+ },
95
+ },
76
96
  };
77
97
  exports.codeFeatures = raw;
78
98
  //# sourceMappingURL=codeFeatures.js.map
@@ -1,3 +1,3 @@
1
1
  import type { VueCompilerOptions } from '../types';
2
- export declare function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }: VueCompilerOptions): string;
3
- export declare function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }: VueCompilerOptions): string;
2
+ export declare function getGlobalTypesFileName(options: VueCompilerOptions): string;
3
+ export declare function generateGlobalTypes(options: VueCompilerOptions): string;
@@ -3,16 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getGlobalTypesFileName = getGlobalTypesFileName;
4
4
  exports.generateGlobalTypes = generateGlobalTypes;
5
5
  const shared_1 = require("../utils/shared");
6
- function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
6
+ function getGlobalTypesFileName(options) {
7
7
  return [
8
- lib,
9
- target,
10
- checkUnknownProps,
11
- checkUnknownEvents,
12
- checkUnknownComponents,
8
+ options.lib,
9
+ options.target,
10
+ options.checkUnknownProps,
13
11
  ].map(v => (typeof v === 'boolean' ? Number(v) : v)).join('_') + '.d.ts';
14
12
  }
15
- function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
13
+ function generateGlobalTypes(options) {
14
+ const { lib, target, checkUnknownProps } = options;
16
15
  const fnPropsType = `(T extends { $props: infer Props } ? Props : {})${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
17
16
  let text = `// @ts-nocheck\nexport {};\n`;
18
17
  if (target < 3.5) {
@@ -50,7 +49,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
50
49
  N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
51
50
  N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
52
51
  N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
53
- ${checkUnknownComponents ? '{}' : '{ [K in N0]: unknown }'};
52
+ {};
54
53
  type __VLS_FunctionalComponentCtx<T, K> = __VLS_PickNotAny<'__ctx' extends keyof __VLS_PickNotAny<K, {}>
55
54
  ? K extends { __ctx?: infer Ctx } ? NonNullable<Ctx> : never : any
56
55
  , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
@@ -61,21 +60,13 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
61
60
  : {};
62
61
  type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
63
62
  __ctx?: {
64
- attrs?: any,
65
- slots?: T extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : Record<string, any>,
66
- emit?: T extends { $emit: infer Emit } ? Emit : {},
67
- props?: ${fnPropsType},
68
- expose?: (exposed: T) => void,
69
- }
63
+ attrs?: any;
64
+ slots?: T extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : Record<string, any>;
65
+ emit?: T extends { $emit: infer Emit } ? Emit : {};
66
+ props?: ${fnPropsType};
67
+ expose?: (exposed: T) => void;
68
+ };
70
69
  };
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
70
  type __VLS_IsFunction<T, K> = K extends keyof T
80
71
  ? __VLS_IsAny<T[K]> extends false
81
72
  ? unknown extends T[K]
@@ -83,15 +74,19 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
83
74
  : true
84
75
  : false
85
76
  : false;
86
- type __VLS_NormalizeComponentEvent<Props, Emits, onEvent extends keyof Props, Event extends keyof Emits, CamelizedEvent extends keyof Emits> = (
87
- __VLS_IsFunction<Props, onEvent> extends true
88
- ? Props
89
- : __VLS_IsFunction<Emits, Event> extends true
90
- ? { [K in onEvent]?: Emits[Event] }
91
- : __VLS_IsFunction<Emits, CamelizedEvent> extends true
92
- ? { [K in onEvent]?: Emits[CamelizedEvent] }
93
- : Props
94
- )${checkUnknownEvents ? '' : ' & Record<string, unknown>'};
77
+ type __VLS_NormalizeComponentEvent<
78
+ Props,
79
+ Emits,
80
+ onEvent extends keyof Props,
81
+ Event extends keyof Emits,
82
+ CamelizedEvent extends keyof Emits,
83
+ > = __VLS_IsFunction<Props, onEvent> extends true
84
+ ? Props
85
+ : __VLS_IsFunction<Emits, Event> extends true
86
+ ? { [K in onEvent]?: Emits[Event] }
87
+ : __VLS_IsFunction<Emits, CamelizedEvent> extends true
88
+ ? { [K in onEvent]?: Emits[CamelizedEvent] }
89
+ : Props;
95
90
  // fix https://github.com/vuejs/language-tools/issues/926
96
91
  type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
97
92
  type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
@@ -158,7 +153,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
158
153
  : T extends (...args: any) => any ? T
159
154
  : __VLS_FunctionalComponent<{}>;
160
155
  function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
161
- function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
156
+ function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownProps ? '' : ' & Record<string, unknown>'}) => void;
162
157
  function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
163
158
  function __VLS_tryAsConstant<const T>(t: T): T;
164
159
  }
@@ -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)];
@@ -77,10 +85,14 @@ function* generateEmitsOption(options, scriptSetupRanges) {
77
85
  }
78
86
  }
79
87
  if (options.vueCompilerOptions.target >= 3.5 && typeOptionCodes.length) {
80
- yield* generateIntersectMerge('__typeEmits', typeOptionCodes);
88
+ yield `__typeEmits: {} as `;
89
+ yield* (0, merge_1.generateIntersectMerge)(typeOptionCodes);
90
+ yield `,${utils_1.newLine}`;
81
91
  }
82
92
  else if (optionCodes.length) {
83
- yield* generateSpreadMerge('emits', optionCodes);
93
+ yield `emits: `;
94
+ yield* (0, merge_1.generateSpreadMerge)(optionCodes);
95
+ yield `,${utils_1.newLine}`;
84
96
  }
85
97
  }
86
98
  function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption, inheritAttrs) {
@@ -121,35 +133,14 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
121
133
  && scriptSetupRanges.withDefaults?.arg) {
122
134
  yield `__defaults: __VLS_withDefaultsArg,${utils_1.newLine}`;
123
135
  }
124
- yield* generateSpreadMerge('__typeProps', typeOptionCodes);
136
+ yield `__typeProps: `;
137
+ yield* (0, merge_1.generateSpreadMerge)(typeOptionCodes);
138
+ yield `,${utils_1.newLine}`;
125
139
  }
126
140
  if (useOption) {
127
- yield* generateSpreadMerge('props', getOptionCodes.map(fn => fn()));
128
- }
129
- }
130
- function* generateIntersectMerge(key, codes) {
131
- yield `${key}: {} as `;
132
- yield codes[0];
133
- for (let i = 1; i < codes.length; i++) {
134
- yield ` & `;
135
- yield codes[i];
136
- }
137
- yield `,${utils_1.newLine}`;
138
- }
139
- function* generateSpreadMerge(key, codes) {
140
- yield `${key}: `;
141
- if (codes.length === 1) {
142
- yield codes[0];
143
- }
144
- else {
145
- yield `{${utils_1.newLine}`;
146
- for (const code of codes) {
147
- yield `...`;
148
- yield code;
149
- yield `,${utils_1.newLine}`;
150
- }
151
- yield `}`;
141
+ yield `props: `;
142
+ yield* (0, merge_1.generateSpreadMerge)(getOptionCodes.map(fn => fn()));
143
+ yield `,${utils_1.newLine}`;
152
144
  }
153
- yield `,${utils_1.newLine}`;
154
145
  }
155
146
  //# sourceMappingURL=component.js.map
@@ -12,24 +12,7 @@ const src_1 = require("./src");
12
12
  const template_1 = require("./template");
13
13
  function* generateScript(options) {
14
14
  const ctx = (0, context_1.createScriptCodegenContext)(options);
15
- if (options.vueCompilerOptions.globalTypesPath) {
16
- const globalTypesPath = options.vueCompilerOptions.globalTypesPath;
17
- if (path.isAbsolute(globalTypesPath)) {
18
- let relativePath = path.relative(path.dirname(options.fileName), globalTypesPath);
19
- if (relativePath !== globalTypesPath
20
- && !relativePath.startsWith('./')
21
- && !relativePath.startsWith('../')) {
22
- relativePath = './' + relativePath;
23
- }
24
- yield `/// <reference types="${relativePath}" />${utils_1.newLine}`;
25
- }
26
- else {
27
- yield `/// <reference types="${globalTypesPath}" />${utils_1.newLine}`;
28
- }
29
- }
30
- else {
31
- yield `/* placeholder */${utils_1.newLine}`;
32
- }
15
+ yield* generateGlobalTypesPath(options);
33
16
  if (options.sfc.script?.src) {
34
17
  yield* (0, src_1.generateSrc)(options.sfc.script.src);
35
18
  }
@@ -112,6 +95,24 @@ function* generateScript(options) {
112
95
  }
113
96
  return ctx;
114
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
+ }
115
116
  function* generateScriptSectionPartiallyEnding(source, end, mark, delimiter = 'debugger') {
116
117
  yield delimiter;
117
118
  yield ['', source, end, codeFeatures_1.codeFeatures.verification];
@@ -248,10 +248,9 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
248
248
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
249
249
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
250
250
  if (syntax) {
251
- if (!options.vueCompilerOptions.skipTemplateCodegen
252
- && (scriptSetupRanges.defineSlots
253
- || options.templateCodegen?.slots.length
254
- || options.templateCodegen?.dynamicSlots.length)) {
251
+ if (scriptSetupRanges.defineSlots
252
+ || options.templateCodegen?.slots.length
253
+ || options.templateCodegen?.dynamicSlots.length) {
255
254
  yield `const __VLS_component = `;
256
255
  yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
257
256
  yield utils_1.endOfLine;
@@ -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
  }
@@ -130,6 +130,9 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
130
130
  withoutHighlightAndCompletion: VueCodeInformation;
131
131
  withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
132
132
  withoutSemantic: VueCodeInformation;
133
+ doNotReportTs2339AndTs2551: VueCodeInformation;
134
+ doNotReportTs2353AndTs2561: VueCodeInformation;
135
+ doNotReportTs6133: VueCodeInformation;
133
136
  };
134
137
  resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
135
138
  inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
@@ -163,7 +166,6 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
163
166
  }[]>;
164
167
  currentComponent: {
165
168
  ctxVar: string;
166
- childTypes: string[];
167
169
  used: boolean;
168
170
  } | undefined;
169
171
  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;
@@ -112,7 +110,12 @@ function* generateComponent(options, ctx, node) {
112
110
  .map(name => `'${name}'`)
113
111
  .join(`, `);
114
112
  yield `>).`;
115
- yield* generateCanonicalComponentName(node.tag, tagOffsets[0], ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation);
113
+ yield* generateCanonicalComponentName(node.tag, tagOffsets[0], ctx.resolveCodeFeatures({
114
+ ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
115
+ ...options.vueCompilerOptions.checkUnknownComponents
116
+ ? codeFeatures_1.codeFeatures.verification
117
+ : codeFeatures_1.codeFeatures.doNotReportTs2339AndTs2551,
118
+ }));
116
119
  yield `${utils_1.endOfLine}`;
117
120
  const camelizedTag = (0, shared_1.camelize)(node.tag);
118
121
  if (utils_1.identifierRegex.test(camelizedTag)) {
@@ -142,14 +145,7 @@ function* generateComponent(options, ctx, node) {
142
145
  yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, false);
143
146
  yield `}))${utils_1.endOfLine}`;
144
147
  yield `const `;
145
- yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.resolveCodeFeatures({
146
- verification: {
147
- shouldReport(_source, code) {
148
- // https://typescript.tv/errors/#ts6133
149
- return String(code) !== '6133';
150
- },
151
- },
152
- }), componentVNodeVar);
148
+ yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.doNotReportTs6133, componentVNodeVar);
153
149
  yield ` = ${componentFunctionalVar}`;
154
150
  yield* generateComponentGeneric(ctx);
155
151
  yield `(`;
@@ -196,7 +192,6 @@ function* generateElement(options, ctx, node) {
196
192
  ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
197
193
  : undefined;
198
194
  const failedPropExps = [];
199
- ctx.currentComponent?.childTypes.push(`__VLS_NativeElements['${node.tag}']`);
200
195
  yield `__VLS_asFunctionalElement(__VLS_elements`;
201
196
  yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
202
197
  if (endTagOffset !== undefined) {
@@ -4,7 +4,7 @@ import type { Code, VueCodeInformation } from '../../types';
4
4
  import type { TemplateCodegenContext } from './context';
5
5
  import type { TemplateCodegenOptions } from './index';
6
6
  export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
7
- export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
7
+ export declare function generateEventArg(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
8
8
  export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
9
9
  export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
10
10
  export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
@@ -7,6 +7,7 @@ exports.generateModelEventExpression = generateModelEventExpression;
7
7
  exports.isCompoundExpression = isCompoundExpression;
8
8
  const CompilerDOM = require("@vue/compiler-dom");
9
9
  const shared_1 = require("@vue/shared");
10
+ const codeFeatures_1 = require("../codeFeatures");
10
11
  const utils_1 = require("../utils");
11
12
  const camelized_1 = require("../utils/camelized");
12
13
  const wrapWith_1 = require("../utils/wrapWith");
@@ -48,12 +49,12 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
48
49
  yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
49
50
  if (prop.name === 'on') {
50
51
  yield `{ `;
51
- yield* generateEventArg(ctx, source, start, emitPrefix.slice(0, -1), ctx.codeFeatures.navigation);
52
+ yield* generateEventArg(options, ctx, source, start, emitPrefix.slice(0, -1), ctx.codeFeatures.navigation);
52
53
  yield `: {} as any } as typeof ${emitsVar},${utils_1.newLine}`;
53
54
  }
54
55
  yield `{ `;
55
56
  if (prop.name === 'on') {
56
- yield* generateEventArg(ctx, source, start, propPrefix.slice(0, -1));
57
+ yield* generateEventArg(options, ctx, source, start, propPrefix.slice(0, -1));
57
58
  yield `: `;
58
59
  yield* generateEventExpression(options, ctx, prop);
59
60
  }
@@ -65,10 +66,14 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
65
66
  }
66
67
  }
67
68
  }
68
- function* generateEventArg(ctx, name, start, directive = 'on', features = {
69
- ...ctx.codeFeatures.withoutHighlightAndCompletion,
70
- ...ctx.codeFeatures.navigationWithoutRename,
71
- }) {
69
+ function* generateEventArg(options, ctx, name, start, directive = 'on', features) {
70
+ features ??= ctx.resolveCodeFeatures({
71
+ ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
72
+ ...codeFeatures_1.codeFeatures.navigationWithoutRename,
73
+ ...options.vueCompilerOptions.checkUnknownEvents
74
+ ? codeFeatures_1.codeFeatures.verification
75
+ : codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
76
+ });
72
77
  if (directive.length) {
73
78
  name = (0, shared_1.capitalize)(name);
74
79
  }
@@ -27,7 +27,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
27
27
  && !prop.arg.loc.source.endsWith(']')) {
28
28
  if (!isComponent) {
29
29
  yield `...{ `;
30
- yield* (0, elementEvents_1.generateEventArg)(ctx, prop.arg.loc.source, prop.arg.loc.start.offset);
30
+ yield* (0, elementEvents_1.generateEventArg)(options, ctx, prop.arg.loc.source, prop.arg.loc.start.offset);
31
31
  yield `: `;
32
32
  yield* (0, elementEvents_1.generateEventExpression)(options, ctx, prop);
33
33
  yield `},`;
@@ -223,16 +223,9 @@ function getShouldCamelize(options, prop, propName) {
223
223
  function getPropsCodeInfo(ctx, strictPropsCheck) {
224
224
  return ctx.resolveCodeFeatures({
225
225
  ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
226
- verification: strictPropsCheck || {
227
- shouldReport(_source, code) {
228
- // https://typescript.tv/errors/#ts2353
229
- // https://typescript.tv/errors/#ts2561
230
- if (String(code) === '2353' || String(code) === '2561') {
231
- return false;
232
- }
233
- return true;
234
- },
235
- },
226
+ ...strictPropsCheck
227
+ ? codeFeatures_1.codeFeatures.verification
228
+ : codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
236
229
  });
237
230
  }
238
231
  function getModelPropName(node, vueCompilerOptions) {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateInterpolation = generateInterpolation;
4
4
  const shared_1 = require("@vue/shared");
5
+ const collectBindings_1 = require("../../utils/collectBindings");
5
6
  const shared_2 = require("../../utils/shared");
6
7
  const utils_1 = require("../utils");
7
8
  // https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
@@ -133,7 +134,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars, isRoot = false) {
133
134
  walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars);
134
135
  }
135
136
  else if (ts.isVariableDeclaration(node)) {
136
- const bindingNames = (0, utils_1.collectBindingNames)(ts, node.name, ast);
137
+ const bindingNames = (0, collectBindings_1.collectBindingNames)(ts, node.name, ast);
137
138
  for (const name of bindingNames) {
138
139
  ctx.addLocalVariable(name);
139
140
  blockVars.push(name);
@@ -195,7 +196,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars, isRoot = false) {
195
196
  function walkIdentifiersInFunction(ts, node, ast, cb, ctx) {
196
197
  const functionArgs = [];
197
198
  for (const param of node.parameters) {
198
- functionArgs.push(...(0, utils_1.collectBindingNames)(ts, param.name, ast));
199
+ functionArgs.push(...(0, collectBindings_1.collectBindingNames)(ts, param.name, ast));
199
200
  if (param.type) {
200
201
  walkIdentifiersInTypeNode(ts, param.type, cb);
201
202
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVFor = generateVFor;
4
4
  exports.parseVForNode = parseVForNode;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
+ const collectBindings_1 = require("../../utils/collectBindings");
6
7
  const utils_1 = require("../utils");
7
8
  const elementChildren_1 = require("./elementChildren");
8
9
  const interpolation_1 = require("./interpolation");
@@ -13,7 +14,7 @@ function* generateVFor(options, ctx, node) {
13
14
  yield `for (const [`;
14
15
  if (leftExpressionRange && leftExpressionText) {
15
16
  const collectAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `const [${leftExpressionText}]`);
16
- forBlockVars.push(...(0, utils_1.collectBindingNames)(options.ts, collectAst, collectAst));
17
+ forBlockVars.push(...(0, collectBindings_1.collectBindingNames)(options.ts, collectAst, collectAst));
17
18
  yield [
18
19
  leftExpressionText,
19
20
  'template',
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVSlot = generateVSlot;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
+ const collectBindings_1 = require("../../utils/collectBindings");
5
6
  const shared_1 = require("../../utils/shared");
6
7
  const utils_1 = require("../utils");
7
8
  const wrapWith_1 = require("../utils/wrapWith");
@@ -35,7 +36,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
35
36
  }
36
37
  if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
37
38
  const slotAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `(${slotDir.exp.content}) => {}`);
38
- slotBlockVars.push(...(0, utils_1.collectBindingNames)(options.ts, slotAst, slotAst));
39
+ slotBlockVars.push(...(0, collectBindings_1.collectBindingNames)(options.ts, slotAst, slotAst));
39
40
  yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
40
41
  }
41
42
  for (const varName of slotBlockVars) {
@@ -45,11 +46,6 @@ function* generateVSlot(options, ctx, node, slotDir) {
45
46
  for (const varName of slotBlockVars) {
46
47
  ctx.removeLocalVariable(varName);
47
48
  }
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
49
  if (slotDir) {
54
50
  let isStatic = true;
55
51
  if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=tenp.js.map
@@ -5,16 +5,6 @@ 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 collectBindingNames(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string[];
9
- export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
10
- id: ts.Identifier;
11
- isRest: boolean;
12
- initializer: ts.Expression | undefined;
13
- }[], isRest?: boolean, initializer?: ts.Expression | undefined): {
14
- id: ts.Identifier;
15
- isRest: boolean;
16
- initializer: ts.Expression | undefined;
17
- }[];
18
8
  export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
19
9
  export declare function createTsAst(ts: typeof import('typescript'), inlineTsAsts: Map<string, ts.SourceFile> | undefined, text: string): ts.SourceFile;
20
10
  export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
@@ -1,40 +1,13 @@
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.collectBindingNames = collectBindingNames;
5
- exports.collectIdentifiers = collectIdentifiers;
6
4
  exports.normalizeAttributeValue = normalizeAttributeValue;
7
5
  exports.createTsAst = createTsAst;
8
6
  exports.generateSfcBlockSection = generateSfcBlockSection;
9
- const shared_1 = require("../../utils/shared");
10
7
  exports.newLine = `\n`;
11
8
  exports.endOfLine = `;${exports.newLine}`;
12
9
  exports.combineLastMapping = { __combineOffset: 1 };
13
10
  exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
14
- function collectBindingNames(ts, node, ast) {
15
- return collectIdentifiers(ts, node).map(({ id }) => (0, shared_1.getNodeText)(ts, id, ast));
16
- }
17
- function collectIdentifiers(ts, node, results = [], isRest = false, initializer = undefined) {
18
- if (ts.isIdentifier(node)) {
19
- results.push({ id: node, isRest, initializer });
20
- }
21
- else if (ts.isObjectBindingPattern(node)) {
22
- for (const el of node.elements) {
23
- collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken, el.initializer);
24
- }
25
- }
26
- else if (ts.isArrayBindingPattern(node)) {
27
- for (const el of node.elements) {
28
- if (ts.isBindingElement(el)) {
29
- collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
30
- }
31
- }
32
- }
33
- else {
34
- ts.forEachChild(node, node => collectIdentifiers(ts, node, results, false));
35
- }
36
- return results;
37
- }
38
11
  function normalizeAttributeValue(node) {
39
12
  let offset = node.loc.start.offset;
40
13
  let content = node.loc.source;
@@ -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
@@ -72,5 +72,4 @@ export declare function parseBindingRanges(ts: typeof import('typescript'), ast:
72
72
  isDefaultImport?: boolean;
73
73
  isNamespace?: boolean;
74
74
  }[];
75
- export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, ast: ts.SourceFile): TextRange[];
76
75
  export {};
@@ -2,8 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptSetupRanges = parseScriptSetupRanges;
4
4
  exports.parseBindingRanges = parseBindingRanges;
5
- exports.findBindingVars = findBindingVars;
6
- const utils_1 = require("../codegen/utils");
5
+ const collectBindings_1 = require("../utils/collectBindings");
7
6
  const shared_1 = require("../utils/shared");
8
7
  const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
9
8
  function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
@@ -147,7 +146,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
147
146
  };
148
147
  if (ts.isVariableDeclaration(parent) && ts.isObjectBindingPattern(parent.name)) {
149
148
  defineProps.destructured = new Map();
150
- const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name);
149
+ const identifiers = (0, collectBindings_1.collectBindingIdentifiers)(ts, parent.name);
151
150
  for (const { id, isRest, initializer } of identifiers) {
152
151
  const name = _getNodeText(id);
153
152
  if (isRest) {
@@ -267,8 +266,8 @@ function parseBindingRanges(ts, ast) {
267
266
  ts.forEachChild(ast, node => {
268
267
  if (ts.isVariableStatement(node)) {
269
268
  for (const decl of node.declarationList.declarations) {
270
- const vars = _findBindingVars(decl.name);
271
- bindings.push(...vars.map(range => ({ range })));
269
+ const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
270
+ bindings.push(...ranges.map(range => ({ range })));
272
271
  }
273
272
  }
274
273
  else if (ts.isFunctionDeclaration(node)) {
@@ -332,41 +331,6 @@ function parseBindingRanges(ts, ast) {
332
331
  function _getNodeText(node) {
333
332
  return (0, shared_1.getNodeText)(ts, node, ast);
334
333
  }
335
- function _findBindingVars(left) {
336
- return findBindingVars(ts, left, ast);
337
- }
338
- }
339
- function findBindingVars(ts, left, ast) {
340
- const vars = [];
341
- worker(left);
342
- return vars;
343
- function worker(node) {
344
- if (ts.isIdentifier(node)) {
345
- vars.push((0, shared_1.getStartEnd)(ts, node, ast));
346
- }
347
- // { ? } = ...
348
- // [ ? ] = ...
349
- else if (ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node)) {
350
- for (const property of node.elements) {
351
- if (ts.isBindingElement(property)) {
352
- worker(property.name);
353
- }
354
- }
355
- }
356
- // { foo: ? } = ...
357
- else if (ts.isPropertyAssignment(node)) {
358
- worker(node.initializer);
359
- }
360
- // { foo } = ...
361
- else if (ts.isShorthandPropertyAssignment(node)) {
362
- vars.push((0, shared_1.getStartEnd)(ts, node.name, ast));
363
- }
364
- // { ...? } = ...
365
- // [ ...? ] = ...
366
- else if (ts.isSpreadAssignment(node) || ts.isSpreadElement(node)) {
367
- worker(node.expression);
368
- }
369
- }
370
334
  }
371
335
  function getStatementRange(ts, parents, node, ast) {
372
336
  let statementRange;
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const parseSfc_1 = require("../utils/parseSfc");
4
+ const plugin = ({ vueCompilerOptions }) => {
5
+ return {
6
+ version: 2.1,
7
+ getLanguageId(fileName) {
8
+ if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
9
+ return 'vue';
10
+ }
11
+ },
12
+ isValidFile(_fileName, languageId) {
13
+ return languageId === 'vue';
14
+ },
15
+ parseSFC2(_fileName, languageId, content) {
16
+ if (languageId !== 'vue') {
17
+ return;
18
+ }
19
+ return (0, parseSfc_1.parse)(content);
20
+ },
21
+ updateSFC(sfc, change) {
22
+ const blocks = [
23
+ sfc.descriptor.template,
24
+ sfc.descriptor.script,
25
+ sfc.descriptor.scriptSetup,
26
+ ...sfc.descriptor.styles,
27
+ ...sfc.descriptor.customBlocks,
28
+ ].filter(block => !!block);
29
+ const hitBlock = blocks.find(block => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset);
30
+ if (!hitBlock) {
31
+ return;
32
+ }
33
+ const oldContent = hitBlock.content;
34
+ const newContent = hitBlock.content = hitBlock.content.slice(0, change.start - hitBlock.loc.start.offset)
35
+ + change.newText
36
+ + hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
37
+ // #3449
38
+ const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
39
+ const insertedEndTag = endTagRegex.test(oldContent) !== endTagRegex.test(newContent);
40
+ if (insertedEndTag) {
41
+ return;
42
+ }
43
+ const lengthDiff = change.newText.length - (change.end - change.start);
44
+ for (const block of blocks) {
45
+ if (block.loc.start.offset > change.end) {
46
+ block.loc.start.offset += lengthDiff;
47
+ }
48
+ if (block.loc.end.offset >= change.end) {
49
+ block.loc.end.offset += lengthDiff;
50
+ }
51
+ }
52
+ return sfc;
53
+ },
54
+ };
55
+ };
56
+ exports.default = plugin;
57
+ //# sourceMappingURL=file-css.js.map
@@ -15,23 +15,16 @@ const plugin = () => {
15
15
  if (embeddedFile.id === 'root_tags') {
16
16
  embeddedFile.content.push([sfc.content, undefined, 0, shared_1.allCodeFeatures]);
17
17
  for (const block of [
18
+ sfc.template,
18
19
  sfc.script,
19
20
  sfc.scriptSetup,
20
- sfc.template,
21
21
  ...sfc.styles,
22
22
  ...sfc.customBlocks,
23
23
  ]) {
24
24
  if (!block) {
25
25
  continue;
26
26
  }
27
- let content = block.content;
28
- if (content.endsWith('\r\n')) {
29
- content = content.slice(0, -2);
30
- }
31
- else if (content.endsWith('\n')) {
32
- content = content.slice(0, -1);
33
- }
34
- const offset = content.lastIndexOf('\n') + 1;
27
+ const offset = block.content.lastIndexOf('\n', block.content.lastIndexOf('\n') - 1) + 1;
35
28
  // fix folding range end position failed to mapping
36
29
  (0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart, sfc.content.slice(block.startTagEnd, block.startTagEnd + offset), [
37
30
  '',
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const plugin = () => {
4
+ return {
5
+ version: 2.1,
6
+ compileSFCStyle(_lang, style) {
7
+ return {
8
+ imports: [...parseCssImports(style)],
9
+ bindings: [...parseCssBindings(style)],
10
+ classNames: [...parseCssClassNames(style)],
11
+ };
12
+ },
13
+ };
14
+ };
15
+ exports.default = plugin;
16
+ const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
17
+ const cssBindingReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi;
18
+ const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#)[{])/gi;
19
+ const commentReg = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
20
+ const fragmentReg = /(?<={)[^{]*(?=(?<!\\);)/g;
21
+ function* parseCssImports(css) {
22
+ const matches = css.matchAll(cssImportReg);
23
+ for (const match of matches) {
24
+ let text = match[0];
25
+ let offset = match.index;
26
+ if (text.startsWith("'") || text.startsWith('"')) {
27
+ text = text.slice(1, -1);
28
+ offset += 1;
29
+ }
30
+ if (text) {
31
+ yield { text, offset };
32
+ }
33
+ }
34
+ }
35
+ function* parseCssBindings(css) {
36
+ css = fillBlank(css, commentReg);
37
+ const matchs = css.matchAll(cssBindingReg);
38
+ for (const match of matchs) {
39
+ const matchText = match.slice(1).find(t => t);
40
+ if (matchText) {
41
+ const offset = match.index + css.slice(match.index).indexOf(matchText);
42
+ yield { offset, text: matchText };
43
+ }
44
+ }
45
+ }
46
+ function* parseCssClassNames(css) {
47
+ css = fillBlank(css, commentReg, fragmentReg);
48
+ const matches = css.matchAll(cssClassNameReg);
49
+ for (const match of matches) {
50
+ const matchText = match[1];
51
+ if (matchText) {
52
+ yield { offset: match.index, text: matchText };
53
+ }
54
+ }
55
+ }
56
+ function fillBlank(css, ...regs) {
57
+ for (const reg of regs) {
58
+ css = css.replace(reg, match => ' '.repeat(match.length));
59
+ }
60
+ return css;
61
+ }
62
+ //# sourceMappingURL=vue-style-css.js.map
@@ -1,5 +1,6 @@
1
1
  import type { Code, Sfc, VueLanguagePlugin } from '../types';
2
2
  export declare const tsCodegen: WeakMap<Sfc, {
3
+ getLang: () => string;
3
4
  getScriptRanges: () => {
4
5
  exportDefault: (import("../types").TextRange & {
5
6
  expression: import("../types").TextRange;
@@ -115,7 +116,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
115
116
  name?: string;
116
117
  })[];
117
118
  } | undefined;
118
- getLang: () => string;
119
+ getSetupSlotsAssignName: () => string | undefined;
119
120
  getGeneratedScript: () => {
120
121
  codes: Code[];
121
122
  generatedTemplate: boolean;
@@ -166,6 +167,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
166
167
  withoutHighlightAndCompletion: import("../types").VueCodeInformation;
167
168
  withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
168
169
  withoutSemantic: import("../types").VueCodeInformation;
170
+ doNotReportTs2339AndTs2551: import("../types").VueCodeInformation;
171
+ doNotReportTs2353AndTs2561: import("../types").VueCodeInformation;
172
+ doNotReportTs6133: import("../types").VueCodeInformation;
169
173
  };
170
174
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
171
175
  inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
@@ -199,7 +203,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
199
203
  }[]>;
200
204
  currentComponent: {
201
205
  ctxVar: string;
202
- childTypes: string[];
203
206
  used: boolean;
204
207
  } | undefined;
205
208
  singleRootElTypes: string[];
@@ -198,9 +198,10 @@ function createTsx(fileName, sfc, ctx) {
198
198
  };
199
199
  });
200
200
  return {
201
+ getLang,
201
202
  getScriptRanges,
202
203
  getScriptSetupRanges,
203
- getLang,
204
+ getSetupSlotsAssignName,
204
205
  getGeneratedScript,
205
206
  getGeneratedTemplate,
206
207
  };
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,12 +20,11 @@ export type Code = Segment<VueCodeInformation>;
19
20
  export interface VueCompilerOptions {
20
21
  target: number;
21
22
  lib: string;
22
- globalTypesPath?: string;
23
+ globalTypesPath: (fileName: string) => string | void;
23
24
  extensions: string[];
24
25
  vitePressExtensions: string[];
25
26
  petiteVueExtensions: string[];
26
27
  jsxSlots: boolean;
27
- strictSlotChildren: boolean;
28
28
  strictVModel: boolean;
29
29
  strictCssModules: boolean;
30
30
  checkUnknownProps: boolean;
@@ -0,0 +1,12 @@
1
+ import type * as ts from 'typescript';
2
+ export declare function collectBindingNames(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string[];
3
+ export declare function collectBindingRanges(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): import("../types").TextRange[];
4
+ export declare function collectBindingIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
5
+ id: ts.Identifier;
6
+ isRest: boolean;
7
+ initializer: ts.Expression | undefined;
8
+ }[], isRest?: boolean, initializer?: ts.Expression | undefined): {
9
+ id: ts.Identifier;
10
+ isRest: boolean;
11
+ initializer: ts.Expression | undefined;
12
+ }[];
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectBindingNames = collectBindingNames;
4
+ exports.collectBindingRanges = collectBindingRanges;
5
+ exports.collectBindingIdentifiers = collectBindingIdentifiers;
6
+ const shared_1 = require("./shared");
7
+ function collectBindingNames(ts, node, ast) {
8
+ return collectBindingIdentifiers(ts, node).map(({ id }) => (0, shared_1.getNodeText)(ts, id, ast));
9
+ }
10
+ function collectBindingRanges(ts, node, ast) {
11
+ return collectBindingIdentifiers(ts, node).map(({ id }) => (0, shared_1.getStartEnd)(ts, id, ast));
12
+ }
13
+ function collectBindingIdentifiers(ts, node, results = [], isRest = false, initializer = undefined) {
14
+ if (ts.isIdentifier(node)) {
15
+ results.push({ id: node, isRest, initializer });
16
+ }
17
+ else if (ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node)) {
18
+ for (const el of node.elements) {
19
+ if (ts.isBindingElement(el)) {
20
+ collectBindingIdentifiers(ts, el.name, results, !!el.dotDotDotToken, el.initializer);
21
+ }
22
+ }
23
+ }
24
+ else {
25
+ ts.forEachChild(node, node => collectBindingIdentifiers(ts, node, results, false));
26
+ }
27
+ return results;
28
+ }
29
+ //# sourceMappingURL=collectBindings.js.map
package/lib/utils/ts.d.ts CHANGED
@@ -10,12 +10,14 @@ export declare function createParsedCommandLine(ts: typeof import('typescript'),
10
10
  export declare class CompilerOptionsResolver {
11
11
  fileExists?: ((path: string) => boolean) | undefined;
12
12
  configRoots: Set<string>;
13
- options: Omit<RawVueCompilerOptions, 'target' | 'plugin'>;
13
+ options: Omit<RawVueCompilerOptions, 'target' | 'globalTypesPath' | 'plugins'>;
14
14
  target: number | undefined;
15
15
  globalTypesPath: string | undefined;
16
16
  plugins: VueLanguagePlugin[];
17
17
  constructor(fileExists?: ((path: string) => boolean) | undefined);
18
18
  addConfig(options: RawVueCompilerOptions, rootDir: string): void;
19
19
  build(defaults?: VueCompilerOptions): VueCompilerOptions;
20
+ private findNodeModulesRoot;
20
21
  }
21
22
  export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
23
+ export declare function writeGlobalTypes(vueOptions: VueCompilerOptions, writeFile: (fileName: string, data: string) => void): void;
package/lib/utils/ts.js CHANGED
@@ -4,6 +4,7 @@ exports.CompilerOptionsResolver = void 0;
4
4
  exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
5
5
  exports.createParsedCommandLine = createParsedCommandLine;
6
6
  exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
7
+ exports.writeGlobalTypes = writeGlobalTypes;
7
8
  const shared_1 = require("@vue/shared");
8
9
  const path_browserify_1 = require("path-browserify");
9
10
  const globalTypes_1 = require("../codegen/globalTypes");
@@ -178,25 +179,38 @@ class CompilerOptionsResolver {
178
179
  // https://vuejs.org/guide/essentials/forms.html#form-input-bindings
179
180
  experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
180
181
  };
181
- if (this.fileExists && this.globalTypesPath === undefined) {
182
- root: for (const rootDir of [...this.configRoots].reverse()) {
183
- let dir = rootDir;
184
- while (!this.fileExists(path_browserify_1.posix.join(dir, 'node_modules', resolvedOptions.lib, 'package.json'))) {
185
- const parentDir = path_browserify_1.posix.dirname(dir);
186
- if (dir === parentDir) {
187
- continue root;
182
+ if (resolvedOptions.globalTypesPath === shared_1.NOOP) {
183
+ if (this.fileExists && this.globalTypesPath === undefined) {
184
+ const fileDirToGlobalTypesPath = new Map();
185
+ resolvedOptions.globalTypesPath = fileName => {
186
+ const fileDir = path_browserify_1.posix.dirname(fileName);
187
+ if (fileDirToGlobalTypesPath.has(fileDir)) {
188
+ return fileDirToGlobalTypesPath.get(fileDir);
188
189
  }
189
- dir = parentDir;
190
- }
191
- resolvedOptions.globalTypesPath = path_browserify_1.posix.join(dir, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions));
192
- break;
190
+ const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
191
+ const result = root
192
+ ? path_browserify_1.posix.join(root, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions))
193
+ : undefined;
194
+ fileDirToGlobalTypesPath.set(fileDir, result);
195
+ return result;
196
+ };
197
+ }
198
+ else {
199
+ resolvedOptions.globalTypesPath = () => this.globalTypesPath;
193
200
  }
194
- }
195
- else {
196
- resolvedOptions.globalTypesPath = this.globalTypesPath;
197
201
  }
198
202
  return resolvedOptions;
199
203
  }
204
+ findNodeModulesRoot(dir, lib) {
205
+ while (!this.fileExists(path_browserify_1.posix.join(dir, 'node_modules', lib, 'package.json'))) {
206
+ const parentDir = path_browserify_1.posix.dirname(dir);
207
+ if (dir === parentDir) {
208
+ return;
209
+ }
210
+ dir = parentDir;
211
+ }
212
+ return dir;
213
+ }
200
214
  }
201
215
  exports.CompilerOptionsResolver = CompilerOptionsResolver;
202
216
  function findVueVersion(rootDir) {
@@ -227,11 +241,11 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
227
241
  return {
228
242
  target,
229
243
  lib,
244
+ globalTypesPath: shared_1.NOOP,
230
245
  extensions: ['.vue'],
231
246
  vitePressExtensions: [],
232
247
  petiteVueExtensions: [],
233
248
  jsxSlots: false,
234
- strictSlotChildren: strictTemplates,
235
249
  strictVModel: strictTemplates,
236
250
  strictCssModules: false,
237
251
  checkUnknownProps: strictTemplates,
@@ -287,4 +301,19 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
287
301
  },
288
302
  };
289
303
  }
304
+ function writeGlobalTypes(vueOptions, writeFile) {
305
+ const originalFn = vueOptions.globalTypesPath;
306
+ if (!originalFn) {
307
+ return;
308
+ }
309
+ const writed = new Set();
310
+ vueOptions.globalTypesPath = (fileName) => {
311
+ const result = originalFn(fileName);
312
+ if (result && !writed.has(result)) {
313
+ writed.add(result);
314
+ writeFile(result, (0, globalTypes_1.generateGlobalTypes)(vueOptions));
315
+ }
316
+ return result;
317
+ };
318
+ }
290
319
  //# sourceMappingURL=ts.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "2.4.19",
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",
@@ -26,7 +26,7 @@
26
26
  "@types/node": "^22.10.4",
27
27
  "@types/path-browserify": "^1.0.1",
28
28
  "@types/picomatch": "^4.0.0",
29
- "@volar/typescript": "2.4.19",
29
+ "@volar/typescript": "2.4.20",
30
30
  "@vue/compiler-sfc": "^3.5.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -37,5 +37,5 @@
37
37
  "optional": true
38
38
  }
39
39
  },
40
- "gitHead": "7343119e9ca4f6a54f63b57f448f15df4b592a9a"
40
+ "gitHead": "148d386f9779c2de64cdcbd35310e03b36943b05"
41
41
  }