@vue/language-core 3.1.5 → 3.1.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 (100) hide show
  1. package/index.d.ts +2 -1
  2. package/index.js +3 -2
  3. package/lib/codegen/codeFeatures.d.ts +5 -9
  4. package/lib/codegen/codeFeatures.js +5 -5
  5. package/lib/codegen/globalTypes.js +12 -18
  6. package/lib/codegen/localTypes.d.ts +1 -1
  7. package/lib/codegen/localTypes.js +6 -6
  8. package/lib/codegen/names.d.ts +30 -0
  9. package/lib/codegen/names.js +34 -0
  10. package/lib/codegen/script/component.js +45 -54
  11. package/lib/codegen/script/context.d.ts +2 -5
  12. package/lib/codegen/script/context.js +1 -7
  13. package/lib/codegen/script/index.d.ts +10 -12
  14. package/lib/codegen/script/index.js +74 -73
  15. package/lib/codegen/script/scriptSetup.d.ts +3 -2
  16. package/lib/codegen/script/scriptSetup.js +209 -283
  17. package/lib/codegen/script/src.js +9 -3
  18. package/lib/codegen/script/template.js +64 -108
  19. package/lib/codegen/style/common.d.ts +3 -0
  20. package/lib/codegen/style/common.js +43 -0
  21. package/lib/codegen/style/index.d.ts +63 -0
  22. package/lib/codegen/style/index.js +38 -0
  23. package/lib/codegen/style/modules.d.ts +3 -2
  24. package/lib/codegen/style/modules.js +12 -11
  25. package/lib/codegen/style/scopedClasses.d.ts +2 -3
  26. package/lib/codegen/style/scopedClasses.js +23 -21
  27. package/lib/codegen/template/context.d.ts +7 -16
  28. package/lib/codegen/template/context.js +81 -93
  29. package/lib/codegen/template/element.js +151 -55
  30. package/lib/codegen/template/elementDirectives.js +32 -12
  31. package/lib/codegen/template/elementEvents.js +27 -28
  32. package/lib/codegen/template/elementProps.d.ts +2 -2
  33. package/lib/codegen/template/elementProps.js +49 -23
  34. package/lib/codegen/template/index.d.ts +8 -19
  35. package/lib/codegen/template/index.js +85 -80
  36. package/lib/codegen/template/interpolation.d.ts +3 -3
  37. package/lib/codegen/template/interpolation.js +90 -136
  38. package/lib/codegen/template/objectProperty.js +8 -4
  39. package/lib/codegen/template/propertyAccess.d.ts +1 -1
  40. package/lib/codegen/template/propertyAccess.js +5 -7
  41. package/lib/codegen/template/slotOutlet.js +25 -8
  42. package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
  43. package/lib/codegen/template/styleScopedClasses.js +23 -149
  44. package/lib/codegen/template/templateChild.d.ts +0 -1
  45. package/lib/codegen/template/templateChild.js +11 -68
  46. package/lib/codegen/template/vFor.js +10 -13
  47. package/lib/codegen/template/vIf.js +5 -3
  48. package/lib/codegen/template/vSlot.js +20 -15
  49. package/lib/codegen/utils/boundary.d.ts +3 -0
  50. package/lib/codegen/utils/boundary.js +13 -0
  51. package/lib/codegen/utils/camelized.js +3 -3
  52. package/lib/codegen/utils/escaped.js +4 -2
  53. package/lib/codegen/utils/index.d.ts +3 -4
  54. package/lib/codegen/utils/index.js +42 -16
  55. package/lib/codegen/utils/merge.d.ts +2 -2
  56. package/lib/codegen/utils/merge.js +9 -9
  57. package/lib/codegen/utils/stringLiteralKey.js +6 -3
  58. package/lib/codegen/utils/transform.d.ts +8 -0
  59. package/lib/codegen/utils/transform.js +27 -0
  60. package/lib/codegen/utils/unicode.js +4 -2
  61. package/lib/compilerOptions.d.ts +5 -2
  62. package/lib/compilerOptions.js +67 -44
  63. package/lib/languagePlugin.d.ts +1 -1
  64. package/lib/languagePlugin.js +2 -2
  65. package/lib/plugins/vue-template-inline-css.js +2 -6
  66. package/lib/plugins/vue-template-inline-ts.js +12 -14
  67. package/lib/plugins/vue-tsx.d.ts +11 -20
  68. package/lib/plugins/vue-tsx.js +121 -68
  69. package/lib/plugins.js +1 -1
  70. package/lib/types.d.ts +5 -4
  71. package/lib/utils/parseSfc.js +7 -3
  72. package/lib/utils/shared.d.ts +1 -1
  73. package/lib/utils/shared.js +7 -6
  74. package/lib/utils/signals.d.ts +2 -2
  75. package/lib/utils/signals.js +8 -6
  76. package/lib/virtualCode/embeddedCodes.d.ts +12 -0
  77. package/lib/virtualCode/embeddedCodes.js +249 -0
  78. package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
  79. package/lib/virtualCode/index.js +81 -0
  80. package/lib/virtualCode/ir.d.ts +4 -0
  81. package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +59 -94
  82. package/lib/virtualCode/normalize.d.ts +2 -0
  83. package/lib/virtualCode/normalize.js +170 -0
  84. package/package.json +4 -4
  85. package/lib/codegen/style/classProperty.d.ts +0 -2
  86. package/lib/codegen/style/classProperty.js +0 -18
  87. package/lib/codegen/style/imports.d.ts +0 -2
  88. package/lib/codegen/style/imports.js +0 -27
  89. package/lib/codegen/template/elementChildren.d.ts +0 -5
  90. package/lib/codegen/template/elementChildren.js +0 -12
  91. package/lib/codegen/utils/wrapWith.d.ts +0 -2
  92. package/lib/codegen/utils/wrapWith.js +0 -15
  93. package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
  94. package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
  95. package/lib/virtualFile/computedSfc.d.ts +0 -6
  96. package/lib/virtualFile/computedVueSfc.d.ts +0 -4
  97. package/lib/virtualFile/computedVueSfc.js +0 -41
  98. package/lib/virtualFile/embeddedFile.d.ts +0 -11
  99. package/lib/virtualFile/embeddedFile.js +0 -14
  100. package/lib/virtualFile/vueFile.js +0 -49
