@vue/language-core 2.2.2 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/lib/codegen/globalTypes.js +20 -28
  2. package/lib/codegen/script/component.js +10 -6
  3. package/lib/codegen/script/index.js +4 -6
  4. package/lib/codegen/script/scriptSetup.js +45 -34
  5. package/lib/codegen/script/src.d.ts +2 -2
  6. package/lib/codegen/script/src.js +36 -37
  7. package/lib/codegen/script/template.d.ts +1 -2
  8. package/lib/codegen/script/template.js +4 -50
  9. package/lib/codegen/style/classProperty.d.ts +2 -0
  10. package/lib/codegen/style/classProperty.js +31 -0
  11. package/lib/codegen/style/modules.d.ts +3 -0
  12. package/lib/codegen/{script/styleModulesType.js → style/modules.js} +14 -14
  13. package/lib/codegen/style/scopedClasses.d.ts +4 -0
  14. package/lib/codegen/style/scopedClasses.js +32 -0
  15. package/lib/codegen/template/context.d.ts +106 -5
  16. package/lib/codegen/template/context.js +129 -5
  17. package/lib/codegen/template/element.d.ts +1 -1
  18. package/lib/codegen/template/element.js +61 -85
  19. package/lib/codegen/template/elementChildren.d.ts +1 -1
  20. package/lib/codegen/template/elementChildren.js +1 -13
  21. package/lib/codegen/template/elementDirectives.js +2 -1
  22. package/lib/codegen/template/elementEvents.d.ts +1 -1
  23. package/lib/codegen/template/elementEvents.js +15 -11
  24. package/lib/codegen/template/elementProps.d.ts +1 -1
  25. package/lib/codegen/template/elementProps.js +11 -9
  26. package/lib/codegen/template/index.js +27 -13
  27. package/lib/codegen/template/interpolation.js +5 -5
  28. package/lib/codegen/template/slotOutlet.js +11 -10
  29. package/lib/codegen/template/styleScopedClasses.js +5 -9
  30. package/lib/codegen/template/templateChild.js +60 -28
  31. package/lib/codegen/template/vFor.js +2 -2
  32. package/lib/codegen/template/vIf.js +3 -3
  33. package/lib/codegen/template/vSlot.d.ts +1 -0
  34. package/lib/codegen/template/vSlot.js +12 -0
  35. package/lib/codegen/utils/index.d.ts +2 -1
  36. package/lib/codegen/utils/index.js +18 -2
  37. package/lib/parsers/scriptSetupRanges.js +20 -28
  38. package/lib/plugins/file-md.js +3 -0
  39. package/lib/plugins/vue-template-inline-ts.js +3 -3
  40. package/lib/plugins/vue-tsx.d.ts +9 -5
  41. package/lib/plugins/vue-tsx.js +20 -20
  42. package/lib/types.d.ts +23 -14
  43. package/lib/utils/parseSfc.js +40 -16
  44. package/lib/utils/ts.js +17 -0
  45. package/lib/virtualFile/computedEmbeddedCodes.js +3 -13
  46. package/lib/virtualFile/computedSfc.js +21 -28
  47. package/lib/virtualFile/vueFile.d.ts +7 -10
  48. package/lib/virtualFile/vueFile.js +10 -4
  49. package/package.json +2 -2
  50. package/lib/codeFeatures.d.ts +0 -1
  51. package/lib/codeFeatures.js +0 -3
  52. package/lib/codegen/common.d.ts +0 -12
  53. package/lib/codegen/common.js +0 -79
  54. package/lib/codegen/script/binding.d.ts +0 -4
  55. package/lib/codegen/script/binding.js +0 -41
  56. package/lib/codegen/script/styleModulesType.d.ts +0 -4
  57. package/lib/codegen/template/camelized.d.ts +0 -2
  58. package/lib/codegen/template/camelized.js +0 -31
  59. package/lib/codegen/utils/src.d.ts +0 -2
  60. package/lib/codegen/utils/src.js +0 -19
  61. package/lib/plugins/vue-style-class-names.d.ts +0 -5
  62. package/lib/plugins/vue-style-class-names.js +0 -32
  63. package/lib/plugins/vue-style-reference-link.d.ts +0 -1
  64. package/lib/plugins/vue-style-reference-link.js +0 -3
  65. package/lib/plugins/vue-style-reference-links.d.ts +0 -3
  66. package/lib/plugins/vue-style-reference-links.js +0 -26
  67. package/lib/plugins/vue-vine.d.ts +0 -3
  68. package/lib/plugins/vue-vine.js +0 -35
  69. package/lib/utils/findDestructuredProps.d.ts +0 -1
  70. package/lib/utils/findDestructuredProps.js +0 -3
  71. package/lib/utils/parseCssImports.d.ts +0 -4
  72. package/lib/utils/parseCssImports.js +0 -19
