@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
|
@@ -2,108 +2,116 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateTemplate = generate;
|
|
4
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
5
|
+
const names = require("../names");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
|
-
const
|
|
7
|
+
const boundary_1 = require("../utils/boundary");
|
|
7
8
|
const context_1 = require("./context");
|
|
8
9
|
const objectProperty_1 = require("./objectProperty");
|
|
9
|
-
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
10
10
|
const templateChild_1 = require("./templateChild");
|
|
11
11
|
function generate(options) {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const ctx = (0, context_1.createTemplateCodegenContext)();
|
|
13
|
+
const codeGenerator = generateWorker(options, ctx);
|
|
14
14
|
const codes = [];
|
|
15
|
-
for (const code of
|
|
15
|
+
for (const code of codeGenerator) {
|
|
16
16
|
if (typeof code === 'object') {
|
|
17
|
-
code[3] =
|
|
17
|
+
code[3] = ctx.resolveCodeFeatures(code[3]);
|
|
18
18
|
}
|
|
19
19
|
codes.push(code);
|
|
20
20
|
}
|
|
21
|
-
return {
|
|
22
|
-
...context,
|
|
23
|
-
codes,
|
|
24
|
-
};
|
|
21
|
+
return { ...ctx, codes };
|
|
25
22
|
}
|
|
26
|
-
function*
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
function* generateWorker(options, ctx) {
|
|
24
|
+
const endScope = ctx.startScope();
|
|
25
|
+
ctx.declare(...options.setupConsts);
|
|
26
|
+
const { slotsAssignName, propsAssignName, vueCompilerOptions, template, } = options;
|
|
27
|
+
if (slotsAssignName) {
|
|
28
|
+
ctx.declare(slotsAssignName);
|
|
29
29
|
}
|
|
30
|
-
if (
|
|
31
|
-
ctx.
|
|
30
|
+
if (propsAssignName) {
|
|
31
|
+
ctx.declare(propsAssignName);
|
|
32
32
|
}
|
|
33
|
-
if (
|
|
33
|
+
if (vueCompilerOptions.inferTemplateDollarSlots) {
|
|
34
34
|
ctx.dollarVars.add('$slots');
|
|
35
35
|
}
|
|
36
|
-
if (
|
|
36
|
+
if (vueCompilerOptions.inferTemplateDollarAttrs) {
|
|
37
37
|
ctx.dollarVars.add('$attrs');
|
|
38
38
|
}
|
|
39
|
-
if (
|
|
39
|
+
if (vueCompilerOptions.inferTemplateDollarRefs) {
|
|
40
40
|
ctx.dollarVars.add('$refs');
|
|
41
41
|
}
|
|
42
|
-
if (
|
|
42
|
+
if (vueCompilerOptions.inferTemplateDollarEl) {
|
|
43
43
|
ctx.dollarVars.add('$el');
|
|
44
44
|
}
|
|
45
|
-
if (
|
|
46
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx,
|
|
45
|
+
if (template.ast) {
|
|
46
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, template.ast);
|
|
47
47
|
}
|
|
48
|
-
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
|
|
49
48
|
yield* ctx.generateHoistVariables();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
yield `${name}: ${type}${utils_1.endOfLine}`;
|
|
49
|
+
yield* generateSlotsType(options, ctx);
|
|
50
|
+
yield* generateInheritedAttrsType(ctx);
|
|
51
|
+
yield* generateTemplateRefsType(options, ctx);
|
|
52
|
+
yield* generateRootElType(ctx);
|
|
53
|
+
if (ctx.dollarVars.size) {
|
|
54
|
+
yield `var ${names.dollars}!: {${utils_1.newLine}`;
|
|
55
|
+
if (ctx.dollarVars.has('$slots')) {
|
|
56
|
+
const type = ctx.generatedTypes.has(names.Slots) ? names.Slots : `{}`;
|
|
57
|
+
yield `$slots: ${type}${utils_1.endOfLine}`;
|
|
60
58
|
}
|
|
61
|
-
|
|
59
|
+
if (ctx.dollarVars.has('$attrs')) {
|
|
60
|
+
yield `$attrs: import('${vueCompilerOptions.lib}').ComponentPublicInstance['$attrs']`;
|
|
61
|
+
if (ctx.generatedTypes.has(names.InheritedAttrs)) {
|
|
62
|
+
yield ` & ${names.InheritedAttrs}`;
|
|
63
|
+
}
|
|
64
|
+
yield utils_1.endOfLine;
|
|
65
|
+
}
|
|
66
|
+
if (ctx.dollarVars.has('$refs')) {
|
|
67
|
+
const type = ctx.generatedTypes.has(names.TemplateRefs) ? names.TemplateRefs : `{}`;
|
|
68
|
+
yield `$refs: ${type}${utils_1.endOfLine}`;
|
|
69
|
+
}
|
|
70
|
+
if (ctx.dollarVars.has('$el')) {
|
|
71
|
+
const type = ctx.generatedTypes.has(names.RootEl) ? names.RootEl : `any`;
|
|
72
|
+
yield `$el: ${type}${utils_1.endOfLine}`;
|
|
73
|
+
}
|
|
74
|
+
yield `} & { [K in keyof import('${vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
|
|
62
75
|
}
|
|
76
|
+
yield* endScope();
|
|
63
77
|
}
|
|
64
|
-
function*
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
function* generateSlotsType(options, ctx) {
|
|
79
|
+
if (options.hasDefineSlots || (!ctx.slots.length && !ctx.dynamicSlots.length)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
ctx.generatedTypes.add(names.Slots);
|
|
83
|
+
yield `type ${names.Slots} = {}`;
|
|
84
|
+
for (const { expVar, propsVar } of ctx.dynamicSlots) {
|
|
85
|
+
yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
|
|
86
|
+
}
|
|
87
|
+
for (const slot of ctx.slots) {
|
|
88
|
+
yield `${utils_1.newLine}& { `;
|
|
89
|
+
if (slot.name && slot.offset !== undefined) {
|
|
90
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, codeFeatures_1.codeFeatures.navigation);
|
|
69
91
|
}
|
|
70
|
-
|
|
71
|
-
yield
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], codeFeatures_1.codeFeatures.navigation, `default`);
|
|
77
|
-
}
|
|
78
|
-
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
92
|
+
else {
|
|
93
|
+
const token = yield* (0, boundary_1.startBoundary)('template', slot.tagRange[0], codeFeatures_1.codeFeatures.navigation);
|
|
94
|
+
yield `default`;
|
|
95
|
+
yield (0, boundary_1.endBoundary)(token, slot.tagRange[1]);
|
|
79
96
|
}
|
|
80
|
-
yield
|
|
97
|
+
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
81
98
|
}
|
|
82
|
-
return `__VLS_Slots`;
|
|
83
|
-
}
|
|
84
|
-
function* generateInheritedAttrs(options, ctx) {
|
|
85
|
-
yield `type __VLS_InheritedAttrs = ${ctx.inheritedAttrVars.size
|
|
86
|
-
? `Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`
|
|
87
|
-
: `{}`}`;
|
|
88
99
|
yield utils_1.endOfLine;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
yield [
|
|
94
|
-
loc.source,
|
|
95
|
-
'template',
|
|
96
|
-
loc.start.offset,
|
|
97
|
-
codeFeatures_1.codeFeatures.all,
|
|
98
|
-
];
|
|
99
|
-
yield `,`;
|
|
100
|
-
}
|
|
101
|
-
yield `]${utils_1.endOfLine}`;
|
|
100
|
+
}
|
|
101
|
+
function* generateInheritedAttrsType(ctx) {
|
|
102
|
+
if (!ctx.inheritedAttrVars.size) {
|
|
103
|
+
return;
|
|
102
104
|
}
|
|
103
|
-
|
|
105
|
+
ctx.generatedTypes.add(names.InheritedAttrs);
|
|
106
|
+
yield `type ${names.InheritedAttrs} = Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`;
|
|
107
|
+
yield utils_1.endOfLine;
|
|
104
108
|
}
|
|
105
|
-
function*
|
|
106
|
-
|
|
109
|
+
function* generateTemplateRefsType(options, ctx) {
|
|
110
|
+
if (!ctx.templateRefs.size) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
ctx.generatedTypes.add(names.TemplateRefs);
|
|
114
|
+
yield `type ${names.TemplateRefs} = {}`;
|
|
107
115
|
for (const [name, refs] of ctx.templateRefs) {
|
|
108
116
|
yield `${utils_1.newLine}& `;
|
|
109
117
|
if (refs.length >= 2) {
|
|
@@ -123,19 +131,16 @@ function* generateTemplateRefs(options, ctx) {
|
|
|
123
131
|
}
|
|
124
132
|
}
|
|
125
133
|
yield utils_1.endOfLine;
|
|
126
|
-
return `__VLS_TemplateRefs`;
|
|
127
134
|
}
|
|
128
|
-
function*
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
for (const type of ctx.singleRootElTypes) {
|
|
132
|
-
yield `${utils_1.newLine}| ${type}`;
|
|
133
|
-
}
|
|
135
|
+
function* generateRootElType(ctx) {
|
|
136
|
+
if (!ctx.singleRootElTypes.size || ctx.singleRootNodes.has(null)) {
|
|
137
|
+
return;
|
|
134
138
|
}
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
ctx.generatedTypes.add(names.RootEl);
|
|
140
|
+
yield `type ${names.RootEl} = `;
|
|
141
|
+
for (const type of ctx.singleRootElTypes) {
|
|
142
|
+
yield `${utils_1.newLine}| ${type}`;
|
|
137
143
|
}
|
|
138
144
|
yield utils_1.endOfLine;
|
|
139
|
-
return `__VLS_RootEl`;
|
|
140
145
|
}
|
|
141
146
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
-
import type {
|
|
1
|
+
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
|
|
2
|
+
import type { StyleCodegenOptions } from '../style';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
|
-
export declare function generateInterpolation(options: TemplateCodegenOptions |
|
|
5
|
+
export declare function generateInterpolation(options: Pick<TemplateCodegenOptions | StyleCodegenOptions, 'ts' | 'setupRefs'>, ctx: TemplateCodegenContext, block: SfcBlock, data: VueCodeInformation, code: string, start: number, prefix?: string, suffix?: string): Generator<Code>;
|
|
@@ -5,246 +5,199 @@ const shared_1 = require("@vue/shared");
|
|
|
5
5
|
const collectBindings_1 = require("../../utils/collectBindings");
|
|
6
6
|
const shared_2 = require("../../utils/shared");
|
|
7
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
|
+
const names = require("../names");
|
|
8
9
|
const utils_1 = require("../utils");
|
|
9
10
|
// https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
|
|
10
11
|
const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
|
|
11
|
-
function* generateInterpolation(options, ctx,
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
function* generateInterpolation(options, ctx, block, data, code, start, prefix = '', suffix = '') {
|
|
13
|
+
for (const segment of forEachInterpolationSegment(options, ctx, block, code, start, prefix, suffix)) {
|
|
14
|
+
if (typeof segment === 'string') {
|
|
15
|
+
yield segment;
|
|
16
|
+
continue;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
const shouldSkip = section.length === 0 && (type === 'startText' || type === 'endText');
|
|
31
|
-
if (!shouldSkip) {
|
|
32
|
-
if (start !== undefined
|
|
33
|
-
&& data) {
|
|
34
|
-
yield [
|
|
35
|
-
section,
|
|
36
|
-
source,
|
|
37
|
-
start + offset,
|
|
38
|
-
type === 'errorMappingOnly'
|
|
39
|
-
? codeFeatures_1.codeFeatures.verification
|
|
40
|
-
: typeof data === 'function'
|
|
41
|
-
? data(start + offset)
|
|
42
|
-
: data,
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
yield section;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
yield addSuffix;
|
|
18
|
+
let [section, offset, type] = segment;
|
|
19
|
+
offset -= prefix.length;
|
|
20
|
+
let addSuffix = '';
|
|
21
|
+
const overLength = offset + section.length - code.length;
|
|
22
|
+
if (overLength > 0) {
|
|
23
|
+
addSuffix = section.slice(section.length - overLength);
|
|
24
|
+
section = section.slice(0, -overLength);
|
|
25
|
+
}
|
|
26
|
+
if (offset < 0) {
|
|
27
|
+
yield section.slice(0, -offset);
|
|
28
|
+
section = section.slice(-offset);
|
|
29
|
+
offset = 0;
|
|
50
30
|
}
|
|
31
|
+
const shouldSkip = section.length === 0 && type === 'startEnd';
|
|
32
|
+
if (!shouldSkip) {
|
|
33
|
+
yield [
|
|
34
|
+
section,
|
|
35
|
+
block.name,
|
|
36
|
+
start + offset,
|
|
37
|
+
type === 'errorMappingOnly'
|
|
38
|
+
? codeFeatures_1.codeFeatures.verification
|
|
39
|
+
: data,
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
yield addSuffix;
|
|
51
43
|
}
|
|
52
44
|
}
|
|
53
|
-
function* forEachInterpolationSegment(ts,
|
|
45
|
+
function* forEachInterpolationSegment({ ts, setupRefs }, ctx, block, originalCode, start, prefix, suffix) {
|
|
54
46
|
const code = prefix + originalCode + suffix;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb, ctx, [], true));
|
|
76
|
-
}
|
|
77
|
-
ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
|
|
78
|
-
if (ctxVars.length) {
|
|
79
|
-
for (let i = 0; i < ctxVars.length; i++) {
|
|
80
|
-
const lastVar = ctxVars[i - 1];
|
|
81
|
-
const curVar = ctxVars[i];
|
|
82
|
-
const lastVarEnd = lastVar ? lastVar.offset + lastVar.text.length : 0;
|
|
83
|
-
if (curVar.isShorthand) {
|
|
84
|
-
yield [code.slice(lastVarEnd, curVar.offset + curVar.text.length), lastVarEnd];
|
|
85
|
-
yield [': ', undefined];
|
|
47
|
+
let prevEnd = 0;
|
|
48
|
+
for (const [name, offset, isShorthand] of forEachIdentifiers(ts, ctx, block, originalCode, code, prefix)) {
|
|
49
|
+
if (isShorthand) {
|
|
50
|
+
yield [code.slice(prevEnd, offset + name.length), prevEnd];
|
|
51
|
+
yield `: `;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
yield [code.slice(prevEnd, offset), prevEnd, prevEnd > 0 ? undefined : 'startEnd'];
|
|
55
|
+
}
|
|
56
|
+
if (setupRefs.has(name)) {
|
|
57
|
+
yield [name, offset];
|
|
58
|
+
yield `.value`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
yield ['', offset, 'errorMappingOnly']; // #1205, #1264
|
|
62
|
+
if (ctx.dollarVars.has(name)) {
|
|
63
|
+
yield names.dollars;
|
|
86
64
|
}
|
|
87
65
|
else {
|
|
88
|
-
|
|
66
|
+
ctx.recordComponentAccess(block.name, name, start - prefix.length + offset);
|
|
67
|
+
yield names.ctx;
|
|
89
68
|
}
|
|
90
|
-
yield
|
|
91
|
-
|
|
92
|
-
const lastVar = ctxVars.at(-1);
|
|
93
|
-
if (lastVar.offset + lastVar.text.length < code.length) {
|
|
94
|
-
yield [code.slice(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
|
|
69
|
+
yield `.`;
|
|
70
|
+
yield [name, offset];
|
|
95
71
|
}
|
|
72
|
+
prevEnd = offset + name.length;
|
|
96
73
|
}
|
|
97
|
-
|
|
98
|
-
yield [code,
|
|
74
|
+
if (prevEnd < code.length) {
|
|
75
|
+
yield [code.slice(prevEnd), prevEnd, 'startEnd'];
|
|
99
76
|
}
|
|
100
77
|
}
|
|
101
|
-
function*
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (offset !== undefined) {
|
|
113
|
-
ctx.accessExternalVariable(curVar.text, offset + curVar.offset);
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
ctx.accessExternalVariable(curVar.text);
|
|
117
|
-
}
|
|
118
|
-
if (ctx.dollarVars.has(curVar.text)) {
|
|
119
|
-
yield [`__VLS_dollars.`, undefined];
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
yield [`__VLS_ctx.`, undefined];
|
|
78
|
+
function* forEachIdentifiers(ts, ctx, block, originalCode, code, prefix) {
|
|
79
|
+
if (utils_1.identifierRegex.test(originalCode) && !shouldIdentifierSkipped(ctx, originalCode)) {
|
|
80
|
+
yield [originalCode, prefix.length, false];
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const endScope = ctx.startScope();
|
|
84
|
+
const ast = (0, utils_1.getTypeScriptAST)(ts, block, code);
|
|
85
|
+
for (const [id, isShorthand] of forEachDeclarations(ts, ast, ast, ctx)) {
|
|
86
|
+
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
|
87
|
+
if (shouldIdentifierSkipped(ctx, text)) {
|
|
88
|
+
continue;
|
|
123
89
|
}
|
|
124
|
-
yield [
|
|
90
|
+
yield [text, (0, shared_2.getStartEnd)(ts, id, ast).start, isShorthand];
|
|
125
91
|
}
|
|
92
|
+
endScope();
|
|
126
93
|
}
|
|
127
|
-
function
|
|
94
|
+
function* forEachDeclarations(ts, node, ast, ctx) {
|
|
128
95
|
if (ts.isIdentifier(node)) {
|
|
129
|
-
|
|
96
|
+
yield [node, false];
|
|
130
97
|
}
|
|
131
98
|
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
132
|
-
|
|
99
|
+
yield [node.name, true];
|
|
133
100
|
}
|
|
134
101
|
else if (ts.isPropertyAccessExpression(node)) {
|
|
135
|
-
|
|
102
|
+
yield* forEachDeclarations(ts, node.expression, ast, ctx);
|
|
136
103
|
}
|
|
137
104
|
else if (ts.isVariableDeclaration(node)) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
ctx.addLocalVariable(name);
|
|
141
|
-
blockVars.push(name);
|
|
142
|
-
}
|
|
143
|
-
walkIdentifiersInBinding(ts, node, ast, cb, ctx, blockVars);
|
|
105
|
+
ctx.declare(...(0, collectBindings_1.collectBindingNames)(ts, node.name, ast));
|
|
106
|
+
yield* forEachDeclarationsInBinding(ts, node, ast, ctx);
|
|
144
107
|
}
|
|
145
108
|
else if (ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node)) {
|
|
146
109
|
for (const element of node.elements) {
|
|
147
110
|
if (ts.isBindingElement(element)) {
|
|
148
|
-
|
|
111
|
+
yield* forEachDeclarationsInBinding(ts, element, ast, ctx);
|
|
149
112
|
}
|
|
150
113
|
}
|
|
151
114
|
}
|
|
152
115
|
else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
153
|
-
|
|
116
|
+
yield* forEachDeclarationsInFunction(ts, node, ast, ctx);
|
|
154
117
|
}
|
|
155
118
|
else if (ts.isObjectLiteralExpression(node)) {
|
|
156
119
|
for (const prop of node.properties) {
|
|
157
120
|
if (ts.isPropertyAssignment(prop)) {
|
|
158
121
|
// fix https://github.com/vuejs/language-tools/issues/1176
|
|
159
122
|
if (ts.isComputedPropertyName(prop.name)) {
|
|
160
|
-
|
|
123
|
+
yield* forEachDeclarations(ts, prop.name.expression, ast, ctx);
|
|
161
124
|
}
|
|
162
|
-
|
|
125
|
+
yield* forEachDeclarations(ts, prop.initializer, ast, ctx);
|
|
163
126
|
}
|
|
164
127
|
// fix https://github.com/vuejs/language-tools/issues/1156
|
|
165
128
|
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
166
|
-
|
|
129
|
+
yield* forEachDeclarations(ts, prop, ast, ctx);
|
|
167
130
|
}
|
|
168
131
|
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
169
132
|
else if (ts.isSpreadAssignment(prop)) {
|
|
170
133
|
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
|
171
|
-
|
|
134
|
+
yield* forEachDeclarations(ts, prop.expression, ast, ctx);
|
|
172
135
|
}
|
|
173
136
|
// fix https://github.com/vuejs/language-tools/issues/4604
|
|
174
137
|
else if (ts.isFunctionLike(prop) && prop.body) {
|
|
175
|
-
|
|
138
|
+
yield* forEachDeclarationsInFunction(ts, prop, ast, ctx);
|
|
176
139
|
}
|
|
177
140
|
}
|
|
178
141
|
}
|
|
179
142
|
// fix https://github.com/vuejs/language-tools/issues/1422
|
|
180
143
|
else if (ts.isTypeNode(node)) {
|
|
181
|
-
|
|
144
|
+
yield* forEachDeclarationsInTypeNode(ts, node);
|
|
182
145
|
}
|
|
183
|
-
else {
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
ts.forEachChild(node, node => walkIdentifiers(ts, node, ast, cb, ctx, blockVars));
|
|
189
|
-
if (ts.isBlock(node)) {
|
|
190
|
-
for (const varName of blockVars) {
|
|
191
|
-
ctx.removeLocalVariable(varName);
|
|
192
|
-
}
|
|
146
|
+
else if (ts.isBlock(node)) {
|
|
147
|
+
const endScope = ctx.startScope();
|
|
148
|
+
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
|
149
|
+
yield* forEachDeclarations(ts, child, ast, ctx);
|
|
193
150
|
}
|
|
194
|
-
|
|
151
|
+
endScope();
|
|
195
152
|
}
|
|
196
|
-
|
|
197
|
-
for (const
|
|
198
|
-
ctx
|
|
153
|
+
else {
|
|
154
|
+
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
|
155
|
+
yield* forEachDeclarations(ts, child, ast, ctx);
|
|
199
156
|
}
|
|
200
157
|
}
|
|
201
158
|
}
|
|
202
|
-
function
|
|
159
|
+
function* forEachDeclarationsInBinding(ts, node, ast, ctx) {
|
|
203
160
|
if ('type' in node && node.type) {
|
|
204
|
-
|
|
161
|
+
yield* forEachDeclarationsInTypeNode(ts, node.type);
|
|
205
162
|
}
|
|
206
163
|
if (!ts.isIdentifier(node.name)) {
|
|
207
|
-
|
|
164
|
+
yield* forEachDeclarations(ts, node.name, ast, ctx);
|
|
208
165
|
}
|
|
209
166
|
if (node.initializer) {
|
|
210
|
-
|
|
167
|
+
yield* forEachDeclarations(ts, node.initializer, ast, ctx);
|
|
211
168
|
}
|
|
212
169
|
}
|
|
213
|
-
function
|
|
214
|
-
const
|
|
170
|
+
function* forEachDeclarationsInFunction(ts, node, ast, ctx) {
|
|
171
|
+
const endScope = ctx.startScope();
|
|
215
172
|
for (const param of node.parameters) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
for (const varName of functionArgs) {
|
|
220
|
-
ctx.addLocalVariable(varName);
|
|
173
|
+
ctx.declare(...(0, collectBindings_1.collectBindingNames)(ts, param.name, ast));
|
|
174
|
+
yield* forEachDeclarationsInBinding(ts, param, ast, ctx);
|
|
221
175
|
}
|
|
222
176
|
if (node.body) {
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
for (const varName of functionArgs) {
|
|
226
|
-
ctx.removeLocalVariable(varName);
|
|
177
|
+
yield* forEachDeclarations(ts, node.body, ast, ctx);
|
|
227
178
|
}
|
|
179
|
+
endScope();
|
|
228
180
|
}
|
|
229
|
-
function
|
|
181
|
+
function* forEachDeclarationsInTypeNode(ts, node) {
|
|
230
182
|
if (ts.isTypeQueryNode(node)) {
|
|
231
183
|
let id = node.exprName;
|
|
232
184
|
while (!ts.isIdentifier(id)) {
|
|
233
185
|
id = id.left;
|
|
234
186
|
}
|
|
235
|
-
|
|
187
|
+
yield [id, false];
|
|
236
188
|
}
|
|
237
189
|
else {
|
|
238
|
-
|
|
190
|
+
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
|
191
|
+
yield* forEachDeclarationsInTypeNode(ts, child);
|
|
192
|
+
}
|
|
239
193
|
}
|
|
240
194
|
}
|
|
241
|
-
function shouldIdentifierSkipped(ctx, text
|
|
242
|
-
return ctx.
|
|
195
|
+
function shouldIdentifierSkipped(ctx, text) {
|
|
196
|
+
return ctx.scopes.some(scope => scope.has(text))
|
|
243
197
|
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
|
244
198
|
|| (0, shared_1.isGloballyAllowed)(text)
|
|
245
199
|
|| isLiteralWhitelisted(text)
|
|
246
200
|
|| text === 'require'
|
|
247
|
-
|| text.startsWith('__VLS_')
|
|
248
|
-
|| destructuredPropNames?.has(text);
|
|
201
|
+
|| text.startsWith('__VLS_');
|
|
249
202
|
}
|
|
250
203
|
//# sourceMappingURL=interpolation.js.map
|
|
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateObjectProperty = generateObjectProperty;
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
+
const boundary_1 = require("../utils/boundary");
|
|
6
7
|
const camelized_1 = require("../utils/camelized");
|
|
7
8
|
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
8
|
-
const wrapWith_1 = require("../utils/wrapWith");
|
|
9
9
|
const interpolation_1 = require("./interpolation");
|
|
10
10
|
function* generateObjectProperty(options, ctx, code, offset, features, shouldCamelize = false, shouldBeConstant = false) {
|
|
11
11
|
if (code.startsWith('[') && code.endsWith(']')) {
|
|
12
12
|
if (shouldBeConstant) {
|
|
13
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
13
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, features, code.slice(1, -1), offset + 1, `[__VLS_tryAsConstant(`, `)]`);
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
16
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, features, code, offset);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
else if (shouldCamelize) {
|
|
@@ -21,7 +21,11 @@ function* generateObjectProperty(options, ctx, code, offset, features, shouldCam
|
|
|
21
21
|
yield* (0, camelized_1.generateCamelized)(code, 'template', offset, features);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
|
|
24
|
+
const token = yield* (0, boundary_1.startBoundary)('template', offset, features);
|
|
25
|
+
yield `'`;
|
|
26
|
+
yield* (0, camelized_1.generateCamelized)(code, 'template', offset, { __combineToken: token });
|
|
27
|
+
yield `'`;
|
|
28
|
+
yield (0, boundary_1.endBoundary)(token, offset + code.length);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
else {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Code, VueCodeInformation } from '../../types';
|
|
2
2
|
import type { TemplateCodegenContext } from './context';
|
|
3
3
|
import type { TemplateCodegenOptions } from './index';
|
|
4
|
-
export declare function generatePropertyAccess(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset
|
|
4
|
+
export declare function generatePropertyAccess(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset: number, features: VueCodeInformation): Generator<Code>;
|
|
@@ -5,14 +5,12 @@ const utils_1 = require("../utils");
|
|
|
5
5
|
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
6
6
|
const interpolation_1 = require("./interpolation");
|
|
7
7
|
function* generatePropertyAccess(options, ctx, code, offset, features) {
|
|
8
|
-
if (
|
|
9
|
-
yield
|
|
10
|
-
yield offset !== undefined && features
|
|
11
|
-
? [code, 'template', offset, features]
|
|
12
|
-
: code;
|
|
8
|
+
if (code.startsWith('[') && code.endsWith(']')) {
|
|
9
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, features, code, offset);
|
|
13
10
|
}
|
|
14
|
-
else if (
|
|
15
|
-
yield
|
|
11
|
+
else if (utils_1.identifierRegex.test(code)) {
|
|
12
|
+
yield `.`;
|
|
13
|
+
yield [code, 'template', offset, features];
|
|
16
14
|
}
|
|
17
15
|
else {
|
|
18
16
|
yield `[`;
|