@vue/language-core 3.1.4 → 3.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/index.d.ts +2 -1
  2. package/index.js +3 -2
  3. package/lib/codegen/codeFeatures.d.ts +5 -9
  4. package/lib/codegen/codeFeatures.js +5 -5
  5. package/lib/codegen/globalTypes.js +15 -20
  6. package/lib/codegen/localTypes.d.ts +1 -1
  7. package/lib/codegen/localTypes.js +6 -6
  8. package/lib/codegen/names.d.ts +30 -0
  9. package/lib/codegen/names.js +34 -0
  10. package/lib/codegen/script/component.js +45 -54
  11. package/lib/codegen/script/context.d.ts +2 -5
  12. package/lib/codegen/script/context.js +1 -7
  13. package/lib/codegen/script/index.d.ts +10 -12
  14. package/lib/codegen/script/index.js +74 -73
  15. package/lib/codegen/script/scriptSetup.d.ts +3 -2
  16. package/lib/codegen/script/scriptSetup.js +209 -283
  17. package/lib/codegen/script/src.js +9 -3
  18. package/lib/codegen/script/template.js +64 -108
  19. package/lib/codegen/style/common.d.ts +3 -0
  20. package/lib/codegen/style/common.js +43 -0
  21. package/lib/codegen/style/index.d.ts +63 -0
  22. package/lib/codegen/style/index.js +38 -0
  23. package/lib/codegen/style/modules.d.ts +3 -2
  24. package/lib/codegen/style/modules.js +12 -11
  25. package/lib/codegen/style/scopedClasses.d.ts +2 -3
  26. package/lib/codegen/style/scopedClasses.js +23 -21
  27. package/lib/codegen/template/context.d.ts +10 -19
  28. package/lib/codegen/template/context.js +82 -94
  29. package/lib/codegen/template/element.js +174 -65
  30. package/lib/codegen/template/elementDirectives.js +32 -12
  31. package/lib/codegen/template/elementEvents.d.ts +1 -1
  32. package/lib/codegen/template/elementEvents.js +30 -35
  33. package/lib/codegen/template/elementProps.d.ts +3 -3
  34. package/lib/codegen/template/elementProps.js +64 -83
  35. package/lib/codegen/template/index.d.ts +11 -22
  36. package/lib/codegen/template/index.js +85 -80
  37. package/lib/codegen/template/interpolation.d.ts +3 -3
  38. package/lib/codegen/template/interpolation.js +108 -155
  39. package/lib/codegen/template/objectProperty.js +8 -4
  40. package/lib/codegen/template/propertyAccess.d.ts +1 -1
  41. package/lib/codegen/template/propertyAccess.js +5 -7
  42. package/lib/codegen/template/slotOutlet.js +26 -14
  43. package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
  44. package/lib/codegen/template/styleScopedClasses.js +23 -149
  45. package/lib/codegen/template/templateChild.d.ts +0 -1
  46. package/lib/codegen/template/templateChild.js +11 -68
  47. package/lib/codegen/template/vFor.js +10 -13
  48. package/lib/codegen/template/vIf.js +5 -3
  49. package/lib/codegen/template/vSlot.js +20 -16
  50. package/lib/codegen/utils/boundary.d.ts +3 -0
  51. package/lib/codegen/utils/boundary.js +13 -0
  52. package/lib/codegen/utils/camelized.js +3 -3
  53. package/lib/codegen/utils/escaped.js +4 -2
  54. package/lib/codegen/utils/index.d.ts +3 -6
  55. package/lib/codegen/utils/index.js +41 -26
  56. package/lib/codegen/utils/merge.d.ts +2 -2
  57. package/lib/codegen/utils/merge.js +9 -9
  58. package/lib/codegen/utils/stringLiteralKey.js +6 -3
  59. package/lib/codegen/utils/transform.d.ts +8 -0
  60. package/lib/codegen/utils/transform.js +27 -0
  61. package/lib/codegen/utils/unicode.js +4 -2
  62. package/lib/compilerOptions.js +4 -4
  63. package/lib/languagePlugin.d.ts +1 -1
  64. package/lib/languagePlugin.js +18 -25
  65. package/lib/plugins/vue-template-html.js +12 -9
  66. package/lib/plugins/vue-template-inline-css.js +8 -18
  67. package/lib/plugins/vue-template-inline-ts.js +12 -14
  68. package/lib/plugins/vue-tsx.d.ts +14 -23
  69. package/lib/plugins/vue-tsx.js +121 -69
  70. package/lib/plugins.js +1 -1
  71. package/lib/types.d.ts +5 -4
  72. package/lib/utils/parseSfc.js +10 -11
  73. package/lib/utils/shared.d.ts +1 -0
  74. package/lib/utils/shared.js +9 -0
  75. package/lib/utils/signals.d.ts +2 -2
  76. package/lib/utils/signals.js +8 -6
  77. package/lib/virtualCode/embeddedCodes.d.ts +12 -0
  78. package/lib/virtualCode/embeddedCodes.js +249 -0
  79. package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
  80. package/lib/virtualCode/index.js +81 -0
  81. package/lib/virtualCode/ir.d.ts +4 -0
  82. package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +65 -96
  83. package/lib/virtualCode/normalize.d.ts +2 -0
  84. package/lib/virtualCode/normalize.js +170 -0
  85. package/package.json +4 -4
  86. package/lib/codegen/style/classProperty.d.ts +0 -2
  87. package/lib/codegen/style/classProperty.js +0 -18
  88. package/lib/codegen/style/imports.d.ts +0 -2
  89. package/lib/codegen/style/imports.js +0 -27
  90. package/lib/codegen/template/elementChildren.d.ts +0 -5
  91. package/lib/codegen/template/elementChildren.js +0 -12
  92. package/lib/codegen/utils/wrapWith.d.ts +0 -3
  93. package/lib/codegen/utils/wrapWith.js +0 -24
  94. package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
  95. package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
  96. package/lib/virtualFile/computedSfc.d.ts +0 -6
  97. package/lib/virtualFile/computedVueSfc.d.ts +0 -4
  98. package/lib/virtualFile/computedVueSfc.js +0 -41
  99. package/lib/virtualFile/embeddedFile.d.ts +0 -11
  100. package/lib/virtualFile/embeddedFile.js +0 -14
  101. package/lib/virtualFile/vueFile.js +0 -49