@@ -34,11 +34,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
34
34
  const __VLS_unref: typeof import('${lib}').unref;
35
35
  const __VLS_placeholder: any;
36
36
 
37
- const __VLS_nativeElements = {
38
- ...{} as SVGElementTagNameMap,
39
- ...{} as HTMLElementTagNameMap,
40
- };
41
-
37
+ type __VLS_NativeElements = __VLS_SpreadMerge<SVGElementTagNameMap, HTMLElementTagNameMap>;
42
38
  type __VLS_IntrinsicElements = ${(target >= 3.3
43
39
  ? `import('${lib}/jsx-runtime').JSX.IntrinsicElements;`
44
40
  : `globalThis.JSX.IntrinsicElements;`)}
@@ -51,7 +47,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
51
47
  type __VLS_GlobalDirectives = import('${lib}').GlobalDirectives;
52
48
  type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
53
49
  type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
54
- type __VLS_unknownDirective = (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
50
+ type __VLS_SpreadMerge<A, B> = Omit<A, keyof B> & B;
55
51
  type __VLS_WithComponent<N0 extends string, LocalComponents, Self, N1 extends string, N2 extends string, N3 extends string> =
56
52
  N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
57
53
  N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
@@ -114,19 +110,12 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
114
110
  };
115
111
  type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
116
112
 
117
- function __VLS_getVForSourceType(source: number): [number, number][];
118
- function __VLS_getVForSourceType(source: string): [string, number][];
119
- function __VLS_getVForSourceType<T extends any[]>(source: T): [
120
- item: T[number],
121
- index: number,
122
- ][];
123
- function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
124
- item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
125
- index: number,
126
- ][];
127
- // #3845
128
- function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
129
- item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
113
+ function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [
114
+ item: T extends number ? number
115
+ : T extends string ? string
116
+ : T extends any[] ? T[number]
117
+ : T extends Iterable<infer T1> ? T1
118
+ : any,
130
119
  index: number,
131
120
  ][];
132
121
  function __VLS_getVForSourceType<T>(source: T): [
@@ -142,22 +131,25 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
142
131
  ? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
143
132
  : T extends (...args: any) => any
144
133
  ? T
145
- : __VLS_unknownDirective;
146
- function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
134
+ : (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
147
135
  function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
148
136
  function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
149
137
  T extends new (...args: any) => any
150
- ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
151
- attrs?: any,
152
- slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any,
153
- emit?: K extends { $emit: infer Emit } ? Emit : any
154
- } & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
138
+ ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
139
+ __ctx?: {
140
+ attrs?: any;
141
+ slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any;
142
+ emit?: K extends { $emit: infer Emit } ? Emit : any;
143
+ expose?(exposed: K): void;
144
+ props?: ${fnPropsType};
145
+ }
146
+ }
155
147
  : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
156
148
  : T extends (...args: any) => any ? T
