@vue/language-core 3.1.6 → 3.1.8

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 (51) hide show
  1. package/lib/codegen/globalTypes.js +1 -1
  2. package/lib/codegen/names.d.ts +0 -1
  3. package/lib/codegen/names.js +1 -2
  4. package/lib/codegen/script/component.js +1 -14
  5. package/lib/codegen/script/index.js +59 -53
  6. package/lib/codegen/script/scriptSetup.js +2 -2
  7. package/lib/codegen/script/src.d.ts +1 -0
  8. package/lib/codegen/script/src.js +17 -12
  9. package/lib/codegen/script/template.d.ts +1 -1
  10. package/lib/codegen/script/template.js +9 -24
  11. package/lib/codegen/style/classProperty.d.ts +2 -0
  12. package/lib/codegen/style/classProperty.js +18 -0
  13. package/lib/codegen/style/imports.d.ts +2 -0
  14. package/lib/codegen/style/imports.js +27 -0
  15. package/lib/codegen/style/index.d.ts +1 -4
  16. package/lib/codegen/template/context.d.ts +1 -4
  17. package/lib/codegen/template/context.js +2 -1
  18. package/lib/codegen/template/element.js +105 -157
  19. package/lib/codegen/template/elementChildren.d.ts +5 -0
  20. package/lib/codegen/template/elementChildren.js +12 -0
  21. package/lib/codegen/template/elementEvents.d.ts +1 -1
  22. package/lib/codegen/template/elementEvents.js +3 -3
  23. package/lib/codegen/template/index.d.ts +2 -5
  24. package/lib/codegen/template/templateChild.js +11 -15
  25. package/lib/codegen/template/vSlot.d.ts +1 -1
  26. package/lib/codegen/template/vSlot.js +14 -20
  27. package/lib/codegen/utils/index.d.ts +2 -2
  28. package/lib/codegen/utils/index.js +15 -11
  29. package/lib/codegen/utils/wrapWith.d.ts +2 -0
  30. package/lib/codegen/utils/wrapWith.js +15 -0
  31. package/lib/languagePlugin.js +3 -4
  32. package/lib/parsers/scriptRanges.d.ts +6 -8
  33. package/lib/parsers/scriptRanges.js +5 -2
  34. package/lib/parsers/scriptSetupRanges.d.ts +2 -6
  35. package/lib/parsers/scriptSetupRanges.js +3 -2
  36. package/lib/parsers/utils.d.ts +4 -6
  37. package/lib/parsers/utils.js +25 -27
  38. package/lib/plugins/vue-script-js.js +1 -1
  39. package/lib/plugins/vue-tsx.d.ts +7 -17
  40. package/lib/plugins/vue-tsx.js +7 -18
  41. package/lib/virtualFile/computedEmbeddedCodes.d.ts +4 -0
  42. package/lib/virtualFile/computedEmbeddedCodes.js +262 -0
  43. package/lib/virtualFile/computedSfc.d.ts +6 -0
  44. package/lib/virtualFile/computedSfc.js +340 -0
  45. package/lib/virtualFile/computedVueSfc.d.ts +4 -0
  46. package/lib/virtualFile/computedVueSfc.js +41 -0
  47. package/lib/virtualFile/embeddedFile.d.ts +11 -0
  48. package/lib/virtualFile/embeddedFile.js +14 -0
  49. package/lib/virtualFile/vueFile.d.ts +24 -0
  50. package/lib/virtualFile/vueFile.js +49 -0
  51. package/package.json +2 -2
@@ -38,7 +38,7 @@ function generateGlobalTypes(options) {
38
38
  type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
39
39
  type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
40
40
  type __VLS_SpreadMerge<A, B> = Omit<A, keyof B> & B;
41
- type __VLS_WithComponent<N0 extends string, LocalComponents, Self, N1 extends string, N2 extends string, N3 extends string> =
41
+ type __VLS_WithComponent<N0 extends string, LocalComponents, Self, N1 extends string, N2 extends string = N1, N3 extends string = N1> =
42
42
  N1 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N1] } :
