@vue/language-core 3.2.8 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/lib/codegen/names.d.ts +1 -0
- package/lib/codegen/names.js +1 -0
- package/lib/codegen/script/component.d.ts +2 -2
- package/lib/codegen/script/component.js +64 -58
- package/lib/codegen/script/index.d.ts +3 -3
- package/lib/codegen/script/scriptSetup.d.ts +4 -4
- package/lib/codegen/script/template.js +9 -9
- package/lib/codegen/style/common.d.ts +2 -2
- package/lib/codegen/style/index.d.ts +2 -2
- package/lib/codegen/template/element.d.ts +1 -0
- package/lib/codegen/template/element.js +46 -24
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +17 -16
- package/lib/codegen/template/index.d.ts +2 -2
- package/lib/codegen/template/index.js +6 -3
- package/lib/codegen/template/interpolation.d.ts +2 -2
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -3
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +20 -25
- package/lib/codegen/template/vFor.js +1 -19
- package/lib/codegen/template/vIf.js +1 -5
- package/lib/codegen/utils/index.d.ts +3 -3
- package/lib/codegen/utils/merge.d.ts +2 -2
- package/lib/codegen/utils/merge.js +9 -9
- package/lib/compilerOptions.js +1 -0
- package/lib/languagePlugin.js +2 -0
- package/lib/plugins/file-md.js +26 -30
- package/lib/plugins/vue-root-tags.js +9 -9
- package/lib/plugins/vue-sfc-customblocks.js +4 -4
- package/lib/plugins/vue-sfc-scripts.js +8 -8
- package/lib/plugins/vue-sfc-styles.js +5 -5
- package/lib/plugins/vue-sfc-template.js +7 -7
- package/lib/plugins/vue-template-html.js +37 -12
- package/lib/plugins/vue-template-inline-css.js +6 -6
- package/lib/plugins/vue-template-inline-ts.js +12 -16
- package/lib/plugins/vue-tsx.d.ts +2 -2
- package/lib/plugins/vue-tsx.js +35 -35
- package/lib/template/compile.d.ts +2 -0
- package/lib/template/compile.js +31 -0
- package/lib/template/transforms/transformElement.d.ts +2 -0
- package/lib/template/transforms/transformElement.js +95 -0
- package/lib/template/transforms/transformText.d.ts +2 -0
- package/lib/template/transforms/transformText.js +35 -0
- package/lib/template/transforms/vFor.d.ts +1 -0
- package/lib/template/transforms/vFor.js +42 -0
- package/lib/template/transforms/vIf.d.ts +1 -0
- package/lib/template/transforms/vIf.js +92 -0
- package/lib/template/utils.d.ts +3 -0
- package/lib/template/utils.js +37 -0
- package/lib/types.d.ts +55 -48
- package/lib/utils/forEachTemplateNode.js +0 -3
- package/lib/utils/parseSfc.js +0 -1
- package/lib/utils/shared.d.ts +2 -2
- package/lib/virtualCode/embeddedCodes.d.ts +2 -2
- package/lib/virtualCode/embeddedCodes.js +11 -11
- package/lib/virtualCode/index.d.ts +4 -2
- package/lib/virtualCode/index.js +4 -0
- package/lib/virtualCode/ir.d.ts +2 -2
- package/lib/virtualCode/ir.js +0 -39
- package/package.json +9 -6
- package/types/template-helpers.d.ts +1 -0
- package/lib/virtualCode/normalize.d.ts +0 -2
- package/lib/virtualCode/normalize.js +0 -205
- package/scripts/generate-names.js +0 -41
|
@@ -45,14 +45,10 @@ const slotOutlet_1 = require("./slotOutlet");
|
|
|
45
45
|
const vFor_1 = require("./vFor");
|
|
46
46
|
const vIf_1 = require("./vIf");
|
|
47
47
|
const vSlot_1 = require("./vSlot");
|
|
48
|
-
function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
48
|
+
function* generateTemplateChild(options, ctx, node, enterNode = true, treatTemplateAsFragment = false) {
|
|
49
49
|
if (enterNode && !ctx.enter(node)) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
const cur = node;
|
|
53
|
-
if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
|
|
54
|
-
cur.codegenNode = cur.codegenNode.value;
|
|
55
|
-
}
|
|
56
52
|
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
57
53
|
for (const item of collectSingleRootNodes(options, node.children)) {
|
|
58
54
|
ctx.singleRootNodes.add(item);
|
|
@@ -62,27 +58,25 @@ function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
|
62
58
|
}
|
|
63
59
|
}
|
|
64
60
|
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
65
|
-
let slotDir;
|
|
66
61
|
if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
|
|
67
62
|
yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node);
|
|
68
63
|
}
|
|
69
|
-
else if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE
|
|
70
|
-
&& ctx.components.length
|
|
71
|
-
&& (slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot'))) {
|
|
72
|
-
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, ctx.components[ctx.components.length - 1]());
|
|
73
|
-
}
|
|
74
|
-
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
|
75
|
-
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
|
76
|
-
yield* (0, element_1.generateElement)(options, ctx, node);
|
|
77
|
-
}
|
|
78
64
|
else {
|
|
79
|
-
|
|
65
|
+
const slotDir = node.props.find(CompilerDOM.isVSlot);
|
|
66
|
+
if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE && ctx.components.length && slotDir) {
|
|
67
|
+
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, ctx.components.at(-1)());
|
|
68
|
+
}
|
|
69
|
+
else if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE && treatTemplateAsFragment) {
|
|
70
|
+
yield* (0, element_1.generateFragment)(options, ctx, node);
|
|
71
|
+
}
|
|
72
|
+
else if (node.tagType === CompilerDOM.ElementTypes.COMPONENT) {
|
|
73
|
+
yield* (0, element_1.generateComponent)(options, ctx, node);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
yield* (0, element_1.generateElement)(options, ctx, node);
|
|
77
|
+
}
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
|
-
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
83
|
-
// {{ var }}
|
|
84
|
-
yield* generateTemplateChild(options, ctx, node.content, false);
|
|
85
|
-
}
|
|
86
80
|
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
87
81
|
// {{ ... }} {{ ... }}
|
|
88
82
|
for (const child of node.children) {
|
|
@@ -105,14 +99,11 @@ function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
|
105
99
|
// v-for
|
|
106
100
|
yield* (0, vFor_1.generateVFor)(options, ctx, node);
|
|
107
101
|
}
|
|
108
|
-
else if (node.type === CompilerDOM.NodeTypes.TEXT) {
|
|
109
|
-
// not needed progress
|
|
110
|
-
}
|
|
111
102
|
if (enterNode) {
|
|
112
103
|
yield* ctx.exit();
|
|
113
104
|
}
|
|
114
105
|
}
|
|
115
|
-
function* collectSingleRootNodes(options, children) {
|
|
106
|
+
function* collectSingleRootNodes(options, children, treatTemplateAsFragment = false) {
|
|
116
107
|
// Exclude the effect of comments on the root node
|
|
117
108
|
children = children.filter(node => node.type !== CompilerDOM.NodeTypes.COMMENT);
|
|
118
109
|
if (children.length !== 1) {
|
|
@@ -125,13 +116,17 @@ function* collectSingleRootNodes(options, children) {
|
|
|
125
116
|
const child = children[0];
|
|
126
117
|
if (child.type === CompilerDOM.NodeTypes.IF) {
|
|
127
118
|
for (const branch of child.branches) {
|
|
128
|
-
yield* collectSingleRootNodes(options, branch.children);
|
|
119
|
+
yield* collectSingleRootNodes(options, branch.children, true);
|
|
129
120
|
}
|
|
130
121
|
return;
|
|
131
122
|
}
|
|
132
123
|
else if (child.type !== CompilerDOM.NodeTypes.ELEMENT) {
|
|
133
124
|
return;
|
|
134
125
|
}
|
|
126
|
+
if (child.tagType === CompilerDOM.ElementTypes.TEMPLATE && treatTemplateAsFragment) {
|
|
127
|
+
yield* collectSingleRootNodes(options, child.children);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
135
130
|
yield child;
|
|
136
131
|
const tag = (0, shared_1.hyphenateTag)(child.tag);
|
|
137
132
|
if (options.vueCompilerOptions.fallthroughComponentNames.includes(tag)) {
|
|
@@ -67,28 +67,10 @@ function* generateVFor(options, ctx, node) {
|
|
|
67
67
|
yield `{} as any`;
|
|
68
68
|
}
|
|
69
69
|
yield `) {${utils_1.newLine}`;
|
|
70
|
-
let isFragment = true;
|
|
71
|
-
for (const argument of node.codegenNode?.children.arguments ?? []) {
|
|
72
|
-
if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
|
|
73
|
-
&& argument.returns?.type === CompilerDOM.NodeTypes.VNODE_CALL
|
|
74
|
-
&& argument.returns.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
|
|
75
|
-
if (argument.returns.tag !== CompilerDOM.FRAGMENT) {
|
|
76
|
-
isFragment = false;
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
for (const prop of argument.returns.props.properties) {
|
|
80
|
-
if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
81
|
-
&& !prop.value.isStatic) {
|
|
82
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, `(`, `)`);
|
|
83
|
-
yield utils_1.endOfLine;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
70
|
const { inVFor } = ctx;
|
|
89
71
|
ctx.inVFor = true;
|
|
90
72
|
for (const child of node.children) {
|
|
91
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child,
|
|
73
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, false, true);
|
|
92
74
|
}
|
|
93
75
|
ctx.inVFor = inVFor;
|
|
94
76
|
yield* endScope();
|
|
@@ -42,10 +42,6 @@ const interpolation_1 = require("./interpolation");
|
|
|
42
42
|
const templateChild_1 = require("./templateChild");
|
|
43
43
|
function* generateVIf(options, ctx, node) {
|
|
44
44
|
const originalBlockConditionsLength = ctx.blockConditions.length;
|
|
45
|
-
const isFragment = node.codegenNode
|
|
46
|
-
&& 'consequent' in node.codegenNode
|
|
47
|
-
&& 'tag' in node.codegenNode.consequent
|
|
48
|
-
&& node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
|
|
49
45
|
for (let i = 0; i < node.branches.length; i++) {
|
|
50
46
|
const branch = node.branches[i];
|
|
51
47
|
if (i === 0) {
|
|
@@ -67,7 +63,7 @@ function* generateVIf(options, ctx, node) {
|
|
|
67
63
|
}
|
|
68
64
|
yield `{${utils_1.newLine}`;
|
|
69
65
|
for (const child of branch.children) {
|
|
70
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, i !== 0
|
|
66
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, i !== 0, true);
|
|
71
67
|
}
|
|
72
68
|
yield `}${utils_1.newLine}`;
|
|
73
69
|
if (addedBlockCondition) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
import type { Code,
|
|
2
|
+
import type { Code, IRBlock, IRScript, IRScriptSetup, VueCodeInformation } from '../../types';
|
|
3
3
|
export declare const newLine = "\n";
|
|
4
4
|
export declare const endOfLine = ";\n";
|
|
5
5
|
export declare const identifierRegex: RegExp;
|
|
6
|
-
export declare function getTypeScriptAST(ts: typeof import('typescript'), block:
|
|
7
|
-
export declare function generateSfcBlockSection(block:
|
|
6
|
+
export declare function getTypeScriptAST(ts: typeof import('typescript'), block: IRBlock, text: string): ts.SourceFile;
|
|
7
|
+
export declare function generateSfcBlockSection(block: IRScript | IRScriptSetup, start: number, end: number, features: VueCodeInformation): Generator<Code>;
|
|
8
8
|
export declare function forEachNode(ts: typeof import('typescript'), node: ts.Node): Generator<ts.Node>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Code } from '../../types';
|
|
2
|
-
export declare function generateIntersectMerge(
|
|
3
|
-
export declare function generateSpreadMerge(
|
|
2
|
+
export declare function generateIntersectMerge(...codes: Code[]): Generator<Code>;
|
|
3
|
+
export declare function generateSpreadMerge(...codes: Code[]): Generator<Code>;
|
|
@@ -3,22 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateIntersectMerge = generateIntersectMerge;
|
|
4
4
|
exports.generateSpreadMerge = generateSpreadMerge;
|
|
5
5
|
const index_1 = require("./index");
|
|
6
|
-
function* generateIntersectMerge(
|
|
7
|
-
yield
|
|
8
|
-
for (let i = 1; i <
|
|
6
|
+
function* generateIntersectMerge(...codes) {
|
|
7
|
+
yield codes[0];
|
|
8
|
+
for (let i = 1; i < codes.length; i++) {
|
|
9
9
|
yield ` & `;
|
|
10
|
-
yield
|
|
10
|
+
yield codes[i];
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
function* generateSpreadMerge(
|
|
14
|
-
if (
|
|
15
|
-
yield*
|
|
13
|
+
function* generateSpreadMerge(...codes) {
|
|
14
|
+
if (codes.length <= 1) {
|
|
15
|
+
yield* codes;
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
18
|
yield `{${index_1.newLine}`;
|
|
19
|
-
for (const
|
|
19
|
+
for (const code of codes) {
|
|
20
20
|
yield `...`;
|
|
21
|
-
yield
|
|
21
|
+
yield code;
|
|
22
22
|
yield `,${index_1.newLine}`;
|
|
23
23
|
}
|
|
24
24
|
yield `}`;
|
package/lib/compilerOptions.js
CHANGED
|
@@ -211,6 +211,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
211
211
|
inferTemplateDollarSlots: false,
|
|
212
212
|
skipTemplateCodegen: false,
|
|
213
213
|
fallthroughAttributes: false,
|
|
214
|
+
checkRequiredFallthroughAttributes: false,
|
|
214
215
|
resolveStyleImports: false,
|
|
215
216
|
resolveStyleClassNames: 'scoped',
|
|
216
217
|
fallthroughComponentNames: [
|
package/lib/languagePlugin.js
CHANGED
|
@@ -38,6 +38,7 @@ exports.createVueLanguagePlugin = createVueLanguagePlugin;
|
|
|
38
38
|
exports.getAllExtensions = getAllExtensions;
|
|
39
39
|
const language_core_1 = require("@volar/language-core");
|
|
40
40
|
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
41
|
+
const LanguageCore = __importStar(require("../index"));
|
|
41
42
|
const plugins_1 = require("./plugins");
|
|
42
43
|
const virtualCode_1 = require("./virtualCode");
|
|
43
44
|
const fileRegistries = {};
|
|
@@ -60,6 +61,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
60
61
|
const pluginContext = {
|
|
61
62
|
modules: {
|
|
62
63
|
'@vue/compiler-dom': CompilerDOM,
|
|
64
|
+
'@vue/language-core': LanguageCore,
|
|
63
65
|
typescript: ts,
|
|
64
66
|
},
|
|
65
67
|
compilerOptions,
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -5,14 +5,13 @@ const muggle_string_1 = require("muggle-string");
|
|
|
5
5
|
const buildMappings_1 = require("../utils/buildMappings");
|
|
6
6
|
const parseSfc_1 = require("../utils/parseSfc");
|
|
7
7
|
const frontmatterReg = /^---[\s\S]*?\n---(?:\r?\n|$)/;
|
|
8
|
-
const codeblockReg = /(`{3
|
|
9
|
-
const inlineCodeblockReg = /`[^\n`]+?`/g;
|
|
10
|
-
const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
|
|
11
|
-
const scriptSetupReg = /\\<[\s\S]+?>\n?/g;
|
|
8
|
+
const codeblockReg = /(`{3}|\${2})[\s\S]+?\1/g;
|
|
12
9
|
const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
|
|
13
|
-
const sfcBlockReg = /<(script|style)\b[
|
|
14
|
-
const
|
|
15
|
-
const
|
|
10
|
+
const sfcBlockReg = /<(script|style)\b[^>]*>([\s\S]*?)<\/\1>/g;
|
|
11
|
+
const htmlTagReg = /(?<=<\/?)([a-z][a-z0-9-]*)\b[^>]*(?=>)/gi;
|
|
12
|
+
const interpolationReg = /(?<=\{\{)[\s\S]*?(?=\}\})/g;
|
|
13
|
+
const inlineCodeReg = /(`{1,2})[^`]+\1/g;
|
|
14
|
+
const angleBracketReg = /<[^\s:]*:\S*>/g;
|
|
16
15
|
const plugin = ({ vueCompilerOptions }) => {
|
|
17
16
|
return {
|
|
18
17
|
version: 2.2,
|
|
@@ -28,32 +27,29 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
28
27
|
if (languageId !== 'markdown') {
|
|
29
28
|
return;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// code block
|
|
35
|
-
.replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
|
|
36
|
-
// latex block
|
|
37
|
-
.replace(latexBlockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
|
|
38
|
-
// # \<script setup>
|
|
39
|
-
.replace(scriptSetupReg, match => ' '.repeat(match.length))
|
|
40
|
-
// <<< https://vitepress.dev/guide/markdown#import-code-snippets
|
|
41
|
-
.replace(codeSnippetImportReg, match => ' '.repeat(match.length));
|
|
30
|
+
for (const reg of [frontmatterReg, codeblockReg, codeSnippetImportReg]) {
|
|
31
|
+
content = content.replace(reg, match => ' '.repeat(match.length));
|
|
32
|
+
}
|
|
42
33
|
const codes = [];
|
|
43
|
-
for (const
|
|
44
|
-
|
|
45
|
-
codes.push([matchText, undefined, match.index]);
|
|
34
|
+
for (const { 0: text, index } of content.matchAll(sfcBlockReg)) {
|
|
35
|
+
codes.push([text, undefined, index]);
|
|
46
36
|
codes.push('\n\n');
|
|
47
|
-
content = content.slice(0,
|
|
48
|
-
|
|
37
|
+
content = content.slice(0, index) + ' '.repeat(text.length) + content.slice(index + text.length);
|
|
38
|
+
}
|
|
39
|
+
const ranges = [];
|
|
40
|
+
for (const reg of [htmlTagReg, interpolationReg]) {
|
|
41
|
+
for (const { 0: text, index } of content.matchAll(reg)) {
|
|
42
|
+
ranges.push([index, index + text.length]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const reg of [inlineCodeReg, angleBracketReg]) {
|
|
46
|
+
for (const { 0: text, index } of content.matchAll(reg)) {
|
|
47
|
+
if (ranges.some(([start, end]) => index >= start && index < end)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
content = content.slice(0, index) + ' '.repeat(text.length) + content.slice(index + text.length);
|
|
51
|
+
}
|
|
49
52
|
}
|
|
50
|
-
content = content
|
|
51
|
-
// inline code block
|
|
52
|
-
.replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
|
|
53
|
-
// angle bracket: <http://foo.com>
|
|
54
|
-
.replace(angleBracketReg, match => ' '.repeat(match.length))
|
|
55
|
-
// [foo](http://foo.com)
|
|
56
|
-
.replace(linkReg, match => ' '.repeat(match.length));
|
|
57
53
|
codes.push('<template>\n');
|
|
58
54
|
codes.push([content, undefined, 0]);
|
|
59
55
|
codes.push('\n</template>');
|
|
@@ -11,27 +11,27 @@ const plugin = () => {
|
|
|
11
11
|
lang: 'vue-root-tags',
|
|
12
12
|
}];
|
|
13
13
|
},
|
|
14
|
-
resolveEmbeddedCode(_fileName,
|
|
14
|
+
resolveEmbeddedCode(_fileName, ir, embeddedFile) {
|
|
15
15
|
if (embeddedFile.id === 'root_tags') {
|
|
16
|
-
embeddedFile.content.push([
|
|
16
|
+
embeddedFile.content.push([ir.content, undefined, 0, shared_1.allCodeFeatures]);
|
|
17
17
|
for (const block of [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
...
|
|
22
|
-
...
|
|
18
|
+
ir.template,
|
|
19
|
+
ir.script,
|
|
20
|
+
ir.scriptSetup,
|
|
21
|
+
...ir.styles,
|
|
22
|
+
...ir.customBlocks,
|
|
23
23
|
]) {
|
|
24
24
|
if (!block) {
|
|
25
25
|
continue;
|
|
26
26
|
}
|
|
27
27
|
const offset = block.content.lastIndexOf('\n', block.content.lastIndexOf('\n') - 1) + 1;
|
|
28
28
|
// fix folding range end position failed to mapping
|
|
29
|
-
(0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart,
|
|
29
|
+
(0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart, ir.content.slice(block.startTagEnd, block.startTagEnd + offset), [
|
|
30
30
|
'',
|
|
31
31
|
undefined,
|
|
32
32
|
block.startTagEnd + offset,
|
|
33
33
|
{ structure: true },
|
|
34
|
-
],
|
|
34
|
+
], ir.content.slice(block.startTagEnd + offset, block.endTagStart));
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
@@ -4,16 +4,16 @@ const shared_1 = require("./shared");
|
|
|
4
4
|
const plugin = () => {
|
|
5
5
|
return {
|
|
6
6
|
version: 2.2,
|
|
7
|
-
getEmbeddedCodes(_fileName,
|
|
8
|
-
return
|
|
7
|
+
getEmbeddedCodes(_fileName, ir) {
|
|
8
|
+
return ir.customBlocks.map((customBlock, i) => ({
|
|
9
9
|
id: 'custom_block_' + i,
|
|
10
10
|
lang: customBlock.lang,
|
|
11
11
|
}));
|
|
12
12
|
},
|
|
13
|
-
resolveEmbeddedCode(_fileName,
|
|
13
|
+
resolveEmbeddedCode(_fileName, ir, embeddedFile) {
|
|
14
14
|
if (embeddedFile.id.startsWith('custom_block_')) {
|
|
15
15
|
const index = parseInt(embeddedFile.id.slice('custom_block_'.length));
|
|
16
|
-
const customBlock =
|
|
16
|
+
const customBlock = ir.customBlocks[index];
|
|
17
17
|
embeddedFile.content.push([
|
|
18
18
|
customBlock.content,
|
|
19
19
|
customBlock.name,
|
|
@@ -3,21 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const plugin = () => {
|
|
4
4
|
return {
|
|
5
5
|
version: 2.2,
|
|
6
|
-
getEmbeddedCodes(_fileName,
|
|
6
|
+
getEmbeddedCodes(_fileName, ir) {
|
|
7
7
|
const names = [];
|
|
8
|
-
if (
|
|
9
|
-
names.push({ id: 'script_raw', lang:
|
|
8
|
+
if (ir.script) {
|
|
9
|
+
names.push({ id: 'script_raw', lang: ir.script.lang });
|
|
10
10
|
}
|
|
11
|
-
if (
|
|
12
|
-
names.push({ id: 'scriptsetup_raw', lang:
|
|
11
|
+
if (ir.scriptSetup) {
|
|
12
|
+
names.push({ id: 'scriptsetup_raw', lang: ir.scriptSetup.lang });
|
|
13
13
|
}
|
|
14
14
|
return names;
|
|
15
15
|
},
|
|
16
|
-
resolveEmbeddedCode(_fileName,
|
|
16
|
+
resolveEmbeddedCode(_fileName, ir, embeddedFile) {
|
|
17
17
|
const script = embeddedFile.id === 'script_raw'
|
|
18
|
-
?
|
|
18
|
+
? ir.script
|
|
19
19
|
: embeddedFile.id === 'scriptsetup_raw'
|
|
20
|
-
?
|
|
20
|
+
? ir.scriptSetup
|
|
21
21
|
: undefined;
|
|
22
22
|
if (script) {
|
|
23
23
|
embeddedFile.content.push([
|
|
@@ -4,10 +4,10 @@ const shared_1 = require("./shared");
|
|
|
4
4
|
const plugin = () => {
|
|
5
5
|
return {
|
|
6
6
|
version: 2.2,
|
|
7
|
-
getEmbeddedCodes(_fileName,
|
|
7
|
+
getEmbeddedCodes(_fileName, ir) {
|
|
8
8
|
const result = [];
|
|
9
|
-
for (let i = 0; i <
|
|
10
|
-
const style =
|
|
9
|
+
for (let i = 0; i < ir.styles.length; i++) {
|
|
10
|
+
const style = ir.styles[i];
|
|
11
11
|
if (style) {
|
|
12
12
|
result.push({
|
|
13
13
|
id: 'style_' + i,
|
|
@@ -23,10 +23,10 @@ const plugin = () => {
|
|
|
23
23
|
}
|
|
24
24
|
return result;
|
|
25
25
|
},
|
|
26
|
-
resolveEmbeddedCode(_fileName,
|
|
26
|
+
resolveEmbeddedCode(_fileName, ir, embeddedFile) {
|
|
27
27
|
if (embeddedFile.id.startsWith('style_')) {
|
|
28
28
|
const index = parseInt(embeddedFile.id.split('_')[1]);
|
|
29
|
-
const style =
|
|
29
|
+
const style = ir.styles[index];
|
|
30
30
|
if (embeddedFile.id.endsWith('_inline_ts')) {
|
|
31
31
|
embeddedFile.parentCodeId = 'style_' + index;
|
|
32
32
|
for (const binding of style.bindings) {
|
|
@@ -4,20 +4,20 @@ const shared_1 = require("./shared");
|
|
|
4
4
|
const plugin = () => {
|
|
5
5
|
return {
|
|
6
6
|
version: 2.2,
|
|
7
|
-
getEmbeddedCodes(_fileName,
|
|
8
|
-
if (
|
|
7
|
+
getEmbeddedCodes(_fileName, ir) {
|
|
8
|
+
if (ir.template?.lang === 'html') {
|
|
9
9
|
return [{
|
|
10
10
|
id: 'template',
|
|
11
|
-
lang:
|
|
11
|
+
lang: ir.template.lang,
|
|
12
12
|
}];
|
|
13
13
|
}
|
|
14
14
|
return [];
|
|
15
15
|
},
|
|
16
|
-
resolveEmbeddedCode(_fileName,
|
|
17
|
-
if (embeddedFile.id === 'template' &&
|
|
16
|
+
resolveEmbeddedCode(_fileName, ir, embeddedFile) {
|
|
17
|
+
if (embeddedFile.id === 'template' && ir.template?.lang === 'html') {
|
|
18
18
|
embeddedFile.content.push([
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
ir.template.content,
|
|
20
|
+
ir.template.name,
|
|
21
21
|
0,
|
|
22
22
|
shared_1.allCodeFeatures,
|
|
23
23
|
]);
|
|
@@ -1,8 +1,42 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
37
|
+
const compile_1 = require("../template/compile");
|
|
3
38
|
const shouldAddSuffix = /(?<=<[^>/]+)$/;
|
|
4
|
-
const plugin = (
|
|
5
|
-
const CompilerDOM = modules['@vue/compiler-dom'];
|
|
39
|
+
const plugin = () => {
|
|
6
40
|
return {
|
|
7
41
|
version: 2.2,
|
|
8
42
|
compileSFCTemplate(lang, template, options) {
|
|
@@ -13,11 +47,7 @@ const plugin = ({ modules }) => {
|
|
|
13
47
|
template += '>';
|
|
14
48
|
addedSuffix = true;
|
|
15
49
|
}
|
|
16
|
-
const ast =
|
|
17
|
-
...options,
|
|
18
|
-
comments: true,
|
|
19
|
-
});
|
|
20
|
-
CompilerDOM.transform(ast, options);
|
|
50
|
+
const ast = (0, compile_1.compileTemplate)(template, options);
|
|
21
51
|
return {
|
|
22
52
|
ast,
|
|
23
53
|
code: '',
|
|
@@ -97,11 +127,6 @@ const plugin = ({ modules }) => {
|
|
|
97
127
|
return false;
|
|
98
128
|
}
|
|
99
129
|
}
|
|
100
|
-
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
101
|
-
if (!tryUpdateNode(node.content)) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
130
|
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
106
131
|
for (const childNode of node.children) {
|
|
107
132
|
if (typeof childNode === 'object') {
|
|
@@ -45,18 +45,18 @@ const codeFeatures = {
|
|
|
45
45
|
const plugin = () => {
|
|
46
46
|
return {
|
|
47
47
|
version: 2.2,
|
|
48
|
-
getEmbeddedCodes(_fileName,
|
|
49
|
-
if (!
|
|
48
|
+
getEmbeddedCodes(_fileName, ir) {
|
|
49
|
+
if (!ir.template?.ast) {
|
|
50
50
|
return [];
|
|
51
51
|
}
|
|
52
52
|
return [{ id: 'template_inline_css', lang: 'css' }];
|
|
53
53
|
},
|
|
54
|
-
resolveEmbeddedCode(_fileName,
|
|
55
|
-
if (embeddedFile.id !== 'template_inline_css' || !
|
|
54
|
+
resolveEmbeddedCode(_fileName, ir, embeddedFile) {
|
|
55
|
+
if (embeddedFile.id !== 'template_inline_css' || !ir.template?.ast) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
embeddedFile.parentCodeId =
|
|
59
|
-
embeddedFile.content.push(...generate(
|
|
58
|
+
embeddedFile.parentCodeId = ir.template.lang === 'md' ? 'root_tags' : 'template';
|
|
59
|
+
embeddedFile.content.push(...generate(ir.template.ast));
|
|
60
60
|
},
|
|
61
61
|
};
|
|
62
62
|
};
|
|
@@ -57,42 +57,42 @@ const plugin = ({ modules: { typescript: ts } }) => {
|
|
|
57
57
|
const parseds = new WeakMap();
|
|
58
58
|
return {
|
|
59
59
|
version: 2.2,
|
|
60
|
-
getEmbeddedCodes(_fileName,
|
|
61
|
-
if (!
|
|
60
|
+
getEmbeddedCodes(_fileName, ir) {
|
|
61
|
+
if (!ir.template?.ast) {
|
|
62
62
|
return [];
|
|
63
63
|
}
|
|
64
|
-
const parsed = parse(
|
|
65
|
-
parseds.set(
|
|
64
|
+
const parsed = parse(ir);
|
|
65
|
+
parseds.set(ir, parsed);
|
|
66
66
|
const result = [];
|
|
67
67
|
for (const [id] of parsed) {
|
|
68
68
|
result.push({ id, lang: 'ts' });
|
|
69
69
|
}
|
|
70
70
|
return result;
|
|
71
71
|
},
|
|
72
|
-
resolveEmbeddedCode(_fileName,
|
|
72
|
+
resolveEmbeddedCode(_fileName, ir, embeddedFile) {
|
|
73
73
|
if (!embeddedFile.id.startsWith('template_inline_ts_')) {
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
// access template content to watch change
|
|
77
|
-
void
|
|
78
|
-
const parsed = parseds.get(
|
|
77
|
+
void ir.template?.content;
|
|
78
|
+
const parsed = parseds.get(ir);
|
|
79
79
|
if (parsed) {
|
|
80
80
|
const codes = parsed.get(embeddedFile.id);
|
|
81
81
|
if (codes) {
|
|
82
82
|
embeddedFile.content.push(...codes);
|
|
83
|
-
embeddedFile.parentCodeId =
|
|
83
|
+
embeddedFile.parentCodeId = ir.template?.lang === 'md' ? 'root_tags' : 'template';
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
87
|
};
|
|
88
|
-
function parse(
|
|
88
|
+
function parse(ir) {
|
|
89
89
|
const result = new Map();
|
|
90
|
-
if (!
|
|
90
|
+
if (!ir.template?.ast) {
|
|
91
91
|
return result;
|
|
92
92
|
}
|
|
93
|
-
const template =
|
|
93
|
+
const template = ir.template;
|
|
94
94
|
let i = 0;
|
|
95
|
-
|
|
95
|
+
ir.template.ast.children.forEach(visit);
|
|
96
96
|
return result;
|
|
97
97
|
function visit(node) {
|
|
98
98
|
if (node.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
@@ -178,10 +178,6 @@ const plugin = ({ modules: { typescript: ts } }) => {
|
|
|
178
178
|
visit(child);
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
182
|
-
// {{ var }}
|
|
183
|
-
visit(node.content);
|
|
184
|
-
}
|
|
185
181
|
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
186
182
|
// {{ ... }} {{ ... }}
|
|
187
183
|
for (const childNode of node.children) {
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const tsCodegen: WeakMap<
|
|
1
|
+
import type { IR, VueLanguagePlugin } from '../types';
|
|
2
|
+
export declare const tsCodegen: WeakMap<IR, {
|
|
3
3
|
getScriptRanges: () => {
|
|
4
4
|
exportDefault: (import("../types").TextRange<import("typescript").Node> & {
|
|
5
5
|
expression: import("../types").TextRange<import("typescript").Expression>;
|