@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,169 +1,125 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateTemplate = generateTemplate;
|
|
4
|
-
const shared_1 = require("@vue/shared");
|
|
5
4
|
const path = require("path-browserify");
|
|
6
5
|
const codeFeatures_1 = require("../codeFeatures");
|
|
7
|
-
const
|
|
8
|
-
const scopedClasses_1 = require("../style/scopedClasses");
|
|
9
|
-
const context_1 = require("../template/context");
|
|
10
|
-
const interpolation_1 = require("../template/interpolation");
|
|
11
|
-
const styleScopedClasses_1 = require("../template/styleScopedClasses");
|
|
6
|
+
const names = require("../names");
|
|
12
7
|
const utils_1 = require("../utils");
|
|
13
8
|
const merge_1 = require("../utils/merge");
|
|
14
9
|
function* generateTemplate(options, ctx) {
|
|
15
|
-
ctx.generatedTemplate = true;
|
|
16
10
|
yield* generateSelf(options);
|
|
11
|
+
yield* generateSetupExposed(options, ctx);
|
|
17
12
|
yield* generateTemplateCtx(options, ctx);
|
|
18
13
|
yield* generateTemplateComponents(options);
|
|
19
14
|
yield* generateTemplateDirectives(options);
|
|
20
|
-
|
|
15
|
+
if (options.styleCodegen) {
|
|
16
|
+
yield* options.styleCodegen.codes;
|
|
17
|
+
}
|
|
18
|
+
if (options.templateCodegen) {
|
|
19
|
+
yield* options.templateCodegen.codes;
|
|
20
|
+
}
|
|
21
21
|
}
|
|
22
|
-
function* generateSelf(
|
|
23
|
-
if (
|
|
24
|
-
yield `const
|
|
25
|
-
const { args } =
|
|
26
|
-
yield (0, utils_1.generateSfcBlockSection)(
|
|
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
27
|
yield `)${utils_1.endOfLine}`;
|
|
28
28
|
}
|
|
29
|
-
else if (
|
|
30
|
-
yield `const
|
|
31
|
-
const { expression } =
|
|
32
|
-
yield (0, utils_1.generateSfcBlockSection)(
|
|
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
33
|
yield utils_1.endOfLine;
|
|
34
34
|
}
|
|
35
|
-
else if (
|
|
36
|
-
yield `let
|
|
35
|
+
else if (script?.src) {
|
|
36
|
+
yield `let ${names.self}!: typeof import('./${path.basename(fileName)}').default${utils_1.endOfLine}`;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
function* generateTemplateCtx(
|
|
39
|
+
function* generateTemplateCtx({ vueCompilerOptions, script, scriptRanges, styleCodegen, scriptSetupRanges, fileName }, ctx) {
|
|
40
40
|
const exps = [];
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const emitTypes = [];
|
|
42
|
+
const propTypes = [];
|
|
43
|
+
if (vueCompilerOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
|
|
44
|
+
exps.push([`globalThis`]);
|
|
43
45
|
}
|
|
44
|
-
if (
|
|
45
|
-
exps.push(`{} as InstanceType<__VLS_PickNotAny<typeof
|
|
46
|
+
if (script?.src || scriptRanges?.exportDefault) {
|
|
47
|
+
exps.push([`{} as InstanceType<__VLS_PickNotAny<typeof ${names.self}, new () => {}>>`]);
|
|
46
48
|
}
|
|
47
49
|
else {
|
|
48
|
-
exps.push(`{} as import('${
|
|
50
|
+
exps.push([`{} as import('${vueCompilerOptions.lib}').ComponentPublicInstance`]);
|
|
49
51
|
}
|
|
50
|
-
if (
|
|
51
|
-
exps.push(`{} as
|
|
52
|
+
if (styleCodegen?.generatedTypes.has(names.StyleModules)) {
|
|
53
|
+
exps.push([`{} as ${names.StyleModules}`]);
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
emitTypes.push(`typeof ${defineEmits.name ?? `__VLS_emit`}`);
|
|
55
|
+
if (scriptSetupRanges?.defineEmits) {
|
|
56
|
+
const { defineEmits } = scriptSetupRanges;
|
|
57
|
+
emitTypes.push(`typeof ${defineEmits.name ?? names.emit}`);
|
|
57
58
|
}
|
|
58
|
-
if (
|
|
59
|
-
emitTypes.push(`typeof
|
|
59
|
+
if (scriptSetupRanges?.defineModel.length) {
|
|
60
|
+
emitTypes.push(`typeof ${names.modelEmit}`);
|
|
60
61
|
}
|
|
61
62
|
if (emitTypes.length) {
|
|
62
|
-
yield `type
|
|
63
|
-
exps.push(`{} as { $emit: ${emitTypes.join(` & `)} }`);
|
|
63
|
+
yield `type ${names.EmitProps} = __VLS_EmitsToProps<__VLS_NormalizeEmits<${emitTypes.join(` & `)}>>${utils_1.endOfLine}`;
|
|
64
|
+
exps.push([`{} as { $emit: ${emitTypes.join(` & `)} }`]);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
? withDefaults?.arg
|
|
71
|
-
? `__VLS_WithDefaultsGlobal<__VLS_Props, typeof __VLS_defaults>`
|
|
72
|
-
: `__VLS_Props`
|
|
73
|
-
: undefined;
|
|
74
|
-
if (props) {
|
|
75
|
-
propTypes.push(props);
|
|
76
|
-
}
|
|
77
|
-
if (options.scriptSetupRanges?.defineModel.length) {
|
|
78
|
-
propTypes.push(`__VLS_ModelProps`);
|
|
66
|
+
if (scriptSetupRanges?.defineProps) {
|
|
67
|
+
propTypes.push(`typeof ${scriptSetupRanges.defineProps.name ?? names.props}`);
|
|
68
|
+
}
|
|
69
|
+
if (scriptSetupRanges?.defineModel.length) {
|
|
70
|
+
propTypes.push(names.ModelProps);
|
|
79
71
|
}
|
|
80
72
|
if (emitTypes.length) {
|
|
81
|
-
propTypes.push(
|
|
73
|
+
propTypes.push(names.EmitProps);
|
|
82
74
|
}
|
|
83
75
|
if (propTypes.length) {
|
|
84
|
-
yield `type
|
|
85
|
-
exps.push(`{} as { $props:
|
|
86
|
-
exps.push(`{} as
|
|
76
|
+
yield `type ${names.InternalProps} = ${propTypes.join(` & `)}${utils_1.endOfLine}`;
|
|
77
|
+
exps.push([`{} as { $props: ${names.InternalProps} }`]);
|
|
78
|
+
exps.push([`{} as ${names.InternalProps}`]);
|
|
87
79
|
}
|
|
88
|
-
if (
|
|
89
|
-
exps.push(`{} as
|
|
80
|
+
if (ctx.generatedTypes.has(names.SetupExposed)) {
|
|
81
|
+
exps.push([`{} as ${names.SetupExposed}`]);
|
|
90
82
|
}
|
|
91
|
-
yield `const
|
|
83
|
+
yield `const ${names.ctx} = `;
|
|
92
84
|
yield* (0, merge_1.generateSpreadMerge)(exps);
|
|
93
85
|
yield utils_1.endOfLine;
|
|
94
86
|
}
|
|
95
87
|
function* generateTemplateComponents(options) {
|
|
96
|
-
const types = [`typeof
|
|
97
|
-
if (options.
|
|
88
|
+
const types = [`typeof ${names.ctx}`];
|
|
89
|
+
if (options.script && options.scriptRanges?.componentOptions?.components) {
|
|
98
90
|
const { components } = options.scriptRanges.componentOptions;
|
|
99
91
|
yield `const __VLS_componentsOption = `;
|
|
100
|
-
yield (0, utils_1.generateSfcBlockSection)(options.
|
|
92
|
+
yield* (0, utils_1.generateSfcBlockSection)(options.script, components.start, components.end, codeFeatures_1.codeFeatures.navigation);
|
|
101
93
|
yield utils_1.endOfLine;
|
|
102
94
|
types.push(`typeof __VLS_componentsOption`);
|
|
103
95
|
}
|
|
104
96
|
yield `type __VLS_LocalComponents = ${types.join(` & `)}${utils_1.endOfLine}`;
|
|
105
|
-
yield `let
|
|
97
|
+
yield `let ${names.components}!: __VLS_LocalComponents & __VLS_GlobalComponents${utils_1.endOfLine}`;
|
|
106
98
|
}
|
|
107
99
|
function* generateTemplateDirectives(options) {
|
|
108
|
-
const types = [`typeof
|
|
109
|
-
if (options.
|
|
100
|
+
const types = [`typeof ${names.ctx}`];
|
|
101
|
+
if (options.script && options.scriptRanges?.componentOptions?.directives) {
|
|
110
102
|
const { directives } = options.scriptRanges.componentOptions;
|
|
111
103
|
yield `const __VLS_directivesOption = `;
|
|
112
|
-
yield (0, utils_1.generateSfcBlockSection)(options.
|
|
104
|
+
yield* (0, utils_1.generateSfcBlockSection)(options.script, directives.start, directives.end, codeFeatures_1.codeFeatures.navigation);
|
|
113
105
|
yield utils_1.endOfLine;
|
|
114
106
|
types.push(`__VLS_ResolveDirectives<typeof __VLS_directivesOption>`);
|
|
115
107
|
}
|
|
116
108
|
yield `type __VLS_LocalDirectives = ${types.join(` & `)}${utils_1.endOfLine}`;
|
|
117
|
-
yield `let
|
|
118
|
-
}
|
|
119
|
-
function* generateTemplateBody(options, ctx) {
|
|
120
|
-
const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)({
|
|
121
|
-
scriptSetupBindingNames: new Set(),
|
|
122
|
-
});
|
|
123
|
-
yield* (0, scopedClasses_1.generateStyleScopedClasses)(options, templateCodegenCtx);
|
|
124
|
-
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(templateCodegenCtx, true);
|
|
125
|
-
yield* (0, modules_1.generateStyleModules)(options);
|
|
126
|
-
yield* generateCssVars(options, templateCodegenCtx);
|
|
127
|
-
yield* generateBindings(options, ctx, templateCodegenCtx);
|
|
128
|
-
if (options.templateCodegen) {
|
|
129
|
-
yield* options.templateCodegen.codes;
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
if (!options.scriptSetupRanges?.defineSlots) {
|
|
133
|
-
yield `type __VLS_Slots = {}${utils_1.endOfLine}`;
|
|
134
|
-
}
|
|
135
|
-
yield `type __VLS_InheritedAttrs = {}${utils_1.endOfLine}`;
|
|
136
|
-
yield `type __VLS_TemplateRefs = {}${utils_1.endOfLine}`;
|
|
137
|
-
yield `type __VLS_RootEl = any${utils_1.endOfLine}`;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function* generateCssVars(options, ctx) {
|
|
141
|
-
for (const style of options.sfc.styles) {
|
|
142
|
-
for (const binding of style.bindings) {
|
|
143
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name, codeFeatures_1.codeFeatures.all, binding.text, binding.offset, `(`, `)`);
|
|
144
|
-
yield utils_1.endOfLine;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
109
|
+
yield `let ${names.directives}!: __VLS_LocalDirectives & __VLS_GlobalDirectives${utils_1.endOfLine}`;
|
|
147
110
|
}
|
|
148
|
-
function*
|
|
149
|
-
if (!
|
|
111
|
+
function* generateSetupExposed({ setupExposed }, ctx) {
|
|
112
|
+
if (!setupExposed.size) {
|
|
150
113
|
return;
|
|
151
114
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
]);
|
|
157
|
-
yield `type __VLS_Bindings = __VLS_ProxyRefs<{${utils_1.newLine}`;
|
|
158
|
-
for (const varName of ctx.bindingNames) {
|
|
159
|
-
if (!usageVars.has(varName)) {
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
const token = Symbol(varName.length);
|
|
115
|
+
ctx.generatedTypes.add(names.SetupExposed);
|
|
116
|
+
yield `type ${names.SetupExposed} = __VLS_ProxyRefs<{${utils_1.newLine}`;
|
|
117
|
+
for (const bindingName of setupExposed) {
|
|
118
|
+
const token = Symbol(bindingName.length);
|
|
163
119
|
yield ['', undefined, 0, { __linkedToken: token }];
|
|
164
|
-
yield `${
|
|
120
|
+
yield `${bindingName}: typeof `;
|
|
165
121
|
yield ['', undefined, 0, { __linkedToken: token }];
|
|
166
|
-
yield
|
|
122
|
+
yield bindingName;
|
|
167
123
|
yield utils_1.endOfLine;
|
|
168
124
|
}
|
|
169
125
|
yield `}>${utils_1.endOfLine}`;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Code, Sfc } from '../../types';
|
|
2
|
+
export declare function generateClassProperty(source: string, classNameWithDot: string, offset: number, propertyType: string): Generator<Code>;
|
|
3
|
+
export declare function generateStyleImports(style: Sfc['styles'][number]): Generator<Code>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateClassProperty = generateClassProperty;
|
|
4
|
+
exports.generateStyleImports = generateStyleImports;
|
|
5
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const boundary_1 = require("../utils/boundary");
|
|
8
|
+
function* generateClassProperty(source, classNameWithDot, offset, propertyType) {
|
|
9
|
+
yield `${utils_1.newLine} & { `;
|
|
10
|
+
const token = yield* (0, boundary_1.startBoundary)(source, offset, codeFeatures_1.codeFeatures.navigation);
|
|
11
|
+
yield `'`;
|
|
12
|
+
yield [classNameWithDot.slice(1), source, offset + 1, { __combineToken: token }];
|
|
13
|
+
yield `'`;
|
|
14
|
+
yield (0, boundary_1.endBoundary)(token, offset + classNameWithDot.length);
|
|
15
|
+
yield `: ${propertyType}`;
|
|
16
|
+
yield ` }`;
|
|
17
|
+
}
|
|
18
|
+
function* generateStyleImports(style) {
|
|
19
|
+
const features = {
|
|
20
|
+
navigation: true,
|
|
21
|
+
verification: true,
|
|
22
|
+
};
|
|
23
|
+
if (typeof style.src === 'object') {
|
|
24
|
+
yield `${utils_1.newLine} & typeof import(`;
|
|
25
|
+
const token = yield* (0, boundary_1.startBoundary)('main', style.src.offset, features);
|
|
26
|
+
yield `'`;
|
|
27
|
+
yield [style.src.text, 'main', style.src.offset, { __combineToken: token }];
|
|
28
|
+
yield `'`;
|
|
29
|
+
yield (0, boundary_1.endBoundary)(token, style.src.offset + style.src.text.length);
|
|
30
|
+
yield `).default`;
|
|
31
|
+
}
|
|
32
|
+
for (const { text, offset } of style.imports) {
|
|
33
|
+
yield `${utils_1.newLine} & typeof import('`;
|
|
34
|
+
yield [
|
|
35
|
+
text,
|
|
36
|
+
style.name,
|
|
37
|
+
offset,
|
|
38
|
+
features,
|
|
39
|
+
];
|
|
40
|
+
yield `').default`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
|
2
|
+
export interface StyleCodegenOptions {
|
|
3
|
+
ts: typeof import('typescript');
|
|
4
|
+
vueCompilerOptions: VueCompilerOptions;
|
|
5
|
+
styles: Sfc['styles'];
|
|
6
|
+
setupRefs: Set<string>;
|
|
7
|
+
setupConsts: Set<string>;
|
|
8
|
+
}
|
|
9
|
+
export { generate as generateStyle };
|
|
10
|
+
declare function generate(options: StyleCodegenOptions): {
|
|
11
|
+
codes: Code[];
|
|
12
|
+
generatedTypes: Set<string>;
|
|
13
|
+
currentInfo: {
|
|
14
|
+
ignoreError?: boolean;
|
|
15
|
+
expectError?: {
|
|
16
|
+
token: number;
|
|
17
|
+
node: import("@vue/compiler-dom").CommentNode;
|
|
18
|
+
};
|
|
19
|
+
generic?: {
|
|
20
|
+
content: string;
|
|
21
|
+
offset: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
|
|
25
|
+
inVFor: boolean;
|
|
26
|
+
slots: {
|
|
27
|
+
name: string;
|
|
28
|
+
offset?: number;
|
|
29
|
+
tagRange: [number, number];
|
|
30
|
+
nodeLoc: any;
|
|
31
|
+
propsVar: string;
|
|
32
|
+
}[];
|
|
33
|
+
dynamicSlots: {
|
|
34
|
+
expVar: string;
|
|
35
|
+
propsVar: string;
|
|
36
|
+
}[];
|
|
37
|
+
dollarVars: Set<string>;
|
|
38
|
+
componentAccessMap: Map<string, Map<string, Set<number>>>;
|
|
39
|
+
blockConditions: string[];
|
|
40
|
+
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
41
|
+
inheritedAttrVars: Set<string>;
|
|
42
|
+
templateRefs: Map<string, {
|
|
43
|
+
typeExp: string;
|
|
44
|
+
offset: number;
|
|
45
|
+
}[]>;
|
|
46
|
+
currentComponent: {
|
|
47
|
+
get ctxVar(): string;
|
|
48
|
+
get propsVar(): string;
|
|
49
|
+
} | undefined;
|
|
50
|
+
singleRootElTypes: Set<string>;
|
|
51
|
+
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
52
|
+
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
53
|
+
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
54
|
+
scopes: Set<string>[];
|
|
55
|
+
declare(...varNames: string[]): void;
|
|
56
|
+
startScope(): () => Generator<Code, any, any>;
|
|
57
|
+
getInternalVariable(): string;
|
|
58
|
+
getHoistVariable(originalVar: string): string;
|
|
59
|
+
generateHoistVariables(): Generator<string, void, unknown>;
|
|
60
|
+
generateConditionGuards(): Generator<string, void, unknown>;
|
|
61
|
+
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
|
|
62
|
+
exit(): Generator<Code>;
|
|
63
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateStyle = generate;
|
|
4
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
5
|
+
const modules_1 = require("../style/modules");
|
|
6
|
+
const scopedClasses_1 = require("../style/scopedClasses");
|
|
7
|
+
const context_1 = require("../template/context");
|
|
8
|
+
const interpolation_1 = require("../template/interpolation");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
function generate(options) {
|
|
11
|
+
const ctx = (0, context_1.createTemplateCodegenContext)();
|
|
12
|
+
const codeGenerator = generateWorker(options, ctx);
|
|
13
|
+
const codes = [];
|
|
14
|
+
for (const code of codeGenerator) {
|
|
15
|
+
if (typeof code === 'object') {
|
|
16
|
+
code[3] = ctx.resolveCodeFeatures(code[3]);
|
|
17
|
+
}
|
|
18
|
+
codes.push(code);
|
|
19
|
+
}
|
|
20
|
+
return { ...ctx, codes };
|
|
21
|
+
}
|
|
22
|
+
function* generateWorker(options, ctx) {
|
|
23
|
+
const endScope = ctx.startScope();
|
|
24
|
+
ctx.declare(...options.setupConsts);
|
|
25
|
+
yield* (0, scopedClasses_1.generateStyleScopedClasses)(options);
|
|
26
|
+
yield* (0, modules_1.generateStyleModules)(options, ctx);
|
|
27
|
+
yield* generateCssVars(options, ctx);
|
|
28
|
+
yield* endScope();
|
|
29
|
+
}
|
|
30
|
+
function* generateCssVars(options, ctx) {
|
|
31
|
+
for (const style of options.styles) {
|
|
32
|
+
for (const binding of style.bindings) {
|
|
33
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, style, codeFeatures_1.codeFeatures.all, binding.text, binding.offset, `(`, `)`);
|
|
34
|
+
yield utils_1.endOfLine;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Code } from '../../types';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { TemplateCodegenContext } from '../template/context';
|
|
3
|
+
import type { StyleCodegenOptions } from '.';
|
|
4
|
+
export declare function generateStyleModules({ styles, vueCompilerOptions }: StyleCodegenOptions, ctx: TemplateCodegenContext): Generator<Code>;
|
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateStyleModules = generateStyleModules;
|
|
4
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
5
|
+
const names = require("../names");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (!styles.length && !options.scriptSetupRanges?.useCssModule.length) {
|
|
7
|
+
const common_1 = require("./common");
|
|
8
|
+
function* generateStyleModules({ styles, vueCompilerOptions }, ctx) {
|
|
9
|
+
const styleModules = styles.filter(style => style.module);
|
|
10
|
+
if (!styleModules.length) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
ctx.generatedTypes.add(names.StyleModules);
|
|
14
|
+
yield `type ${names.StyleModules} = {${utils_1.newLine}`;
|
|
15
|
+
for (const style of styleModules) {
|
|
15
16
|
if (style.module === true) {
|
|
16
17
|
yield `$style`;
|
|
17
18
|
}
|
|
@@ -25,15 +26,15 @@ function* generateStyleModules(options) {
|
|
|
25
26
|
];
|
|
26
27
|
}
|
|
27
28
|
yield `: `;
|
|
28
|
-
if (!
|
|
29
|
+
if (!vueCompilerOptions.strictCssModules) {
|
|
29
30
|
yield `Record<string, string> & `;
|
|
30
31
|
}
|
|
31
32
|
yield `__VLS_PrettifyGlobal<{}`;
|
|
32
|
-
if (
|
|
33
|
-
yield* (0,
|
|
33
|
+
if (vueCompilerOptions.resolveStyleImports) {
|
|
34
|
+
yield* (0, common_1.generateStyleImports)(style);
|
|
34
35
|
}
|
|
35
36
|
for (const className of style.classNames) {
|
|
36
|
-
yield* (0,
|
|
37
|
+
yield* (0, common_1.generateClassProperty)(style.name, className.text, className.offset, 'string');
|
|
37
38
|
}
|
|
38
39
|
yield `>${utils_1.endOfLine}`;
|
|
39
40
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { Code } from '../../types';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export declare function generateStyleScopedClasses(options: ScriptCodegenOptions, ctx: TemplateCodegenContext): Generator<Code>;
|
|
2
|
+
import type { StyleCodegenOptions } from '.';
|
|
3
|
+
export declare function generateStyleScopedClasses({ vueCompilerOptions, styles }: StyleCodegenOptions): Generator<Code>;
|
|
@@ -1,36 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateStyleScopedClasses = generateStyleScopedClasses;
|
|
4
|
+
const styleScopedClasses_1 = require("../template/styleScopedClasses");
|
|
4
5
|
const utils_1 = require("../utils");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const styles = options.sfc.styles
|
|
10
|
-
.map((style, i) => [style, i])
|
|
11
|
-
.filter(([style]) => option === true || (option === 'scoped' && style.scoped));
|
|
12
|
-
if (!styles.length) {
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
function* generateStyleScopedClasses({ vueCompilerOptions, styles }) {
|
|
8
|
+
const { resolveStyleClassNames, resolveStyleImports } = vueCompilerOptions;
|
|
9
|
+
if (!resolveStyleClassNames) {
|
|
13
10
|
return;
|
|
14
11
|
}
|
|
15
|
-
const
|
|
12
|
+
const scopedStyles = styles.filter(style => resolveStyleClassNames === true || style.scoped);
|
|
13
|
+
if (!scopedStyles.length) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const visited = new Set();
|
|
17
|
+
const deferredGenerations = [];
|
|
16
18
|
yield `type __VLS_StyleScopedClasses = {}`;
|
|
17
|
-
for (const
|
|
18
|
-
if (
|
|
19
|
-
yield* (0,
|
|
19
|
+
for (const style of scopedStyles) {
|
|
20
|
+
if (resolveStyleImports) {
|
|
21
|
+
yield* (0, common_1.generateStyleImports)(style);
|
|
20
22
|
}
|
|
21
23
|
for (const className of style.classNames) {
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
continue;
|
|
24
|
+
if (!visited.has(className.text)) {
|
|
25
|
+
visited.add(className.text);
|
|
26
|
+
yield* (0, common_1.generateClassProperty)(style.name, className.text, className.offset, 'boolean');
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
deferredGenerations.push((0, styleScopedClasses_1.generateStyleScopedClassReference)(style, className.text.slice(1), className.offset + 1));
|
|
29
30
|
}
|
|
30
|
-
firstClasses.add(className.text);
|
|
31
|
-
yield* (0, classProperty_1.generateClassProperty)(i, className.text, className.offset, 'boolean');
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
yield utils_1.endOfLine;
|
|
34
|
+
for (const generate of deferredGenerations) {
|
|
35
|
+
yield* generate;
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
38
|
//# sourceMappingURL=scopedClasses.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type { Code, VueCodeInformation } from '../../types';
|
|
3
3
|
import type { InlayHintInfo } from '../inlayHints';
|
|
4
|
-
import type { TemplateCodegenOptions } from './index';
|
|
5
4
|
export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;
|
|
6
5
|
/**
|
|
7
6
|
* Creates and returns a Context object used for generating type-checkable TS code
|
|
@@ -100,7 +99,8 @@ export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenCont
|
|
|
100
99
|
* an error/diagnostic was encountered for a region of code covered by a `@vue-expect-error` directive,
|
|
101
100
|
* and additionally how we use that to determine whether to propagate diagnostics back upward.
|
|
102
101
|
*/
|
|
103
|
-
export declare function createTemplateCodegenContext(
|
|
102
|
+
export declare function createTemplateCodegenContext(): {
|
|
103
|
+
generatedTypes: Set<string>;
|
|
104
104
|
readonly currentInfo: {
|
|
105
105
|
ignoreError?: boolean;
|
|
106
106
|
expectError?: {
|
|
@@ -113,7 +113,6 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
113
113
|
};
|
|
114
114
|
};
|
|
115
115
|
resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
|
|
116
|
-
inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
|
|
117
116
|
inVFor: boolean;
|
|
118
117
|
slots: {
|
|
119
118
|
name: string;
|
|
@@ -127,37 +126,29 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
127
126
|
propsVar: string;
|
|
128
127
|
}[];
|
|
129
128
|
dollarVars: Set<string>;
|
|
130
|
-
|
|
129
|
+
componentAccessMap: Map<string, Map<string, Set<number>>>;
|
|
131
130
|
blockConditions: string[];
|
|
132
|
-
scopedClasses: {
|
|
133
|
-
source: string;
|
|
134
|
-
className: string;
|
|
135
|
-
offset: number;
|
|
136
|
-
}[];
|
|
137
|
-
emptyClassOffsets: number[];
|
|
138
131
|
inlayHints: InlayHintInfo[];
|
|
139
|
-
bindingAttrLocs: CompilerDOM.SourceLocation[];
|
|
140
132
|
inheritedAttrVars: Set<string>;
|
|
141
133
|
templateRefs: Map<string, {
|
|
142
134
|
typeExp: string;
|
|
143
135
|
offset: number;
|
|
144
136
|
}[]>;
|
|
145
137
|
currentComponent: {
|
|
146
|
-
ctxVar: string;
|
|
147
|
-
|
|
138
|
+
get ctxVar(): string;
|
|
139
|
+
get propsVar(): string;
|
|
148
140
|
} | undefined;
|
|
149
|
-
singleRootElTypes: string
|
|
141
|
+
singleRootElTypes: Set<string>;
|
|
150
142
|
singleRootNodes: Set<CompilerDOM.ElementNode | null>;
|
|
151
143
|
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
144
|
+
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
145
|
+
scopes: Set<string>[];
|
|
146
|
+
declare(...varNames: string[]): void;
|
|
147
|
+
startScope(): () => Generator<Code, any, any>;
|
|
156
148
|
getInternalVariable(): string;
|
|
157
149
|
getHoistVariable(originalVar: string): string;
|
|
158
150
|
generateHoistVariables(): Generator<string, void, unknown>;
|
|
159
151
|
generateConditionGuards(): Generator<string, void, unknown>;
|
|
160
|
-
generateAutoImportCompletion(): Generator<Code>;
|
|
161
152
|
enter(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode): boolean;
|
|
162
153
|
exit(): Generator<Code>;
|
|
163
154
|
};
|