@vue/language-core 2.0.29 → 2.1.0
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 +4 -3
- package/index.js +4 -3
- package/lib/codegen/common.d.ts +2 -1
- package/lib/codegen/common.js +16 -5
- package/lib/codegen/globalTypes.d.ts +1 -0
- package/lib/codegen/globalTypes.js +123 -0
- package/lib/codegen/localTypes.d.ts +14 -0
- package/lib/codegen/localTypes.js +120 -0
- package/lib/codegen/script/component.d.ts +1 -4
- package/lib/codegen/script/component.js +112 -63
- package/lib/codegen/script/context.d.ts +14 -10
- package/lib/codegen/script/context.js +5 -107
- package/lib/codegen/script/index.d.ts +3 -2
- package/lib/codegen/script/index.js +37 -53
- package/lib/codegen/script/internalComponent.d.ts +1 -1
- package/lib/codegen/script/internalComponent.js +13 -5
- package/lib/codegen/script/scriptSetup.js +144 -62
- package/lib/codegen/script/template.d.ts +3 -0
- package/lib/codegen/script/template.js +80 -79
- package/lib/codegen/template/context.d.ts +6 -1
- package/lib/codegen/template/context.js +9 -2
- package/lib/codegen/template/element.d.ts +1 -1
- package/lib/codegen/template/element.js +214 -92
- package/lib/codegen/template/elementChildren.js +1 -0
- package/lib/codegen/template/elementDirectives.js +8 -4
- package/lib/codegen/template/elementEvents.js +13 -14
- package/lib/codegen/template/elementProps.js +43 -22
- package/lib/codegen/template/index.d.ts +3 -0
- package/lib/codegen/template/index.js +29 -41
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +24 -15
- package/lib/codegen/template/objectProperty.d.ts +1 -1
- package/lib/codegen/template/objectProperty.js +7 -2
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
- package/lib/codegen/template/styleScopedClasses.js +72 -0
- package/lib/codegen/template/templateChild.js +5 -1
- package/lib/codegen/types.d.ts +9 -0
- package/lib/codegen/types.js +3 -0
- package/lib/languagePlugin.d.ts +2 -4
- package/lib/languagePlugin.js +4 -57
- package/lib/parsers/scriptRanges.d.ts +1 -0
- package/lib/parsers/scriptRanges.js +5 -0
- package/lib/parsers/scriptSetupRanges.d.ts +17 -3
- package/lib/parsers/scriptSetupRanges.js +127 -44
- package/lib/plugins/file-md.js +9 -6
- package/lib/plugins/vue-root-tags.js +51 -0
- package/lib/plugins/vue-tsx.d.ts +40 -3
- package/lib/plugins/vue-tsx.js +17 -4
- package/lib/plugins.js +2 -0
- package/lib/types.d.ts +14 -10
- package/lib/utils/findDestructuredProps.js +3 -0
- package/lib/utils/parseCssClassNames.js +4 -6
- package/lib/utils/parseCssVars.js +5 -7
- package/lib/utils/parseSfc.js +4 -1
- package/lib/utils/ts.js +8 -2
- package/lib/virtualFile/{computedFiles.d.ts → computedEmbeddedCodes.d.ts} +1 -1
- package/lib/virtualFile/{computedFiles.js → computedEmbeddedCodes.js} +3 -3
- package/lib/virtualFile/computedSfc.d.ts +1 -1
- package/lib/virtualFile/computedSfc.js +14 -3
- package/lib/virtualFile/vueFile.d.ts +13 -3
- package/lib/virtualFile/vueFile.js +17 -9
- package/package.json +4 -4
- package/lib/codegen/script/globalTypes.d.ts +0 -2
- package/lib/codegen/script/globalTypes.js +0 -134
- package/lib/codegen/template/objectKey.js +0 -34
- package/lib/languageModule.d.ts +0 -5
- package/lib/languageModule.js +0 -159
- package/lib/plugins/file-dot-setup.js +0 -34
- package/lib/virtualFile/computedMappings.d.ts +0 -4
- package/lib/virtualFile/computedMappings.js +0 -65
- /package/lib/plugins/{file-dot-setup.d.ts → vue-root-tags.d.ts} +0 -0
- /package/lib/{codegen/template/objectKey.d.ts → utils/findDestructuredProps.d.ts} +0 -0
|
@@ -5,6 +5,7 @@ exports.parseBindingRanges = parseBindingRanges;
|
|
|
5
5
|
exports.findBindingVars = findBindingVars;
|
|
6
6
|
exports.getStartEnd = getStartEnd;
|
|
7
7
|
exports.getNodeText = getNodeText;
|
|
8
|
+
const common_1 = require("../codegen/common");
|
|
8
9
|
function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
9
10
|
let foundNonImportExportNode = false;
|
|
10
11
|
let importSectionEndOffset = 0;
|
|
@@ -13,6 +14,8 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
13
14
|
const emits = {};
|
|
14
15
|
const expose = {};
|
|
15
16
|
const options = {};
|
|
17
|
+
const cssModules = [];
|
|
18
|
+
const templateRefs = [];
|
|
16
19
|
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
|
|
17
20
|
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
|
|
18
21
|
const defineProp = [];
|
|
@@ -57,8 +60,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
57
60
|
slots,
|
|
58
61
|
emits,
|
|
59
62
|
expose,
|
|
60
|
-
defineProp,
|
|
61
63
|
options,
|
|
64
|
+
cssModules,
|
|
65
|
+
defineProp,
|
|
66
|
+
templateRefs,
|
|
62
67
|
};
|
|
63
68
|
function _getStartEnd(node) {
|
|
64
69
|
return getStartEnd(ts, node, ast);
|
|
@@ -76,81 +81,124 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
76
81
|
&& ts.isIdentifier(node.expression)) {
|
|
77
82
|
const callText = getNodeText(ts, node.expression, ast);
|
|
78
83
|
if (vueCompilerOptions.macros.defineModel.includes(callText)) {
|
|
79
|
-
let
|
|
84
|
+
let localName;
|
|
85
|
+
let propName;
|
|
80
86
|
let options;
|
|
87
|
+
if (ts.isVariableDeclaration(parent) &&
|
|
88
|
+
ts.isIdentifier(parent.name)) {
|
|
89
|
+
localName = _getStartEnd(parent.name);
|
|
90
|
+
}
|
|
81
91
|
if (node.arguments.length >= 2) {
|
|
82
|
-
|
|
92
|
+
propName = _getStartEnd(node.arguments[0]);
|
|
83
93
|
options = node.arguments[1];
|
|
84
94
|
}
|
|
85
95
|
else if (node.arguments.length >= 1) {
|
|
86
96
|
if (ts.isStringLiteral(node.arguments[0])) {
|
|
87
|
-
|
|
97
|
+
propName = _getStartEnd(node.arguments[0]);
|
|
88
98
|
}
|
|
89
99
|
else {
|
|
90
100
|
options = node.arguments[0];
|
|
91
101
|
}
|
|
92
102
|
}
|
|
103
|
+
let runtimeType;
|
|
104
|
+
let defaultValue;
|
|
93
105
|
let required = false;
|
|
94
106
|
if (options && ts.isObjectLiteralExpression(options)) {
|
|
95
107
|
for (const property of options.properties) {
|
|
96
|
-
if (ts.isPropertyAssignment(property)
|
|
108
|
+
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const text = getNodeText(ts, property.name, ast);
|
|
112
|
+
if (text === 'type') {
|
|
113
|
+
runtimeType = _getStartEnd(property.initializer);
|
|
114
|
+
}
|
|
115
|
+
else if (text === 'default') {
|
|
116
|
+
defaultValue = _getStartEnd(property.initializer);
|
|
117
|
+
}
|
|
118
|
+
else if (text === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
97
119
|
required = true;
|
|
98
|
-
break;
|
|
99
120
|
}
|
|
100
121
|
}
|
|
101
122
|
}
|
|
102
123
|
defineProp.push({
|
|
103
|
-
|
|
104
|
-
|
|
124
|
+
localName,
|
|
125
|
+
name: propName,
|
|
105
126
|
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
|
106
127
|
modifierType: node.typeArguments && node.typeArguments?.length >= 2 ? _getStartEnd(node.typeArguments[1]) : undefined,
|
|
107
|
-
|
|
128
|
+
runtimeType,
|
|
129
|
+
defaultValue,
|
|
108
130
|
required,
|
|
109
131
|
isModel: true,
|
|
110
132
|
});
|
|
111
133
|
}
|
|
112
134
|
else if (callText === 'defineProp') {
|
|
135
|
+
let localName;
|
|
136
|
+
let propName;
|
|
137
|
+
let options;
|
|
138
|
+
if (ts.isVariableDeclaration(parent) &&
|
|
139
|
+
ts.isIdentifier(parent.name)) {
|
|
140
|
+
localName = _getStartEnd(parent.name);
|
|
141
|
+
}
|
|
142
|
+
let runtimeType;
|
|
143
|
+
let defaultValue;
|
|
144
|
+
let required = false;
|
|
113
145
|
if (definePropProposalA) {
|
|
114
|
-
let required = false;
|
|
115
146
|
if (node.arguments.length >= 2) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
147
|
+
options = node.arguments[1];
|
|
148
|
+
}
|
|
149
|
+
if (node.arguments.length >= 1) {
|
|
150
|
+
propName = _getStartEnd(node.arguments[0]);
|
|
151
|
+
}
|
|
152
|
+
if (options && ts.isObjectLiteralExpression(options)) {
|
|
153
|
+
for (const property of options.properties) {
|
|
154
|
+
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
|
155
|
+
continue;
|
|
123
156
|
}
|
|
157
|
+
const text = getNodeText(ts, property.name, ast);
|
|
158
|
+
if (text === 'type') {
|
|
159
|
+
runtimeType = _getStartEnd(property.initializer);
|
|
160
|
+
}
|
|
161
|
+
else if (text === 'default') {
|
|
162
|
+
defaultValue = _getStartEnd(property.initializer);
|
|
163
|
+
}
|
|
164
|
+
else if (text === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
165
|
+
required = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (definePropProposalB) {
|
|
171
|
+
if (node.arguments.length >= 3) {
|
|
172
|
+
options = node.arguments[2];
|
|
173
|
+
}
|
|
174
|
+
if (node.arguments.length >= 2) {
|
|
175
|
+
if (node.arguments[1].kind === ts.SyntaxKind.TrueKeyword) {
|
|
176
|
+
required = true;
|
|
124
177
|
}
|
|
125
178
|
}
|
|
126
179
|
if (node.arguments.length >= 1) {
|
|
127
|
-
|
|
128
|
-
name: _getStartEnd(node.arguments[0]),
|
|
129
|
-
nameIsString: true,
|
|
130
|
-
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
|
131
|
-
defaultValue: undefined,
|
|
132
|
-
required,
|
|
133
|
-
});
|
|
180
|
+
defaultValue = _getStartEnd(node.arguments[0]);
|
|
134
181
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
182
|
+
if (options && ts.isObjectLiteralExpression(options)) {
|
|
183
|
+
for (const property of options.properties) {
|
|
184
|
+
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const text = getNodeText(ts, property.name, ast);
|
|
188
|
+
if (text === 'type') {
|
|
189
|
+
runtimeType = _getStartEnd(property.initializer);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
143
192
|
}
|
|
144
193
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
194
|
+
defineProp.push({
|
|
195
|
+
localName,
|
|
196
|
+
name: propName,
|
|
197
|
+
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
|
198
|
+
runtimeType,
|
|
199
|
+
defaultValue,
|
|
200
|
+
required,
|
|
201
|
+
});
|
|
154
202
|
}
|
|
155
203
|
else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
|
156
204
|
slots.define = parseDefineFunction(node);
|
|
@@ -181,6 +229,14 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
181
229
|
expose.define = parseDefineFunction(node);
|
|
182
230
|
}
|
|
183
231
|
else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
|
232
|
+
if (ts.isVariableDeclaration(parent)) {
|
|
233
|
+
if (ts.isObjectBindingPattern(parent.name)) {
|
|
234
|
+
props.destructured = (0, common_1.collectVars)(ts, parent.name, ast, [], false);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
props.name = getNodeText(ts, parent.name, ast);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
184
240
|
let statementRange;
|
|
185
241
|
for (let i = parents.length - 1; i >= 0; i--) {
|
|
186
242
|
if (ts.isStatement(parents[i])) {
|
|
@@ -200,9 +256,6 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
200
256
|
...parseDefineFunction(node),
|
|
201
257
|
statement: statementRange,
|
|
202
258
|
};
|
|
203
|
-
if (ts.isVariableDeclaration(parent)) {
|
|
204
|
-
props.name = getNodeText(ts, parent.name, ast);
|
|
205
|
-
}
|
|
206
259
|
if (node.arguments.length) {
|
|
207
260
|
props.define.arg = _getStartEnd(node.arguments[0]);
|
|
208
261
|
}
|
|
@@ -222,6 +275,15 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
222
275
|
}
|
|
223
276
|
else if (vueCompilerOptions.macros.defineOptions.includes(callText)) {
|
|
224
277
|
if (node.arguments.length && ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
278
|
+
const obj = node.arguments[0];
|
|
279
|
+
ts.forEachChild(obj, node => {
|
|
280
|
+
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
|
|
281
|
+
const name = getNodeText(ts, node.name, ast);
|
|
282
|
+
if (name === 'inheritAttrs') {
|
|
283
|
+
options.inheritAttrs = getNodeText(ts, node.initializer, ast);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
});
|
|
225
287
|
for (const prop of node.arguments[0].properties) {
|
|
226
288
|
if ((ts.isPropertyAssignment(prop)) && getNodeText(ts, prop.name, ast) === 'name' && ts.isStringLiteral(prop.initializer)) {
|
|
227
289
|
options.name = prop.initializer.text;
|
|
@@ -229,6 +291,27 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
229
291
|
}
|
|
230
292
|
}
|
|
231
293
|
}
|
|
294
|
+
else if (vueCompilerOptions.macros.templateRef.includes(callText) && node.arguments.length && !node.typeArguments?.length) {
|
|
295
|
+
const define = parseDefineFunction(node);
|
|
296
|
+
define.arg = _getStartEnd(node.arguments[0]);
|
|
297
|
+
let name;
|
|
298
|
+
if (ts.isVariableDeclaration(parent)) {
|
|
299
|
+
name = getNodeText(ts, parent.name, ast);
|
|
300
|
+
}
|
|
301
|
+
templateRefs.push({
|
|
302
|
+
name,
|
|
303
|
+
define
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
else if (vueCompilerOptions.composibles.useCssModule.includes(callText)) {
|
|
307
|
+
const module = {
|
|
308
|
+
exp: _getStartEnd(node)
|
|
309
|
+
};
|
|
310
|
+
if (node.arguments.length) {
|
|
311
|
+
module.arg = _getStartEnd(node.arguments[0]);
|
|
312
|
+
}
|
|
313
|
+
cssModules.push(module);
|
|
314
|
+
}
|
|
232
315
|
}
|
|
233
316
|
ts.forEachChild(node, child => {
|
|
234
317
|
parents.push(node);
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -72,14 +72,17 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
72
72
|
}
|
|
73
73
|
return sfc;
|
|
74
74
|
function transformRange(block) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
const { start, end } = block.loc;
|
|
76
|
+
const startOffset = start.offset;
|
|
77
|
+
const endOffset = end.offset;
|
|
78
|
+
start.offset = -1;
|
|
79
|
+
end.offset = -1;
|
|
80
|
+
for (const [offset] of file2VueSourceMap.toSourceLocation(startOffset)) {
|
|
81
|
+
start.offset = offset;
|
|
79
82
|
break;
|
|
80
83
|
}
|
|
81
|
-
for (const [
|
|
82
|
-
|
|
84
|
+
for (const [offset] of file2VueSourceMap.toSourceLocation(endOffset)) {
|
|
85
|
+
end.offset = offset;
|
|
83
86
|
break;
|
|
84
87
|
}
|
|
85
88
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const muggle_string_1 = require("muggle-string");
|
|
4
|
+
const shared_1 = require("./shared");
|
|
5
|
+
const plugin = () => {
|
|
6
|
+
return {
|
|
7
|
+
version: 2.1,
|
|
8
|
+
getEmbeddedCodes() {
|
|
9
|
+
return [{
|
|
10
|
+
id: 'root_tags',
|
|
11
|
+
lang: 'vue-root-tags',
|
|
12
|
+
}];
|
|
13
|
+
},
|
|
14
|
+
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
|
15
|
+
if (embeddedFile.id === 'root_tags') {
|
|
16
|
+
embeddedFile.content.push([sfc.content, undefined, 0, shared_1.allCodeFeatures]);
|
|
17
|
+
for (const block of [
|
|
18
|
+
sfc.script,
|
|
19
|
+
sfc.scriptSetup,
|
|
20
|
+
sfc.template,
|
|
21
|
+
...sfc.styles,
|
|
22
|
+
...sfc.customBlocks,
|
|
23
|
+
]) {
|
|
24
|
+
if (!block) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
let content = block.content;
|
|
28
|
+
if (content.endsWith('\r\n')) {
|
|
29
|
+
content = content.slice(0, -2);
|
|
30
|
+
}
|
|
31
|
+
else if (content.endsWith('\n')) {
|
|
32
|
+
content = content.slice(0, -1);
|
|
33
|
+
}
|
|
34
|
+
const offset = content.lastIndexOf('\n') + 1;
|
|
35
|
+
// fix folding range end position failed to mapping
|
|
36
|
+
(0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart, sfc.content.substring(block.startTagEnd, block.startTagEnd + offset), [
|
|
37
|
+
'',
|
|
38
|
+
undefined,
|
|
39
|
+
block.startTagEnd + offset,
|
|
40
|
+
{ structure: true },
|
|
41
|
+
], sfc.content.substring(block.startTagEnd + offset, block.endTagStart));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
embeddedFile.parentCodeId ??= 'root_tags';
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
exports.default = plugin;
|
|
51
|
+
//# sourceMappingURL=vue-root-tags.js.map
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
9
9
|
componentsOption: import("../types").TextRange | undefined;
|
|
10
10
|
componentsOptionNode: import("typescript").ObjectLiteralExpression | undefined;
|
|
11
11
|
nameOption: import("../types").TextRange | undefined;
|
|
12
|
+
inheritAttrsOption: string | undefined;
|
|
12
13
|
}) | undefined;
|
|
13
14
|
classBlockEnd: number | undefined;
|
|
14
15
|
bindings: import("../types").TextRange[];
|
|
@@ -20,6 +21,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
20
21
|
importComponentNames: Set<string>;
|
|
21
22
|
props: {
|
|
22
23
|
name?: string;
|
|
24
|
+
destructured?: string[];
|
|
23
25
|
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
24
26
|
arg?: import("../types").TextRange;
|
|
25
27
|
typeArg?: import("../types").TextRange;
|
|
@@ -54,23 +56,54 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
54
56
|
typeArg?: import("../types").TextRange;
|
|
55
57
|
}>;
|
|
56
58
|
};
|
|
59
|
+
options: {
|
|
60
|
+
name?: string;
|
|
61
|
+
inheritAttrs?: string;
|
|
62
|
+
};
|
|
63
|
+
cssModules: {
|
|
64
|
+
exp: import("../types").TextRange;
|
|
65
|
+
arg?: import("../types").TextRange;
|
|
66
|
+
}[];
|
|
57
67
|
defineProp: {
|
|
68
|
+
localName: import("../types").TextRange | undefined;
|
|
58
69
|
name: import("../types").TextRange | undefined;
|
|
59
|
-
nameIsString: boolean;
|
|
60
70
|
type: import("../types").TextRange | undefined;
|
|
61
71
|
modifierType?: import("../types").TextRange | undefined;
|
|
72
|
+
runtimeType: import("../types").TextRange | undefined;
|
|
62
73
|
defaultValue: import("../types").TextRange | undefined;
|
|
63
74
|
required: boolean;
|
|
64
75
|
isModel?: boolean;
|
|
65
76
|
}[];
|
|
66
|
-
|
|
77
|
+
templateRefs: {
|
|
67
78
|
name?: string;
|
|
68
|
-
|
|
79
|
+
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
80
|
+
arg?: import("../types").TextRange;
|
|
81
|
+
typeArg?: import("../types").TextRange;
|
|
82
|
+
}>;
|
|
83
|
+
}[];
|
|
69
84
|
} | undefined;
|
|
70
85
|
lang: () => string;
|
|
71
86
|
generatedScript: () => {
|
|
72
87
|
codes: Code[];
|
|
73
88
|
linkedCodeMappings: Mapping<unknown>[];
|
|
89
|
+
generatedTemplate: boolean;
|
|
90
|
+
generatedPropsType: boolean;
|
|
91
|
+
scriptSetupGeneratedOffset: number | undefined;
|
|
92
|
+
bypassDefineComponent: boolean;
|
|
93
|
+
bindingNames: Set<string>;
|
|
94
|
+
localTypes: {
|
|
95
|
+
generate: (names: string[]) => Generator<string, void, unknown>;
|
|
96
|
+
getUsedNames(): Set<string>;
|
|
97
|
+
readonly PrettifyLocal: string;
|
|
98
|
+
readonly OmitKeepDiscriminatedUnion: string;
|
|
99
|
+
readonly WithDefaults: string;
|
|
100
|
+
readonly WithTemplateSlots: string;
|
|
101
|
+
readonly PropsChildren: string;
|
|
102
|
+
readonly TypePropsToOption: string;
|
|
103
|
+
readonly OmitIndexSignature: string;
|
|
104
|
+
readonly PickRefsExpose: string;
|
|
105
|
+
};
|
|
106
|
+
inlayHints: import("../codegen/types").InlayHintInfo[];
|
|
74
107
|
};
|
|
75
108
|
generatedTemplate: () => {
|
|
76
109
|
codes: Code[];
|
|
@@ -103,11 +136,15 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
103
136
|
blockConditions: string[];
|
|
104
137
|
usedComponentCtxVars: Set<string>;
|
|
105
138
|
scopedClasses: {
|
|
139
|
+
source: string;
|
|
106
140
|
className: string;
|
|
107
141
|
offset: number;
|
|
108
142
|
}[];
|
|
109
143
|
emptyClassOffsets: number[];
|
|
144
|
+
inlayHints: import("../codegen/types").InlayHintInfo[];
|
|
110
145
|
hasSlot: boolean;
|
|
146
|
+
inheritedAttrVars: Set<unknown>;
|
|
147
|
+
singleRootNode: import("@vue/compiler-dom").ElementNode | undefined;
|
|
111
148
|
accessExternalVariable(name: string, offset?: number): void;
|
|
112
149
|
hasLocalVariable: (name: string) => boolean;
|
|
113
150
|
addLocalVariable: (name: string) => void;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -8,6 +8,7 @@ const template_1 = require("../codegen/template");
|
|
|
8
8
|
const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
9
9
|
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
10
10
|
exports.tsCodegen = new WeakMap();
|
|
11
|
+
const fileEditTimes = new Map();
|
|
11
12
|
const plugin = ctx => {
|
|
12
13
|
return {
|
|
13
14
|
version: 2.1,
|
|
@@ -67,11 +68,14 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
67
68
|
compilerOptions: ctx.compilerOptions,
|
|
68
69
|
vueCompilerOptions: ctx.vueCompilerOptions,
|
|
69
70
|
template: _sfc.template,
|
|
71
|
+
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
70
72
|
scriptSetupBindingNames: scriptSetupBindingNames(),
|
|
71
73
|
scriptSetupImportComponentNames: scriptSetupImportComponentNames(),
|
|
74
|
+
templateRefNames: new Map(),
|
|
72
75
|
hasDefineSlots: hasDefineSlots(),
|
|
73
76
|
slotsAssignName: slotsAssignName(),
|
|
74
77
|
propsAssignName: propsAssignName(),
|
|
78
|
+
inheritAttrs: inheritAttrs(),
|
|
75
79
|
});
|
|
76
80
|
let current = codegen.next();
|
|
77
81
|
while (!current.done) {
|
|
@@ -107,15 +111,18 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
107
111
|
});
|
|
108
112
|
const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name);
|
|
109
113
|
const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name);
|
|
114
|
+
const inheritAttrs = (0, computeds_1.computed)(() => {
|
|
115
|
+
const value = scriptSetupRanges()?.options.inheritAttrs ?? scriptRanges()?.exportDefault?.inheritAttrsOption;
|
|
116
|
+
return value !== 'false';
|
|
117
|
+
});
|
|
110
118
|
const generatedScript = (0, computeds_1.computed)(() => {
|
|
111
119
|
const codes = [];
|
|
112
120
|
const linkedCodeMappings = [];
|
|
113
121
|
const _template = generatedTemplate();
|
|
114
122
|
let generatedLength = 0;
|
|
115
|
-
|
|
123
|
+
const codegen = (0, script_1.generateScript)({
|
|
116
124
|
ts,
|
|
117
125
|
fileBaseName: path.basename(fileName),
|
|
118
|
-
globalTypes: ctx.globalTypesHolder === fileName,
|
|
119
126
|
sfc: _sfc,
|
|
120
127
|
lang: lang(),
|
|
121
128
|
scriptRanges: scriptRanges(),
|
|
@@ -123,16 +130,22 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
123
130
|
templateCodegen: _template,
|
|
124
131
|
compilerOptions: ctx.compilerOptions,
|
|
125
132
|
vueCompilerOptions: ctx.vueCompilerOptions,
|
|
133
|
+
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
126
134
|
getGeneratedLength: () => generatedLength,
|
|
127
135
|
linkedCodeMappings,
|
|
128
|
-
})
|
|
136
|
+
});
|
|
137
|
+
fileEditTimes.set(fileName, (fileEditTimes.get(fileName) ?? 0) + 1);
|
|
138
|
+
let current = codegen.next();
|
|
139
|
+
while (!current.done) {
|
|
140
|
+
const code = current.value;
|
|
129
141
|
codes.push(code);
|
|
130
142
|
generatedLength += typeof code === 'string'
|
|
131
143
|
? code.length
|
|
132
144
|
: code[0].length;
|
|
145
|
+
current = codegen.next();
|
|
133
146
|
}
|
|
134
|
-
;
|
|
135
147
|
return {
|
|
148
|
+
...current.value,
|
|
136
149
|
codes,
|
|
137
150
|
linkedCodeMappings,
|
|
138
151
|
};
|
package/lib/plugins.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.createPlugins = createPlugins;
|
|
|
18
18
|
const file_html_1 = require("./plugins/file-html");
|
|
19
19
|
const file_md_1 = require("./plugins/file-md");
|
|
20
20
|
const file_vue_1 = require("./plugins/file-vue");
|
|
21
|
+
const vue_root_tags_1 = require("./plugins/vue-root-tags");
|
|
21
22
|
const vue_script_js_1 = require("./plugins/vue-script-js");
|
|
22
23
|
const vue_sfc_customblocks_1 = require("./plugins/vue-sfc-customblocks");
|
|
23
24
|
const vue_sfc_scripts_1 = require("./plugins/vue-sfc-scripts");
|
|
@@ -34,6 +35,7 @@ function createPlugins(pluginContext) {
|
|
|
34
35
|
file_vue_1.default,
|
|
35
36
|
file_md_1.default,
|
|
36
37
|
file_html_1.default,
|
|
38
|
+
vue_root_tags_1.default,
|
|
37
39
|
vue_script_js_1.default,
|
|
38
40
|
vue_template_html_1.default,
|
|
39
41
|
vue_template_inline_css_1.default,
|
package/lib/types.d.ts
CHANGED
|
@@ -11,13 +11,6 @@ export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' |
|
|
|
11
11
|
plugins?: string[];
|
|
12
12
|
};
|
|
13
13
|
export interface VueCodeInformation extends CodeInformation {
|
|
14
|
-
__hint?: {
|
|
15
|
-
setting: string;
|
|
16
|
-
label: string;
|
|
17
|
-
tooltip: string;
|
|
18
|
-
paddingRight?: boolean;
|
|
19
|
-
paddingLeft?: boolean;
|
|
20
|
-
};
|
|
21
14
|
__combineLastMapping?: boolean;
|
|
22
15
|
__combineOffsetMapping?: number;
|
|
23
16
|
}
|
|
@@ -31,6 +24,7 @@ export interface VueCompilerOptions {
|
|
|
31
24
|
jsxSlots: boolean;
|
|
32
25
|
strictTemplates: boolean;
|
|
33
26
|
skipTemplateCodegen: boolean;
|
|
27
|
+
fallthroughAttributes: boolean;
|
|
34
28
|
dataAttributes: string[];
|
|
35
29
|
htmlAttributes: string[];
|
|
36
30
|
optionsWrapper: [string, string] | [];
|
|
@@ -42,11 +36,16 @@ export interface VueCompilerOptions {
|
|
|
42
36
|
defineModel: string[];
|
|
43
37
|
defineOptions: string[];
|
|
44
38
|
withDefaults: string[];
|
|
39
|
+
templateRef: string[];
|
|
40
|
+
};
|
|
41
|
+
composibles: {
|
|
42
|
+
useCssModule: string[];
|
|
45
43
|
};
|
|
46
44
|
plugins: VueLanguagePlugin[];
|
|
47
45
|
experimentalDefinePropProposal: 'kevinEdition' | 'johnsonEdition' | false;
|
|
48
46
|
experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
|
|
49
47
|
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
|
|
48
|
+
__test?: boolean;
|
|
50
49
|
}
|
|
51
50
|
export declare const validVersions: readonly [2, 2.1];
|
|
52
51
|
export type VueLanguagePluginReturn = {
|
|
@@ -84,7 +83,6 @@ export type VueLanguagePlugin = (ctx: {
|
|
|
84
83
|
};
|
|
85
84
|
compilerOptions: ts.CompilerOptions;
|
|
86
85
|
vueCompilerOptions: VueCompilerOptions;
|
|
87
|
-
globalTypesHolder: string | undefined;
|
|
88
86
|
}) => VueLanguagePluginReturn | VueLanguagePluginReturn[];
|
|
89
87
|
export interface SfcBlock {
|
|
90
88
|
name: string;
|
|
@@ -96,7 +94,14 @@ export interface SfcBlock {
|
|
|
96
94
|
content: string;
|
|
97
95
|
attrs: Record<string, string | true>;
|
|
98
96
|
}
|
|
97
|
+
export interface SFCStyleOverride {
|
|
98
|
+
module?: {
|
|
99
|
+
name: string;
|
|
100
|
+
offset?: number;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
99
103
|
export interface Sfc {
|
|
104
|
+
content: string;
|
|
100
105
|
template: SfcBlock & {
|
|
101
106
|
ast: CompilerDOM.RootNode | undefined;
|
|
102
107
|
errors: CompilerDOM.CompilerError[];
|
|
@@ -112,8 +117,7 @@ export interface Sfc {
|
|
|
112
117
|
genericOffset: number;
|
|
113
118
|
ast: ts.SourceFile;
|
|
114
119
|
} | undefined;
|
|
115
|
-
styles: readonly (SfcBlock & {
|
|
116
|
-
module: string | undefined;
|
|
120
|
+
styles: readonly (SfcBlock & SFCStyleOverride & {
|
|
117
121
|
scoped: boolean;
|
|
118
122
|
cssVars: {
|
|
119
123
|
text: string;
|
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseCssClassNames = parseCssClassNames;
|
|
4
4
|
const parseCssVars_1 = require("./parseCssVars");
|
|
5
|
-
const cssClassNameReg = /(?=(
|
|
5
|
+
const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#[{])/gi;
|
|
6
6
|
function* parseCssClassNames(styleContent) {
|
|
7
7
|
styleContent = (0, parseCssVars_1.clearComments)(styleContent);
|
|
8
8
|
const matches = styleContent.matchAll(cssClassNameReg);
|
|
9
9
|
for (const match of matches) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
yield { offset: match.index, text: matchText };
|
|
14
|
-
}
|
|
10
|
+
const matchText = match[1];
|
|
11
|
+
if (matchText) {
|
|
12
|
+
yield { offset: match.index, text: matchText };
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
}
|
|
@@ -3,19 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.parseCssVars = parseCssVars;
|
|
5
5
|
exports.clearComments = clearComments;
|
|
6
|
-
const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([
|
|
6
|
+
const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi;
|
|
7
7
|
const commentReg1 = /\/\*([\s\S]*?)\*\//g;
|
|
8
8
|
const commentReg2 = /\/\/([\s\S]*?)\n/g;
|
|
9
9
|
function* parseCssVars(styleContent) {
|
|
10
10
|
styleContent = clearComments(styleContent);
|
|
11
11
|
const matchs = styleContent.matchAll(vBindCssVarReg);
|
|
12
12
|
for (const match of matchs) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
yield { offset, text: matchText };
|
|
18
|
-
}
|
|
13
|
+
const matchText = match.slice(1).find(t => t);
|
|
14
|
+
if (matchText) {
|
|
15
|
+
const offset = match.index + styleContent.slice(match.index).indexOf(matchText);
|
|
16
|
+
yield { offset, text: matchText };
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
19
|
}
|
package/lib/utils/parseSfc.js
CHANGED
|
@@ -107,7 +107,10 @@ function createBlock(node, source) {
|
|
|
107
107
|
block.scoped = true;
|
|
108
108
|
}
|
|
109
109
|
else if (p.name === 'module') {
|
|
110
|
-
block.module =
|
|
110
|
+
block.module = {
|
|
111
|
+
name: p.value?.content ?? '$style',
|
|
112
|
+
offset: p.value?.content ? p.value?.loc.start.offset - node.loc.start.offset : undefined
|
|
113
|
+
};
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
else if (type === 'script' && p.name === 'setup') {
|