43
43
  N2 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N2] } :
44
44
  N3 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N3] } :
@@ -1,5 +1,4 @@
1
1
  export declare const ctx = "__VLS_ctx";
2
- export declare const self = "__VLS_self";
3
2
  export declare const dollars = "__VLS_dollars";
4
3
  export declare const slots = "__VLS_slots";
5
4
  export declare const props = "__VLS_props";
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PROPS_FALLBACK = exports.StyleModules = exports.PublicProps = exports.SetupExposed = exports.Emit = exports.InternalProps = exports.EmitProps = exports.ModelEmit = exports.RootEl = exports.TemplateRefs = exports.InheritedAttrs = exports.Slots = exports.Props = exports.ModelProps = exports._export = exports.placeholder = exports.intrinsics = exports.directives = exports.components = exports.setup = exports.exposed = exports.emit = exports.modelEmit = exports.defaultModels = exports.defaults = exports.props = exports.slots = exports.dollars = exports.self = exports.ctx = void 0;
3
+ exports.PROPS_FALLBACK = exports.StyleModules = exports.PublicProps = exports.SetupExposed = exports.Emit = exports.InternalProps = exports.EmitProps = exports.ModelEmit = exports.RootEl = exports.TemplateRefs = exports.InheritedAttrs = exports.Slots = exports.Props = exports.ModelProps = exports._export = exports.placeholder = exports.intrinsics = exports.directives = exports.components = exports.setup = exports.exposed = exports.emit = exports.modelEmit = exports.defaultModels = exports.defaults = exports.props = exports.slots = exports.dollars = exports.ctx = void 0;
4
4
  exports.ctx = '__VLS_ctx';
5
- exports.self = '__VLS_self';
6
5
  exports.dollars = '__VLS_dollars';
7
6
  exports.slots = '__VLS_slots';
8
7
  exports.props = '__VLS_props';
@@ -6,16 +6,7 @@ const names = require("../names");
6
6
  const utils_1 = require("../utils");
7
7
  const merge_1 = require("../utils/merge");
8
8
  function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
9
- if (options.script
10
- && options.scriptRanges?.componentOptions
11
- && options.scriptRanges.componentOptions.expression.start !== options.scriptRanges.componentOptions.args.start) {
12
- // use defineComponent() from user space code if it exist
13
- yield* (0, utils_1.generateSfcBlockSection)(options.script, options.scriptRanges.componentOptions.expression.start, options.scriptRanges.componentOptions.args.start, codeFeatures_1.codeFeatures.all);
14
- yield `{${utils_1.newLine}`;
15
- }
16
- else {
17
- yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
18
- }
9
+ yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
19
10
  const returns = [];
20
11
  if (scriptSetupRanges.defineExpose) {
21
12
  returns.push([names.exposed]);
@@ -38,10 +29,6 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
38
29
  && options.templateCodegen?.generatedTypes.has(names.RootEl)) {
39
30
  yield `__typeEl: {} as ${names.RootEl},${utils_1.newLine}`;
40
31
  }
41
- if (options.script && options.scriptRanges?.componentOptions?.args) {
42
- const { args } = options.scriptRanges.componentOptions;
43
- yield* (0, utils_1.generateSfcBlockSection)(options.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
44
- }
45
32
  yield `})`;
46
33
  }
47
34
  function* generateEmitsOption(options, scriptSetupRanges) {
@@ -28,91 +28,97 @@ function* generateWorker(options, ctx) {
28
28
  // <script> + <script setup>
29
29
  if (script && scriptRanges && scriptSetup && scriptSetupRanges) {
30
30
  // <script>
31
- const { exportDefault, componentOptions } = scriptRanges;
31
+ let selfType;
32
+ const { exportDefault } = scriptRanges;
32
33
  if (exportDefault) {
33
- const { expression: options } = componentOptions ?? exportDefault;
34
- yield* (0, utils_1.generateSfcBlockSection)(script, 0, options.start, codeFeatures_1.codeFeatures.all);
35
- yield exportExpression;
36
- yield* (0, utils_1.generateSfcBlockSection)(script, options.end, script.content.length, codeFeatures_1.codeFeatures.all, true);
34
+ yield* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, selfType = '__VLS_self');
37
35
  }
38
36
  else {
39
- yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all, true);
37
+ yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all);
40
38
  yield `export default ${exportExpression}${utils_1.endOfLine}`;
41
39
  }
