@vue/language-core 2.1.10 → 2.2.2

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 (109) hide show
  1. package/index.d.ts +0 -1
  2. package/index.js +1 -2
  3. package/lib/codeFeatures.d.ts +1 -0
  4. package/lib/codeFeatures.js +3 -0
  5. package/lib/codegen/codeFeatures.d.ts +83 -0
  6. package/lib/codegen/codeFeatures.js +71 -0
  7. package/lib/codegen/globalTypes.d.ts +3 -1
  8. package/lib/codegen/globalTypes.js +39 -14
  9. package/lib/codegen/localTypes.d.ts +1 -1
  10. package/lib/codegen/localTypes.js +7 -7
  11. package/lib/codegen/script/binding.d.ts +4 -0
  12. package/lib/codegen/script/binding.js +41 -0
  13. package/lib/codegen/script/component.d.ts +1 -1
  14. package/lib/codegen/script/component.js +44 -44
  15. package/lib/codegen/script/componentSelf.d.ts +1 -1
  16. package/lib/codegen/script/componentSelf.js +14 -14
  17. package/lib/codegen/script/context.d.ts +1 -1
  18. package/lib/codegen/script/context.js +2 -2
  19. package/lib/codegen/script/index.d.ts +6 -11
  20. package/lib/codegen/script/index.js +21 -63
  21. package/lib/codegen/script/scriptSetup.d.ts +1 -1
  22. package/lib/codegen/script/scriptSetup.js +236 -205
  23. package/lib/codegen/script/src.js +8 -8
  24. package/lib/codegen/script/styleModulesType.d.ts +1 -1
  25. package/lib/codegen/script/styleModulesType.js +7 -7
  26. package/lib/codegen/script/template.d.ts +2 -2
  27. package/lib/codegen/script/template.js +81 -114
  28. package/lib/codegen/template/context.d.ts +29 -15
  29. package/lib/codegen/template/context.js +51 -96
  30. package/lib/codegen/template/element.d.ts +2 -4
  31. package/lib/codegen/template/element.js +124 -317
  32. package/lib/codegen/template/elementChildren.d.ts +1 -1
  33. package/lib/codegen/template/elementChildren.js +10 -11
  34. package/lib/codegen/template/elementDirectives.d.ts +1 -0
  35. package/lib/codegen/template/elementDirectives.js +43 -30
  36. package/lib/codegen/template/elementEvents.d.ts +2 -2
  37. package/lib/codegen/template/elementEvents.js +32 -65
  38. package/lib/codegen/template/elementProps.d.ts +5 -3
  39. package/lib/codegen/template/elementProps.js +116 -123
  40. package/lib/codegen/template/index.d.ts +1 -0
  41. package/lib/codegen/template/index.js +67 -69
  42. package/lib/codegen/template/interpolation.d.ts +5 -3
  43. package/lib/codegen/template/interpolation.js +30 -27
  44. package/lib/codegen/template/objectProperty.js +8 -8
  45. package/lib/codegen/template/propertyAccess.js +4 -4
  46. package/lib/codegen/template/slotOutlet.d.ts +1 -1
  47. package/lib/codegen/template/slotOutlet.js +47 -25
  48. package/lib/codegen/template/styleScopedClasses.d.ts +4 -1
  49. package/lib/codegen/template/styleScopedClasses.js +152 -8
  50. package/lib/codegen/template/templateChild.d.ts +1 -1
  51. package/lib/codegen/template/templateChild.js +39 -20
  52. package/lib/codegen/template/vFor.d.ts +1 -1
  53. package/lib/codegen/template/vFor.js +11 -11
  54. package/lib/codegen/template/vIf.d.ts +1 -1
  55. package/lib/codegen/template/vIf.js +6 -6
  56. package/lib/codegen/template/vSlot.d.ts +5 -0
  57. package/lib/codegen/template/vSlot.js +80 -0
  58. package/lib/codegen/utils/camelized.d.ts +2 -0
  59. package/lib/codegen/utils/camelized.js +31 -0
  60. package/lib/codegen/utils/index.d.ts +21 -0
  61. package/lib/codegen/utils/index.js +79 -0
  62. package/lib/codegen/utils/src.d.ts +2 -0
  63. package/lib/codegen/utils/src.js +19 -0
  64. package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
  65. package/lib/codegen/utils/unicode.d.ts +2 -0
  66. package/lib/codegen/utils/unicode.js +25 -0
  67. package/lib/languagePlugin.js +1 -1
  68. package/lib/parsers/scriptRanges.d.ts +7 -2
  69. package/lib/parsers/scriptSetupRanges.d.ts +69 -83
  70. package/lib/parsers/scriptSetupRanges.js +194 -171
  71. package/lib/parsers/vueCompilerOptions.d.ts +2 -0
  72. package/lib/parsers/vueCompilerOptions.js +23 -0
  73. package/lib/plugins/file-html.js +4 -3
  74. package/lib/plugins/file-md.js +1 -1
  75. package/lib/plugins/file-vue.js +4 -4
  76. package/lib/plugins/vue-root-tags.js +2 -2
  77. package/lib/plugins/vue-style-class-names.d.ts +5 -0
  78. package/lib/plugins/vue-style-class-names.js +32 -0
  79. package/lib/plugins/vue-style-reference-link.d.ts +1 -0
  80. package/lib/plugins/vue-style-reference-link.js +3 -0
  81. package/lib/plugins/vue-style-reference-links.d.ts +3 -0
  82. package/lib/plugins/vue-style-reference-links.js +26 -0
  83. package/lib/plugins/vue-template-html.js +6 -2
  84. package/lib/plugins/vue-template-inline-css.js +1 -1
  85. package/lib/plugins/vue-template-inline-ts.js +66 -17
  86. package/lib/plugins/vue-tsx.d.ts +126 -92
  87. package/lib/plugins/vue-tsx.js +114 -97
  88. package/lib/plugins/vue-vine.d.ts +3 -0
  89. package/lib/plugins/vue-vine.js +35 -0
  90. package/lib/types.d.ts +25 -12
  91. package/lib/utils/buildMappings.d.ts +1 -1
  92. package/lib/utils/parseCssImports.d.ts +4 -0
  93. package/lib/utils/parseCssImports.js +19 -0
  94. package/lib/utils/parseSfc.d.ts +5 -0
  95. package/lib/utils/parseSfc.js +11 -5
  96. package/lib/utils/signals.d.ts +2 -0
  97. package/lib/utils/signals.js +54 -0
  98. package/lib/utils/ts.d.ts +14 -2
  99. package/lib/utils/ts.js +134 -91
  100. package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
  101. package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
  102. package/lib/virtualFile/computedSfc.d.ts +1 -2
  103. package/lib/virtualFile/computedSfc.js +87 -79
  104. package/lib/virtualFile/computedVueSfc.d.ts +1 -2
  105. package/lib/virtualFile/computedVueSfc.js +7 -7
  106. package/lib/virtualFile/vueFile.d.ts +5 -5
  107. package/lib/virtualFile/vueFile.js +6 -6
  108. package/package.json +6 -6
  109. /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
