@vue/language-core 2.1.8 → 2.2.0

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 (77) hide show
  1. package/lib/codegen/globalTypes.js +12 -5
  2. package/lib/codegen/localTypes.js +3 -3
  3. package/lib/codegen/script/component.js +42 -42
  4. package/lib/codegen/script/componentSelf.js +14 -13
  5. package/lib/codegen/script/context.js +2 -2
  6. package/lib/codegen/script/index.d.ts +5 -3
  7. package/lib/codegen/script/index.js +24 -37
  8. package/lib/codegen/script/scriptSetup.js +240 -193
  9. package/lib/codegen/script/src.js +6 -6
  10. package/lib/codegen/script/styleModulesType.js +5 -5
  11. package/lib/codegen/script/template.d.ts +1 -1
  12. package/lib/codegen/script/template.js +89 -99
  13. package/lib/codegen/template/context.d.ts +13 -3
  14. package/lib/codegen/template/context.js +21 -12
  15. package/lib/codegen/template/element.d.ts +2 -4
  16. package/lib/codegen/template/element.js +132 -105
  17. package/lib/codegen/template/elementChildren.d.ts +1 -1
  18. package/lib/codegen/template/elementChildren.js +8 -8
  19. package/lib/codegen/template/elementDirectives.d.ts +1 -0
  20. package/lib/codegen/template/elementDirectives.js +28 -22
  21. package/lib/codegen/template/elementEvents.d.ts +2 -2
  22. package/lib/codegen/template/elementEvents.js +32 -65
  23. package/lib/codegen/template/elementProps.d.ts +3 -2
  24. package/lib/codegen/template/elementProps.js +119 -122
  25. package/lib/codegen/template/index.js +52 -60
  26. package/lib/codegen/template/interpolation.d.ts +5 -3
  27. package/lib/codegen/template/interpolation.js +18 -19
  28. package/lib/codegen/template/objectProperty.js +8 -8
  29. package/lib/codegen/template/propertyAccess.js +4 -4
  30. package/lib/codegen/template/slotOutlet.d.ts +1 -1
  31. package/lib/codegen/template/slotOutlet.js +13 -13
  32. package/lib/codegen/template/styleScopedClasses.d.ts +1 -1
  33. package/lib/codegen/template/styleScopedClasses.js +11 -8
  34. package/lib/codegen/template/templateChild.d.ts +1 -1
  35. package/lib/codegen/template/templateChild.js +31 -19
  36. package/lib/codegen/template/vFor.d.ts +1 -1
  37. package/lib/codegen/template/vFor.js +11 -11
  38. package/lib/codegen/template/vIf.d.ts +1 -1
  39. package/lib/codegen/template/vIf.js +6 -6
  40. package/lib/codegen/{template → utils}/camelized.js +2 -2
  41. package/lib/codegen/{common.d.ts → utils/index.d.ts} +1 -2
  42. package/lib/codegen/{common.js → utils/index.js} +4 -15
  43. package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
  44. package/lib/codegen/utils/unicode.d.ts +2 -0
  45. package/lib/codegen/utils/unicode.js +25 -0
  46. package/lib/languagePlugin.js +1 -1
  47. package/lib/parsers/scriptRanges.d.ts +7 -2
  48. package/lib/parsers/scriptSetupRanges.d.ts +67 -81
  49. package/lib/parsers/scriptSetupRanges.js +195 -166
  50. package/lib/parsers/vueCompilerOptions.d.ts +2 -0
  51. package/lib/parsers/vueCompilerOptions.js +23 -0
  52. package/lib/plugins/file-html.js +4 -3
  53. package/lib/plugins/file-md.js +1 -1
  54. package/lib/plugins/file-vue.js +4 -4
  55. package/lib/plugins/vue-root-tags.js +2 -2
  56. package/lib/plugins/vue-template-html.js +6 -2
  57. package/lib/plugins/vue-template-inline-css.js +1 -1
  58. package/lib/plugins/vue-template-inline-ts.js +13 -5
  59. package/lib/plugins/vue-tsx.d.ts +101 -72
  60. package/lib/plugins/vue-tsx.js +65 -69
  61. package/lib/types.d.ts +19 -10
  62. package/lib/utils/buildMappings.d.ts +1 -1
  63. package/lib/utils/parseSfc.d.ts +5 -0
  64. package/lib/utils/parseSfc.js +7 -2
  65. package/lib/utils/ts.d.ts +1 -1
  66. package/lib/utils/ts.js +38 -24
  67. package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
  68. package/lib/virtualFile/computedSfc.js +23 -12
  69. package/lib/virtualFile/computedVueSfc.d.ts +1 -1
  70. package/lib/virtualFile/vueFile.d.ts +3 -3
  71. package/package.json +5 -5
  72. package/lib/codegen/types.d.ts +0 -9
  73. package/lib/codegen/types.js +0 -3
  74. package/lib/utils/findDestructuredProps.d.ts +0 -1
  75. package/lib/utils/findDestructuredProps.js +0 -3
  76. /package/lib/codegen/{template → utils}/camelized.d.ts +0 -0
  77. /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