42
40
  // <script setup>
43
- yield* generateExportDeclareEqual(scriptSetup);
41
+ yield* generateExportDeclareEqual(scriptSetup, names._export);
44
42
  if (scriptSetup.generic) {
45
- yield* (0, scriptSetup_1.generateGeneric)(options, ctx, scriptSetup, scriptSetupRanges, scriptSetup.generic, (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx)));
43
+ yield* (0, scriptSetup_1.generateGeneric)(options, ctx, scriptSetup, scriptSetupRanges, scriptSetup.generic, (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx, selfType)));
46
44
  }
47
45
  else {
48
46
  yield `await (async () => {${utils_1.newLine}`;
49
- yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx), [`return `]);
47
+ yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx, selfType), [`return `]);
50
48
  yield `})()${utils_1.endOfLine}`;
51
49
  }
52
50
  }
53
51
  // only <script setup>
54
52
  else if (scriptSetup && scriptSetupRanges) {
55
53
  if (scriptSetup.generic) {
56
- yield* generateExportDeclareEqual(scriptSetup);
54
+ yield* generateExportDeclareEqual(scriptSetup, names._export);
57
55
  yield* (0, scriptSetup_1.generateGeneric)(options, ctx, scriptSetup, scriptSetupRanges, scriptSetup.generic, (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx)));
58
56
  }
59
57
  else {
60
58
  // no script block, generate script setup code at root
61
- yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx), generateExportDeclareEqual(scriptSetup));
59
+ yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx), generateExportDeclareEqual(scriptSetup, names._export));
62
60
  }
63
61
  yield `export default ${exportExpression}${utils_1.endOfLine}`;
64
62
  }
65
63
  // only <script>