package/index.d.ts CHANGED
@@ -7,7 +7,6 @@ export * from './lib/types';
7
7
  export * from './lib/utils/parseSfc';
8
8
  export * from './lib/utils/ts';
9
9
  export * from './lib/virtualFile/vueFile';
10
- export * as scriptRanges from './lib/parsers/scriptRanges';
11
10
  export { tsCodegen } from './lib/plugins/vue-tsx';
12
11
  export * from './lib/utils/shared';
13
12
  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 = exports.scriptRanges = void 0;
17
+ exports.tsCodegen = void 0;
18
18
  __exportStar(require("./lib/codegen/globalTypes"), exports);
19
19
  __exportStar(require("./lib/codegen/template"), exports);
20
20
  __exportStar(require("./lib/languagePlugin"), exports);
@@ -24,7 +24,6 @@ __exportStar(require("./lib/types"), exports);
24
24
  __exportStar(require("./lib/utils/parseSfc"), exports);
25
25
  __exportStar(require("./lib/utils/ts"), exports);
26
26
  __exportStar(require("./lib/virtualFile/vueFile"), exports);
27
- exports.scriptRanges = require("./lib/parsers/scriptRanges");
28
27
  var vue_tsx_1 = require("./lib/plugins/vue-tsx");
29
28
  Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
