@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
|
@@ -5,12 +5,13 @@ const CompilerDOM = require("@vue/compiler-dom");
|
|
|
5
5
|
const shared_1 = require("../../utils/shared");
|
|
6
6
|
const codeFeatures_1 = require("../codeFeatures");
|
|
7
7
|
const inlayHints_1 = require("../inlayHints");
|
|
8
|
+
const names = require("../names");
|
|
8
9
|
const utils_1 = require("../utils");
|
|
9
|
-
const
|
|
10
|
-
const elementChildren_1 = require("./elementChildren");
|
|
10
|
+
const boundary_1 = require("../utils/boundary");
|
|
11
11
|
const elementProps_1 = require("./elementProps");
|
|
12
12
|
const interpolation_1 = require("./interpolation");
|
|
13
13
|
const propertyAccess_1 = require("./propertyAccess");
|
|
14
|
+
const templateChild_1 = require("./templateChild");
|
|
14
15
|
function* generateSlotOutlet(options, ctx, node) {
|
|
15
16
|
const [startTagOffset] = (0, shared_1.getElementTagOffsets)(node, options.template);
|
|
16
17
|
const startTagEndOffset = startTagOffset + node.tag.length;
|
|
@@ -29,12 +30,8 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
29
30
|
if (nameProp) {
|
|
30
31
|
let codes;
|
|
31
32
|
if (nameProp.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
source = source.slice(1, -1);
|
|
35
|
-
offset++;
|
|
36
|
-
}
|
|
37
|
-
codes = (0, propertyAccess_1.generatePropertyAccess)(options, ctx, source, offset, codeFeatures_1.codeFeatures.navigationAndVerification);
|
|
33
|
+
const [content, offset] = (0, shared_1.normalizeAttributeValue)(nameProp.value);
|
|
34
|
+
codes = (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, offset, codeFeatures_1.codeFeatures.navigationAndVerification);
|
|
38
35
|
}
|
|
39
36
|
else if (nameProp.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
40
37
|
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -47,18 +44,31 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
47
44
|
else {
|
|
48
45
|
codes = [`['default']`];
|
|
49
46
|
}
|
|
50
|
-
yield* (0,
|
|
47
|
+
const token = yield* (0, boundary_1.startBoundary)('template', nameProp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
48
|
+
yield options.slotsAssignName ?? names.slots;
|
|
49
|
+
yield* codes;
|
|
50
|
+
yield (0, boundary_1.endBoundary)(token, nameProp.loc.end.offset);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
yield* (0,
|
|
53
|
+
const token = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
54
|
+
yield `${options.slotsAssignName ?? names.slots}[`;
|
|
55
|
+
const token2 = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
56
|
+
yield `'default'`;
|
|
57
|
+
yield (0, boundary_1.endBoundary)(token2, startTagEndOffset);
|
|
58
|
+
yield `]`;
|
|
59
|
+
yield (0, boundary_1.endBoundary)(token, startTagEndOffset);
|
|
54
60
|
}
|
|
55
61
|
yield `)(`;
|
|
56
|
-
yield* (0,
|
|
62
|
+
const token = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
63
|
+
yield `{${utils_1.newLine}`;
|
|
64
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
|
|
65
|
+
yield `}`;
|
|
66
|
+
yield (0, boundary_1.endBoundary)(token, startTagEndOffset);
|
|
57
67
|
yield `)${utils_1.endOfLine}`;
|
|
58
68
|
}
|
|
59
69
|
else {
|
|
60
70
|
yield `var ${propsVar} = {${utils_1.newLine}`;
|
|
61
|
-
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), options.vueCompilerOptions.checkUnknownProps
|
|
71
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), options.vueCompilerOptions.checkUnknownProps);
|
|
62
72
|
yield `}${utils_1.endOfLine}`;
|
|
63
73
|
if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
64
74
|
&& nameProp.value) {
|
|
@@ -78,7 +88,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
78
88
|
}
|
|
79
89
|
const expVar = ctx.getInternalVariable();
|
|
80
90
|
yield `var ${expVar} = __VLS_tryAsConstant(`;
|
|
81
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
91
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset);
|
|
82
92
|
yield `)${utils_1.endOfLine}`;
|
|
83
93
|
ctx.dynamicSlots.push({
|
|
84
94
|
expVar: ctx.getHoistVariable(expVar),
|
|
@@ -94,6 +104,8 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
94
104
|
});
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
|
-
|
|
107
|
+
for (const child of node.children) {
|
|
108
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
|
109
|
+
}
|
|
98
110
|
}
|
|
99
111
|
//# sourceMappingURL=slotOutlet.js.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { TemplateCodegenOptions } from './index';
|
|
5
|
-
export declare function generateStyleScopedClassReferences(ctx: TemplateCodegenContext, withDot?: boolean): Generator<Code>;
|
|
6
|
-
export declare function collectStyleScopedClassReferences(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): void;
|
|
1
|
+
import type { Code, SfcBlock } from '../../types';
|
|
2
|
+
export declare const references: WeakMap<SfcBlock, [version: string, [className: string, offset: number][]]>;
|
|
3
|
+
export declare function generateStyleScopedClassReference(block: SfcBlock, className: string, offset: number, fullStart?: number): Generator<Code>;
|
|
@@ -1,162 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
|
-
const shared_1 = require("../../utils/shared");
|
|
3
|
+
exports.references = void 0;
|
|
4
|
+
exports.generateStyleScopedClassReference = generateStyleScopedClassReference;
|
|
7
5
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
6
|
const utils_1 = require("../utils");
|
|
7
|
+
const boundary_1 = require("../utils/boundary");
|
|
9
8
|
const escaped_1 = require("../utils/escaped");
|
|
10
|
-
const wrapWith_1 = require("../utils/wrapWith");
|
|
11
9
|
const classNameEscapeRegex = /([\\'])/;
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
// For language-service/lib/plugins/vue-scoped-class-links.ts usage
|
|
11
|
+
exports.references = new WeakMap();
|
|
12
|
+
function* generateStyleScopedClassReference(block, className, offset, fullStart = offset) {
|
|
13
|
+
if (!className) {
|
|
14
14
|
yield `/** @type {__VLS_StyleScopedClasses['`;
|
|
15
|
-
yield [
|
|
16
|
-
'',
|
|
17
|
-
'template',
|
|
18
|
-
offset,
|
|
19
|
-
codeFeatures_1.codeFeatures.additionalCompletion,
|
|
20
|
-
];
|
|
15
|
+
yield ['', 'template', offset, codeFeatures_1.codeFeatures.completion];
|
|
21
16
|
yield `']} */${utils_1.endOfLine}`;
|
|
17
|
+
return;
|
|
22
18
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
const cache = exports.references.get(block);
|
|
20
|
+
if (!cache || cache[0] !== block.content) {
|
|
21
|
+
const arr = [];
|
|
22
|
+
exports.references.set(block, [block.content, arr]);
|
|
23
|
+
arr.push([className, offset]);
|
|
27
24
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for (const prop of node.props) {
|
|
31
|
-
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
32
|
-
&& prop.name === 'class'
|
|
33
|
-
&& prop.value) {
|
|
34
|
-
if (options.template.lang === 'pug') {
|
|
35
|
-
const getClassOffset = Reflect.get(prop.value.loc.start, 'getClassOffset');
|
|
36
|
-
const content = prop.value.loc.source.slice(1, -1);
|
|
37
|
-
let startOffset = 1;
|
|
38
|
-
for (const className of content.split(' ')) {
|
|
39
|
-
if (className) {
|
|
40
|
-
ctx.scopedClasses.push({
|
|
41
|
-
source: 'template',
|
|
42
|
-
className,
|
|
43
|
-
offset: getClassOffset(startOffset),
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
startOffset += className.length + 1;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const [content, startOffset] = (0, utils_1.normalizeAttributeValue)(prop.value);
|
|
51
|
-
if (content) {
|
|
52
|
-
const classes = collectClasses(content, startOffset);
|
|
53
|
-
ctx.scopedClasses.push(...classes);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
ctx.emptyClassOffsets.push(startOffset);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
61
|
-
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
62
|
-
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
63
|
-
&& prop.arg.content === 'class') {
|
|
64
|
-
const content = '(' + prop.exp.content + ')';
|
|
65
|
-
const startOffset = prop.exp.loc.start.offset - 1;
|
|
66
|
-
const { ts } = options;
|
|
67
|
-
const ast = ts.createSourceFile('', content, 99);
|
|
68
|
-
const literals = [];
|
|
69
|
-
ts.forEachChild(ast, node => {
|
|
70
|
-
if (!ts.isExpressionStatement(node)
|
|
71
|
-
|| !ts.isParenthesizedExpression(node.expression)) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const { expression } = node.expression;
|
|
75
|
-
if (ts.isStringLiteralLike(expression)) {
|
|
76
|
-
literals.push(expression);
|
|
77
|
-
}
|
|
78
|
-
else if (ts.isArrayLiteralExpression(expression)) {
|
|
79
|
-
walkArrayLiteral(expression);
|
|
80
|
-
}
|
|
81
|
-
else if (ts.isObjectLiteralExpression(expression)) {
|
|
82
|
-
walkObjectLiteral(expression);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
for (const literal of literals) {
|
|
86
|
-
if (literal.text) {
|
|
87
|
-
const classes = collectClasses(literal.text, literal.end - literal.text.length - 1 + startOffset);
|
|
88
|
-
ctx.scopedClasses.push(...classes);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
ctx.emptyClassOffsets.push(literal.end - 1 + startOffset);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
function walkArrayLiteral(node) {
|
|
95
|
-
const { elements } = node;
|
|
96
|
-
for (const element of elements) {
|
|
97
|
-
if (ts.isStringLiteralLike(element)) {
|
|
98
|
-
literals.push(element);
|
|
99
|
-
}
|
|
100
|
-
else if (ts.isObjectLiteralExpression(element)) {
|
|
101
|
-
walkObjectLiteral(element);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function walkObjectLiteral(node) {
|
|
106
|
-
const { properties } = node;
|
|
107
|
-
for (const property of properties) {
|
|
108
|
-
if (ts.isPropertyAssignment(property)) {
|
|
109
|
-
const { name } = property;
|
|
110
|
-
if (ts.isIdentifier(name)) {
|
|
111
|
-
walkIdentifier(name);
|
|
112
|
-
}
|
|
113
|
-
else if (ts.isStringLiteral(name)) {
|
|
114
|
-
literals.push(name);
|
|
115
|
-
}
|
|
116
|
-
else if (ts.isComputedPropertyName(name)) {
|
|
117
|
-
const { expression } = name;
|
|
118
|
-
if (ts.isStringLiteralLike(expression)) {
|
|
119
|
-
literals.push(expression);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else if (ts.isShorthandPropertyAssignment(property)) {
|
|
124
|
-
walkIdentifier(property.name);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function walkIdentifier(node) {
|
|
129
|
-
const text = (0, shared_1.getNodeText)(ts, node, ast);
|
|
130
|
-
ctx.scopedClasses.push({
|
|
131
|
-
source: 'template',
|
|
132
|
-
className: text,
|
|
133
|
-
offset: node.end - text.length + startOffset,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function collectClasses(content, startOffset = 0) {
|
|
140
|
-
const classes = [];
|
|
141
|
-
let currentClassName = '';
|
|
142
|
-
let offset = 0;
|
|
143
|
-
for (const char of (content + ' ')) {
|
|
144
|
-
if (char.trim() === '') {
|
|
145
|
-
if (currentClassName !== '') {
|
|
146
|
-
classes.push({
|
|
147
|
-
source: 'template',
|
|
148
|
-
className: currentClassName,
|
|
149
|
-
offset: offset + startOffset,
|
|
150
|
-
});
|
|
151
|
-
offset += currentClassName.length;
|
|
152
|
-
currentClassName = '';
|
|
153
|
-
}
|
|
154
|
-
offset += char.length;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
currentClassName += char;
|
|
158
|
-
}
|
|
25
|
+
else {
|
|
26
|
+
cache[1].push([className, offset]);
|
|
159
27
|
}
|
|
160
|
-
|
|
28
|
+
yield `/** @type {__VLS_StyleScopedClasses[`;
|
|
29
|
+
const token = yield* (0, boundary_1.startBoundary)(block.name, fullStart, codeFeatures_1.codeFeatures.navigation);
|
|
30
|
+
yield `'`;
|
|
31
|
+
yield* (0, escaped_1.generateEscaped)(className, block.name, offset, codeFeatures_1.codeFeatures.navigationAndCompletion, classNameEscapeRegex);
|
|
32
|
+
yield `'`;
|
|
33
|
+
yield (0, boundary_1.endBoundary)(token, offset + className.length);
|
|
34
|
+
yield `]} */${utils_1.endOfLine}`;
|
|
161
35
|
}
|
|
162
36
|
//# sourceMappingURL=styleScopedClasses.js.map
|
|
@@ -3,5 +3,4 @@ import type { Code } from '../../types';
|
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
5
|
export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, enterNode?: boolean): Generator<Code>;
|
|
6
|
-
export declare function getVForNode(node: CompilerDOM.ElementNode): CompilerDOM.ForNode | undefined;
|
|
7
6
|
export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];
|
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateTemplateChild = generateTemplateChild;
|
|
4
|
-
exports.getVForNode = getVForNode;
|
|
5
4
|
exports.parseInterpolationNode = parseInterpolationNode;
|
|
6
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
7
6
|
const shared_1 = require("../../utils/shared");
|
|
8
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
9
8
|
const utils_1 = require("../utils");
|
|
10
9
|
const element_1 = require("./element");
|
|
11
|
-
const elementChildren_1 = require("./elementChildren");
|
|
12
10
|
const interpolation_1 = require("./interpolation");
|
|
13
11
|
const slotOutlet_1 = require("./slotOutlet");
|
|
14
12
|
const vFor_1 = require("./vFor");
|
|
15
13
|
const vIf_1 = require("./vIf");
|
|
16
14
|
const vSlot_1 = require("./vSlot");
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
const transformContext = {
|
|
19
|
-
onError: () => { },
|
|
20
|
-
helperString: str => str.toString(),
|
|
21
|
-
replaceNode: () => { },
|
|
22
|
-
cacheHandlers: false,
|
|
23
|
-
prefixIdentifiers: false,
|
|
24
|
-
scopes: {
|
|
25
|
-
vFor: 0,
|
|
26
|
-
vOnce: 0,
|
|
27
|
-
vPre: 0,
|
|
28
|
-
vSlot: 0,
|
|
29
|
-
},
|
|
30
|
-
expressionPlugins: ['typescript'],
|
|
31
|
-
};
|
|
32
15
|
function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
33
16
|
if (enterNode && !ctx.enter(node)) {
|
|
34
17
|
return;
|
|
@@ -41,18 +24,12 @@ function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
|
41
24
|
for (const item of collectSingleRootNodes(options, node.children)) {
|
|
42
25
|
ctx.singleRootNodes.add(item);
|
|
43
26
|
}
|
|
44
|
-
|
|
27
|
+
for (const child of node.children) {
|
|
28
|
+
yield* generateTemplateChild(options, ctx, child);
|
|
29
|
+
}
|
|
45
30
|
}
|
|
46
31
|
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
47
|
-
|
|
48
|
-
const vIfNode = getVIfNode(node);
|
|
49
|
-
if (vForNode) {
|
|
50
|
-
yield* (0, vFor_1.generateVFor)(options, ctx, vForNode);
|
|
51
|
-
}
|
|
52
|
-
else if (vIfNode) {
|
|
53
|
-
yield* (0, vIf_1.generateVIf)(options, ctx, vIfNode);
|
|
54
|
-
}
|
|
55
|
-
else if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
|
|
32
|
+
if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
|
|
56
33
|
yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node);
|
|
57
34
|
}
|
|
58
35
|
else {
|
|
@@ -79,12 +56,17 @@ function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
|
79
56
|
}
|
|
80
57
|
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
81
58
|
// {{ ... }} {{ ... }}
|
|
82
|
-
|
|
59
|
+
for (const child of node.children) {
|
|
60
|
+
if (typeof child !== 'object') {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
yield* generateTemplateChild(options, ctx, child, false);
|
|
64
|
+
}
|
|
83
65
|
}
|
|
84
66
|
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
85
67
|
// {{ ... }}
|
|
86
68
|
const [content, start] = parseInterpolationNode(node, options.template.content);
|
|
87
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
69
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, content, start, `(`, `)${utils_1.endOfLine}`);
|
|
88
70
|
}
|
|
89
71
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
90
72
|
// v-if / v-else-if / v-else
|
|
@@ -127,45 +109,6 @@ function* collectSingleRootNodes(options, children) {
|
|
|
127
109
|
yield* collectSingleRootNodes(options, child.children);
|
|
128
110
|
}
|
|
129
111
|
}
|
|
130
|
-
// TODO: track https://github.com/vuejs/vue-next/issues/3498
|
|
131
|
-
function getVForNode(node) {
|
|
132
|
-
const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
133
|
-
&& prop.name === 'for');
|
|
134
|
-
if (forDirective) {
|
|
135
|
-
let forNode;
|
|
136
|
-
CompilerDOM.processFor(node, forDirective, transformContext, _forNode => {
|
|
137
|
-
forNode = { ..._forNode };
|
|
138
|
-
return undefined;
|
|
139
|
-
});
|
|
140
|
-
if (forNode) {
|
|
141
|
-
forNode.children = [{
|
|
142
|
-
...node,
|
|
143
|
-
props: node.props.filter(prop => prop !== forDirective),
|
|
144
|
-
}];
|
|
145
|
-
return forNode;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function getVIfNode(node) {
|
|
150
|
-
const ifDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
151
|
-
&& prop.name === 'if');
|
|
152
|
-
if (ifDirective) {
|
|
153
|
-
let ifNode;
|
|
154
|
-
CompilerDOM.processIf(node, ifDirective, transformContext, _ifNode => {
|
|
155
|
-
ifNode = { ..._ifNode };
|
|
156
|
-
return undefined;
|
|
157
|
-
});
|
|
158
|
-
if (ifNode) {
|
|
159
|
-
for (const branch of ifNode.branches) {
|
|
160
|
-
branch.children = [{
|
|
161
|
-
...node,
|
|
162
|
-
props: node.props.filter(prop => prop !== ifDirective),
|
|
163
|
-
}];
|
|
164
|
-
}
|
|
165
|
-
return ifNode;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
112
|
function parseInterpolationNode(node, template) {
|
|
170
113
|
let start = node.content.loc.start.offset;
|
|
171
114
|
let end = node.content.loc.end.offset;
|
|
@@ -6,16 +6,16 @@ const CompilerDOM = require("@vue/compiler-dom");
|
|
|
6
6
|
const collectBindings_1 = require("../../utils/collectBindings");
|
|
7
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
|
-
const elementChildren_1 = require("./elementChildren");
|
|
10
9
|
const interpolation_1 = require("./interpolation");
|
|
10
|
+
const templateChild_1 = require("./templateChild");
|
|
11
11
|
function* generateVFor(options, ctx, node) {
|
|
12
12
|
const { source } = node.parseResult;
|
|
13
13
|
const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
|
|
14
|
-
const
|
|
14
|
+
const endScope = ctx.startScope();
|
|
15
15
|
yield `for (const [`;
|
|
16
16
|
if (leftExpressionRange && leftExpressionText) {
|
|
17
|
-
const collectAst = (0, utils_1.
|
|
18
|
-
|
|
17
|
+
const collectAst = (0, utils_1.getTypeScriptAST)(options.ts, options.template, `const [${leftExpressionText}]`);
|
|
18
|
+
ctx.declare(...(0, collectBindings_1.collectBindingNames)(options.ts, collectAst, collectAst));
|
|
19
19
|
yield [
|
|
20
20
|
leftExpressionText,
|
|
21
21
|
'template',
|
|
@@ -26,16 +26,13 @@ function* generateVFor(options, ctx, node) {
|
|
|
26
26
|
yield `] of `;
|
|
27
27
|
if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
28
28
|
yield `__VLS_getVForSourceType(`;
|
|
29
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
29
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, source.content, source.loc.start.offset, `(`, `)`);
|
|
30
30
|
yield `!)`; // #3102
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
yield `{} as any`;
|
|
34
34
|
}
|
|
35
35
|
yield `) {${utils_1.newLine}`;
|
|
36
|
-
for (const varName of forBlockVars) {
|
|
37
|
-
ctx.addLocalVariable(varName);
|
|
38
|
-
}
|
|
39
36
|
let isFragment = true;
|
|
40
37
|
for (const argument of node.codegenNode?.children.arguments ?? []) {
|
|
41
38
|
if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
|
|
@@ -48,7 +45,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
48
45
|
for (const prop of argument.returns.props.properties) {
|
|
49
46
|
if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
50
47
|
&& !prop.value.isStatic) {
|
|
51
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
48
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, `(`, `)`);
|
|
52
49
|
yield utils_1.endOfLine;
|
|
53
50
|
}
|
|
54
51
|
}
|
|
@@ -56,11 +53,11 @@ function* generateVFor(options, ctx, node) {
|
|
|
56
53
|
}
|
|
57
54
|
const { inVFor } = ctx;
|
|
58
55
|
ctx.inVFor = true;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
for (const varName of forBlockVars) {
|
|
62
|
-
ctx.removeLocalVariable(varName);
|
|
56
|
+
for (const child of node.children) {
|
|
57
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, isFragment);
|
|
63
58
|
}
|
|
59
|
+
ctx.inVFor = inVFor;
|
|
60
|
+
yield* endScope();
|
|
64
61
|
yield `}${utils_1.newLine}`;
|
|
65
62
|
}
|
|
66
63
|
function parseVForNode(node) {
|
|
@@ -5,8 +5,8 @@ const CompilerDOM = require("@vue/compiler-dom");
|
|
|
5
5
|
const muggle_string_1 = require("muggle-string");
|
|
6
6
|
const codeFeatures_1 = require("../codeFeatures");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
-
const elementChildren_1 = require("./elementChildren");
|
|
9
8
|
const interpolation_1 = require("./interpolation");
|
|
9
|
+
const templateChild_1 = require("./templateChild");
|
|
10
10
|
function* generateVIf(options, ctx, node) {
|
|
11
11
|
const originalBlockConditionsLength = ctx.blockConditions.length;
|
|
12
12
|
const isFragment = node.codegenNode
|
|
@@ -26,14 +26,16 @@ function* generateVIf(options, ctx, node) {
|
|
|
26
26
|
}
|
|
27
27
|
let addedBlockCondition = false;
|
|
28
28
|
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
29
|
-
const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx,
|
|
29
|
+
const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, `(`, `)`)];
|
|
30
30
|
yield* codes;
|
|
31
31
|
ctx.blockConditions.push((0, muggle_string_1.toString)(codes));
|
|
32
32
|
addedBlockCondition = true;
|
|
33
33
|
yield ` `;
|
|
34
34
|
}
|
|
35
35
|
yield `{${utils_1.newLine}`;
|
|
36
|
-
|
|
36
|
+
for (const child of branch.children) {
|
|
37
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, i !== 0 || isFragment);
|
|
38
|
+
}
|
|
37
39
|
yield `}${utils_1.newLine}`;
|
|
38
40
|
if (addedBlockCondition) {
|
|
39
41
|
ctx.blockConditions[ctx.blockConditions.length - 1] = `!${ctx.blockConditions[ctx.blockConditions.length - 1]}`;
|
|
@@ -6,48 +6,48 @@ const muggle_string_1 = require("muggle-string");
|
|
|
6
6
|
const collectBindings_1 = require("../../utils/collectBindings");
|
|
7
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
|
-
const
|
|
10
|
-
const elementChildren_1 = require("./elementChildren");
|
|
9
|
+
const boundary_1 = require("../utils/boundary");
|
|
11
10
|
const interpolation_1 = require("./interpolation");
|
|
12
11
|
const objectProperty_1 = require("./objectProperty");
|
|
12
|
+
const templateChild_1 = require("./templateChild");
|
|
13
13
|
function* generateVSlot(options, ctx, node, slotDir) {
|
|
14
14
|
if (!ctx.currentComponent) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
const slotBlockVars = [];
|
|
18
17
|
const slotVar = ctx.getInternalVariable();
|
|
19
18
|
if (slotDir) {
|
|
20
19
|
yield `{${utils_1.newLine}`;
|
|
21
20
|
}
|
|
22
21
|
if (slotDir || node.children.length) {
|
|
23
|
-
ctx.currentComponent.used = true;
|
|
24
22
|
yield `const { `;
|
|
25
23
|
if (slotDir) {
|
|
26
24
|
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
27
25
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? codeFeatures_1.codeFeatures.withoutHighlight : codeFeatures_1.codeFeatures.all, false, true);
|
|
28
26
|
}
|
|
29
27
|
else {
|
|
30
|
-
yield* (0,
|
|
28
|
+
const token = yield* (0, boundary_1.startBoundary)('template', slotDir.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
29
|
+
yield `default`;
|
|
30
|
+
yield (0, boundary_1.endBoundary)(token, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0));
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
// #932: reference for implicit default slot
|
|
35
|
-
yield* (0,
|
|
35
|
+
const token = yield* (0, boundary_1.startBoundary)('template', node.loc.start.offset, codeFeatures_1.codeFeatures.navigation);
|
|
36
|
+
yield `default`;
|
|
37
|
+
yield (0, boundary_1.endBoundary)(token, node.loc.end.offset);
|
|
36
38
|
}
|
|
37
39
|
yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
38
40
|
}
|
|
41
|
+
const endScope = ctx.startScope();
|
|
39
42
|
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
40
|
-
const slotAst = (0, utils_1.
|
|
41
|
-
slotBlockVars.push(...(0, collectBindings_1.collectBindingNames)(options.ts, slotAst, slotAst));
|
|
43
|
+
const slotAst = (0, utils_1.getTypeScriptAST)(options.ts, options.template, `(${slotDir.exp.content}) => {}`);
|
|
42
44
|
yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
|
|
45
|
+
ctx.declare(...(0, collectBindings_1.collectBindingNames)(options.ts, slotAst, slotAst));
|
|
43
46
|
}
|
|
44
|
-
for (const
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
48
|
-
for (const varName of slotBlockVars) {
|
|
49
|
-
ctx.removeLocalVariable(varName);
|
|
47
|
+
for (const child of node.children) {
|
|
48
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
|
50
49
|
}
|
|
50
|
+
yield* endScope();
|
|
51
51
|
if (slotDir) {
|
|
52
52
|
let isStatic = true;
|
|
53
53
|
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -79,7 +79,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
|
79
79
|
const { expression } = statement;
|
|
80
80
|
const startOffset = exp.loc.start.offset - 1;
|
|
81
81
|
const types = [];
|
|
82
|
-
const interpolation = [...(0, interpolation_1.generateInterpolation)(options, ctx,
|
|
82
|
+
const interpolation = [...(0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, ast.text, startOffset)];
|
|
83
83
|
(0, muggle_string_1.replaceSourceRange)(interpolation, 'template', startOffset, startOffset + `(`.length);
|
|
84
84
|
(0, muggle_string_1.replaceSourceRange)(interpolation, 'template', startOffset + ast.text.length - `) => {}`.length, startOffset + ast.text.length);
|
|
85
85
|
for (const { name, type } of expression.parameters) {
|
|
@@ -101,7 +101,11 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
|
101
101
|
yield `] = __VLS_getSlotParameters(${slotVar}!`;
|
|
102
102
|
if (types.some(t => t)) {
|
|
103
103
|
yield `, `;
|
|
104
|
-
yield* (0,
|
|
104
|
+
const token = yield* (0, boundary_1.startBoundary)('template', exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
105
|
+
yield `(`;
|
|
106
|
+
yield* types.flatMap(type => type ? [`_`, type, `, `] : `_, `);
|
|
107
|
+
yield `) => [] as any`;
|
|
108
|
+
yield (0, boundary_1.endBoundary)(token, exp.loc.end.offset);
|
|
105
109
|
}
|
|
106
110
|
yield `)${utils_1.endOfLine}`;
|
|
107
111
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
+
export declare function startBoundary(source: string, startOffset: number, features: VueCodeInformation): Generator<Code, symbol, unknown>;
|
|
3
|
+
export declare function endBoundary(token: symbol, endOffset: number): Code;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startBoundary = startBoundary;
|
|
4
|
+
exports.endBoundary = endBoundary;
|
|
5
|
+
function* startBoundary(source, startOffset, features) {
|
|
6
|
+
const token = Symbol(source);
|
|
7
|
+
yield ['', source, startOffset, { ...features, __combineToken: token }];
|
|
8
|
+
return token;
|
|
9
|
+
}
|
|
10
|
+
function endBoundary(token, endOffset) {
|
|
11
|
+
return ['', token.description, endOffset, { __combineToken: token }];
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=boundary.js.map
|
|
@@ -4,7 +4,7 @@ exports.generateCamelized = generateCamelized;
|
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
5
|
function* generateCamelized(code, source, offset, features) {
|
|
6
6
|
const parts = code.split('-');
|
|
7
|
-
const
|
|
7
|
+
const combineToken = features.__combineToken ?? Symbol();
|
|
8
8
|
for (let i = 0; i < parts.length; i++) {
|
|
9
9
|
const part = parts[i];
|
|
10
10
|
if (part !== '') {
|
|
@@ -13,7 +13,7 @@ function* generateCamelized(code, source, offset, features) {
|
|
|
13
13
|
part,
|
|
14
14
|
source,
|
|
15
15
|
offset,
|
|
16
|
-
features,
|
|
16
|
+
{ ...features, __combineToken: combineToken },
|
|
17
17
|
];
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
@@ -21,7 +21,7 @@ function* generateCamelized(code, source, offset, features) {
|
|
|
21
21
|
(0, shared_1.capitalize)(part),
|
|
22
22
|
source,
|
|
23
23
|
offset,
|
|
24
|
-
{
|
|
24
|
+
{ __combineToken: combineToken },
|
|
25
25
|
];
|
|
26
26
|
}
|
|
27
27
|
}
|