@vue/language-core 2.0.10 → 2.0.12
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/generators/template.js +40 -21
- package/package.json +3 -3
|
@@ -68,7 +68,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
68
68
|
if (expectErrorToken) {
|
|
69
69
|
const token = expectErrorToken;
|
|
70
70
|
const data = code[3];
|
|
71
|
-
if (data.verification) {
|
|
71
|
+
if (data.verification && (typeof data.verification !== 'object' || !data.verification.shouldReport)) {
|
|
72
72
|
code[3] = {
|
|
73
73
|
...data,
|
|
74
74
|
verification: {
|
|
@@ -102,7 +102,6 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
102
102
|
let hasSlot = false;
|
|
103
103
|
let ignoreError = false;
|
|
104
104
|
let expectErrorToken;
|
|
105
|
-
let expectedErrorNode;
|
|
106
105
|
let elementIndex = 0;
|
|
107
106
|
if (slotsAssignName) {
|
|
108
107
|
localVars.set(slotsAssignName, 1);
|
|
@@ -166,13 +165,13 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
166
165
|
}
|
|
167
166
|
return tagOffsetsMap;
|
|
168
167
|
}
|
|
169
|
-
function*
|
|
170
|
-
if (expectErrorToken
|
|
168
|
+
function* resetDirectiveComments(endStr) {
|
|
169
|
+
if (expectErrorToken) {
|
|
171
170
|
const token = expectErrorToken;
|
|
172
171
|
yield _ts([
|
|
173
172
|
'',
|
|
174
173
|
'template',
|
|
175
|
-
|
|
174
|
+
expectErrorToken.node.loc.start.offset,
|
|
176
175
|
(0, utils_1.disableAllFeatures)({
|
|
177
176
|
verification: {
|
|
178
177
|
shouldReport: () => token.errors === 0,
|
|
@@ -183,14 +182,17 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
183
182
|
yield _ts([
|
|
184
183
|
'',
|
|
185
184
|
'template',
|
|
186
|
-
|
|
185
|
+
expectErrorToken.node.loc.end.offset,
|
|
187
186
|
(0, utils_1.disableAllFeatures)({ __combineLastMapping: true }),
|
|
188
187
|
]);
|
|
189
188
|
yield _ts('\n;\n');
|
|
189
|
+
expectErrorToken = undefined;
|
|
190
|
+
yield _ts(`// @vue-expect-error ${endStr}\n`);
|
|
191
|
+
}
|
|
192
|
+
if (ignoreError) {
|
|
193
|
+
ignoreError = false;
|
|
194
|
+
yield _ts(`// @vue-ignore ${endStr}\n`);
|
|
190
195
|
}
|
|
191
|
-
ignoreError = false;
|
|
192
|
-
expectErrorToken = undefined;
|
|
193
|
-
expectedErrorNode = undefined;
|
|
194
196
|
}
|
|
195
197
|
function* generateCanonicalComponentName(tagText, offset, info) {
|
|
196
198
|
if (validTsVarReg.test(tagText)) {
|
|
@@ -292,18 +294,22 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
292
294
|
}
|
|
293
295
|
}
|
|
294
296
|
function* generateAstNode(node, parentEl, prevNode, componentCtxVar) {
|
|
295
|
-
yield* generateExpectErrorComment();
|
|
296
297
|
if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
297
298
|
const commentText = prevNode.content.trim().split(' ')[0];
|
|
298
299
|
if (commentText.match(/^@vue-skip\b[\s\S]*/)) {
|
|
300
|
+
yield _ts('// @vue-skip\n');
|
|
299
301
|
return;
|
|
300
302
|
}
|
|
301
|
-
else if (commentText.match(/^@vue-ignore\b[\s\S]*/)) {
|
|
303
|
+
else if (commentText.match(/^@vue-ignore\b[\s\S]*/) && !ignoreError) {
|
|
302
304
|
ignoreError = true;
|
|
305
|
+
yield _ts('// @vue-ignore start\n');
|
|
303
306
|
}
|
|
304
|
-
else if (commentText.match(/^@vue-expect-error\b[\s\S]*/)) {
|
|
305
|
-
expectErrorToken = {
|
|
306
|
-
|
|
307
|
+
else if (commentText.match(/^@vue-expect-error\b[\s\S]*/) && !expectErrorToken) {
|
|
308
|
+
expectErrorToken = {
|
|
309
|
+
errors: 0,
|
|
310
|
+
node: prevNode,
|
|
311
|
+
};
|
|
312
|
+
yield _ts('// @vue-expect-error start\n');
|
|
307
313
|
}
|
|
308
314
|
}
|
|
309
315
|
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
@@ -312,7 +318,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
312
318
|
yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
|
|
313
319
|
prev = childNode;
|
|
314
320
|
}
|
|
315
|
-
yield*
|
|
321
|
+
yield* resetDirectiveComments('end of root');
|
|
316
322
|
}
|
|
317
323
|
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
318
324
|
const vForNode = getVForNode(node);
|
|
@@ -343,6 +349,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
343
349
|
// {{ ... }}
|
|
344
350
|
const [content, start] = parseInterpolationNode(node, template.content);
|
|
345
351
|
yield* generateInterpolation(content, node.content.loc, start, presetInfos.all, '(', ');\n');
|
|
352
|
+
yield* resetDirectiveComments('end of INTERPOLATION');
|
|
346
353
|
}
|
|
347
354
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
348
355
|
// v-if / v-else-if / v-else
|
|
@@ -374,16 +381,18 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
374
381
|
yield _ts(` `);
|
|
375
382
|
yield* generateInterpolation(branch.condition.content, branch.condition.loc, branch.condition.loc.start.offset, presetInfos.all, '(', ')');
|
|
376
383
|
blockConditions.push((0, language_core_1.toString)([...generateInterpolation(branch.condition.content, branch.condition.loc, undefined, undefined, '(', ')')]
|
|
377
|
-
.map(code => code
|
|
384
|
+
.map(([code]) => code)));
|
|
378
385
|
addedBlockCondition = true;
|
|
379
386
|
}
|
|
380
387
|
yield _ts(` {\n`);
|
|
388
|
+
if (isFragment(node)) {
|
|
389
|
+
yield* resetDirectiveComments('end of v-if start');
|
|
390
|
+
}
|
|
381
391
|
let prev;
|
|
382
392
|
for (const childNode of branch.children) {
|
|
383
393
|
yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
|
|
384
394
|
prev = childNode;
|
|
385
395
|
}
|
|
386
|
-
yield* generateExpectErrorComment();
|
|
387
396
|
yield* generateExtraAutoImport();
|
|
388
397
|
yield _ts('}\n');
|
|
389
398
|
if (addedBlockCondition) {
|
|
@@ -411,12 +420,14 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
411
420
|
yield* generateInterpolation(source.content, source.loc, source.loc.start.offset, presetInfos.all, '(', ')');
|
|
412
421
|
yield _ts('!)'); // #3102
|
|
413
422
|
yield _ts(') {\n');
|
|
423
|
+
if (isFragment(node)) {
|
|
424
|
+
yield* resetDirectiveComments('end of v-for start');
|
|
425
|
+
}
|
|
414
426
|
let prev;
|
|
415
427
|
for (const childNode of node.children) {
|
|
416
428
|
yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
|
|
417
429
|
prev = childNode;
|
|
418
430
|
}
|
|
419
|
-
yield* generateExpectErrorComment();
|
|
420
431
|
yield* generateExtraAutoImport();
|
|
421
432
|
yield _ts('}\n');
|
|
422
433
|
}
|
|
@@ -608,6 +619,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
608
619
|
}
|
|
609
620
|
const slotBlockVars = [];
|
|
610
621
|
yield _ts(`{\n`);
|
|
622
|
+
yield* resetDirectiveComments('end of element slot start');
|
|
611
623
|
let hasProps = false;
|
|
612
624
|
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
613
625
|
const slotAst = createTsAst(ts, slotDir, `(${slotDir.exp.content}) => {}`);
|
|
@@ -658,8 +670,6 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
658
670
|
yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
|
|
659
671
|
prev = childNode;
|
|
660
672
|
}
|
|
661
|
-
yield* generateExpectErrorComment();
|
|
662
|
-
yield* generateExtraAutoImport();
|
|
663
673
|
slotBlockVars.forEach(varName => {
|
|
664
674
|
localVars.set(varName, localVars.get(varName) - 1);
|
|
665
675
|
});
|
|
@@ -680,15 +690,16 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
680
690
|
]);
|
|
681
691
|
yield _ts(`'/* empty slot name completion */]\n`);
|
|
682
692
|
}
|
|
693
|
+
yield* generateExtraAutoImport();
|
|
683
694
|
yield _ts(`}\n`);
|
|
684
695
|
}
|
|
685
696
|
else {
|
|
697
|
+
yield* resetDirectiveComments('end of element children start');
|
|
686
698
|
let prev;
|
|
687
699
|
for (const childNode of node.children) {
|
|
688
700
|
yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
|
|
689
701
|
prev = childNode;
|
|
690
702
|
}
|
|
691
|
-
yield* generateExpectErrorComment();
|
|
692
703
|
// fix https://github.com/vuejs/language-tools/issues/932
|
|
693
704
|
if (!hasSlotElements.has(node) && node.children.length) {
|
|
694
705
|
yield _ts(`(${componentCtxVar}.slots!).`);
|
|
@@ -1187,8 +1198,13 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
1187
1198
|
}
|
|
1188
1199
|
yield _ts('// @ts-ignore\n'); // #2304
|
|
1189
1200
|
yield _ts('[');
|
|
1201
|
+
const visited = new Set();
|
|
1190
1202
|
for (const _vars of tempVars) {
|
|
1191
1203
|
for (const v of _vars) {
|
|
1204
|
+
if (visited.has(v.offset)) {
|
|
1205
|
+
continue;
|
|
1206
|
+
}
|
|
1207
|
+
visited.add(v.offset);
|
|
1192
1208
|
yield _ts([
|
|
1193
1209
|
v.text,
|
|
1194
1210
|
'template',
|
|
@@ -1343,6 +1359,9 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
|
|
|
1343
1359
|
}
|
|
1344
1360
|
}
|
|
1345
1361
|
exports.generate = generate;
|
|
1362
|
+
function isFragment(node) {
|
|
1363
|
+
return node.codegenNode && 'consequent' in node.codegenNode && 'tag' in node.codegenNode.consequent && node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
|
|
1364
|
+
}
|
|
1346
1365
|
function createTsAst(ts, astHolder, text) {
|
|
1347
1366
|
if (astHolder.__volar_ast_text !== text) {
|
|
1348
1367
|
astHolder.__volar_ast_text = text;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/language-core"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "
|
|
15
|
+
"@volar/language-core": "2.2.0-alpha.7",
|
|
16
16
|
"@vue/compiler-dom": "^3.4.0",
|
|
17
17
|
"@vue/shared": "^3.4.0",
|
|
18
18
|
"computeds": "^0.0.1",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"optional": true
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "c1c4e1a2a6c32da59351641bd41bf7f5db0cac69"
|
|
38
38
|
}
|