@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
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -50,29 +50,29 @@ const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
|
|
|
50
50
|
const plugin = ({ modules: { typescript: ts }, vueCompilerOptions, }) => {
|
|
51
51
|
return {
|
|
52
52
|
version: 2.2,
|
|
53
|
-
getEmbeddedCodes(_fileName,
|
|
54
|
-
const lang = computeLang(
|
|
53
|
+
getEmbeddedCodes(_fileName, ir) {
|
|
54
|
+
const lang = computeLang(ir);
|
|
55
55
|
return [{ lang, id: 'script_' + lang }];
|
|
56
56
|
},
|
|
57
|
-
resolveEmbeddedCode(fileName,
|
|
57
|
+
resolveEmbeddedCode(fileName, ir, embeddedFile) {
|
|
58
58
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
59
|
-
let codegen = exports.tsCodegen.get(
|
|
59
|
+
let codegen = exports.tsCodegen.get(ir);
|
|
60
60
|
if (!codegen) {
|
|
61
|
-
exports.tsCodegen.set(
|
|
61
|
+
exports.tsCodegen.set(ir, codegen = useCodegen(ts, vueCompilerOptions, fileName, ir));
|
|
62
62
|
}
|
|
63
63
|
const generatedScript = codegen.getGeneratedScript();
|
|
64
64
|
embeddedFile.content = [...generatedScript.codes];
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
};
|
|
68
|
-
function computeLang(
|
|
69
|
-
let lang =
|
|
70
|
-
if (
|
|
71
|
-
if (
|
|
72
|
-
lang =
|
|
68
|
+
function computeLang(ir) {
|
|
69
|
+
let lang = ir.scriptSetup?.lang ?? ir.script?.lang;
|
|
70
|
+
if (ir.script && ir.scriptSetup) {
|
|
71
|
+
if (ir.scriptSetup.lang !== 'js') {
|
|
72
|
+
lang = ir.scriptSetup.lang;
|
|
73
73
|
}
|
|
74
74
|
else {
|
|
75
|
-
lang =
|
|
75
|
+
lang = ir.script.lang;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
if (lang && validLangs.has(lang)) {
|
|
@@ -82,9 +82,9 @@ const plugin = ({ modules: { typescript: ts }, vueCompilerOptions, }) => {
|
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
84
|
exports.default = plugin;
|
|
85
|
-
function useCodegen(ts, vueCompilerOptions, fileName,
|
|
85
|
+
function useCodegen(ts, vueCompilerOptions, fileName, ir) {
|
|
86
86
|
const getResolvedOptions = (0, alien_signals_1.computed)(() => {
|
|
87
|
-
const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(
|
|
87
|
+
const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(ir.comments);
|
|
88
88
|
if (options) {
|
|
89
89
|
const resolver = new compilerOptions_1.CompilerOptionsResolver(ts, () => undefined /* does not support resolving target="auto" */);
|
|
90
90
|
resolver.addConfig(options, path.dirname(fileName));
|
|
@@ -92,23 +92,23 @@ function useCodegen(ts, vueCompilerOptions, fileName, sfc) {
|
|
|
92
92
|
}
|
|
93
93
|
return vueCompilerOptions;
|
|
94
94
|
});
|
|
95
|
-
const getScriptRanges = (0, alien_signals_1.computed)(() =>
|
|
96
|
-
? (0, scriptRanges_1.parseScriptRanges)(ts,
|
|
95
|
+
const getScriptRanges = (0, alien_signals_1.computed)(() => ir.script && validLangs.has(ir.script.lang)
|
|
96
|
+
? (0, scriptRanges_1.parseScriptRanges)(ts, ir.script.ast, getResolvedOptions())
|
|
97
97
|
: undefined);
|
|
98
|
-
const getScriptSetupRanges = (0, alien_signals_1.computed)(() =>
|
|
99
|
-
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts,
|
|
98
|
+
const getScriptSetupRanges = (0, alien_signals_1.computed)(() => ir.scriptSetup && validLangs.has(ir.scriptSetup.lang)
|
|
99
|
+
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, ir.scriptSetup.ast, getResolvedOptions())
|
|
100
100
|
: undefined);
|
|
101
101
|
const getImportedComponents = (0, signals_1.computedSet)(() => {
|
|
102
102
|
const names = new Set();
|
|
103
103
|
const scriptSetupRanges = getScriptSetupRanges();
|
|
104
|
-
if (
|
|
104
|
+
if (ir.scriptSetup && scriptSetupRanges) {
|
|
105
105
|
for (const range of scriptSetupRanges.components) {
|
|
106
|
-
names.add(
|
|
106
|
+
names.add(ir.scriptSetup.content.slice(range.start, range.end));
|
|
107
107
|
}
|
|
108
108
|
const scriptRange = getScriptRanges();
|
|
109
|
-
if (
|
|
109
|
+
if (ir.script && scriptRange) {
|
|
110
110
|
for (const range of scriptRange.components) {
|
|
111
|
-
names.add(
|
|
111
|
+
names.add(ir.script.content.slice(range.start, range.end));
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -142,12 +142,12 @@ function useCodegen(ts, vueCompilerOptions, fileName, sfc) {
|
|
|
142
142
|
const getComponentName = (0, alien_signals_1.computed)(() => {
|
|
143
143
|
let name;
|
|
144
144
|
const componentOptions = getScriptRanges()?.exportDefault?.options;
|
|
145
|
-
if (
|
|
146
|
-
name =
|
|
145
|
+
if (ir.script && componentOptions?.name) {
|
|
146
|
+
name = ir.script.content.slice(componentOptions.name.start + 1, componentOptions.name.end - 1);
|
|
147
147
|
}
|
|
148
148
|
else {
|
|
149
149
|
const { defineOptions } = getScriptSetupRanges() ?? {};
|
|
150
|
-
if (
|
|
150
|
+
if (ir.scriptSetup && defineOptions?.name) {
|
|
151
151
|
name = defineOptions.name;
|
|
152
152
|
}
|
|
153
153
|
else {
|
|
@@ -158,13 +158,13 @@ function useCodegen(ts, vueCompilerOptions, fileName, sfc) {
|
|
|
158
158
|
return (0, shared_1.capitalize)((0, shared_1.camelize)(name));
|
|
159
159
|
});
|
|
160
160
|
const getGeneratedTemplate = (0, alien_signals_1.computed)(() => {
|
|
161
|
-
if (getResolvedOptions().skipTemplateCodegen || !
|
|
161
|
+
if (getResolvedOptions().skipTemplateCodegen || !ir.template) {
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
164
|
return (0, template_1.generateTemplate)({
|
|
165
165
|
typescript: ts,
|
|
166
166
|
vueCompilerOptions: getResolvedOptions(),
|
|
167
|
-
template:
|
|
167
|
+
template: ir.template,
|
|
168
168
|
componentName: getComponentName(),
|
|
169
169
|
setupConsts: getSetupConsts(),
|
|
170
170
|
setupRefs: getSetupRefs(),
|
|
@@ -175,13 +175,13 @@ function useCodegen(ts, vueCompilerOptions, fileName, sfc) {
|
|
|
175
175
|
});
|
|
176
176
|
});
|
|
177
177
|
const getGeneratedStyle = (0, alien_signals_1.computed)(() => {
|
|
178
|
-
if (!
|
|
178
|
+
if (!ir.styles.length) {
|
|
179
179
|
return;
|
|
180
180
|
}
|
|
181
181
|
return (0, style_1.generateStyle)({
|
|
182
182
|
typescript: ts,
|
|
183
183
|
vueCompilerOptions: getResolvedOptions(),
|
|
184
|
-
styles:
|
|
184
|
+
styles: ir.styles,
|
|
185
185
|
setupConsts: getSetupConsts(),
|
|
186
186
|
setupRefs: getSetupRefs(),
|
|
187
187
|
});
|
|
@@ -189,17 +189,17 @@ function useCodegen(ts, vueCompilerOptions, fileName, sfc) {
|
|
|
189
189
|
const getSetupExposed = (0, signals_1.computedSet)(() => {
|
|
190
190
|
const allVars = new Set();
|
|
191
191
|
const scriptSetupRanges = getScriptSetupRanges();
|
|
192
|
-
if (!
|
|
192
|
+
if (!ir.scriptSetup || !scriptSetupRanges) {
|
|
193
193
|
return allVars;
|
|
194
194
|
}
|
|
195
195
|
for (const range of scriptSetupRanges.bindings) {
|
|
196
|
-
const name =
|
|
196
|
+
const name = ir.scriptSetup.content.slice(range.start, range.end);
|
|
197
197
|
allVars.add(name);
|
|
198
198
|
}
|
|
199
199
|
const scriptRanges = getScriptRanges();
|
|
200
|
-
if (
|
|
200
|
+
if (ir.script && scriptRanges) {
|
|
201
201
|
for (const range of scriptRanges.bindings) {
|
|
202
|
-
const name =
|
|
202
|
+
const name = ir.script.content.slice(range.start, range.end);
|
|
203
203
|
allVars.add(name);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -209,15 +209,15 @@ function useCodegen(ts, vueCompilerOptions, fileName, sfc) {
|
|
|
209
209
|
return new Set([
|
|
210
210
|
...getGeneratedTemplate()?.componentAccessMap.keys() ?? [],
|
|
211
211
|
...getGeneratedStyle()?.componentAccessMap.keys() ?? [],
|
|
212
|
-
...
|
|
212
|
+
...ir.template?.ast?.components.flatMap(name => [(0, shared_1.camelize)(name), (0, shared_1.capitalize)((0, shared_1.camelize)(name))]) ?? [],
|
|
213
213
|
].filter(name => allVars.has(name)));
|
|
214
214
|
});
|
|
215
215
|
const getGeneratedScript = (0, alien_signals_1.computed)(() => {
|
|
216
216
|
return (0, script_1.generateScript)({
|
|
217
217
|
vueCompilerOptions: getResolvedOptions(),
|
|
218
218
|
fileName,
|
|
219
|
-
script:
|
|
220
|
-
scriptSetup:
|
|
219
|
+
script: ir.script,
|
|
220
|
+
scriptSetup: ir.scriptSetup,
|
|
221
221
|
exposed: getSetupExposed(),
|
|
222
222
|
scriptRanges: getScriptRanges(),
|
|
223
223
|
scriptSetupRanges: getScriptSetupRanges(),
|
|
@@ -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
|