@vue/language-core 3.0.4 → 3.0.6

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 (61) hide show
  1. package/lib/codegen/codeFeatures.d.ts +0 -17
  2. package/lib/codegen/codeFeatures.js +0 -13
  3. package/lib/codegen/script/component.d.ts +1 -1
  4. package/lib/codegen/script/component.js +10 -14
  5. package/lib/codegen/script/componentSelf.js +19 -23
  6. package/lib/codegen/script/context.d.ts +0 -6
  7. package/lib/codegen/script/index.d.ts +2 -1
  8. package/lib/codegen/script/index.js +16 -4
  9. package/lib/codegen/script/scriptSetup.js +2 -2
  10. package/lib/codegen/script/template.d.ts +0 -1
  11. package/lib/codegen/script/template.js +6 -43
  12. package/lib/codegen/template/context.d.ts +0 -22
  13. package/lib/codegen/template/context.js +0 -6
  14. package/lib/codegen/template/element.js +17 -27
  15. package/lib/codegen/template/elementDirectives.js +10 -10
  16. package/lib/codegen/template/elementEvents.d.ts +1 -1
  17. package/lib/codegen/template/elementEvents.js +17 -19
  18. package/lib/codegen/template/elementProps.js +14 -14
  19. package/lib/codegen/template/index.d.ts +3 -2
  20. package/lib/codegen/template/index.js +25 -13
  21. package/lib/codegen/template/interpolation.js +2 -1
  22. package/lib/codegen/template/slotOutlet.js +8 -7
  23. package/lib/codegen/template/styleScopedClasses.js +9 -12
  24. package/lib/codegen/template/templateChild.js +2 -1
  25. package/lib/codegen/template/vFor.js +4 -3
  26. package/lib/codegen/template/vIf.js +2 -1
  27. package/lib/codegen/template/vSlot.js +9 -8
  28. package/lib/plugins/file-html.js +1 -1
  29. package/lib/plugins/file-md.js +1 -1
  30. package/lib/plugins/file-vue.js +17 -2
  31. package/lib/plugins/vue-root-tags.js +1 -1
  32. package/lib/plugins/vue-script-js.js +1 -1
  33. package/lib/plugins/vue-sfc-customblocks.js +1 -1
  34. package/lib/plugins/vue-sfc-scripts.js +1 -1
  35. package/lib/plugins/vue-sfc-styles.js +5 -5
  36. package/lib/plugins/vue-sfc-template.js +1 -1
  37. package/lib/plugins/vue-style-css.js +1 -1
  38. package/lib/plugins/vue-template-html.js +1 -1
  39. package/lib/plugins/vue-template-inline-css.js +1 -1
  40. package/lib/plugins/vue-template-inline-ts.js +1 -1
  41. package/lib/plugins/vue-tsx.d.ts +0 -22
  42. package/lib/plugins/vue-tsx.js +17 -20
  43. package/lib/plugins.js +2 -0
  44. package/lib/types.d.ts +3 -2
  45. package/lib/types.js +1 -1
  46. package/lib/utils/shared.d.ts +3 -1
  47. package/lib/utils/shared.js +13 -0
  48. package/lib/utils/ts.d.ts +7 -6
  49. package/lib/utils/ts.js +43 -66
  50. package/lib/virtualFile/computedSfc.js +13 -8
  51. package/package.json +4 -4
  52. package/lib/codegen/tenp.d.ts +0 -1
  53. package/lib/codegen/tenp.js +0 -3
  54. package/lib/plugins/file-css.d.ts +0 -3
  55. package/lib/plugins/file-css.js +0 -57
  56. package/lib/utils/parseCssClassNames.d.ts +0 -4
  57. package/lib/utils/parseCssClassNames.js +0 -17
  58. package/lib/utils/parseCssImports.d.ts +0 -4
  59. package/lib/utils/parseCssImports.js +0 -19
  60. package/lib/utils/parseCssVars.d.ts +0 -6
  61. package/lib/utils/parseCssVars.js +0 -26
@@ -30,10 +30,6 @@ declare const raw: {
30
30
  shouldRename: () => false;
31
31
  };
32
32
  };