66
64
  else if (script && scriptRanges) {
67
- const { exportDefault, componentOptions } = scriptRanges;
65
+ const { exportDefault } = scriptRanges;
68
66
  if (exportDefault) {
69
- const { expression } = componentOptions ?? exportDefault;
70
- let wrapLeft;
71
- let wrapRight;
72
- if (script.content[expression.start] === '{'
73
- && vueCompilerOptions.optionsWrapper.length) {
74
- [wrapLeft, wrapRight] = vueCompilerOptions.optionsWrapper;
75
- ctx.inlayHints.push({
76
- blockName: script.name,
77
- offset: expression.start,
78
- setting: 'vue.inlayHints.optionsWrapper',
79
- label: wrapLeft || '[Missing optionsWrapper[0]]',
80
- tooltip: [
81
- 'This is virtual code that is automatically wrapped for type support, it does not affect your runtime behavior, you can customize it via `vueCompilerOptions.optionsWrapper` option in tsconfig / jsconfig.',
82
- 'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
83
- ].join('\n\n'),
84
- }, {
85
- blockName: script.name,
86
- offset: expression.end,
87
- setting: 'vue.inlayHints.optionsWrapper',
88
- label: wrapRight || '[Missing optionsWrapper[1]]',
89
- });
90
- }
91
- yield* (0, utils_1.generateSfcBlockSection)(script, 0, exportDefault.start, codeFeatures_1.codeFeatures.all, true);
92
- yield* generateExportDeclareEqual(script);
93
- if (wrapLeft) {
94
- yield wrapLeft;
95
- }
96
- yield* (0, utils_1.generateSfcBlockSection)(script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
97
- if (wrapRight) {
98
- yield wrapRight;
99
- }
100
- yield utils_1.endOfLine;
101
- yield* (0, template_1.generateTemplate)(options, ctx);
102
- yield* (0, utils_1.generateSfcBlockSection)(script, exportDefault.start, expression.start, codeFeatures_1.codeFeatures.all);
103
- yield exportExpression;
104
- yield* (0, utils_1.generateSfcBlockSection)(script, expression.end, script.content.length, codeFeatures_1.codeFeatures.all);
67
+ yield* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, names._export, (0, template_1.generateTemplate)(options, ctx, names._export));
105
68
  }
106
69
  else {
107
- yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all, true);
108
- yield* generateExportDeclareEqual(script);
70
+ yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all);
71
+ yield* generateExportDeclareEqual(script, names._export);
109
72
  yield `(await import('${vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
110
- yield* (0, template_1.generateTemplate)(options, ctx);
73
+ yield* (0, template_1.generateTemplate)(options, ctx, names._export);
111
74
  yield `export default ${exportExpression}${utils_1.endOfLine}`;
112
75
  }
113
76
  }
114
77
  yield* ctx.localTypes.generate();
115
78
  }
79
+ function* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, varName, templateGenerator) {
80
+ const { componentOptions } = scriptRanges;
81
+ const { expression, isObjectLiteral } = componentOptions ?? exportDefault;
82
+ let wrapLeft;
83
+ let wrapRight;
84
+ if (isObjectLiteral
85
+ && vueCompilerOptions.optionsWrapper.length) {
86
+ [wrapLeft, wrapRight] = vueCompilerOptions.optionsWrapper;
87
+ ctx.inlayHints.push({
88
+ blockName: script.name,
89
+ offset: expression.start,
90
+ setting: 'vue.inlayHints.optionsWrapper',
91
+ label: wrapLeft || '[Missing optionsWrapper[0]]',
92
+ tooltip: [
93
+ 'This is virtual code that is automatically wrapped for type support, it does not affect your runtime behavior, you can customize it via `vueCompilerOptions.optionsWrapper` option in tsconfig / jsconfig.',
94
+ 'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
95
+ ].join('\n\n'),
96
+ }, {
97
+ blockName: script.name,
98
+ offset: expression.end,
99
+ setting: 'vue.inlayHints.optionsWrapper',
100
+ label: wrapRight || '[Missing optionsWrapper[1]]',
101
+ });
102
+ }
103
+ yield* (0, utils_1.generateSfcBlockSection)(script, 0, expression.start, codeFeatures_1.codeFeatures.all);
104
+ yield exportExpression;
105
+ yield* (0, utils_1.generateSfcBlockSection)(script, expression.end, exportDefault.end, codeFeatures_1.codeFeatures.all);
106
+ yield utils_1.endOfLine;
107
+ if (templateGenerator) {
108
+ yield* templateGenerator;
109
+ }
110
+ yield* generateExportDeclareEqual(script, varName);
111
+ if (wrapLeft && wrapRight) {
112
+ yield wrapLeft;
113
+ yield* (0, utils_1.generateSfcBlockSection)(script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
114
+ yield wrapRight;
115
+ }
116
+ else {
117
+ yield* (0, utils_1.generateSfcBlockSection)(script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
118
+ }
119
+ yield utils_1.endOfLine;
120
+ yield* (0, utils_1.generateSfcBlockSection)(script, exportDefault.end, script.content.length, codeFeatures_1.codeFeatures.all);
121
+ }
116
122
  function* generateGlobalTypesReference(options) {
117
123
  const globalTypesPath = options.vueCompilerOptions.globalTypesPath(options.fileName);
118
124
  if (!globalTypesPath) {
@@ -131,10 +137,10 @@ function* generateGlobalTypesReference(options) {
131
137
  yield `/// <reference types="${globalTypesPath}" />${utils_1.newLine}`;
132
138
  }
133
139
  }
