@vue/language-core 1.8.19 → 1.8.21
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/out/generators/script.d.ts +2 -1
- package/out/generators/script.js +112 -117
- package/out/generators/template.d.ts +1 -1
- package/out/generators/template.js +54 -83
- package/out/index.d.ts +1 -1
- package/out/index.js +3 -15
- package/out/languageModule.d.ts +1 -1
- package/out/languageModule.js +3 -26
- package/out/plugins/vue-tsx.d.ts +9 -9
- package/out/plugins/vue-tsx.js +49 -52
- package/out/plugins.d.ts +1 -1
- package/out/plugins.js +11 -37
- package/out/types.d.ts +21 -6
- package/out/utils/globalTypes.js +7 -0
- package/out/utils/parseSfc.js +1 -24
- package/out/utils/transform.d.ts +1 -1
- package/out/utils/transform.js +8 -8
- package/out/utils/ts.js +1 -24
- package/out/utils/vue2TemplateCompiler.js +1 -24
- package/out/virtualFile/computedFiles.d.ts +4 -0
- package/out/virtualFile/computedFiles.js +204 -0
- package/out/virtualFile/computedMappings.d.ts +6 -0
- package/out/virtualFile/computedMappings.js +39 -0
- package/out/virtualFile/computedSfc.d.ts +5 -0
- package/out/virtualFile/computedSfc.js +197 -0
- package/out/virtualFile/computedVueSfc.d.ts +5 -0
- package/out/virtualFile/computedVueSfc.js +41 -0
- package/out/virtualFile/embeddedFile.d.ts +13 -0
- package/out/virtualFile/embeddedFile.js +16 -0
- package/out/virtualFile/vueFile.d.ts +28 -0
- package/out/virtualFile/vueFile.js +53 -0
- package/package.json +6 -6
- package/out/sourceFile.d.ts +0 -79
- package/out/sourceFile.js +0 -527
|
@@ -1,34 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.walkElementNodes = exports.generate = void 0;
|
|
27
4
|
const language_core_1 = require("@volar/language-core");
|
|
28
|
-
const CompilerDOM =
|
|
5
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
29
6
|
const shared_1 = require("@vue/shared");
|
|
30
7
|
const minimatch_1 = require("minimatch");
|
|
31
|
-
const muggle =
|
|
8
|
+
const muggle = require("muggle-string");
|
|
32
9
|
const shared_2 = require("../utils/shared");
|
|
33
10
|
const transform_1 = require("../utils/transform");
|
|
34
11
|
const capabilitiesPresets = {
|
|
@@ -84,7 +61,7 @@ const transformContext = {
|
|
|
84
61
|
},
|
|
85
62
|
expressionPlugins: ['typescript'],
|
|
86
63
|
};
|
|
87
|
-
function generate(ts, compilerOptions, vueCompilerOptions,
|
|
64
|
+
function generate(ts, compilerOptions, vueCompilerOptions, template, shouldGenerateScopedClasses, stylesScopedClasses, hasScriptSetupSlots, slotsAssignName, propsAssignName, codegenStack) {
|
|
88
65
|
const nativeTags = new Set(vueCompilerOptions.nativeTags);
|
|
89
66
|
const [codes, codeStacks] = codegenStack ? muggle.track([]) : [[], []];
|
|
90
67
|
const [formatCodes, formatCodeStacks] = codegenStack ? muggle.track([]) : [[], []];
|
|
@@ -104,12 +81,15 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
104
81
|
let ignoreStart;
|
|
105
82
|
let expectedErrorStart;
|
|
106
83
|
let expectedErrorNode;
|
|
84
|
+
if (slotsAssignName) {
|
|
85
|
+
localVars.set(slotsAssignName, 1);
|
|
86
|
+
}
|
|
107
87
|
if (propsAssignName) {
|
|
108
88
|
localVars.set(propsAssignName, 1);
|
|
109
89
|
}
|
|
110
90
|
generatePreResolveComponents();
|
|
111
|
-
if (
|
|
112
|
-
visitNode(
|
|
91
|
+
if (template.ast) {
|
|
92
|
+
visitNode(template.ast, undefined, undefined, undefined);
|
|
113
93
|
}
|
|
114
94
|
generateStyleScopedClasses();
|
|
115
95
|
if (!hasScriptSetupSlots) {
|
|
@@ -151,14 +131,6 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
151
131
|
return codes;
|
|
152
132
|
}
|
|
153
133
|
function generateStyleScopedClasses() {
|
|
154
|
-
const allClasses = new Set();
|
|
155
|
-
for (const block of sfc.styles) {
|
|
156
|
-
if (block.scoped || vueCompilerOptions.experimentalResolveStyleCssClasses === 'always') {
|
|
157
|
-
for (const className of block.classNames) {
|
|
158
|
-
allClasses.add(className.text.substring(1));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
134
|
codes.push(`if (typeof __VLS_styleScopedClasses === 'object' && !Array.isArray(__VLS_styleScopedClasses)) {\n`);
|
|
163
135
|
for (const { className, offset } of scopedClasses) {
|
|
164
136
|
codes.push(`__VLS_styleScopedClasses[`);
|
|
@@ -168,7 +140,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
168
140
|
offset,
|
|
169
141
|
{
|
|
170
142
|
...capabilitiesPresets.scopedClassName,
|
|
171
|
-
displayWithLink:
|
|
143
|
+
displayWithLink: stylesScopedClasses.has(className),
|
|
172
144
|
},
|
|
173
145
|
]));
|
|
174
146
|
codes.push(`];\n`);
|
|
@@ -205,7 +177,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
205
177
|
const names = nativeTags.has(tagName) ? [tagName] : getPossibleOriginalComponentName(tagName);
|
|
206
178
|
for (const name of names) {
|
|
207
179
|
for (const tagRange of tagRanges) {
|
|
208
|
-
codes.push(nativeTags.has(tagName) ? '
|
|
180
|
+
codes.push(nativeTags.has(tagName) ? '__VLS_intrinsicElements' : '__VLS_components', ...createPropertyAccessCode([
|
|
209
181
|
name,
|
|
210
182
|
'template',
|
|
211
183
|
tagRange,
|
|
@@ -215,6 +187,10 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
215
187
|
normalize: tagName === name ? capabilitiesPresets.tagReference.rename.normalize : camelizeComponentName,
|
|
216
188
|
apply: getTagRenameApply(tagName),
|
|
217
189
|
},
|
|
190
|
+
...nativeTags.has(tagName) ? {
|
|
191
|
+
...capabilitiesPresets.tagHover,
|
|
192
|
+
...capabilitiesPresets.diagnosticOnly,
|
|
193
|
+
} : {},
|
|
218
194
|
},
|
|
219
195
|
]), ';');
|
|
220
196
|
}
|
|
@@ -247,10 +223,10 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
247
223
|
}
|
|
248
224
|
function collectTagOffsets() {
|
|
249
225
|
const tagOffsetsMap = {};
|
|
250
|
-
if (!
|
|
226
|
+
if (!template.ast) {
|
|
251
227
|
return tagOffsetsMap;
|
|
252
228
|
}
|
|
253
|
-
walkElementNodes(
|
|
229
|
+
walkElementNodes(template.ast, node => {
|
|
254
230
|
if (node.tag === 'slot') {
|
|
255
231
|
// ignore
|
|
256
232
|
}
|
|
@@ -267,10 +243,10 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
267
243
|
else {
|
|
268
244
|
tagOffsetsMap[node.tag] ??= [];
|
|
269
245
|
const offsets = tagOffsetsMap[node.tag];
|
|
270
|
-
const source =
|
|
246
|
+
const source = template.content.substring(node.loc.start.offset);
|
|
271
247
|
const startTagOffset = node.loc.start.offset + source.indexOf(node.tag);
|
|
272
248
|
offsets.push(startTagOffset); // start tag
|
|
273
|
-
if (!node.isSelfClosing &&
|
|
249
|
+
if (!node.isSelfClosing && template.lang === 'html') {
|
|
274
250
|
const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
|
|
275
251
|
if (endTagOffset !== startTagOffset) {
|
|
276
252
|
offsets.push(endTagOffset); // end tag
|
|
@@ -387,11 +363,11 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
387
363
|
let leftCharacter;
|
|
388
364
|
let rightCharacter;
|
|
389
365
|
// fix https://github.com/vuejs/language-tools/issues/1787
|
|
390
|
-
while ((leftCharacter =
|
|
366
|
+
while ((leftCharacter = template.content.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
|
|
391
367
|
start--;
|
|
392
368
|
content = leftCharacter + content;
|
|
393
369
|
}
|
|
394
|
-
while ((rightCharacter =
|
|
370
|
+
while ((rightCharacter = template.content.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
|
|
395
371
|
content = content + rightCharacter;
|
|
396
372
|
}
|
|
397
373
|
codes.push(...createInterpolationCode(content, node.content.loc, start, capabilitiesPresets.all, '(', ');\n'));
|
|
@@ -456,7 +432,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
456
432
|
codes.push(`for (const [`);
|
|
457
433
|
if (leftExpressionRange && leftExpressionText) {
|
|
458
434
|
const collectAst = createTsAst(node.parseResult, `const [${leftExpressionText}]`);
|
|
459
|
-
(0, transform_1.
|
|
435
|
+
(0, transform_1.collectVars)(ts, collectAst, forBlockVars);
|
|
460
436
|
for (const varName of forBlockVars)
|
|
461
437
|
localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
|
|
462
438
|
codes.push([leftExpressionText, 'template', leftExpressionRange.start, capabilitiesPresets.all]);
|
|
@@ -481,8 +457,8 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
481
457
|
}
|
|
482
458
|
function visitElementNode(node, parentEl, componentCtxVar) {
|
|
483
459
|
codes.push(`{\n`);
|
|
484
|
-
const startTagOffset = node.loc.start.offset +
|
|
485
|
-
let endTagOffset = !node.isSelfClosing &&
|
|
460
|
+
const startTagOffset = node.loc.start.offset + template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
|
461
|
+
let endTagOffset = !node.isSelfClosing && template.lang === 'html' ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag) : undefined;
|
|
486
462
|
if (endTagOffset === startTagOffset) {
|
|
487
463
|
endTagOffset = undefined;
|
|
488
464
|
}
|
|
@@ -516,7 +492,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
516
492
|
}
|
|
517
493
|
const isIntrinsicElement = nativeTags.has(tag) && tagOffsets.length;
|
|
518
494
|
if (isIntrinsicElement) {
|
|
519
|
-
codes.push('const ', var_originalComponent, ` =
|
|
495
|
+
codes.push('const ', var_originalComponent, ` = __VLS_intrinsicElements[`, ...createStringLiteralKeyCode([
|
|
520
496
|
tag,
|
|
521
497
|
'template',
|
|
522
498
|
tagOffsets[0],
|
|
@@ -543,34 +519,20 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
543
519
|
codes.push(`const ${var_functionalComponent} = __VLS_asFunctionalComponent(`, `${var_originalComponent}, `, `new ${var_originalComponent}({`, ...createPropsCode(node, props, 'extraReferences'), '})', ');\n');
|
|
544
520
|
}
|
|
545
521
|
for (const offset of tagOffsets) {
|
|
546
|
-
if (isNamespacedTag || dynamicTagExp) {
|
|
522
|
+
if (isNamespacedTag || dynamicTagExp || isIntrinsicElement) {
|
|
547
523
|
continue;
|
|
548
524
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
}
|
|
561
|
-
else {
|
|
562
|
-
const key = toCanonicalComponentName(tag);
|
|
563
|
-
codes.push(`({} as { ${key}: typeof ${var_originalComponent} }).`);
|
|
564
|
-
codes.push([
|
|
565
|
-
key,
|
|
566
|
-
'template',
|
|
567
|
-
[offset, offset + tag.length],
|
|
568
|
-
{
|
|
569
|
-
...capabilitiesPresets.tagHover,
|
|
570
|
-
...capabilitiesPresets.diagnosticOnly,
|
|
571
|
-
},
|
|
572
|
-
], ';\n');
|
|
573
|
-
}
|
|
525
|
+
const key = toCanonicalComponentName(tag);
|
|
526
|
+
codes.push(`({} as { ${key}: typeof ${var_originalComponent} }).`);
|
|
527
|
+
codes.push([
|
|
528
|
+
key,
|
|
529
|
+
'template',
|
|
530
|
+
[offset, offset + tag.length],
|
|
531
|
+
{
|
|
532
|
+
...capabilitiesPresets.tagHover,
|
|
533
|
+
...capabilitiesPresets.diagnosticOnly,
|
|
534
|
+
},
|
|
535
|
+
], ';\n');
|
|
574
536
|
}
|
|
575
537
|
if (vueCompilerOptions.strictTemplates) {
|
|
576
538
|
// with strictTemplates, generate once for props type-checking + instance type
|
|
@@ -636,7 +598,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
636
598
|
}
|
|
637
599
|
generateDirectives(node);
|
|
638
600
|
generateElReferences(node); // <el ref="foo" />
|
|
639
|
-
if (
|
|
601
|
+
if (shouldGenerateScopedClasses) {
|
|
640
602
|
generateClassScoped(node);
|
|
641
603
|
}
|
|
642
604
|
if (componentCtxVar) {
|
|
@@ -661,7 +623,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
661
623
|
if (slotDir?.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
|
|
662
624
|
formatCodes.push(...createFormatCode(slotDir.exp.content, slotDir.exp.loc.start.offset, formatBrackets.params));
|
|
663
625
|
const slotAst = createTsAst(slotDir, `(${slotDir.exp.content}) => {}`);
|
|
664
|
-
(0, transform_1.
|
|
626
|
+
(0, transform_1.collectVars)(ts, slotAst, slotBlockVars);
|
|
665
627
|
hasProps = true;
|
|
666
628
|
if (slotDir.exp.content.indexOf(':') === -1) {
|
|
667
629
|
codes.push('const [', [
|
|
@@ -706,6 +668,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
706
668
|
prev = childNode;
|
|
707
669
|
}
|
|
708
670
|
resolveComment();
|
|
671
|
+
generateAutoImportCompletionCode();
|
|
709
672
|
slotBlockVars.forEach(varName => {
|
|
710
673
|
localVars.set(varName, localVars.get(varName) - 1);
|
|
711
674
|
});
|
|
@@ -773,7 +736,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
773
736
|
},
|
|
774
737
|
},
|
|
775
738
|
},
|
|
776
|
-
]), `) };\n`, `${eventVar} = {
|
|
739
|
+
]), `) };\n`, `${eventVar} = { `);
|
|
777
740
|
if (prop.arg.loc.source.startsWith('[') && prop.arg.loc.source.endsWith(']')) {
|
|
778
741
|
codes.push('[(', ...createInterpolationCode(prop.arg.loc.source.slice(1, -1), prop.arg.loc, prop.arg.loc.start.offset + 1, capabilitiesPresets.all, '', ''), ')!]');
|
|
779
742
|
}
|
|
@@ -787,7 +750,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
787
750
|
}
|
|
788
751
|
codes.push(`: `);
|
|
789
752
|
appendExpressionNode(prop);
|
|
790
|
-
codes.push(`};\n`);
|
|
753
|
+
codes.push(` };\n`);
|
|
791
754
|
}
|
|
792
755
|
else if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
|
|
793
756
|
&& prop.name === 'on'
|
|
@@ -820,14 +783,16 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
820
783
|
}
|
|
821
784
|
let prefix = '(';
|
|
822
785
|
let suffix = ')';
|
|
786
|
+
let isFirstMapping = true;
|
|
823
787
|
if (isCompoundExpression) {
|
|
824
|
-
|
|
788
|
+
codes.push('$event => {\n');
|
|
789
|
+
localVars.set('$event', (localVars.get('$event') ?? 0) + 1);
|
|
790
|
+
prefix = '';
|
|
791
|
+
suffix = '';
|
|
825
792
|
for (const blockCondition of blockConditions) {
|
|
826
793
|
prefix += `if (!(${blockCondition})) return;\n`;
|
|
827
794
|
}
|
|
828
|
-
suffix = '\n}';
|
|
829
795
|
}
|
|
830
|
-
let isFirstMapping = true;
|
|
831
796
|
codes.push(...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, () => {
|
|
832
797
|
if (isCompoundExpression && isFirstMapping) {
|
|
833
798
|
isFirstMapping = false;
|
|
@@ -835,6 +800,12 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
835
800
|
}
|
|
836
801
|
return capabilitiesPresets.all;
|
|
837
802
|
}, prefix, suffix));
|
|
803
|
+
if (isCompoundExpression) {
|
|
804
|
+
localVars.set('$event', localVars.get('$event') - 1);
|
|
805
|
+
codes.push(';\n');
|
|
806
|
+
generateAutoImportCompletionCode();
|
|
807
|
+
codes.push('}\n');
|
|
808
|
+
}
|
|
838
809
|
formatCodes.push(...createFormatCode(prop.exp.content, prop.exp.loc.start.offset, isCompoundExpression ? formatBrackets.event : formatBrackets.normal));
|
|
839
810
|
}
|
|
840
811
|
else {
|
|
@@ -1028,7 +999,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
1028
999
|
&& prop.name === 'bind'
|
|
1029
1000
|
&& !prop.arg
|
|
1030
1001
|
&& prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
|
|
1031
|
-
codes.push('...', ...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, caps_all, '(', ')'), ', ');
|
|
1002
|
+
codes.push(['', 'template', prop.exp.loc.start.offset, capabilitiesPresets.diagnosticOnly], '...', ...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, caps_all, '(', ')'), ['', 'template', prop.exp.loc.end.offset, capabilitiesPresets.diagnosticOnly], ', ');
|
|
1032
1003
|
if (mode === 'normal') {
|
|
1033
1004
|
formatCodes.push(...createFormatCode(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal));
|
|
1034
1005
|
}
|
|
@@ -1235,7 +1206,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
1235
1206
|
else {
|
|
1236
1207
|
codes.push(...createInterpolationCode(slotNameExpNode.content, slotNameExpNode, undefined, undefined, '(', ')'));
|
|
1237
1208
|
}
|
|
1238
|
-
codes.push(
|
|
1209
|
+
codes.push(` as const;\n`);
|
|
1239
1210
|
slotExps.set(varSlotExp, {
|
|
1240
1211
|
varName: varSlot,
|
|
1241
1212
|
});
|
package/out/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * from './generators/template';
|
|
|
2
2
|
export * from './languageModule';
|
|
3
3
|
export * from './parsers/scriptSetupRanges';
|
|
4
4
|
export * from './plugins';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './virtualFile/vueFile';
|
|
6
6
|
export * from './types';
|
|
7
7
|
export * from './utils/ts';
|
|
8
8
|
export * from './utils/parseSfc';
|
package/out/index.js
CHANGED
|
@@ -10,33 +10,21 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
15
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
17
|
exports.tsCodegen = exports.sharedTypes = exports.scriptRanges = void 0;
|
|
30
18
|
__exportStar(require("./generators/template"), exports);
|
|
31
19
|
__exportStar(require("./languageModule"), exports);
|
|
32
20
|
__exportStar(require("./parsers/scriptSetupRanges"), exports);
|
|
33
21
|
__exportStar(require("./plugins"), exports);
|
|
34
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./virtualFile/vueFile"), exports);
|
|
35
23
|
__exportStar(require("./types"), exports);
|
|
36
24
|
__exportStar(require("./utils/ts"), exports);
|
|
37
25
|
__exportStar(require("./utils/parseSfc"), exports);
|
|
38
|
-
exports.scriptRanges =
|
|
39
|
-
exports.sharedTypes =
|
|
26
|
+
exports.scriptRanges = require("./parsers/scriptRanges");
|
|
27
|
+
exports.sharedTypes = require("./utils/globalTypes");
|
|
40
28
|
__exportStar(require("./utils/shared"), exports);
|
|
41
29
|
var vue_tsx_1 = require("./plugins/vue-tsx");
|
|
42
30
|
Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
|
package/out/languageModule.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Language } from '@volar/language-core';
|
|
2
|
-
import { VueFile } from './
|
|
2
|
+
import { VueFile } from './virtualFile/vueFile';
|
|
3
3
|
import { VueCompilerOptions } from './types';
|
|
4
4
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
5
5
|
export declare function createVueLanguage(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions?: ts.CompilerOptions, _vueCompilerOptions?: Partial<VueCompilerOptions>, codegenStack?: boolean): Language<VueFile>;
|
package/out/languageModule.js
CHANGED
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.createLanguages = exports.createVueLanguage = void 0;
|
|
27
4
|
const path_1 = require("path");
|
|
28
5
|
const plugins_1 = require("./plugins");
|
|
29
|
-
const
|
|
30
|
-
const sharedTypes =
|
|
6
|
+
const vueFile_1 = require("./virtualFile/vueFile");
|
|
7
|
+
const sharedTypes = require("./utils/globalTypes");
|
|
31
8
|
const ts_1 = require("./utils/ts");
|
|
32
9
|
const fileRegistries = [];
|
|
33
10
|
function getVueFileRegistry(key, plugins) {
|
|
@@ -73,7 +50,7 @@ function createVueLanguage(ts, compilerOptions = {}, _vueCompilerOptions = {}, c
|
|
|
73
50
|
reusedVueFile.update(snapshot);
|
|
74
51
|
return reusedVueFile;
|
|
75
52
|
}
|
|
76
|
-
const vueFile = new
|
|
53
|
+
const vueFile = new vueFile_1.VueFile(fileName, snapshot, vueCompilerOptions, plugins, ts, codegenStack);
|
|
77
54
|
fileRegistry.set(fileName, vueFile);
|
|
78
55
|
return vueFile;
|
|
79
56
|
}
|
package/out/plugins/vue-tsx.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Sfc, VueLanguagePlugin } from '../types';
|
|
2
2
|
import * as muggle from 'muggle-string';
|
|
3
3
|
export declare const tsCodegen: WeakMap<Sfc, {
|
|
4
|
-
scriptRanges:
|
|
4
|
+
scriptRanges: () => {
|
|
5
5
|
exportDefault: (import("../types").TextRange & {
|
|
6
6
|
expression: import("../types").TextRange;
|
|
7
7
|
args: import("../types").TextRange;
|
|
@@ -11,8 +11,8 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
11
11
|
nameOption: import("../types").TextRange | undefined;
|
|
12
12
|
}) | undefined;
|
|
13
13
|
bindings: import("../types").TextRange[];
|
|
14
|
-
} | undefined
|
|
15
|
-
scriptSetupRanges:
|
|
14
|
+
} | undefined;
|
|
15
|
+
scriptSetupRanges: () => {
|
|
16
16
|
leadingCommentEndOffset: number;
|
|
17
17
|
importSectionEndOffset: number;
|
|
18
18
|
bindings: import("../types").TextRange[];
|
|
@@ -49,14 +49,14 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
49
49
|
defaultValue: import("../types").TextRange | undefined;
|
|
50
50
|
required: boolean;
|
|
51
51
|
}[];
|
|
52
|
-
} | undefined
|
|
53
|
-
lang:
|
|
54
|
-
generatedScript:
|
|
52
|
+
} | undefined;
|
|
53
|
+
lang: () => string;
|
|
54
|
+
generatedScript: () => {
|
|
55
55
|
codes: muggle.Segment<import("@volar/language-core").FileRangeCapabilities>[];
|
|
56
56
|
codeStacks: muggle.StackNode[];
|
|
57
57
|
mirrorBehaviorMappings: import("@volar/source-map").Mapping<[import("@volar/language-core").MirrorBehaviorCapabilities, import("@volar/language-core").MirrorBehaviorCapabilities]>[];
|
|
58
|
-
}
|
|
59
|
-
generatedTemplate:
|
|
58
|
+
};
|
|
59
|
+
generatedTemplate: () => {
|
|
60
60
|
codes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
|
|
61
61
|
codeStacks: muggle.StackNode[];
|
|
62
62
|
formatCodes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
|
|
@@ -66,7 +66,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
66
66
|
tagNames: Record<string, number[]>;
|
|
67
67
|
accessedGlobalVariables: Set<string>;
|
|
68
68
|
hasSlot: boolean;
|
|
69
|
-
} | undefined
|
|
69
|
+
} | undefined;
|
|
70
70
|
}>;
|
|
71
71
|
declare const plugin: VueLanguagePlugin;
|
|
72
72
|
export default plugin;
|
package/out/plugins/vue-tsx.js
CHANGED
|
@@ -1,36 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.tsCodegen = void 0;
|
|
27
|
-
const
|
|
4
|
+
const computeds_1 = require("computeds");
|
|
28
5
|
const script_1 = require("../generators/script");
|
|
29
6
|
const template_1 = require("../generators/template");
|
|
30
7
|
const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
31
8
|
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
32
9
|
const language_core_1 = require("@volar/language-core");
|
|
33
|
-
const muggle =
|
|
10
|
+
const muggle = require("muggle-string");
|
|
34
11
|
const templateFormatReg = /^\.template_format\.ts$/;
|
|
35
12
|
const templateStyleCssReg = /^\.template_style\.css$/;
|
|
36
13
|
exports.tsCodegen = new WeakMap();
|
|
@@ -44,8 +21,8 @@ const plugin = (ctx) => {
|
|
|
44
21
|
getEmbeddedFileNames(fileName, sfc) {
|
|
45
22
|
const tsx = useTsx(fileName, sfc);
|
|
46
23
|
const fileNames = [];
|
|
47
|
-
if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang
|
|
48
|
-
fileNames.push(fileName + '.' + tsx.lang
|
|
24
|
+
if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang())) {
|
|
25
|
+
fileNames.push(fileName + '.' + tsx.lang());
|
|
49
26
|
}
|
|
50
27
|
if (sfc.template) {
|
|
51
28
|
fileNames.push(fileName + '.template_format.ts');
|
|
@@ -56,7 +33,7 @@ const plugin = (ctx) => {
|
|
|
56
33
|
resolveEmbeddedFile(fileName, sfc, embeddedFile) {
|
|
57
34
|
const _tsx = useTsx(fileName, sfc);
|
|
58
35
|
const suffix = embeddedFile.fileName.replace(fileName, '');
|
|
59
|
-
if (suffix === '.' + _tsx.lang
|
|
36
|
+
if (suffix === '.' + _tsx.lang()) {
|
|
60
37
|
embeddedFile.kind = language_core_1.FileKind.TypeScriptHostFile;
|
|
61
38
|
embeddedFile.capabilities = {
|
|
62
39
|
...language_core_1.FileCapabilities.full,
|
|
@@ -64,7 +41,7 @@ const plugin = (ctx) => {
|
|
|
64
41
|
documentFormatting: false,
|
|
65
42
|
documentSymbol: false,
|
|
66
43
|
};
|
|
67
|
-
const tsx = _tsx.generatedScript
|
|
44
|
+
const tsx = _tsx.generatedScript();
|
|
68
45
|
if (tsx) {
|
|
69
46
|
const [content, contentStacks] = ctx.codegenStack ? muggle.track([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]];
|
|
70
47
|
embeddedFile.content = content;
|
|
@@ -82,8 +59,11 @@ const plugin = (ctx) => {
|
|
|
82
59
|
codeAction: false,
|
|
83
60
|
inlayHint: false,
|
|
84
61
|
};
|
|
85
|
-
|
|
86
|
-
|
|
62
|
+
const template = _tsx.generatedTemplate();
|
|
63
|
+
if (template) {
|
|
64
|
+
const [content, contentStacks] = ctx.codegenStack
|
|
65
|
+
? muggle.track([...template.formatCodes], [...template.formatCodeStacks])
|
|
66
|
+
: [[...template.formatCodes], [...template.formatCodeStacks]];
|
|
87
67
|
embeddedFile.content = content;
|
|
88
68
|
embeddedFile.contentStacks = contentStacks;
|
|
89
69
|
}
|
|
@@ -103,8 +83,11 @@ const plugin = (ctx) => {
|
|
|
103
83
|
}
|
|
104
84
|
else if (suffix.match(templateStyleCssReg)) {
|
|
105
85
|
embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang;
|
|
106
|
-
|
|
107
|
-
|
|
86
|
+
const template = _tsx.generatedTemplate();
|
|
87
|
+
if (template) {
|
|
88
|
+
const [content, contentStacks] = ctx.codegenStack
|
|
89
|
+
? muggle.track([...template.cssCodes], [...template.cssCodeStacks])
|
|
90
|
+
: [[...template.cssCodes], [...template.cssCodeStacks]];
|
|
108
91
|
embeddedFile.content = content;
|
|
109
92
|
embeddedFile.contentStacks = contentStacks;
|
|
110
93
|
}
|
|
@@ -123,34 +106,48 @@ const plugin = (ctx) => {
|
|
|
123
106
|
exports.default = plugin;
|
|
124
107
|
function createTsx(fileName, _sfc, { vueCompilerOptions, compilerOptions, codegenStack, modules }) {
|
|
125
108
|
const ts = modules.typescript;
|
|
126
|
-
const lang = (0,
|
|
109
|
+
const lang = (0, computeds_1.computed)(() => {
|
|
127
110
|
return !_sfc.script && !_sfc.scriptSetup ? 'ts'
|
|
128
111
|
: _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
|
|
129
112
|
: _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
|
|
130
113
|
: 'js';
|
|
131
114
|
});
|
|
132
|
-
const scriptRanges = (0,
|
|
133
|
-
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.
|
|
115
|
+
const scriptRanges = (0, computeds_1.computed)(() => _sfc.script
|
|
116
|
+
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
|
|
134
117
|
: undefined);
|
|
135
|
-
const scriptSetupRanges = (0,
|
|
136
|
-
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.
|
|
118
|
+
const scriptSetupRanges = (0, computeds_1.computed)(() => _sfc.scriptSetup
|
|
119
|
+
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, vueCompilerOptions)
|
|
137
120
|
: undefined);
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
const shouldGenerateScopedClasses = (0, computeds_1.computed)(() => {
|
|
122
|
+
const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
|
|
123
|
+
return _sfc.styles.some(s => {
|
|
124
|
+
return option === 'always' || (option === 'scoped' && s.scoped);
|
|
125
|
+
});
|
|
142
126
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
127
|
+
const stylesScopedClasses = (0, computeds_1.computedSet)(() => {
|
|
128
|
+
const classes = new Set();
|
|
129
|
+
if (!shouldGenerateScopedClasses()) {
|
|
130
|
+
return classes;
|
|
131
|
+
}
|
|
132
|
+
for (const style of _sfc.styles) {
|
|
133
|
+
const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
|
|
134
|
+
if ((option === 'always' || option === 'scoped') && style.scoped) {
|
|
135
|
+
for (const className of style.classNames) {
|
|
136
|
+
classes.add(className.text.substring(1));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return classes;
|
|
141
|
+
});
|
|
142
|
+
const generatedTemplate = (0, computeds_1.computed)(() => {
|
|
143
|
+
if (!_sfc.template)
|
|
144
|
+
return;
|
|
145
|
+
return (0, template_1.generate)(ts, compilerOptions, vueCompilerOptions, _sfc.template, shouldGenerateScopedClasses(), stylesScopedClasses(), hasScriptSetupSlots(), slotsAssignName(), propsAssignName(), codegenStack);
|
|
153
146
|
});
|
|
147
|
+
const hasScriptSetupSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
|
|
148
|
+
const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name);
|
|
149
|
+
const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name);
|
|
150
|
+
const generatedScript = (0, computeds_1.computed)(() => (0, script_1.generate)(ts, fileName, _sfc.script, _sfc.scriptSetup, _sfc.styles, lang(), scriptRanges(), scriptSetupRanges(), generatedTemplate(), compilerOptions, vueCompilerOptions, codegenStack));
|
|
154
151
|
return {
|
|
155
152
|
scriptRanges,
|
|
156
153
|
scriptSetupRanges,
|
package/out/plugins.d.ts
CHANGED
|
@@ -20,6 +20,6 @@ export declare function getDefaultVueLanguagePlugins(ts: typeof import('typescri
|
|
|
20
20
|
newText: string;
|
|
21
21
|
}): CompilerDOM.CodegenResult | undefined;
|
|
22
22
|
getEmbeddedFileNames?(fileName: string, sfc: import("./types").Sfc): string[];
|
|
23
|
-
resolveEmbeddedFile?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./
|
|
23
|
+
resolveEmbeddedFile?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./virtualFile/embeddedFile").VueEmbeddedFile): void;
|
|
24
24
|
}[];
|
|
25
25
|
//# sourceMappingURL=plugins.d.ts.map
|