157
149
  : (_: {}${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;
159
150
  function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
160
- function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
151
+ function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
152
+ function __VLS_asFunctionalSlot<S>(slot: S): (props: NonNullable<S> extends (props: infer P) => any ? P : {}) => void;
161
153
  function __VLS_tryAsConstant<const T>(t: T): T;
162
154
  }
163
155
  `;
@@ -32,16 +32,20 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
32
32
  }
33
33
  yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length, true);
34
34
  }
35
- if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
36
- const { args } = options.scriptRanges.exportDefault;
37
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
38
- }
39
- if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.templateRefs.size) {
35
+ if (options.vueCompilerOptions.target >= 3.5
36
+ && options.vueCompilerOptions.inferComponentDollarRefs
37
+ && options.templateCodegen?.templateRefs.size) {
40
38
  yield `__typeRefs: {} as __VLS_TemplateRefs,${utils_1.newLine}`;
41
39
  }
42
- if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.singleRootElType) {
40
+ if (options.vueCompilerOptions.target >= 3.5
41
+ && options.vueCompilerOptions.inferComponentDollarEl
42
+ && options.templateCodegen?.singleRootElTypes.length) {
43
43
  yield `__typeEl: {} as __VLS_RootEl,${utils_1.newLine}`;
44
44
  }
45
+ if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
46
+ const { args } = options.scriptRanges.exportDefault;
47
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
48
+ }
45
49
  yield `})`;
46
50
  }
47
51
  function* generateComponentSetupReturns(scriptSetupRanges) {
@@ -10,7 +10,6 @@ const componentSelf_1 = require("./componentSelf");
10
10
  const context_1 = require("./context");
11
11
  const scriptSetup_1 = require("./scriptSetup");
12
12
  const src_1 = require("./src");
13
- const styleModulesType_1 = require("./styleModulesType");
14
13
  const template_1 = require("./template");
15
14
  function* generateScript(options) {
16
15
  const ctx = (0, context_1.createScriptCodegenContext)(options);
@@ -31,14 +30,16 @@ function* generateScript(options) {
31
30
  yield `/* placeholder */`;
32
31
  }
33
32
  if (options.sfc.script?.src) {
34
- yield* (0, src_1.generateSrc)(options.sfc.script, options.sfc.script.src);
33
+ yield* (0, src_1.generateSrc)(options.sfc.script.src);
34
+ }
35
+ if (options.sfc.scriptSetup && options.scriptSetupRanges) {
36
+ yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
35
37
  }
36
38
  if (options.sfc.script && options.scriptRanges) {
37
39
  const { exportDefault, classBlockEnd } = options.scriptRanges;
38
40
  const isExportRawObject = exportDefault
39
41
  && options.sfc.script.content[exportDefault.expression.start] === '{';
40
42
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
41
- yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
42
43
  if (exportDefault) {
43
44
  yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, codeFeatures_1.codeFeatures.all);
44
45
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
@@ -94,7 +95,6 @@ function* generateScript(options) {
94
95
  }
95
96
  }
96
97
  else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
97
- yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
98
98
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
99
99
  }
100
100
  if (options.sfc.script) {
@@ -107,8 +107,6 @@ function* generateScript(options) {
107
107
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
108
108
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
109
109
  }
110
- // #4788
111
- yield* (0, styleModulesType_1.generateStyleModulesType)(options, ctx);
112
110
  if (options.edited) {
113
111
  yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${utils_1.endOfLine}`;
114
112
  }
@@ -30,17 +30,21 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
30
30
  }
31
31
  yield `export default `;
32
32
  }