@@ -17,6 +17,7 @@ function generateGlobalTypes(lib, target, strictTemplates) {
17
17
  const __VLS_intrinsicElements: __VLS_IntrinsicElements;
18
18
  const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
19
19
  const __VLS_unref: typeof import('${lib}').unref;
20
+ const __VLS_placeholder: any;
20
21
 
21
22
  const __VLS_nativeElements = {
22
23
  ...{} as SVGElementTagNameMap,
@@ -43,7 +44,7 @@ function generateGlobalTypes(lib, target, strictTemplates) {
43
44
  N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
44
45
  N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
45
46
  N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
46
- ${strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
47
+ ${strictTemplates ? '{}' : '{ [K in N0]: unknown }'};
47
48
  type __VLS_FunctionalComponentProps<T, K> =
48
49
  '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
49
50
  : T extends (props: infer P, ...args: any) => any ? P :
@@ -55,6 +56,15 @@ function generateGlobalTypes(lib, target, strictTemplates) {
55
56
  : true
56
57
  : false
57
58
  : false;
59
+ type __VLS_NormalizeComponentEvent<Props, Events, onEvent extends keyof Props, Event extends keyof Events, CamelizedEvent extends keyof Events> = (
60
+ __VLS_IsFunction<Props, onEvent> extends true
61
+ ? Props
62
+ : __VLS_IsFunction<Events, Event> extends true
63
+ ? { [K in onEvent]?: Events[Event] }
64
+ : __VLS_IsFunction<Events, CamelizedEvent> extends true
65
+ ? { [K in onEvent]?: Events[CamelizedEvent] }
66
+ : Props
67
+ )${strictTemplates ? '' : ' & Record<string, unknown>'};
58
68
  // fix https://github.com/vuejs/language-tools/issues/926
59
69
  type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
60
70
  type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
@@ -88,9 +98,7 @@ function generateGlobalTypes(lib, target, strictTemplates) {
88
98
  function __VLS_getVForSourceType(source: number): [number, number, number][];
89
99
  function __VLS_getVForSourceType(source: string): [string, number, number][];
90
100
  function __VLS_getVForSourceType<T extends any[]>(source: T): [
91
- item: ${(target >= 3 ? `import('${lib}').Reactive<T[number]>` :
92
- target >= 2.7 ? `import('${lib}').UnwrapNestedRefs<T[number]>` :
93
- `T[number]`)},
101
+ item: T[number],
94
102
  key: number,
95
103
  index: number,
96
104
  ][];
@@ -121,7 +129,6 @@ function generateGlobalTypes(lib, target, strictTemplates) {
121
129
  : __VLS_unknownDirective;
122
130
  function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
123
131
  function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
124
- function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
125
132
  function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
126
133
  T extends new (...args: any) => any
127
134
  ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLocalTypesGenerator = getLocalTypesGenerator;
4
4
  const shared_1 = require("../utils/shared");
5
- const common_1 = require("./common");
5
+ const utils_1 = require("./utils");
6
6
  function getLocalTypesGenerator(compilerOptions, vueCompilerOptions) {
7
7
  const used = new Set();
8
8
  const OmitKeepDiscriminatedUnion = defineHelper(`__VLS_OmitKeepDiscriminatedUnion`, () => `
@@ -17,7 +17,7 @@ type __VLS_WithDefaults<P, D> = {
17
17
  : P[K]
18
18
  };
19
19
  `.trimStart());
20
- const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}${common_1.endOfLine}`);
20
+ const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}${utils_1.endOfLine}`);
21
21
  const WithTemplateSlots = defineHelper(`__VLS_WithTemplateSlots`, () => `
22
22
  type __VLS_WithTemplateSlots<T, S> = T & {
23
23
  new(): {
@@ -57,7 +57,7 @@ type __VLS_TypePropsToOption<T> = {
57
57
  : { type: import('${vueCompilerOptions.lib}').PropType<T[K]>, required: true }
58
58
  };
59
59
  `.trimStart());
60
- const OmitIndexSignature = defineHelper(`__VLS_OmitIndexSignature`, () => `type __VLS_OmitIndexSignature<T> = { [K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K]; }${common_1.endOfLine}`);
60
+ 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}`);
61
61
  const helpers = {
62
62
  [PrettifyLocal.name]: PrettifyLocal,
63
63
  [OmitKeepDiscriminatedUnion.name]: OmitKeepDiscriminatedUnion,
@@ -4,27 +4,27 @@ exports.generateComponent = generateComponent;
4
4
  exports.generateComponentSetupReturns = generateComponentSetupReturns;
5
5
  exports.generateEmitsOption = generateEmitsOption;
6
6
  exports.generatePropsOption = generatePropsOption;
7
- const common_1 = require("../common");
7
+ const utils_1 = require("../utils");
8
8
  const index_1 = require("./index");
9
9
  function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
10
10
  if (options.sfc.script && options.scriptRanges?.exportDefault && options.scriptRanges.exportDefault.expression.start !== options.scriptRanges.exportDefault.args.start) {
11
11
  // use defineComponent() from user space code if it exist
12
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start, index_1.codeFeatures.all);
13
- yield `{${common_1.newLine}`;
12
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start, index_1.codeFeatures.all);
13
+ yield `{${utils_1.newLine}`;
14
14
  }
15
15
  else {
16
- yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
16
+ yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
17
17
  }
18
- yield `setup() {${common_1.newLine}`;
19
- yield `return {${common_1.newLine}`;
18
+ yield `setup() {${utils_1.newLine}`;
19
+ yield `return {${utils_1.newLine}`;
20
20
  if (ctx.bypassDefineComponent) {
21
21
  yield* generateComponentSetupReturns(scriptSetupRanges);
22
22
  }
23
- if (scriptSetupRanges.expose.define) {
24
- yield `...__VLS_exposed,${common_1.newLine}`;
23
+ if (scriptSetupRanges.defineExpose) {
24
+ yield `...__VLS_exposed,${utils_1.newLine}`;
25
25
  }
26
- yield `}${common_1.endOfLine}`;
27
- yield `},${common_1.newLine}`;
26
+ yield `}${utils_1.endOfLine}`;
27
+ yield `},${utils_1.newLine}`;
28
28
  if (!ctx.bypassDefineComponent) {
29
29
  const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
30
30
  for (const code of emitOptionCodes) {
@@ -34,26 +34,26 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
34
34
  }
35
35
  if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
36
36
  const { args } = options.scriptRanges.exportDefault;
37
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
37
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
38
38
  }
39
- if (options.vueCompilerOptions.target >= 3.5 && scriptSetupRanges.templateRefs.length) {
40
- yield `__typeRefs: {} as __VLS_TemplateResult['refs'],${common_1.newLine}`;
39
+ if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.templateRefs.size) {
40
+ yield `__typeRefs: {} as __VLS_TemplateResult['refs'],${utils_1.newLine}`;
41
41
  }
42
42
  if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.singleRootElType) {
43
- yield `__typeEl: {} as __VLS_TemplateResult['rootEl'],${common_1.newLine}`;
43
+ yield `__typeEl: {} as __VLS_TemplateResult['rootEl'],${utils_1.newLine}`;
44
44
  }
45
45
  yield `})`;
46
46
  }
47
47
  function* generateComponentSetupReturns(scriptSetupRanges) {
48
48
  // fill $props
49
- if (scriptSetupRanges.props.define) {
49
+ if (scriptSetupRanges.defineProps) {
50
50
  // NOTE: defineProps is inaccurate for $props
51
- yield `$props: __VLS_makeOptional(${scriptSetupRanges.props.name ?? `__VLS_props`}),${common_1.newLine}`;
52
- yield `...${scriptSetupRanges.props.name ?? `__VLS_props`},${common_1.newLine}`;
51
+ yield `$props: __VLS_makeOptional(${scriptSetupRanges.defineProps.name ?? `__VLS_props`}),${utils_1.newLine}`;
52
+ yield `...${scriptSetupRanges.defineProps.name ?? `__VLS_props`},${utils_1.newLine}`;
53
53
  }
54
54
  // fill $emit
55
- if (scriptSetupRanges.emits.define) {
56
- yield `$emit: ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
55
+ if (scriptSetupRanges.defineEmits) {
56
+ yield `$emit: ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'},${utils_1.newLine}`;
57
57
  }
58
58
  }
59
59
  function* generateEmitsOption(options, scriptSetupRanges) {
@@ -64,10 +64,10 @@ function* generateEmitsOption(options, scriptSetupRanges) {
64
64
  typeOptionType: `__VLS_ModelEmit`,
65
65
  });
66
66
  }
67
- if (scriptSetupRanges.emits.define) {
68
- const { typeArg, hasUnionTypeArg } = scriptSetupRanges.emits.define;
67
+ if (scriptSetupRanges.defineEmits) {
68
+ const { name, typeArg, hasUnionTypeArg } = scriptSetupRanges.defineEmits;
69
69
  codes.push({
70
- optionExp: `{} as __VLS_NormalizeEmits<typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}>`,
70
+ optionExp: `{} as __VLS_NormalizeEmits<typeof ${name ?? '__VLS_emit'}>`,
71
71
  typeOptionType: typeArg && !hasUnionTypeArg
72
72
  ? `__VLS_Emit`
73
73
  : undefined,
@@ -77,7 +77,7 @@ function* generateEmitsOption(options, scriptSetupRanges) {
77
77
  if (codes.length === 1) {
78
78
  yield `__typeEmits: {} as `;
79
79
  yield codes[0].typeOptionType;
80
- yield `,${common_1.newLine}`;
80
+ yield `,${utils_1.newLine}`;
81
81
  }
82
82
  else if (codes.length >= 2) {
83
83
  yield `__typeEmits: {} as `;
@@ -86,23 +86,23 @@ function* generateEmitsOption(options, scriptSetupRanges) {
86
86
  yield ` & `;
87
87
  yield codes[i].typeOptionType;
88
88
  }
89
- yield `,${common_1.newLine}`;
89
+ yield `,${utils_1.newLine}`;
90
90
  }
91
91
  }
92
92
  else if (codes.every(code => code.optionExp)) {
93
93
  if (codes.length === 1) {
94
94
  yield `emits: `;
95
95
  yield codes[0].optionExp;
96
- yield `,${common_1.newLine}`;
96
+ yield `,${utils_1.newLine}`;
97
97
  }
98
98
  else if (codes.length >= 2) {
99
- yield `emits: {${common_1.newLine}`;
99
+ yield `emits: {${utils_1.newLine}`;
100
100
  for (const code of codes) {
101
101
  yield `...`;
102
102
  yield code.optionExp;
103
- yield `,${common_1.newLine}`;
103
+ yield `,${utils_1.newLine}`;
104
104
  }
105
- yield `},${common_1.newLine}`;
105
+ yield `},${utils_1.newLine}`;
106
106
  }
107
107
  }
108
108
  }
@@ -112,17 +112,17 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
112
112
  codes.push({
113
113
  optionExp: [
114
114
  `{} as `,
115
- scriptSetupRanges.props.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
115
+ scriptSetupRanges.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
116
116
  `${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`,
117
- scriptSetupRanges.props.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
117
+ scriptSetupRanges.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
118
118
  ].join(''),
119
119
  typeOptionExp: `{} as __VLS_PublicProps`,
120
120
  });
121
121
  }
122
- if (scriptSetupRanges.props.define?.arg) {
123
- const { arg } = scriptSetupRanges.props.define;
122
+ if (scriptSetupRanges.defineProps?.arg) {
123
+ const { arg } = scriptSetupRanges.defineProps;
124
124
  codes.push({
125
- optionExp: (0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation),
125
+ optionExp: (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation),
126
126
  typeOptionExp: undefined,
127
127
  });
128
128
  }
@@ -142,37 +142,37 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
142
142
  });
143
143
  }
144
144
  const useTypeOption = options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionExp);
145
- const useOption = !useTypeOption || scriptSetupRanges.props.withDefaults;
145
+ const useOption = !useTypeOption || scriptSetupRanges.withDefaults;
146
146
  if (useTypeOption) {
147
147
  if (codes.length === 1) {
148
148
  yield `__typeProps: `;
149
149
  yield codes[0].typeOptionExp;
150
- yield `,${common_1.newLine}`;
150
+ yield `,${utils_1.newLine}`;
151
151
  }
152
152
  else if (codes.length >= 2) {
153
- yield `__typeProps: {${common_1.newLine}`;
153
+ yield `__typeProps: {${utils_1.newLine}`;
154
154
  for (const { typeOptionExp } of codes) {
155
155
  yield `...`;
156
156
  yield typeOptionExp;
157
- yield `,${common_1.newLine}`;
157
+ yield `,${utils_1.newLine}`;
158
158
  }
159
- yield `},${common_1.newLine}`;
159
+ yield `},${utils_1.newLine}`;
160
160
  }
161
161
  }
162
162
  if (useOption) {
163
163
  if (codes.length === 1) {
164
164
  yield `props: `;
165
165
  yield codes[0].optionExp;
166
- yield `,${common_1.newLine}`;
166
+ yield `,${utils_1.newLine}`;
167
167
  }
168
168
  else if (codes.length >= 2) {
169
- yield `props: {${common_1.newLine}`;
169
+ yield `props: {${utils_1.newLine}`;
170
170
  for (const { optionExp } of codes) {
171
171
  yield `...`;
172
172
  yield optionExp;
173
- yield `,${common_1.newLine}`;
173
+ yield `,${utils_1.newLine}`;
174
174
  }
175
- yield `},${common_1.newLine}`;
175
+ yield `},${utils_1.newLine}`;
176
176
  }
177
177
  }
178
178
  }
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateComponentSelf = generateComponentSelf;
4
- const common_1 = require("../common");
4
+ const path = require("path-browserify");
5
+ const utils_1 = require("../utils");
5
6
  const component_1 = require("./component");
6
7
  const index_1 = require("./index");
7
8
  const template_1 = require("./template");
8
9
  function* generateComponentSelf(options, ctx, templateCodegenCtx) {
9
10
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
10
- yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
11
- yield `setup() {${common_1.newLine}`;
12
- yield `return {${common_1.newLine}`;
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}`;
13
14
  if (ctx.bypassDefineComponent) {
14
15
  yield* (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges);
15
16
  }
@@ -21,15 +22,15 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
21
22
  ? [options.sfc.script.content, options.scriptRanges.bindings]
22
23
  : ['', []],
23
24
  ]) {
24
- for (const expose of bindings) {
25
- const varName = content.substring(expose.start, expose.end);
25
+ for (const { range } of bindings) {
26
+ const varName = content.slice(range.start, range.end);
26
27
  if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
27
28
  continue;
28
29
  }
29
30
  const templateOffset = options.getGeneratedLength();
30
31
  yield `${varName}: ${varName} as typeof `;
31
32
  const scriptOffset = options.getGeneratedLength();
32
- yield `${varName},${common_1.newLine}`;
33
+ yield `${varName},${utils_1.newLine}`;
33
34
  options.linkedCodeMappings.push({
34
35
  sourceOffsets: [scriptOffset],
35
36
  generatedOffsets: [templateOffset],
@@ -38,8 +39,8 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
38
39
  });
39
40
  }
40
41
  }
41
- yield `}${common_1.endOfLine}`; // return {
42
- yield `},${common_1.newLine}`; // setup() {
42
+ yield `}${utils_1.endOfLine}`; // return {
43
+ yield `},${utils_1.newLine}`; // setup() {
43
44
  if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
44
45
  const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
45
46
  for (const code of emitOptionCodes) {
@@ -49,15 +50,15 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
49
50
  }
50
51
  if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
51
52
  const { args } = options.scriptRanges.exportDefault;
52
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
53
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
53
54
  }
54
- yield `})${common_1.endOfLine}`; // defineComponent {
55
+ yield `})${utils_1.endOfLine}`; // defineComponent {
55
56
  }
56
57
  else if (options.sfc.script) {
57
- yield `let __VLS_self!: typeof import('./${options.fileBaseName}').default${common_1.endOfLine}`;
58
+ yield `let __VLS_self!: typeof import('./${path.basename(options.fileName)}').default${utils_1.endOfLine}`;
58
59
  }
59
60
  else {
60
- yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${common_1.endOfLine}`;
61
+ yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
61
62
  }
