@vue/language-core 2.1.8 → 2.2.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/lib/codegen/globalTypes.js +12 -5
- package/lib/codegen/localTypes.js +3 -3
- package/lib/codegen/script/component.js +42 -42
- package/lib/codegen/script/componentSelf.js +14 -13
- package/lib/codegen/script/context.js +2 -2
- package/lib/codegen/script/index.d.ts +5 -3
- package/lib/codegen/script/index.js +24 -37
- package/lib/codegen/script/scriptSetup.js +240 -193
- package/lib/codegen/script/src.js +6 -6
- package/lib/codegen/script/styleModulesType.js +5 -5
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +89 -99
- package/lib/codegen/template/context.d.ts +13 -3
- package/lib/codegen/template/context.js +21 -12
- package/lib/codegen/template/element.d.ts +2 -4
- package/lib/codegen/template/element.js +132 -105
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +8 -8
- package/lib/codegen/template/elementDirectives.d.ts +1 -0
- package/lib/codegen/template/elementDirectives.js +28 -22
- package/lib/codegen/template/elementEvents.d.ts +2 -2
- package/lib/codegen/template/elementEvents.js +32 -65
- package/lib/codegen/template/elementProps.d.ts +3 -2
- package/lib/codegen/template/elementProps.js +119 -122
- package/lib/codegen/template/index.js +52 -60
- package/lib/codegen/template/interpolation.d.ts +5 -3
- package/lib/codegen/template/interpolation.js +18 -19
- package/lib/codegen/template/objectProperty.js +8 -8
- package/lib/codegen/template/propertyAccess.js +4 -4
- package/lib/codegen/template/slotOutlet.d.ts +1 -1
- package/lib/codegen/template/slotOutlet.js +13 -13
- package/lib/codegen/template/styleScopedClasses.d.ts +1 -1
- package/lib/codegen/template/styleScopedClasses.js +11 -8
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +31 -19
- package/lib/codegen/template/vFor.d.ts +1 -1
- package/lib/codegen/template/vFor.js +11 -11
- package/lib/codegen/template/vIf.d.ts +1 -1
- package/lib/codegen/template/vIf.js +6 -6
- package/lib/codegen/{template → utils}/camelized.js +2 -2
- package/lib/codegen/{common.d.ts → utils/index.d.ts} +1 -2
- package/lib/codegen/{common.js → utils/index.js} +4 -15
- package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
- package/lib/codegen/utils/unicode.d.ts +2 -0
- package/lib/codegen/utils/unicode.js +25 -0
- package/lib/languagePlugin.js +1 -1
- package/lib/parsers/scriptRanges.d.ts +7 -2
- package/lib/parsers/scriptSetupRanges.d.ts +67 -81
- package/lib/parsers/scriptSetupRanges.js +195 -166
- package/lib/parsers/vueCompilerOptions.d.ts +2 -0
- package/lib/parsers/vueCompilerOptions.js +23 -0
- package/lib/plugins/file-html.js +4 -3
- package/lib/plugins/file-md.js +1 -1
- package/lib/plugins/file-vue.js +4 -4
- package/lib/plugins/vue-root-tags.js +2 -2
- package/lib/plugins/vue-template-html.js +6 -2
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +13 -5
- package/lib/plugins/vue-tsx.d.ts +101 -72
- package/lib/plugins/vue-tsx.js +65 -69
- package/lib/types.d.ts +19 -10
- package/lib/utils/buildMappings.d.ts +1 -1
- package/lib/utils/parseSfc.d.ts +5 -0
- package/lib/utils/parseSfc.js +7 -2
- package/lib/utils/ts.d.ts +1 -1
- package/lib/utils/ts.js +38 -24
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +23 -12
- package/lib/virtualFile/computedVueSfc.d.ts +1 -1
- package/lib/virtualFile/vueFile.d.ts +3 -3
- package/package.json +5 -5
- package/lib/codegen/types.d.ts +0 -9
- package/lib/codegen/types.js +0 -3
- package/lib/utils/findDestructuredProps.d.ts +0 -1
- package/lib/utils/findDestructuredProps.js +0 -3
- /package/lib/codegen/{template → utils}/camelized.d.ts +0 -0
- /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
|
@@ -5,26 +5,31 @@ exports.parseBindingRanges = parseBindingRanges;
|
|
|
5
5
|
exports.findBindingVars = findBindingVars;
|
|
6
6
|
exports.getStartEnd = getStartEnd;
|
|
7
7
|
exports.getNodeText = getNodeText;
|
|
8
|
-
const
|
|
8
|
+
const utils_1 = require("../codegen/utils");
|
|
9
|
+
const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
|
|
9
10
|
function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
10
|
-
let foundNonImportExportNode = false;
|
|
11
|
-
let importSectionEndOffset = 0;
|
|
12
|
-
const props = {};
|
|
13
|
-
const slots = {};
|
|
14
|
-
const emits = {};
|
|
15
|
-
const expose = {};
|
|
16
|
-
const options = {};
|
|
17
|
-
const cssModules = [];
|
|
18
|
-
const templateRefs = [];
|
|
19
|
-
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
|
|
20
|
-
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
|
|
21
11
|
const defineProp = [];
|
|
12
|
+
let defineProps;
|
|
13
|
+
let withDefaults;
|
|
14
|
+
let defineEmits;
|
|
15
|
+
let defineSlots;
|
|
16
|
+
let defineExpose;
|
|
17
|
+
let defineOptions;
|
|
18
|
+
const useAttrs = [];
|
|
19
|
+
const useCssModule = [];
|
|
20
|
+
const useSlots = [];
|
|
21
|
+
const useTemplateRef = [];
|
|
22
|
+
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
|
|
23
|
+
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
|
|
22
24
|
const text = ast.text;
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
+
const leadingCommentRanges = ts.getLeadingCommentRanges(text, 0)?.reverse() ?? [];
|
|
26
|
+
const leadingCommentEndOffset = leadingCommentRanges.find(range => tsCheckReg.test(text.slice(range.pos, range.end)))?.end ?? 0;
|
|
25
27
|
let bindings = parseBindingRanges(ts, ast);
|
|
28
|
+
let foundNonImportExportNode = false;
|
|
29
|
+
let importSectionEndOffset = 0;
|
|
26
30
|
ts.forEachChild(ast, node => {
|
|
27
|
-
const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node))
|
|
31
|
+
const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node))
|
|
32
|
+
&& node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
|
|
28
33
|
if (!foundNonImportExportNode
|
|
29
34
|
&& !ts.isImportDeclaration(node)
|
|
30
35
|
&& !isTypeExport
|
|
@@ -41,51 +46,34 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
41
46
|
}
|
|
42
47
|
foundNonImportExportNode = true;
|
|
43
48
|
}
|
|
44
|
-
if (ts.isImportDeclaration(node)
|
|
45
|
-
&& node.importClause?.name
|
|
46
|
-
&& !node.importClause.isTypeOnly) {
|
|
47
|
-
const moduleName = getNodeText(ts, node.moduleSpecifier, ast).slice(1, -1);
|
|
48
|
-
if (vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
|
49
|
-
importComponentNames.add(getNodeText(ts, node.importClause.name, ast));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
49
|
});
|
|
53
|
-
ts.forEachChild(ast,
|
|
54
|
-
const templateRefNames = new Set(
|
|
55
|
-
bindings = bindings.filter(range => {
|
|
56
|
-
const name = text.
|
|
50
|
+
ts.forEachChild(ast, node => visitNode(node, [ast]));
|
|
51
|
+
const templateRefNames = new Set(useTemplateRef.map(ref => ref.name));
|
|
52
|
+
bindings = bindings.filter(({ range }) => {
|
|
53
|
+
const name = text.slice(range.start, range.end);
|
|
57
54
|
return !templateRefNames.has(name);
|
|
58
55
|
});
|
|
59
56
|
return {
|
|
60
57
|
leadingCommentEndOffset,
|
|
61
58
|
importSectionEndOffset,
|
|
62
59
|
bindings,
|
|
63
|
-
importComponentNames,
|
|
64
|
-
props,
|
|
65
|
-
slots,
|
|
66
|
-
emits,
|
|
67
|
-
expose,
|
|
68
|
-
options,
|
|
69
|
-
cssModules,
|
|
70
60
|
defineProp,
|
|
71
|
-
|
|
61
|
+
defineProps,
|
|
62
|
+
withDefaults,
|
|
63
|
+
defineEmits,
|
|
64
|
+
defineSlots,
|
|
65
|
+
defineExpose,
|
|
66
|
+
defineOptions,
|
|
67
|
+
useAttrs,
|
|
68
|
+
useCssModule,
|
|
69
|
+
useSlots,
|
|
70
|
+
useTemplateRef,
|
|
72
71
|
};
|
|
73
|
-
function _getStartEnd(node) {
|
|
74
|
-
return getStartEnd(ts, node, ast);
|
|
75
|
-
}
|
|
76
|
-
function parseDefineFunction(node) {
|
|
77
|
-
return {
|
|
78
|
-
..._getStartEnd(node),
|
|
79
|
-
exp: _getStartEnd(node.expression),
|
|
80
|
-
arg: node.arguments.length ? _getStartEnd(node.arguments[0]) : undefined,
|
|
81
|
-
typeArg: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
72
|
function visitNode(node, parents) {
|
|
85
73
|
const parent = parents[parents.length - 1];
|
|
86
74
|
if (ts.isCallExpression(node)
|
|
87
75
|
&& ts.isIdentifier(node.expression)) {
|
|
88
|
-
const callText =
|
|
76
|
+
const callText = _getNodeText(node.expression);
|
|
89
77
|
if (vueCompilerOptions.macros.defineModel.includes(callText)) {
|
|
90
78
|
let localName;
|
|
91
79
|
let propName;
|
|
@@ -99,7 +87,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
99
87
|
options = node.arguments[1];
|
|
100
88
|
}
|
|
101
89
|
else if (node.arguments.length >= 1) {
|
|
102
|
-
if (ts.
|
|
90
|
+
if (ts.isStringLiteralLike(node.arguments[0])) {
|
|
103
91
|
propName = _getStartEnd(node.arguments[0]);
|
|
104
92
|
}
|
|
105
93
|
else {
|
|
@@ -114,7 +102,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
114
102
|
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
|
115
103
|
continue;
|
|
116
104
|
}
|
|
117
|
-
const text =
|
|
105
|
+
const text = _getNodeText(property.name);
|
|
118
106
|
if (text === 'type') {
|
|
119
107
|
runtimeType = _getStartEnd(property.initializer);
|
|
120
108
|
}
|
|
@@ -160,7 +148,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
160
148
|
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
|
161
149
|
continue;
|
|
162
150
|
}
|
|
163
|
-
const text =
|
|
151
|
+
const text = _getNodeText(property.name);
|
|
164
152
|
if (text === 'type') {
|
|
165
153
|
runtimeType = _getStartEnd(property.initializer);
|
|
166
154
|
}
|
|
@@ -190,7 +178,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
190
178
|
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
|
191
179
|
continue;
|
|
192
180
|
}
|
|
193
|
-
const text =
|
|
181
|
+
const text = _getNodeText(property.name);
|
|
194
182
|
if (text === 'type') {
|
|
195
183
|
runtimeType = _getStartEnd(property.initializer);
|
|
196
184
|
}
|
|
@@ -206,160 +194,198 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
206
194
|
required,
|
|
207
195
|
});
|
|
208
196
|
}
|
|
209
|
-
else if (vueCompilerOptions.macros.
|
|
210
|
-
|
|
197
|
+
else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
|
198
|
+
defineProps = {
|
|
199
|
+
...parseCallExpression(node),
|
|
200
|
+
statement: getStatementRange(ts, parents, node, ast)
|
|
201
|
+
};
|
|
211
202
|
if (ts.isVariableDeclaration(parent)) {
|
|
212
|
-
if (ts.
|
|
213
|
-
|
|
203
|
+
if (ts.isObjectBindingPattern(parent.name)) {
|
|
204
|
+
defineProps.destructured = new Set();
|
|
205
|
+
const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name, []);
|
|
206
|
+
for (const [id, isRest] of identifiers) {
|
|
207
|
+
const name = _getNodeText(id);
|
|
208
|
+
if (isRest) {
|
|
209
|
+
defineProps.destructuredRest = name;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
defineProps.destructured.add(name);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
214
215
|
}
|
|
215
216
|
else {
|
|
216
|
-
|
|
217
|
+
defineProps.name = _getNodeText(parent.name);
|
|
217
218
|
}
|
|
218
219
|
}
|
|
220
|
+
else if (ts.isCallExpression(parent)
|
|
221
|
+
&& vueCompilerOptions.macros.withDefaults.includes(_getNodeText(parent.expression))) {
|
|
222
|
+
const grand = parents.at(-2);
|
|
223
|
+
if (grand && ts.isVariableDeclaration(grand)) {
|
|
224
|
+
defineProps.name = _getNodeText(grand.name);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else if (vueCompilerOptions.macros.withDefaults.includes(callText)) {
|
|
229
|
+
const [, arg] = node.arguments;
|
|
230
|
+
withDefaults = {
|
|
231
|
+
callExp: _getStartEnd(node),
|
|
232
|
+
exp: _getStartEnd(node.expression),
|
|
233
|
+
arg: arg ? _getStartEnd(arg) : undefined
|
|
234
|
+
};
|
|
219
235
|
}
|
|
220
236
|
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
|
221
|
-
|
|
222
|
-
...
|
|
237
|
+
defineEmits = {
|
|
238
|
+
...parseCallExpression(node),
|
|
223
239
|
statement: getStatementRange(ts, parents, node, ast)
|
|
224
240
|
};
|
|
225
241
|
if (ts.isVariableDeclaration(parent)) {
|
|
226
|
-
|
|
242
|
+
defineEmits.name = _getNodeText(parent.name);
|
|
227
243
|
}
|
|
228
|
-
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])
|
|
244
|
+
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])) {
|
|
229
245
|
for (const member of node.typeArguments[0].members) {
|
|
230
|
-
if (ts.isCallSignatureDeclaration(member)
|
|
231
|
-
|
|
232
|
-
|
|
246
|
+
if (ts.isCallSignatureDeclaration(member)) {
|
|
247
|
+
const type = member.parameters[0]?.type;
|
|
248
|
+
if (type && ts.isUnionTypeNode(type)) {
|
|
249
|
+
defineEmits.hasUnionTypeArg = true;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
233
252
|
}
|
|
234
253
|
}
|
|
235
254
|
}
|
|
236
255
|
}
|
|
237
|
-
else if (vueCompilerOptions.macros.
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
256
|
+
else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
|
257
|
+
defineSlots = {
|
|
258
|
+
...parseCallExpression(node),
|
|
259
|
+
statement: getStatementRange(ts, parents, node, ast)
|
|
260
|
+
};
|
|
241
261
|
if (ts.isVariableDeclaration(parent)) {
|
|
242
|
-
if (ts.
|
|
243
|
-
|
|
244
|
-
const identifiers = (0, common_1.collectIdentifiers)(ts, parent.name, []);
|
|
245
|
-
for (const [id, isRest] of identifiers) {
|
|
246
|
-
const name = getNodeText(ts, id, ast);
|
|
247
|
-
if (isRest) {
|
|
248
|
-
props.destructuredRest = name;
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
props.destructured.add(name);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
262
|
+
if (ts.isIdentifier(parent.name)) {
|
|
263
|
+
defineSlots.name = _getNodeText(parent.name);
|
|
254
264
|
}
|
|
255
265
|
else {
|
|
256
|
-
|
|
266
|
+
defineSlots.isObjectBindingPattern = ts.isObjectBindingPattern(parent.name);
|
|
257
267
|
}
|
|
258
268
|
}
|
|
259
|
-
props.define = {
|
|
260
|
-
...parseDefineFunction(node),
|
|
261
|
-
statement: getStatementRange(ts, parents, node, ast),
|
|
262
|
-
};
|
|
263
|
-
if (node.arguments.length) {
|
|
264
|
-
props.define.arg = _getStartEnd(node.arguments[0]);
|
|
265
|
-
}
|
|
266
|
-
if (node.typeArguments?.length) {
|
|
267
|
-
props.define.typeArg = _getStartEnd(node.typeArguments[0]);
|
|
268
|
-
}
|
|
269
269
|
}
|
|
270
|
-
else if (vueCompilerOptions.macros.
|
|
271
|
-
|
|
272
|
-
if (node.arguments.length >= 2) {
|
|
273
|
-
const arg = node.arguments[1];
|
|
274
|
-
props.withDefaults.arg = _getStartEnd(arg);
|
|
275
|
-
}
|
|
276
|
-
if (ts.isVariableDeclaration(parent)) {
|
|
277
|
-
props.name = getNodeText(ts, parent.name, ast);
|
|
278
|
-
}
|
|
270
|
+
else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
|
|
271
|
+
defineExpose = parseCallExpression(node);
|
|
279
272
|
}
|
|
280
|
-
else if (vueCompilerOptions.macros.defineOptions.includes(callText)
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
273
|
+
else if (vueCompilerOptions.macros.defineOptions.includes(callText)
|
|
274
|
+
&& node.arguments.length
|
|
275
|
+
&& ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
276
|
+
defineOptions = {};
|
|
277
|
+
const obj = node.arguments[0];
|
|
278
|
+
for (const prop of obj.properties) {
|
|
279
|
+
if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {
|
|
280
|
+
const name = _getNodeText(prop.name);
|
|
281
|
+
if (name === 'inheritAttrs') {
|
|
282
|
+
defineOptions.inheritAttrs = _getNodeText(prop.initializer);
|
|
289
283
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if ((ts.isPropertyAssignment(prop)) && getNodeText(ts, prop.name, ast) === 'name' && ts.isStringLiteral(prop.initializer)) {
|
|
293
|
-
options.name = prop.initializer.text;
|
|
284
|
+
else if (name === 'name' && ts.isStringLiteral(prop.initializer)) {
|
|
285
|
+
defineOptions.name = prop.initializer.text;
|
|
294
286
|
}
|
|
295
287
|
}
|
|
296
288
|
}
|
|
297
289
|
}
|
|
298
|
-
else if (vueCompilerOptions.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
define
|
|
307
|
-
});
|
|
290
|
+
else if (vueCompilerOptions.composables.useAttrs.includes(callText)) {
|
|
291
|
+
useAttrs.push(parseCallExpression(node));
|
|
292
|
+
}
|
|
293
|
+
else if (vueCompilerOptions.composables.useCssModule.includes(callText)) {
|
|
294
|
+
useCssModule.push(parseCallExpression(node));
|
|
295
|
+
}
|
|
296
|
+
else if (vueCompilerOptions.composables.useSlots.includes(callText)) {
|
|
297
|
+
useSlots.push(parseCallExpression(node));
|
|
308
298
|
}
|
|
309
|
-
else if (vueCompilerOptions.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
299
|
+
else if (vueCompilerOptions.composables.useTemplateRef.includes(callText)
|
|
300
|
+
&& !node.typeArguments?.length) {
|
|
301
|
+
useTemplateRef.push({
|
|
302
|
+
name: ts.isVariableDeclaration(parent) ? _getNodeText(parent.name) : undefined,
|
|
303
|
+
...parseCallExpression(node)
|
|
313
304
|
});
|
|
314
305
|
}
|
|
315
306
|
}
|
|
316
307
|
ts.forEachChild(node, child => {
|
|
308
|
+
if (ts.isFunctionLike(node)) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
317
311
|
parents.push(node);
|
|
318
312
|
visitNode(child, parents);
|
|
319
313
|
parents.pop();
|
|
320
314
|
});
|
|
321
315
|
}
|
|
316
|
+
function parseCallExpression(node) {
|
|
317
|
+
return {
|
|
318
|
+
callExp: _getStartEnd(node),
|
|
319
|
+
exp: _getStartEnd(node.expression),
|
|
320
|
+
arg: node.arguments.length ? _getStartEnd(node.arguments[0]) : undefined,
|
|
321
|
+
typeArg: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function _getStartEnd(node) {
|
|
325
|
+
return getStartEnd(ts, node, ast);
|
|
326
|
+
}
|
|
327
|
+
function _getNodeText(node) {
|
|
328
|
+
return getNodeText(ts, node, ast);
|
|
329
|
+
}
|
|
322
330
|
}
|
|
323
|
-
function parseBindingRanges(ts,
|
|
331
|
+
function parseBindingRanges(ts, ast) {
|
|
324
332
|
const bindings = [];
|
|
325
|
-
ts.forEachChild(
|
|
333
|
+
ts.forEachChild(ast, node => {
|
|
326
334
|
if (ts.isVariableStatement(node)) {
|
|
327
|
-
for (const
|
|
328
|
-
const vars = _findBindingVars(
|
|
329
|
-
|
|
330
|
-
bindings.push(_var);
|
|
331
|
-
}
|
|
335
|
+
for (const decl of node.declarationList.declarations) {
|
|
336
|
+
const vars = _findBindingVars(decl.name);
|
|
337
|
+
bindings.push(...vars.map(range => ({ range })));
|
|
332
338
|
}
|
|
333
339
|
}
|
|
334
340
|
else if (ts.isFunctionDeclaration(node)) {
|
|
335
341
|
if (node.name && ts.isIdentifier(node.name)) {
|
|
336
|
-
bindings.push(
|
|
342
|
+
bindings.push({
|
|
343
|
+
range: _getStartEnd(node.name)
|
|
344
|
+
});
|
|
337
345
|
}
|
|
338
346
|
}
|
|
339
347
|
else if (ts.isClassDeclaration(node)) {
|
|
340
348
|
if (node.name) {
|
|
341
|
-
bindings.push(
|
|
349
|
+
bindings.push({
|
|
350
|
+
range: _getStartEnd(node.name)
|
|
351
|
+
});
|
|
342
352
|
}
|
|
343
353
|
}
|
|
344
354
|
else if (ts.isEnumDeclaration(node)) {
|
|
345
|
-
bindings.push(
|
|
355
|
+
bindings.push({
|
|
356
|
+
range: _getStartEnd(node.name)
|
|
357
|
+
});
|
|
346
358
|
}
|
|
347
359
|
if (ts.isImportDeclaration(node)) {
|
|
360
|
+
const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
|
|
348
361
|
if (node.importClause && !node.importClause.isTypeOnly) {
|
|
349
|
-
|
|
350
|
-
|
|
362
|
+
const { name, namedBindings } = node.importClause;
|
|
363
|
+
if (name) {
|
|
364
|
+
bindings.push({
|
|
365
|
+
range: _getStartEnd(name),
|
|
366
|
+
moduleName,
|
|
367
|
+
isDefaultImport: true
|
|
368
|
+
});
|
|
351
369
|
}
|
|
352
|
-
if (
|
|
353
|
-
if (ts.isNamedImports(
|
|
354
|
-
for (const element of
|
|
370
|
+
if (namedBindings) {
|
|
371
|
+
if (ts.isNamedImports(namedBindings)) {
|
|
372
|
+
for (const element of namedBindings.elements) {
|
|
355
373
|
if (element.isTypeOnly) {
|
|
356
374
|
continue;
|
|
357
375
|
}
|
|
358
|
-
bindings.push(
|
|
376
|
+
bindings.push({
|
|
377
|
+
range: _getStartEnd(element.name),
|
|
378
|
+
moduleName,
|
|
379
|
+
isDefaultImport: element.propertyName?.text === 'default'
|
|
380
|
+
});
|
|
359
381
|
}
|
|
360
382
|
}
|
|
361
|
-
else
|
|
362
|
-
bindings.push(
|
|
383
|
+
else {
|
|
384
|
+
bindings.push({
|
|
385
|
+
range: _getStartEnd(namedBindings.name),
|
|
386
|
+
moduleName,
|
|
387
|
+
isNamespace: true
|
|
388
|
+
});
|
|
363
389
|
}
|
|
364
390
|
}
|
|
365
391
|
}
|
|
@@ -367,61 +393,64 @@ function parseBindingRanges(ts, sourceFile) {
|
|
|
367
393
|
});
|
|
368
394
|
return bindings;
|
|
369
395
|
function _getStartEnd(node) {
|
|
370
|
-
return getStartEnd(ts, node,
|
|
396
|
+
return getStartEnd(ts, node, ast);
|
|
397
|
+
}
|
|
398
|
+
function _getNodeText(node) {
|
|
399
|
+
return getNodeText(ts, node, ast);
|
|
371
400
|
}
|
|
372
401
|
function _findBindingVars(left) {
|
|
373
|
-
return findBindingVars(ts, left,
|
|
402
|
+
return findBindingVars(ts, left, ast);
|
|
374
403
|
}
|
|
375
404
|
}
|
|
376
|
-
function findBindingVars(ts, left,
|
|
405
|
+
function findBindingVars(ts, left, ast) {
|
|
377
406
|
const vars = [];
|
|
378
407
|
worker(left);
|
|
379
408
|
return vars;
|
|
380
|
-
function worker(
|
|
381
|
-
if (ts.isIdentifier(
|
|
382
|
-
vars.push(getStartEnd(ts,
|
|
409
|
+
function worker(node) {
|
|
410
|
+
if (ts.isIdentifier(node)) {
|
|
411
|
+
vars.push(getStartEnd(ts, node, ast));
|
|
383
412
|
}
|
|
384
413
|
// { ? } = ...
|
|
385
414
|
// [ ? ] = ...
|
|
386
|
-
else if (ts.isObjectBindingPattern(
|
|
387
|
-
for (const property of
|
|
415
|
+
else if (ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node)) {
|
|
416
|
+
for (const property of node.elements) {
|
|
388
417
|
if (ts.isBindingElement(property)) {
|
|
389
418
|
worker(property.name);
|
|
390
419
|
}
|
|
391
420
|
}
|
|
392
421
|
}
|
|
393
422
|
// { foo: ? } = ...
|
|
394
|
-
else if (ts.isPropertyAssignment(
|
|
395
|
-
worker(
|
|
423
|
+
else if (ts.isPropertyAssignment(node)) {
|
|
424
|
+
worker(node.initializer);
|
|
396
425
|
}
|
|
397
426
|
// { foo } = ...
|
|
398
|
-
else if (ts.isShorthandPropertyAssignment(
|
|
399
|
-
vars.push(getStartEnd(ts,
|
|
427
|
+
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
428
|
+
vars.push(getStartEnd(ts, node.name, ast));
|
|
400
429
|
}
|
|
401
430
|
// { ...? } = ...
|
|
402
431
|
// [ ...? ] = ...
|
|
403
|
-
else if (ts.isSpreadAssignment(
|
|
404
|
-
worker(
|
|
432
|
+
else if (ts.isSpreadAssignment(node) || ts.isSpreadElement(node)) {
|
|
433
|
+
worker(node.expression);
|
|
405
434
|
}
|
|
406
435
|
}
|
|
407
436
|
}
|
|
408
|
-
function getStartEnd(ts, node,
|
|
437
|
+
function getStartEnd(ts, node, ast) {
|
|
409
438
|
return {
|
|
410
|
-
start: ts.getTokenPosOfNode(node,
|
|
439
|
+
start: ts.getTokenPosOfNode(node, ast),
|
|
411
440
|
end: node.end,
|
|
412
441
|
};
|
|
413
442
|
}
|
|
414
|
-
function getNodeText(ts, node,
|
|
415
|
-
const { start, end } = getStartEnd(ts, node,
|
|
416
|
-
return
|
|
443
|
+
function getNodeText(ts, node, ast) {
|
|
444
|
+
const { start, end } = getStartEnd(ts, node, ast);
|
|
445
|
+
return ast.text.slice(start, end);
|
|
417
446
|
}
|
|
418
|
-
function getStatementRange(ts, parents, node,
|
|
447
|
+
function getStatementRange(ts, parents, node, ast) {
|
|
419
448
|
let statementRange;
|
|
420
449
|
for (let i = parents.length - 1; i >= 0; i--) {
|
|
421
450
|
if (ts.isStatement(parents[i])) {
|
|
422
451
|
const statement = parents[i];
|
|
423
452
|
ts.forEachChild(statement, child => {
|
|
424
|
-
const range = getStartEnd(ts, child,
|
|
453
|
+
const range = getStartEnd(ts, child, ast);
|
|
425
454
|
statementRange ??= range;
|
|
426
455
|
statementRange.end = range.end;
|
|
427
456
|
});
|
|
@@ -429,7 +458,7 @@ function getStatementRange(ts, parents, node, sourceFile) {
|
|
|
429
458
|
}
|
|
430
459
|
}
|
|
431
460
|
if (!statementRange) {
|
|
432
|
-
statementRange = getStartEnd(ts, node,
|
|
461
|
+
statementRange = getStartEnd(ts, node, ast);
|
|
433
462
|
}
|
|
434
463
|
return statementRange;
|
|
435
464
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseVueCompilerOptions = parseVueCompilerOptions;
|
|
4
|
+
const syntaxReg = /^\s*@(?<key>.+?)\s+(?<value>.+?)\s*$/m;
|
|
5
|
+
function parseVueCompilerOptions(comments) {
|
|
6
|
+
const entries = comments
|
|
7
|
+
.map(text => {
|
|
8
|
+
try {
|
|
9
|
+
const match = text.match(syntaxReg);
|
|
10
|
+
if (match) {
|
|
11
|
+
const { key, value } = match.groups ?? {};
|
|
12
|
+
return [key, JSON.parse(value)];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch { }
|
|
16
|
+
;
|
|
17
|
+
})
|
|
18
|
+
.filter(item => !!item);
|
|
19
|
+
if (entries.length) {
|
|
20
|
+
return Object.fromEntries(entries);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=vueCompilerOptions.js.map
|
package/lib/plugins/file-html.js
CHANGED
|
@@ -21,6 +21,7 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
21
21
|
descriptor: {
|
|
22
22
|
filename: fileName,
|
|
23
23
|
source: content,
|
|
24
|
+
comments: [],
|
|
24
25
|
template: null,
|
|
25
26
|
script: null,
|
|
26
27
|
scriptSetup: null,
|
|
@@ -54,8 +55,8 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
// ignore `<script src="...">`
|
|
57
|
-
else if (tag === 'script' && attrs.
|
|
58
|
-
let type = attrs.
|
|
58
|
+
else if (tag === 'script' && !attrs.includes('src=')) {
|
|
59
|
+
let type = attrs.includes('type=') ? 'scriptSetup' : 'script';
|
|
59
60
|
sfc.descriptor[type] = {
|
|
60
61
|
attrs: {},
|
|
61
62
|
content,
|
|
@@ -68,7 +69,7 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
68
69
|
lang,
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
|
-
templateContent = templateContent.
|
|
72
|
+
templateContent = templateContent.slice(0, match.index) + ' '.repeat(matchText.length) + templateContent.slice(match.index + matchText.length);
|
|
72
73
|
}
|
|
73
74
|
sfc.descriptor.template = {
|
|
74
75
|
attrs: {},
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -41,7 +41,7 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
41
41
|
const matchText = match[0];
|
|
42
42
|
codes.push([matchText, undefined, match.index]);
|
|
43
43
|
codes.push('\n\n');
|
|
44
|
-
content = content.
|
|
44
|
+
content = content.slice(0, match.index) + ' '.repeat(matchText.length) + content.slice(match.index + matchText.length);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
content = content
|
package/lib/plugins/file-vue.js
CHANGED
|
@@ -25,19 +25,19 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
25
25
|
sfc.descriptor.scriptSetup,
|
|
26
26
|
...sfc.descriptor.styles,
|
|
27
27
|
...sfc.descriptor.customBlocks,
|
|
28
|
-
].filter(
|
|
28
|
+
].filter(block => !!block);
|
|
29
29
|
const hitBlock = blocks.find(block => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset);
|
|
30
30
|
if (!hitBlock) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
const oldContent = hitBlock.content;
|
|
34
34
|
const newContent = hitBlock.content =
|
|
35
|
-
hitBlock.content.
|
|
35
|
+
hitBlock.content.slice(0, change.start - hitBlock.loc.start.offset)
|
|
36
36
|
+ change.newText
|
|
37
|
-
+ hitBlock.content.
|
|
37
|
+
+ hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
|
|
38
38
|
// #3449
|
|
39
39
|
const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
|
|
40
|
-
const insertedEndTag =
|
|
40
|
+
const insertedEndTag = endTagRegex.test(oldContent) !== endTagRegex.test(newContent);
|
|
41
41
|
if (insertedEndTag) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
@@ -33,12 +33,12 @@ const plugin = () => {
|
|
|
33
33
|
}
|
|
34
34
|
const offset = content.lastIndexOf('\n') + 1;
|
|
35
35
|
// fix folding range end position failed to mapping
|
|
36
|
-
(0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart, sfc.content.
|
|
36
|
+
(0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart, sfc.content.slice(block.startTagEnd, block.startTagEnd + offset), [
|
|
37
37
|
'',
|
|
38
38
|
undefined,
|
|
39
39
|
block.startTagEnd + offset,
|
|
40
40
|
{ structure: true },
|
|
41
|
-
], sfc.content.
|
|
41
|
+
], sfc.content.slice(block.startTagEnd + offset, block.endTagStart));
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
else {
|