package/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export * from './lib/utils/collectBindings';
9
9
  export * from './lib/utils/forEachTemplateNode';
10
10
  export * from './lib/utils/parseSfc';
11
11
  export * from './lib/utils/shared';
12
- export * from './lib/virtualFile/vueFile';
12
+ export * from './lib/virtualCode';
13
+ export * as names from './lib/codegen/names';
13
14
  export { tsCodegen } from './lib/plugins/vue-tsx';
14
15
  export * from '@volar/language-core';
package/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.tsCodegen = void 0;
17
+ exports.tsCodegen = exports.names = void 0;
18
18
  __exportStar(require("./lib/codegen/globalTypes"), exports);
19
19
  __exportStar(require("./lib/codegen/template"), exports);
20
20
  __exportStar(require("./lib/compilerOptions"), exports);
@@ -26,7 +26,8 @@ __exportStar(require("./lib/utils/collectBindings"), exports);
26
26
  __exportStar(require("./lib/utils/forEachTemplateNode"), exports);
27
27
  __exportStar(require("./lib/utils/parseSfc"), exports);
28
28
  __exportStar(require("./lib/utils/shared"), exports);
29
- __exportStar(require("./lib/virtualFile/vueFile"), exports);
29
+ __exportStar(require("./lib/virtualCode"), exports);
30
+ exports.names = require("./lib/codegen/names");
30
31
  var vue_tsx_1 = require("./lib/plugins/vue-tsx");
31
32
  Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
32
33
  __exportStar(require("@volar/language-core"), exports);
@@ -6,17 +6,15 @@ declare const raw: {
6
6
  semantic: true;
7
7
  navigation: true;
8
8
  };
9
+ importCompletionOnly: {
10
+ __importCompletion: true;
11
+ };
9
12
  verification: {
10
13
  verification: true;
11
14
  };
12
15
  completion: {
13
16
  completion: true;
14
17
  };
15
- additionalCompletion: {
16
- completion: {
17
- isAdditional: true;
18
- };
19
- };
20
18
  withoutCompletion: {
21
19
  verification: true;
22
20
  semantic: true;
@@ -30,11 +28,9 @@ declare const raw: {
30
28
  shouldRename: () => false;
31
29
  };
32
30
  };
