@vue/language-core 2.1.10 → 2.2.2
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 +0 -1
- package/index.js +1 -2
- package/lib/codeFeatures.d.ts +1 -0
- package/lib/codeFeatures.js +3 -0
- package/lib/codegen/codeFeatures.d.ts +83 -0
- package/lib/codegen/codeFeatures.js +71 -0
- package/lib/codegen/globalTypes.d.ts +3 -1
- package/lib/codegen/globalTypes.js +39 -14
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +7 -7
- package/lib/codegen/script/binding.d.ts +4 -0
- package/lib/codegen/script/binding.js +41 -0
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +44 -44
- package/lib/codegen/script/componentSelf.d.ts +1 -1
- package/lib/codegen/script/componentSelf.js +14 -14
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/context.js +2 -2
- package/lib/codegen/script/index.d.ts +6 -11
- package/lib/codegen/script/index.js +21 -63
- package/lib/codegen/script/scriptSetup.d.ts +1 -1
- package/lib/codegen/script/scriptSetup.js +236 -205
- package/lib/codegen/script/src.js +8 -8
- package/lib/codegen/script/styleModulesType.d.ts +1 -1
- package/lib/codegen/script/styleModulesType.js +7 -7
- package/lib/codegen/script/template.d.ts +2 -2
- package/lib/codegen/script/template.js +81 -114
- package/lib/codegen/template/context.d.ts +29 -15
- package/lib/codegen/template/context.js +51 -96
- package/lib/codegen/template/element.d.ts +2 -4
- package/lib/codegen/template/element.js +124 -317
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +10 -11
- package/lib/codegen/template/elementDirectives.d.ts +1 -0
- package/lib/codegen/template/elementDirectives.js +43 -30
- package/lib/codegen/template/elementEvents.d.ts +2 -2
- package/lib/codegen/template/elementEvents.js +32 -65
- package/lib/codegen/template/elementProps.d.ts +5 -3
- package/lib/codegen/template/elementProps.js +116 -123
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +67 -69
- package/lib/codegen/template/interpolation.d.ts +5 -3
- package/lib/codegen/template/interpolation.js +30 -27
- 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 +47 -25
- package/lib/codegen/template/styleScopedClasses.d.ts +4 -1
- package/lib/codegen/template/styleScopedClasses.js +152 -8
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +39 -20
- 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/vSlot.d.ts +5 -0
- package/lib/codegen/template/vSlot.js +80 -0
- package/lib/codegen/utils/camelized.d.ts +2 -0
- package/lib/codegen/utils/camelized.js +31 -0
- package/lib/codegen/utils/index.d.ts +21 -0
- package/lib/codegen/utils/index.js +79 -0
- package/lib/codegen/utils/src.d.ts +2 -0
- package/lib/codegen/utils/src.js +19 -0
- 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 +69 -83
- package/lib/parsers/scriptSetupRanges.js +194 -171
- 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-style-class-names.d.ts +5 -0
- package/lib/plugins/vue-style-class-names.js +32 -0
- package/lib/plugins/vue-style-reference-link.d.ts +1 -0
- package/lib/plugins/vue-style-reference-link.js +3 -0
- package/lib/plugins/vue-style-reference-links.d.ts +3 -0
- package/lib/plugins/vue-style-reference-links.js +26 -0
- 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 +66 -17
- package/lib/plugins/vue-tsx.d.ts +126 -92
- package/lib/plugins/vue-tsx.js +114 -97
- package/lib/plugins/vue-vine.d.ts +3 -0
- package/lib/plugins/vue-vine.js +35 -0
- package/lib/types.d.ts +25 -12
- package/lib/utils/buildMappings.d.ts +1 -1
- package/lib/utils/parseCssImports.d.ts +4 -0
- package/lib/utils/parseCssImports.js +19 -0
- package/lib/utils/parseSfc.d.ts +5 -0
- package/lib/utils/parseSfc.js +11 -5
- package/lib/utils/signals.d.ts +2 -0
- package/lib/utils/signals.js +54 -0
- package/lib/utils/ts.d.ts +14 -2
- package/lib/utils/ts.js +134 -91
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
- package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
- package/lib/virtualFile/computedSfc.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +87 -79
- package/lib/virtualFile/computedVueSfc.d.ts +1 -2
- package/lib/virtualFile/computedVueSfc.js +7 -7
- package/lib/virtualFile/vueFile.d.ts +5 -5
- package/lib/virtualFile/vueFile.js +6 -6
- package/package.json +6 -6
- /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,195 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
206
194
|
required,
|
|
207
195
|
});
|
|
208
196
|
}
|
|
209
|
-
else if (vueCompilerOptions.macros.
|
|
210
|
-
|
|
211
|
-
...
|
|
212
|
-
statement: getStatementRange(ts, parents, node, ast)
|
|
197
|
+
else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
|
198
|
+
defineProps = {
|
|
199
|
+
...parseCallExpression(node),
|
|
200
|
+
statement: getStatementRange(ts, parents, node, ast),
|
|
201
|
+
argNode: node.arguments[0]
|
|
213
202
|
};
|
|
214
203
|
if (ts.isVariableDeclaration(parent)) {
|
|
215
|
-
if (ts.
|
|
216
|
-
|
|
204
|
+
if (ts.isObjectBindingPattern(parent.name)) {
|
|
205
|
+
defineProps.destructured = new Map();
|
|
206
|
+
const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name, []);
|
|
207
|
+
for (const { id, isRest, initializer } of identifiers) {
|
|
208
|
+
const name = _getNodeText(id);
|
|
209
|
+
if (isRest) {
|
|
210
|
+
defineProps.destructuredRest = name;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
defineProps.destructured.set(name, initializer);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
217
216
|
}
|
|
218
217
|
else {
|
|
219
|
-
|
|
218
|
+
defineProps.name = _getNodeText(parent.name);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else if (ts.isCallExpression(parent)
|
|
222
|
+
&& vueCompilerOptions.macros.withDefaults.includes(_getNodeText(parent.expression))) {
|
|
223
|
+
const grand = parents.at(-2);
|
|
224
|
+
if (grand && ts.isVariableDeclaration(grand)) {
|
|
225
|
+
defineProps.name = _getNodeText(grand.name);
|
|
220
226
|
}
|
|
221
227
|
}
|
|
222
228
|
}
|
|
229
|
+
else if (vueCompilerOptions.macros.withDefaults.includes(callText)) {
|
|
230
|
+
const [, arg] = node.arguments;
|
|
231
|
+
withDefaults = {
|
|
232
|
+
callExp: _getStartEnd(node),
|
|
233
|
+
exp: _getStartEnd(node.expression),
|
|
234
|
+
arg: arg ? _getStartEnd(arg) : undefined,
|
|
235
|
+
argNode: arg
|
|
236
|
+
};
|
|
237
|
+
}
|
|
223
238
|
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
|
224
|
-
|
|
225
|
-
...
|
|
239
|
+
defineEmits = {
|
|
240
|
+
...parseCallExpression(node),
|
|
226
241
|
statement: getStatementRange(ts, parents, node, ast)
|
|
227
242
|
};
|
|
228
243
|
if (ts.isVariableDeclaration(parent)) {
|
|
229
|
-
|
|
244
|
+
defineEmits.name = _getNodeText(parent.name);
|
|
230
245
|
}
|
|
231
|
-
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])
|
|
246
|
+
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])) {
|
|
232
247
|
for (const member of node.typeArguments[0].members) {
|
|
233
|
-
if (ts.isCallSignatureDeclaration(member)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
|
|
241
|
-
expose.define = parseDefineFunction(node);
|
|
242
|
-
}
|
|
243
|
-
else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
|
244
|
-
if (ts.isVariableDeclaration(parent)) {
|
|
245
|
-
if (ts.isObjectBindingPattern(parent.name)) {
|
|
246
|
-
props.destructured = new Set();
|
|
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);
|
|
248
|
+
if (ts.isCallSignatureDeclaration(member)) {
|
|
249
|
+
const type = member.parameters[0]?.type;
|
|
250
|
+
if (type && ts.isUnionTypeNode(type)) {
|
|
251
|
+
defineEmits.hasUnionTypeArg = true;
|
|
252
|
+
break;
|
|
255
253
|
}
|
|
256
254
|
}
|
|
257
255
|
}
|
|
258
|
-
else {
|
|
259
|
-
props.name = getNodeText(ts, parent.name, ast);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
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
256
|
}
|
|
272
257
|
}
|
|
273
|
-
else if (vueCompilerOptions.macros.
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
258
|
+
else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
|
259
|
+
defineSlots = {
|
|
260
|
+
...parseCallExpression(node),
|
|
261
|
+
statement: getStatementRange(ts, parents, node, ast)
|
|
262
|
+
};
|
|
279
263
|
if (ts.isVariableDeclaration(parent)) {
|
|
280
|
-
|
|
264
|
+
defineSlots.name = _getNodeText(parent.name);
|
|
281
265
|
}
|
|
282
266
|
}
|
|
283
|
-
else if (vueCompilerOptions.macros.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
267
|
+
else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
|
|
268
|
+
defineExpose = parseCallExpression(node);
|
|
269
|
+
}
|
|
270
|
+
else if (vueCompilerOptions.macros.defineOptions.includes(callText)
|
|
271
|
+
&& node.arguments.length
|
|
272
|
+
&& ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
273
|
+
defineOptions = {};
|
|
274
|
+
const obj = node.arguments[0];
|
|
275
|
+
for (const prop of obj.properties) {
|
|
276
|
+
if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {
|
|
277
|
+
const name = _getNodeText(prop.name);
|
|
278
|
+
if (name === 'inheritAttrs') {
|
|
279
|
+
defineOptions.inheritAttrs = _getNodeText(prop.initializer);
|
|
292
280
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if ((ts.isPropertyAssignment(prop)) && getNodeText(ts, prop.name, ast) === 'name' && ts.isStringLiteral(prop.initializer)) {
|
|
296
|
-
options.name = prop.initializer.text;
|
|
281
|
+
else if (name === 'name' && ts.isStringLiteral(prop.initializer)) {
|
|
282
|
+
defineOptions.name = prop.initializer.text;
|
|
297
283
|
}
|
|
298
284
|
}
|
|
299
285
|
}
|
|
300
286
|
}
|
|
301
|
-
else if (vueCompilerOptions.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
define
|
|
310
|
-
});
|
|
287
|
+
else if (vueCompilerOptions.composables.useAttrs.includes(callText)) {
|
|
288
|
+
useAttrs.push(parseCallExpression(node));
|
|
289
|
+
}
|
|
290
|
+
else if (vueCompilerOptions.composables.useCssModule.includes(callText)) {
|
|
291
|
+
useCssModule.push(parseCallExpression(node));
|
|
292
|
+
}
|
|
293
|
+
else if (vueCompilerOptions.composables.useSlots.includes(callText)) {
|
|
294
|
+
useSlots.push(parseCallExpression(node));
|
|
311
295
|
}
|
|
312
|
-
else if (vueCompilerOptions.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
296
|
+
else if (vueCompilerOptions.composables.useTemplateRef.includes(callText)
|
|
297
|
+
&& !node.typeArguments?.length) {
|
|
298
|
+
useTemplateRef.push({
|
|
299
|
+
name: ts.isVariableDeclaration(parent) ? _getNodeText(parent.name) : undefined,
|
|
300
|
+
...parseCallExpression(node)
|
|
316
301
|
});
|
|
317
302
|
}
|
|
318
303
|
}
|
|
319
304
|
ts.forEachChild(node, child => {
|
|
305
|
+
if (ts.isFunctionLike(node)) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
320
308
|
parents.push(node);
|
|
321
309
|
visitNode(child, parents);
|
|
322
310
|
parents.pop();
|
|
323
311
|
});
|
|
324
312
|
}
|
|
313
|
+
function parseCallExpression(node) {
|
|
314
|
+
return {
|
|
315
|
+
callExp: _getStartEnd(node),
|
|
316
|
+
exp: _getStartEnd(node.expression),
|
|
317
|
+
arg: node.arguments.length ? _getStartEnd(node.arguments[0]) : undefined,
|
|
318
|
+
typeArg: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function _getStartEnd(node) {
|
|
322
|
+
return getStartEnd(ts, node, ast);
|
|
323
|
+
}
|
|
324
|
+
function _getNodeText(node) {
|
|
325
|
+
return getNodeText(ts, node, ast);
|
|
326
|
+
}
|
|
325
327
|
}
|
|
326
|
-
function parseBindingRanges(ts,
|
|
328
|
+
function parseBindingRanges(ts, ast) {
|
|
327
329
|
const bindings = [];
|
|
328
|
-
ts.forEachChild(
|
|
330
|
+
ts.forEachChild(ast, node => {
|
|
329
331
|
if (ts.isVariableStatement(node)) {
|
|
330
|
-
for (const
|
|
331
|
-
const vars = _findBindingVars(
|
|
332
|
-
|
|
333
|
-
bindings.push(_var);
|
|
334
|
-
}
|
|
332
|
+
for (const decl of node.declarationList.declarations) {
|
|
333
|
+
const vars = _findBindingVars(decl.name);
|
|
334
|
+
bindings.push(...vars.map(range => ({ range })));
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
else if (ts.isFunctionDeclaration(node)) {
|
|
338
338
|
if (node.name && ts.isIdentifier(node.name)) {
|
|
339
|
-
bindings.push(
|
|
339
|
+
bindings.push({
|
|
340
|
+
range: _getStartEnd(node.name)
|
|
341
|
+
});
|
|
340
342
|
}
|
|
341
343
|
}
|
|
342
344
|
else if (ts.isClassDeclaration(node)) {
|
|
343
345
|
if (node.name) {
|
|
344
|
-
bindings.push(
|
|
346
|
+
bindings.push({
|
|
347
|
+
range: _getStartEnd(node.name)
|
|
348
|
+
});
|
|
345
349
|
}
|
|
346
350
|
}
|
|
347
351
|
else if (ts.isEnumDeclaration(node)) {
|
|
348
|
-
bindings.push(
|
|
352
|
+
bindings.push({
|
|
353
|
+
range: _getStartEnd(node.name)
|
|
354
|
+
});
|
|
349
355
|
}
|
|
350
356
|
if (ts.isImportDeclaration(node)) {
|
|
357
|
+
const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
|
|
351
358
|
if (node.importClause && !node.importClause.isTypeOnly) {
|
|
352
|
-
|
|
353
|
-
|
|
359
|
+
const { name, namedBindings } = node.importClause;
|
|
360
|
+
if (name) {
|
|
361
|
+
bindings.push({
|
|
362
|
+
range: _getStartEnd(name),
|
|
363
|
+
moduleName,
|
|
364
|
+
isDefaultImport: true
|
|
365
|
+
});
|
|
354
366
|
}
|
|
355
|
-
if (
|
|
356
|
-
if (ts.isNamedImports(
|
|
357
|
-
for (const element of
|
|
367
|
+
if (namedBindings) {
|
|
368
|
+
if (ts.isNamedImports(namedBindings)) {
|
|
369
|
+
for (const element of namedBindings.elements) {
|
|
358
370
|
if (element.isTypeOnly) {
|
|
359
371
|
continue;
|
|
360
372
|
}
|
|
361
|
-
bindings.push(
|
|
373
|
+
bindings.push({
|
|
374
|
+
range: _getStartEnd(element.name),
|
|
375
|
+
moduleName,
|
|
376
|
+
isDefaultImport: element.propertyName?.text === 'default'
|
|
377
|
+
});
|
|
362
378
|
}
|
|
363
379
|
}
|
|
364
|
-
else
|
|
365
|
-
bindings.push(
|
|
380
|
+
else {
|
|
381
|
+
bindings.push({
|
|
382
|
+
range: _getStartEnd(namedBindings.name),
|
|
383
|
+
moduleName,
|
|
384
|
+
isNamespace: true
|
|
385
|
+
});
|
|
366
386
|
}
|
|
367
387
|
}
|
|
368
388
|
}
|
|
@@ -370,61 +390,64 @@ function parseBindingRanges(ts, sourceFile) {
|
|
|
370
390
|
});
|
|
371
391
|
return bindings;
|
|
372
392
|
function _getStartEnd(node) {
|
|
373
|
-
return getStartEnd(ts, node,
|
|
393
|
+
return getStartEnd(ts, node, ast);
|
|
394
|
+
}
|
|
395
|
+
function _getNodeText(node) {
|
|
396
|
+
return getNodeText(ts, node, ast);
|
|
374
397
|
}
|
|
375
398
|
function _findBindingVars(left) {
|
|
376
|
-
return findBindingVars(ts, left,
|
|
399
|
+
return findBindingVars(ts, left, ast);
|
|
377
400
|
}
|
|
378
401
|
}
|
|
379
|
-
function findBindingVars(ts, left,
|
|
402
|
+
function findBindingVars(ts, left, ast) {
|
|
380
403
|
const vars = [];
|
|
381
404
|
worker(left);
|
|
382
405
|
return vars;
|
|
383
|
-
function worker(
|
|
384
|
-
if (ts.isIdentifier(
|
|
385
|
-
vars.push(getStartEnd(ts,
|
|
406
|
+
function worker(node) {
|
|
407
|
+
if (ts.isIdentifier(node)) {
|
|
408
|
+
vars.push(getStartEnd(ts, node, ast));
|
|
386
409
|
}
|
|
387
410
|
// { ? } = ...
|
|
388
411
|
// [ ? ] = ...
|
|
389
|
-
else if (ts.isObjectBindingPattern(
|
|
390
|
-
for (const property of
|
|
412
|
+
else if (ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node)) {
|
|
413
|
+
for (const property of node.elements) {
|
|
391
414
|
if (ts.isBindingElement(property)) {
|
|
392
415
|
worker(property.name);
|
|
393
416
|
}
|
|
394
417
|
}
|
|
395
418
|
}
|
|
396
419
|
// { foo: ? } = ...
|
|
397
|
-
else if (ts.isPropertyAssignment(
|
|
398
|
-
worker(
|
|
420
|
+
else if (ts.isPropertyAssignment(node)) {
|
|
421
|
+
worker(node.initializer);
|
|
399
422
|
}
|
|
400
423
|
// { foo } = ...
|
|
401
|
-
else if (ts.isShorthandPropertyAssignment(
|
|
402
|
-
vars.push(getStartEnd(ts,
|
|
424
|
+
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
425
|
+
vars.push(getStartEnd(ts, node.name, ast));
|
|
403
426
|
}
|
|
404
427
|
// { ...? } = ...
|
|
405
428
|
// [ ...? ] = ...
|
|
406
|
-
else if (ts.isSpreadAssignment(
|
|
407
|
-
worker(
|
|
429
|
+
else if (ts.isSpreadAssignment(node) || ts.isSpreadElement(node)) {
|
|
430
|
+
worker(node.expression);
|
|
408
431
|
}
|
|
409
432
|
}
|
|
410
433
|
}
|
|
411
|
-
function getStartEnd(ts, node,
|
|
434
|
+
function getStartEnd(ts, node, ast) {
|
|
412
435
|
return {
|
|
413
|
-
start: ts.getTokenPosOfNode(node,
|
|
436
|
+
start: ts.getTokenPosOfNode(node, ast),
|
|
414
437
|
end: node.end,
|
|
415
438
|
};
|
|
416
439
|
}
|
|
417
|
-
function getNodeText(ts, node,
|
|
418
|
-
const { start, end } = getStartEnd(ts, node,
|
|
419
|
-
return
|
|
440
|
+
function getNodeText(ts, node, ast) {
|
|
441
|
+
const { start, end } = getStartEnd(ts, node, ast);
|
|
442
|
+
return ast.text.slice(start, end);
|
|
420
443
|
}
|
|
421
|
-
function getStatementRange(ts, parents, node,
|
|
444
|
+
function getStatementRange(ts, parents, node, ast) {
|
|
422
445
|
let statementRange;
|
|
423
446
|
for (let i = parents.length - 1; i >= 0; i--) {
|
|
424
447
|
if (ts.isStatement(parents[i])) {
|
|
425
448
|
const statement = parents[i];
|
|
426
449
|
ts.forEachChild(statement, child => {
|
|
427
|
-
const range = getStartEnd(ts, child,
|
|
450
|
+
const range = getStartEnd(ts, child, ast);
|
|
428
451
|
statementRange ??= range;
|
|
429
452
|
statementRange.end = range.end;
|
|
430
453
|
});
|
|
@@ -432,7 +455,7 @@ function getStatementRange(ts, parents, node, sourceFile) {
|
|
|
432
455
|
}
|
|
433
456
|
}
|
|
434
457
|
if (!statementRange) {
|
|
435
|
-
statementRange = getStartEnd(ts, node,
|
|
458
|
+
statementRange = getStartEnd(ts, node, ast);
|
|
436
459
|
}
|
|
437
460
|
return statementRange;
|
|
438
461
|
}
|
|
@@ -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 {
|