@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.
- package/index.d.ts +2 -1
- package/index.js +3 -2
- package/lib/codegen/codeFeatures.d.ts +5 -9
- package/lib/codegen/codeFeatures.js +5 -5
- package/lib/codegen/globalTypes.js +15 -20
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +6 -6
- package/lib/codegen/names.d.ts +30 -0
- package/lib/codegen/names.js +34 -0
- package/lib/codegen/script/component.js +45 -54
- package/lib/codegen/script/context.d.ts +2 -5
- package/lib/codegen/script/context.js +1 -7
- package/lib/codegen/script/index.d.ts +10 -12
- package/lib/codegen/script/index.js +74 -73
- package/lib/codegen/script/scriptSetup.d.ts +3 -2
- package/lib/codegen/script/scriptSetup.js +209 -283
- package/lib/codegen/script/src.js +9 -3
- package/lib/codegen/script/template.js +64 -108
- package/lib/codegen/style/common.d.ts +3 -0
- package/lib/codegen/style/common.js +43 -0
- package/lib/codegen/style/index.d.ts +63 -0
- package/lib/codegen/style/index.js +38 -0
- package/lib/codegen/style/modules.d.ts +3 -2
- package/lib/codegen/style/modules.js +12 -11
- package/lib/codegen/style/scopedClasses.d.ts +2 -3
- package/lib/codegen/style/scopedClasses.js +23 -21
- package/lib/codegen/template/context.d.ts +10 -19
- package/lib/codegen/template/context.js +82 -94
- package/lib/codegen/template/element.js +174 -65
- package/lib/codegen/template/elementDirectives.js +32 -12
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +30 -35
- package/lib/codegen/template/elementProps.d.ts +3 -3
- package/lib/codegen/template/elementProps.js +64 -83
- package/lib/codegen/template/index.d.ts +11 -22
- package/lib/codegen/template/index.js +85 -80
- package/lib/codegen/template/interpolation.d.ts +3 -3
- package/lib/codegen/template/interpolation.js +108 -155
- package/lib/codegen/template/objectProperty.js +8 -4
- package/lib/codegen/template/propertyAccess.d.ts +1 -1
- package/lib/codegen/template/propertyAccess.js +5 -7
- package/lib/codegen/template/slotOutlet.js +26 -14
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
- package/lib/codegen/template/styleScopedClasses.js +23 -149
- package/lib/codegen/template/templateChild.d.ts +0 -1
- package/lib/codegen/template/templateChild.js +11 -68
- package/lib/codegen/template/vFor.js +10 -13
- package/lib/codegen/template/vIf.js +5 -3
- package/lib/codegen/template/vSlot.js +20 -16
- package/lib/codegen/utils/boundary.d.ts +3 -0
- package/lib/codegen/utils/boundary.js +13 -0
- package/lib/codegen/utils/camelized.js +3 -3
- package/lib/codegen/utils/escaped.js +4 -2
- package/lib/codegen/utils/index.d.ts +3 -6
- package/lib/codegen/utils/index.js +41 -26
- package/lib/codegen/utils/merge.d.ts +2 -2
- package/lib/codegen/utils/merge.js +9 -9
- package/lib/codegen/utils/stringLiteralKey.js +6 -3
- package/lib/codegen/utils/transform.d.ts +8 -0
- package/lib/codegen/utils/transform.js +27 -0
- package/lib/codegen/utils/unicode.js +4 -2
- package/lib/compilerOptions.js +4 -4
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +18 -25
- package/lib/plugins/vue-template-html.js +12 -9
- package/lib/plugins/vue-template-inline-css.js +8 -18
- package/lib/plugins/vue-template-inline-ts.js +12 -14
- package/lib/plugins/vue-tsx.d.ts +14 -23
- package/lib/plugins/vue-tsx.js +121 -69
- package/lib/plugins.js +1 -1
- package/lib/types.d.ts +5 -4
- package/lib/utils/parseSfc.js +10 -11
- package/lib/utils/shared.d.ts +1 -0
- package/lib/utils/shared.js +9 -0
- package/lib/utils/signals.d.ts +2 -2
- package/lib/utils/signals.js +8 -6
- package/lib/virtualCode/embeddedCodes.d.ts +12 -0
- package/lib/virtualCode/embeddedCodes.js +249 -0
- package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
- package/lib/virtualCode/index.js +81 -0
- package/lib/virtualCode/ir.d.ts +4 -0
- package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +65 -96
- package/lib/virtualCode/normalize.d.ts +2 -0
- package/lib/virtualCode/normalize.js +170 -0
- package/package.json +4 -4
- package/lib/codegen/style/classProperty.d.ts +0 -2
- package/lib/codegen/style/classProperty.js +0 -18
- package/lib/codegen/style/imports.d.ts +0 -2
- package/lib/codegen/style/imports.js +0 -27
- package/lib/codegen/template/elementChildren.d.ts +0 -5
- package/lib/codegen/template/elementChildren.js +0 -12
- package/lib/codegen/utils/wrapWith.d.ts +0 -3
- package/lib/codegen/utils/wrapWith.js +0 -24
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
- package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
- package/lib/virtualFile/computedSfc.d.ts +0 -6
- package/lib/virtualFile/computedVueSfc.d.ts +0 -4
- package/lib/virtualFile/computedVueSfc.js +0 -41
- package/lib/virtualFile/embeddedFile.d.ts +0 -11
- package/lib/virtualFile/embeddedFile.js +0 -14
- 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
|
|
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
|
|
15
|
-
const
|
|
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*
|
|
19
|
+
function* generateWorker(options, ctx) {
|
|
22
20
|
yield* generateGlobalTypesReference(options);
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const { script, scriptRanges, scriptSetup, scriptSetupRanges, vueCompilerOptions } = options;
|
|
22
|
+
if (scriptSetup && scriptSetupRanges) {
|
|
23
|
+
yield* (0, scriptSetup_1.generateScriptSetupImports)(scriptSetup, scriptSetupRanges);
|
|
25
24
|
}
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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 (
|
|
43
|
-
&&
|
|
44
|
-
[wrapLeft, wrapRight] =
|
|
72
|
+
if (script.content[expression.start] === '{'
|
|
73
|
+
&& vueCompilerOptions.optionsWrapper.length) {
|
|
74
|
+
[wrapLeft, wrapRight] = vueCompilerOptions.optionsWrapper;
|
|
45
75
|
ctx.inlayHints.push({
|
|
46
|
-
blockName:
|
|
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:
|
|
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)(
|
|
62
|
-
yield*
|
|
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)(
|
|
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)(
|
|
74
|
-
yield*
|
|
75
|
-
yield `(await import('${
|
|
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*
|
|
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,
|
|
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 {
|
|
4
|
+
import type { ScriptCodegenOptions } from './index';
|
|
5
5
|
export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
6
|
-
export declare function
|
|
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>;
|