33
- navigationAndAdditionalCompletion: {
31
+ navigationAndCompletion: {
34
32
  navigation: true;
35
- completion: {
36
- isAdditional: true;
37
- };
33
+ completion: true;
38
34
  };
39
35
  navigationAndVerification: {
40
36
  navigation: true;
@@ -8,15 +8,15 @@ const raw = {
8
8
  semantic: true,
9
9
  navigation: true,
10
10
  },
11
+ importCompletionOnly: {
12
+ __importCompletion: true,
13
+ },
11
14
  verification: {
12
15
  verification: true,
13
16
  },
14
17
  completion: {
15
18
  completion: true,
16
19
  },
17
- additionalCompletion: {
18
- completion: { isAdditional: true },
19
- },
20
20
  withoutCompletion: {
21
21
  verification: true,
22
22
  semantic: true,
@@ -28,9 +28,9 @@ const raw = {
28
28
  navigationWithoutRename: {
29
29
  navigation: { shouldRename: () => false },
30
30
  },
31
- navigationAndAdditionalCompletion: {
31
+ navigationAndCompletion: {
32
32
  navigation: true,
33
- completion: { isAdditional: true },
33
+ completion: true,
34
34
  },
35
35
  navigationAndVerification: {
36
36
  navigation: true,
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getGlobalTypesFileName = getGlobalTypesFileName;
4
4
  exports.generateGlobalTypes = generateGlobalTypes;
5
+ const names = require("./names");
6
+ const utils_1 = require("./utils");
5
7
  function getGlobalTypesFileName(options) {
6
8
  return [
7
9
  options.lib,
@@ -11,22 +13,20 @@ function getGlobalTypesFileName(options) {
11
13
  }
12
14
  function generateGlobalTypes(options) {
13
15
  const { lib, target, checkUnknownProps } = options;
14
- let text = `// @ts-nocheck\nexport {};\n`;
16
+ let text = `// @ts-nocheck${utils_1.newLine}`;
17
+ text += `export {}${utils_1.endOfLine}`;
15
18
  if (target < 3.5) {
16
- text += `
17
- ; declare module '${lib}' {
19
+ text += `declare module '${lib}' {
18
20
  export interface GlobalComponents { }
19
21
  export interface GlobalDirectives { }
20
- }`;
22
+ }${utils_1.newLine}`;
21
23
  }
22
- text += `
23
- ; declare global {
24
- ${checkUnknownProps ? '' : 'var __VLS_PROPS_FALLBACK: Record<string, unknown>;'}
24
+ text += `declare global {
25
+ ${checkUnknownProps ? '' : `var ${names.PROPS_FALLBACK}: Record<string, unknown>;`}
25
26
 
26
27
  const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
27
- const __VLS_unref: typeof import('${lib}').unref;
28
- const __VLS_placeholder: any;
29
- const __VLS_intrinsics: ${target >= 3.3
28
+ const ${names.placeholder}: any;
29
+ const ${names.intrinsics}: ${target >= 3.3
30
30
  ? `import('${lib}/jsx-runtime').JSX.IntrinsicElements`
31
31
  : `globalThis.JSX.IntrinsicElements`};
32
32
 
@@ -124,12 +124,7 @@ function generateGlobalTypes(options) {
124
124
  type __VLS_ResolveDirectives<T> = {
125
125
  [K in keyof T & string as \`v\${Capitalize<K>}\`]: T[K];
126
126
  };
127
- type __VLS_PrettifyGlobal<T> = { [K in keyof T as K]: T[K]; } & {};
128
- type __VLS_WithDefaultsGlobal<P, D> = {
129
- [K in keyof P as K extends keyof D ? K : never]-?: P[K];
130
- } & {
131
- [K in keyof P as K extends keyof D ? never : K]: P[K];
132
- };
127
+ type __VLS_PrettifyGlobal<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {};
133
128
  type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
134
129
  type __VLS_ProxyRefs<T> = import('${lib}').ShallowUnwrapRef<T>;
135
130
 
@@ -162,8 +157,7 @@ function generateGlobalTypes(options) {
162
157
  function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownProps ? '' : ' & Record<string, unknown>'}) => void;
163
158
  function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
164
159
  function __VLS_tryAsConstant<const T>(t: T): T;
165
- }
166
- `;
160
+ }${utils_1.newLine}`;
167
161
  return text;
168
162
  }
169
163
  //# sourceMappingURL=globalTypes.js.map
@@ -2,7 +2,7 @@ import type { VueCompilerOptions } from '../types';
2
2
  export declare function getLocalTypesGenerator(vueCompilerOptions: VueCompilerOptions): {
3
3
  generate: () => Generator<string, void, unknown>;
4
4
  readonly PrettifyLocal: string;
5
- readonly WithDefaultsLocal: string;
5
+ readonly WithDefaults: string;
6
6
  readonly WithSlots: string;
7
7
  readonly PropsChildren: string;
8
8
  readonly TypePropsToOption: string;
@@ -4,14 +4,14 @@ exports.getLocalTypesGenerator = getLocalTypesGenerator;
4
4
  const utils_1 = require("./utils");
5
5
  function getLocalTypesGenerator(vueCompilerOptions) {
6
6
  const used = new Set();
7
- const WithDefaultsLocal = defineHelper(`__VLS_WithDefaultsLocal`, () => `
8
- type __VLS_WithDefaultsLocal<P, D> = {
7
+ const WithDefaults = defineHelper(`__VLS_WithDefaults`, () => `
8
+ type __VLS_WithDefaults<P, D> = {
9
9
  [K in keyof Pick<P, keyof P>]: K extends keyof D
10
10
  ? ${PrettifyLocal.name}<P[K] & { default: D[K] }>
11
11
  : P[K]
12
12
  };
13
13
  `.trimStart());
14
- const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T as K]: T[K]; } & {}${utils_1.endOfLine}`);
14
+ const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {}${utils_1.endOfLine}`);
15
15
  const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
16
16
  type __VLS_WithSlots<T, S> = T & {
17
17
  new(): {
@@ -44,7 +44,7 @@ type __VLS_TypePropsToOption<T> = {
44
44
  const OmitIndexSignature = defineHelper(`__VLS_OmitIndexSignature`, () => `type __VLS_OmitIndexSignature<T> = { [K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K]; }${utils_1.endOfLine}`);
45
45
  const helpers = {
46
46
  [PrettifyLocal.name]: PrettifyLocal,
47
- [WithDefaultsLocal.name]: WithDefaultsLocal,
47
+ [WithDefaults.name]: WithDefaults,
48
48
  [WithSlots.name]: WithSlots,
49
49
  [PropsChildren.name]: PropsChildren,
50
50
  [TypePropsToOption.name]: TypePropsToOption,
@@ -56,8 +56,8 @@ type __VLS_TypePropsToOption<T> = {
56
56
  get PrettifyLocal() {
57
57
  return PrettifyLocal.name;
58
58
  },
59
- get WithDefaultsLocal() {
60
- return WithDefaultsLocal.name;
59
+ get WithDefaults() {
60
+ return WithDefaults.name;
61
61
  },
62
62
  get WithSlots() {
63
63
  return WithSlots.name;
@@ -0,0 +1,30 @@
1
+ export declare const ctx = "__VLS_ctx";
2
+ export declare const self = "__VLS_self";
3
+ export declare const dollars = "__VLS_dollars";
4
+ export declare const slots = "__VLS_slots";
5
+ export declare const props = "__VLS_props";
6
+ export declare const defaults = "__VLS_defaults";
7
+ export declare const defaultModels = "__VLS_defaultModels";
8
+ export declare const modelEmit = "__VLS_modelEmit";
9
+ export declare const emit = "__VLS_emit";
10
+ export declare const exposed = "__VLS_exposed";
11
+ export declare const setup = "__VLS_setup";
12
+ export declare const components = "___VLS_components";
13
+ export declare const directives = "___VLS_directives";
14
+ export declare const intrinsics = "__VLS_intrinsics";
15
+ export declare const placeholder = "__VLS_placeholder";
16
+ export declare const _export = "__VLS_export";
17
+ export declare const ModelProps = "__VLS_ModelProps";
18
+ export declare const Props = "__VLS_Props";
19
+ export declare const Slots = "__VLS_Slots";
20
+ export declare const InheritedAttrs = "__VLS_InheritedAttrs";
21
+ export declare const TemplateRefs = "__VLS_TemplateRefs";
22
+ export declare const RootEl = "__VLS_RootEl";
23
+ export declare const ModelEmit = "__VLS_ModelEmit";
24
+ export declare const EmitProps = "__VLS_EmitProps";
25
+ export declare const InternalProps = "__VLS_InternalProps";
26
+ export declare const Emit = "__VLS_Emit";
27
+ export declare const SetupExposed = "__VLS_SetupExposed";
28
+ export declare const PublicProps = "__VLS_PublicProps";
29
+ export declare const StyleModules = "__VLS_StyleModules";
30
+ export declare const PROPS_FALLBACK = "__VLS_PROPS_FALLBACK";
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROPS_FALLBACK = exports.StyleModules = exports.PublicProps = exports.SetupExposed = exports.Emit = exports.InternalProps = exports.EmitProps = exports.ModelEmit = exports.RootEl = exports.TemplateRefs = exports.InheritedAttrs = exports.Slots = exports.Props = exports.ModelProps = exports._export = exports.placeholder = exports.intrinsics = exports.directives = exports.components = exports.setup = exports.exposed = exports.emit = exports.modelEmit = exports.defaultModels = exports.defaults = exports.props = exports.slots = exports.dollars = exports.self = exports.ctx = void 0;
4
+ exports.ctx = '__VLS_ctx';
5
+ exports.self = '__VLS_self';
6
+ exports.dollars = '__VLS_dollars';
7
+ exports.slots = '__VLS_slots';
8
+ exports.props = '__VLS_props';
9
+ exports.defaults = '__VLS_defaults';
10
+ exports.defaultModels = '__VLS_defaultModels';
11
+ exports.modelEmit = '__VLS_modelEmit';
12
+ exports.emit = '__VLS_emit';
13
+ exports.exposed = '__VLS_exposed';
14
+ exports.setup = '__VLS_setup';
15
+ exports.components = '___VLS_components';
16
+ exports.directives = '___VLS_directives';
17
+ exports.intrinsics = '__VLS_intrinsics';
18
+ exports.placeholder = '__VLS_placeholder';
19
+ exports._export = '__VLS_export';
20
+ exports.ModelProps = '__VLS_ModelProps';
21
+ exports.Props = '__VLS_Props';
22
+ exports.Slots = '__VLS_Slots';
23
+ exports.InheritedAttrs = '__VLS_InheritedAttrs';
24
+ exports.TemplateRefs = '__VLS_TemplateRefs';
25
+ exports.RootEl = '__VLS_RootEl';
26
+ exports.ModelEmit = '__VLS_ModelEmit';
27
+ exports.EmitProps = '__VLS_EmitProps';
28
+ exports.InternalProps = '__VLS_InternalProps';
29
+ exports.Emit = '__VLS_Emit';
30
+ exports.SetupExposed = '__VLS_SetupExposed';
31
+ exports.PublicProps = '__VLS_PublicProps';
32
+ exports.StyleModules = '__VLS_StyleModules';
33
+ exports.PROPS_FALLBACK = '__VLS_PROPS_FALLBACK';
34
+ //# sourceMappingURL=names.js.map
@@ -2,58 +2,45 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateComponent = generateComponent;
4
4
  const codeFeatures_1 = require("../codeFeatures");
5
+ const names = require("../names");
5
6
  const utils_1 = require("../utils");
6
7
  const merge_1 = require("../utils/merge");
7
8
  function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
8
- if (options.sfc.script
9
+ if (options.script
9
10
  && options.scriptRanges?.componentOptions
10
11
  && options.scriptRanges.componentOptions.expression.start !== options.scriptRanges.componentOptions.args.start) {
11
12
  // use defineComponent() from user space code if it exist
12
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.componentOptions.expression.start, options.scriptRanges.componentOptions.args.start, codeFeatures_1.codeFeatures.all);
13
+ yield* (0, utils_1.generateSfcBlockSection)(options.script, options.scriptRanges.componentOptions.expression.start, options.scriptRanges.componentOptions.args.start, codeFeatures_1.codeFeatures.all);
13
14
  yield `{${utils_1.newLine}`;
14
15
  }
15
16
  else {
16
17
  yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
17
18
  }
18
19
  const returns = [];
19
- if (ctx.bypassDefineComponent) {
20
- // fill $props
21
- if (scriptSetupRanges.defineProps) {
22
- const name = scriptSetupRanges.defineProps.name ?? `__VLS_props`;
23
- // NOTE: defineProps is inaccurate for $props
24
- returns.push(name, `{} as { $props: Partial<typeof ${name}> }`);
25
- }
26
- // fill $emit
27
- if (scriptSetupRanges.defineEmits) {
28
- returns.push(`{} as { $emit: typeof ${scriptSetupRanges.defineEmits.name ?? `__VLS_emit`} }`);
29
- }
30
- }
31
20
  if (scriptSetupRanges.defineExpose) {
32
- returns.push(`__VLS_exposed`);
21
+ returns.push([names.exposed]);
33
22
  }
34
23
  if (returns.length) {
35
24
  yield `setup: () => (`;
36
25
  yield* (0, merge_1.generateSpreadMerge)(returns);
37
26
  yield `),${utils_1.newLine}`;
38
27
  }
39
- if (!ctx.bypassDefineComponent) {
40
- const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
41
- yield* emitOptionCodes;
42
- yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length);
43
- }
28
+ const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
29
+ yield* emitOptionCodes;
30
+ yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length);
44
31
  if (options.vueCompilerOptions.target >= 3.5
45
32
  && options.vueCompilerOptions.inferComponentDollarRefs
46
- && options.templateCodegen?.templateRefs.size) {
47
- yield `__typeRefs: {} as __VLS_TemplateRefs,${utils_1.newLine}`;
33
+ && options.templateCodegen?.generatedTypes.has(names.TemplateRefs)) {
34
+ yield `__typeRefs: {} as ${names.TemplateRefs},${utils_1.newLine}`;
48
35
  }
49
36
  if (options.vueCompilerOptions.target >= 3.5
50
37
  && options.vueCompilerOptions.inferComponentDollarEl
51
- && options.templateCodegen?.singleRootElTypes.size) {
52
- yield `__typeEl: {} as __VLS_RootEl,${utils_1.newLine}`;
38
+ && options.templateCodegen?.generatedTypes.has(names.RootEl)) {
39
+ yield `__typeEl: {} as ${names.RootEl},${utils_1.newLine}`;
53
40
  }
54
- if (options.sfc.script && options.scriptRanges?.componentOptions?.args) {
41
+ if (options.script && options.scriptRanges?.componentOptions?.args) {
55
42
  const { args } = options.scriptRanges.componentOptions;
56
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
43
+ yield* (0, utils_1.generateSfcBlockSection)(options.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
57
44
  }
58
45
  yield `})`;
59
46
  }
@@ -61,14 +48,14 @@ function* generateEmitsOption(options, scriptSetupRanges) {
61
48
  const optionCodes = [];
62
49
  const typeOptionCodes = [];
63
50
  if (scriptSetupRanges.defineModel.length) {
64
- optionCodes.push(`{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`);
65
- typeOptionCodes.push(`__VLS_ModelEmit`);
51
+ optionCodes.push([`{} as __VLS_NormalizeEmits<typeof ${names.modelEmit}>`]);
52
+ typeOptionCodes.push([names.ModelEmit]);
66
53
  }
67
54
  if (scriptSetupRanges.defineEmits) {
68
55
  const { name, typeArg, hasUnionTypeArg } = scriptSetupRanges.defineEmits;
69
- optionCodes.push(`{} as __VLS_NormalizeEmits<typeof ${name ?? '__VLS_emit'}>`);
56
+ optionCodes.push([`{} as __VLS_NormalizeEmits<typeof ${name ?? names.emit}>`]);
70
57
  if (typeArg && !hasUnionTypeArg) {
71
- typeOptionCodes.push(`__VLS_Emit`);
58
+ typeOptionCodes.push([names.Emit]);
72
59
  }
73
60
  else {
74
61
  typeOptionCodes.length = 0;
@@ -86,50 +73,54 @@ function* generateEmitsOption(options, scriptSetupRanges) {
86
73
  }
87
74
  }
88
75
  function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) {
89
- const getOptionCodes = [];
90
- const typeOptionCodes = [];
91
- if (options.templateCodegen?.inheritedAttrVars.size) {
92
- let attrsType = `__VLS_InheritedAttrs`;
93
- if (hasEmitsOption) {
94
- attrsType = `Omit<${attrsType}, keyof __VLS_EmitProps>`;
95
- }
96
- getOptionCodes.push(() => {
76
+ const optionGenerates = [];
77
+ const typeOptionGenerates = [];
78
+ if (options.templateCodegen?.generatedTypes.has(names.InheritedAttrs)) {
79
+ const attrsType = hasEmitsOption
80
+ ? `Omit<${names.InheritedAttrs}, keyof ${names.EmitProps}>`
81
+ : names.InheritedAttrs;
82
+ optionGenerates.push(function* () {
97
83
  const propsType = `__VLS_PickNotAny<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
98
84
  const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`;
99
- return `{} as ${optionType}`;
85
+ yield `{} as ${optionType}`;
86
+ });
87
+ typeOptionGenerates.push(function* () {
88
+ yield `{} as ${attrsType}`;
100
89
  });
101
- typeOptionCodes.push(`{} as ${attrsType}`);
102
90
  }
103
- if (ctx.generatedPropsType) {
91
+ if (ctx.generatedTypes.has(names.PublicProps)) {
104
92
  if (options.vueCompilerOptions.target < 3.6) {
105
- getOptionCodes.push(() => {
106
- const propsType = `${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`;
107
- return `{} as ` + (scriptSetupRanges.withDefaults?.arg
108
- ? `${ctx.localTypes.WithDefaultsLocal}<${propsType}, typeof __VLS_defaults>`
109
- : propsType);
93
+ optionGenerates.push(function* () {
94
+ let propsType = `${ctx.localTypes.TypePropsToOption}<${names.PublicProps}>`;
95
+ if (scriptSetupRanges.withDefaults?.arg) {
96
+ propsType = `${ctx.localTypes.WithDefaults}<${propsType}, typeof ${names.defaults}>`;
97
+ }
98
+ yield `{} as ${propsType}`;
110
99
  });
111
100
  }
112
- typeOptionCodes.push(`{} as __VLS_PublicProps`);
101
+ typeOptionGenerates.push(function* () {
102
+ yield `{} as ${names.PublicProps}`;
103
+ });
113
104
  }
114
105
  if (scriptSetupRanges.defineProps?.arg) {
115
106
  const { arg } = scriptSetupRanges.defineProps;
116
- getOptionCodes.push(() => (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation));
117
- typeOptionCodes.length = 0;
107
+ optionGenerates.push(() => (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation));
108
+ typeOptionGenerates.length = 0;
118
109
  }
119
- const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionCodes.length;
120
- const useOption = (!useTypeOption || scriptSetupRanges.withDefaults) && getOptionCodes.length;
110
+ const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionGenerates.length;
111
+ const useOption = (!useTypeOption || scriptSetupRanges.withDefaults) && optionGenerates.length;
121
112
  if (useTypeOption) {
122
113
  if (options.vueCompilerOptions.target >= 3.6
123
114
  && scriptSetupRanges.withDefaults?.arg) {
124
- yield `__defaults: __VLS_defaults,${utils_1.newLine}`;
115
+ yield `__defaults: ${names.defaults},${utils_1.newLine}`;
125
116
  }
126
117
  yield `__typeProps: `;
127
- yield* (0, merge_1.generateSpreadMerge)(typeOptionCodes);
118
+ yield* (0, merge_1.generateSpreadMerge)(typeOptionGenerates.map(g => g()));
128
119
  yield `,${utils_1.newLine}`;
129
120
  }
130
121
  if (useOption) {
131
122
  yield `props: `;
132
- yield* (0, merge_1.generateSpreadMerge)(getOptionCodes.map(fn => fn()));
123
+ yield* (0, merge_1.generateSpreadMerge)(optionGenerates.map(g => g()));
133
124
  yield `,${utils_1.newLine}`;
134
125
  }
135
126
  }
@@ -2,14 +2,11 @@ import type { InlayHintInfo } from '../inlayHints';
2
2
  import type { ScriptCodegenOptions } from './index';
3
3
  export type ScriptCodegenContext = ReturnType<typeof createScriptCodegenContext>;
4
4
  export declare function createScriptCodegenContext(options: ScriptCodegenOptions): {
5
- generatedTemplate: boolean;
6
- generatedPropsType: boolean;
7
- bypassDefineComponent: boolean;
8
- bindingNames: Set<string>;
5
+ generatedTypes: Set<string>;
9
6
  localTypes: {
10
7
  generate: () => Generator<string, void, unknown>;
11
8
  readonly PrettifyLocal: string;
12
- readonly WithDefaultsLocal: string;
9
+ readonly WithDefaults: string;
13
10
  readonly WithSlots: string;
14
11
  readonly PropsChildren: string;
15
12
  readonly TypePropsToOption: string;
@@ -6,13 +6,7 @@ function createScriptCodegenContext(options) {
6
6
  const localTypes = (0, localTypes_1.getLocalTypesGenerator)(options.vueCompilerOptions);
7
7
  const inlayHints = [];
8
8
  return {
9
- generatedTemplate: false,
10
- generatedPropsType: false,
11
- bypassDefineComponent: options.lang === 'js' || options.lang === 'jsx',
12
- bindingNames: new Set([
13
- ...options.scriptRanges?.bindings.map(({ range }) => options.sfc.script.content.slice(range.start, range.end)) ?? [],
14
- ...options.scriptSetupRanges?.bindings.map(({ range }) => options.sfc.scriptSetup.content.slice(range.start, range.end)) ?? [],
15
- ]),
9
+ generatedTypes: new Set(),
16
10
  localTypes,
17
11
  inlayHints,
18
12
  };
@@ -1,34 +1,33 @@
1
1
  import type * as ts from 'typescript';
2
2
  import type { ScriptRanges } from '../../parsers/scriptRanges';
3
3
  import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
4
- import type { Code, Sfc, SfcBlock, VueCompilerOptions } from '../../types';
4
+ import type { Code, Sfc, VueCompilerOptions } from '../../types';
5
5
  import type { TemplateCodegenContext } from '../template/context';
6
6
  export interface ScriptCodegenOptions {
7
7
  ts: typeof ts;
8
- compilerOptions: ts.CompilerOptions;
9
8
  vueCompilerOptions: VueCompilerOptions;
10
- sfc: Sfc;
9
+ script: Sfc['script'];
10
+ scriptSetup: Sfc['scriptSetup'];
11
11
  fileName: string;
12
- lang: string;
13
12
  scriptRanges: ScriptRanges | undefined;
14
13
  scriptSetupRanges: ScriptSetupRanges | undefined;
14
+ templateStartTagOffset: number | undefined;
15
15
  templateCodegen: TemplateCodegenContext & {
16
16
  codes: Code[];
17
17
  } | undefined;
18
- destructuredPropNames: Set<string>;
19
- templateRefNames: Set<string>;
18
+ styleCodegen: TemplateCodegenContext & {
19
+ codes: Code[];
20
+ } | undefined;
21
+ setupExposed: Set<string>;
20
22
  }
21
23
  export { generate as generateScript };
22
24
  declare function generate(options: ScriptCodegenOptions): {
23
25
  codes: Code[];
24
- generatedTemplate: boolean;
25
- generatedPropsType: boolean;
26
- bypassDefineComponent: boolean;
27
- bindingNames: Set<string>;
26
+ generatedTypes: Set<string>;
28
27
  localTypes: {
29
28
  generate: () => Generator<string, void, unknown>;
30
29
  readonly PrettifyLocal: string;
31
- readonly WithDefaultsLocal: string;
30
+ readonly WithDefaults: string;
32
31
  readonly WithSlots: string;
33
32
  readonly PropsChildren: string;
34
33
  readonly TypePropsToOption: string;
@@ -36,4 +35,3 @@ declare function generate(options: ScriptCodegenOptions): {
36
35
  };
37
36
  inlayHints: import("../inlayHints").InlayHintInfo[];
38
37
  };
39
- export declare function generateConstExport(options: ScriptCodegenOptions, block: SfcBlock): Generator<Code>;