134
- function* generateExportDeclareEqual(block) {
140
+ function* generateExportDeclareEqual(block, name) {
135
141
  yield `const `;
136
142
  const token = yield* (0, boundary_1.startBoundary)(block.name, 0, codeFeatures_1.codeFeatures.doNotReportTs6133);
137
- yield names._export;
143
+ yield name;
138
144
  yield (0, boundary_1.endBoundary)(token, block.content.length);
139
145
  yield ` = `;
140
146
  }
@@ -81,7 +81,7 @@ function* generateGeneric(options, ctx, scriptSetup, scriptSetupRanges, generic,
81
81
  }
82
82
  yield `) => void${utils_1.endOfLine}`;
83
83
  yield ` attrs: any${utils_1.endOfLine}`;
84
- yield ` slots: ${names.Slots}${utils_1.endOfLine}`;
84
+ yield ` slots: ${hasSlotsType(options) ? names.Slots : `{}`}${utils_1.endOfLine}`;
85
85
  yield ` emit: ${emitTypes.length ? emitTypes.join(` & `) : `{}`}${utils_1.endOfLine}`;
86
86
  yield `}${utils_1.endOfLine}`;
87
87
  yield `})(),${utils_1.newLine}`; // __VLS_setup = (async () => {
@@ -194,7 +194,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
194
194
  }));
195
195
  }
196
196
  }
197
- yield* (0, transform_1.generateCodeWithTransforms)(Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset), scriptSetup.content.length, transforms, (start, end) => (0, utils_1.generateSfcBlockSection)(scriptSetup, start, end, codeFeatures_1.codeFeatures.all, end === scriptSetup.content.length));
197
+ yield* (0, transform_1.generateCodeWithTransforms)(Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset), scriptSetup.content.length, transforms, (start, end) => (0, utils_1.generateSfcBlockSection)(scriptSetup, start, end, codeFeatures_1.codeFeatures.all));
198
198
  yield* generateMacros(options);
199
199
  yield* generateModels(scriptSetup, scriptSetupRanges);
200
200
  yield* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges);
@@ -1,2 +1,3 @@
1
1
  import type { Code, SfcBlockAttr } from '../../types';
2
2
  export declare function generateSrc(src: SfcBlockAttr): Generator<Code>;
3
+ export declare function resolveSrcPath(text: string): string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSrc = generateSrc;
4
+ exports.resolveSrcPath = resolveSrcPath;
4
5
  const codeFeatures_1 = require("../codeFeatures");
5
6
  const utils_1 = require("../utils");
6
7
  const boundary_1 = require("../utils/boundary");
@@ -9,18 +10,7 @@ function* generateSrc(src) {
9
10
  return;
10
11
  }
11
12
  let { text } = src;
12
- if (text.endsWith('.d.ts')) {
13
- text = text.slice(0, -'.d.ts'.length);
14
- }
15
- else if (text.endsWith('.ts')) {
16
- text = text.slice(0, -'.ts'.length);
17
- }
18
- else if (text.endsWith('.tsx')) {
19
- text = text.slice(0, -'.tsx'.length) + '.jsx';
20
- }
21
- if (!text.endsWith('.js') && !text.endsWith('.jsx')) {
22
- text = text + '.js';
23
- }
13
+ text = resolveSrcPath(text);
24
14
  yield `export * from `;
25
15
  const wrapCodeFeatures = {
26
16
  ...codeFeatures_1.codeFeatures.all,
@@ -35,4 +25,19 @@ function* generateSrc(src) {
35
25
  yield utils_1.endOfLine;
36
26
  yield `export { default } from '${text}'${utils_1.endOfLine}`;
37
27
  }
28
+ function resolveSrcPath(text) {
29
+ if (text.endsWith('.d.ts')) {
30
+ text = text.slice(0, -'.d.ts'.length);
31
+ }
32
+ else if (text.endsWith('.ts')) {
33
+ text = text.slice(0, -'.ts'.length);
34
+ }
35
+ else if (text.endsWith('.tsx')) {
36
+ text = text.slice(0, -'.tsx'.length) + '.jsx';
37
+ }
38
+ if (!text.endsWith('.js') && !text.endsWith('.jsx')) {
39
+ text = text + '.js';
40
+ }
41
+ return text;
42
+ }
38
43
  //# sourceMappingURL=src.js.map
@@ -1,4 +1,4 @@
1
1
  import type { Code } from '../../types';
2
2
  import type { ScriptCodegenContext } from './context';
3
3
  import type { ScriptCodegenOptions } from './index';
4
- export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
4
+ export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, selfType?: string): Generator<Code>;
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTemplate = generateTemplate;
4
- const path = require("path-browserify");
5
4
  const codeFeatures_1 = require("../codeFeatures");