33
- navigationAndCompletion: {
34
- navigation: true;
35
- completion: true;
36
- };
37
33
  navigationAndAdditionalCompletion: {
38
34
  navigation: true;
39
35
  completion: {
@@ -62,13 +58,6 @@ declare const raw: {
62
58
  navigation: true;
63
59
  completion: true;
64
60
  };
65
- withoutHighlightAndNavigation: {
66
- semantic: {
67
- shouldHighlight: () => false;
68
- };
69
- verification: true;
70
- completion: true;
71
- };
72
61
  withoutHighlightAndCompletion: {
73
62
  semantic: {
74
63
  shouldHighlight: () => false;
@@ -76,12 +65,6 @@ declare const raw: {
76
65
  verification: true;
77
66
  navigation: true;
78
67
  };
79
- withoutHighlightAndCompletionAndNavigation: {
80
- semantic: {
81
- shouldHighlight: () => false;
82
- };
83
- verification: true;
84
- };
85
68
  withoutSemantic: {
86
69
  verification: true;
87
70
  navigation: true;
@@ -28,10 +28,6 @@ const raw = {
28
28
  navigationWithoutRename: {
29
29
  navigation: { shouldRename: () => false },
30
30
  },
31
- navigationAndCompletion: {
32
- navigation: true,
33
- completion: true,
34
- },
35
31
  navigationAndAdditionalCompletion: {
36
32
  navigation: true,
37
33
  completion: { isAdditional: true },
@@ -54,20 +50,11 @@ const raw = {
54
50
  navigation: true,
55
51
  completion: true,
56
52
  },
57
- withoutHighlightAndNavigation: {
58
- semantic: { shouldHighlight: () => false },
59
- verification: true,
60
- completion: true,
61
- },
62
53
  withoutHighlightAndCompletion: {
63
54
  semantic: { shouldHighlight: () => false },
64
55
  verification: true,
65
56
  navigation: true,
66
57
  },
67
- withoutHighlightAndCompletionAndNavigation: {
68
- semantic: { shouldHighlight: () => false },
69
- verification: true,
70
- },
71
58
  withoutSemantic: {
72
59
  verification: true,
73
60
  navigation: true,
@@ -3,6 +3,6 @@ import type { Code, Sfc } from '../../types';
3
3
  import type { ScriptCodegenContext } from './context';
4
4
  import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
- export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
+ export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<string>;
7
7
  export declare function generateEmitsOption(options: ScriptCodegenOptions, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
8
8
  export declare function generatePropsOption(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, hasEmitsOption: boolean, inheritAttrs: boolean): Generator<Code>;
@@ -17,23 +17,18 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
17
17
  else {
18
18
  yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
19
19
  }
20
- yield `setup() {${utils_1.newLine}`;
21
20
  const returns = [];
22
21
  if (ctx.bypassDefineComponent) {
23
- yield* `const __VLS_returns = {${utils_1.newLine}`;
24
- yield* generateComponentSetupReturns(scriptSetupRanges);
25
- yield `}${utils_1.endOfLine}`;
26
- returns.push(`typeof __VLS_returns`);
22
+ returns.push(...generateComponentSetupReturns(scriptSetupRanges));
27
23
  }
28
24
  if (scriptSetupRanges.defineExpose) {
29
- returns.push(`typeof __VLS_exposed`);
25
+ returns.push(`__VLS_exposed`);
30
26
  }
31
27
  if (returns.length) {
32
- yield `return {} as `;
33
- yield* (0, merge_1.generateIntersectMerge)(returns);
34
- yield utils_1.endOfLine;
28
+ yield `setup: () => (`;
29
+ yield* (0, merge_1.generateSpreadMerge)(returns);
30
+ yield `),${utils_1.newLine}`;
35
31
  }
36
- yield `},${utils_1.newLine}`;
37
32
  if (!ctx.bypassDefineComponent) {
38
33
  const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
39
34
  yield* emitOptionCodes;
@@ -58,13 +53,14 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
58
53
  function* generateComponentSetupReturns(scriptSetupRanges) {
59
54
  // fill $props
60
55
  if (scriptSetupRanges.defineProps) {
56
+ const name = scriptSetupRanges.defineProps.name ?? `__VLS_props`;
61
57
  // NOTE: defineProps is inaccurate for $props
62
- yield `$props: __VLS_makeOptional(${scriptSetupRanges.defineProps.name ?? `__VLS_props`}),${utils_1.newLine}`;
63
- yield `...${scriptSetupRanges.defineProps.name ?? `__VLS_props`},${utils_1.newLine}`;
58
+ yield name;
59
+ yield `{} as { $props: Partial<typeof ${name}> }`;
64
60
  }
65
61
  // fill $emit
66
62
  if (scriptSetupRanges.defineEmits) {
67
- yield `$emit: ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'},${utils_1.newLine}`;
63
+ yield `{} as { $emit: typeof ${scriptSetupRanges.defineEmits.name ?? `__VLS_emit`} }`;
68
64
  }
69
65
  }
70
66
  function* generateEmitsOption(options, scriptSetupRanges) {
@@ -99,7 +95,7 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
99
95
  const getOptionCodes = [];
100
96
  const typeOptionCodes = [];
101
97
  if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
102
- let attrsType = `Partial<__VLS_InheritedAttrs>`;
98
+ let attrsType = `__VLS_InheritedAttrs`;
103
99
  if (hasEmitsOption) {
104
100
  attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
105
101
  }
@@ -1,41 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateComponentSelf = generateComponentSelf;
4
+ const shared_1 = require("@vue/shared");
4
5
  const path = require("path-browserify");
5
6
  const codeFeatures_1 = require("../codeFeatures");
6
7
  const utils_1 = require("../utils");
7
8
  const component_1 = require("./component");
8
- const template_1 = require("./template");
9
9
  function* generateComponentSelf(options, ctx, templateCodegenCtx) {
10
10
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
11
11
  yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
12
- yield `setup() {${utils_1.newLine}`;
13
- yield `return {${utils_1.newLine}`;
12
+ yield `setup: () => ({${utils_1.newLine}`;
14
13
  if (ctx.bypassDefineComponent) {
15
- yield* (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges);
14
+ for (const code of (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges)) {
15
+ yield `...${code},${utils_1.newLine}`;
16
+ }
16
17
  }
17
18
  // bindings
18
- const templateUsageVars = (0, template_1.getTemplateUsageVars)(options, ctx);
19
- for (const [content, bindings] of [
20
- [options.sfc.scriptSetup.content, options.scriptSetupRanges.bindings],
21
- options.sfc.script && options.scriptRanges
22
- ? [options.sfc.script.content, options.scriptRanges.bindings]
23
- : ['', []],
24
- ]) {
25
- for (const { range } of bindings) {
26
- const varName = content.slice(range.start, range.end);
27
- if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
28
- continue;
29
- }
30
- const token = Symbol(varName.length);
31
- yield ['', undefined, 0, { __linkedToken: token }];
32
- yield `${varName}: ${varName} as typeof `;
33
- yield ['', undefined, 0, { __linkedToken: token }];
34
- yield `${varName},${utils_1.newLine}`;
19
+ const templateUsageVars = new Set([
20
+ ...options.sfc.template?.ast?.components.flatMap(c => [(0, shared_1.camelize)(c), (0, shared_1.capitalize)((0, shared_1.camelize)(c))]) ?? [],
21
+ ...options.templateCodegen?.accessExternalVariables.keys() ?? [],
22
+ ...templateCodegenCtx.accessExternalVariables.keys(),
23
+ ]);
24
+ for (const varName of ctx.bindingNames) {
25
+ if (!templateUsageVars.has(varName)) {
26
+ continue;
35
27
  }
28
+ const token = Symbol(varName.length);
29
+ yield ['', undefined, 0, { __linkedToken: token }];
30
+ yield `${varName}: ${varName} as typeof `;
31
+ yield ['', undefined, 0, { __linkedToken: token }];
32
+ yield `${varName},${utils_1.newLine}`;
36
33
  }
37
- yield `}${utils_1.endOfLine}`; // return {
38
- yield `},${utils_1.newLine}`; // setup() {
34
+ yield `}),${utils_1.newLine}`;
39
35
  if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
40
36
  const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
41
37
  yield* emitOptionCodes;
@@ -1,11 +1,5 @@
1
1
  import type { InlayHintInfo } from '../inlayHints';
2
2
  import type { ScriptCodegenOptions } from './index';
3
- export interface HelperType {
4
- name: string;
5
- used?: boolean;
6
- generated?: boolean;
7
- code: string;
8
- }
9
3
  export type ScriptCodegenContext = ReturnType<typeof createScriptCodegenContext>;
10
4
  export declare function createScriptCodegenContext(options: ScriptCodegenOptions): {
11
5
  generatedTemplate: boolean;
@@ -4,6 +4,7 @@ import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
4
4
  import type { Code, Sfc, VueCompilerOptions } from '../../types';
5
5
  import type { TemplateCodegenContext } from '../template/context';
6
6
  import { type ScriptCodegenContext } from './context';
7
+ export * from './context';
7
8
  export interface ScriptCodegenOptions {
8
9
  ts: typeof ts;
9
10
  compilerOptions: ts.CompilerOptions;
@@ -19,5 +20,5 @@ export interface ScriptCodegenOptions {
19
20
  destructuredPropNames: Set<string>;
20
21
  templateRefNames: Set<string>;
21
22
  }
22
- export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
23
+ export declare function generateScript(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
23
24
  export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.generateScript = generateScript;
4
18
  exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
@@ -6,12 +20,11 @@ const path = require("path-browserify");
6
20
  const codeFeatures_1 = require("../codeFeatures");
7
21
  const utils_1 = require("../utils");
8
22
  const componentSelf_1 = require("./componentSelf");
9
- const context_1 = require("./context");
10
23
  const scriptSetup_1 = require("./scriptSetup");
11
24
  const src_1 = require("./src");
12
25
  const template_1 = require("./template");
13
- function* generateScript(options) {
14
- const ctx = (0, context_1.createScriptCodegenContext)(options);
26
+ __exportStar(require("./context"), exports);
27
+ function* generateScript(options, ctx) {
15
28
  yield* generateGlobalTypesPath(options);
16
29
  if (options.sfc.script?.src) {
17
30
  yield* (0, src_1.generateSrc)(options.sfc.script.src);
@@ -93,7 +106,6 @@ function* generateScript(options) {
93
106
  if (options.sfc.scriptSetup) {
94
107
  yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, codeFeatures_1.codeFeatures.verification];
95
108
  }
96
- return ctx;
97
109
  }
98
110
  function* generateGlobalTypesPath(options) {
99
111
  const globalTypesPath = options.vueCompilerOptions.globalTypesPath(options.fileName);
@@ -54,7 +54,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
54
54
  emitTypes.push(`typeof __VLS_modelEmit`);
55
55
  }
56
56
  yield `return {} as {${utils_1.newLine}`
57
- + ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & Partial<__VLS_InheritedAttrs>> & __VLS_BuiltInPublicProps,${utils_1.newLine}`
57
+ + ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & __VLS_InheritedAttrs> & __VLS_BuiltInPublicProps,${utils_1.newLine}`
58
58
  + ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.defineExpose ? 'typeof __VLS_exposed' : '{}'}>): void,${utils_1.newLine}`
59
59
  + ` attrs: any,${utils_1.newLine}`
60
60
  + ` slots: __VLS_Slots,${utils_1.newLine}`
@@ -400,7 +400,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
400
400
  yield* generateDefineModelType(scriptSetup, propName, localName, defineModel);
401
401
  yield `,${utils_1.newLine}`;
402
402
  if (defineModel.modifierType) {
403
- const modifierName = `${defineModel.name ? propName : 'model'}Modifiers`;
403
+ const modifierName = `${propName === 'modelValue' ? 'model' : propName}Modifiers`;
404
404
  const modifierType = getRangeText(scriptSetup, defineModel.modifierType);
405
405
  yield `'${modifierName}'?: Partial<Record<${modifierType}, true>>,${utils_1.newLine}`;
406
406
  }
@@ -4,4 +4,3 @@ import type { ScriptCodegenContext } from './context';
4
4
  import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code, TemplateCodegenContext>;
6
6
  export declare function generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code>;
7
- export declare function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Set<string>;
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTemplate = generateTemplate;
4
4
  exports.generateTemplateDirectives = generateTemplateDirectives;
5
- exports.getTemplateUsageVars = getTemplateUsageVars;
6
- const shared_1 = require("../../utils/shared");
7
5
  const codeFeatures_1 = require("../codeFeatures");
8
6
  const modules_1 = require("../style/modules");
9
7
  const scopedClasses_1 = require("../style/scopedClasses");
@@ -45,18 +43,11 @@ function* generateTemplateComponents(options) {
45
43
  if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
46
44
  const { componentsOption } = options.scriptRanges.exportDefault;
47
45
  yield `const __VLS_componentsOption = `;
48
- yield [
49
- options.sfc.script.content.slice(componentsOption.start, componentsOption.end),
50
- 'script',
51
- componentsOption.start,
52
- codeFeatures_1.codeFeatures.navigation,
53
- ];
46
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, componentsOption.start, componentsOption.end, codeFeatures_1.codeFeatures.navigation);
54
47
  yield utils_1.endOfLine;
55
48
  types.push(`typeof __VLS_componentsOption`);
56
49
  }
57
- yield `type __VLS_LocalComponents =`;
58
- yield* (0, merge_1.generateIntersectMerge)(types);
59
- yield utils_1.endOfLine;
50
+ yield `type __VLS_LocalComponents = ${types.join(` & `)}${utils_1.endOfLine}`;
60
51
  yield `let __VLS_components!: __VLS_LocalComponents & __VLS_GlobalComponents${utils_1.endOfLine}`;
61
52
  }
62
53
  function* generateTemplateDirectives(options) {
@@ -64,18 +55,11 @@ function* generateTemplateDirectives(options) {
64
55
  if (options.sfc.script && options.scriptRanges?.exportDefault?.directivesOption) {
65
56
  const { directivesOption } = options.scriptRanges.exportDefault;
66
57
  yield `const __VLS_directivesOption = `;
67
- yield [
68
- options.sfc.script.content.slice(directivesOption.start, directivesOption.end),
69
- 'script',
70
- directivesOption.start,
71
- codeFeatures_1.codeFeatures.navigation,
72
- ];
58
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, directivesOption.start, directivesOption.end, codeFeatures_1.codeFeatures.navigation);
73
59
  yield utils_1.endOfLine;
74
60
  types.push(`__VLS_ResolveDirectives<typeof __VLS_directivesOption>`);
75
61
  }
76
- yield `type __VLS_LocalDirectives =`;
77
- yield* (0, merge_1.generateIntersectMerge)(types);
78
- yield utils_1.endOfLine;
62
+ yield `type __VLS_LocalDirectives = ${types.join(` & `)}${utils_1.endOfLine}`;
79
63
  yield `let __VLS_directives!: __VLS_LocalDirectives & __VLS_GlobalDirectives${utils_1.endOfLine}`;
80
64
  }
81
65
  function* generateTemplateBody(options, templateCodegenCtx) {
@@ -101,32 +85,11 @@ function* generateCssVars(options, ctx) {
101
85
  }
102
86
  yield `// CSS variable injection ${utils_1.newLine}`;
103
87
  for (const style of options.sfc.styles) {
104
- for (const cssBind of style.cssVars) {
105
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name, codeFeatures_1.codeFeatures.all, cssBind.text, cssBind.offset);
88
+ for (const binding of style.bindings) {
89
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name, codeFeatures_1.codeFeatures.all, binding.text, binding.offset);
106
90
  yield utils_1.endOfLine;
107
91
  }
108
92
  }
109
93
  yield `// CSS variable injection end ${utils_1.newLine}`;
110
94
  }
111
- function getTemplateUsageVars(options, ctx) {
112
- const usageVars = new Set();
113
- const components = new Set(options.sfc.template?.ast?.components);
114
- if (options.templateCodegen) {
115
- // fix import components unused report
116
- for (const varName of ctx.bindingNames) {
117
- if (components.has(varName) || components.has((0, shared_1.hyphenateTag)(varName))) {
118
- usageVars.add(varName);
119
- }
120
- }
121
- for (const component of components) {
122
- if (component.includes('.')) {
123
- usageVars.add(component.split('.')[0]);
124
- }
125
- }
126
- for (const [varName] of options.templateCodegen.accessExternalVariables) {
127
- usageVars.add(varName);
128
- }
129
- }
130
- return usageVars;
131
- }
132
95
  //# sourceMappingURL=template.js.map
@@ -112,28 +112,6 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
112
112
  offset: number;
113
113
  };
114
114
  };
115
- codeFeatures: {
116
- all: VueCodeInformation;
117
- verification: VueCodeInformation;
118
- completion: VueCodeInformation;
119
- additionalCompletion: VueCodeInformation;
120
- withoutCompletion: VueCodeInformation;
121
- navigation: VueCodeInformation;
122
- navigationWithoutRename: VueCodeInformation;
123
- navigationAndCompletion: VueCodeInformation;
124
- navigationAndAdditionalCompletion: VueCodeInformation;
125
- navigationAndVerification: VueCodeInformation;
126
- withoutNavigation: VueCodeInformation;
127
- semanticWithoutHighlight: VueCodeInformation;
128
- withoutHighlight: VueCodeInformation;
129
- withoutHighlightAndNavigation: VueCodeInformation;
130
- withoutHighlightAndCompletion: VueCodeInformation;
131
- withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
132
- withoutSemantic: VueCodeInformation;
133
- doNotReportTs2339AndTs2551: VueCodeInformation;
134
- doNotReportTs2353AndTs2561: VueCodeInformation;
135
- doNotReportTs6133: VueCodeInformation;
136
- };
137
115
  resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
138
116
  inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
139
117
  inVFor: boolean;
@@ -154,12 +154,6 @@ function createTemplateCodegenContext(options, templateAst) {
154
154
  get currentInfo() {
155
155
  return stack[stack.length - 1];
156
156
  },
157
- codeFeatures: new Proxy(codeFeatures_1.codeFeatures, {
158
- get(target, key) {
159
- const data = target[key];
160
- return resolveCodeFeatures(data);
161
- },
162
- }),
163
157
  resolveCodeFeatures,
164
158
  inlineTsAsts: templateAst && computedSfc_1.templateInlineTsAsts.get(templateAst),
165
159
  inVFor: false,
@@ -20,13 +20,7 @@ const styleScopedClasses_1 = require("./styleScopedClasses");
20
20
  const vSlot_1 = require("./vSlot");
21
21
  const colonReg = /:/g;
22
22
  function* generateComponent(options, ctx, node) {
23
- const tagOffsets = [node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag)];
24
- if (!node.isSelfClosing && options.template.lang === 'html') {
25
- const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
26
- if (endTagOffset > tagOffsets[0]) {
27
- tagOffsets.push(endTagOffset);
28
- }
29
- }
23
+ const tagOffsets = (0, shared_2.getElementTagOffsets)(node, options.template);
30
24
  const failedPropExps = [];
31
25
  const possibleOriginalNames = getPossibleOriginalComponentNames(node.tag, true);
32
26
  const matchImportName = possibleOriginalNames.find(name => options.scriptSetupImportComponentNames.has(name));
@@ -76,12 +70,12 @@ function* generateComponent(options, ctx, node) {
76
70
  componentOriginalVar,
77
71
  'template',
78
72
  tagOffset,
79
- ctx.codeFeatures.withoutHighlightAndCompletion,
73
+ codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
80
74
  ];
81
75
  }
82
76
  else {
83
77
  const shouldCapitalize = matchImportName[0].toUpperCase() === matchImportName[0];
84
- yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
78
+ yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
85
79
  }
86
80
  yield `, `;
87
81
  }
@@ -89,10 +83,10 @@ function* generateComponent(options, ctx, node) {
89
83
  }
90
84
  else if (dynamicTagInfo) {
91
85
  yield `const ${componentOriginalVar} = (`;
92
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, dynamicTagInfo.tag, dynamicTagInfo.offsets[0], `(`, `)`);
86
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, dynamicTagInfo.tag, dynamicTagInfo.offsets[0], `(`, `)`);
93
87
  if (dynamicTagInfo.offsets[1] !== undefined) {
94
88
  yield `,`;
95
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.withoutCompletion, dynamicTagInfo.tag, dynamicTagInfo.offsets[1], `(`, `)`);
89
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.withoutCompletion, dynamicTagInfo.tag, dynamicTagInfo.offsets[1], `(`, `)`);
96
90
  }
97
91
  yield `)${utils_1.endOfLine}`;
98
92
  }
@@ -110,12 +104,12 @@ function* generateComponent(options, ctx, node) {
110
104
  .map(name => `'${name}'`)
111
105
  .join(`, `);
112
106
  yield `>).`;
113
- yield* generateCanonicalComponentName(node.tag, tagOffsets[0], ctx.resolveCodeFeatures({
107
+ yield* generateCanonicalComponentName(node.tag, tagOffsets[0], {
114
108
  ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
115
109
  ...options.vueCompilerOptions.checkUnknownComponents
116
110
  ? codeFeatures_1.codeFeatures.verification
117
111
  : codeFeatures_1.codeFeatures.doNotReportTs2339AndTs2551,
118
- }));
112
+ });
119
113
  yield `${utils_1.endOfLine}`;
120
114
  const camelizedTag = (0, shared_1.camelize)(node.tag);
121
115
  if (utils_1.identifierRegex.test(camelizedTag)) {
@@ -145,11 +139,11 @@ function* generateComponent(options, ctx, node) {
145
139
  yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, false);
146
140
  yield `}))${utils_1.endOfLine}`;
147
141
  yield `const `;
148
- yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.doNotReportTs6133, componentVNodeVar);
142
+ yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, codeFeatures_1.codeFeatures.doNotReportTs6133, componentVNodeVar);
149
143
  yield ` = ${componentFunctionalVar}`;
150
144
  yield* generateComponentGeneric(ctx);
151
145
  yield `(`;
152
- yield* (0, wrapWith_1.wrapWith)(tagOffsets[0], tagOffsets[0] + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
146
+ yield* (0, wrapWith_1.wrapWith)(tagOffsets[0], tagOffsets[0] + node.tag.length, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
153
147
  yield `, ...__VLS_functionalComponentArgsRest(${componentFunctionalVar}))${utils_1.endOfLine}`;
154
148
  yield* generateFailedPropExps(options, ctx, failedPropExps);
155
149
  yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar);
@@ -186,20 +180,16 @@ function* generateComponent(options, ctx, node) {
186
180
  }
187
181
  }
188
182
  function* generateElement(options, ctx, node) {
189
- const startTagOffset = node.loc.start.offset
190
- + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
191
- const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
192
- ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
193
- : undefined;
183
+ const [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
194
184
  const failedPropExps = [];
195
185
  yield `__VLS_asFunctionalElement(__VLS_elements`;
196
- yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
186
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
197
187
  if (endTagOffset !== undefined) {
198
188
  yield `, __VLS_elements`;
199
- yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
189
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
200
190
  }
201
191
  yield `)(`;
202
- yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
192
+ yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
203
193
  yield `)${utils_1.endOfLine}`;
204
194
  yield* generateFailedPropExps(options, ctx, failedPropExps);
205
195
  yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
@@ -225,7 +215,7 @@ function* generateElement(options, ctx, node) {
225
215
  }
226
216
  function* generateFailedPropExps(options, ctx, failedPropExps) {
227
217
  for (const failedExp of failedPropExps) {
228
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, failedExp.node.loc.source, failedExp.node.loc.start.offset, failedExp.prefix, failedExp.suffix);
218
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, failedExp.node.loc.source, failedExp.node.loc.start.offset, failedExp.prefix, failedExp.suffix);
229
219
  yield utils_1.endOfLine;
230
220
  }
231
221
  }
@@ -258,11 +248,11 @@ function* generateCanonicalComponentName(tagText, offset, features) {
258
248
  function* generateComponentGeneric(ctx) {
259
249
  if (ctx.currentInfo.generic) {
260
250
  const { content, offset } = ctx.currentInfo.generic;
261
- yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, ctx.codeFeatures.verification, `<`, [
251
+ yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, codeFeatures_1.codeFeatures.verification, `<`, [
262
252
  content,
263
253
  'template',
264
254
  offset,
265
- ctx.codeFeatures.all,
255
+ codeFeatures_1.codeFeatures.all,
266
256
  ], `>`);
267
257
  }
268
258
  }
@@ -274,7 +264,7 @@ function* generateElementReference(options, ctx, node) {
274
264
  const [content, startOffset] = (0, utils_1.normalizeAttributeValue)(prop.value);
275
265
  // navigation support for `const foo = ref()`
276
266
  yield `/** @type {typeof __VLS_ctx`;
277
- yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, ctx.codeFeatures.navigation);
267
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, codeFeatures_1.codeFeatures.navigation);
278
268
  yield `} */${utils_1.endOfLine}`;
279
269
  if (utils_1.identifierRegex.test(content) && !options.templateRefNames.has(content)) {
280
270
  ctx.accessExternalVariable(content, startOffset);
@@ -30,16 +30,16 @@ function* generateElementDirectives(options, ctx, node) {
30
30
  continue;
31
31
  }
32
32
  ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
33
- yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, `__VLS_asFunctionalDirective(`, ...generateIdentifier(options, ctx, prop), `)(null!, { ...__VLS_directiveBindingRestFields, `, ...generateArg(options, ctx, prop), ...generateModifiers(options, ctx, prop), ...generateValue(options, ctx, prop), ` }, null!, null!)`);
33
+ yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, `__VLS_asFunctionalDirective(`, ...generateIdentifier(options, prop), `)(null!, { ...__VLS_directiveBindingRestFields, `, ...generateArg(options, ctx, prop), ...generateModifiers(options, ctx, prop), ...generateValue(options, ctx, prop), ` }, null!, null!)`);
34
34
  yield utils_1.endOfLine;
35
35
  }
36
36
  }
37
- function* generateIdentifier(options, ctx, prop) {
37
+ function* generateIdentifier(options, prop) {
38
38
  const rawName = 'v-' + prop.name;
39
- yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + rawName.length, ctx.codeFeatures.verification, `__VLS_directives.`, ...(0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, ctx.resolveCodeFeatures({
39
+ yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + rawName.length, codeFeatures_1.codeFeatures.verification, `__VLS_directives.`, ...(0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, {
40
40
  ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
41
41
  verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
42
- })));
42
+ }));
43
43
  }
44
44
  function* generateArg(options, ctx, prop) {
45
45
  const { arg } = prop;
@@ -47,13 +47,13 @@ function* generateArg(options, ctx, prop) {
47
47
  return;
48
48
  }
49
49
  const startOffset = arg.loc.start.offset + arg.loc.source.indexOf(arg.content);
50
- yield* (0, wrapWith_1.wrapWith)(startOffset, startOffset + arg.content.length, ctx.codeFeatures.verification, `arg`);
50
+ yield* (0, wrapWith_1.wrapWith)(startOffset, startOffset + arg.content.length, codeFeatures_1.codeFeatures.verification, `arg`);
51
51
  yield `: `;
52
52
  if (arg.isStatic) {
53
- yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, ctx.codeFeatures.all);
53
+ yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, codeFeatures_1.codeFeatures.all);
54
54
  }
55
55
  else {
56
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, arg.content, startOffset, `(`, `)`);
56
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, arg.content, startOffset, `(`, `)`);
57
57
  }
58
58
  yield `, `;
59
59
  }
@@ -64,10 +64,10 @@ function* generateModifiers(options, ctx, prop, propertyName = 'modifiers') {
64
64
  }
65
65
  const startOffset = modifiers[0].loc.start.offset - 1;
66
66
  const endOffset = modifiers.at(-1).loc.end.offset;
67
- yield* (0, wrapWith_1.wrapWith)(startOffset, endOffset, ctx.codeFeatures.verification, propertyName);
67
+ yield* (0, wrapWith_1.wrapWith)(startOffset, endOffset, codeFeatures_1.codeFeatures.verification, propertyName);
68
68
  yield `: { `;
69
69
  for (const mod of modifiers) {
70
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, ctx.codeFeatures.withoutHighlightAndNavigation);
70
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlight);
71
71
  yield `: true, `;
72
72
  }
73
73
  yield `}, `;
@@ -77,7 +77,7 @@ function* generateValue(options, ctx, prop) {
77
77
  if (exp?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
78
78
  return;
79
79
  }
80
- yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `value`);
80
+ yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `value`);
81
81
  yield `: `;
82
82
  yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp);
83
83
  }
@@ -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(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
7
+ export declare function generateEventArg(options: TemplateCodegenOptions, 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;