@vue/language-core 2.0.13 → 2.0.15
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 +1 -1
- package/index.js +1 -1
- package/lib/codegen/common.d.ts +11 -0
- package/lib/codegen/common.js +70 -0
- package/lib/codegen/script/component.d.ts +9 -0
- package/lib/codegen/script/component.js +109 -0
- package/lib/codegen/script/context.d.ts +25 -0
- package/lib/codegen/script/context.js +124 -0
- package/lib/{generators → codegen/script}/globalTypes.d.ts +1 -1
- package/lib/codegen/script/globalTypes.js +135 -0
- package/lib/codegen/script/index.d.ts +33 -0
- package/lib/codegen/script/index.js +127 -0
- package/lib/codegen/script/internalComponent.d.ts +5 -0
- package/lib/codegen/script/internalComponent.js +58 -0
- package/lib/codegen/script/scriptSetup.d.ts +6 -0
- package/lib/codegen/script/scriptSetup.js +371 -0
- package/lib/codegen/script/src.d.ts +2 -0
- package/lib/codegen/script/src.js +52 -0
- package/lib/codegen/script/template.d.ts +5 -0
- package/lib/codegen/script/template.js +196 -0
- package/lib/codegen/template/camelized.d.ts +2 -0
- package/lib/codegen/template/camelized.js +32 -0
- package/lib/codegen/template/context.d.ts +44 -0
- package/lib/codegen/template/context.js +170 -0
- package/lib/codegen/template/element.d.ts +8 -0
- package/lib/codegen/template/element.js +378 -0
- package/lib/codegen/template/elementChildren.d.ts +5 -0
- package/lib/codegen/template/elementChildren.js +26 -0
- package/lib/codegen/template/elementDirectives.d.ts +5 -0
- package/lib/codegen/template/elementDirectives.js +46 -0
- package/lib/codegen/template/elementEvents.d.ts +9 -0
- package/lib/codegen/template/elementEvents.js +157 -0
- package/lib/codegen/template/elementProps.d.ts +5 -0
- package/lib/codegen/template/elementProps.js +275 -0
- package/lib/codegen/template/index.d.ts +60 -0
- package/lib/codegen/template/index.js +130 -0
- package/lib/codegen/template/interpolation.d.ts +6 -0
- package/lib/{utils/transform.js → codegen/template/interpolation.js} +76 -46
- package/lib/codegen/template/objectProperty.d.ts +4 -0
- package/lib/codegen/template/objectProperty.js +31 -0
- package/lib/codegen/template/propertyAccess.d.ts +4 -0
- package/lib/codegen/template/propertyAccess.js +24 -0
- package/lib/codegen/template/slotOutlet.d.ts +5 -0
- package/lib/codegen/template/slotOutlet.js +72 -0
- package/lib/codegen/template/stringLiteralKey.d.ts +2 -0
- package/lib/codegen/template/stringLiteralKey.js +14 -0
- package/lib/codegen/template/templateChild.d.ts +7 -0
- package/lib/codegen/template/templateChild.js +160 -0
- package/lib/codegen/template/vFor.d.ts +12 -0
- package/lib/codegen/template/vFor.js +69 -0
- package/lib/codegen/template/vIf.d.ts +5 -0
- package/lib/codegen/template/vIf.js +53 -0
- package/lib/languageModule.d.ts +3 -4
- package/lib/languageModule.js +31 -14
- package/lib/parsers/scriptSetupRanges.d.ts +1 -0
- package/lib/parsers/scriptSetupRanges.js +6 -1
- package/lib/plugins/file-html.js +63 -66
- package/lib/plugins/file-md.js +47 -50
- package/lib/plugins/shared.d.ts +2 -0
- package/lib/plugins/shared.js +12 -0
- package/lib/plugins/vue-sfc-customblocks.js +2 -2
- package/lib/plugins/vue-sfc-scripts.js +2 -3
- package/lib/plugins/vue-sfc-styles.js +3 -3
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-template-inline-css.js +34 -2
- package/lib/plugins/vue-template-inline-ts.js +10 -8
- package/lib/plugins/vue-tsx.d.ts +43 -5
- package/lib/plugins/vue-tsx.js +38 -28
- package/lib/plugins.d.ts +2 -1
- package/lib/plugins.js +18 -9
- package/lib/types.d.ts +3 -3
- package/lib/utils/ts.js +20 -32
- package/lib/virtualFile/computedFiles.d.ts +2 -1
- package/lib/virtualFile/computedFiles.js +41 -15
- package/lib/virtualFile/computedMappings.js +3 -3
- package/lib/virtualFile/computedSfc.js +22 -1
- package/lib/virtualFile/embeddedFile.d.ts +2 -3
- package/lib/virtualFile/embeddedFile.js +1 -2
- package/lib/virtualFile/vueFile.d.ts +3 -5
- package/lib/virtualFile/vueFile.js +6 -8
- package/package.json +3 -3
- package/lib/generators/globalTypes.js +0 -135
- package/lib/generators/inlineCss.d.ts +0 -3
- package/lib/generators/inlineCss.js +0 -37
- package/lib/generators/script.d.ts +0 -13
- package/lib/generators/script.js +0 -981
- package/lib/generators/template.d.ts +0 -19
- package/lib/generators/template.js +0 -1578
- package/lib/generators/utils.d.ts +0 -5
- package/lib/generators/utils.js +0 -54
- package/lib/utils/transform.d.ts +0 -8
package/lib/plugins/file-html.js
CHANGED
|
@@ -6,74 +6,71 @@ const plugin = () => {
|
|
|
6
6
|
return {
|
|
7
7
|
version: 2,
|
|
8
8
|
parseSFC(fileName, content) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
// ignore `<script src="...">`
|
|
47
|
-
else if (tag === 'script' && attrs.indexOf('src=') === -1) {
|
|
48
|
-
let type = attrs.indexOf('type=') >= 0 ? 'scriptSetup' : 'script';
|
|
49
|
-
sfc.descriptor[type] = {
|
|
50
|
-
attrs: {},
|
|
51
|
-
content,
|
|
52
|
-
loc: {
|
|
53
|
-
start: { column: -1, line: -1, offset: contentStart },
|
|
54
|
-
end: { column: -1, line: -1, offset: contentStart + content.length },
|
|
55
|
-
source: content,
|
|
56
|
-
},
|
|
57
|
-
type: 'script',
|
|
58
|
-
lang,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
templateContent = templateContent.substring(0, match.index) + ' '.repeat(matchText.length) + templateContent.substring(match.index + matchText.length);
|
|
9
|
+
let sfc = {
|
|
10
|
+
descriptor: {
|
|
11
|
+
filename: fileName,
|
|
12
|
+
source: content,
|
|
13
|
+
template: null,
|
|
14
|
+
script: null,
|
|
15
|
+
scriptSetup: null,
|
|
16
|
+
styles: [],
|
|
17
|
+
customBlocks: [],
|
|
18
|
+
cssVars: [],
|
|
19
|
+
shouldForceReload: () => false,
|
|
20
|
+
slotted: false,
|
|
21
|
+
},
|
|
22
|
+
errors: [],
|
|
23
|
+
};
|
|
24
|
+
let templateContent = content;
|
|
25
|
+
for (const match of content.matchAll(sfcBlockReg)) {
|
|
26
|
+
const matchText = match[0];
|
|
27
|
+
const tag = match[1];
|
|
28
|
+
const attrs = match[2];
|
|
29
|
+
const lang = attrs.match(langReg)?.[2];
|
|
30
|
+
const content = match[3];
|
|
31
|
+
const contentStart = match.index + matchText.indexOf(content);
|
|
32
|
+
if (tag === 'style') {
|
|
33
|
+
sfc.descriptor.styles.push({
|
|
34
|
+
attrs: {},
|
|
35
|
+
content,
|
|
36
|
+
loc: {
|
|
37
|
+
start: { column: -1, line: -1, offset: contentStart },
|
|
38
|
+
end: { column: -1, line: -1, offset: contentStart + content.length },
|
|
39
|
+
source: content,
|
|
40
|
+
},
|
|
41
|
+
type: 'style',
|
|
42
|
+
lang,
|
|
43
|
+
});
|
|
62
44
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
45
|
+
// ignore `<script src="...">`
|
|
46
|
+
else if (tag === 'script' && attrs.indexOf('src=') === -1) {
|
|
47
|
+
let type = attrs.indexOf('type=') >= 0 ? 'scriptSetup' : 'script';
|
|
48
|
+
sfc.descriptor[type] = {
|
|
49
|
+
attrs: {},
|
|
50
|
+
content,
|
|
51
|
+
loc: {
|
|
52
|
+
start: { column: -1, line: -1, offset: contentStart },
|
|
53
|
+
end: { column: -1, line: -1, offset: contentStart + content.length },
|
|
54
|
+
source: content,
|
|
55
|
+
},
|
|
56
|
+
type: 'script',
|
|
57
|
+
lang,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
templateContent = templateContent.substring(0, match.index) + ' '.repeat(matchText.length) + templateContent.substring(match.index + matchText.length);
|
|
75
61
|
}
|
|
76
|
-
|
|
62
|
+
sfc.descriptor.template = {
|
|
63
|
+
attrs: {},
|
|
64
|
+
content: templateContent,
|
|
65
|
+
loc: {
|
|
66
|
+
start: { column: -1, line: -1, offset: 0 },
|
|
67
|
+
end: { column: -1, line: -1, offset: templateContent.length },
|
|
68
|
+
source: templateContent,
|
|
69
|
+
},
|
|
70
|
+
type: 'template',
|
|
71
|
+
ast: {},
|
|
72
|
+
};
|
|
73
|
+
return sfc;
|
|
77
74
|
}
|
|
78
75
|
};
|
|
79
76
|
};
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -12,58 +12,55 @@ const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
|
|
|
12
12
|
const plugin = () => {
|
|
13
13
|
return {
|
|
14
14
|
version: 2,
|
|
15
|
-
parseSFC(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
content = content.substring(0, match.index) + ' '.repeat(matchText.length) + content.substring(match.index + matchText.length);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
content = content
|
|
36
|
-
// angle bracket: <http://foo.com>
|
|
37
|
-
.replace(angleBracketReg, match => ' '.repeat(match.length))
|
|
38
|
-
// [foo](http://foo.com)
|
|
39
|
-
.replace(linkReg, match => ' '.repeat(match.length));
|
|
40
|
-
codes.push('<template>\n');
|
|
41
|
-
codes.push([content, undefined, 0]);
|
|
42
|
-
codes.push('\n</template>');
|
|
43
|
-
const file2VueSourceMap = new language_core_1.SourceMap((0, language_core_1.buildMappings)(codes));
|
|
44
|
-
const sfc = (0, parseSfc_1.parse)((0, language_core_1.toString)(codes));
|
|
45
|
-
if (sfc.descriptor.template) {
|
|
46
|
-
transformRange(sfc.descriptor.template);
|
|
47
|
-
}
|
|
48
|
-
if (sfc.descriptor.script) {
|
|
49
|
-
transformRange(sfc.descriptor.script);
|
|
50
|
-
}
|
|
51
|
-
if (sfc.descriptor.scriptSetup) {
|
|
52
|
-
transformRange(sfc.descriptor.scriptSetup);
|
|
53
|
-
}
|
|
54
|
-
for (const style of sfc.descriptor.styles) {
|
|
55
|
-
transformRange(style);
|
|
56
|
-
}
|
|
57
|
-
for (const customBlock of sfc.descriptor.customBlocks) {
|
|
58
|
-
transformRange(customBlock);
|
|
59
|
-
}
|
|
60
|
-
return sfc;
|
|
61
|
-
function transformRange(block) {
|
|
62
|
-
block.loc.start.offset = file2VueSourceMap.getSourceOffset(block.loc.start.offset)?.[0] ?? -1;
|
|
63
|
-
block.loc.end.offset = file2VueSourceMap.getSourceOffset(block.loc.end.offset)?.[0] ?? -1;
|
|
15
|
+
parseSFC(_fileName, content) {
|
|
16
|
+
content = content
|
|
17
|
+
// code block
|
|
18
|
+
.replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
|
|
19
|
+
// inline code block
|
|
20
|
+
.replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
|
|
21
|
+
// # \<script setup>
|
|
22
|
+
.replace(scriptSetupReg, match => ' '.repeat(match.length))
|
|
23
|
+
// <<< https://vitepress.dev/guide/markdown#import-code-snippets
|
|
24
|
+
.replace(codeSnippetImportReg, match => ' '.repeat(match.length));
|
|
25
|
+
const codes = [];
|
|
26
|
+
for (const match of content.matchAll(sfcBlockReg)) {
|
|
27
|
+
if (match.index !== undefined) {
|
|
28
|
+
const matchText = match[0];
|
|
29
|
+
codes.push([matchText, undefined, match.index]);
|
|
30
|
+
codes.push('\n\n');
|
|
31
|
+
content = content.substring(0, match.index) + ' '.repeat(matchText.length) + content.substring(match.index + matchText.length);
|
|
64
32
|
}
|
|
65
33
|
}
|
|
66
|
-
|
|
34
|
+
content = content
|
|
35
|
+
// angle bracket: <http://foo.com>
|
|
36
|
+
.replace(angleBracketReg, match => ' '.repeat(match.length))
|
|
37
|
+
// [foo](http://foo.com)
|
|
38
|
+
.replace(linkReg, match => ' '.repeat(match.length));
|
|
39
|
+
codes.push('<template>\n');
|
|
40
|
+
codes.push([content, undefined, 0]);
|
|
41
|
+
codes.push('\n</template>');
|
|
42
|
+
const file2VueSourceMap = new language_core_1.SourceMap((0, language_core_1.buildMappings)(codes));
|
|
43
|
+
const sfc = (0, parseSfc_1.parse)((0, language_core_1.toString)(codes));
|
|
44
|
+
if (sfc.descriptor.template) {
|
|
45
|
+
transformRange(sfc.descriptor.template);
|
|
46
|
+
}
|
|
47
|
+
if (sfc.descriptor.script) {
|
|
48
|
+
transformRange(sfc.descriptor.script);
|
|
49
|
+
}
|
|
50
|
+
if (sfc.descriptor.scriptSetup) {
|
|
51
|
+
transformRange(sfc.descriptor.scriptSetup);
|
|
52
|
+
}
|
|
53
|
+
for (const style of sfc.descriptor.styles) {
|
|
54
|
+
transformRange(style);
|
|
55
|
+
}
|
|
56
|
+
for (const customBlock of sfc.descriptor.customBlocks) {
|
|
57
|
+
transformRange(customBlock);
|
|
58
|
+
}
|
|
59
|
+
return sfc;
|
|
60
|
+
function transformRange(block) {
|
|
61
|
+
block.loc.start.offset = file2VueSourceMap.getSourceOffset(block.loc.start.offset)?.[0] ?? -1;
|
|
62
|
+
block.loc.end.offset = file2VueSourceMap.getSourceOffset(block.loc.end.offset)?.[0] ?? -1;
|
|
63
|
+
}
|
|
67
64
|
}
|
|
68
65
|
};
|
|
69
66
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.allCodeFeatures = void 0;
|
|
4
|
+
exports.allCodeFeatures = {
|
|
5
|
+
verification: true,
|
|
6
|
+
completion: true,
|
|
7
|
+
semantic: true,
|
|
8
|
+
navigation: true,
|
|
9
|
+
structure: true,
|
|
10
|
+
format: true,
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const shared_1 = require("./shared");
|
|
4
4
|
const plugin = () => {
|
|
5
5
|
return {
|
|
6
6
|
version: 2,
|
|
@@ -18,7 +18,7 @@ const plugin = () => {
|
|
|
18
18
|
customBlock.content,
|
|
19
19
|
customBlock.name,
|
|
20
20
|
0,
|
|
21
|
-
|
|
21
|
+
shared_1.allCodeFeatures,
|
|
22
22
|
]);
|
|
23
23
|
}
|
|
24
24
|
},
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("../generators/utils");
|
|
4
3
|
const plugin = () => {
|
|
5
4
|
return {
|
|
6
5
|
version: 2,
|
|
@@ -23,10 +22,10 @@ const plugin = () => {
|
|
|
23
22
|
script.content,
|
|
24
23
|
script.name,
|
|
25
24
|
0,
|
|
26
|
-
|
|
25
|
+
{
|
|
27
26
|
structure: true,
|
|
28
27
|
format: true,
|
|
29
|
-
}
|
|
28
|
+
},
|
|
30
29
|
]);
|
|
31
30
|
}
|
|
32
31
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const shared_1 = require("./shared");
|
|
4
4
|
const plugin = () => {
|
|
5
5
|
return {
|
|
6
6
|
version: 2,
|
|
@@ -34,7 +34,7 @@ const plugin = () => {
|
|
|
34
34
|
cssVar.text,
|
|
35
35
|
style.name,
|
|
36
36
|
cssVar.offset,
|
|
37
|
-
|
|
37
|
+
shared_1.allCodeFeatures,
|
|
38
38
|
], ');\n');
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -43,7 +43,7 @@ const plugin = () => {
|
|
|
43
43
|
style.content,
|
|
44
44
|
style.name,
|
|
45
45
|
0,
|
|
46
|
-
|
|
46
|
+
shared_1.allCodeFeatures,
|
|
47
47
|
]);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const shared_1 = require("./shared");
|
|
4
4
|
const plugin = () => {
|
|
5
5
|
return {
|
|
6
6
|
version: 2,
|
|
@@ -19,7 +19,7 @@ const plugin = () => {
|
|
|
19
19
|
sfc.template.content,
|
|
20
20
|
sfc.template.name,
|
|
21
21
|
0,
|
|
22
|
-
|
|
22
|
+
shared_1.allCodeFeatures,
|
|
23
23
|
]);
|
|
24
24
|
}
|
|
25
25
|
},
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
4
|
+
const template_1 = require("../codegen/template");
|
|
5
|
+
const shared_1 = require("./shared");
|
|
6
|
+
const codeFeatures = {
|
|
7
|
+
...shared_1.allCodeFeatures,
|
|
8
|
+
format: false,
|
|
9
|
+
structure: false,
|
|
10
|
+
};
|
|
4
11
|
const plugin = () => {
|
|
5
12
|
return {
|
|
6
13
|
version: 2,
|
|
@@ -15,9 +22,34 @@ const plugin = () => {
|
|
|
15
22
|
return;
|
|
16
23
|
}
|
|
17
24
|
embeddedFile.parentCodeId = 'template';
|
|
18
|
-
embeddedFile.content.push(...
|
|
25
|
+
embeddedFile.content.push(...generate(sfc.template.ast));
|
|
19
26
|
},
|
|
20
27
|
};
|
|
21
28
|
};
|
|
22
29
|
exports.default = plugin;
|
|
30
|
+
function* generate(templateAst) {
|
|
31
|
+
for (const node of (0, template_1.forEachElementNode)(templateAst)) {
|
|
32
|
+
for (const prop of node.props) {
|
|
33
|
+
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
34
|
+
&& prop.name === 'bind'
|
|
35
|
+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
36
|
+
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
37
|
+
&& prop.arg.content === 'style'
|
|
38
|
+
&& prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
|
39
|
+
const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | '
|
|
40
|
+
const start = prop.arg.loc.source.indexOf(endCrt) + 1;
|
|
41
|
+
const end = prop.arg.loc.source.lastIndexOf(endCrt);
|
|
42
|
+
const content = prop.arg.loc.source.substring(start, end);
|
|
43
|
+
yield `x { `;
|
|
44
|
+
yield [
|
|
45
|
+
content,
|
|
46
|
+
'template',
|
|
47
|
+
prop.arg.loc.start.offset + start,
|
|
48
|
+
codeFeatures,
|
|
49
|
+
];
|
|
50
|
+
yield ` }\n`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
23
55
|
//# sourceMappingURL=vue-template-inline-css.js.map
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const common_1 = require("../codegen/common");
|
|
4
|
+
const elementEvents_1 = require("../codegen/template/elementEvents");
|
|
5
|
+
const templateChild_1 = require("../codegen/template/templateChild");
|
|
6
|
+
const vFor_1 = require("../codegen/template/vFor");
|
|
5
7
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
|
-
const codeFeatures =
|
|
8
|
+
const codeFeatures = {
|
|
7
9
|
format: true,
|
|
8
10
|
// autoInserts: true, // TODO: support vue-autoinsert-parentheses
|
|
9
|
-
}
|
|
11
|
+
};
|
|
10
12
|
const formatBrackets = {
|
|
11
13
|
normal: ['`${', '}`;'],
|
|
12
14
|
if: ['if (', ') { }'],
|
|
@@ -73,8 +75,8 @@ const plugin = ctx => {
|
|
|
73
75
|
&& prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
|
|
74
76
|
) {
|
|
75
77
|
if (prop.name === 'on') {
|
|
76
|
-
const ast = (0,
|
|
77
|
-
addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0,
|
|
78
|
+
const ast = (0, common_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content);
|
|
79
|
+
addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)
|
|
78
80
|
? formatBrackets.event
|
|
79
81
|
: formatBrackets.normal);
|
|
80
82
|
}
|
|
@@ -99,7 +101,7 @@ const plugin = ctx => {
|
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
|
102
|
-
const { leftExpressionRange, leftExpressionText } = (0,
|
|
104
|
+
const { leftExpressionRange, leftExpressionText } = (0, vFor_1.parseVForNode)(node);
|
|
103
105
|
const { source } = node.parseResult;
|
|
104
106
|
if (leftExpressionRange && leftExpressionText && source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
105
107
|
const start = leftExpressionRange.start;
|
|
@@ -124,7 +126,7 @@ const plugin = ctx => {
|
|
|
124
126
|
}
|
|
125
127
|
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
126
128
|
// {{ ... }}
|
|
127
|
-
const [content, start] = (0,
|
|
129
|
+
const [content, start] = (0, templateChild_1.parseInterpolationNode)(node, templateContent);
|
|
128
130
|
const lines = content.split('\n');
|
|
129
131
|
addFormatCodes(content, start, lines.length <= 1 ? formatBrackets.curly : [
|
|
130
132
|
lines[0].trim() === '' ? '(' : formatBrackets.curly[0],
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Mapping
|
|
1
|
+
import type { Mapping } from '@volar/language-core';
|
|
2
2
|
import type { Code, Sfc, VueLanguagePlugin } from '../types';
|
|
3
3
|
export declare const tsCodegen: WeakMap<Sfc, {
|
|
4
4
|
scriptRanges: () => {
|
|
@@ -30,6 +30,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
30
30
|
};
|
|
31
31
|
slots: {
|
|
32
32
|
name?: string | undefined;
|
|
33
|
+
isObjectBindingPattern?: boolean | undefined;
|
|
33
34
|
define?: (import("../types").TextRange & {
|
|
34
35
|
arg?: import("../types").TextRange | undefined;
|
|
35
36
|
typeArg?: import("../types").TextRange | undefined;
|
|
@@ -62,14 +63,51 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
62
63
|
lang: () => string;
|
|
63
64
|
generatedScript: () => {
|
|
64
65
|
codes: Code[];
|
|
65
|
-
codeStacks: StackNode[];
|
|
66
66
|
linkedCodeMappings: Mapping<any>[];
|
|
67
67
|
};
|
|
68
68
|
generatedTemplate: () => {
|
|
69
69
|
codes: Code[];
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
ctx: {
|
|
71
|
+
slots: {
|
|
72
|
+
name: string;
|
|
73
|
+
loc?: number | undefined;
|
|
74
|
+
tagRange: [number, number];
|
|
75
|
+
varName: string;
|
|
76
|
+
nodeLoc: any;
|
|
77
|
+
}[];
|
|
78
|
+
dynamicSlots: {
|
|
79
|
+
expVar: string;
|
|
80
|
+
varName: string;
|
|
81
|
+
}[];
|
|
82
|
+
codeFeatures: {
|
|
83
|
+
all: import("../types").VueCodeInformation;
|
|
84
|
+
verification: import("../types").VueCodeInformation;
|
|
85
|
+
completion: import("../types").VueCodeInformation;
|
|
86
|
+
additionalCompletion: import("../types").VueCodeInformation;
|
|
87
|
+
navigation: import("../types").VueCodeInformation;
|
|
88
|
+
navigationAndCompletion: import("../types").VueCodeInformation;
|
|
89
|
+
withoutHighlight: import("../types").VueCodeInformation;
|
|
90
|
+
withoutHighlightAndCompletion: import("../types").VueCodeInformation;
|
|
91
|
+
withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
|
|
92
|
+
};
|
|
93
|
+
accessGlobalVariables: Map<string, Set<number>>;
|
|
94
|
+
hasSlotElements: Set<import("@vue/compiler-dom").ElementNode>;
|
|
95
|
+
blockConditions: string[];
|
|
96
|
+
usedComponentCtxVars: Set<string>;
|
|
97
|
+
scopedClasses: {
|
|
98
|
+
className: string;
|
|
99
|
+
offset: number;
|
|
100
|
+
}[];
|
|
101
|
+
accessGlobalVariable(name: string, offset?: number | undefined): void;
|
|
102
|
+
hasLocalVariable: (name: string) => boolean;
|
|
103
|
+
addLocalVariable: (name: string) => void;
|
|
104
|
+
removeLocalVariable: (name: string) => void;
|
|
105
|
+
getInternalVariable: () => string;
|
|
106
|
+
ignoreError: () => Generator<Code, any, unknown>;
|
|
107
|
+
expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code, any, unknown>;
|
|
108
|
+
resetDirectiveComments: (endStr: string) => Generator<Code, any, unknown>;
|
|
109
|
+
generateAutoImportCompletion: () => Generator<Code, any, unknown>;
|
|
110
|
+
};
|
|
73
111
|
hasSlot: boolean;
|
|
74
112
|
} | undefined;
|
|
75
113
|
}>;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tsCodegen = void 0;
|
|
4
|
-
const language_core_1 = require("@volar/language-core");
|
|
5
4
|
const computeds_1 = require("computeds");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const path = require("path-browserify");
|
|
6
|
+
const script_1 = require("../codegen/script");
|
|
7
|
+
const template_1 = require("../codegen/template");
|
|
8
8
|
const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
9
9
|
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
10
10
|
exports.tsCodegen = new WeakMap();
|
|
@@ -28,9 +28,8 @@ const plugin = ctx => {
|
|
|
28
28
|
if (embeddedFile.id.startsWith('script_')) {
|
|
29
29
|
const tsx = _tsx.generatedScript();
|
|
30
30
|
if (tsx) {
|
|
31
|
-
const
|
|
31
|
+
const content = [...tsx.codes];
|
|
32
32
|
embeddedFile.content = content;
|
|
33
|
-
embeddedFile.contentStacks = contentStacks;
|
|
34
33
|
embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
|
|
35
34
|
}
|
|
36
35
|
}
|
|
@@ -83,44 +82,56 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
83
82
|
if (!_sfc.template) {
|
|
84
83
|
return;
|
|
85
84
|
}
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
|
|
85
|
+
const codes = [];
|
|
86
|
+
const codegen = (0, template_1.generateTemplate)({
|
|
87
|
+
ts,
|
|
88
|
+
compilerOptions: ctx.compilerOptions,
|
|
89
|
+
vueCompilerOptions: ctx.vueCompilerOptions,
|
|
90
|
+
template: _sfc.template,
|
|
91
|
+
shouldGenerateScopedClasses: shouldGenerateScopedClasses(),
|
|
92
|
+
stylesScopedClasses: stylesScopedClasses(),
|
|
93
|
+
hasDefineSlots: hasDefineSlots(),
|
|
94
|
+
slotsAssignName: slotsAssignName(),
|
|
95
|
+
propsAssignName: propsAssignName(),
|
|
96
|
+
});
|
|
89
97
|
let current = codegen.next();
|
|
90
98
|
while (!current.done) {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
if (ctx.codegenStack) {
|
|
94
|
-
tsCodegenStacks.push(stack);
|
|
95
|
-
}
|
|
99
|
+
const code = current.value;
|
|
100
|
+
codes.push(code);
|
|
96
101
|
current = codegen.next();
|
|
97
102
|
}
|
|
98
103
|
return {
|
|
99
104
|
...current.value,
|
|
100
|
-
codes:
|
|
101
|
-
codeStacks: tsCodegenStacks,
|
|
105
|
+
codes: codes,
|
|
102
106
|
};
|
|
103
107
|
});
|
|
104
|
-
const
|
|
108
|
+
const hasDefineSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
|
|
105
109
|
const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name);
|
|
106
110
|
const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name);
|
|
107
111
|
const generatedScript = (0, computeds_1.computed)(() => {
|
|
108
112
|
const codes = [];
|
|
109
|
-
const codeStacks = [];
|
|
110
113
|
const linkedCodeMappings = [];
|
|
111
114
|
const _template = generatedTemplate();
|
|
112
115
|
let generatedLength = 0;
|
|
113
|
-
for (const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
for (const code of (0, script_1.generateScript)({
|
|
117
|
+
ts,
|
|
118
|
+
fileBaseName: path.basename(fileName),
|
|
119
|
+
globalTypes: ctx.globalTypesHolder === fileName,
|
|
120
|
+
sfc: _sfc,
|
|
121
|
+
lang: lang(),
|
|
122
|
+
scriptRanges: scriptRanges(),
|
|
123
|
+
scriptSetupRanges: scriptSetupRanges(),
|
|
124
|
+
templateCodegen: _template ? {
|
|
125
|
+
tsCodes: _template.codes,
|
|
126
|
+
ctx: _template.ctx,
|
|
127
|
+
hasSlot: _template.hasSlot,
|
|
128
|
+
} : undefined,
|
|
129
|
+
compilerOptions: ctx.compilerOptions,
|
|
130
|
+
vueCompilerOptions: ctx.vueCompilerOptions,
|
|
131
|
+
getGeneratedLength: () => generatedLength,
|
|
132
|
+
linkedCodeMappings,
|
|
133
|
+
})) {
|
|
120
134
|
codes.push(code);
|
|
121
|
-
if (ctx.codegenStack) {
|
|
122
|
-
codeStacks.push({ stack, length: 1 });
|
|
123
|
-
}
|
|
124
135
|
generatedLength += typeof code === 'string'
|
|
125
136
|
? code.length
|
|
126
137
|
: code[0].length;
|
|
@@ -128,7 +139,6 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
128
139
|
;
|
|
129
140
|
return {
|
|
130
141
|
codes,
|
|
131
|
-
codeStacks,
|
|
132
142
|
linkedCodeMappings,
|
|
133
143
|
};
|
|
134
144
|
});
|
package/lib/plugins.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type VueLanguagePlugin } from './types';
|
|
2
|
-
export
|
|
2
|
+
export * from './plugins/shared';
|
|
3
|
+
export declare function getBasePlugins(pluginContext: Parameters<VueLanguagePlugin>[0]): {
|
|
3
4
|
version: 2;
|
|
4
5
|
name?: string | undefined;
|
|
5
6
|
order?: number | undefined;
|