30
29
  __exportStar(require("./lib/utils/shared"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=codeFeatures.js.map
@@ -0,0 +1,83 @@
1
+ import type { VueCodeInformation } from '../types';
2
+ declare const raw: {
3
+ all: {
4
+ verification: true;
5
+ completion: true;
6
+ semantic: true;
7
+ navigation: true;
8
+ };
9
+ none: {};
10
+ verification: {
11
+ verification: true;
12
+ };
13
+ completion: {
14
+ completion: true;
15
+ };
16
+ additionalCompletion: {
17
+ completion: {
18
+ isAdditional: true;
19
+ };
20
+ };
21
+ withoutCompletion: {
22
+ verification: true;
23
+ semantic: true;
24
+ navigation: true;
25
+ };
26
+ navigation: {
27
+ navigation: true;
28
+ };
29
+ navigationWithoutRename: {
30
+ navigation: {
31
+ shouldRename: () => false;
32
+ };
33
+ };
34
+ navigationAndCompletion: {
35
+ navigation: true;
36
+ completion: true;
37
+ };
38
+ navigationAndAdditionalCompletion: {
39
+ navigation: true;
40
+ completion: {
41
+ isAdditional: true;
42
+ };
43
+ };
44
+ navigationAndVerification: {
45
+ navigation: true;
46
+ verification: true;
47
+ };
48
+ withoutNavigation: {
49
+ verification: true;
50
+ completion: true;
51
+ semantic: true;
52
+ };
53
+ withoutHighlight: {
54
+ semantic: {
55
+ shouldHighlight: () => false;
56
+ };
57
+ verification: true;
58
+ navigation: true;
59
+ completion: true;
60
+ };
61
+ withoutHighlightAndNavigation: {
62
+ semantic: {
63
+ shouldHighlight: () => false;
64
+ };
65
+ verification: true;
66
+ completion: true;
67
+ };
68
+ withoutHighlightAndCompletion: {
69
+ semantic: {
70
+ shouldHighlight: () => false;
71
+ };
72
+ verification: true;
73
+ navigation: true;
74
+ };
75
+ withoutHighlightAndCompletionAndNavigation: {
76
+ semantic: {
77
+ shouldHighlight: () => false;
78
+ };
79
+ verification: true;
80
+ };
81
+ };
82
+ export declare const codeFeatures: { [K in keyof typeof raw]: VueCodeInformation; };
83
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.codeFeatures = void 0;
4
+ const raw = {
5
+ all: {
6
+ verification: true,
7
+ completion: true,
8
+ semantic: true,
9
+ navigation: true,
10
+ },
11
+ none: {},
12
+ verification: {
13
+ verification: true,
14
+ },
15
+ completion: {
16
+ completion: true,
17
+ },
18
+ additionalCompletion: {
19
+ completion: { isAdditional: true },
20
+ },
21
+ withoutCompletion: {
22
+ verification: true,
23
+ semantic: true,
24
+ navigation: true,
25
+ },
26
+ navigation: {
27
+ navigation: true,
28
+ },
29
+ navigationWithoutRename: {
30
+ navigation: { shouldRename: () => false },
31
+ },
32
+ navigationAndCompletion: {
33
+ navigation: true,
34
+ completion: true,
35
+ },
36
+ navigationAndAdditionalCompletion: {
37
+ navigation: true,
38
+ completion: { isAdditional: true },
39
+ },
40
+ navigationAndVerification: {
41
+ navigation: true,
42
+ verification: true,
43
+ },
44
+ withoutNavigation: {
45
+ verification: true,
46
+ completion: true,
47
+ semantic: true,
48
+ },
49
+ withoutHighlight: {
50
+ semantic: { shouldHighlight: () => false },
51
+ verification: true,
52
+ navigation: true,
53
+ completion: true,
54
+ },
55
+ withoutHighlightAndNavigation: {
56
+ semantic: { shouldHighlight: () => false },
57
+ verification: true,
58
+ completion: true,
59
+ },
60
+ withoutHighlightAndCompletion: {
61
+ semantic: { shouldHighlight: () => false },
62
+ verification: true,
63
+ navigation: true,
64
+ },
65
+ withoutHighlightAndCompletionAndNavigation: {
66
+ semantic: { shouldHighlight: () => false },
67
+ verification: true,
68
+ },
69
+ };
70
+ exports.codeFeatures = raw;
71
+ //# sourceMappingURL=codeFeatures.js.map
@@ -1 +1,3 @@
1
- export declare function generateGlobalTypes(lib: string, target: number, strictTemplates: boolean): string;
1
+ import type { VueCompilerOptions } from '../types';
2
+ export declare function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }: VueCompilerOptions): string;
3
+ export declare function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }: VueCompilerOptions): string;
@@ -1,9 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGlobalTypesFileName = getGlobalTypesFileName;
3
4
  exports.generateGlobalTypes = generateGlobalTypes;
