@vue/language-core 2.1.10 → 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 +11 -2
- package/lib/codegen/localTypes.js +3 -3
- package/lib/codegen/script/component.js +42 -42
- package/lib/codegen/script/componentSelf.js +13 -13
- package/lib/codegen/script/context.js +2 -2
- package/lib/codegen/script/index.d.ts +5 -3
- package/lib/codegen/script/index.js +19 -37
- package/lib/codegen/script/scriptSetup.js +240 -197
- 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 +86 -98
- 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 -83
- package/lib/parsers/scriptSetupRanges.js +193 -167
- 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 -74
- package/lib/plugins/vue-tsx.js +65 -68
- 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/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,163 +194,198 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
206
194
|
required,
|
|
207
195
|
});
|
|
208
196
|
}
|
|
209
|
-
else if (vueCompilerOptions.macros.
|
|
210
|
-
|
|
211
|
-
...
|
|
197
|
+
else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
|
198
|
+
defineProps = {
|
|
199
|
+
...parseCallExpression(node),
|
|
212
200
|
statement: getStatementRange(ts, parents, node, ast)
|
|
213
201
|
};
|
|
214
202
|
if (ts.isVariableDeclaration(parent)) {
|
|
215
|
-
if (ts.
|
|
216
|
-
|
|
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
|
+
}
|
|
217
215
|
}
|
|
218
216
|
else {
|
|
219
|
-
|
|
217
|
+
defineProps.name = _getNodeText(parent.name);
|
|
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);
|
|
220
225
|
}
|
|
221
226
|
}
|
|
222
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
|
+
};
|
|
235
|
+
}
|
|
223
236
|
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
|
224
|
-
|
|
225
|
-
...
|
|
237
|
+
defineEmits = {
|
|
238
|
+
...parseCallExpression(node),
|
|
226
239
|
statement: getStatementRange(ts, parents, node, ast)
|
|
227
240
|
};
|
|
228
241
|
if (ts.isVariableDeclaration(parent)) {
|
|
229
|
-
|
|
242
|
+
defineEmits.name = _getNodeText(parent.name);
|
|
230
243
|
}
|
|
231
|
-
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])
|
|
244
|
+
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])) {
|
|
232
245
|
for (const member of node.typeArguments[0].members) {
|
|
233
|
-
if (ts.isCallSignatureDeclaration(member)
|
|
234
|
-
|
|
235
|
-
|
|
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
|
+
}
|
|
236
252
|
}
|
|
237
253
|
}
|
|
238
254
|
}
|
|
239
255
|
}
|
|
240
|
-
else if (vueCompilerOptions.macros.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
256
|
+
else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
|
257
|
+
defineSlots = {
|
|
258
|
+
...parseCallExpression(node),
|
|
259
|
+
statement: getStatementRange(ts, parents, node, ast)
|
|
260
|
+
};
|
|
244
261
|
if (ts.isVariableDeclaration(parent)) {
|
|
245
|
-
if (ts.
|
|
246
|
-
|
|
247
|
-
const identifiers = (0, common_1.collectIdentifiers)(ts, parent.name, []);
|
|
248
|
-
for (const [id, isRest] of identifiers) {
|
|
249
|
-
const name = getNodeText(ts, id, ast);
|
|
250
|
-
if (isRest) {
|
|
251
|
-
props.destructuredRest = name;
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
props.destructured.add(name);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
262
|
+
if (ts.isIdentifier(parent.name)) {
|
|
263
|
+
defineSlots.name = _getNodeText(parent.name);
|
|
257
264
|
}
|
|
258
265
|
else {
|
|
259
|
-
|
|
266
|
+
defineSlots.isObjectBindingPattern = ts.isObjectBindingPattern(parent.name);
|
|
260
267
|
}
|
|
261
268
|
}
|
|
262
|
-
props.define = {
|
|
263
|
-
...parseDefineFunction(node),
|
|
264
|
-
statement: getStatementRange(ts, parents, node, ast),
|
|
265
|
-
};
|
|
266
|
-
if (node.arguments.length) {
|
|
267
|
-
props.define.arg = _getStartEnd(node.arguments[0]);
|
|
268
|
-
}
|
|
269
|
-
if (node.typeArguments?.length) {
|
|
270
|
-
props.define.typeArg = _getStartEnd(node.typeArguments[0]);
|
|
271
|
-
}
|
|
272
269
|
}
|
|
273
|
-
else if (vueCompilerOptions.macros.
|
|
274
|
-
|
|
275
|
-
if (node.arguments.length >= 2) {
|
|
276
|
-
const arg = node.arguments[1];
|
|
277
|
-
props.withDefaults.arg = _getStartEnd(arg);
|
|
278
|
-
}
|
|
279
|
-
if (ts.isVariableDeclaration(parent)) {
|
|
280
|
-
props.name = getNodeText(ts, parent.name, ast);
|
|
281
|
-
}
|
|
270
|
+
else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
|
|
271
|
+
defineExpose = parseCallExpression(node);
|
|
282
272
|
}
|
|
283
|
-
else if (vueCompilerOptions.macros.defineOptions.includes(callText)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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);
|
|
292
283
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if ((ts.isPropertyAssignment(prop)) && getNodeText(ts, prop.name, ast) === 'name' && ts.isStringLiteral(prop.initializer)) {
|
|
296
|
-
options.name = prop.initializer.text;
|
|
284
|
+
else if (name === 'name' && ts.isStringLiteral(prop.initializer)) {
|
|
285
|
+
defineOptions.name = prop.initializer.text;
|
|
297
286
|
}
|
|
298
287
|
}
|
|
299
288
|
}
|
|
300
289
|
}
|
|
301
|
-
else if (vueCompilerOptions.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
define
|
|
310
|
-
});
|
|
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));
|
|
311
298
|
}
|
|
312
|
-
else if (vueCompilerOptions.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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)
|
|
316
304
|
});
|
|
317
305
|
}
|
|
318
306
|
}
|
|
319
307
|
ts.forEachChild(node, child => {
|
|
308
|
+
if (ts.isFunctionLike(node)) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
320
311
|
parents.push(node);
|
|
321
312
|
visitNode(child, parents);
|
|
322
313
|
parents.pop();
|
|
323
314
|
});
|
|
324
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
|
+
}
|
|
325
330
|
}
|
|
326
|
-
function parseBindingRanges(ts,
|
|
331
|
+
function parseBindingRanges(ts, ast) {
|
|
327
332
|
const bindings = [];
|
|
328
|
-
ts.forEachChild(
|
|
333
|
+
ts.forEachChild(ast, node => {
|
|
329
334
|
if (ts.isVariableStatement(node)) {
|
|
330
|
-
for (const
|
|
331
|
-
const vars = _findBindingVars(
|
|
332
|
-
|
|
333
|
-
bindings.push(_var);
|
|
334
|
-
}
|
|
335
|
+
for (const decl of node.declarationList.declarations) {
|
|
336
|
+
const vars = _findBindingVars(decl.name);
|
|
337
|
+
bindings.push(...vars.map(range => ({ range })));
|
|
335
338
|
}
|
|
336
339
|
}
|
|
337
340
|
else if (ts.isFunctionDeclaration(node)) {
|
|
338
341
|
if (node.name && ts.isIdentifier(node.name)) {
|
|
339
|
-
bindings.push(
|
|
342
|
+
bindings.push({
|
|
343
|
+
range: _getStartEnd(node.name)
|
|
344
|
+
});
|
|
340
345
|
}
|
|
341
346
|
}
|
|
342
347
|
else if (ts.isClassDeclaration(node)) {
|
|
343
348
|
if (node.name) {
|
|
344
|
-
bindings.push(
|
|
349
|
+
bindings.push({
|
|
350
|
+
range: _getStartEnd(node.name)
|
|
351
|
+
});
|
|
345
352
|
}
|
|
346
353
|
}
|
|
347
354
|
else if (ts.isEnumDeclaration(node)) {
|
|
348
|
-
bindings.push(
|
|
355
|
+
bindings.push({
|
|
356
|
+
range: _getStartEnd(node.name)
|
|
357
|
+
});
|
|
349
358
|
}
|
|
350
359
|
if (ts.isImportDeclaration(node)) {
|
|
360
|
+
const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
|
|
351
361
|
if (node.importClause && !node.importClause.isTypeOnly) {
|
|
352
|
-
|
|
353
|
-
|
|
362
|
+
const { name, namedBindings } = node.importClause;
|
|
363
|
+
if (name) {
|
|
364
|
+
bindings.push({
|
|
365
|
+
range: _getStartEnd(name),
|
|
366
|
+
moduleName,
|
|
367
|
+
isDefaultImport: true
|
|
368
|
+
});
|
|
354
369
|
}
|
|
355
|
-
if (
|
|
356
|
-
if (ts.isNamedImports(
|
|
357
|
-
for (const element of
|
|
370
|
+
if (namedBindings) {
|
|
371
|
+
if (ts.isNamedImports(namedBindings)) {
|
|
372
|
+
for (const element of namedBindings.elements) {
|
|
358
373
|
if (element.isTypeOnly) {
|
|
359
374
|
continue;
|
|
360
375
|
}
|
|
361
|
-
bindings.push(
|
|
376
|
+
bindings.push({
|
|
377
|
+
range: _getStartEnd(element.name),
|
|
378
|
+
moduleName,
|
|
379
|
+
isDefaultImport: element.propertyName?.text === 'default'
|
|
380
|
+
});
|
|
362
381
|
}
|
|
363
382
|
}
|
|
364
|
-
else
|
|
365
|
-
bindings.push(
|
|
383
|
+
else {
|
|
384
|
+
bindings.push({
|
|
385
|
+
range: _getStartEnd(namedBindings.name),
|
|
386
|
+
moduleName,
|
|
387
|
+
isNamespace: true
|
|
388
|
+
});
|
|
366
389
|
}
|
|
367
390
|
}
|
|
368
391
|
}
|
|
@@ -370,61 +393,64 @@ function parseBindingRanges(ts, sourceFile) {
|
|
|
370
393
|
});
|
|
371
394
|
return bindings;
|
|
372
395
|
function _getStartEnd(node) {
|
|
373
|
-
return getStartEnd(ts, node,
|
|
396
|
+
return getStartEnd(ts, node, ast);
|
|
397
|
+
}
|
|
398
|
+
function _getNodeText(node) {
|
|
399
|
+
return getNodeText(ts, node, ast);
|
|
374
400
|
}
|
|
375
401
|
function _findBindingVars(left) {
|
|
376
|
-
return findBindingVars(ts, left,
|
|
402
|
+
return findBindingVars(ts, left, ast);
|
|
377
403
|
}
|
|
378
404
|
}
|
|
379
|
-
function findBindingVars(ts, left,
|
|
405
|
+
function findBindingVars(ts, left, ast) {
|
|
380
406
|
const vars = [];
|
|
381
407
|
worker(left);
|
|
382
408
|
return vars;
|
|
383
|
-
function worker(
|
|
384
|
-
if (ts.isIdentifier(
|
|
385
|
-
vars.push(getStartEnd(ts,
|
|
409
|
+
function worker(node) {
|
|
410
|
+
if (ts.isIdentifier(node)) {
|
|
411
|
+
vars.push(getStartEnd(ts, node, ast));
|
|
386
412
|
}
|
|
387
413
|
// { ? } = ...
|
|
388
414
|
// [ ? ] = ...
|
|
389
|
-
else if (ts.isObjectBindingPattern(
|
|
390
|
-
for (const property of
|
|
415
|
+
else if (ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node)) {
|
|
416
|
+
for (const property of node.elements) {
|
|
391
417
|
if (ts.isBindingElement(property)) {
|
|
392
418
|
worker(property.name);
|
|
393
419
|
}
|
|
394
420
|
}
|
|
395
421
|
}
|
|
396
422
|
// { foo: ? } = ...
|
|
397
|
-
else if (ts.isPropertyAssignment(
|
|
398
|
-
worker(
|
|
423
|
+
else if (ts.isPropertyAssignment(node)) {
|
|
424
|
+
worker(node.initializer);
|
|
399
425
|
}
|
|
400
426
|
// { foo } = ...
|
|
401
|
-
else if (ts.isShorthandPropertyAssignment(
|
|
402
|
-
vars.push(getStartEnd(ts,
|
|
427
|
+
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
428
|
+
vars.push(getStartEnd(ts, node.name, ast));
|
|
403
429
|
}
|
|
404
430
|
// { ...? } = ...
|
|
405
431
|
// [ ...? ] = ...
|
|
406
|
-
else if (ts.isSpreadAssignment(
|
|
407
|
-
worker(
|
|
432
|
+
else if (ts.isSpreadAssignment(node) || ts.isSpreadElement(node)) {
|
|
433
|
+
worker(node.expression);
|
|
408
434
|
}
|
|
409
435
|
}
|
|
410
436
|
}
|
|
411
|
-
function getStartEnd(ts, node,
|
|
437
|
+
function getStartEnd(ts, node, ast) {
|
|
412
438
|
return {
|
|
413
|
-
start: ts.getTokenPosOfNode(node,
|
|
439
|
+
start: ts.getTokenPosOfNode(node, ast),
|
|
414
440
|
end: node.end,
|
|
415
441
|
};
|
|
416
442
|
}
|
|
417
|
-
function getNodeText(ts, node,
|
|
418
|
-
const { start, end } = getStartEnd(ts, node,
|
|
419
|
-
return
|
|
443
|
+
function getNodeText(ts, node, ast) {
|
|
444
|
+
const { start, end } = getStartEnd(ts, node, ast);
|
|
445
|
+
return ast.text.slice(start, end);
|
|
420
446
|
}
|
|
421
|
-
function getStatementRange(ts, parents, node,
|
|
447
|
+
function getStatementRange(ts, parents, node, ast) {
|
|
422
448
|
let statementRange;
|
|
423
449
|
for (let i = parents.length - 1; i >= 0; i--) {
|
|
424
450
|
if (ts.isStatement(parents[i])) {
|
|
425
451
|
const statement = parents[i];
|
|
426
452
|
ts.forEachChild(statement, child => {
|
|
427
|
-
const range = getStartEnd(ts, child,
|
|
453
|
+
const range = getStartEnd(ts, child, ast);
|
|
428
454
|
statementRange ??= range;
|
|
429
455
|
statementRange.end = range.end;
|
|
430
456
|
});
|
|
@@ -432,7 +458,7 @@ function getStatementRange(ts, parents, node, sourceFile) {
|
|
|
432
458
|
}
|
|
433
459
|
}
|
|
434
460
|
if (!statementRange) {
|
|
435
|
-
statementRange = getStartEnd(ts, node,
|
|
461
|
+
statementRange = getStartEnd(ts, node, ast);
|
|
436
462
|
}
|
|
437
463
|
return statementRange;
|
|
438
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 {
|