62
63
  }
63
64
  //# sourceMappingURL=componentSelf.js.map
@@ -11,8 +11,8 @@ function createScriptCodegenContext(options) {
11
11
  scriptSetupGeneratedOffset: undefined,
12
12
  bypassDefineComponent: options.lang === 'js' || options.lang === 'jsx',
13
13
  bindingNames: new Set([
14
- ...options.scriptRanges?.bindings.map(range => options.sfc.script.content.substring(range.start, range.end)) ?? [],
15
- ...options.scriptSetupRanges?.bindings.map(range => options.sfc.scriptSetup.content.substring(range.start, range.end)) ?? [],
14
+ ...options.scriptRanges?.bindings.map(({ range }) => options.sfc.script.content.slice(range.start, range.end)) ?? [],
15
+ ...options.scriptSetupRanges?.bindings.map(({ range }) => options.sfc.scriptSetup.content.slice(range.start, range.end)) ?? [],
16
16
  ]),
17
17
  localTypes,
18
18
  inlayHints,
@@ -13,21 +13,23 @@ export declare const codeFeatures: {
13
13
  navigationWithoutRename: VueCodeInformation;
14
14
  };
15
15
  export interface ScriptCodegenOptions {
16
- fileBaseName: string;
17
16
  ts: typeof ts;
18
17
  compilerOptions: ts.CompilerOptions;
19
18
  vueCompilerOptions: VueCompilerOptions;
20
19
  sfc: Sfc;
20
+ edited: boolean;
21
+ fileName: string;
21
22
  lang: string;
22
23
  scriptRanges: ScriptRanges | undefined;
23
24
  scriptSetupRanges: ScriptSetupRanges | undefined;
24
25
  templateCodegen: TemplateCodegenContext & {
25
26
  codes: Code[];
26
27
  } | undefined;
27
- edited: boolean;
28
- appendGlobalTypes: boolean;
28
+ destructuredPropNames: Set<string>;
29
+ templateRefNames: Set<string>;
29
30
  getGeneratedLength: () => number;
30
31
  linkedCodeMappings: Mapping[];
32
+ appendGlobalTypes: boolean;
31
33
  }
32
34
  export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
33
35
  export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string): Generator<Code>;
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.codeFeatures = void 0;
4
4
  exports.generateScript = generateScript;
