@vue/language-core 3.1.5 → 3.1.7
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 +12 -18
- 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 +7 -16
- package/lib/codegen/template/context.js +81 -93
- package/lib/codegen/template/element.js +153 -55
- package/lib/codegen/template/elementDirectives.js +32 -12
- package/lib/codegen/template/elementEvents.js +27 -28
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +49 -23
- package/lib/codegen/template/index.d.ts +8 -19
- package/lib/codegen/template/index.js +85 -80
- package/lib/codegen/template/interpolation.d.ts +3 -3
- package/lib/codegen/template/interpolation.js +90 -136
- 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 +25 -8
- 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 -15
- 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 +4 -5
- package/lib/codegen/utils/index.js +49 -21
- 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.d.ts +5 -2
- package/lib/compilerOptions.js +67 -44
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +5 -6
- package/lib/parsers/scriptRanges.d.ts +4 -8
- package/lib/parsers/scriptRanges.js +3 -2
- package/lib/parsers/scriptSetupRanges.d.ts +2 -6
- package/lib/parsers/scriptSetupRanges.js +3 -2
- package/lib/parsers/utils.d.ts +4 -6
- package/lib/parsers/utils.js +22 -27
- package/lib/plugins/vue-template-inline-css.js +2 -6
- package/lib/plugins/vue-template-inline-ts.js +12 -14
- package/lib/plugins/vue-tsx.d.ts +14 -32
- package/lib/plugins/vue-tsx.js +114 -72
- package/lib/plugins.js +1 -1
- package/lib/types.d.ts +5 -4
- package/lib/utils/parseSfc.js +7 -3
- package/lib/utils/shared.d.ts +1 -1
- package/lib/utils/shared.js +7 -6
- 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} +59 -94
- 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 -2
- package/lib/codegen/utils/wrapWith.js +0 -15
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
- package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
- package/lib/virtualFile/computedSfc.d.ts +0 -6
- package/lib/virtualFile/computedVueSfc.d.ts +0 -4
- package/lib/virtualFile/computedVueSfc.js +0 -41
- package/lib/virtualFile/embeddedFile.d.ts +0 -11
- package/lib/virtualFile/embeddedFile.js +0 -14
- package/lib/virtualFile/vueFile.js +0 -49
|
@@ -1,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 offset = 1;
|
|
38
|
-
for (const className of content.split(' ')) {
|
|
39
|
-
if (className) {
|
|
40
|
-
ctx.scopedClasses.push({
|
|
41
|
-
source: 'template',
|
|
42
|
-
className,
|
|
43
|
-
offset: getClassOffset(offset),
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
offset += className.length + 1;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const offset = (0, shared_1.getAttributeValueOffset)(prop.value);
|
|
51
|
-
if (prop.value.content) {
|
|
52
|
-
const classes = collectClasses(prop.value.content, offset);
|
|
53
|
-
ctx.scopedClasses.push(...classes);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
ctx.emptyClassOffsets.push(offset);
|
|
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,15 +6,14 @@ 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}`;
|
|
@@ -26,27 +25,29 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
26
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);
|
|
27
26
|
}
|
|
28
27
|
else {
|
|
29
|
-
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));
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
else {
|
|
33
34
|
// #932: reference for implicit default slot
|
|
34
|
-
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);
|
|
35
38
|
}
|
|
36
39
|
yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
37
40
|
}
|
|
41
|
+
const endScope = ctx.startScope();
|
|
38
42
|
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
39
|
-
const slotAst = (0, utils_1.
|
|
40
|
-
slotBlockVars.push(...(0, collectBindings_1.collectBindingNames)(options.ts, slotAst, slotAst));
|
|
43
|
+
const slotAst = (0, utils_1.getTypeScriptAST)(options.ts, options.template, `(${slotDir.exp.content}) => {}`);
|
|
41
44
|
yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
|
|
45
|
+
ctx.declare(...(0, collectBindings_1.collectBindingNames)(options.ts, slotAst, slotAst));
|
|
42
46
|
}
|
|
43
|
-
for (const
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
47
|
-
for (const varName of slotBlockVars) {
|
|
48
|
-
ctx.removeLocalVariable(varName);
|
|
47
|
+
for (const child of node.children) {
|
|
48
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
|
49
49
|
}
|
|
50
|
+
yield* endScope();
|
|
50
51
|
if (slotDir) {
|
|
51
52
|
let isStatic = true;
|
|
52
53
|
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -78,7 +79,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
|
78
79
|
const { expression } = statement;
|
|
79
80
|
const startOffset = exp.loc.start.offset - 1;
|
|
80
81
|
const types = [];
|
|
81
|
-
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)];
|
|
82
83
|
(0, muggle_string_1.replaceSourceRange)(interpolation, 'template', startOffset, startOffset + `(`.length);
|
|
83
84
|
(0, muggle_string_1.replaceSourceRange)(interpolation, 'template', startOffset + ast.text.length - `) => {}`.length, startOffset + ast.text.length);
|
|
84
85
|
for (const { name, type } of expression.parameters) {
|
|
@@ -100,7 +101,11 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
|
100
101
|
yield `] = __VLS_getSlotParameters(${slotVar}!`;
|
|
101
102
|
if (types.some(t => t)) {
|
|
102
103
|
yield `, `;
|
|
103
|
-
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);
|
|
104
109
|
}
|
|
105
110
|
yield `)${utils_1.endOfLine}`;
|
|
106
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
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateEscaped = generateEscaped;
|
|
4
4
|
function* generateEscaped(text, source, offset, features, escapeTarget) {
|
|
5
5
|
const parts = text.split(escapeTarget);
|
|
6
|
-
const
|
|
6
|
+
const combineToken = features.__combineToken ?? Symbol();
|
|
7
7
|
let isEscapeTarget = false;
|
|
8
8
|
for (let i = 0; i < parts.length; i++) {
|
|
9
9
|
const part = parts[i];
|
|
@@ -14,7 +14,9 @@ function* generateEscaped(text, source, offset, features, escapeTarget) {
|
|
|
14
14
|
part,
|
|
15
15
|
source,
|
|
16
16
|
offset,
|
|
17
|
-
i === 0
|
|
17
|
+
i === 0
|
|
18
|
+
? { ...features, __combineToken: combineToken }
|
|
19
|
+
: { __combineToken: combineToken },
|
|
18
20
|
];
|
|
19
21
|
offset += part.length;
|
|
20
22
|
isEscapeTarget = !isEscapeTarget;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
|
|
2
|
+
import type { Code, Sfc, SfcBlock, VueCodeInformation } from '../../types';
|
|
3
3
|
export declare const newLine = "\n";
|
|
4
4
|
export declare const endOfLine = ";\n";
|
|
5
|
-
export declare const combineLastMapping: VueCodeInformation;
|
|
6
5
|
export declare const identifierRegex: RegExp;
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function generateSfcBlockSection(block:
|
|
9
|
-
export declare function
|
|
6
|
+
export declare function getTypeScriptAST(ts: typeof import('typescript'), block: SfcBlock, text: string): ts.SourceFile;
|
|
7
|
+
export declare function generateSfcBlockSection(block: NonNullable<Sfc['script' | 'scriptSetup']>, start: number, end: number, features: VueCodeInformation): Generator<Code>;
|
|
8
|
+
export declare function forEachNode(ts: typeof import('typescript'), node: ts.Node): Generator<ts.Node>;
|
|
@@ -1,34 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.identifierRegex = exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.identifierRegex = exports.endOfLine = exports.newLine = void 0;
|
|
4
|
+
exports.getTypeScriptAST = getTypeScriptAST;
|
|
5
5
|
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
6
|
-
exports.
|
|
6
|
+
exports.forEachNode = forEachNode;
|
|
7
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
8
|
exports.newLine = `\n`;
|
|
9
9
|
exports.endOfLine = `;${exports.newLine}`;
|
|
10
|
-
exports.combineLastMapping = { __combineOffset: 1 };
|
|
11
10
|
exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (!
|
|
15
|
-
|
|
16
|
-
inlineTsAsts?.set(text, ast);
|
|
11
|
+
const cacheMaps = new Map();
|
|
12
|
+
function getTypeScriptAST(ts, block, text) {
|
|
13
|
+
if (!cacheMaps.has(block)) {
|
|
14
|
+
cacheMaps.set(block, [block.content, new Map()]);
|
|
17
15
|
}
|
|
18
|
-
|
|
16
|
+
const cacheMap = cacheMaps.get(block);
|
|
17
|
+
if (cacheMap[0] !== block.content) {
|
|
18
|
+
cacheMap[0] = block.content;
|
|
19
|
+
for (const [key, info] of cacheMap[1]) {
|
|
20
|
+
if (info[1]) {
|
|
21
|
+
info[1] = 0;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
cacheMap[1].delete(key);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const cache = cacheMap[1].get(text);
|
|
29
|
+
if (cache) {
|
|
30
|
+
cache[1]++;
|
|
31
|
+
return cache[0];
|
|
32
|
+
}
|
|
33
|
+
const ast = ts.createSourceFile('/dummy.ts', text, 99);
|
|
34
|
+
cacheMap[1].set(text, [ast, 1]);
|
|
19
35
|
return ast;
|
|
20
36
|
}
|
|
21
|
-
function generateSfcBlockSection(block, start, end, features) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
function* generateSfcBlockSection(block, start, end, features) {
|
|
38
|
+
const text = block.content.slice(start, end);
|
|
39
|
+
yield [text, block.name, start, features];
|
|
40
|
+
// #3632
|
|
41
|
+
if ('parseDiagnostics' in block.ast) {
|
|
42
|
+
const emptyEndLength = text.length - text.trimEnd().length;
|
|
43
|
+
for (const diag of block.ast.parseDiagnostics) {
|
|
44
|
+
if (diag.start >= end - emptyEndLength) {
|
|
45
|
+
yield `;`;
|
|
46
|
+
yield ['', block.name, end, codeFeatures_1.codeFeatures.verification];
|
|
47
|
+
yield exports.newLine;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
28
52
|
}
|
|
29
|
-
function*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
53
|
+
function* forEachNode(ts, node) {
|
|
54
|
+
const children = [];
|
|
55
|
+
ts.forEachChild(node, child => {
|
|
56
|
+
children.push(child);
|
|
57
|
+
});
|
|
58
|
+
for (const child of children) {
|
|
59
|
+
yield child;
|
|
60
|
+
}
|
|
33
61
|
}
|
|
34
62
|
//# sourceMappingURL=index.js.map
|