6
5
  const names = require("../names");
7
6
  const utils_1 = require("../utils");
8
7
  const merge_1 = require("../utils/merge");
9
- function* generateTemplate(options, ctx) {
10
- yield* generateSelf(options);
8
+ const src_1 = require("./src");
9
+ function* generateTemplate(options, ctx, selfType) {
11
10
  yield* generateSetupExposed(options, ctx);
12
- yield* generateTemplateCtx(options, ctx);
11
+ yield* generateTemplateCtx(options, ctx, selfType);
13
12
  yield* generateTemplateComponents(options);
14
13
  yield* generateTemplateDirectives(options);
15
14
  if (options.styleCodegen) {
@@ -19,32 +18,18 @@ function* generateTemplate(options, ctx) {
19
18
  yield* options.templateCodegen.codes;
20
19
  }
21
20
  }
22
- function* generateSelf({ script, scriptRanges, vueCompilerOptions, fileName }) {
23
- if (script && scriptRanges?.componentOptions) {
24
- yield `const ${names.self} = (await import('${vueCompilerOptions.lib}')).defineComponent(`;
25
- const { args } = scriptRanges.componentOptions;
26
- yield* (0, utils_1.generateSfcBlockSection)(script, args.start, args.end, codeFeatures_1.codeFeatures.all);
27
- yield `)${utils_1.endOfLine}`;
28
- }
29
- else if (script && scriptRanges?.exportDefault) {
30
- yield `const ${names.self} = `;
31
- const { expression } = scriptRanges.exportDefault;
32
- yield* (0, utils_1.generateSfcBlockSection)(script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
33
- yield utils_1.endOfLine;
34
- }
35
- else if (script?.src) {
36
- yield `let ${names.self}!: typeof import('./${path.basename(fileName)}').default${utils_1.endOfLine}`;
37
- }
38
- }
39
- function* generateTemplateCtx({ vueCompilerOptions, script, scriptRanges, styleCodegen, scriptSetupRanges, fileName }, ctx) {
21
+ function* generateTemplateCtx({ vueCompilerOptions, script, styleCodegen, scriptSetupRanges, fileName }, ctx, selfType) {
40
22
  const exps = [];
41
23
  const emitTypes = [];
42
24
  const propTypes = [];
43
25
  if (vueCompilerOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
44
26
  exps.push([`globalThis`]);
45
27
  }
46
- if (script?.src || scriptRanges?.exportDefault) {
47
- exps.push([`{} as InstanceType<__VLS_PickNotAny<typeof ${names.self}, new () => {}>>`]);
28
+ if (selfType) {
29
+ exps.push([`{} as InstanceType<__VLS_PickNotAny<typeof ${selfType}, new () => {}>>`]);
30
+ }
31
+ else if (typeof script?.src === 'object') {
32
+ exps.push([`{} as typeof import('${(0, src_1.resolveSrcPath)(script.src.text)}').default`]);
48
33
  }
49
34
  else {
50
35
  exps.push([`{} as import('${vueCompilerOptions.lib}').ComponentPublicInstance`]);
@@ -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,18 @@
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
+ const wrapWith_1 = require("../utils/wrapWith");
7
+ function* generateClassProperty(styleIndex, classNameWithDot, offset, propertyType) {
8
+ yield `${utils_1.newLine} & { `;
9
+ yield* (0, wrapWith_1.wrapWith)('style_' + styleIndex, offset, offset + classNameWithDot.length, codeFeatures_1.codeFeatures.navigation, `'`, [
10
+ classNameWithDot.slice(1),
11
+ 'style_' + styleIndex,
12
+ offset + 1,
13
+ utils_1.combineLastMapping,
14
+ ], `'`);
15
+ yield `: ${propertyType}`;
16
+ yield ` }`;
17
+ }
18
+ //# sourceMappingURL=classProperty.js.map
@@ -0,0 +1,2 @@
1
+ import type { Code, Sfc } from '../../types';
2
+ export declare function generateStyleImports(style: Sfc['styles'][number]): Generator<Code>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateStyleImports = generateStyleImports;
4
+ const utils_1 = require("../utils");
5
+ const wrapWith_1 = require("../utils/wrapWith");
6
+ function* generateStyleImports(style) {
7
+ const features = {
8
+ navigation: true,
9
+ verification: true,
10
+ };
11
+ if (typeof style.src === 'object') {
12
+ yield `${utils_1.newLine} & typeof import(`;
13
+ yield* (0, wrapWith_1.wrapWith)('main', style.src.offset, style.src.offset + style.src.text.length, features, `'`, [style.src.text, 'main', style.src.offset, utils_1.combineLastMapping], `'`);
14
+ yield `).default`;
15
+ }
16
+ for (const { text, offset } of style.imports) {
17
+ yield `${utils_1.newLine} & typeof import('`;
18
+ yield [
19
+ text,
20
+ style.name,
21
+ offset,
22
+ features,
23
+ ];
24
+ yield `').default`;
25
+ }
26
+ }
27
+ //# sourceMappingURL=imports.js.map
@@ -43,15 +43,12 @@ declare function generate(options: StyleCodegenOptions): {
43
43
  typeExp: string;
44
44
  offset: number;
45
45
  }[]>;
46
- currentComponent: {
47
- get ctxVar(): string;
48
- get propsVar(): string;
49
- } | undefined;
50
46
  singleRootElTypes: Set<string>;
51
47
  singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
52
48
  addTemplateRef(name: string, typeExp: string, offset: number): void;
53
49
  recordComponentAccess(source: string, name: string, offset?: number): void;
54
50
  scopes: Set<string>[];
51
+ components: (() => string)[];
55
52
  declare(...varNames: string[]): void;
56
53
  startScope(): () => Generator<Code, any, any>;
57
54
  getInternalVariable(): string;
@@ -134,15 +134,12 @@ export declare function createTemplateCodegenContext(): {
134
134
  typeExp: string;
135
135
  offset: number;
136
136
  }[]>;
137
- currentComponent: {
138
- get ctxVar(): string;
139
- get propsVar(): string;
140
- } | undefined;
141
137
  singleRootElTypes: Set<string>;
142
138
  singleRootNodes: Set<CompilerDOM.ElementNode | null>;
143
139
  addTemplateRef(name: string, typeExp: string, offset: number): void;
144
140
  recordComponentAccess(source: string, name: string, offset?: number): void;
145
141
  scopes: Set<string>[];
142
+ components: (() => string)[];
146
143
  declare(...varNames: string[]): void;
147
144
  startScope(): () => Generator<Code, any, any>;
148
145
  getInternalVariable(): string;
@@ -106,6 +106,7 @@ const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)
106
106
  function createTemplateCodegenContext() {
107
107
  let variableId = 0;
108
108
  const scopes = [];
109
+ const components = [];
109
110
  const hoistVars = new Map();
110
111
  const dollarVars = new Set();
111
112
  const componentAccessMap = new Map();
@@ -132,7 +133,6 @@ function createTemplateCodegenContext() {
132
133
  inlayHints,
133
134
  inheritedAttrVars,
134
135
  templateRefs,
135
- currentComponent: undefined,
136
136
  singleRootElTypes: new Set(),
137
137
  singleRootNodes: new Set(),
138
138
  addTemplateRef(name, typeExp, offset) {
@@ -156,6 +156,7 @@ function createTemplateCodegenContext() {
156
156
  }
157
157
  },
158
158
  scopes,
159
+ components,
159
160
  declare(...varNames) {
160
161
  const scope = scopes.at(-1);
161
162
  for (const varName of varNames) {