5
5
  exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
6
- const common_1 = require("../common");
6
+ const path = require("path-browserify");
7
7
  const globalTypes_1 = require("../globalTypes");
8
+ const utils_1 = require("../utils");
8
9
  const componentSelf_1 = require("./componentSelf");
9
10
  const context_1 = require("./context");
10
11
  const scriptSetup_1 = require("./scriptSetup");
@@ -38,10 +39,14 @@ function* generateScript(options) {
38
39
  if (options.vueCompilerOptions.__setupedGlobalTypes) {
39
40
  const globalTypes = options.vueCompilerOptions.__setupedGlobalTypes;
40
41
  if (typeof globalTypes === 'object') {
41
- yield `/// <reference types="${globalTypes.absolutePath}" />${common_1.newLine}`;
42
+ let relativePath = path.relative(path.dirname(options.fileName), globalTypes.absolutePath);
43
+ if (relativePath !== globalTypes.absolutePath && !relativePath.startsWith('./') && !relativePath.startsWith('../')) {
44
+ relativePath = './' + relativePath;
45
+ }
46
+ yield `/// <reference types="${relativePath}" />${utils_1.newLine}`;
42
47
  }
43
48
  else {
44
- yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${common_1.newLine}`;
49
+ yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${utils_1.newLine}`;
45
50
  }
46
51
  }
47
52
  else {
@@ -56,14 +61,13 @@ function* generateScript(options) {
56
61
  && options.sfc.script.content[exportDefault.expression.start] === '{';
57
62
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
58
63
  yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
59
- yield* generateDefineProp(options, options.sfc.scriptSetup);
60
64
  if (exportDefault) {
61
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
65
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
62
66
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
63
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
67
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
64
68
  }
65
69
  else {
66
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
70
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
67
71
  yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/both.vue');
68
72
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
69
73
  }
@@ -88,32 +92,31 @@ function* generateScript(options) {
88
92
  ? options.vueCompilerOptions.optionsWrapper[1]
89
93
  : '[Missing optionsWrapper[1]]',
90
94
  });
91
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
95
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
92
96
  yield options.vueCompilerOptions.optionsWrapper[0];
93
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, exports.codeFeatures.all);
97
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, exports.codeFeatures.all);
94
98
  yield options.vueCompilerOptions.optionsWrapper[1];