@@ -1,49 +1,79 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateScript = generate;
4
- exports.generateConstExport = generateConstExport;
5
4
  const path = require("path-browserify");
6
5
  const codeFeatures_1 = require("../codeFeatures");
6
+ const names = require("../names");
7
7
  const utils_1 = require("../utils");
8
- const wrapWith_1 = require("../utils/wrapWith");
8
+ const boundary_1 = require("../utils/boundary");
9
9
  const context_1 = require("./context");
10
10
  const scriptSetup_1 = require("./scriptSetup");
11
11
  const src_1 = require("./src");
12
12
  const template_1 = require("./template");
13
+ const exportExpression = `{} as typeof ${names._export}`;
13
14
  function generate(options) {
14
- const context = (0, context_1.createScriptCodegenContext)(options);
15
- const codegen = generateScript(options, context);
16
- return {
17
- ...context,
18
- codes: [...codegen],
19
- };
15
+ const ctx = (0, context_1.createScriptCodegenContext)(options);
16
+ const codeGenerator = generateWorker(options, ctx);
17
+ return { ...ctx, codes: [...codeGenerator] };
20
18
  }
21
- function* generateScript(options, ctx) {
19
+ function* generateWorker(options, ctx) {
22
20
  yield* generateGlobalTypesReference(options);
23
- if (options.sfc.scriptSetup && options.scriptSetupRanges) {
24
- yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
21
+ const { script, scriptRanges, scriptSetup, scriptSetupRanges, vueCompilerOptions } = options;
22
+ if (scriptSetup && scriptSetupRanges) {
23
+ yield* (0, scriptSetup_1.generateScriptSetupImports)(scriptSetup, scriptSetupRanges);
25
24
  }
26
- if (options.sfc.script && options.scriptRanges) {
27
- const { exportDefault, componentOptions } = options.scriptRanges;
28
- if (options.sfc.scriptSetup && options.scriptSetupRanges) {
29
- if (exportDefault) {
30
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.start, codeFeatures_1.codeFeatures.all);
31
- yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
32
- }
33
- else {
34
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
35
- yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
36
- }
25
+ if (script?.src) {
26
+ yield* (0, src_1.generateSrc)(script.src);
27
+ }
28
+ // <script> + <script setup>
29
+ if (script && scriptRanges && scriptSetup && scriptSetupRanges) {
30
+ // <script>
31
+ const { exportDefault, componentOptions } = scriptRanges;
32
+ 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);
37
+ }
38
+ else {
39
+ yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all, true);
40
+ yield `export default ${exportExpression}${utils_1.endOfLine}`;
41
+ }
42
+ // <script setup>
43
+ yield* generateExportDeclareEqual(scriptSetup);
44
+ 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)));
46
+ }
47
+ else {
48
+ yield `await (async () => {${utils_1.newLine}`;
49
+ yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx), [`return `]);
50
+ yield `})()${utils_1.endOfLine}`;
51
+ }
52
+ }
53
+ // only <script setup>
54
+ else if (scriptSetup && scriptSetupRanges) {
55
+ if (scriptSetup.generic) {
56
+ yield* generateExportDeclareEqual(scriptSetup);
57
+ 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
+ }
59
+ else {
60
+ // 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));
37
62
  }
38
- else if (exportDefault) {
63
+ yield `export default ${exportExpression}${utils_1.endOfLine}`;
64
+ }
65
+ // only <script>
66
+ else if (script && scriptRanges) {
67
+ const { exportDefault, componentOptions } = scriptRanges;
68
+ if (exportDefault) {
39
69
  const { expression } = componentOptions ?? exportDefault;
40
70
  let wrapLeft;
41
71
  let wrapRight;
42
- if (options.sfc.script.content[expression.start] === '{'
43
- && options.vueCompilerOptions.optionsWrapper.length) {
44
- [wrapLeft, wrapRight] = options.vueCompilerOptions.optionsWrapper;
72
+ if (script.content[expression.start] === '{'
73
+ && vueCompilerOptions.optionsWrapper.length) {
74
+ [wrapLeft, wrapRight] = vueCompilerOptions.optionsWrapper;
45
75
  ctx.inlayHints.push({
46
- blockName: options.sfc.script.name,
76
+ blockName: script.name,
47
77
  offset: expression.start,
48
78
  setting: 'vue.inlayHints.optionsWrapper',
49
79
  label: wrapLeft || '[Missing optionsWrapper[0]]',
@@ -52,36 +82,35 @@ function* generateScript(options, ctx) {
52
82
  'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
53
83
  ].join('\n\n'),
54
84
  }, {
55
- blockName: options.sfc.script.name,
85
+ blockName: script.name,
56
86
  offset: expression.end,
57
87
  setting: 'vue.inlayHints.optionsWrapper',
58
88
  label: wrapRight || '[Missing optionsWrapper[1]]',
59
89
  });
60
90
  }
61
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.start, codeFeatures_1.codeFeatures.all);
62
- yield* generateConstExport(options, options.sfc.script);
91
+ yield* (0, utils_1.generateSfcBlockSection)(script, 0, exportDefault.start, codeFeatures_1.codeFeatures.all, true);
92
+ yield* generateExportDeclareEqual(script);
63
93
  if (wrapLeft) {
64
94
  yield wrapLeft;
65
95
  }
66
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
96
+ yield* (0, utils_1.generateSfcBlockSection)(script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
67
97
  if (wrapRight) {
68
98
  yield wrapRight;
69
99
  }
70
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);
71
105
  }
72
106
  else {
73
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
74
- yield* generateConstExport(options, options.sfc.script);
75
- yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
107
+ yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all, true);
108
+ yield* generateExportDeclareEqual(script);
109
+ yield `(await import('${vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
110
+ yield* (0, template_1.generateTemplate)(options, ctx);
111
+ yield `export default ${exportExpression}${utils_1.endOfLine}`;
76
112
  }
77
113
  }
78
- else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
79
- yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
80
- }
81
- if (!ctx.generatedTemplate) {
82
- yield* (0, template_1.generateTemplate)(options, ctx);
83
- }
84
- yield* generateExportDefault(options);
85
114
  yield* ctx.localTypes.generate();
86
115
  }
87
116
  function* generateGlobalTypesReference(options) {
@@ -102,39 +131,11 @@ function* generateGlobalTypesReference(options) {
102
131
  yield `/// <reference types="${globalTypesPath}" />${utils_1.newLine}`;
103
132
  }
104
133
  }
