@vue/language-core 3.2.8 → 3.2.9
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 -0
- package/index.js +1 -0
- package/lib/codegen/template/element.d.ts +1 -0
- package/lib/codegen/template/element.js +17 -0
- package/lib/codegen/template/elementProps.js +6 -6
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +14 -23
- package/lib/codegen/template/vFor.js +1 -19
- package/lib/codegen/template/vIf.js +1 -5
- package/lib/languagePlugin.js +2 -0
- package/lib/plugins/file-md.js +26 -30
- package/lib/plugins/vue-template-html.js +37 -12
- package/lib/plugins/vue-template-inline-ts.js +0 -4
- 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 +1 -0
- package/lib/utils/forEachTemplateNode.js +0 -3
- package/lib/virtualCode/ir.js +0 -39
- package/package.json +9 -6
- package/lib/virtualCode/normalize.d.ts +0 -2
- package/lib/virtualCode/normalize.js +0 -205
- package/scripts/generate-names.js +0 -41
package/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './lib/languagePlugin';
|
|
|
4
4
|
export * from './lib/parsers/scriptRanges';
|
|
5
5
|
export * from './lib/parsers/scriptSetupRanges';
|
|
6
6
|
export * from './lib/plugins';
|
|
7
|
+
export * from './lib/template/compile';
|
|
7
8
|
export * from './lib/types';
|
|
8
9
|
export * from './lib/utils/collectBindings';
|
|
9
10
|
export * from './lib/utils/forEachTemplateNode';
|
package/index.js
CHANGED
|
@@ -21,6 +21,7 @@ __exportStar(require("./lib/languagePlugin"), exports);
|
|
|
21
21
|
__exportStar(require("./lib/parsers/scriptRanges"), exports);
|
|
22
22
|
__exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
|
|
23
23
|
__exportStar(require("./lib/plugins"), exports);
|
|
24
|
+
__exportStar(require("./lib/template/compile"), exports);
|
|
24
25
|
__exportStar(require("./lib/types"), exports);
|
|
25
26
|
__exportStar(require("./lib/utils/collectBindings"), exports);
|
|
26
27
|
__exportStar(require("./lib/utils/forEachTemplateNode"), exports);
|
|
@@ -4,3 +4,4 @@ import type { TemplateCodegenContext } from './context';
|
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
5
|
export declare function generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
|
6
6
|
export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
|
7
|
+
export declare function generateFragment(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
|
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.generateComponent = generateComponent;
|
|
37
37
|
exports.generateElement = generateElement;
|
|
38
|
+
exports.generateFragment = generateFragment;
|
|
38
39
|
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
39
40
|
const shared_1 = require("@vue/shared");
|
|
40
41
|
const muggle_string_1 = require("muggle-string");
|
|
@@ -268,6 +269,22 @@ function* generateElement(options, ctx, node) {
|
|
|
268
269
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
|
269
270
|
}
|
|
270
271
|
}
|
|
272
|
+
function* generateFragment(options, ctx, node) {
|
|
273
|
+
const [startTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
|
|
274
|
+
// special case for <template v-for="..." :key="..." />
|
|
275
|
+
if (node.props.length) {
|
|
276
|
+
yield `__VLS_asFunctionalElement(__VLS_intrinsics.template)(`;
|
|
277
|
+
const token = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
278
|
+
yield `{${utils_1.newLine}`;
|
|
279
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps);
|
|
280
|
+
yield `}`;
|
|
281
|
+
yield (0, boundary_1.endBoundary)(token, startTagOffset + node.tag.length);
|
|
282
|
+
yield `)${utils_1.endOfLine}`;
|
|
283
|
+
}
|
|
284
|
+
for (const child of node.children) {
|
|
285
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
271
288
|
function* generateStyleScopedClassReferences({ template, typescript: ts }, node) {
|
|
272
289
|
for (const prop of node.props) {
|
|
273
290
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
@@ -109,7 +109,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
|
|
|
109
109
|
propName = propName.slice(1);
|
|
110
110
|
}
|
|
111
111
|
const shouldSpread = propName === 'style' || propName === 'class';
|
|
112
|
-
const shouldCamelize =
|
|
112
|
+
const shouldCamelize = getShouldCamelize(options, node, prop, propName);
|
|
113
113
|
const features = getPropsCodeFeatures(strictPropsCheck);
|
|
114
114
|
if (shouldSpread) {
|
|
115
115
|
yield `...{ `;
|
|
@@ -148,7 +148,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
|
|
|
148
148
|
continue;
|
|
149
149
|
}
|
|
150
150
|
const shouldSpread = prop.name === 'style' || prop.name === 'class';
|
|
151
|
-
const shouldCamelize =
|
|
151
|
+
const shouldCamelize = getShouldCamelize(options, node, prop, prop.name);
|
|
152
152
|
const features = getPropsCodeFeatures(strictPropsCheck);
|
|
153
153
|
if (shouldSpread) {
|
|
154
154
|
yield `...{ `;
|
|
@@ -234,10 +234,10 @@ function* generateAttrValue(node, features) {
|
|
|
234
234
|
yield* (0, unicode_1.generateUnicode)(content, offset, features);
|
|
235
235
|
yield quote;
|
|
236
236
|
}
|
|
237
|
-
function getShouldCamelize(options, prop, propName) {
|
|
238
|
-
return (
|
|
239
|
-
||
|
|
240
|
-
||
|
|
237
|
+
function getShouldCamelize(options, node, prop, propName) {
|
|
238
|
+
return (node.tagType === CompilerDOM.ElementTypes.COMPONENT
|
|
239
|
+
|| node.tagType === CompilerDOM.ElementTypes.SLOT) && (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
|
|
240
|
+
|| prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)
|
|
241
241
|
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
|
242
242
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern));
|
|
243
243
|
}
|
|
@@ -2,5 +2,5 @@ import * as CompilerDOM from '@vue/compiler-dom';
|
|
|
2
2
|
import type { Code } from '../../types';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
|
-
export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, enterNode?: boolean): Generator<Code>;
|
|
5
|
+
export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, enterNode?: boolean, isVForChild?: boolean): Generator<Code>;
|
|
6
6
|
export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];
|
|
@@ -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, isVForChild = 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 && isVForChild) {
|
|
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,9 +99,6 @@ 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
|
}
|
|
@@ -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) {
|
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>');
|
|
@@ -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') {
|
|
@@ -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) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compileTemplate = compileTemplate;
|
|
4
|
+
const compiler_dom_1 = require("@vue/compiler-dom");
|
|
5
|
+
const transformElement_1 = require("./transforms/transformElement");
|
|
6
|
+
const transformText_1 = require("./transforms/transformText");
|
|
7
|
+
const vFor_1 = require("./transforms/vFor");
|
|
8
|
+
const vIf_1 = require("./transforms/vIf");
|
|
9
|
+
function compileTemplate(source, options) {
|
|
10
|
+
const [nodeTransforms, directiveTransforms] = (0, compiler_dom_1.getBaseTransformPreset)();
|
|
11
|
+
const resolvedOptions = {
|
|
12
|
+
...options,
|
|
13
|
+
comments: true,
|
|
14
|
+
nodeTransforms: [
|
|
15
|
+
nodeTransforms[0], // transformVBindShorthand
|
|
16
|
+
vIf_1.transformIf,
|
|
17
|
+
vFor_1.transformFor,
|
|
18
|
+
transformElement_1.transformElement,
|
|
19
|
+
transformText_1.transformText,
|
|
20
|
+
...options.nodeTransforms || [],
|
|
21
|
+
],
|
|
22
|
+
directiveTransforms: {
|
|
23
|
+
...directiveTransforms,
|
|
24
|
+
...options.directiveTransforms,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const ast = (0, compiler_dom_1.parse)(source, resolvedOptions);
|
|
28
|
+
(0, compiler_dom_1.transform)(ast, resolvedOptions);
|
|
29
|
+
return ast;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformElement = void 0;
|
|
4
|
+
const compiler_dom_1 = require("@vue/compiler-dom");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
const transformElement = (node, context) => {
|
|
7
|
+
return () => {
|
|
8
|
+
if (node.type !== compiler_dom_1.NodeTypes.ELEMENT || node.tagType === compiler_dom_1.ElementTypes.TEMPLATE) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const isComponent = node.tagType === compiler_dom_1.ElementTypes.COMPONENT;
|
|
12
|
+
const isSlotOutlet = node.tagType === compiler_dom_1.ElementTypes.SLOT;
|
|
13
|
+
for (const prop of node.props) {
|
|
14
|
+
if (prop.type !== compiler_dom_1.NodeTypes.DIRECTIVE) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (prop.name === 'slot') {
|
|
18
|
+
if (!isComponent) {
|
|
19
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_SLOT_MISPLACED, prop.loc));
|
|
20
|
+
}
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const isVBind = prop.name === 'bind';
|
|
24
|
+
const isVOn = prop.name === 'on';
|
|
25
|
+
if (!prop.arg && (isVBind || isVOn)) {
|
|
26
|
+
if (!prop.exp) {
|
|
27
|
+
context.onError((0, compiler_dom_1.createCompilerError)(isVBind
|
|
28
|
+
? compiler_dom_1.ErrorCodes.X_V_BIND_NO_EXPRESSION
|
|
29
|
+
: compiler_dom_1.ErrorCodes.X_V_ON_NO_EXPRESSION, prop.loc));
|
|
30
|
+
}
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const runtimeDirectives = [];
|
|
34
|
+
const directiveTransform = context.directiveTransforms[prop.name];
|
|
35
|
+
if (directiveTransform) {
|
|
36
|
+
const { needRuntime } = directiveTransform(prop, node, context);
|
|
37
|
+
if (needRuntime) {
|
|
38
|
+
runtimeDirectives.push(prop);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (!(0, shared_1.isBuiltInDirective)(prop.name)) {
|
|
42
|
+
runtimeDirectives.push(prop);
|
|
43
|
+
}
|
|
44
|
+
if (isSlotOutlet && runtimeDirectives.length) {
|
|
45
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET, prop.loc));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (isComponent) {
|
|
49
|
+
let hasTemplateSlots = false;
|
|
50
|
+
let hasNamedDefaultSlot = false;
|
|
51
|
+
const implicitDefaultChildren = [];
|
|
52
|
+
const seenSlotNames = new Set();
|
|
53
|
+
const onComponentSlot = (0, compiler_dom_1.findDir)(node, 'slot', true);
|
|
54
|
+
for (const child of node.children) {
|
|
55
|
+
let slotDir;
|
|
56
|
+
if (!(0, compiler_dom_1.isTemplateNode)(child) || !(slotDir = (0, compiler_dom_1.findDir)(child, 'slot', true))) {
|
|
57
|
+
if (child.type !== compiler_dom_1.NodeTypes.COMMENT) {
|
|
58
|
+
implicitDefaultChildren.push(child);
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (onComponentSlot) {
|
|
63
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, slotDir.loc));
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if ((0, compiler_dom_1.findDir)(child, /^(?:if|else-if|else|for)$/, true)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
hasTemplateSlots = true;
|
|
70
|
+
const staticSlotName = slotDir.arg
|
|
71
|
+
? (0, compiler_dom_1.isStaticExp)(slotDir.arg)
|
|
72
|
+
? slotDir.arg.content
|
|
73
|
+
: undefined
|
|
74
|
+
: 'default';
|
|
75
|
+
if (staticSlotName) {
|
|
76
|
+
if (seenSlotNames.has(staticSlotName)) {
|
|
77
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES, slotDir.loc));
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
seenSlotNames.add(staticSlotName);
|
|
81
|
+
if (staticSlotName === 'default') {
|
|
82
|
+
hasNamedDefaultSlot = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (hasTemplateSlots && hasNamedDefaultSlot
|
|
87
|
+
&& implicitDefaultChildren.some(node => node.type !== compiler_dom_1.NodeTypes.TEXT || !!node.content.trim())) {
|
|
88
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN, implicitDefaultChildren[0].loc));
|
|
89
|
+
}
|
|
90
|
+
context.components.add(node.tag);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
exports.transformElement = transformElement;
|
|
95
|
+
//# sourceMappingURL=transformElement.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformText = void 0;
|
|
4
|
+
const compiler_dom_1 = require("@vue/compiler-dom");
|
|
5
|
+
const transformText = node => {
|
|
6
|
+
if (node.type === compiler_dom_1.NodeTypes.ROOT
|
|
7
|
+
|| node.type === compiler_dom_1.NodeTypes.ELEMENT
|
|
8
|
+
|| node.type === compiler_dom_1.NodeTypes.FOR
|
|
9
|
+
|| node.type === compiler_dom_1.NodeTypes.IF_BRANCH) {
|
|
10
|
+
return () => {
|
|
11
|
+
const children = node.children;
|
|
12
|
+
let currentContainer = undefined;
|
|
13
|
+
for (let i = 0; i < children.length; i++) {
|
|
14
|
+
const child = children[i];
|
|
15
|
+
if ((0, compiler_dom_1.isText)(child)) {
|
|
16
|
+
for (let j = i + 1; j < children.length; j++) {
|
|
17
|
+
const next = children[j];
|
|
18
|
+
if ((0, compiler_dom_1.isText)(next)) {
|
|
19
|
+
currentContainer ??= children[i] = (0, compiler_dom_1.createCompoundExpression)([child], child.loc);
|
|
20
|
+
currentContainer.children.push(` + `, next);
|
|
21
|
+
children.splice(j, 1);
|
|
22
|
+
j--;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
currentContainer = undefined;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.transformText = transformText;
|
|
35
|
+
//# sourceMappingURL=transformText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const transformFor: import("@vue/compiler-dom").NodeTransform;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformFor = void 0;
|
|
4
|
+
const compiler_dom_1 = require("@vue/compiler-dom");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
exports.transformFor = (0, utils_1.createStructuralDirectiveTransform)('for', (node, dir, context) => {
|
|
7
|
+
if (!dir.exp) {
|
|
8
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_FOR_NO_EXPRESSION, dir.loc));
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const parseResult = dir.forParseResult;
|
|
12
|
+
if (!parseResult) {
|
|
13
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION, dir.loc));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const { source, value, key, index } = parseResult;
|
|
17
|
+
const forNode = {
|
|
18
|
+
type: compiler_dom_1.NodeTypes.FOR,
|
|
19
|
+
loc: dir.loc,
|
|
20
|
+
source,
|
|
21
|
+
valueAlias: value,
|
|
22
|
+
keyAlias: key,
|
|
23
|
+
objectIndexAlias: index,
|
|
24
|
+
parseResult,
|
|
25
|
+
children: [node],
|
|
26
|
+
};
|
|
27
|
+
context.replaceNode(forNode);
|
|
28
|
+
return () => {
|
|
29
|
+
if ((0, compiler_dom_1.isTemplateNode)(node)) {
|
|
30
|
+
for (const child of node.children) {
|
|
31
|
+
if (child.type === compiler_dom_1.NodeTypes.ELEMENT) {
|
|
32
|
+
const key = (0, compiler_dom_1.findProp)(child, 'key');
|
|
33
|
+
if (key) {
|
|
34
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT, key.loc));
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=vFor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const transformIf: import("@vue/compiler-dom").NodeTransform;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformIf = void 0;
|
|
4
|
+
const compiler_dom_1 = require("@vue/compiler-dom");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
exports.transformIf = (0, utils_1.createStructuralDirectiveTransform)(/^(?:if|else-if|else)$/, (node, dir, context) => {
|
|
7
|
+
if (dir.name !== 'else'
|
|
8
|
+
&& (!dir.exp || !dir.exp.content.trim())) {
|
|
9
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_IF_NO_EXPRESSION, dir.loc));
|
|
10
|
+
}
|
|
11
|
+
if (dir.name === 'if') {
|
|
12
|
+
const branch = createIfBranch(node, dir);
|
|
13
|
+
const ifNode = {
|
|
14
|
+
type: compiler_dom_1.NodeTypes.IF,
|
|
15
|
+
loc: (0, utils_1.cloneLoc)(node.loc),
|
|
16
|
+
branches: [branch],
|
|
17
|
+
};
|
|
18
|
+
context.replaceNode(ifNode);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const siblings = context.parent.children;
|
|
22
|
+
const comments = [];
|
|
23
|
+
let i = siblings.indexOf(node);
|
|
24
|
+
while (i-- >= -1) {
|
|
25
|
+
const sibling = siblings[i];
|
|
26
|
+
if (sibling?.type === compiler_dom_1.NodeTypes.COMMENT) {
|
|
27
|
+
context.removeNode(sibling);
|
|
28
|
+
comments.unshift(sibling);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (sibling?.type === compiler_dom_1.NodeTypes.TEXT && !sibling.content.trim().length) {
|
|
32
|
+
context.removeNode(sibling);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (sibling?.type === compiler_dom_1.NodeTypes.IF) {
|
|
36
|
+
if (!sibling.branches.at(-1).condition) {
|
|
37
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, node.loc));
|
|
38
|
+
}
|
|
39
|
+
context.removeNode();
|
|
40
|
+
const branch = createIfBranch(node, dir);
|
|
41
|
+
if (comments.length) {
|
|
42
|
+
branch.children.unshift(...comments);
|
|
43
|
+
}
|
|
44
|
+
if (branch.userKey) {
|
|
45
|
+
for (const { userKey } of sibling.branches) {
|
|
46
|
+
if (isSameKey(userKey, branch.userKey)) {
|
|
47
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_IF_SAME_KEY, branch.userKey.loc));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
sibling.branches.push(branch);
|
|
52
|
+
(0, compiler_dom_1.traverseNode)(branch, context);
|
|
53
|
+
context.currentNode = null;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
context.onError((0, compiler_dom_1.createCompilerError)(compiler_dom_1.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, node.loc));
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
function createIfBranch(node, dir) {
|
|
63
|
+
return {
|
|
64
|
+
type: compiler_dom_1.NodeTypes.IF_BRANCH,
|
|
65
|
+
loc: node.loc,
|
|
66
|
+
condition: dir.name === 'else' ? undefined : dir.exp,
|
|
67
|
+
children: [node],
|
|
68
|
+
userKey: (0, compiler_dom_1.findProp)(node, 'key'),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function isSameKey(a, b) {
|
|
72
|
+
if (!a || a.type !== b.type) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (a.type === compiler_dom_1.NodeTypes.ATTRIBUTE) {
|
|
76
|
+
if (a.value.content !== b.value.content) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const exp = a.exp;
|
|
82
|
+
const branchExp = b.exp;
|
|
83
|
+
if (exp.type !== branchExp.type
|
|
84
|
+
|| exp.type !== compiler_dom_1.NodeTypes.SIMPLE_EXPRESSION
|
|
85
|
+
|| exp.isStatic !== branchExp.isStatic
|
|
86
|
+
|| exp.content !== branchExp.content) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=vIf.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type NodeTransform, type SourceLocation, type StructuralDirectiveTransform } from '@vue/compiler-dom';
|
|
2
|
+
export declare function createStructuralDirectiveTransform(name: string | RegExp, fn: StructuralDirectiveTransform): NodeTransform;
|
|
3
|
+
export declare function cloneLoc(loc: SourceLocation): SourceLocation;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
|
|
4
|
+
exports.cloneLoc = cloneLoc;
|
|
5
|
+
const compiler_dom_1 = require("@vue/compiler-dom");
|
|
6
|
+
const shared_1 = require("@vue/shared");
|
|
7
|
+
function createStructuralDirectiveTransform(name, fn) {
|
|
8
|
+
const matches = (0, shared_1.isString)(name)
|
|
9
|
+
? (n) => n === name
|
|
10
|
+
: (n) => name.test(n);
|
|
11
|
+
return (node, context) => {
|
|
12
|
+
if (node.type === compiler_dom_1.NodeTypes.ELEMENT) {
|
|
13
|
+
const { props } = node;
|
|
14
|
+
const exitFns = [];
|
|
15
|
+
for (let i = 0; i < props.length; i++) {
|
|
16
|
+
const prop = props[i];
|
|
17
|
+
if (prop.type === compiler_dom_1.NodeTypes.DIRECTIVE && matches(prop.name)) {
|
|
18
|
+
props.splice(i, 1);
|
|
19
|
+
i--;
|
|
20
|
+
const onExit = fn(node, prop, context);
|
|
21
|
+
if (onExit) {
|
|
22
|
+
exitFns.push(onExit);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return exitFns;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function cloneLoc(loc) {
|
|
31
|
+
return {
|
|
32
|
+
start: { ...loc.start },
|
|
33
|
+
end: { ...loc.end },
|
|
34
|
+
source: loc.source,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=utils.js.map
|
package/lib/types.d.ts
CHANGED
|
@@ -101,6 +101,7 @@ export type VueLanguagePlugin<T extends Record<string, any> = {}> = (ctx: {
|
|
|
101
101
|
modules: {
|
|
102
102
|
typescript: typeof ts;
|
|
103
103
|
'@vue/compiler-dom': typeof CompilerDOM;
|
|
104
|
+
'@vue/language-core': typeof import('../index');
|
|
104
105
|
};
|
|
105
106
|
compilerOptions: ts.CompilerOptions;
|
|
106
107
|
vueCompilerOptions: VueCompilerOptions;
|
|
@@ -72,9 +72,6 @@ function* forEachInterpolationNode(node) {
|
|
|
72
72
|
yield* forEachInterpolationNode(child);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
76
|
-
yield* forEachInterpolationNode(node.content);
|
|
77
|
-
}
|
|
78
75
|
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
79
76
|
for (const child of node.children) {
|
|
80
77
|
if (typeof child === 'object') {
|
package/lib/virtualCode/ir.js
CHANGED
|
@@ -1,43 +1,8 @@
|
|
|
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
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.useIR = useIR;
|
|
37
|
-
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
38
4
|
const alien_signals_1 = require("alien-signals");
|
|
39
5
|
const signals_1 = require("../utils/signals");
|
|
40
|
-
const normalize_1 = require("./normalize");
|
|
41
6
|
function useIR(ts, plugins, fileName, getSnapshot, getParseSfcResult) {
|
|
42
7
|
const getUntrackedSnapshot = () => {
|
|
43
8
|
const pausedSub = (0, alien_signals_1.setActiveSub)(undefined);
|
|
@@ -229,13 +194,10 @@ function useIR(ts, plugins, fileName, getSnapshot, getParseSfcResult) {
|
|
|
229
194
|
}
|
|
230
195
|
const errors = [];
|
|
231
196
|
const warnings = [];
|
|
232
|
-
const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset();
|
|
233
197
|
let options = {
|
|
234
198
|
onError: err => errors.push(err),
|
|
235
199
|
onWarn: err => warnings.push(err),
|
|
236
200
|
expressionPlugins: ['typescript'],
|
|
237
|
-
nodeTransforms,
|
|
238
|
-
directiveTransforms,
|
|
239
201
|
};
|
|
240
202
|
for (const plugin of plugins) {
|
|
241
203
|
if (plugin.resolveTemplateCompilerOptions) {
|
|
@@ -246,7 +208,6 @@ function useIR(ts, plugins, fileName, getSnapshot, getParseSfcResult) {
|
|
|
246
208
|
try {
|
|
247
209
|
const result = plugin.compileSFCTemplate?.(base.lang, base.content, options);
|
|
248
210
|
if (result) {
|
|
249
|
-
(0, normalize_1.normalizeTemplateAST)(result.ast);
|
|
250
211
|
return {
|
|
251
212
|
snapshot: getUntrackedSnapshot(),
|
|
252
213
|
template: base.content,
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"index.d.ts",
|
|
7
|
+
"index.js",
|
|
8
|
+
"lib/**/*.d.ts",
|
|
9
|
+
"lib/**/*.js",
|
|
10
|
+
"types"
|
|
8
11
|
],
|
|
9
12
|
"sideEffects": false,
|
|
10
13
|
"repository": {
|
|
@@ -19,17 +22,17 @@
|
|
|
19
22
|
"@volar/language-core": "2.4.28",
|
|
20
23
|
"@vue/compiler-dom": "^3.5.0",
|
|
21
24
|
"@vue/shared": "^3.5.0",
|
|
22
|
-
"alien-signals": "^3.
|
|
25
|
+
"alien-signals": "^3.2.0",
|
|
23
26
|
"muggle-string": "^0.4.1",
|
|
24
27
|
"path-browserify": "^1.0.1",
|
|
25
28
|
"picomatch": "^4.0.4"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^
|
|
31
|
+
"@types/node": "^24.1.0",
|
|
29
32
|
"@types/path-browserify": "^1.0.3",
|
|
30
33
|
"@types/picomatch": "^4.0.3",
|
|
31
34
|
"@volar/typescript": "2.4.28",
|
|
32
35
|
"@vue/compiler-sfc": "^3.5.0"
|
|
33
36
|
},
|
|
34
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "9c1fd47ffe25e86394232dfc76453a5f76cb4fe0"
|
|
35
38
|
}
|
|
@@ -1,205 +0,0 @@
|
|
|
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
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.normalizeTemplateAST = normalizeTemplateAST;
|
|
37
|
-
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
38
|
-
const forEachTemplateNode_1 = require("../utils/forEachTemplateNode");
|
|
39
|
-
// See https://github.com/vuejs/core/issues/3498
|
|
40
|
-
function normalizeTemplateAST(root) {
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
const transformContext = {
|
|
43
|
-
onError: () => { },
|
|
44
|
-
helperString: str => str.toString(),
|
|
45
|
-
replaceNode: () => { },
|
|
46
|
-
cacheHandlers: false,
|
|
47
|
-
prefixIdentifiers: false,
|
|
48
|
-
scopes: {
|
|
49
|
-
vFor: 0,
|
|
50
|
-
vOnce: 0,
|
|
51
|
-
vPre: 0,
|
|
52
|
-
vSlot: 0,
|
|
53
|
-
},
|
|
54
|
-
expressionPlugins: ['typescript'],
|
|
55
|
-
};
|
|
56
|
-
for (const { children, codegenNode, props } of (0, forEachTemplateNode_1.forEachElementNode)(root)) {
|
|
57
|
-
for (let i = 0; i < children.length; i++) {
|
|
58
|
-
const child = children[i];
|
|
59
|
-
if (child.type !== CompilerDOM.NodeTypes.ELEMENT) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
const forNode = getVForNode(child, transformContext);
|
|
63
|
-
if (forNode) {
|
|
64
|
-
children[i] = forNode;
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
const ifNode = getVIfNode(child, transformContext);
|
|
68
|
-
if (ifNode) {
|
|
69
|
-
const normalized = normalizeIfBranch(ifNode, children, i);
|
|
70
|
-
children.splice(i, normalized.end - i + 1, normalized.node);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// #4539
|
|
75
|
-
if (codegenNode
|
|
76
|
-
&& 'props' in codegenNode
|
|
77
|
-
&& codegenNode.props
|
|
78
|
-
&& 'properties' in codegenNode.props) {
|
|
79
|
-
for (const p of codegenNode.props.properties) {
|
|
80
|
-
if (p.key.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
81
|
-
&& p.key.content === 'key'
|
|
82
|
-
&& !p.key.isHandlerKey
|
|
83
|
-
&& !p.key.loc.source
|
|
84
|
-
&& p.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
85
|
-
&& p.value.constType === CompilerDOM.ConstantTypes.NOT_CONSTANT) {
|
|
86
|
-
const contentBeforeValue = root.loc.source.slice(0, p.value.loc.start.offset);
|
|
87
|
-
const argOffset = contentBeforeValue.lastIndexOf('key');
|
|
88
|
-
props.push({
|
|
89
|
-
type: CompilerDOM.NodeTypes.DIRECTIVE,
|
|
90
|
-
name: 'bind',
|
|
91
|
-
exp: p.value,
|
|
92
|
-
loc: p.loc,
|
|
93
|
-
arg: {
|
|
94
|
-
...p.key,
|
|
95
|
-
loc: {
|
|
96
|
-
start: { line: -1, column: -1, offset: argOffset },
|
|
97
|
-
end: { line: -1, column: -1, offset: argOffset + 'key'.length },
|
|
98
|
-
source: 'key',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
modifiers: [],
|
|
102
|
-
});
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function normalizeIfBranch(ifNode, children, start) {
|
|
110
|
-
let end = start;
|
|
111
|
-
let comments = [];
|
|
112
|
-
for (let i = start + 1; i < children.length; i++) {
|
|
113
|
-
const sibling = children[i];
|
|
114
|
-
if (sibling.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
115
|
-
comments.push(sibling);
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (sibling.type === CompilerDOM.NodeTypes.TEXT && !sibling.content.trim()) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
const elseBranch = getVElseDirective(sibling);
|
|
122
|
-
if (elseBranch) {
|
|
123
|
-
const branchNode = {
|
|
124
|
-
...elseBranch.element,
|
|
125
|
-
props: elseBranch.element.props.filter(prop => prop !== elseBranch.directive),
|
|
126
|
-
};
|
|
127
|
-
const branch = createIfBranch(branchNode, elseBranch.directive);
|
|
128
|
-
if (comments.length) {
|
|
129
|
-
branch.children = [...comments, ...branch.children];
|
|
130
|
-
}
|
|
131
|
-
ifNode.branches.push(branch);
|
|
132
|
-
comments = [];
|
|
133
|
-
end = i;
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
return { node: ifNode, end };
|
|
139
|
-
}
|
|
140
|
-
// source: https://github.com/vuejs/core/blob/25ebe3a42cd80ac0256355c2740a0258cdd7419d/packages/compiler-core/src/transforms/vIf.ts#L207
|
|
141
|
-
function createIfBranch(node, dir) {
|
|
142
|
-
const isTemplateIf = node.tagType === CompilerDOM.ElementTypes.TEMPLATE;
|
|
143
|
-
return {
|
|
144
|
-
type: CompilerDOM.NodeTypes.IF_BRANCH,
|
|
145
|
-
loc: node.loc,
|
|
146
|
-
condition: dir.name === 'else' ? undefined : dir.exp,
|
|
147
|
-
children: isTemplateIf && !CompilerDOM.findDir(node, 'for') && !CompilerDOM.findDir(node, 'slot')
|
|
148
|
-
? node.children
|
|
149
|
-
: [node],
|
|
150
|
-
userKey: CompilerDOM.findProp(node, 'key'),
|
|
151
|
-
isTemplateIf,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function getVElseDirective(node) {
|
|
155
|
-
if (node.type !== CompilerDOM.NodeTypes.ELEMENT) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const directive = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
159
|
-
&& (prop.name === 'else-if' || prop.name === 'else'));
|
|
160
|
-
if (directive) {
|
|
161
|
-
return {
|
|
162
|
-
element: node,
|
|
163
|
-
directive,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function getVForNode(node, transformContext) {
|
|
168
|
-
const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
169
|
-
&& prop.name === 'for');
|
|
170
|
-
if (forDirective) {
|
|
171
|
-
let forNode;
|
|
172
|
-
CompilerDOM.processFor(node, forDirective, transformContext, _forNode => {
|
|
173
|
-
forNode = { ..._forNode };
|
|
174
|
-
return undefined;
|
|
175
|
-
});
|
|
176
|
-
if (forNode) {
|
|
177
|
-
forNode.children = [{
|
|
178
|
-
...node,
|
|
179
|
-
props: node.props.filter(prop => prop !== forDirective),
|
|
180
|
-
}];
|
|
181
|
-
return forNode;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
function getVIfNode(node, transformContext) {
|
|
186
|
-
const ifDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
187
|
-
&& prop.name === 'if');
|
|
188
|
-
if (ifDirective) {
|
|
189
|
-
let ifNode;
|
|
190
|
-
CompilerDOM.processIf(node, ifDirective, transformContext, _ifNode => {
|
|
191
|
-
ifNode = { ..._ifNode };
|
|
192
|
-
return undefined;
|
|
193
|
-
});
|
|
194
|
-
if (ifNode) {
|
|
195
|
-
for (const branch of ifNode.branches) {
|
|
196
|
-
branch.children = [{
|
|
197
|
-
...node,
|
|
198
|
-
props: node.props.filter(prop => prop !== ifDirective),
|
|
199
|
-
}];
|
|
200
|
-
}
|
|
201
|
-
return ifNode;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
//# sourceMappingURL=normalize.js.map
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
const { readFile, writeFile } = require('node:fs/promises');
|
|
3
|
-
const { join } = require('node:path');
|
|
4
|
-
|
|
5
|
-
generateNames();
|
|
6
|
-
|
|
7
|
-
async function generateNames() {
|
|
8
|
-
const typePath = join(__dirname, '../types/template-helpers.d.ts');
|
|
9
|
-
const typeText = await readFile(typePath, 'utf-8');
|
|
10
|
-
|
|
11
|
-
/** @type {Set<string>} */
|
|
12
|
-
const pascalNames = new Set();
|
|
13
|
-
/** @type {Set<string>} */
|
|
14
|
-
const camelNames = new Set();
|
|
15
|
-
|
|
16
|
-
const declReg = /(?<=const\s+)\w*?(?=:)|(?<=type\s+)\w*?(?=\s*=|<)|(?<=function\s+)\w*?(?=\(|<)/g;
|
|
17
|
-
const prefix = '__VLS_';
|
|
18
|
-
|
|
19
|
-
for (const match of typeText.matchAll(declReg)) {
|
|
20
|
-
const name = match[0].slice(prefix.length);
|
|
21
|
-
if (name[0]?.toUpperCase() === name[0]) {
|
|
22
|
-
pascalNames.add(name);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
camelNames.add(name);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const namesPath = join(__dirname, '../lib/codegen/names.ts');
|
|
30
|
-
const namesText = await readFile(namesPath, 'utf-8');
|
|
31
|
-
|
|
32
|
-
await writeFile(
|
|
33
|
-
namesPath,
|
|
34
|
-
namesText.replace(
|
|
35
|
-
/(?<=\/\/ #region .*\n).*?(?=\t\/\/ #endregion)/ms,
|
|
36
|
-
[...camelNames].sort().map(name => `\t${name}: '',\n`).join('')
|
|
37
|
-
+ '\n'
|
|
38
|
-
+ [...pascalNames].sort().map(name => `\t${name}: '',\n`).join(''),
|
|
39
|
-
),
|
|
40
|
-
);
|
|
41
|
-
}
|