95
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
99
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
96
100
  }
97
101
  else if (classBlockEnd !== undefined) {
98
102
  if (options.vueCompilerOptions.skipTemplateCodegen) {
99
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
103
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
100
104
  }
101
105
  else {
102
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, exports.codeFeatures.all);
103
- yield `__VLS_template = () => {${common_1.newLine}`;
106
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, exports.codeFeatures.all);
107
+ yield `__VLS_template = () => {${utils_1.newLine}`;
104
108
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
105
109
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
106
- yield `}${common_1.endOfLine}`;
107
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
110
+ yield `}${utils_1.endOfLine}`;
111
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
108
112
  }
109
113
  }
110
114
  else {
111
- yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
115
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
112
116
  }
113
117
  }
114
118
  else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
115
119
  yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
116
- yield* generateDefineProp(options, options.sfc.scriptSetup);
117
120
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
118
121
  }
119
122
  if (options.sfc.script) {
@@ -123,15 +126,15 @@ function* generateScript(options) {
123
126
  yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
124
127
  }
125
128
  if (!ctx.generatedTemplate) {
126
- yield `function __VLS_template() {${common_1.newLine}`;
129
+ yield `function __VLS_template() {${utils_1.newLine}`;
127
130
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
128
- yield `}${common_1.endOfLine}`;
131
+ yield `}${utils_1.endOfLine}`;
129
132
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
130
133
  }
131
134
  // #4788
132
135
  yield* (0, styleModulesType_1.generateStyleModulesType)(options, ctx);
133
136
  if (options.edited) {
134
- yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${common_1.endOfLine}`;
137
+ yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${utils_1.endOfLine}`;
135
138
  }
136
139
  yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
137
140
  if (options.appendGlobalTypes) {
@@ -145,22 +148,6 @@ function* generateScript(options) {
145
148
  function* generateScriptSectionPartiallyEnding(source, end, mark) {
146
149
  yield `;`;
147
150
  yield ['', source, end, exports.codeFeatures.verification];
148
- yield `/* PartiallyEnd: ${mark} */${common_1.newLine}`;
149
- }
150
- function* generateDefineProp(options, scriptSetup) {
151
- const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
152
- const definePropProposalB = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
153
- if (definePropProposalA || definePropProposalB) {
154
- yield `type __VLS_PropOptions<T> = Exclude<import('${options.vueCompilerOptions.lib}').Prop<T>, import('${options.vueCompilerOptions.lib}').PropType<T>>${common_1.endOfLine}`;
155
- if (definePropProposalA) {
156
- yield `declare function defineProp<T>(name: string, options: ({ required: true } | { default: T }) & __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
157
- yield `declare function defineProp<T>(name?: string, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${common_1.endOfLine}`;
158
- }
159
- if (definePropProposalB) {
160
- yield `declare function defineProp<T>(value: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
161
- yield `declare function defineProp<T>(value: T | (() => T) | undefined, required: true, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${common_1.endOfLine}`;
162
- yield `declare function defineProp<T>(value?: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${common_1.endOfLine}`;
163
- }
164
- }
151
+ yield `/* PartiallyEnd: ${mark} */${utils_1.newLine}`;
165
152
  }
166
153
  //# sourceMappingURL=index.js.map