4
5
  const shared_1 = require("../utils/shared");
5
- function generateGlobalTypes(lib, target, strictTemplates) {
6
- const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${strictTemplates ? '' : ' & Record<string, unknown>'}`;
6
+ function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
7
+ return [
8
+ lib,
9
+ target,
10
+ checkUnknownProps,
11
+ checkUnknownEvents,
12
+ checkUnknownComponents,
13
+ ].map(v => {
14
+ if (typeof v === 'boolean') {
15
+ return v ? 1 : 0;
16
+ }
17
+ return v;
18
+ }).join('_') + '.d.ts';
19
+ }
20
+ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
21
+ const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
7
22
  let text = ``;
8
23
  if (target < 3.5) {
9
24
  text += `
@@ -17,6 +32,7 @@ function generateGlobalTypes(lib, target, strictTemplates) {
17
32
  const __VLS_intrinsicElements: __VLS_IntrinsicElements;
18
33
  const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
19
34
  const __VLS_unref: typeof import('${lib}').unref;
35
+ const __VLS_placeholder: any;
20
36
 
21
37
  const __VLS_nativeElements = {
22
38
  ...{} as SVGElementTagNameMap,
@@ -36,14 +52,15 @@ function generateGlobalTypes(lib, target, strictTemplates) {
36
52
  type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
37
53
  type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
38
54
  type __VLS_unknownDirective = (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
39
- type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
55
+ type __VLS_WithComponent<N0 extends string, LocalComponents, Self, N1 extends string, N2 extends string, N3 extends string> =
40
56
  N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
41
57
  N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
42
58
  N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N3] } :
59
+ Self extends object ? { [K in N0]: Self } :
43
60
  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
61
  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
62
  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 }'}
63
+ ${checkUnknownComponents ? '{}' : '{ [K in N0]: unknown }'};
47
64
  type __VLS_FunctionalComponentProps<T, K> =
48
65
  '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
49
66
  : T extends (props: infer P, ...args: any) => any ? P :
@@ -55,6 +72,15 @@ function generateGlobalTypes(lib, target, strictTemplates) {
55
72
  : true
56
73
  : false
57
74
  : false;
75
+ type __VLS_NormalizeComponentEvent<Props, Events, onEvent extends keyof Props, Event extends keyof Events, CamelizedEvent extends keyof Events> = (
76
+ __VLS_IsFunction<Props, onEvent> extends true
77
+ ? Props
78
+ : __VLS_IsFunction<Events, Event> extends true
79
+ ? { [K in onEvent]?: Events[Event] }
80
+ : __VLS_IsFunction<Events, CamelizedEvent> extends true
81
+ ? { [K in onEvent]?: Events[CamelizedEvent] }
82
+ : Props
83
+ )${checkUnknownEvents ? '' : ' & Record<string, unknown>'};
58
84
  // fix https://github.com/vuejs/language-tools/issues/926
59
85
  type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
60
86
  type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
@@ -83,25 +109,25 @@ function generateGlobalTypes(lib, target, strictTemplates) {
83
109
  '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
84
110
  , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
85
111
  >>;
112
+ type __VLS_OmitStringIndex<T> = {
113
+ [K in keyof T as string extends K ? never : K]: T[K];
114
+ };
86
115
  type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
87
116
 
88
- function __VLS_getVForSourceType(source: number): [number, number, number][];
89
- function __VLS_getVForSourceType(source: string): [string, number, number][];
117
+ function __VLS_getVForSourceType(source: number): [number, number][];
118
+ function __VLS_getVForSourceType(source: string): [string, number][];
90
119
  function __VLS_getVForSourceType<T extends any[]>(source: T): [
91
120
  item: T[number],
92
- key: number,
93
121
  index: number,
94
122
  ][];
95
123
  function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
96
124
  item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
97
- key: number,
98
- index: undefined,
125
+ index: number,
99
126
  ][];
100
127
  // #3845
101
128
  function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
102
129
  item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
103
- key: number,
104
- index: undefined,
130
+ index: number,
105
131
  ][];
106
132
  function __VLS_getVForSourceType<T>(source: T): [
107
133
  item: T[keyof T],
@@ -119,7 +145,6 @@ function generateGlobalTypes(lib, target, strictTemplates) {
119
145
  : __VLS_unknownDirective;
120
146
  function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
121
147
  function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
122
- function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
123
148
  function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
124
149
  T extends new (...args: any) => any
125
150
  ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
@@ -129,8 +154,8 @@ function generateGlobalTypes(lib, target, strictTemplates) {
129
154
  } & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
130
155
  : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
131
156
  : T extends (...args: any) => any ? T
132
- : (_: {}${strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates ? '' : ' & Record<string, unknown>'} } };
133
- function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
157
+ : (_: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'} } };
158
+ function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (_: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
134
159
  function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
135
160
  function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
136
161
  function __VLS_tryAsConstant<const T>(t: T): T;
@@ -6,7 +6,7 @@ export declare function getLocalTypesGenerator(compilerOptions: ts.CompilerOptio
6
6
  readonly PrettifyLocal: string;
7
7
  readonly OmitKeepDiscriminatedUnion: string;
8
8
  readonly WithDefaults: string;
9
- readonly WithTemplateSlots: string;
9
+ readonly WithSlots: string;
10
10
  readonly PropsChildren: string;
11
11
  readonly TypePropsToOption: string;
12
12
  readonly OmitIndexSignature: string;
@@ -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,9 +17,9 @@ 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}`);
21
- const WithTemplateSlots = defineHelper(`__VLS_WithTemplateSlots`, () => `
22
- type __VLS_WithTemplateSlots<T, S> = T & {
20
+ const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}${utils_1.endOfLine}`);
21
+ const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
22
+ type __VLS_WithSlots<T, S> = T & {
23
23
  new(): {
24
24
  ${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;
25
25
  ${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
@@ -57,12 +57,12 @@ 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,
64
64
  [WithDefaults.name]: WithDefaults,
65
- [WithTemplateSlots.name]: WithTemplateSlots,
65
+ [WithSlots.name]: WithSlots,
66
66
  [PropsChildren.name]: PropsChildren,
67
67
  [TypePropsToOption.name]: TypePropsToOption,
68
68
  [OmitIndexSignature.name]: OmitIndexSignature,
@@ -76,7 +76,7 @@ type __VLS_TypePropsToOption<T> = {
76
76
  get PrettifyLocal() { return PrettifyLocal.name; },
77
77
  get OmitKeepDiscriminatedUnion() { return OmitKeepDiscriminatedUnion.name; },
78
78
  get WithDefaults() { return WithDefaults.name; },
79
- get WithTemplateSlots() { return WithTemplateSlots.name; },
79
+ get WithSlots() { return WithSlots.name; },
80
80
  get PropsChildren() { return PropsChildren.name; },
81
81
  get TypePropsToOption() { return TypePropsToOption.name; },
82
82
  get OmitIndexSignature() { return OmitIndexSignature.name; },
@@ -0,0 +1,4 @@
1
+ import type { TemplateCodegenContext } from '../template/context';
2
+ import type { ScriptCodegenContext } from './context';
3
+ import type { ScriptCodegenOptions } from './index';
4
+ export declare function generateBindings(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<import("../../types").Code, void, any>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateBindings = generateBindings;
4
+ const utils_1 = require("../utils");
5
+ const component_1 = require("./component");
6
+ const template_1 = require("./template");
7
+ function* generateBindings(options, ctx, templateCodegenCtx) {
8
+ if (!options.sfc.scriptSetup || !options.scriptSetupRanges) {
9
+ return;
10
+ }
11
+ yield `const __VLS_bindings = {`;
12
+ if (ctx.bypassDefineComponent) {
13
+ yield* (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges);
14
+ }
15
+ const templateUsageVars = (0, template_1.getTemplateUsageVars)(options, ctx);
16
+ for (const [content, bindings] of [
17
+ [options.sfc.scriptSetup.content, options.scriptSetupRanges.bindings],
18
+ options.sfc.script && options.scriptRanges
19
+ ? [options.sfc.script.content, options.scriptRanges.bindings]
20
+ : ['', []],
21
+ ]) {
22
+ for (const { range } of bindings) {
23
+ const varName = content.slice(range.start, range.end);
24
+ if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
25
+ continue;
26
+ }
27
+ const templateOffset = options.getGeneratedLength();
28
+ yield `${varName}: ${varName} as typeof `;
29
+ const scriptOffset = options.getGeneratedLength();
30
+ yield `${varName},${utils_1.newLine}`;
31
+ options.linkedCodeMappings.push({
32
+ sourceOffsets: [scriptOffset],
33
+ generatedOffsets: [templateOffset],
34
+ lengths: [varName.length],
35
+ data: undefined,
36
+ });
37
+ }
38
+ }
39
+ yield `}${utils_1.endOfLine}`;
40
+ }
41
+ //# sourceMappingURL=binding.js.map
@@ -1,7 +1,7 @@
1
1
  import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
2
2
  import type { Code, Sfc } from '../../types';
3
3
  import type { ScriptCodegenContext } from './context';
4
- import { ScriptCodegenOptions } from './index';
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
6
  export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
7
7
  export declare function generateEmitsOption(options: ScriptCodegenOptions, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
@@ -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");
8
- const index_1 = require("./index");
7
+ const codeFeatures_1 = require("../codeFeatures");
8
+ const utils_1 = require("../utils");
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, codeFeatures_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, codeFeatures_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_TemplateRefs,${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_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,22 +112,22 @@ 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, codeFeatures_1.codeFeatures.navigation),
126
126
  typeOptionExp: undefined,
127
127
  });
128
128
  }
129
129
  if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
130
- let attrsType = `__VLS_TemplateResult['attrs']`;
130
+ let attrsType = `Partial<__VLS_InheritedAttrs>`;
131
131
  if (hasEmitsOption) {
132
132
  attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
133
133
  }
@@ -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,5 +1,5 @@
1
1
  import type { Code } from '../../types';
2
2
  import type { TemplateCodegenContext } from '../template/context';
3
3
  import type { ScriptCodegenContext } from './context';
4
- import { type ScriptCodegenOptions } from './index';
4
+ import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateComponentSelf(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<Code>;