105
- function* generateConstExport(options, block) {
106
- if (options.sfc.script) {
107
- yield* (0, utils_1.generatePartiallyEnding)(options.sfc.script.name, options.scriptRanges?.exportDefault?.start ?? options.sfc.script.content.length, '#3632/script.vue');
108
- }
134
+ function* generateExportDeclareEqual(block) {
109
135
  yield `const `;
110
- yield* (0, wrapWith_1.wrapWith)(0, block.content.length, block.name, codeFeatures_1.codeFeatures.doNotReportTs6133, `__VLS_export`);
136
+ const token = yield* (0, boundary_1.startBoundary)(block.name, 0, codeFeatures_1.codeFeatures.doNotReportTs6133);
137
+ yield names._export;
138
+ yield (0, boundary_1.endBoundary)(token, block.content.length);
111
139
  yield ` = `;
112
140
  }
113
- function* generateExportDefault(options) {
114
- if (options.sfc.script?.src) {
115
- yield* (0, src_1.generateSrc)(options.sfc.script.src);
116
- return;
117
- }
118
- const expression = `{} as typeof __VLS_export`;
119
- if (options.sfc.script && options.scriptRanges?.exportDefault) {
120
- const { exportDefault, componentOptions } = options.scriptRanges;
121
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.start, (componentOptions ?? exportDefault).expression.start, codeFeatures_1.codeFeatures.all);
122
- yield expression;
123
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, (componentOptions ?? exportDefault).expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
124
- }
125
- else {
126
- yield `export `;
127
- if (options.sfc.template) {
128
- for (let i = 0; i < 'template'.length + 1; i++) {
129
- yield [
130
- ``,
131
- 'main',
132
- options.sfc.template.start + 1 + i,
133
- i ? { __combineOffset: i } : codeFeatures_1.codeFeatures.navigationWithoutRename,
134
- ];
135
- }
136
- }
137
- yield `default ${expression}${utils_1.endOfLine}`;
138
- }
139
- }
140
141
  //# sourceMappingURL=index.js.map
@@ -1,6 +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 { type ScriptCodegenOptions } from './index';
4
+ import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
- export declare function generateScriptSetup(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
+ export declare function generateGeneric(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, generic: NonNullable<NonNullable<Sfc['scriptSetup']>['generic']>, body: Iterable<Code>): Generator<Code>;
7
+ export declare function generateSetupFunction(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, body: Iterable<Code>, output?: Iterable<Code>): Generator<Code>;