33
- yield `(<`;
34
- yield [
35
- scriptSetup.generic,
36
- scriptSetup.name,
37
- scriptSetup.genericOffset,
38
- codeFeatures_1.codeFeatures.all,
39
- ];
40
- if (!scriptSetup.generic.endsWith(`,`)) {
41
- yield `,`;
33
+ yield `(`;
34
+ if (typeof scriptSetup.generic === 'object') {
35
+ yield `<`;
36
+ yield [
37
+ scriptSetup.generic.text,
38
+ 'main',
39
+ scriptSetup.generic.offset,
40
+ codeFeatures_1.codeFeatures.all,
41
+ ];
42
+ if (!scriptSetup.generic.text.endsWith(`,`)) {
43
+ yield `,`;
44
+ }
45
+ yield `>`;
42
46
  }
43
- yield `>(${utils_1.newLine}`
47
+ yield `(${utils_1.newLine}`
44
48
  + ` __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'],${utils_1.newLine}`
45
49
  + ` __VLS_ctx?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>,${utils_1.newLine}` // use __VLS_Prettify for less dts code
46
50
  + ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${utils_1.newLine}`
@@ -123,16 +127,18 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
123
127
  ]);
124
128
  }
125
129
  }
126
- for (const { callExp } of scriptSetupRanges.useAttrs) {
127
- setupCodeModifies.push([
128
- [`(`],
129
- callExp.start,
130
- callExp.start
131
- ], [
132
- [` as typeof __VLS_special.$attrs)`],
133
- callExp.end,
134
- callExp.end
135
- ]);
130
+ if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
131
+ for (const { callExp } of scriptSetupRanges.useAttrs) {
132
+ setupCodeModifies.push([
133
+ [`(`],
134
+ callExp.start,
135
+ callExp.start
136
+ ], [
137
+ [` as typeof __VLS_dollars.$attrs)`],
138
+ callExp.end,
139
+ callExp.end
140
+ ]);
141
+ }
136
142
  }
137
143
  for (const { callExp, exp, arg } of scriptSetupRanges.useCssModule) {
138
144
  setupCodeModifies.push([
@@ -156,22 +162,24 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
156
162
  ]);
157
163
  if (arg) {
158
164
  setupCodeModifies.push([
159
- [`(__VLS_placeholder)`],
165
+ [`__VLS_placeholder`],
160
166
  arg.start,
161
167
  arg.end
162
168
  ]);
163
169
  }
164
170
  }
165
- for (const { callExp } of scriptSetupRanges.useSlots) {
166
- setupCodeModifies.push([
167
- [`(`],
168
- callExp.start,
169
- callExp.start
170
- ], [
171
- [` as typeof __VLS_special.$slots)`],
172
- callExp.end,
173
- callExp.end
174
- ]);
171
+ if (options.vueCompilerOptions.inferTemplateDollarSlots) {
172
+ for (const { callExp } of scriptSetupRanges.useSlots) {
173
+ setupCodeModifies.push([
174
+ [`(`],
175
+ callExp.start,
176
+ callExp.start
177
+ ], [
178
+ [` as typeof __VLS_dollars.$slots)`],
179
+ callExp.end,
180
+ callExp.end
181
+ ]);
182
+ }
175
183
  }
176
184
  const isTs = options.lang !== 'js' && options.lang !== 'jsx';
177
185
  for (const { callExp, exp, arg } of scriptSetupRanges.useTemplateRef) {
@@ -210,7 +218,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
210
218
  }
211
219
  if (arg) {
212
220
  setupCodeModifies.push([
213
- [`(__VLS_placeholder)`],
221
+ [`__VLS_placeholder`],
214
222
  arg.start,
215
223
  arg.end
216
224
  ]);
@@ -240,7 +248,10 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
240
248
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
241
249
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
242
250
  if (syntax) {
243
- if (!options.vueCompilerOptions.skipTemplateCodegen && (options.templateCodegen?.hasSlot || scriptSetupRanges.defineSlots)) {
251
+ if (!options.vueCompilerOptions.skipTemplateCodegen
252
+ && (scriptSetupRanges.defineSlots
253
+ || options.templateCodegen?.slots.length
254
+ || options.templateCodegen?.dynamicSlots.length)) {
244
255
  yield `const __VLS_component = `;
245
256
  yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
246
257
  yield utils_1.endOfLine;
@@ -423,7 +434,7 @@ function* generateModelEmit(scriptSetup, scriptSetupRanges) {
423
434
  const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
424
435
  yield `'update:${propName}': [value: `;
425
436
  yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
426
- if (!defineModel.required) {
437
+ if (!defineModel.required && defineModel.defaultValue === undefined) {
427
438
  yield ` | undefined`;
428
439
  }
429
440
  yield `]${utils_1.endOfLine}`;
@@ -1,2 +1,2 @@
1
- import type { Code, Sfc } from '../../types';
2
- export declare function generateSrc(script: NonNullable<Sfc['script']>, src: string): Generator<Code>;
1
+ import type { Code, SfcBlockAttr } from '../../types';
2
+ export declare function generateSrc(src: SfcBlockAttr): Generator<Code>;
@@ -3,49 +3,48 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSrc = generateSrc;
4
4
  const codeFeatures_1 = require("../codeFeatures");
5
5
  const utils_1 = require("../utils");
6
- function* generateSrc(script, src) {
7
- if (src.endsWith('.d.ts')) {
8
- src = src.slice(0, -'.d.ts'.length);
6
+ function* generateSrc(src) {
7
+ if (src === true) {
8
+ return;
9
9
  }
10
- else if (src.endsWith('.ts')) {
11
- src = src.slice(0, -'.ts'.length);
10
+ let { text } = src;
11
+ if (text.endsWith('.d.ts')) {
12
+ text = text.slice(0, -'.d.ts'.length);
12
13
  }
13
- else if (src.endsWith('.tsx')) {
14
- src = src.slice(0, -'.tsx'.length) + '.jsx';
14
+ else if (text.endsWith('.ts')) {
15
+ text = text.slice(0, -'.ts'.length);
15
16
  }
16
- if (!src.endsWith('.js') && !src.endsWith('.jsx')) {
17
- src = src + '.js';
17
+ else if (text.endsWith('.tsx')) {
18
+ text = text.slice(0, -'.tsx'.length) + '.jsx';
19
+ }
20
+ if (!text.endsWith('.js') && !text.endsWith('.jsx')) {
21
+ text = text + '.js';
18
22
  }
19
23
  yield `export * from `;
20
- yield [
21
- `'${src}'`,
22
- 'script',
23
- script.srcOffset - 1,
24
- {
25
- ...codeFeatures_1.codeFeatures.all,
26
- navigation: src === script.src
27
- ? true
28
- : {
29
- shouldRename: () => false,
30
- resolveRenameEditText(newName) {
31
- if (newName.endsWith('.jsx') || newName.endsWith('.js')) {
32
- newName = newName.split('.').slice(0, -1).join('.');
33
- }
34
- if (script?.src?.endsWith('.d.ts')) {
35
- newName = newName + '.d.ts';
36
- }
37
- else if (script?.src?.endsWith('.ts')) {
38
- newName = newName + '.ts';
39
- }
40
- else if (script?.src?.endsWith('.tsx')) {
41
- newName = newName + '.tsx';
42
- }
43
- return newName;
44
- },
24
+ yield* (0, utils_1.generateSfcBlockAttrValue)(src, text, {
25
+ ...codeFeatures_1.codeFeatures.all,
26
+ navigation: text === src.text
27
+ ? true
28
+ : {
29
+ shouldRename: () => false,
30
+ resolveRenameEditText(newName) {
31
+ if (newName.endsWith('.jsx') || newName.endsWith('.js')) {
32
+ newName = newName.split('.').slice(0, -1).join('.');
33
+ }
34
+ if (src?.text.endsWith('.d.ts')) {
35
+ newName = newName + '.d.ts';
36
+ }
37
+ else if (src?.text.endsWith('.ts')) {
38
+ newName = newName + '.ts';
39
+ }
40
+ else if (src?.text.endsWith('.tsx')) {
41
+ newName = newName + '.tsx';
42
+ }
43
+ return newName;
45
44
  },
46
- },
47
- ];
45
+ },
46
+ });
48
47
  yield utils_1.endOfLine;
49
- yield `export { default } from '${src}'${utils_1.endOfLine}`;
48
+ yield `export { default } from '${text}'${utils_1.endOfLine}`;
50
49
  }
51
50
  //# sourceMappingURL=src.js.map
@@ -1,8 +1,7 @@
1
1
  import type { Code } from '../../types';
2
- import { TemplateCodegenContext } from '../template/context';
2
+ import { type TemplateCodegenContext } from '../template/context';
3
3
  import type { ScriptCodegenContext } from './context';
4
4
  import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code, TemplateCodegenContext>;
6
6
  export declare function generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code>;
7
- export declare function generateCssClassProperty(styleIndex: number, classNameWithDot: string, offset: number, propertyType: string, optional: boolean): Generator<Code>;
8
7
  export declare function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Set<string>;
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTemplate = generateTemplate;
4
4
  exports.generateTemplateDirectives = generateTemplateDirectives;
5
- exports.generateCssClassProperty = generateCssClassProperty;
6
5
  exports.getTemplateUsageVars = getTemplateUsageVars;
7
6
  const shared_1 = require("../../utils/shared");
8
7
  const codeFeatures_1 = require("../codeFeatures");
8
+ const modules_1 = require("../style/modules");
9
+ const scopedClasses_1 = require("../style/scopedClasses");
9
10
  const context_1 = require("../template/context");
10
11
  const interpolation_1 = require("../template/interpolation");
11
12
  const styleScopedClasses_1 = require("../template/styleScopedClasses");
@@ -93,8 +94,9 @@ function* generateTemplateDirectives(options) {
93
94
  yield `let __VLS_directives!: __VLS_LocalDirectives & __VLS_GlobalDirectives${utils_1.endOfLine}`;
94
95
  }
95
96
  function* generateTemplateBody(options, templateCodegenCtx) {
96
- yield* generateStyleScopedClasses(options, templateCodegenCtx);
97
+ yield* (0, scopedClasses_1.generateStyleScopedClasses)(options, templateCodegenCtx);
97
98
  yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(templateCodegenCtx, true);
99
+ yield* (0, modules_1.generateStyleModules)(options);
98
100
  yield* generateCssVars(options, templateCodegenCtx);
99
101
  if (options.templateCodegen) {
100
102
  for (const code of options.templateCodegen.codes) {
@@ -111,54 +113,6 @@ function* generateTemplateBody(options, templateCodegenCtx) {
111
113
  yield `type __VLS_RootEl = any${utils_1.endOfLine}`;
112
114
  }
113
115
  }
114
- function* generateStyleScopedClasses(options, ctx) {
115
- const firstClasses = new Set();
116
- yield `type __VLS_StyleScopedClasses = {}`;
117
- for (let i = 0; i < options.sfc.styles.length; i++) {
118
- const style = options.sfc.styles[i];
119
- const option = options.vueCompilerOptions.experimentalResolveStyleCssClasses;
120
- if (option === 'always' || (option === 'scoped' && style.scoped)) {
121
- for (const className of style.classNames) {
122
- if (firstClasses.has(className.text)) {
123
- ctx.scopedClasses.push({
124
- source: 'style_' + i,
125
- className: className.text.slice(1),
126
- offset: className.offset + 1
127
- });
128
- continue;
129
- }
130
- firstClasses.add(className.text);
131
- yield* generateCssClassProperty(i, className.text, className.offset, 'boolean', true);
132
- }
133
- }
134
- }
135
- yield utils_1.endOfLine;
136
- }
137
- function* generateCssClassProperty(styleIndex, classNameWithDot, offset, propertyType, optional) {
138
- yield `${utils_1.newLine} & { `;
139
- yield [
140
- '',
141
- 'style_' + styleIndex,
142
- offset,
143
- codeFeatures_1.codeFeatures.navigation,
144
- ];
145
- yield `'`;
146
- yield [
147
- classNameWithDot.slice(1),
148
- 'style_' + styleIndex,
149
- offset + 1,
150
- codeFeatures_1.codeFeatures.navigation,
151
- ];
152
- yield `'`;
153
- yield [
154
- '',
155
- 'style_' + styleIndex,
156
- offset + classNameWithDot.length,
157
- codeFeatures_1.codeFeatures.navigationWithoutRename,
158
- ];
159
- yield `${optional ? '?' : ''}: ${propertyType}`;
160
- yield ` }`;
161
- }
162
116
  function* generateCssVars(options, ctx) {
163
117
  if (!options.sfc.styles.length) {
164
118
  return;
@@ -0,0 +1,2 @@
1
+ import type { Code } from '../../types';
2
+ export declare function generateClassProperty(styleIndex: number, classNameWithDot: string, offset: number, propertyType: string): Generator<Code>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateClassProperty = generateClassProperty;
4
+ const codeFeatures_1 = require("../codeFeatures");
5
+ const utils_1 = require("../utils");
6
+ function* generateClassProperty(styleIndex, classNameWithDot, offset, propertyType) {
7
+ yield `${utils_1.newLine} & { `;
8
+ yield [
9
+ '',
10
+ 'style_' + styleIndex,
11
+ offset,
12
+ codeFeatures_1.codeFeatures.navigation,
13
+ ];
14
+ yield `'`;
15
+ yield [
16
+ classNameWithDot.slice(1),
17
+ 'style_' + styleIndex,
18
+ offset + 1,
19
+ codeFeatures_1.codeFeatures.navigation,
20
+ ];
21
+ yield `'`;
22
+ yield [
23
+ '',
24
+ 'style_' + styleIndex,
25
+ offset + classNameWithDot.length,
26
+ codeFeatures_1.codeFeatures.navigation,
27
+ ];
28
+ yield `: ${propertyType}`;
29
+ yield ` }`;
30
+ }
31
+ //# sourceMappingURL=classProperty.js.map
@@ -0,0 +1,3 @@
1
+ import type { Code } from '../../types';
2
+ import type { ScriptCodegenOptions } from '../script';
3
+ export declare function generateStyleModules(options: ScriptCodegenOptions): Generator<Code>;
@@ -1,34 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateStyleModulesType = generateStyleModulesType;
3
+ exports.generateStyleModules = generateStyleModules;
4
4
  const codeFeatures_1 = require("../codeFeatures");
5
5
  const utils_1 = require("../utils");
6
- const template_1 = require("./template");
7
- function* generateStyleModulesType(options, ctx) {
6
+ const classProperty_1 = require("./classProperty");
7
+ function* generateStyleModules(options) {
8
8
  const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
9
9
  if (!styles.length && !options.scriptSetupRanges?.useCssModule.length) {
10
10
  return;
11
11
  }
12
12
  yield `type __VLS_StyleModules = {${utils_1.newLine}`;
13
13
  for (const [style, i] of styles) {
14
- const { name, offset } = style.module;
15
- if (offset) {
14
+ if (style.module === true) {
15
+ yield `$style`;
16
+ }
17
+ else {
18
+ const { text, offset } = style.module;
16
19
  yield [
17
- name,
20
+ text,
18
21
  'main',
19
- offset + 1,
20
- codeFeatures_1.codeFeatures.all
22
+ offset,
23
+ codeFeatures_1.codeFeatures.withoutHighlight
21
24
  ];
22
25
  }
23
- else {
24
- yield name;
25
- }
26
- yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
26
+ yield `: Record<string, string> & __VLS_PrettifyGlobal<{}`;
27
27
  for (const className of style.classNames) {
28
- yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
28
+ yield* (0, classProperty_1.generateClassProperty)(i, className.text, className.offset, 'string');
29
29
  }
30
30
  yield `>${utils_1.endOfLine}`;
31
31
  }
32
32
  yield `}${utils_1.endOfLine}`;
33
33
  }
34
- //# sourceMappingURL=styleModulesType.js.map
34
+ //# sourceMappingURL=modules.js.map
@@ -0,0 +1,4 @@
1
+ import type { Code } from '../../types';
2
+ import type { ScriptCodegenOptions } from '../script';
3
+ import type { TemplateCodegenContext } from '../template/context';
4
+ export declare function generateStyleScopedClasses(options: ScriptCodegenOptions, ctx: TemplateCodegenContext): Generator<Code>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateStyleScopedClasses = generateStyleScopedClasses;
4
+ const utils_1 = require("../utils");
5
+ const classProperty_1 = require("./classProperty");
6
+ function* generateStyleScopedClasses(options, ctx) {
7
+ const option = options.vueCompilerOptions.experimentalResolveStyleCssClasses;
8
+ const styles = options.sfc.styles
9
+ .map((style, i) => [style, i])
10
+ .filter(([style]) => option === 'always' || (option === 'scoped' && style.scoped));
11
+ if (!styles.length) {
12
+ return;
13
+ }
14
+ const firstClasses = new Set();
15
+ yield `type __VLS_StyleScopedClasses = {}`;
16
+ for (const [style, i] of styles) {
17
+ for (const className of style.classNames) {
18
+ if (firstClasses.has(className.text)) {
19
+ ctx.scopedClasses.push({
20
+ source: 'style_' + i,
21
+ className: className.text.slice(1),
22
+ offset: className.offset + 1
23
+ });
24
+ continue;
25
+ }
26
+ firstClasses.add(className.text);
27
+ yield* (0, classProperty_1.generateClassProperty)(i, className.text, className.offset, 'boolean');
28
+ }
29
+ }
30
+ yield utils_1.endOfLine;
31
+ }
32
+ //# sourceMappingURL=scopedClasses.js.map