@vue/language-core 2.0.13 → 2.0.14
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 +1 -1
- package/index.js +1 -1
- package/lib/codegen/common.d.ts +11 -0
- package/lib/codegen/common.js +70 -0
- package/lib/codegen/script/component.d.ts +9 -0
- package/lib/codegen/script/component.js +101 -0
- package/lib/codegen/script/context.d.ts +25 -0
- package/lib/codegen/script/context.js +124 -0
- package/lib/{generators → codegen/script}/globalTypes.d.ts +1 -1
- package/lib/codegen/script/globalTypes.js +135 -0
- package/lib/codegen/script/index.d.ts +33 -0
- package/lib/codegen/script/index.js +127 -0
- package/lib/codegen/script/internalComponent.d.ts +5 -0
- package/lib/codegen/script/internalComponent.js +58 -0
- package/lib/codegen/script/scriptSetup.d.ts +6 -0
- package/lib/codegen/script/scriptSetup.js +338 -0
- package/lib/codegen/script/src.d.ts +2 -0
- package/lib/codegen/script/src.js +52 -0
- package/lib/codegen/script/template.d.ts +5 -0
- package/lib/codegen/script/template.js +193 -0
- package/lib/codegen/template/camelized.d.ts +2 -0
- package/lib/codegen/template/camelized.js +32 -0
- package/lib/codegen/template/context.d.ts +44 -0
- package/lib/codegen/template/context.js +171 -0
- package/lib/codegen/template/element.d.ts +7 -0
- package/lib/codegen/template/element.js +325 -0
- package/lib/codegen/template/elementChildren.d.ts +5 -0
- package/lib/codegen/template/elementChildren.js +21 -0
- package/lib/codegen/template/elementDirectives.d.ts +5 -0
- package/lib/codegen/template/elementDirectives.js +46 -0
- package/lib/codegen/template/elementEvents.d.ts +7 -0
- package/lib/codegen/template/elementEvents.js +141 -0
- package/lib/codegen/template/elementProps.d.ts +5 -0
- package/lib/codegen/template/elementProps.js +250 -0
- package/lib/codegen/template/index.d.ts +60 -0
- package/lib/codegen/template/index.js +217 -0
- package/lib/codegen/template/interpolation.d.ts +6 -0
- package/lib/{utils/transform.js → codegen/template/interpolation.js} +76 -46
- package/lib/codegen/template/objectProperty.d.ts +4 -0
- package/lib/codegen/template/objectProperty.js +31 -0
- package/lib/codegen/template/propertyAccess.d.ts +4 -0
- package/lib/codegen/template/propertyAccess.js +24 -0
- package/lib/codegen/template/slotOutlet.d.ts +5 -0
- package/lib/codegen/template/slotOutlet.js +72 -0
- package/lib/codegen/template/stringLiteralKey.d.ts +2 -0
- package/lib/codegen/template/stringLiteralKey.js +14 -0
- package/lib/codegen/template/templateChild.d.ts +7 -0
- package/lib/codegen/template/templateChild.js +156 -0
- package/lib/codegen/template/vFor.d.ts +12 -0
- package/lib/codegen/template/vFor.js +69 -0
- package/lib/codegen/template/vIf.d.ts +5 -0
- package/lib/codegen/template/vIf.js +53 -0
- package/lib/languageModule.d.ts +3 -3
- package/lib/languageModule.js +2 -3
- package/lib/plugins/shared.d.ts +2 -0
- package/lib/plugins/shared.js +12 -0
- package/lib/plugins/vue-sfc-customblocks.js +2 -2
- package/lib/plugins/vue-sfc-scripts.js +2 -3
- package/lib/plugins/vue-sfc-styles.js +3 -3
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-template-inline-css.js +34 -2
- package/lib/plugins/vue-template-inline-ts.js +10 -8
- package/lib/plugins/vue-tsx.d.ts +42 -5
- package/lib/plugins/vue-tsx.js +38 -28
- package/lib/types.d.ts +1 -3
- package/lib/utils/ts.js +0 -29
- package/lib/virtualFile/computedFiles.d.ts +1 -1
- package/lib/virtualFile/computedFiles.js +22 -12
- package/lib/virtualFile/computedMappings.js +3 -3
- package/lib/virtualFile/computedSfc.js +22 -1
- package/lib/virtualFile/embeddedFile.d.ts +2 -3
- package/lib/virtualFile/embeddedFile.js +1 -2
- package/lib/virtualFile/vueFile.d.ts +3 -5
- package/lib/virtualFile/vueFile.js +6 -8
- package/package.json +3 -3
- package/lib/generators/globalTypes.js +0 -135
- package/lib/generators/inlineCss.d.ts +0 -3
- package/lib/generators/inlineCss.js +0 -37
- package/lib/generators/script.d.ts +0 -13
- package/lib/generators/script.js +0 -981
- package/lib/generators/template.d.ts +0 -19
- package/lib/generators/template.js +0 -1578
- package/lib/generators/utils.d.ts +0 -5
- package/lib/generators/utils.js +0 -54
- package/lib/utils/transform.d.ts +0 -8
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type { Code, VueCodeInformation, VueCompilerOptions } from '../../types';
|
|
3
|
+
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateInterpolation(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, _code: string, astHolder: any, start: number | undefined, data: VueCodeInformation | (() => VueCodeInformation) | undefined, prefix: string, suffix: string): Generator<Code>;
|
|
6
|
+
export declare function forEachInterpolationSegment(ts: typeof import('typescript'), vueOptions: VueCompilerOptions, ctx: TemplateCodegenContext, code: string, offset: number | undefined, ast: ts.SourceFile): Generator<[fragment: string, offset: number | undefined, isJustForErrorMapping?: boolean]>;
|
|
@@ -1,12 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.forEachInterpolationSegment = exports.generateInterpolation = void 0;
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
|
-
const scriptSetupRanges_1 = require("
|
|
6
|
-
|
|
5
|
+
const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
function* generateInterpolation(options, ctx, _code, astHolder, start, data, prefix, suffix) {
|
|
8
|
+
const code = prefix + _code + suffix;
|
|
9
|
+
const ast = (0, common_1.createTsAst)(options.ts, astHolder, code);
|
|
10
|
+
const vars = [];
|
|
11
|
+
for (let [section, offset, onlyError] of forEachInterpolationSegment(options.ts, options.vueCompilerOptions, ctx, code, start !== undefined ? start - prefix.length : undefined, ast)) {
|
|
12
|
+
if (offset === undefined) {
|
|
13
|
+
yield section;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
offset -= prefix.length;
|
|
17
|
+
let addSuffix = '';
|
|
18
|
+
const overLength = offset + section.length - _code.length;
|
|
19
|
+
if (overLength > 0) {
|
|
20
|
+
addSuffix = section.substring(section.length - overLength);
|
|
21
|
+
section = section.substring(0, section.length - overLength);
|
|
22
|
+
}
|
|
23
|
+
if (offset < 0) {
|
|
24
|
+
yield section.substring(0, -offset);
|
|
25
|
+
section = section.substring(-offset);
|
|
26
|
+
offset = 0;
|
|
27
|
+
}
|
|
28
|
+
if (start !== undefined && data !== undefined) {
|
|
29
|
+
yield [
|
|
30
|
+
section,
|
|
31
|
+
'template',
|
|
32
|
+
start + offset,
|
|
33
|
+
onlyError
|
|
34
|
+
? ctx.codeFeatures.verification
|
|
35
|
+
: typeof data === 'function' ? data() : data,
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
yield section;
|
|
40
|
+
}
|
|
41
|
+
yield addSuffix;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (start !== undefined) {
|
|
45
|
+
for (const v of vars) {
|
|
46
|
+
v.offset = start + v.offset - prefix.length;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.generateInterpolation = generateInterpolation;
|
|
51
|
+
function* forEachInterpolationSegment(ts, vueOptions, ctx, code, offset, ast) {
|
|
52
|
+
let ctxVars = [];
|
|
7
53
|
const varCb = (id, isShorthand) => {
|
|
8
54
|
const text = (0, scriptSetupRanges_1.getNodeText)(ts, id, ast);
|
|
9
|
-
if (
|
|
55
|
+
if (ctx.hasLocalVariable(text) ||
|
|
10
56
|
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
|
11
57
|
(0, shared_1.isGloballyWhitelisted)(text) ||
|
|
12
58
|
text === 'require' ||
|
|
@@ -19,10 +65,15 @@ function* eachInterpolationSegment(ts, code, ast, localVars, identifiers, vueOpt
|
|
|
19
65
|
isShorthand: isShorthand,
|
|
20
66
|
offset: (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start,
|
|
21
67
|
});
|
|
22
|
-
|
|
68
|
+
if (offset !== undefined) {
|
|
69
|
+
ctx.accessGlobalVariable(text, offset + (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
ctx.accessGlobalVariable(text);
|
|
73
|
+
}
|
|
23
74
|
}
|
|
24
75
|
};
|
|
25
|
-
ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb,
|
|
76
|
+
ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb, ctx));
|
|
26
77
|
ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
|
|
27
78
|
if (ctxVars.length) {
|
|
28
79
|
if (ctxVars[0].isShorthand) {
|
|
@@ -87,8 +138,8 @@ function* eachInterpolationSegment(ts, code, ast, localVars, identifiers, vueOpt
|
|
|
87
138
|
yield [code, 0];
|
|
88
139
|
}
|
|
89
140
|
}
|
|
90
|
-
exports.
|
|
91
|
-
function walkIdentifiers(ts, node, ast, cb,
|
|
141
|
+
exports.forEachInterpolationSegment = forEachInterpolationSegment;
|
|
142
|
+
function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true) {
|
|
92
143
|
if (ts.isIdentifier(node)) {
|
|
93
144
|
cb(node, false);
|
|
94
145
|
}
|
|
@@ -96,31 +147,31 @@ function walkIdentifiers(ts, node, ast, cb, localVars, blockVars = [], isRoot =
|
|
|
96
147
|
cb(node.name, true);
|
|
97
148
|
}
|
|
98
149
|
else if (ts.isPropertyAccessExpression(node)) {
|
|
99
|
-
walkIdentifiers(ts, node.expression, ast, cb,
|
|
150
|
+
walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars, false);
|
|
100
151
|
}
|
|
101
152
|
else if (ts.isVariableDeclaration(node)) {
|
|
102
|
-
collectVars(ts, node.name, ast, blockVars);
|
|
153
|
+
(0, common_1.collectVars)(ts, node.name, ast, blockVars);
|
|
103
154
|
for (const varName of blockVars) {
|
|
104
|
-
|
|
155
|
+
ctx.addLocalVariable(varName);
|
|
105
156
|
}
|
|
106
157
|
if (node.initializer) {
|
|
107
|
-
walkIdentifiers(ts, node.initializer, ast, cb,
|
|
158
|
+
walkIdentifiers(ts, node.initializer, ast, cb, ctx, blockVars, false);
|
|
108
159
|
}
|
|
109
160
|
}
|
|
110
161
|
else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
111
162
|
const functionArgs = [];
|
|
112
163
|
for (const param of node.parameters) {
|
|
113
|
-
collectVars(ts, param.name, ast, functionArgs);
|
|
164
|
+
(0, common_1.collectVars)(ts, param.name, ast, functionArgs);
|
|
114
165
|
if (param.type) {
|
|
115
|
-
walkIdentifiers(ts, param.type, ast, cb,
|
|
166
|
+
walkIdentifiers(ts, param.type, ast, cb, ctx, blockVars, false);
|
|
116
167
|
}
|
|
117
168
|
}
|
|
118
169
|
for (const varName of functionArgs) {
|
|
119
|
-
|
|
170
|
+
ctx.addLocalVariable(varName);
|
|
120
171
|
}
|
|
121
|
-
walkIdentifiers(ts, node.body, ast, cb,
|
|
172
|
+
walkIdentifiers(ts, node.body, ast, cb, ctx, blockVars, false);
|
|
122
173
|
for (const varName of functionArgs) {
|
|
123
|
-
|
|
174
|
+
ctx.removeLocalVariable(varName);
|
|
124
175
|
}
|
|
125
176
|
}
|
|
126
177
|
else if (ts.isObjectLiteralExpression(node)) {
|
|
@@ -128,18 +179,18 @@ function walkIdentifiers(ts, node, ast, cb, localVars, blockVars = [], isRoot =
|
|
|
128
179
|
if (ts.isPropertyAssignment(prop)) {
|
|
129
180
|
// fix https://github.com/vuejs/language-tools/issues/1176
|
|
130
181
|
if (ts.isComputedPropertyName(prop.name)) {
|
|
131
|
-
walkIdentifiers(ts, prop.name.expression, ast, cb,
|
|
182
|
+
walkIdentifiers(ts, prop.name.expression, ast, cb, ctx, blockVars, false);
|
|
132
183
|
}
|
|
133
|
-
walkIdentifiers(ts, prop.initializer, ast, cb,
|
|
184
|
+
walkIdentifiers(ts, prop.initializer, ast, cb, ctx, blockVars, false);
|
|
134
185
|
}
|
|
135
186
|
// fix https://github.com/vuejs/language-tools/issues/1156
|
|
136
187
|
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
137
|
-
walkIdentifiers(ts, prop, ast, cb,
|
|
188
|
+
walkIdentifiers(ts, prop, ast, cb, ctx, blockVars, false);
|
|
138
189
|
}
|
|
139
190
|
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
140
191
|
else if (ts.isSpreadAssignment(prop)) {
|
|
141
192
|
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
|
142
|
-
walkIdentifiers(ts, prop.expression, ast, cb,
|
|
193
|
+
walkIdentifiers(ts, prop.expression, ast, cb, ctx, blockVars, false);
|
|
143
194
|
}
|
|
144
195
|
}
|
|
145
196
|
}
|
|
@@ -152,17 +203,17 @@ function walkIdentifiers(ts, node, ast, cb, localVars, blockVars = [], isRoot =
|
|
|
152
203
|
if (ts.isBlock(node)) {
|
|
153
204
|
blockVars = [];
|
|
154
205
|
}
|
|
155
|
-
ts.forEachChild(node, node => walkIdentifiers(ts, node, ast, cb,
|
|
206
|
+
ts.forEachChild(node, node => walkIdentifiers(ts, node, ast, cb, ctx, blockVars, false));
|
|
156
207
|
if (ts.isBlock(node)) {
|
|
157
208
|
for (const varName of blockVars) {
|
|
158
|
-
|
|
209
|
+
ctx.removeLocalVariable(varName);
|
|
159
210
|
}
|
|
160
211
|
}
|
|
161
212
|
blockVars = _blockVars;
|
|
162
213
|
}
|
|
163
214
|
if (isRoot) {
|
|
164
215
|
for (const varName of blockVars) {
|
|
165
|
-
|
|
216
|
+
ctx.removeLocalVariable(varName);
|
|
166
217
|
}
|
|
167
218
|
}
|
|
168
219
|
}
|
|
@@ -174,25 +225,4 @@ function walkIdentifiersInTypeReference(ts, node, cb) {
|
|
|
174
225
|
ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
|
|
175
226
|
}
|
|
176
227
|
}
|
|
177
|
-
|
|
178
|
-
if (ts.isIdentifier(node)) {
|
|
179
|
-
result.push((0, scriptSetupRanges_1.getNodeText)(ts, node, ast));
|
|
180
|
-
}
|
|
181
|
-
else if (ts.isObjectBindingPattern(node)) {
|
|
182
|
-
for (const el of node.elements) {
|
|
183
|
-
collectVars(ts, el.name, ast, result);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
else if (ts.isArrayBindingPattern(node)) {
|
|
187
|
-
for (const el of node.elements) {
|
|
188
|
-
if (ts.isBindingElement(el)) {
|
|
189
|
-
collectVars(ts, el.name, ast, result);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
ts.forEachChild(node, node => collectVars(ts, node, ast, result));
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.collectVars = collectVars;
|
|
198
|
-
//# sourceMappingURL=transform.js.map
|
|
228
|
+
//# sourceMappingURL=interpolation.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
+
import type { TemplateCodegenContext } from './context';
|
|
3
|
+
import type { TemplateCodegenOptions } from './index';
|
|
4
|
+
export declare function generateObjectProperty(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset: number, features: VueCodeInformation, astHolder?: any, shouldCamelize?: boolean): Generator<Code>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateObjectProperty = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const camelized_1 = require("./camelized");
|
|
7
|
+
const interpolation_1 = require("./interpolation");
|
|
8
|
+
const stringLiteralKey_1 = require("./stringLiteralKey");
|
|
9
|
+
function* generateObjectProperty(options, ctx, code, offset, features, astHolder, shouldCamelize = false) {
|
|
10
|
+
if (code.startsWith('[') && code.endsWith(']') && astHolder) {
|
|
11
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, code, astHolder, offset, features, '', '');
|
|
12
|
+
}
|
|
13
|
+
else if (shouldCamelize) {
|
|
14
|
+
if (common_1.variableNameRegex.test((0, shared_1.camelize)(code))) {
|
|
15
|
+
yield* (0, camelized_1.generateCamelized)(code, offset, features);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
yield* (0, common_1.wrapWith)(offset, offset + code.length, features, `"`, ...(0, camelized_1.generateCamelized)(code, offset, common_1.combineLastMapping), `"`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (common_1.variableNameRegex.test(code)) {
|
|
23
|
+
yield [code, 'template', offset, features];
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(code, offset, features);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.generateObjectProperty = generateObjectProperty;
|
|
31
|
+
//# sourceMappingURL=objectProperty.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
+
import type { TemplateCodegenContext } from './context';
|
|
3
|
+
import type { TemplateCodegenOptions } from './index';
|
|
4
|
+
export declare function generatePropertyAccess(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset?: number, features?: VueCodeInformation, astHolder?: any): Generator<Code>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generatePropertyAccess = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
const interpolation_1 = require("./interpolation");
|
|
6
|
+
const stringLiteralKey_1 = require("./stringLiteralKey");
|
|
7
|
+
function* generatePropertyAccess(options, ctx, code, offset, features, astHolder) {
|
|
8
|
+
if (!options.compilerOptions.noPropertyAccessFromIndexSignature && common_1.variableNameRegex.test(code)) {
|
|
9
|
+
yield `.`;
|
|
10
|
+
yield offset !== undefined && features
|
|
11
|
+
? [code, 'template', offset, features]
|
|
12
|
+
: code;
|
|
13
|
+
}
|
|
14
|
+
else if (code.startsWith('[') && code.endsWith(']')) {
|
|
15
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, code, astHolder, offset, features, '', '');
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
yield `[`;
|
|
19
|
+
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(code, offset, features);
|
|
20
|
+
yield `]`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.generatePropertyAccess = generatePropertyAccess;
|
|
24
|
+
//# sourceMappingURL=propertyAccess.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
|
+
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateSlotOutlet(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.SlotOutletNode, currentElement: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSlotOutlet = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const elementChildren_1 = require("./elementChildren");
|
|
7
|
+
const elementProps_1 = require("./elementProps");
|
|
8
|
+
const interpolation_1 = require("./interpolation");
|
|
9
|
+
function* generateSlotOutlet(options, ctx, node, currentElement, componentCtxVar) {
|
|
10
|
+
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
|
11
|
+
const varSlot = ctx.getInternalVariable();
|
|
12
|
+
const nameProp = node.props.find(prop => {
|
|
13
|
+
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
14
|
+
return prop.name === 'name';
|
|
15
|
+
}
|
|
16
|
+
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
17
|
+
&& prop.name === 'bind'
|
|
18
|
+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
19
|
+
return prop.arg.content === 'name';
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
if (options.hasDefineSlots) {
|
|
23
|
+
yield `__VLS_normalizeSlot(`;
|
|
24
|
+
yield* (0, common_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, common_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value
|
|
25
|
+
? `'${nameProp.value.content}'`
|
|
26
|
+
: nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
27
|
+
? nameProp.exp.content
|
|
28
|
+
: `('default' as const)`), `]`);
|
|
29
|
+
yield `)?.(`;
|
|
30
|
+
yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${common_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true), `}`);
|
|
31
|
+
yield `)${common_1.endOfLine}`;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
yield `var ${varSlot} = {${common_1.newLine}`;
|
|
36
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
|
|
37
|
+
yield `}${common_1.endOfLine}`;
|
|
38
|
+
}
|
|
39
|
+
if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
40
|
+
&& nameProp.value) {
|
|
41
|
+
ctx.slots.push({
|
|
42
|
+
name: nameProp.value.content,
|
|
43
|
+
loc: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
|
|
44
|
+
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
|
45
|
+
varName: varSlot,
|
|
46
|
+
nodeLoc: node.loc,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
50
|
+
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
51
|
+
const slotExpVar = ctx.getInternalVariable();
|
|
52
|
+
yield `var ${slotExpVar} = `;
|
|
53
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, nameProp.exp.content, nameProp.exp, nameProp.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
|
54
|
+
yield ` as const${common_1.endOfLine}`;
|
|
55
|
+
ctx.dynamicSlots.push({
|
|
56
|
+
expVar: slotExpVar,
|
|
57
|
+
varName: varSlot,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
ctx.slots.push({
|
|
62
|
+
name: 'default',
|
|
63
|
+
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
|
64
|
+
varName: varSlot,
|
|
65
|
+
nodeLoc: node.loc,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
yield* ctx.generateAutoImportCompletion();
|
|
69
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentElement, componentCtxVar);
|
|
70
|
+
}
|
|
71
|
+
exports.generateSlotOutlet = generateSlotOutlet;
|
|
72
|
+
//# sourceMappingURL=slotOutlet.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateStringLiteralKey = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
function* generateStringLiteralKey(code, offset, info) {
|
|
6
|
+
if (offset === undefined || !info) {
|
|
7
|
+
yield `"${code}"`;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
yield* (0, common_1.wrapWith)(offset, offset + code.length, info, `"`, [code, 'template', offset, common_1.combineLastMapping], `"`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.generateStringLiteralKey = generateStringLiteralKey;
|
|
14
|
+
//# sourceMappingURL=stringLiteralKey.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
|
+
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, currentElement: CompilerDOM.ElementNode | undefined, prevNode: CompilerDOM.TemplateChildNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
6
|
+
export declare function getVForNode(node: CompilerDOM.ElementNode): CompilerDOM.ForNode | undefined;
|
|
7
|
+
export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseInterpolationNode = exports.getVForNode = exports.generateTemplateChild = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const element_1 = require("./element");
|
|
7
|
+
const interpolation_1 = require("./interpolation");
|
|
8
|
+
const slotOutlet_1 = require("./slotOutlet");
|
|
9
|
+
const vFor_1 = require("./vFor");
|
|
10
|
+
const vIf_1 = require("./vIf");
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const transformContext = {
|
|
13
|
+
onError: () => { },
|
|
14
|
+
helperString: str => str.toString(),
|
|
15
|
+
replaceNode: () => { },
|
|
16
|
+
cacheHandlers: false,
|
|
17
|
+
prefixIdentifiers: false,
|
|
18
|
+
scopes: {
|
|
19
|
+
vFor: 0,
|
|
20
|
+
vOnce: 0,
|
|
21
|
+
vPre: 0,
|
|
22
|
+
vSlot: 0,
|
|
23
|
+
},
|
|
24
|
+
expressionPlugins: ['typescript'],
|
|
25
|
+
};
|
|
26
|
+
function* generateTemplateChild(options, ctx, node, currentElement, prevNode, componentCtxVar) {
|
|
27
|
+
if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
28
|
+
const commentText = prevNode.content.trim().split(' ')[0];
|
|
29
|
+
if (commentText.match(/^@vue-skip\b[\s\S]*/)) {
|
|
30
|
+
yield `// @vue-skip${common_1.newLine}`;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
else if (commentText.match(/^@vue-ignore\b[\s\S]*/)) {
|
|
34
|
+
yield* ctx.ignoreError();
|
|
35
|
+
}
|
|
36
|
+
else if (commentText.match(/^@vue-expect-error\b[\s\S]*/)) {
|
|
37
|
+
yield* ctx.expectError(prevNode);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
41
|
+
let prev;
|
|
42
|
+
for (const childNode of node.children) {
|
|
43
|
+
yield* generateTemplateChild(options, ctx, childNode, currentElement, prev, componentCtxVar);
|
|
44
|
+
prev = childNode;
|
|
45
|
+
}
|
|
46
|
+
yield* ctx.resetDirectiveComments('end of root');
|
|
47
|
+
}
|
|
48
|
+
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
49
|
+
const vForNode = getVForNode(node);
|
|
50
|
+
const vIfNode = getVIfNode(node);
|
|
51
|
+
if (vForNode) {
|
|
52
|
+
yield* (0, vFor_1.generateVFor)(options, ctx, vForNode, currentElement, componentCtxVar);
|
|
53
|
+
}
|
|
54
|
+
else if (vIfNode) {
|
|
55
|
+
yield* (0, vIf_1.generateVIf)(options, ctx, vIfNode, currentElement, componentCtxVar);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
|
|
59
|
+
yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node, currentElement, componentCtxVar);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
yield* (0, element_1.generateElement)(options, ctx, node, currentElement, componentCtxVar);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
67
|
+
// {{ var }}
|
|
68
|
+
yield* generateTemplateChild(options, ctx, node.content, currentElement, undefined, componentCtxVar);
|
|
69
|
+
}
|
|
70
|
+
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
71
|
+
// {{ ... }} {{ ... }}
|
|
72
|
+
for (const childNode of node.children) {
|
|
73
|
+
if (typeof childNode === 'object') {
|
|
74
|
+
yield* generateTemplateChild(options, ctx, childNode, currentElement, undefined, componentCtxVar);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
79
|
+
// {{ ... }}
|
|
80
|
+
const [content, start] = parseInterpolationNode(node, options.template.content);
|
|
81
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, content, node.content.loc, start, ctx.codeFeatures.all, `(`, `)${common_1.endOfLine}`);
|
|
82
|
+
yield* ctx.resetDirectiveComments('end of INTERPOLATION');
|
|
83
|
+
}
|
|
84
|
+
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
85
|
+
// v-if / v-else-if / v-else
|
|
86
|
+
yield* (0, vIf_1.generateVIf)(options, ctx, node, currentElement, componentCtxVar);
|
|
87
|
+
}
|
|
88
|
+
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
|
89
|
+
// v-for
|
|
90
|
+
yield* (0, vFor_1.generateVFor)(options, ctx, node, currentElement, componentCtxVar);
|
|
91
|
+
}
|
|
92
|
+
else if (node.type === CompilerDOM.NodeTypes.TEXT) {
|
|
93
|
+
// not needed progress
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.generateTemplateChild = generateTemplateChild;
|
|
97
|
+
// TODO: track https://github.com/vuejs/vue-next/issues/3498
|
|
98
|
+
function getVForNode(node) {
|
|
99
|
+
const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
100
|
+
&& prop.name === 'for');
|
|
101
|
+
if (forDirective) {
|
|
102
|
+
let forNode;
|
|
103
|
+
CompilerDOM.processFor(node, forDirective, transformContext, _forNode => {
|
|
104
|
+
forNode = { ..._forNode };
|
|
105
|
+
return undefined;
|
|
106
|
+
});
|
|
107
|
+
if (forNode) {
|
|
108
|
+
forNode.children = [{
|
|
109
|
+
...node,
|
|
110
|
+
props: node.props.filter(prop => prop !== forDirective),
|
|
111
|
+
}];
|
|
112
|
+
return forNode;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.getVForNode = getVForNode;
|
|
117
|
+
function getVIfNode(node) {
|
|
118
|
+
const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
119
|
+
&& prop.name === 'if');
|
|
120
|
+
if (forDirective) {
|
|
121
|
+
let ifNode;
|
|
122
|
+
CompilerDOM.processIf(node, forDirective, transformContext, _ifNode => {
|
|
123
|
+
ifNode = { ..._ifNode };
|
|
124
|
+
return undefined;
|
|
125
|
+
});
|
|
126
|
+
if (ifNode) {
|
|
127
|
+
for (const branch of ifNode.branches) {
|
|
128
|
+
branch.children = [{
|
|
129
|
+
...node,
|
|
130
|
+
props: node.props.filter(prop => prop !== forDirective),
|
|
131
|
+
}];
|
|
132
|
+
}
|
|
133
|
+
return ifNode;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function parseInterpolationNode(node, template) {
|
|
138
|
+
let content = node.content.loc.source;
|
|
139
|
+
let start = node.content.loc.start.offset;
|
|
140
|
+
let leftCharacter;
|
|
141
|
+
let rightCharacter;
|
|
142
|
+
// fix https://github.com/vuejs/language-tools/issues/1787
|
|
143
|
+
while ((leftCharacter = template.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
|
|
144
|
+
start--;
|
|
145
|
+
content = leftCharacter + content;
|
|
146
|
+
}
|
|
147
|
+
while ((rightCharacter = template.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
|
|
148
|
+
content = content + rightCharacter;
|
|
149
|
+
}
|
|
150
|
+
return [
|
|
151
|
+
content,
|
|
152
|
+
start,
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
exports.parseInterpolationNode = parseInterpolationNode;
|
|
156
|
+
//# sourceMappingURL=templateChild.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
|
+
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateVFor(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ForNode, currentElement: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
6
|
+
export declare function parseVForNode(node: CompilerDOM.ForNode): {
|
|
7
|
+
leftExpressionRange: {
|
|
8
|
+
start: number;
|
|
9
|
+
end: number;
|
|
10
|
+
} | undefined;
|
|
11
|
+
leftExpressionText: string | undefined;
|
|
12
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseVForNode = exports.generateVFor = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const index_1 = require("./index");
|
|
7
|
+
const interpolation_1 = require("./interpolation");
|
|
8
|
+
const templateChild_1 = require("./templateChild");
|
|
9
|
+
function* generateVFor(options, ctx, node, currentElement, componentCtxVar) {
|
|
10
|
+
const { source } = node.parseResult;
|
|
11
|
+
const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
|
|
12
|
+
const forBlockVars = [];
|
|
13
|
+
yield `for (const [`;
|
|
14
|
+
if (leftExpressionRange && leftExpressionText) {
|
|
15
|
+
const collectAst = (0, common_1.createTsAst)(options.ts, node.parseResult, `const [${leftExpressionText}]`);
|
|
16
|
+
(0, common_1.collectVars)(options.ts, collectAst, collectAst, forBlockVars);
|
|
17
|
+
yield [
|
|
18
|
+
leftExpressionText,
|
|
19
|
+
'template',
|
|
20
|
+
leftExpressionRange.start,
|
|
21
|
+
ctx.codeFeatures.all,
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
yield `] of `;
|
|
25
|
+
if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
26
|
+
yield `__VLS_getVForSourceType(`;
|
|
27
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, source.content, source.loc, source.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
|
28
|
+
yield `!)`; // #3102
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
yield `{} as any`;
|
|
32
|
+
}
|
|
33
|
+
yield `) {${common_1.newLine}`;
|
|
34
|
+
if ((0, index_1.isFragment)(node)) {
|
|
35
|
+
yield* ctx.resetDirectiveComments('end of v-for start');
|
|
36
|
+
}
|
|
37
|
+
for (const varName of forBlockVars) {
|
|
38
|
+
ctx.addLocalVariable(varName);
|
|
39
|
+
}
|
|
40
|
+
let prev;
|
|
41
|
+
for (const childNode of node.children) {
|
|
42
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentElement, prev, componentCtxVar);
|
|
43
|
+
prev = childNode;
|
|
44
|
+
}
|
|
45
|
+
for (const varName of forBlockVars) {
|
|
46
|
+
ctx.removeLocalVariable(varName);
|
|
47
|
+
}
|
|
48
|
+
yield* ctx.generateAutoImportCompletion();
|
|
49
|
+
yield `}${common_1.newLine}`;
|
|
50
|
+
}
|
|
51
|
+
exports.generateVFor = generateVFor;
|
|
52
|
+
function parseVForNode(node) {
|
|
53
|
+
const { value, key, index } = node.parseResult;
|
|
54
|
+
const leftExpressionRange = (value || key || index)
|
|
55
|
+
? {
|
|
56
|
+
start: (value ?? key ?? index).loc.start.offset,
|
|
57
|
+
end: (index ?? key ?? value).loc.end.offset,
|
|
58
|
+
}
|
|
59
|
+
: undefined;
|
|
60
|
+
const leftExpressionText = leftExpressionRange
|
|
61
|
+
? node.loc.source.substring(leftExpressionRange.start - node.loc.start.offset, leftExpressionRange.end - node.loc.start.offset)
|
|
62
|
+
: undefined;
|
|
63
|
+
return {
|
|
64
|
+
leftExpressionRange,
|
|
65
|
+
leftExpressionText,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.parseVForNode = parseVForNode;
|
|
69
|
+
//# sourceMappingURL=vFor.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
|
+
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateVIf(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.IfNode, currentElement: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|