@vue-jsx-vapor/compiler 2.3.0 → 2.3.2

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/dist/index.cjs CHANGED
@@ -1,1727 +1,1451 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/compile.ts
2
- var _parser = require('@babel/parser');
3
-
4
-
5
- var _compilervapor = require('@vue/compiler-vapor');
6
- var _shared = require('@vue/shared');
7
-
8
- // src/generate.ts
9
-
10
-
11
-
12
-
13
-
14
-
15
- // src/ir/component.ts
16
- var IRDynamicPropsKind = /* @__PURE__ */ ((IRDynamicPropsKind2) => {
17
- IRDynamicPropsKind2[IRDynamicPropsKind2["EXPRESSION"] = 0] = "EXPRESSION";
18
- IRDynamicPropsKind2[IRDynamicPropsKind2["ATTRIBUTE"] = 1] = "ATTRIBUTE";
19
- return IRDynamicPropsKind2;
20
- })(IRDynamicPropsKind || {});
21
- var IRSlotType = /* @__PURE__ */ ((IRSlotType2) => {
22
- IRSlotType2[IRSlotType2["STATIC"] = 0] = "STATIC";
23
- IRSlotType2[IRSlotType2["DYNAMIC"] = 1] = "DYNAMIC";
24
- IRSlotType2[IRSlotType2["LOOP"] = 2] = "LOOP";
25
- IRSlotType2[IRSlotType2["CONDITIONAL"] = 3] = "CONDITIONAL";
26
- IRSlotType2[IRSlotType2["EXPRESSION"] = 4] = "EXPRESSION";
27
- return IRSlotType2;
28
- })(IRSlotType || {});
29
-
30
- // src/ir/index.ts
31
- var IRNodeTypes = /* @__PURE__ */ ((IRNodeTypes2) => {
32
- IRNodeTypes2[IRNodeTypes2["ROOT"] = 0] = "ROOT";
33
- IRNodeTypes2[IRNodeTypes2["BLOCK"] = 1] = "BLOCK";
34
- IRNodeTypes2[IRNodeTypes2["SET_PROP"] = 2] = "SET_PROP";
35
- IRNodeTypes2[IRNodeTypes2["SET_DYNAMIC_PROPS"] = 3] = "SET_DYNAMIC_PROPS";
36
- IRNodeTypes2[IRNodeTypes2["SET_TEXT"] = 4] = "SET_TEXT";
37
- IRNodeTypes2[IRNodeTypes2["SET_EVENT"] = 5] = "SET_EVENT";
38
- IRNodeTypes2[IRNodeTypes2["SET_DYNAMIC_EVENTS"] = 6] = "SET_DYNAMIC_EVENTS";
39
- IRNodeTypes2[IRNodeTypes2["SET_HTML"] = 7] = "SET_HTML";
40
- IRNodeTypes2[IRNodeTypes2["SET_TEMPLATE_REF"] = 8] = "SET_TEMPLATE_REF";
41
- IRNodeTypes2[IRNodeTypes2["INSERT_NODE"] = 9] = "INSERT_NODE";
42
- IRNodeTypes2[IRNodeTypes2["PREPEND_NODE"] = 10] = "PREPEND_NODE";
43
- IRNodeTypes2[IRNodeTypes2["CREATE_COMPONENT_NODE"] = 11] = "CREATE_COMPONENT_NODE";
44
- IRNodeTypes2[IRNodeTypes2["SLOT_OUTLET_NODE"] = 12] = "SLOT_OUTLET_NODE";
45
- IRNodeTypes2[IRNodeTypes2["DIRECTIVE"] = 13] = "DIRECTIVE";
46
- IRNodeTypes2[IRNodeTypes2["DECLARE_OLD_REF"] = 14] = "DECLARE_OLD_REF";
47
- IRNodeTypes2[IRNodeTypes2["IF"] = 15] = "IF";
48
- IRNodeTypes2[IRNodeTypes2["FOR"] = 16] = "FOR";
49
- IRNodeTypes2[IRNodeTypes2["GET_TEXT_CHILD"] = 17] = "GET_TEXT_CHILD";
50
- IRNodeTypes2[IRNodeTypes2["CREATE_NODES"] = 18] = "CREATE_NODES";
51
- IRNodeTypes2[IRNodeTypes2["SET_NODES"] = 19] = "SET_NODES";
52
- return IRNodeTypes2;
53
- })(IRNodeTypes || {});
54
- var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
55
- DynamicFlag2[DynamicFlag2["NONE"] = 0] = "NONE";
56
- DynamicFlag2[DynamicFlag2["REFERENCED"] = 1] = "REFERENCED";
57
- DynamicFlag2[DynamicFlag2["NON_TEMPLATE"] = 2] = "NON_TEMPLATE";
58
- DynamicFlag2[DynamicFlag2["INSERT"] = 4] = "INSERT";
59
- return DynamicFlag2;
60
- })(DynamicFlag || {});
1
+ "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+
24
+ //#endregion
25
+ const __babel_parser = __toESM(require("@babel/parser"));
26
+ const __vue_compiler_vapor = __toESM(require("@vue/compiler-vapor"));
27
+ const __vue_shared = __toESM(require("@vue/shared"));
28
+ const __vue_compiler_dom = __toESM(require("@vue/compiler-dom"));
29
+ const __babel_types = __toESM(require("@babel/types"));
30
+
31
+ //#region src/ir/component.ts
32
+ let IRDynamicPropsKind = /* @__PURE__ */ function(IRDynamicPropsKind$1) {
33
+ IRDynamicPropsKind$1[IRDynamicPropsKind$1["EXPRESSION"] = 0] = "EXPRESSION";
34
+ IRDynamicPropsKind$1[IRDynamicPropsKind$1["ATTRIBUTE"] = 1] = "ATTRIBUTE";
35
+ return IRDynamicPropsKind$1;
36
+ }({});
37
+ let IRSlotType = /* @__PURE__ */ function(IRSlotType$1) {
38
+ IRSlotType$1[IRSlotType$1["STATIC"] = 0] = "STATIC";
39
+ IRSlotType$1[IRSlotType$1["DYNAMIC"] = 1] = "DYNAMIC";
40
+ IRSlotType$1[IRSlotType$1["LOOP"] = 2] = "LOOP";
41
+ IRSlotType$1[IRSlotType$1["CONDITIONAL"] = 3] = "CONDITIONAL";
42
+ IRSlotType$1[IRSlotType$1["EXPRESSION"] = 4] = "EXPRESSION";
43
+ return IRSlotType$1;
44
+ }({});
45
+
46
+ //#endregion
47
+ //#region src/ir/index.ts
48
+ let IRNodeTypes = /* @__PURE__ */ function(IRNodeTypes$1) {
49
+ IRNodeTypes$1[IRNodeTypes$1["ROOT"] = 0] = "ROOT";
50
+ IRNodeTypes$1[IRNodeTypes$1["BLOCK"] = 1] = "BLOCK";
51
+ IRNodeTypes$1[IRNodeTypes$1["SET_PROP"] = 2] = "SET_PROP";
52
+ IRNodeTypes$1[IRNodeTypes$1["SET_DYNAMIC_PROPS"] = 3] = "SET_DYNAMIC_PROPS";
53
+ IRNodeTypes$1[IRNodeTypes$1["SET_TEXT"] = 4] = "SET_TEXT";
54
+ IRNodeTypes$1[IRNodeTypes$1["SET_EVENT"] = 5] = "SET_EVENT";
55
+ IRNodeTypes$1[IRNodeTypes$1["SET_DYNAMIC_EVENTS"] = 6] = "SET_DYNAMIC_EVENTS";
56
+ IRNodeTypes$1[IRNodeTypes$1["SET_HTML"] = 7] = "SET_HTML";
57
+ IRNodeTypes$1[IRNodeTypes$1["SET_TEMPLATE_REF"] = 8] = "SET_TEMPLATE_REF";
58
+ IRNodeTypes$1[IRNodeTypes$1["INSERT_NODE"] = 9] = "INSERT_NODE";
59
+ IRNodeTypes$1[IRNodeTypes$1["PREPEND_NODE"] = 10] = "PREPEND_NODE";
60
+ IRNodeTypes$1[IRNodeTypes$1["CREATE_COMPONENT_NODE"] = 11] = "CREATE_COMPONENT_NODE";
61
+ IRNodeTypes$1[IRNodeTypes$1["SLOT_OUTLET_NODE"] = 12] = "SLOT_OUTLET_NODE";
62
+ IRNodeTypes$1[IRNodeTypes$1["DIRECTIVE"] = 13] = "DIRECTIVE";
63
+ IRNodeTypes$1[IRNodeTypes$1["DECLARE_OLD_REF"] = 14] = "DECLARE_OLD_REF";
64
+ IRNodeTypes$1[IRNodeTypes$1["IF"] = 15] = "IF";
65
+ IRNodeTypes$1[IRNodeTypes$1["FOR"] = 16] = "FOR";
66
+ IRNodeTypes$1[IRNodeTypes$1["GET_TEXT_CHILD"] = 17] = "GET_TEXT_CHILD";
67
+ IRNodeTypes$1[IRNodeTypes$1["CREATE_NODES"] = 18] = "CREATE_NODES";
68
+ IRNodeTypes$1[IRNodeTypes$1["SET_NODES"] = 19] = "SET_NODES";
69
+ return IRNodeTypes$1;
70
+ }({});
71
+ let DynamicFlag = /* @__PURE__ */ function(DynamicFlag$1) {
72
+ DynamicFlag$1[DynamicFlag$1["NONE"] = 0] = "NONE";
73
+ /**
74
+ * This node is referenced and needs to be saved as a variable.
75
+ */
76
+ DynamicFlag$1[DynamicFlag$1["REFERENCED"] = 1] = "REFERENCED";
77
+ /**
78
+ * This node is not generated from template, but is generated dynamically.
79
+ */
80
+ DynamicFlag$1[DynamicFlag$1["NON_TEMPLATE"] = 2] = "NON_TEMPLATE";
81
+ /**
82
+ * This node needs to be inserted back into the template.
83
+ */
84
+ DynamicFlag$1[DynamicFlag$1["INSERT"] = 4] = "INSERT";
85
+ return DynamicFlag$1;
86
+ }({});
61
87
  function isBlockOperation(op) {
62
- const type = op.type;
63
- return type === 11 /* CREATE_COMPONENT_NODE */ || type === 12 /* SLOT_OUTLET_NODE */ || type === 15 /* IF */ || type === 16 /* FOR */;
88
+ const type = op.type;
89
+ return type === IRNodeTypes.CREATE_COMPONENT_NODE || type === IRNodeTypes.SLOT_OUTLET_NODE || type === IRNodeTypes.IF || type === IRNodeTypes.FOR;
64
90
  }
65
91
 
66
- // src/generate.ts
67
- var customGenOperation = (oper, context) => {
68
- if (oper.type === 18 /* CREATE_NODES */) {
69
- return genCreateNodes(oper, context);
70
- } else if (oper.type === 19 /* SET_NODES */) {
71
- return genSetNodes(oper, context);
72
- }
92
+ //#endregion
93
+ //#region src/generate.ts
94
+ const customGenOperation = (oper, context) => {
95
+ if (oper.type === IRNodeTypes.CREATE_NODES) return genCreateNodes(oper, context);
96
+ else if (oper.type === IRNodeTypes.SET_NODES) return genSetNodes(oper, context);
73
97
  };
74
98
  function genSetNodes(oper, context) {
75
- const { helper } = context;
76
- const { element, values, generated } = oper;
77
- return [
78
- _compilervapor.NEWLINE,
79
- ..._compilervapor.genCall.call(void 0,
80
- helper("setNodes"),
81
- `${generated ? "x" : "n"}${element}`,
82
- combineValues(values, context)
83
- )
84
- ];
99
+ const { helper } = context;
100
+ const { element, values, generated } = oper;
101
+ return [__vue_compiler_vapor.NEWLINE, ...(0, __vue_compiler_vapor.genCall)(helper("setNodes"), `${generated ? "x" : "n"}${element}`, combineValues(values, context))];
85
102
  }
86
103
  function genCreateNodes(oper, context) {
87
- const { helper } = context;
88
- const { id, values } = oper;
89
- return [
90
- _compilervapor.NEWLINE,
91
- `const n${id} = `,
92
- ..._compilervapor.genCall.call(void 0, helper("createNodes"), values && combineValues(values, context))
93
- ];
104
+ const { helper } = context;
105
+ const { id, values } = oper;
106
+ return [
107
+ __vue_compiler_vapor.NEWLINE,
108
+ `const n${id} = `,
109
+ ...(0, __vue_compiler_vapor.genCall)(helper("createNodes"), values && combineValues(values, context))
110
+ ];
94
111
  }
95
112
  function combineValues(values, context) {
96
- return values.flatMap((value, i) => {
97
- const exp = _compilervapor.genExpression.call(void 0, value, context);
98
- if (i > 0) {
99
- exp.unshift(", ");
100
- }
101
- return exp;
102
- });
113
+ return values.flatMap((value, i) => {
114
+ const exp = (0, __vue_compiler_vapor.genExpression)(value, context);
115
+ if (i > 0) exp.unshift(", ");
116
+ return exp;
117
+ });
103
118
  }
104
119
 
105
- // src/transform.ts
106
-
107
-
108
-
109
- var _compilerdom = require('@vue/compiler-dom');
110
-
111
-
112
- // src/transforms/utils.ts
113
-
114
-
115
-
116
-
117
-
118
- var _types = require('@babel/types');
119
-
120
-
121
- // src/utils.ts
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
120
+ //#endregion
121
+ //#region src/utils.ts
135
122
  function propToExpression(prop, context) {
136
- return prop.type === "JSXAttribute" && _optionalChain([prop, 'access', _2 => _2.value, 'optionalAccess', _3 => _3.type]) === "JSXExpressionContainer" ? resolveExpression(prop.value.expression, context) : EMPTY_EXPRESSION;
123
+ return prop.type === "JSXAttribute" && prop.value?.type === "JSXExpressionContainer" ? resolveExpression(prop.value.expression, context) : EMPTY_EXPRESSION;
137
124
  }
138
125
  function isConstantExpression(exp) {
139
- return _compilerdom.isLiteralWhitelisted.call(void 0, exp.content) || _shared.isGloballyAllowed.call(void 0, exp.content) || getLiteralExpressionValue(exp) !== null;
126
+ return (0, __vue_compiler_dom.isLiteralWhitelisted)(exp.content) || (0, __vue_shared.isGloballyAllowed)(exp.content) || getLiteralExpressionValue(exp) !== null;
140
127
  }
141
128
  function getLiteralExpressionValue(exp) {
142
- if (exp.ast) {
143
- if (["StringLiteral", "NumericLiteral", "BigIntLiteral"].includes(
144
- exp.ast.type
145
- )) {
146
- return exp.ast.value;
147
- } else if (exp.ast.type === "TemplateLiteral" && exp.ast.expressions.length === 0) {
148
- return exp.ast.quasis[0].value.cooked;
149
- }
150
- }
151
- return exp.isStatic ? exp.content : null;
129
+ if (exp.ast) {
130
+ if ([
131
+ "StringLiteral",
132
+ "NumericLiteral",
133
+ "BigIntLiteral"
134
+ ].includes(exp.ast.type)) return exp.ast.value;
135
+ else if (exp.ast.type === "TemplateLiteral" && exp.ast.expressions.length === 0) return exp.ast.quasis[0].value.cooked;
136
+ }
137
+ return exp.isStatic ? exp.content : null;
152
138
  }
153
- var isConstant = (node) => {
154
- if (!node) return false;
155
- if (node.type === "Identifier") {
156
- return node.name === "undefined";
157
- }
158
- if (node.type === "ArrayExpression") {
159
- const { elements } = node;
160
- return elements.every((element) => element && isConstant(element));
161
- }
162
- if (node.type === "ObjectExpression") {
163
- return node.properties.every(
164
- (property) => isConstant(property.value)
165
- );
166
- }
167
- if (node.type === "TemplateLiteral" ? !node.expressions.length : _types.isLiteral.call(void 0, node)) {
168
- return true;
169
- }
170
- return false;
139
+ const isConstant = (node) => {
140
+ if (!node) return false;
141
+ if (node.type === "Identifier") return node.name === "undefined";
142
+ if (node.type === "ArrayExpression") {
143
+ const { elements } = node;
144
+ return elements.every((element) => element && isConstant(element));
145
+ }
146
+ if (node.type === "ObjectExpression") return node.properties.every((property) => isConstant(property.value));
147
+ if (node.type === "TemplateLiteral" ? !node.expressions.length : (0, __babel_types.isLiteral)(node)) return true;
148
+ return false;
171
149
  };
172
- var EMPTY_TEXT_REGEX = /^[\t\v\f \u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*[\n\r]\s*$/;
173
- var START_EMPTY_TEXT_REGEX = /^\s*[\n\r]/;
174
- var END_EMPTY_TEXT_REGEX = /[\n\r]\s*$/;
150
+ const EMPTY_TEXT_REGEX = /^[\t\v\f \u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*[\n\r]\s*$/;
151
+ const START_EMPTY_TEXT_REGEX = /^\s*[\n\r]/;
152
+ const END_EMPTY_TEXT_REGEX = /[\n\r]\s*$/;
175
153
  function resolveJSXText(node) {
176
- if (EMPTY_TEXT_REGEX.test(String(_optionalChain([node, 'access', _4 => _4.extra, 'optionalAccess', _5 => _5.raw])))) {
177
- return "";
178
- }
179
- let value = node.value;
180
- if (START_EMPTY_TEXT_REGEX.test(value)) {
181
- value = value.trimStart();
182
- }
183
- if (END_EMPTY_TEXT_REGEX.test(value)) {
184
- value = value.trimEnd();
185
- }
186
- return value;
154
+ if (EMPTY_TEXT_REGEX.test(String(node.extra?.raw))) return "";
155
+ let value = node.value;
156
+ if (START_EMPTY_TEXT_REGEX.test(value)) value = value.trimStart();
157
+ if (END_EMPTY_TEXT_REGEX.test(value)) value = value.trimEnd();
158
+ return value;
187
159
  }
188
160
  function isEmptyText(node) {
189
- return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(String(_optionalChain([node, 'access', _6 => _6.extra, 'optionalAccess', _7 => _7.raw]))) || node.type === "JSXExpressionContainer" && node.expression.type === "JSXEmptyExpression";
161
+ return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(String(node.extra?.raw)) || node.type === "JSXExpressionContainer" && node.expression.type === "JSXEmptyExpression";
190
162
  }
191
163
  function resolveSimpleExpressionNode(exp) {
192
- if (!exp.isStatic) {
193
- const value = getLiteralExpressionValue(exp);
194
- if (value !== null) {
195
- return _compilerdom.createSimpleExpression.call(void 0, String(value), true, exp.loc);
196
- }
197
- }
198
- return exp;
164
+ if (!exp.isStatic) {
165
+ const value = getLiteralExpressionValue(exp);
166
+ if (value !== null) return (0, __vue_compiler_dom.createSimpleExpression)(String(value), true, exp.loc);
167
+ }
168
+ return exp;
199
169
  }
170
+ const resolvedExpressions = new WeakSet();
200
171
  function resolveExpression(node, context, effect = false) {
201
- node = _optionalChain([node, 'optionalAccess', _8 => _8.type]) === "JSXExpressionContainer" ? node.expression : node;
202
- const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
203
- let source = !node || node.type === "JSXEmptyExpression" ? "" : node.type === "JSXIdentifier" ? node.name : node.type === "StringLiteral" ? node.value : node.type === "JSXText" ? resolveJSXText(node) : node.type === "Identifier" ? node.name : context.ir.source.slice(node.start, node.end);
204
- const location = node ? node.loc : null;
205
- if (source && !isStatic && effect && !isConstant(node)) {
206
- source = `() => (${source})`;
207
- if (location && node) {
208
- location.start.column -= 7;
209
- node.start -= 7;
210
- }
211
- }
212
- if (node) {
213
- const offset = node.start - 1;
214
- _compilerdom.walkIdentifiers.call(void 0,
215
- node,
216
- (id) => {
217
- if (!id.loc) return;
218
- id.start = id.loc.start.index - offset;
219
- id.end = id.loc.end.index - offset;
220
- },
221
- true
222
- );
223
- }
224
- return resolveSimpleExpression(source, isStatic, location, node);
172
+ node = node?.type === "JSXExpressionContainer" ? node.expression : node;
173
+ const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
174
+ let source = !node || node.type === "JSXEmptyExpression" ? "" : node.type === "JSXIdentifier" ? node.name : node.type === "StringLiteral" ? node.value : node.type === "JSXText" ? resolveJSXText(node) : node.type === "Identifier" ? node.name : context.ir.source.slice(node.start, node.end);
175
+ const location = node ? node.loc : null;
176
+ const isResolved = node && resolvedExpressions.has(node);
177
+ if (source && !isStatic && effect && !isConstant(node)) {
178
+ source = `() => (${source})`;
179
+ if (location && node && !isResolved) {
180
+ location.start.column -= 7;
181
+ node.start -= 7;
182
+ }
183
+ }
184
+ if (node && !isResolved) {
185
+ const offset = node.start - 1;
186
+ (0, __vue_compiler_dom.walkIdentifiers)(node, (id) => {
187
+ if (!id.loc) return;
188
+ id.start = id.loc.start.index - offset;
189
+ id.end = id.loc.end.index - offset;
190
+ }, true);
191
+ resolvedExpressions.add(node);
192
+ }
193
+ return resolveSimpleExpression(source, isStatic, location, node);
225
194
  }
226
195
  function resolveSimpleExpression(source, isStatic, location, ast) {
227
- const result = _compilerdom.createSimpleExpression.call(void 0,
228
- source,
229
- isStatic,
230
- resolveLocation(location, source)
231
- );
232
- result.ast = _nullishCoalesce(ast, () => ( null));
233
- return result;
196
+ const result = (0, __vue_compiler_dom.createSimpleExpression)(source, isStatic, resolveLocation(location, source));
197
+ result.ast = ast ?? null;
198
+ return result;
234
199
  }
235
200
  function resolveLocation(location, context) {
236
- return location ? {
237
- start: {
238
- line: location.start.line,
239
- column: location.start.column + 1,
240
- offset: location.start.index
241
- },
242
- end: {
243
- line: location.end.line,
244
- column: location.end.column + 1,
245
- offset: location.end.index
246
- },
247
- source: _shared.isString.call(void 0, context) ? context : context.ir.source.slice(location.start.index, location.end.index)
248
- } : {
249
- start: { line: 1, column: 1, offset: 0 },
250
- end: { line: 1, column: 1, offset: 0 },
251
- source: ""
252
- };
253
- }
254
- function resolveValue(value, context) {
255
- return value ? {
256
- type: _compilerdom.NodeTypes.TEXT,
257
- content: value.type === "StringLiteral" ? value.value : value.type === "JSXExpressionContainer" ? context.ir.source.slice(
258
- value.expression.start,
259
- value.expression.end
260
- ) : "",
261
- loc: resolveLocation(value.loc, context)
262
- } : void 0;
201
+ return location ? {
202
+ start: {
203
+ line: location.start.line,
204
+ column: location.start.column + 1,
205
+ offset: location.start.index
206
+ },
207
+ end: {
208
+ line: location.end.line,
209
+ column: location.end.column + 1,
210
+ offset: location.end.index
211
+ },
212
+ source: (0, __vue_shared.isString)(context) ? context : context.ir.source.slice(location.start.index, location.end.index)
213
+ } : {
214
+ start: {
215
+ line: 1,
216
+ column: 1,
217
+ offset: 0
218
+ },
219
+ end: {
220
+ line: 1,
221
+ column: 1,
222
+ offset: 0
223
+ },
224
+ source: ""
225
+ };
263
226
  }
264
- function resolveNode(node, context) {
265
- const tag = node.openingElement.name.type === "JSXIdentifier" ? node.openingElement.name.name : "";
266
- const loc = resolveLocation(node.loc, context);
267
- const tagType = isJSXComponent(node) ? _compilerdom.ElementTypes.COMPONENT : _compilerdom.ElementTypes.ELEMENT;
268
- const props = node.openingElement.attributes.reduce(
269
- (result, attr) => {
270
- if (attr.type === "JSXAttribute") {
271
- result.push(
272
- _optionalChain([attr, 'access', _9 => _9.value, 'optionalAccess', _10 => _10.type]) === "StringLiteral" ? {
273
- type: _compilerdom.NodeTypes.ATTRIBUTE,
274
- name: String(attr.name.name),
275
- nameLoc: resolveLocation(attr.name.loc, context),
276
- value: resolveValue(attr.value, context),
277
- loc: resolveLocation(attr.loc, context)
278
- } : resolveDirectiveNode(attr, context)
279
- );
280
- } else if (attr.type === "JSXSpreadAttribute") {
281
- result.push({
282
- type: _compilerdom.NodeTypes.DIRECTIVE,
283
- name: "bind",
284
- rawName: getText(attr, context),
285
- exp: resolveExpression(attr.argument, context),
286
- arg: void 0,
287
- loc: resolveLocation(node.loc, context),
288
- modifiers: []
289
- });
290
- }
291
- return result;
292
- },
293
- []
294
- );
295
- return {
296
- type: _compilerdom.NodeTypes.ELEMENT,
297
- props,
298
- children: node.children,
299
- tag,
300
- loc,
301
- ns: _compilerdom.Namespaces.HTML,
302
- tagType,
303
- isSelfClosing: !!node.selfClosing,
304
- codegenNode: void 0
305
- };
306
- }
307
- var namespaceRE = /^(?:\$([\w-]+)\$)?([\w-]+)?/;
308
- function resolveDirectiveNode(node, context, withFn = false) {
309
- const { value, name } = node;
310
- let nameString = name.type === "JSXNamespacedName" ? name.namespace.name : name.type === "JSXIdentifier" ? name.name : "";
311
- const isDirective = nameString.startsWith("v-");
312
- let modifiers = [];
313
- let isStatic = true;
314
- let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
315
- if (name.type !== "JSXNamespacedName" && !argString) {
316
- ;
317
- [nameString, ...modifiers] = nameString.split("_");
318
- } else {
319
- const result = argString.match(namespaceRE);
320
- if (result) {
321
- let modifierString = "";
322
- [, argString, modifierString] = result;
323
- if (argString) {
324
- argString = argString.replaceAll("_", ".");
325
- isStatic = false;
326
- if (modifierString && modifierString.startsWith("_"))
327
- modifiers = modifierString.slice(1).split("_");
328
- } else if (modifierString) {
329
- ;
330
- [argString, ...modifiers] = modifierString.split("_");
331
- }
332
- }
333
- }
334
- const arg = isDirective ? argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0 : resolveSimpleExpression(nameString, true, name.loc);
335
- const exp = value ? withFn && value.type === "JSXExpressionContainer" ? resolveExpressionWithFn(value.expression, context) : resolveExpression(value, context) : void 0;
336
- return {
337
- type: _compilerdom.NodeTypes.DIRECTIVE,
338
- name: isDirective ? nameString.slice(2) : "bind",
339
- rawName: getText(name, context),
340
- exp,
341
- arg,
342
- loc: resolveLocation(node.loc, context),
343
- modifiers: modifiers.map((modifier) => _compilerdom.createSimpleExpression.call(void 0, modifier))
344
- };
227
+ const namespaceRE = /^(?:\$([\w-]+)\$)?([\w-]+)?/;
228
+ function resolveDirective(node, context, withFn = false) {
229
+ const { value, name } = node;
230
+ let nameString = name.type === "JSXNamespacedName" ? name.namespace.name : name.type === "JSXIdentifier" ? name.name : "";
231
+ const isDirective = nameString.startsWith("v-");
232
+ let modifiers = [];
233
+ let isStatic = true;
234
+ let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
235
+ if (name.type !== "JSXNamespacedName" && !argString) [nameString, ...modifiers] = nameString.split("_");
236
+ else {
237
+ const result = argString.match(namespaceRE);
238
+ if (result) {
239
+ let modifierString = "";
240
+ [, argString, modifierString] = result;
241
+ if (argString) {
242
+ argString = argString.replaceAll("_", ".");
243
+ isStatic = false;
244
+ if (modifierString && modifierString.startsWith("_")) modifiers = modifierString.slice(1).split("_");
245
+ } else if (modifierString) [argString, ...modifiers] = modifierString.split("_");
246
+ }
247
+ }
248
+ const arg = isDirective ? argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0 : resolveSimpleExpression(nameString, true, name.loc);
249
+ const exp = value ? withFn && value.type === "JSXExpressionContainer" ? resolveExpressionWithFn(value.expression, context) : resolveExpression(value, context) : void 0;
250
+ return {
251
+ type: __vue_compiler_dom.NodeTypes.DIRECTIVE,
252
+ name: isDirective ? nameString.slice(2) : "bind",
253
+ rawName: getText(name, context),
254
+ exp,
255
+ arg,
256
+ loc: resolveLocation(node.loc, context),
257
+ modifiers: modifiers.map((modifier) => (0, __vue_compiler_dom.createSimpleExpression)(modifier))
258
+ };
345
259
  }
346
260
  function resolveExpressionWithFn(node, context) {
347
- const text = getText(node, context);
348
- return node.type === "Identifier" ? resolveSimpleExpression(text, false, node.loc) : resolveSimpleExpression(
349
- text,
350
- false,
351
- node.loc,
352
- _parser.parseExpression.call(void 0, `(${text})=>{}`, {
353
- plugins: ["typescript"]
354
- })
355
- );
261
+ const text = getText(node, context);
262
+ return node.type === "Identifier" ? resolveSimpleExpression(text, false, node.loc) : resolveSimpleExpression(text, false, node.loc, (0, __babel_parser.parseExpression)(`(${text})=>{}`, { plugins: ["typescript"] }));
356
263
  }
357
264
  function isJSXComponent(node) {
358
- if (node.type !== "JSXElement") return false;
359
- const { openingElement } = node;
360
- if (openingElement.name.type === "JSXIdentifier") {
361
- const name = openingElement.name.name;
362
- return !_shared.isHTMLTag.call(void 0, name) && !_shared.isSVGTag.call(void 0, name);
363
- } else {
364
- return openingElement.name.type === "JSXMemberExpression";
365
- }
265
+ if (node.type !== "JSXElement") return false;
266
+ const { openingElement } = node;
267
+ if (openingElement.name.type === "JSXIdentifier") {
268
+ const name = openingElement.name.name;
269
+ return !(0, __vue_shared.isHTMLTag)(name) && !(0, __vue_shared.isSVGTag)(name);
270
+ } else return openingElement.name.type === "JSXMemberExpression";
366
271
  }
367
272
  function findProp(expression, key) {
368
- if (_optionalChain([expression, 'optionalAccess', _11 => _11.type]) === "JSXElement") {
369
- for (const attr of expression.openingElement.attributes) {
370
- const name = attr.type === "JSXAttribute" && (attr.name.type === "JSXIdentifier" ? attr.name.name : attr.name.type === "JSXNamespacedName" ? attr.name.namespace.name : "").split("_")[0];
371
- if (name && (_shared.isString.call(void 0, key) ? name === key : key.test(name))) {
372
- return attr;
373
- }
374
- }
375
- }
273
+ if (expression?.type === "JSXElement") for (const attr of expression.openingElement.attributes) {
274
+ const name = attr.type === "JSXAttribute" && (attr.name.type === "JSXIdentifier" ? attr.name.name : attr.name.type === "JSXNamespacedName" ? attr.name.namespace.name : "").split("_")[0];
275
+ if (name && ((0, __vue_shared.isString)(key) ? name === key : key.test(name))) return attr;
276
+ }
376
277
  }
377
278
  function getText(node, content) {
378
- return content.ir.source.slice(node.start, node.end);
279
+ return content.ir.source.slice(node.start, node.end);
379
280
  }
380
281
  function isTemplate(node) {
381
- if (node.type === "JSXElement" && node.openingElement.name.type === "JSXIdentifier") {
382
- return node.openingElement.name.name === "template";
383
- }
282
+ if (node.type === "JSXElement" && node.openingElement.name.type === "JSXIdentifier") return node.openingElement.name.name === "template";
384
283
  }
385
284
 
386
- // src/transforms/utils.ts
285
+ //#endregion
286
+ //#region src/transforms/utils.ts
387
287
  function newDynamic() {
388
- return {
389
- flags: 1 /* REFERENCED */,
390
- children: []
391
- };
288
+ return {
289
+ flags: DynamicFlag.REFERENCED,
290
+ children: []
291
+ };
392
292
  }
393
293
  function newBlock(node) {
394
- return {
395
- type: 1,
396
- node,
397
- dynamic: newDynamic(),
398
- effect: [],
399
- operation: [],
400
- returns: [],
401
- expressions: [],
402
- tempId: 0
403
- };
294
+ return {
295
+ type: 1,
296
+ node,
297
+ dynamic: newDynamic(),
298
+ effect: [],
299
+ operation: [],
300
+ returns: [],
301
+ expressions: [],
302
+ tempId: 0
303
+ };
404
304
  }
405
305
  function createBranch(node, context, isVFor) {
406
- context.node = node = wrapFragment(node);
407
- const branch = newBlock(node);
408
- const exitBlock = context.enterBlock(branch, isVFor);
409
- context.reference();
410
- return [branch, exitBlock];
306
+ context.node = node = wrapFragment(node);
307
+ const branch = newBlock(node);
308
+ const exitBlock = context.enterBlock(branch, isVFor);
309
+ context.reference();
310
+ return [branch, exitBlock];
411
311
  }
412
312
  function wrapFragment(node) {
413
- if (node.type === "JSXFragment" || isTemplate(node)) {
414
- return node;
415
- }
416
- return _types.jsxFragment.call(void 0, _types.jsxOpeningFragment.call(void 0, ), _types.jsxClosingFragment.call(void 0, ), [
417
- node.type === "JSXElement" ? node : _types.jsxExpressionContainer.call(void 0, node)
418
- ]);
313
+ if (node.type === "JSXFragment" || isTemplate(node)) return node;
314
+ return (0, __babel_types.jsxFragment)((0, __babel_types.jsxOpeningFragment)(), (0, __babel_types.jsxClosingFragment)(), [node.type === "JSXElement" ? node : (0, __babel_types.jsxExpressionContainer)(node)]);
419
315
  }
420
- var EMPTY_EXPRESSION = _compilerdom.createSimpleExpression.call(void 0, "", true);
421
- var isFragmentNode = (node) => node.type === 0 /* ROOT */ || node.type === "JSXFragment" || node.type === "JSXElement" && !!isTemplate(node);
422
-
423
- // src/transform.ts
424
- var defaultOptions = {
425
- filename: "",
426
- prefixIdentifiers: false,
427
- hoistStatic: false,
428
- hmr: false,
429
- cacheHandlers: false,
430
- nodeTransforms: [],
431
- directiveTransforms: {},
432
- transformHoist: null,
433
- isBuiltInComponent: _shared.NOOP,
434
- isCustomElement: _shared.NOOP,
435
- expressionPlugins: [],
436
- scopeId: null,
437
- slotted: true,
438
- ssr: false,
439
- inSSR: false,
440
- ssrCssVars: ``,
441
- bindingMetadata: _shared.EMPTY_OBJ,
442
- inline: false,
443
- isTS: false,
444
- onError: _compilerdom.defaultOnError,
445
- onWarn: _compilerdom.defaultOnWarn
316
+ const EMPTY_EXPRESSION = (0, __vue_compiler_dom.createSimpleExpression)("", true);
317
+ const isFragmentNode = (node) => node.type === IRNodeTypes.ROOT || node.type === "JSXFragment" || node.type === "JSXElement" && !!isTemplate(node);
318
+
319
+ //#endregion
320
+ //#region src/transform.ts
321
+ const defaultOptions = {
322
+ filename: "",
323
+ prefixIdentifiers: false,
324
+ hoistStatic: false,
325
+ hmr: false,
326
+ cacheHandlers: false,
327
+ nodeTransforms: [],
328
+ directiveTransforms: {},
329
+ transformHoist: null,
330
+ isBuiltInComponent: __vue_shared.NOOP,
331
+ isCustomElement: __vue_shared.NOOP,
332
+ expressionPlugins: [],
333
+ scopeId: null,
334
+ slotted: true,
335
+ ssr: false,
336
+ inSSR: false,
337
+ ssrCssVars: ``,
338
+ bindingMetadata: __vue_shared.EMPTY_OBJ,
339
+ inline: false,
340
+ isTS: false,
341
+ onError: __vue_compiler_dom.defaultOnError,
342
+ onWarn: __vue_compiler_dom.defaultOnWarn
446
343
  };
447
- var TransformContext = class _TransformContext {
448
- constructor(ir, node, options = {}) {
449
- this.ir = ir;
450
- this.node = node;
451
- this.parent = null;
452
- this.index = 0;
453
- this.block = this.ir.block;
454
- this.template = "";
455
- this.childrenTemplate = [];
456
- this.dynamic = this.ir.block.dynamic;
457
- this.inVOnce = false;
458
- this.inVFor = 0;
459
- this.comment = [];
460
- this.component = this.ir.component;
461
- this.directive = this.ir.directive;
462
- this.slots = [];
463
- this.globalId = 0;
464
- this.increaseId = () => this.globalId++;
465
- this.options = _shared.extend.call(void 0, {}, defaultOptions, options);
466
- this.root = this;
467
- }
468
- enterBlock(ir, isVFor = false) {
469
- const { block, template, dynamic, childrenTemplate, slots } = this;
470
- this.block = ir;
471
- this.dynamic = ir.dynamic;
472
- this.template = "";
473
- this.childrenTemplate = [];
474
- this.slots = [];
475
- isVFor && this.inVFor++;
476
- return () => {
477
- this.registerTemplate();
478
- this.block = block;
479
- this.template = template;
480
- this.dynamic = dynamic;
481
- this.childrenTemplate = childrenTemplate;
482
- this.slots = slots;
483
- isVFor && this.inVFor--;
484
- };
485
- }
486
- reference() {
487
- if (this.dynamic.id !== void 0) return this.dynamic.id;
488
- this.dynamic.flags |= 1 /* REFERENCED */;
489
- return this.dynamic.id = this.increaseId();
490
- }
491
- pushTemplate(content) {
492
- const existing = this.ir.template.indexOf(content);
493
- if (existing !== -1) return existing;
494
- this.ir.template.push(content);
495
- return this.ir.template.length - 1;
496
- }
497
- registerTemplate() {
498
- if (!this.template) return -1;
499
- const id = this.pushTemplate(this.template);
500
- return this.dynamic.template = id;
501
- }
502
- registerEffect(expressions, ...operations) {
503
- expressions = expressions.filter((exp) => !isConstantExpression(exp));
504
- if (this.inVOnce || expressions.length === 0) {
505
- return this.registerOperation(...operations);
506
- }
507
- const existing = this.block.effect.find(
508
- (e) => isSameExpression(e.expressions, expressions)
509
- );
510
- if (existing) {
511
- existing.operations.push(...operations);
512
- } else {
513
- this.block.effect.push({
514
- expressions,
515
- operations
516
- });
517
- }
518
- function isSameExpression(a, b) {
519
- if (a.length !== b.length) return false;
520
- return a.every((exp, i) => exp.content === b[i].content);
521
- }
522
- }
523
- registerOperation(...node) {
524
- this.block.operation.push(...node);
525
- }
526
- create(node, index) {
527
- return Object.assign(Object.create(_TransformContext.prototype), this, {
528
- node,
529
- parent: this,
530
- index,
531
- template: "",
532
- childrenTemplate: [],
533
- dynamic: newDynamic()
534
- });
535
- }
344
+ var TransformContext = class TransformContext {
345
+ parent = null;
346
+ root;
347
+ index = 0;
348
+ block;
349
+ options;
350
+ template = "";
351
+ childrenTemplate = [];
352
+ dynamic;
353
+ inVOnce = false;
354
+ inVFor = 0;
355
+ comment = [];
356
+ component;
357
+ directive;
358
+ slots = [];
359
+ globalId = 0;
360
+ constructor(ir, node, options = {}) {
361
+ this.ir = ir;
362
+ this.node = node;
363
+ this.options = (0, __vue_shared.extend)({}, defaultOptions, options);
364
+ this.block = this.ir.block;
365
+ this.dynamic = this.ir.block.dynamic;
366
+ this.component = this.ir.component;
367
+ this.directive = this.ir.directive;
368
+ this.root = this;
369
+ }
370
+ enterBlock(ir, isVFor = false) {
371
+ const { block, template, dynamic, childrenTemplate, slots } = this;
372
+ this.block = ir;
373
+ this.dynamic = ir.dynamic;
374
+ this.template = "";
375
+ this.childrenTemplate = [];
376
+ this.slots = [];
377
+ isVFor && this.inVFor++;
378
+ return () => {
379
+ this.registerTemplate();
380
+ this.block = block;
381
+ this.template = template;
382
+ this.dynamic = dynamic;
383
+ this.childrenTemplate = childrenTemplate;
384
+ this.slots = slots;
385
+ isVFor && this.inVFor--;
386
+ };
387
+ }
388
+ increaseId = () => this.globalId++;
389
+ reference() {
390
+ if (this.dynamic.id !== void 0) return this.dynamic.id;
391
+ this.dynamic.flags |= DynamicFlag.REFERENCED;
392
+ return this.dynamic.id = this.increaseId();
393
+ }
394
+ pushTemplate(content) {
395
+ const existing = this.ir.template.indexOf(content);
396
+ if (existing !== -1) return existing;
397
+ this.ir.template.push(content);
398
+ return this.ir.template.length - 1;
399
+ }
400
+ registerTemplate() {
401
+ if (!this.template) return -1;
402
+ const id = this.pushTemplate(this.template);
403
+ return this.dynamic.template = id;
404
+ }
405
+ registerEffect(expressions, ...operations) {
406
+ expressions = expressions.filter((exp) => !isConstantExpression(exp));
407
+ if (this.inVOnce || expressions.length === 0 || expressions.every((e) => e.ast && (0, __vue_compiler_dom.isConstantNode)(e.ast, {}))) return this.registerOperation(...operations);
408
+ this.block.expressions.push(...expressions);
409
+ const existing = this.block.effect.find((e) => isSameExpression(e.expressions, expressions));
410
+ if (existing) existing.operations.push(...operations);
411
+ else this.block.effect.push({
412
+ expressions,
413
+ operations
414
+ });
415
+ function isSameExpression(a, b) {
416
+ if (a.length !== b.length) return false;
417
+ return a.every((exp, i) => exp.content === b[i].content);
418
+ }
419
+ }
420
+ registerOperation(...node) {
421
+ this.block.operation.push(...node);
422
+ }
423
+ create(node, index) {
424
+ return Object.assign(Object.create(TransformContext.prototype), this, {
425
+ node,
426
+ parent: this,
427
+ index,
428
+ template: "",
429
+ childrenTemplate: [],
430
+ dynamic: newDynamic()
431
+ });
432
+ }
536
433
  };
537
434
  function transform(node, options = {}) {
538
- const ir = {
539
- type: 0 /* ROOT */,
540
- node,
541
- source: node.source,
542
- template: [],
543
- component: /* @__PURE__ */ new Set(),
544
- directive: /* @__PURE__ */ new Set(),
545
- block: newBlock(node),
546
- hasTemplateRef: false
547
- };
548
- const context = new TransformContext(ir, node, options);
549
- transformNode(context);
550
- return ir;
435
+ const ir = {
436
+ type: IRNodeTypes.ROOT,
437
+ node,
438
+ source: node.source,
439
+ template: [],
440
+ component: new Set(),
441
+ directive: new Set(),
442
+ block: newBlock(node),
443
+ hasTemplateRef: false
444
+ };
445
+ const context = new TransformContext(ir, node, options);
446
+ transformNode(context);
447
+ return ir;
551
448
  }
552
449
  function transformNode(context) {
553
- let { node } = context;
554
- const { nodeTransforms } = context.options;
555
- const exitFns = [];
556
- for (const nodeTransform of nodeTransforms) {
557
- const onExit = nodeTransform(node, context);
558
- if (onExit) {
559
- if (_shared.isArray.call(void 0, onExit)) {
560
- exitFns.push(...onExit);
561
- } else {
562
- exitFns.push(onExit);
563
- }
564
- }
565
- if (!context.node) {
566
- return;
567
- } else {
568
- node = context.node;
569
- }
570
- }
571
- context.node = node;
572
- let i = exitFns.length;
573
- while (i--) {
574
- exitFns[i]();
575
- }
576
- if (context.node.type === 0 /* ROOT */) {
577
- context.registerTemplate();
578
- }
450
+ let { node } = context;
451
+ const { nodeTransforms } = context.options;
452
+ const exitFns = [];
453
+ for (const nodeTransform of nodeTransforms) {
454
+ const onExit = nodeTransform(node, context);
455
+ if (onExit) if ((0, __vue_shared.isArray)(onExit)) exitFns.push(...onExit);
456
+ else exitFns.push(onExit);
457
+ if (!context.node) return;
458
+ else node = context.node;
459
+ }
460
+ context.node = node;
461
+ let i = exitFns.length;
462
+ while (i--) exitFns[i]();
463
+ if (context.node.type === IRNodeTypes.ROOT) context.registerTemplate();
579
464
  }
580
465
  function createStructuralDirectiveTransform(name, fn) {
581
- const matches = (n) => _shared.isString.call(void 0, name) ? n === name : name.includes(n);
582
- return (node, context) => {
583
- if (node.type === "JSXElement") {
584
- const {
585
- openingElement: { attributes }
586
- } = node;
587
- if (isTemplate(node) && findProp(node, "v-slot")) {
588
- return;
589
- }
590
- const exitFns = [];
591
- for (const prop of attributes) {
592
- if (prop.type !== "JSXAttribute") continue;
593
- const propName = getText(prop.name, context);
594
- if (propName.startsWith("v-") && matches(propName.slice(2))) {
595
- attributes.splice(attributes.indexOf(prop), 1);
596
- const onExit = fn(node, prop, context);
597
- if (onExit) exitFns.push(onExit);
598
- break;
599
- }
600
- }
601
- return exitFns;
602
- }
603
- };
466
+ const matches = (n) => (0, __vue_shared.isString)(name) ? n === name : name.includes(n);
467
+ return (node, context) => {
468
+ if (node.type === "JSXElement") {
469
+ const { openingElement: { attributes } } = node;
470
+ if (isTemplate(node) && findProp(node, "v-slot")) return;
471
+ const exitFns = [];
472
+ for (const prop of attributes) {
473
+ if (prop.type !== "JSXAttribute") continue;
474
+ const propName = getText(prop.name, context);
475
+ if (propName.startsWith("v-") && matches(propName.slice(2))) {
476
+ attributes.splice(attributes.indexOf(prop), 1);
477
+ const onExit = fn(node, prop, context);
478
+ if (onExit) exitFns.push(onExit);
479
+ break;
480
+ }
481
+ }
482
+ return exitFns;
483
+ }
484
+ };
604
485
  }
605
486
 
606
- // src/transforms/transformChildren.ts
607
- var transformChildren = (node, context) => {
608
- const isFragment = node.type === 0 /* ROOT */ || node.type === "JSXFragment" || node.type === "JSXElement" && (isTemplate(node) || isJSXComponent(node));
609
- if (node.type !== "JSXElement" && !isFragment) return;
610
- for (const [i, child] of node.children.entries()) {
611
- const childContext = context.create(child, i);
612
- transformNode(childContext);
613
- const childDynamic = childContext.dynamic;
614
- if (isFragment) {
615
- childContext.reference();
616
- childContext.registerTemplate();
617
- if (!(childDynamic.flags & 2 /* NON_TEMPLATE */) || childDynamic.flags & 4 /* INSERT */) {
618
- context.block.returns.push(childDynamic.id);
619
- }
620
- } else {
621
- context.childrenTemplate.push(childContext.template);
622
- }
623
- if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 /* NON_TEMPLATE */ || childDynamic.flags & 4 /* INSERT */) {
624
- context.dynamic.hasDynamicChild = true;
625
- }
626
- context.dynamic.children[i] = childContext.dynamic;
627
- }
628
- if (!isFragment) {
629
- processDynamicChildren(context);
630
- }
487
+ //#endregion
488
+ //#region src/transforms/transformChildren.ts
489
+ const transformChildren = (node, context) => {
490
+ const isFragment = node.type === IRNodeTypes.ROOT || node.type === "JSXFragment" || node.type === "JSXElement" && (isTemplate(node) || isJSXComponent(node));
491
+ if (node.type !== "JSXElement" && !isFragment) return;
492
+ for (const [i, child] of node.children.entries()) {
493
+ const childContext = context.create(child, i);
494
+ transformNode(childContext);
495
+ const childDynamic = childContext.dynamic;
496
+ if (isFragment) {
497
+ childContext.reference();
498
+ childContext.registerTemplate();
499
+ if (!(childDynamic.flags & DynamicFlag.NON_TEMPLATE) || childDynamic.flags & DynamicFlag.INSERT) context.block.returns.push(childDynamic.id);
500
+ } else context.childrenTemplate.push(childContext.template);
501
+ if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & DynamicFlag.NON_TEMPLATE || childDynamic.flags & DynamicFlag.INSERT) context.dynamic.hasDynamicChild = true;
502
+ context.dynamic.children[i] = childContext.dynamic;
503
+ }
504
+ if (!isFragment) processDynamicChildren(context);
631
505
  };
632
506
  function processDynamicChildren(context) {
633
- let prevDynamics = [];
634
- let hasStaticTemplate = false;
635
- const children = context.dynamic.children;
636
- for (const [index, child] of children.entries()) {
637
- if (child.flags & 4 /* INSERT */) {
638
- prevDynamics.push(child);
639
- }
640
- if (!(child.flags & 2 /* NON_TEMPLATE */)) {
641
- if (prevDynamics.length) {
642
- if (hasStaticTemplate) {
643
- context.childrenTemplate[index - prevDynamics.length] = `<!>`;
644
- prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
645
- const anchor = prevDynamics[0].anchor = context.increaseId();
646
- registerInsertion(prevDynamics, context, anchor);
647
- } else {
648
- registerInsertion(
649
- prevDynamics,
650
- context,
651
- -1
652
- /* prepend */
653
- );
654
- }
655
- prevDynamics = [];
656
- }
657
- hasStaticTemplate = true;
658
- }
659
- }
660
- if (prevDynamics.length) {
661
- registerInsertion(prevDynamics, context);
662
- }
507
+ let prevDynamics = [];
508
+ let hasStaticTemplate = false;
509
+ const children = context.dynamic.children;
510
+ for (const [index, child] of children.entries()) {
511
+ if (child.flags & DynamicFlag.INSERT) prevDynamics.push(child);
512
+ if (!(child.flags & DynamicFlag.NON_TEMPLATE)) {
513
+ if (prevDynamics.length) {
514
+ if (hasStaticTemplate) {
515
+ context.childrenTemplate[index - prevDynamics.length] = `<!>`;
516
+ prevDynamics[0].flags -= DynamicFlag.NON_TEMPLATE;
517
+ const anchor = prevDynamics[0].anchor = context.increaseId();
518
+ registerInsertion(prevDynamics, context, anchor);
519
+ } else registerInsertion(
520
+ prevDynamics,
521
+ context,
522
+ -1
523
+ /* prepend */
524
+ );
525
+ prevDynamics = [];
526
+ }
527
+ hasStaticTemplate = true;
528
+ }
529
+ }
530
+ if (prevDynamics.length) registerInsertion(prevDynamics, context);
663
531
  }
664
532
  function registerInsertion(dynamics, context, anchor) {
665
- for (const child of dynamics) {
666
- if (child.template != null) {
667
- context.registerOperation({
668
- type: 9 /* INSERT_NODE */,
669
- elements: dynamics.map((child2) => child2.id),
670
- parent: context.reference(),
671
- anchor
672
- });
673
- } else if (child.operation && isBlockOperation(child.operation)) {
674
- child.operation.parent = context.reference();
675
- child.operation.anchor = anchor;
676
- }
677
- }
533
+ for (const child of dynamics) if (child.template != null) context.registerOperation({
534
+ type: IRNodeTypes.INSERT_NODE,
535
+ elements: dynamics.map((child$1) => child$1.id),
536
+ parent: context.reference(),
537
+ anchor
538
+ });
539
+ else if (child.operation && isBlockOperation(child.operation)) {
540
+ child.operation.parent = context.reference();
541
+ child.operation.anchor = anchor;
542
+ }
678
543
  }
679
544
 
680
- // src/transforms/transformElement.ts
681
-
682
-
683
-
684
-
685
- var isReservedProp = /* @__PURE__ */ _shared.makeMap.call(void 0,
686
- // the leading comma is intentional so empty string "" is also included
687
- ",key,ref,ref_for,ref_key,"
545
+ //#endregion
546
+ //#region src/transforms/transformElement.ts
547
+ const isReservedProp = /* @__PURE__ */ (0, __vue_shared.makeMap)(
548
+ // the leading comma is intentional so empty string "" is also included
549
+ ",key,ref,ref_for,ref_key,"
688
550
  );
689
- var isEventRegex = /^on[A-Z]/;
690
- var isDirectiveRegex = /^v-[a-z]/;
691
- var transformElement = (node, context) => {
692
- return function postTransformElement() {
693
- ;
694
- ({ node } = context);
695
- if (node.type !== "JSXElement" || isTemplate(node)) return;
696
- const {
697
- openingElement: { name }
698
- } = node;
699
- const tag = name.type === "JSXIdentifier" ? name.name : name.type === "JSXMemberExpression" ? context.ir.source.slice(name.start, name.end) : "";
700
- const isComponent = isJSXComponent(node);
701
- const propsResult = buildProps(
702
- node,
703
- context,
704
- isComponent
705
- );
706
- let { parent } = context;
707
- while (parent && parent.parent && parent.node.type === "JSXElement" && isTemplate(parent.node)) {
708
- parent = parent.parent;
709
- }
710
- const singleRoot = context.root === parent && parent.node.children.filter((child) => !isJSXComponent(child)).length === 1;
711
- (isComponent ? transformComponentElement : transformNativeElement)(
712
- tag,
713
- propsResult,
714
- singleRoot,
715
- context
716
- );
717
- };
551
+ const isEventRegex = /^on[A-Z]/;
552
+ const isDirectiveRegex = /^v-[a-z]/;
553
+ const transformElement = (node, context) => {
554
+ return function postTransformElement() {
555
+ ({node} = context);
556
+ if (node.type !== "JSXElement" || isTemplate(node)) return;
557
+ const { openingElement: { name } } = node;
558
+ const tag = name.type === "JSXIdentifier" ? name.name : name.type === "JSXMemberExpression" ? context.ir.source.slice(name.start, name.end) : "";
559
+ const isComponent = isJSXComponent(node);
560
+ const propsResult = buildProps(node, context, isComponent);
561
+ let { parent } = context;
562
+ while (parent && parent.parent && parent.node.type === "JSXElement" && isTemplate(parent.node)) parent = parent.parent;
563
+ const singleRoot = context.root === parent && parent.node.children.filter((child) => !isJSXComponent(child)).length === 1;
564
+ (isComponent ? transformComponentElement : transformNativeElement)(tag, propsResult, singleRoot, context);
565
+ };
718
566
  };
719
567
  function transformComponentElement(tag, propsResult, singleRoot, context) {
720
- let asset = true;
721
- const fromSetup = tag;
722
- if (fromSetup) {
723
- tag = fromSetup;
724
- asset = false;
725
- }
726
- const dotIndex = tag.indexOf(".");
727
- if (dotIndex > 0) {
728
- const ns = tag.slice(0, dotIndex);
729
- if (ns) {
730
- tag = ns + tag.slice(dotIndex);
731
- asset = false;
732
- }
733
- }
734
- if (asset) {
735
- context.component.add(tag);
736
- }
737
- context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
738
- context.dynamic.operation = {
739
- type: 11 /* CREATE_COMPONENT_NODE */,
740
- id: context.reference(),
741
- tag,
742
- props: propsResult[0] ? propsResult[1] : [propsResult[1]],
743
- asset,
744
- root: singleRoot,
745
- slots: [...context.slots],
746
- once: context.inVOnce
747
- };
748
- context.slots = [];
568
+ let asset = true;
569
+ const fromSetup = tag;
570
+ if (fromSetup) {
571
+ tag = fromSetup;
572
+ asset = false;
573
+ }
574
+ const dotIndex = tag.indexOf(".");
575
+ if (dotIndex > 0) {
576
+ const ns = tag.slice(0, dotIndex);
577
+ if (ns) {
578
+ tag = ns + tag.slice(dotIndex);
579
+ asset = false;
580
+ }
581
+ }
582
+ if (asset) context.component.add(tag);
583
+ context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT;
584
+ context.dynamic.operation = {
585
+ type: IRNodeTypes.CREATE_COMPONENT_NODE,
586
+ id: context.reference(),
587
+ tag,
588
+ props: propsResult[0] ? propsResult[1] : [propsResult[1]],
589
+ asset,
590
+ root: singleRoot,
591
+ slots: [...context.slots],
592
+ once: context.inVOnce
593
+ };
594
+ context.slots = [];
749
595
  }
750
596
  function transformNativeElement(tag, propsResult, singleRoot, context) {
751
- const { scopeId } = context.options;
752
- let template = "";
753
- template += `<${tag}`;
754
- if (scopeId) template += ` ${scopeId}`;
755
- const dynamicProps = [];
756
- if (propsResult[0]) {
757
- const [, dynamicArgs, expressions] = propsResult;
758
- context.registerEffect(expressions, {
759
- type: 3 /* SET_DYNAMIC_PROPS */,
760
- element: context.reference(),
761
- props: dynamicArgs,
762
- root: singleRoot
763
- });
764
- } else {
765
- for (const prop of propsResult[1]) {
766
- const { key, values } = prop;
767
- if (key.isStatic && values.length === 1 && values[0].isStatic) {
768
- template += ` ${key.content}`;
769
- if (values[0].content) template += `="${values[0].content}"`;
770
- } else {
771
- dynamicProps.push(key.content);
772
- context.registerEffect(values, {
773
- type: 2 /* SET_PROP */,
774
- element: context.reference(),
775
- prop,
776
- tag,
777
- root: singleRoot
778
- });
779
- }
780
- }
781
- }
782
- template += `>${context.childrenTemplate.join("")}`;
783
- if (!_shared.isVoidTag.call(void 0, tag)) {
784
- template += `</${tag}>`;
785
- }
786
- if (singleRoot) {
787
- context.ir.rootTemplateIndex = context.ir.template.length;
788
- }
789
- if (context.parent && context.parent.node.type === "JSXElement" && context.parent.node.openingElement.name.type === "JSXIdentifier" && !_compilerdom.isValidHTMLNesting.call(void 0, context.parent.node.openingElement.name.name, tag)) {
790
- context.reference();
791
- context.dynamic.template = context.pushTemplate(template);
792
- context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
793
- } else {
794
- context.template += template;
795
- }
597
+ const { scopeId } = context.options;
598
+ let template = "";
599
+ template += `<${tag}`;
600
+ if (scopeId) template += ` ${scopeId}`;
601
+ const dynamicProps = [];
602
+ if (propsResult[0]) {
603
+ const [, dynamicArgs, expressions] = propsResult;
604
+ context.registerEffect(expressions, {
605
+ type: IRNodeTypes.SET_DYNAMIC_PROPS,
606
+ element: context.reference(),
607
+ props: dynamicArgs,
608
+ root: singleRoot
609
+ });
610
+ } else for (const prop of propsResult[1]) {
611
+ const { key, values } = prop;
612
+ if (key.isStatic && values.length === 1 && values[0].isStatic) {
613
+ template += ` ${key.content}`;
614
+ if (values[0].content) template += `="${values[0].content}"`;
615
+ } else {
616
+ dynamicProps.push(key.content);
617
+ context.registerEffect(values, {
618
+ type: IRNodeTypes.SET_PROP,
619
+ element: context.reference(),
620
+ prop,
621
+ tag,
622
+ root: singleRoot
623
+ });
624
+ }
625
+ }
626
+ template += `>${context.childrenTemplate.join("")}`;
627
+ if (!(0, __vue_shared.isVoidTag)(tag)) template += `</${tag}>`;
628
+ if (singleRoot) context.ir.rootTemplateIndex = context.ir.template.length;
629
+ if (context.parent && context.parent.node.type === "JSXElement" && context.parent.node.openingElement.name.type === "JSXIdentifier" && !(0, __vue_compiler_dom.isValidHTMLNesting)(context.parent.node.openingElement.name.name, tag)) {
630
+ context.reference();
631
+ context.dynamic.template = context.pushTemplate(template);
632
+ context.dynamic.flags |= DynamicFlag.INSERT | DynamicFlag.NON_TEMPLATE;
633
+ } else context.template += template;
796
634
  }
797
635
  function buildProps(node, context, isComponent) {
798
- const props = node.openingElement.attributes;
799
- if (props.length === 0) return [false, []];
800
- const dynamicArgs = [];
801
- const dynamicExpr = [];
802
- let results = [];
803
- function pushMergeArg() {
804
- if (results.length) {
805
- dynamicArgs.push(dedupeProperties(results));
806
- results = [];
807
- }
808
- }
809
- for (const prop of props) {
810
- if (prop.type === "JSXSpreadAttribute" && prop.argument) {
811
- const value = resolveExpression(prop.argument, context);
812
- dynamicExpr.push(value);
813
- pushMergeArg();
814
- dynamicArgs.push({
815
- kind: 0 /* EXPRESSION */,
816
- value
817
- });
818
- continue;
819
- }
820
- const result = transformProp(prop, node, context);
821
- if (result) {
822
- dynamicExpr.push(result.key, result.value);
823
- if (isComponent && !result.key.isStatic) {
824
- pushMergeArg();
825
- dynamicArgs.push(
826
- _shared.extend.call(void 0, resolveDirectiveResult(result), {
827
- kind: 1 /* ATTRIBUTE */
828
- })
829
- );
830
- } else {
831
- results.push(result);
832
- }
833
- }
834
- }
835
- if (dynamicArgs.length || results.some(({ key }) => !key.isStatic)) {
836
- pushMergeArg();
837
- return [true, dynamicArgs, dynamicExpr];
838
- }
839
- const irProps = dedupeProperties(results);
840
- return [false, irProps];
636
+ const props = node.openingElement.attributes;
637
+ if (props.length === 0) return [false, []];
638
+ const dynamicArgs = [];
639
+ const dynamicExpr = [];
640
+ let results = [];
641
+ function pushMergeArg() {
642
+ if (results.length) {
643
+ dynamicArgs.push(dedupeProperties(results));
644
+ results = [];
645
+ }
646
+ }
647
+ for (const prop of props) {
648
+ if (prop.type === "JSXSpreadAttribute" && prop.argument) {
649
+ const value = resolveExpression(prop.argument, context);
650
+ dynamicExpr.push(value);
651
+ pushMergeArg();
652
+ dynamicArgs.push({
653
+ kind: IRDynamicPropsKind.EXPRESSION,
654
+ value
655
+ });
656
+ continue;
657
+ }
658
+ const result = transformProp(prop, node, context);
659
+ if (result) {
660
+ dynamicExpr.push(result.key, result.value);
661
+ if (isComponent && !result.key.isStatic) {
662
+ pushMergeArg();
663
+ dynamicArgs.push((0, __vue_shared.extend)(resolveDirectiveResult(result), { kind: IRDynamicPropsKind.ATTRIBUTE }));
664
+ } else results.push(result);
665
+ }
666
+ }
667
+ if (dynamicArgs.length || results.some(({ key }) => !key.isStatic)) {
668
+ pushMergeArg();
669
+ return [
670
+ true,
671
+ dynamicArgs,
672
+ dynamicExpr
673
+ ];
674
+ }
675
+ const irProps = dedupeProperties(results);
676
+ return [false, irProps];
841
677
  }
842
678
  function transformProp(prop, node, context) {
843
- if (prop.type === "JSXSpreadAttribute") return;
844
- let name = prop.name.type === "JSXIdentifier" ? prop.name.name : prop.name.type === "JSXNamespacedName" ? prop.name.namespace.name : "";
845
- name = name.split("_")[0];
846
- if (!isDirectiveRegex.test(name) && !isEventRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
847
- if (isReservedProp(name)) return;
848
- return {
849
- key: resolveSimpleExpression(name, true, prop.name.loc),
850
- value: prop.value && prop.value.type === "StringLiteral" ? resolveSimpleExpression(prop.value.value, true, prop.value.loc) : EMPTY_EXPRESSION
851
- };
852
- }
853
- name = isEventRegex.test(name) ? "on" : isDirectiveRegex.test(name) ? name.slice(2) : "bind";
854
- const directiveTransform = context.options.directiveTransforms[name];
855
- if (directiveTransform) {
856
- return directiveTransform(prop, node, context);
857
- }
858
- if (!_shared.isBuiltInDirective.call(void 0, name)) {
859
- const fromSetup = `v-${name}`;
860
- if (fromSetup) {
861
- name = fromSetup;
862
- } else {
863
- context.directive.add(name);
864
- }
865
- }
679
+ if (prop.type === "JSXSpreadAttribute") return;
680
+ let name = prop.name.type === "JSXIdentifier" ? prop.name.name : prop.name.type === "JSXNamespacedName" ? prop.name.namespace.name : "";
681
+ name = name.split("_")[0];
682
+ if (!isDirectiveRegex.test(name) && !isEventRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
683
+ if (isReservedProp(name)) return;
684
+ return {
685
+ key: resolveSimpleExpression(name, true, prop.name.loc),
686
+ value: prop.value && prop.value.type === "StringLiteral" ? resolveSimpleExpression(prop.value.value, true, prop.value.loc) : EMPTY_EXPRESSION
687
+ };
688
+ }
689
+ name = isEventRegex.test(name) ? "on" : isDirectiveRegex.test(name) ? name.slice(2) : "bind";
690
+ const directiveTransform = context.options.directiveTransforms[name];
691
+ if (directiveTransform) return directiveTransform(prop, node, context);
692
+ if (!(0, __vue_shared.isBuiltInDirective)(name)) {
693
+ const fromSetup = `v-${name}`;
694
+ if (fromSetup) name = fromSetup;
695
+ else context.directive.add(name);
696
+ }
866
697
  }
867
698
  function dedupeProperties(results) {
868
- const knownProps = /* @__PURE__ */ new Map();
869
- const deduped = [];
870
- for (const result of results) {
871
- const prop = resolveDirectiveResult(result);
872
- if (!prop.key.isStatic) {
873
- deduped.push(prop);
874
- continue;
875
- }
876
- const name = prop.key.content;
877
- const existing = knownProps.get(name);
878
- if (existing) {
879
- if (name === "style" || name === "class") {
880
- mergePropValues(existing, prop);
881
- }
882
- } else {
883
- knownProps.set(name, prop);
884
- deduped.push(prop);
885
- }
886
- }
887
- return deduped;
699
+ const knownProps = new Map();
700
+ const deduped = [];
701
+ for (const result of results) {
702
+ const prop = resolveDirectiveResult(result);
703
+ if (!prop.key.isStatic) {
704
+ deduped.push(prop);
705
+ continue;
706
+ }
707
+ const name = prop.key.content;
708
+ const existing = knownProps.get(name);
709
+ if (existing) {
710
+ if (name === "style" || name === "class") mergePropValues(existing, prop);
711
+ } else {
712
+ knownProps.set(name, prop);
713
+ deduped.push(prop);
714
+ }
715
+ }
716
+ return deduped;
888
717
  }
889
718
  function resolveDirectiveResult(prop) {
890
- return _shared.extend.call(void 0, {}, prop, {
891
- value: void 0,
892
- values: [prop.value]
893
- });
719
+ return (0, __vue_shared.extend)({}, prop, {
720
+ value: void 0,
721
+ values: [prop.value]
722
+ });
894
723
  }
895
724
  function mergePropValues(existing, incoming) {
896
- const newValues = incoming.values;
897
- existing.values.push(...newValues);
725
+ const newValues = incoming.values;
726
+ existing.values.push(...newValues);
898
727
  }
899
728
 
900
- // src/transforms/transformTemplateRef.ts
901
- var transformTemplateRef = (node, context) => {
902
- if (node.type !== "JSXElement") return;
903
- const dir = findProp(node, "ref");
904
- if (!_optionalChain([dir, 'optionalAccess', _12 => _12.value])) return;
905
- context.ir.hasTemplateRef = true;
906
- const value = resolveExpression(dir.value, context);
907
- return () => {
908
- const id = context.reference();
909
- const effect = !isConstantExpression(value);
910
- effect && context.registerOperation({
911
- type: 14 /* DECLARE_OLD_REF */,
912
- id
913
- });
914
- context.registerEffect([value], {
915
- type: 8 /* SET_TEMPLATE_REF */,
916
- element: id,
917
- value,
918
- refFor: !!context.inVFor,
919
- effect
920
- });
921
- };
729
+ //#endregion
730
+ //#region src/transforms/transformTemplateRef.ts
731
+ const transformTemplateRef = (node, context) => {
732
+ if (node.type !== "JSXElement") return;
733
+ const dir = findProp(node, "ref");
734
+ if (!dir?.value) return;
735
+ context.ir.hasTemplateRef = true;
736
+ const value = resolveExpression(dir.value, context);
737
+ return () => {
738
+ const id = context.reference();
739
+ const effect = !isConstantExpression(value);
740
+ effect && context.registerOperation({
741
+ type: IRNodeTypes.DECLARE_OLD_REF,
742
+ id
743
+ });
744
+ context.registerEffect([value], {
745
+ type: IRNodeTypes.SET_TEMPLATE_REF,
746
+ element: id,
747
+ value,
748
+ refFor: !!context.inVFor,
749
+ effect
750
+ });
751
+ };
922
752
  };
923
753
 
924
- // src/transforms/expression.ts
925
-
754
+ //#endregion
755
+ //#region src/transforms/expression.ts
926
756
  function processConditionalExpression(node, context) {
927
- const { test, consequent, alternate } = node;
928
- context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
929
- const id = context.reference();
930
- const condition = resolveExpression(test, context);
931
- const [branch, onExit] = createBranch(consequent, context);
932
- const operation = {
933
- type: 15 /* IF */,
934
- id,
935
- condition,
936
- positive: branch,
937
- once: context.inVOnce || _compilerdom.isStaticNode.call(void 0, test)
938
- };
939
- return [
940
- () => {
941
- onExit();
942
- context.dynamic.operation = operation;
943
- },
944
- () => {
945
- const [branch2, onExit2] = createBranch(alternate, context);
946
- operation.negative = branch2;
947
- transformNode(context);
948
- onExit2();
949
- }
950
- ];
757
+ const { test, consequent, alternate } = node;
758
+ context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT;
759
+ const id = context.reference();
760
+ const condition = resolveExpression(test, context);
761
+ const [branch, onExit] = createBranch(consequent, context);
762
+ const operation = {
763
+ type: IRNodeTypes.IF,
764
+ id,
765
+ condition,
766
+ positive: branch,
767
+ once: context.inVOnce || (0, __vue_compiler_dom.isStaticNode)(test)
768
+ };
769
+ return [() => {
770
+ onExit();
771
+ context.dynamic.operation = operation;
772
+ }, () => {
773
+ const [branch$1, onExit$1] = createBranch(alternate, context);
774
+ operation.negative = branch$1;
775
+ transformNode(context);
776
+ onExit$1();
777
+ }];
951
778
  }
952
779
  function processLogicalExpression(node, context) {
953
- const { left, right, operator } = node;
954
- context.dynamic.flags |= 2 /* NON_TEMPLATE */;
955
- context.dynamic.flags |= 4 /* INSERT */;
956
- const id = context.reference();
957
- const condition = resolveExpression(left, context);
958
- const [branch, onExit] = createBranch(
959
- operator === "&&" ? right : left,
960
- context
961
- );
962
- const operation = {
963
- type: 15 /* IF */,
964
- id,
965
- condition,
966
- positive: branch,
967
- once: context.inVOnce
968
- };
969
- return [
970
- () => {
971
- onExit();
972
- context.dynamic.operation = operation;
973
- },
974
- () => {
975
- const [branch2, onExit2] = createBranch(
976
- operator === "&&" ? left : right,
977
- context
978
- );
979
- operation.negative = branch2;
980
- transformNode(context);
981
- onExit2();
982
- }
983
- ];
780
+ const { left, right, operator } = node;
781
+ context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
782
+ context.dynamic.flags |= DynamicFlag.INSERT;
783
+ const id = context.reference();
784
+ const condition = resolveExpression(left, context);
785
+ const [branch, onExit] = createBranch(operator === "&&" ? right : left, context);
786
+ const operation = {
787
+ type: IRNodeTypes.IF,
788
+ id,
789
+ condition,
790
+ positive: branch,
791
+ once: context.inVOnce
792
+ };
793
+ return [() => {
794
+ onExit();
795
+ context.dynamic.operation = operation;
796
+ }, () => {
797
+ const [branch$1, onExit$1] = createBranch(operator === "&&" ? left : right, context);
798
+ operation.negative = branch$1;
799
+ transformNode(context);
800
+ onExit$1();
801
+ }];
984
802
  }
985
803
 
986
- // src/transforms/transformText.ts
987
- var seen = /* @__PURE__ */ new WeakMap();
988
- var transformText = (node, context) => {
989
- if (!seen.has(context.root)) seen.set(context.root, /* @__PURE__ */ new WeakSet());
990
- if (seen.get(context.root).has(node)) {
991
- context.dynamic.flags |= 2 /* NON_TEMPLATE */;
992
- return;
993
- }
994
- const isFragment = isFragmentNode(node);
995
- if ((node.type === "JSXElement" && !isTemplate(node) && !isJSXComponent(node) || isFragment) && node.children.length) {
996
- let hasInterp = false;
997
- let isAllTextLike = true;
998
- for (const c of node.children) {
999
- if (c.type === "JSXExpressionContainer" && c.expression.type !== "ConditionalExpression" && c.expression.type !== "LogicalExpression") {
1000
- hasInterp = true;
1001
- } else if (c.type !== "JSXText") {
1002
- isAllTextLike = false;
1003
- }
1004
- }
1005
- if (!isFragment && isAllTextLike && hasInterp) {
1006
- processTextContainer(node.children, context);
1007
- } else if (hasInterp) {
1008
- for (let i = 0; i < node.children.length; i++) {
1009
- const c = node.children[i];
1010
- const prev = node.children[i - 1];
1011
- if (c.type === "JSXExpressionContainer" && prev && prev.type === "JSXText") {
1012
- seen.get(context.root).add(prev);
1013
- }
1014
- }
1015
- }
1016
- } else if (node.type === "JSXExpressionContainer") {
1017
- if (node.expression.type === "ConditionalExpression") {
1018
- return processConditionalExpression(node.expression, context);
1019
- } else if (node.expression.type === "LogicalExpression") {
1020
- return processLogicalExpression(node.expression, context);
1021
- } else {
1022
- processInterpolation(context);
1023
- }
1024
- } else if (node.type === "JSXText") {
1025
- const value = resolveJSXText(node);
1026
- if (value) {
1027
- context.template += value;
1028
- } else {
1029
- context.dynamic.flags |= 2 /* NON_TEMPLATE */;
1030
- }
1031
- }
804
+ //#endregion
805
+ //#region src/transforms/transformText.ts
806
+ const seen = new WeakMap();
807
+ const transformText = (node, context) => {
808
+ if (!seen.has(context.root)) seen.set(context.root, new WeakSet());
809
+ if (seen.get(context.root).has(node)) {
810
+ context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
811
+ return;
812
+ }
813
+ const isFragment = isFragmentNode(node);
814
+ if ((node.type === "JSXElement" && !isTemplate(node) && !isJSXComponent(node) || isFragment) && node.children.length) {
815
+ let hasInterp = false;
816
+ let isAllTextLike = true;
817
+ for (const c of node.children) if (c.type === "JSXExpressionContainer" && c.expression.type !== "ConditionalExpression" && c.expression.type !== "LogicalExpression") hasInterp = true;
818
+ else if (c.type !== "JSXText") isAllTextLike = false;
819
+ if (!isFragment && isAllTextLike && hasInterp) processTextContainer(node.children, context);
820
+ else if (hasInterp) for (let i = 0; i < node.children.length; i++) {
821
+ const c = node.children[i];
822
+ const prev = node.children[i - 1];
823
+ if (c.type === "JSXExpressionContainer" && prev && prev.type === "JSXText") seen.get(context.root).add(prev);
824
+ }
825
+ } else if (node.type === "JSXExpressionContainer") if (node.expression.type === "ConditionalExpression") return processConditionalExpression(node.expression, context);
826
+ else if (node.expression.type === "LogicalExpression") return processLogicalExpression(node.expression, context);
827
+ else processInterpolation(context);
828
+ else if (node.type === "JSXText") {
829
+ const value = resolveJSXText(node);
830
+ if (value) context.template += value;
831
+ else context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
832
+ }
1032
833
  };
1033
834
  function processInterpolation(context) {
1034
- const parent = context.parent.node;
1035
- const children = parent.children;
1036
- const nexts = children.slice(context.index);
1037
- const idx = nexts.findIndex((n) => !isTextLike(n));
1038
- const nodes = idx !== -1 ? nexts.slice(0, idx) : nexts;
1039
- const prev = children[context.index - 1];
1040
- if (prev && prev.type === "JSXText") {
1041
- nodes.unshift(prev);
1042
- }
1043
- const values = createTextLikeExpressions(nodes, context);
1044
- if (!values.length) {
1045
- context.dynamic.flags |= 2 /* NON_TEMPLATE */;
1046
- return;
1047
- }
1048
- const id = context.reference();
1049
- if (isFragmentNode(parent)) {
1050
- context.registerOperation({
1051
- type: 18 /* CREATE_NODES */,
1052
- id,
1053
- values
1054
- });
1055
- } else {
1056
- context.template += " ";
1057
- context.registerOperation({
1058
- type: 19 /* SET_NODES */,
1059
- element: id,
1060
- values
1061
- });
1062
- }
835
+ const parent = context.parent.node;
836
+ const children = parent.children;
837
+ const nexts = children.slice(context.index);
838
+ const idx = nexts.findIndex((n) => !isTextLike(n));
839
+ const nodes = idx !== -1 ? nexts.slice(0, idx) : nexts;
840
+ const prev = children[context.index - 1];
841
+ if (prev && prev.type === "JSXText") nodes.unshift(prev);
842
+ const values = createTextLikeExpressions(nodes, context);
843
+ if (!values.length) {
844
+ context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
845
+ return;
846
+ }
847
+ const id = context.reference();
848
+ if (isFragmentNode(parent)) context.registerOperation({
849
+ type: IRNodeTypes.CREATE_NODES,
850
+ id,
851
+ values
852
+ });
853
+ else {
854
+ context.template += " ";
855
+ context.registerOperation({
856
+ type: IRNodeTypes.SET_NODES,
857
+ element: id,
858
+ values
859
+ });
860
+ }
1063
861
  }
1064
862
  function processTextContainer(children, context) {
1065
- const values = createTextLikeExpressions(children, context);
1066
- const literals = values.map(getLiteralExpressionValue);
1067
- if (literals.every((l) => l != null)) {
1068
- context.childrenTemplate = literals.map((l) => String(l));
1069
- } else {
1070
- context.childrenTemplate = [" "];
1071
- context.registerOperation({
1072
- type: 17 /* GET_TEXT_CHILD */,
1073
- parent: context.reference()
1074
- });
1075
- context.registerOperation({
1076
- type: 19 /* SET_NODES */,
1077
- element: context.reference(),
1078
- values,
1079
- // indicates this node is generated, so prefix should be "x" instead of "n"
1080
- generated: true
1081
- });
1082
- }
863
+ const values = createTextLikeExpressions(children, context);
864
+ const literals = values.map(getLiteralExpressionValue);
865
+ if (literals.every((l) => l != null)) context.childrenTemplate = literals.map((l) => String(l));
866
+ else {
867
+ context.childrenTemplate = [" "];
868
+ context.registerOperation({
869
+ type: IRNodeTypes.GET_TEXT_CHILD,
870
+ parent: context.reference()
871
+ });
872
+ context.registerOperation({
873
+ type: IRNodeTypes.SET_NODES,
874
+ element: context.reference(),
875
+ values,
876
+ generated: true
877
+ });
878
+ }
1083
879
  }
1084
880
  function createTextLikeExpressions(nodes, context) {
1085
- const values = [];
1086
- for (const node of nodes) {
1087
- seen.get(context.root).add(node);
1088
- if (isEmptyText(node)) continue;
1089
- values.push(resolveExpression(node, context, !context.inVOnce));
1090
- }
1091
- return values;
881
+ const values = [];
882
+ for (const node of nodes) {
883
+ seen.get(context.root).add(node);
884
+ if (isEmptyText(node)) continue;
885
+ values.push(resolveExpression(node, context, !context.inVOnce));
886
+ }
887
+ return values;
1092
888
  }
1093
889
  function isTextLike(node) {
1094
- return node.type === "JSXExpressionContainer" && node.expression.type !== "ConditionalExpression" && node.expression.type !== "LogicalExpression" || node.type === "JSXText";
890
+ return node.type === "JSXExpressionContainer" && node.expression.type !== "ConditionalExpression" && node.expression.type !== "LogicalExpression" || node.type === "JSXText";
1095
891
  }
1096
892
 
1097
- // src/transforms/vBind.ts
1098
-
1099
- var transformVBind = (dir, node, context) => {
1100
- const { name, value, loc } = dir;
1101
- if (!loc || name.type === "JSXNamespacedName") return;
1102
- const [nameString, ...modifiers] = name.name.split("_");
1103
- const exp = resolveExpression(value, context);
1104
- let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
1105
- if (arg.isStatic && isReservedProp(arg.content)) return;
1106
- let camel = false;
1107
- if (modifiers.includes("camel")) {
1108
- if (arg.isStatic) {
1109
- arg = _shared.extend.call(void 0, {}, arg, { content: _shared.camelize.call(void 0, arg.content) });
1110
- } else {
1111
- camel = true;
1112
- }
1113
- }
1114
- return {
1115
- key: arg,
1116
- value: exp,
1117
- loc,
1118
- runtimeCamelize: camel,
1119
- modifier: modifiers.includes("prop") ? "." : modifiers.includes("attr") ? "^" : void 0
1120
- };
893
+ //#endregion
894
+ //#region src/transforms/vBind.ts
895
+ const transformVBind = (dir, node, context) => {
896
+ const { name, value, loc } = dir;
897
+ if (!loc || name.type === "JSXNamespacedName") return;
898
+ const [nameString, ...modifiers] = name.name.split("_");
899
+ const exp = resolveExpression(value, context);
900
+ let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
901
+ if (arg.isStatic && isReservedProp(arg.content)) return;
902
+ let camel = false;
903
+ if (modifiers.includes("camel")) if (arg.isStatic) arg = (0, __vue_shared.extend)({}, arg, { content: (0, __vue_shared.camelize)(arg.content) });
904
+ else camel = true;
905
+ return {
906
+ key: arg,
907
+ value: exp,
908
+ loc,
909
+ runtimeCamelize: camel,
910
+ modifier: modifiers.includes("prop") ? "." : modifiers.includes("attr") ? "^" : void 0
911
+ };
1121
912
  };
1122
913
 
1123
- // src/transforms/vFor.ts
1124
-
1125
-
1126
-
1127
-
1128
-
1129
- var transformVFor = createStructuralDirectiveTransform(
1130
- "for",
1131
- processFor
1132
- );
914
+ //#endregion
915
+ //#region src/transforms/vFor.ts
916
+ const transformVFor = createStructuralDirectiveTransform("for", processFor);
1133
917
  function processFor(node, dir, context) {
1134
- const { value, index, key, source } = getForParseResult(dir, context);
1135
- if (!source) {
1136
- context.options.onError(
1137
- _compilerdom.createCompilerError.call(void 0,
1138
- _compilerdom.ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION,
1139
- resolveLocation(dir.loc, context)
1140
- )
1141
- );
1142
- return;
1143
- }
1144
- const keyProp = findProp(node, "key");
1145
- const keyProperty = keyProp && propToExpression(keyProp, context);
1146
- const isComponent = isJSXComponent(node);
1147
- const id = context.reference();
1148
- context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
1149
- const [render, exitBlock] = createBranch(node, context, true);
1150
- return () => {
1151
- exitBlock();
1152
- const { parent } = context;
1153
- const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
1154
- context.dynamic.operation = {
1155
- type: 16 /* FOR */,
1156
- id,
1157
- source,
1158
- value,
1159
- key,
1160
- index,
1161
- keyProp: keyProperty,
1162
- render,
1163
- once: context.inVOnce || !!(source.ast && _compilerdom.isConstantNode.call(void 0, source.ast, {})),
1164
- component: isComponent,
1165
- onlyChild: !!isOnlyChild
1166
- };
1167
- };
918
+ const { value, index, key, source } = getForParseResult(dir, context);
919
+ if (!source) {
920
+ context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION, resolveLocation(dir.loc, context)));
921
+ return;
922
+ }
923
+ const keyProp = findProp(node, "key");
924
+ const keyProperty = keyProp && propToExpression(keyProp, context);
925
+ const isComponent = isJSXComponent(node);
926
+ const id = context.reference();
927
+ context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT;
928
+ const [render, exitBlock] = createBranch(node, context, true);
929
+ return () => {
930
+ exitBlock();
931
+ const { parent } = context;
932
+ const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
933
+ context.dynamic.operation = {
934
+ type: IRNodeTypes.FOR,
935
+ id,
936
+ source,
937
+ value,
938
+ key,
939
+ index,
940
+ keyProp: keyProperty,
941
+ render,
942
+ once: context.inVOnce || !!(source.ast && (0, __vue_compiler_dom.isConstantNode)(source.ast, {})),
943
+ component: isComponent,
944
+ onlyChild: !!isOnlyChild
945
+ };
946
+ };
1168
947
  }
1169
948
  function getForParseResult(dir, context) {
1170
- let value, index, key, source;
1171
- if (dir.value) {
1172
- if (dir.value.type === "JSXExpressionContainer" && dir.value.expression.type === "BinaryExpression") {
1173
- if (dir.value.expression.left.type === "SequenceExpression") {
1174
- const expressions = dir.value.expression.left.expressions;
1175
- value = expressions[0] && resolveExpressionWithFn(expressions[0], context);
1176
- key = expressions[1] && resolveExpression(expressions[1], context);
1177
- index = expressions[2] && resolveExpression(expressions[2], context);
1178
- } else {
1179
- value = resolveExpressionWithFn(dir.value.expression.left, context);
1180
- }
1181
- source = resolveExpression(dir.value.expression.right, context);
1182
- }
1183
- } else {
1184
- context.options.onError(
1185
- _compilerdom.createCompilerError.call(void 0,
1186
- _compilerdom.ErrorCodes.X_V_FOR_NO_EXPRESSION,
1187
- resolveLocation(dir.loc, context)
1188
- )
1189
- );
1190
- }
1191
- return {
1192
- value,
1193
- index,
1194
- key,
1195
- source
1196
- };
949
+ let value, index, key, source;
950
+ if (dir.value) {
951
+ if (dir.value.type === "JSXExpressionContainer" && dir.value.expression.type === "BinaryExpression") {
952
+ if (dir.value.expression.left.type === "SequenceExpression") {
953
+ const expressions = dir.value.expression.left.expressions;
954
+ value = expressions[0] && resolveExpressionWithFn(expressions[0], context);
955
+ key = expressions[1] && resolveExpression(expressions[1], context);
956
+ index = expressions[2] && resolveExpression(expressions[2], context);
957
+ } else value = resolveExpressionWithFn(dir.value.expression.left, context);
958
+ source = resolveExpression(dir.value.expression.right, context);
959
+ }
960
+ } else context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_FOR_NO_EXPRESSION, resolveLocation(dir.loc, context)));
961
+ return {
962
+ value,
963
+ index,
964
+ key,
965
+ source
966
+ };
1197
967
  }
1198
968
 
1199
- // src/transforms/vHtml.ts
1200
-
1201
- var transformVHtml = (dir, node, context) => {
1202
- return _compilervapor.transformVHtml.call(void 0,
1203
- resolveDirectiveNode(dir, context),
1204
- resolveNode(node, context),
1205
- context
1206
- );
969
+ //#endregion
970
+ //#region src/transforms/vHtml.ts
971
+ const transformVHtml = (dir, node, context) => {
972
+ let exp;
973
+ const loc = resolveLocation(dir.loc, context);
974
+ if (!dir.value) {
975
+ context.options.onError((0, __vue_compiler_dom.createDOMCompilerError)(__vue_compiler_dom.DOMErrorCodes.X_V_HTML_NO_EXPRESSION, loc));
976
+ exp = EMPTY_EXPRESSION;
977
+ } else exp = resolveExpression(dir.value, context);
978
+ if (node.children.length) {
979
+ context.options.onError((0, __vue_compiler_dom.createDOMCompilerError)(__vue_compiler_dom.DOMErrorCodes.X_V_HTML_WITH_CHILDREN, loc));
980
+ context.childrenTemplate.length = 0;
981
+ }
982
+ context.registerEffect([exp], {
983
+ type: IRNodeTypes.SET_HTML,
984
+ element: context.reference(),
985
+ value: exp
986
+ });
1207
987
  };
1208
988
 
1209
- // src/transforms/vIf.ts
1210
-
1211
-
1212
-
1213
-
1214
-
1215
-
1216
- var transformVIf = createStructuralDirectiveTransform(
1217
- ["if", "else", "else-if"],
1218
- processIf
1219
- );
1220
- var transformedIfNode = /* @__PURE__ */ new WeakMap();
989
+ //#endregion
990
+ //#region src/transforms/vIf.ts
991
+ const transformVIf = createStructuralDirectiveTransform([
992
+ "if",
993
+ "else",
994
+ "else-if"
995
+ ], processIf);
996
+ const transformedIfNode = new WeakMap();
1221
997
  function processIf(node, attribute, context) {
1222
- const dir = resolveDirectiveNode(attribute, context);
1223
- if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
1224
- const loc = dir.exp ? dir.exp.loc : resolveLocation(node.loc, context);
1225
- context.options.onError(
1226
- _compilerdom.createCompilerError.call(void 0, _compilerdom.ErrorCodes.X_V_IF_NO_EXPRESSION, dir.loc)
1227
- );
1228
- dir.exp = _compilerdom.createSimpleExpression.call(void 0, `true`, false, loc);
1229
- }
1230
- context.dynamic.flags |= 2 /* NON_TEMPLATE */;
1231
- transformedIfNode.set(node, dir);
1232
- if (dir.name === "if") {
1233
- const id = context.reference();
1234
- context.dynamic.flags |= 4 /* INSERT */;
1235
- const [branch, onExit] = createBranch(node, context);
1236
- return () => {
1237
- onExit();
1238
- context.dynamic.operation = {
1239
- type: 15 /* IF */,
1240
- id,
1241
- condition: dir.exp,
1242
- positive: branch,
1243
- once: context.inVOnce || _compilerdom.isConstantNode.call(void 0, attribute.value, context.options.bindingMetadata)
1244
- };
1245
- };
1246
- } else {
1247
- const siblingIf = getSiblingIf(context);
1248
- const siblings = context.parent && context.parent.dynamic.children;
1249
- let lastIfNode;
1250
- if (siblings) {
1251
- let i = siblings.length;
1252
- while (i--) {
1253
- if (siblings[i].operation) lastIfNode = siblings[i].operation;
1254
- }
1255
- }
1256
- if (
1257
- // check if v-if is the sibling node
1258
- !siblingIf || // check if IfNode is the last operation and get the root IfNode
1259
- !lastIfNode || lastIfNode.type !== 15 /* IF */
1260
- ) {
1261
- context.options.onError(
1262
- _compilerdom.createCompilerError.call(void 0,
1263
- _compilerdom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
1264
- resolveLocation(node.loc, context)
1265
- )
1266
- );
1267
- return;
1268
- }
1269
- while (lastIfNode.negative && lastIfNode.negative.type === 15 /* IF */) {
1270
- lastIfNode = lastIfNode.negative;
1271
- }
1272
- if (dir.name === "else-if" && lastIfNode.negative) {
1273
- context.options.onError(
1274
- _compilerdom.createCompilerError.call(void 0,
1275
- _compilerdom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
1276
- resolveLocation(node.loc, context)
1277
- )
1278
- );
1279
- }
1280
- context.root.comment = [];
1281
- const [branch, onExit] = createBranch(node, context);
1282
- if (dir.name === "else") {
1283
- lastIfNode.negative = branch;
1284
- } else {
1285
- lastIfNode.negative = {
1286
- type: 15 /* IF */,
1287
- id: -1,
1288
- condition: dir.exp,
1289
- positive: branch,
1290
- once: context.inVOnce
1291
- };
1292
- }
1293
- return () => onExit();
1294
- }
998
+ const dir = resolveDirective(attribute, context);
999
+ if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
1000
+ const loc = dir.exp ? dir.exp.loc : resolveLocation(node.loc, context);
1001
+ context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_IF_NO_EXPRESSION, dir.loc));
1002
+ dir.exp = (0, __vue_compiler_dom.createSimpleExpression)(`true`, false, loc);
1003
+ }
1004
+ context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
1005
+ transformedIfNode.set(node, dir);
1006
+ if (dir.name === "if") {
1007
+ const id = context.reference();
1008
+ context.dynamic.flags |= DynamicFlag.INSERT;
1009
+ const [branch, onExit] = createBranch(node, context);
1010
+ return () => {
1011
+ onExit();
1012
+ context.dynamic.operation = {
1013
+ type: IRNodeTypes.IF,
1014
+ id,
1015
+ condition: dir.exp,
1016
+ positive: branch,
1017
+ once: context.inVOnce || (0, __vue_compiler_dom.isConstantNode)(attribute.value, context.options.bindingMetadata)
1018
+ };
1019
+ };
1020
+ } else {
1021
+ const siblingIf = getSiblingIf(context);
1022
+ const siblings = context.parent && context.parent.dynamic.children;
1023
+ let lastIfNode;
1024
+ if (siblings) {
1025
+ let i = siblings.length;
1026
+ while (i--) if (siblings[i].operation) lastIfNode = siblings[i].operation;
1027
+ }
1028
+ if (!siblingIf || !lastIfNode || lastIfNode.type !== IRNodeTypes.IF) {
1029
+ context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, resolveLocation(node.loc, context)));
1030
+ return;
1031
+ }
1032
+ while (lastIfNode.negative && lastIfNode.negative.type === IRNodeTypes.IF) lastIfNode = lastIfNode.negative;
1033
+ if (dir.name === "else-if" && lastIfNode.negative) context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, resolveLocation(node.loc, context)));
1034
+ context.root.comment = [];
1035
+ const [branch, onExit] = createBranch(node, context);
1036
+ if (dir.name === "else") lastIfNode.negative = branch;
1037
+ else lastIfNode.negative = {
1038
+ type: IRNodeTypes.IF,
1039
+ id: -1,
1040
+ condition: dir.exp,
1041
+ positive: branch,
1042
+ once: context.inVOnce
1043
+ };
1044
+ return () => onExit();
1045
+ }
1295
1046
  }
1296
1047
  function getSiblingIf(context) {
1297
- const parent = context.parent;
1298
- if (!parent) return;
1299
- const siblings = parent.node.children;
1300
- let sibling;
1301
- let i = siblings.indexOf(context.node);
1302
- while (--i >= 0) {
1303
- if (!isEmptyText(siblings[i])) {
1304
- sibling = siblings[i];
1305
- break;
1306
- }
1307
- }
1308
- if (sibling && sibling.type === "JSXElement" && transformedIfNode.has(sibling)) {
1309
- return sibling;
1310
- }
1048
+ const parent = context.parent;
1049
+ if (!parent) return;
1050
+ const siblings = parent.node.children;
1051
+ let sibling;
1052
+ let i = siblings.indexOf(context.node);
1053
+ while (--i >= 0) if (!isEmptyText(siblings[i])) {
1054
+ sibling = siblings[i];
1055
+ break;
1056
+ }
1057
+ if (sibling && sibling.type === "JSXElement" && transformedIfNode.has(sibling)) return sibling;
1311
1058
  }
1312
1059
 
1313
- // src/transforms/vModel.ts
1314
-
1315
- var transformVModel = (dir, node, context) => {
1316
- return _compilervapor.transformVModel.call(void 0,
1317
- resolveDirectiveNode(dir, context),
1318
- resolveNode(node, context),
1319
- context
1320
- );
1060
+ //#endregion
1061
+ //#region src/transforms/vModel.ts
1062
+ const transformVModel = (_dir, node, context) => {
1063
+ const dir = resolveDirective(_dir, context);
1064
+ const { exp, arg } = dir;
1065
+ if (!exp) {
1066
+ context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_MODEL_NO_EXPRESSION, dir.loc));
1067
+ return;
1068
+ }
1069
+ const expString = exp.content;
1070
+ if (!expString.trim() || !(0, __vue_compiler_dom.isMemberExpression)(exp, context.options)) {
1071
+ context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION, exp.loc));
1072
+ return;
1073
+ }
1074
+ const isComponent = isJSXComponent(node);
1075
+ if (isComponent) return {
1076
+ key: arg ? arg : (0, __vue_compiler_dom.createSimpleExpression)("modelValue", true),
1077
+ value: exp,
1078
+ model: true,
1079
+ modelModifiers: dir.modifiers.map((m) => m.content)
1080
+ };
1081
+ if (dir.arg) context.options.onError((0, __vue_compiler_dom.createDOMCompilerError)(__vue_compiler_dom.DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT, dir.arg.loc));
1082
+ const tag = getText(node.openingElement.name, context);
1083
+ const isCustomElement = context.options.isCustomElement(tag);
1084
+ let modelType = "text";
1085
+ if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) if (tag === "input" || isCustomElement) {
1086
+ const type = findProp(node, "type");
1087
+ if (type?.value) {
1088
+ if (type.value.type === "JSXExpressionContainer") modelType = "dynamic";
1089
+ else if (type.value.type === "StringLiteral") switch (type.value.value) {
1090
+ case "radio":
1091
+ modelType = "radio";
1092
+ break;
1093
+ case "checkbox":
1094
+ modelType = "checkbox";
1095
+ break;
1096
+ case "file":
1097
+ modelType = void 0;
1098
+ context.options.onError((0, __vue_compiler_dom.createDOMCompilerError)(__vue_compiler_dom.DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT, dir.loc));
1099
+ break;
1100
+ default:
1101
+ checkDuplicatedValue();
1102
+ break;
1103
+ }
1104
+ } else if (hasDynamicKeyVBind(node)) modelType = "dynamic";
1105
+ else checkDuplicatedValue();
1106
+ } else if (tag === "select") modelType = "select";
1107
+ else checkDuplicatedValue();
1108
+ else context.options.onError((0, __vue_compiler_dom.createDOMCompilerError)(__vue_compiler_dom.DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT, dir.loc));
1109
+ if (modelType) context.registerOperation({
1110
+ type: IRNodeTypes.DIRECTIVE,
1111
+ element: context.reference(),
1112
+ dir,
1113
+ name: "model",
1114
+ modelType,
1115
+ builtin: true
1116
+ });
1117
+ function checkDuplicatedValue() {
1118
+ const value = findProp(node, "value");
1119
+ if (value && value.value?.type !== "StringLiteral") context.options.onError((0, __vue_compiler_dom.createDOMCompilerError)(__vue_compiler_dom.DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE, resolveLocation(value.loc, context)));
1120
+ }
1321
1121
  };
1122
+ function hasDynamicKeyVBind(node) {
1123
+ return node.openingElement.attributes.some((p) => p.type === "JSXSpreadAttribute" || p.type === "JSXAttribute" && p.name.type === "JSXNamespacedName" && !p.name.namespace.name.startsWith("v-"));
1124
+ }
1322
1125
 
1323
- // src/transforms/vOn.ts
1324
-
1325
-
1326
-
1327
-
1328
-
1329
-
1330
-
1331
- var delegatedEvents = /* @__PURE__ */ _shared.makeMap.call(void 0,
1332
- "beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart"
1333
- );
1334
- var transformVOn = (dir, node, context) => {
1335
- const { name, loc, value } = dir;
1336
- if (name.type === "JSXNamespacedName") return;
1337
- const isComponent = isJSXComponent(node);
1338
- const [nameString, ...modifiers] = name.name.replace(/^on([A-Z])/, (_, $1) => $1.toLowerCase()).split("_");
1339
- if (!value && !modifiers.length) {
1340
- context.options.onError(
1341
- _compilerdom.createCompilerError.call(void 0,
1342
- _compilerdom.ErrorCodes.X_V_ON_NO_EXPRESSION,
1343
- resolveLocation(loc, context)
1344
- )
1345
- );
1346
- }
1347
- let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
1348
- const exp = resolveExpression(dir.value, context);
1349
- const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = _compilerdom.resolveModifiers.call(void 0,
1350
- arg.isStatic ? `on${nameString}` : arg,
1351
- modifiers.map((modifier) => _compilerdom.createSimpleExpression.call(void 0, modifier)),
1352
- null,
1353
- resolveLocation(loc, context)
1354
- );
1355
- let keyOverride;
1356
- const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
1357
- if (nonKeyModifiers.includes("middle")) {
1358
- if (keyOverride) {
1359
- }
1360
- if (isStaticClick) {
1361
- arg = _shared.extend.call(void 0, {}, arg, { content: "mouseup" });
1362
- } else if (!arg.isStatic) {
1363
- keyOverride = ["click", "mouseup"];
1364
- }
1365
- }
1366
- if (nonKeyModifiers.includes("right")) {
1367
- if (isStaticClick) {
1368
- arg = _shared.extend.call(void 0, {}, arg, { content: "contextmenu" });
1369
- } else if (!arg.isStatic) {
1370
- keyOverride = ["click", "contextmenu"];
1371
- }
1372
- }
1373
- if (isComponent) {
1374
- const handler = exp || EMPTY_EXPRESSION;
1375
- return {
1376
- key: arg,
1377
- value: handler,
1378
- handler: true,
1379
- handlerModifiers: {
1380
- keys: keyModifiers,
1381
- nonKeys: nonKeyModifiers,
1382
- options: eventOptionModifiers
1383
- }
1384
- };
1385
- }
1386
- const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
1387
- const operation = {
1388
- type: 5 /* SET_EVENT */,
1389
- element: context.reference(),
1390
- key: arg,
1391
- value: exp,
1392
- modifiers: {
1393
- keys: keyModifiers,
1394
- nonKeys: nonKeyModifiers,
1395
- options: eventOptionModifiers
1396
- },
1397
- keyOverride,
1398
- delegate,
1399
- effect: !arg.isStatic
1400
- };
1401
- context.registerEffect([arg], operation);
1126
+ //#endregion
1127
+ //#region src/transforms/vOn.ts
1128
+ const delegatedEvents = /* @__PURE__ */ (0, __vue_shared.makeMap)("beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart");
1129
+ const transformVOn = (dir, node, context) => {
1130
+ const { name, loc, value } = dir;
1131
+ if (name.type === "JSXNamespacedName") return;
1132
+ const isComponent = isJSXComponent(node);
1133
+ const [nameString, ...modifiers] = name.name.replace(/^on([A-Z])/, (_, $1) => $1.toLowerCase()).split("_");
1134
+ if (!value && !modifiers.length) context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_ON_NO_EXPRESSION, resolveLocation(loc, context)));
1135
+ let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
1136
+ const exp = resolveExpression(dir.value, context);
1137
+ const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = (0, __vue_compiler_dom.resolveModifiers)(arg.isStatic ? `on${nameString}` : arg, modifiers.map((modifier) => (0, __vue_compiler_dom.createSimpleExpression)(modifier)), null, resolveLocation(loc, context));
1138
+ let keyOverride;
1139
+ const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
1140
+ if (nonKeyModifiers.includes("middle")) {
1141
+ if (keyOverride) {}
1142
+ if (isStaticClick) arg = (0, __vue_shared.extend)({}, arg, { content: "mouseup" });
1143
+ else if (!arg.isStatic) keyOverride = ["click", "mouseup"];
1144
+ }
1145
+ if (nonKeyModifiers.includes("right")) {
1146
+ if (isStaticClick) arg = (0, __vue_shared.extend)({}, arg, { content: "contextmenu" });
1147
+ else if (!arg.isStatic) keyOverride = ["click", "contextmenu"];
1148
+ }
1149
+ if (isComponent) {
1150
+ const handler = exp || EMPTY_EXPRESSION;
1151
+ return {
1152
+ key: arg,
1153
+ value: handler,
1154
+ handler: true,
1155
+ handlerModifiers: {
1156
+ keys: keyModifiers,
1157
+ nonKeys: nonKeyModifiers,
1158
+ options: eventOptionModifiers
1159
+ }
1160
+ };
1161
+ }
1162
+ const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
1163
+ const operation = {
1164
+ type: IRNodeTypes.SET_EVENT,
1165
+ element: context.reference(),
1166
+ key: arg,
1167
+ value: exp,
1168
+ modifiers: {
1169
+ keys: keyModifiers,
1170
+ nonKeys: nonKeyModifiers,
1171
+ options: eventOptionModifiers
1172
+ },
1173
+ keyOverride,
1174
+ delegate,
1175
+ effect: !arg.isStatic
1176
+ };
1177
+ context.registerEffect([arg], operation);
1402
1178
  };
1403
1179
 
1404
- // src/transforms/vOnce.ts
1405
- var transformVOnce = (node, context) => {
1406
- if (
1407
- // !context.inSSR &&
1408
- node.type === "JSXElement" && findProp(node, "v-once")
1409
- ) {
1410
- context.inVOnce = true;
1411
- }
1180
+ //#endregion
1181
+ //#region src/transforms/vOnce.ts
1182
+ const transformVOnce = (node, context) => {
1183
+ if (node.type === "JSXElement" && findProp(node, "v-once")) context.inVOnce = true;
1412
1184
  };
1413
1185
 
1414
- // src/transforms/vShow.ts
1415
-
1416
- var transformVShow = (dir, node, context) => {
1417
- return _compilervapor.transformVShow.call(void 0,
1418
- resolveDirectiveNode(dir, context),
1419
- resolveNode(node, context),
1420
- context
1421
- );
1186
+ //#endregion
1187
+ //#region src/transforms/vShow.ts
1188
+ const transformVShow = (_dir, node, context) => {
1189
+ const dir = resolveDirective(_dir, context);
1190
+ const { exp, loc } = dir;
1191
+ if (!exp) {
1192
+ context.options.onError((0, __vue_compiler_dom.createDOMCompilerError)(__vue_compiler_dom.DOMErrorCodes.X_V_SHOW_NO_EXPRESSION, loc));
1193
+ return;
1194
+ }
1195
+ context.registerOperation({
1196
+ type: IRNodeTypes.DIRECTIVE,
1197
+ element: context.reference(),
1198
+ dir,
1199
+ name: "show",
1200
+ builtin: true
1201
+ });
1422
1202
  };
1423
1203
 
1424
- // src/transforms/vSlot.ts
1425
-
1426
-
1427
-
1428
-
1429
- var transformVSlot = (node, context) => {
1430
- if (node.type !== "JSXElement") return;
1431
- const { children } = node;
1432
- const dir = findProp(node, "v-slot");
1433
- const resolvedDirective = dir ? resolveDirectiveNode(dir, context, true) : void 0;
1434
- const { parent } = context;
1435
- const isComponent = isJSXComponent(node);
1436
- const isSlotTemplate = isTemplate(node) && parent && parent.node.type === "JSXElement" && isJSXComponent(parent.node);
1437
- if (isComponent && children.length) {
1438
- return transformComponentSlot(node, resolvedDirective, context);
1439
- } else if (isSlotTemplate && resolvedDirective) {
1440
- return transformTemplateSlot(node, resolvedDirective, context);
1441
- } else if (!isComponent && dir) {
1442
- context.options.onError(
1443
- _compilerdom.createCompilerError.call(void 0,
1444
- _compilerdom.ErrorCodes.X_V_SLOT_MISPLACED,
1445
- resolveLocation(dir.loc, context)
1446
- )
1447
- );
1448
- }
1204
+ //#endregion
1205
+ //#region src/transforms/vSlot.ts
1206
+ const transformVSlot = (node, context) => {
1207
+ if (node.type !== "JSXElement") return;
1208
+ const { children } = node;
1209
+ const dir = findProp(node, "v-slot");
1210
+ const resolvedDirective = dir ? resolveDirective(dir, context, true) : void 0;
1211
+ const { parent } = context;
1212
+ const isComponent = isJSXComponent(node);
1213
+ const isSlotTemplate = isTemplate(node) && parent && parent.node.type === "JSXElement" && isJSXComponent(parent.node);
1214
+ if (isComponent && children.length) return transformComponentSlot(node, resolvedDirective, context);
1215
+ else if (isSlotTemplate && resolvedDirective) return transformTemplateSlot(node, resolvedDirective, context);
1216
+ else if (!isComponent && dir) context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_SLOT_MISPLACED, resolveLocation(dir.loc, context)));
1449
1217
  };
1450
1218
  function transformComponentSlot(node, dir, context) {
1451
- const { children } = node;
1452
- const arg = dir && dir.arg;
1453
- const nonSlotTemplateChildren = children.filter(
1454
- (n) => !isEmptyText(n) && (n.type !== "JSXElement" || !findProp(n, "v-slot"))
1455
- );
1456
- const [block, onExit] = createSlotBlock(node, dir, context);
1457
- const { slots } = context;
1458
- return () => {
1459
- onExit();
1460
- const hasOtherSlots = !!slots.length;
1461
- if (dir && hasOtherSlots) {
1462
- context.options.onError(
1463
- _compilerdom.createCompilerError.call(void 0, _compilerdom.ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, dir.loc)
1464
- );
1465
- return;
1466
- }
1467
- if (nonSlotTemplateChildren.length) {
1468
- if (hasStaticSlot(slots, "default")) {
1469
- context.options.onError(
1470
- _compilerdom.createCompilerError.call(void 0,
1471
- _compilerdom.ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN,
1472
- resolveLocation(nonSlotTemplateChildren[0].loc, context)
1473
- )
1474
- );
1475
- } else {
1476
- registerSlot(slots, arg, block);
1477
- context.slots = slots;
1478
- }
1479
- } else if (hasOtherSlots) {
1480
- context.slots = slots;
1481
- }
1482
- };
1219
+ const { children } = node;
1220
+ const arg = dir && dir.arg;
1221
+ const nonSlotTemplateChildren = children.filter((n) => !isEmptyText(n) && (n.type !== "JSXElement" || !findProp(n, "v-slot")));
1222
+ const [block, onExit] = createSlotBlock(node, dir, context);
1223
+ const { slots } = context;
1224
+ return () => {
1225
+ onExit();
1226
+ const hasOtherSlots = !!slots.length;
1227
+ if (dir && hasOtherSlots) {
1228
+ context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, dir.loc));
1229
+ return;
1230
+ }
1231
+ if (nonSlotTemplateChildren.length) if (hasStaticSlot(slots, "default")) context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN, resolveLocation(nonSlotTemplateChildren[0].loc, context)));
1232
+ else {
1233
+ registerSlot(slots, arg, block);
1234
+ context.slots = slots;
1235
+ }
1236
+ else if (hasOtherSlots) context.slots = slots;
1237
+ };
1483
1238
  }
1484
- var elseIfRE = /^v-else(-if)?$/;
1239
+ const elseIfRE = /^v-else(-if)?$/;
1485
1240
  function transformTemplateSlot(node, dir, context) {
1486
- context.dynamic.flags |= 2 /* NON_TEMPLATE */;
1487
- const arg = dir.arg && resolveSimpleExpressionNode(dir.arg);
1488
- const vFor = findProp(node, "v-for");
1489
- const vIf = findProp(node, "v-if");
1490
- const vElse = findProp(node, elseIfRE);
1491
- const { slots } = context;
1492
- const [block, onExit] = createSlotBlock(node, dir, context);
1493
- if (!vFor && !vIf && !vElse) {
1494
- const slotName = arg ? arg.isStatic && arg.content : "default";
1495
- if (slotName && hasStaticSlot(slots, slotName)) {
1496
- context.options.onError(
1497
- _compilerdom.createCompilerError.call(void 0, _compilerdom.ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES, dir.loc)
1498
- );
1499
- } else {
1500
- registerSlot(slots, arg, block);
1501
- }
1502
- } else if (vIf) {
1503
- const vIfDir = resolveDirectiveNode(vIf, context);
1504
- registerDynamicSlot(slots, {
1505
- slotType: 3 /* CONDITIONAL */,
1506
- condition: vIfDir.exp,
1507
- positive: {
1508
- slotType: 1 /* DYNAMIC */,
1509
- name: arg,
1510
- fn: block
1511
- }
1512
- });
1513
- } else if (vElse) {
1514
- const vElseDir = resolveDirectiveNode(vElse, context);
1515
- const vIfSlot = slots.at(-1);
1516
- if (vIfSlot.slotType === 3 /* CONDITIONAL */) {
1517
- let ifNode = vIfSlot;
1518
- while (ifNode.negative && ifNode.negative.slotType === 3 /* CONDITIONAL */)
1519
- ifNode = ifNode.negative;
1520
- const negative = vElseDir.exp ? {
1521
- slotType: 3 /* CONDITIONAL */,
1522
- condition: vElseDir.exp,
1523
- positive: {
1524
- slotType: 1 /* DYNAMIC */,
1525
- name: arg,
1526
- fn: block
1527
- }
1528
- } : {
1529
- slotType: 1 /* DYNAMIC */,
1530
- name: arg,
1531
- fn: block
1532
- };
1533
- ifNode.negative = negative;
1534
- } else {
1535
- context.options.onError(
1536
- _compilerdom.createCompilerError.call(void 0, _compilerdom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, vElseDir.loc)
1537
- );
1538
- }
1539
- } else if (vFor) {
1540
- const forParseResult = getForParseResult(vFor, context);
1541
- if (forParseResult.source) {
1542
- registerDynamicSlot(slots, {
1543
- slotType: 2 /* LOOP */,
1544
- name: arg,
1545
- fn: block,
1546
- loop: forParseResult
1547
- });
1548
- }
1549
- }
1550
- return onExit;
1241
+ context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
1242
+ const arg = dir.arg && resolveSimpleExpressionNode(dir.arg);
1243
+ const vFor = findProp(node, "v-for");
1244
+ const vIf = findProp(node, "v-if");
1245
+ const vElse = findProp(node, elseIfRE);
1246
+ const { slots } = context;
1247
+ const [block, onExit] = createSlotBlock(node, dir, context);
1248
+ if (!vFor && !vIf && !vElse) {
1249
+ const slotName = arg ? arg.isStatic && arg.content : "default";
1250
+ if (slotName && hasStaticSlot(slots, slotName)) context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES, dir.loc));
1251
+ else registerSlot(slots, arg, block);
1252
+ } else if (vIf) {
1253
+ const vIfDir = resolveDirective(vIf, context);
1254
+ registerDynamicSlot(slots, {
1255
+ slotType: IRSlotType.CONDITIONAL,
1256
+ condition: vIfDir.exp,
1257
+ positive: {
1258
+ slotType: IRSlotType.DYNAMIC,
1259
+ name: arg,
1260
+ fn: block
1261
+ }
1262
+ });
1263
+ } else if (vElse) {
1264
+ const vElseDir = resolveDirective(vElse, context);
1265
+ const vIfSlot = slots.at(-1);
1266
+ if (vIfSlot.slotType === IRSlotType.CONDITIONAL) {
1267
+ let ifNode = vIfSlot;
1268
+ while (ifNode.negative && ifNode.negative.slotType === IRSlotType.CONDITIONAL) ifNode = ifNode.negative;
1269
+ const negative = vElseDir.exp ? {
1270
+ slotType: IRSlotType.CONDITIONAL,
1271
+ condition: vElseDir.exp,
1272
+ positive: {
1273
+ slotType: IRSlotType.DYNAMIC,
1274
+ name: arg,
1275
+ fn: block
1276
+ }
1277
+ } : {
1278
+ slotType: IRSlotType.DYNAMIC,
1279
+ name: arg,
1280
+ fn: block
1281
+ };
1282
+ ifNode.negative = negative;
1283
+ } else context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, vElseDir.loc));
1284
+ } else if (vFor) {
1285
+ const forParseResult = getForParseResult(vFor, context);
1286
+ if (forParseResult.source) registerDynamicSlot(slots, {
1287
+ slotType: IRSlotType.LOOP,
1288
+ name: arg,
1289
+ fn: block,
1290
+ loop: forParseResult
1291
+ });
1292
+ }
1293
+ return onExit;
1551
1294
  }
1552
1295
  function ensureStaticSlots(slots) {
1553
- let lastSlots = slots.at(-1);
1554
- if (!slots.length || lastSlots.slotType !== 0 /* STATIC */) {
1555
- slots.push(
1556
- lastSlots = {
1557
- slotType: 0 /* STATIC */,
1558
- slots: {}
1559
- }
1560
- );
1561
- }
1562
- return lastSlots.slots;
1296
+ let lastSlots = slots.at(-1);
1297
+ if (!slots.length || lastSlots.slotType !== IRSlotType.STATIC) slots.push(lastSlots = {
1298
+ slotType: IRSlotType.STATIC,
1299
+ slots: {}
1300
+ });
1301
+ return lastSlots.slots;
1563
1302
  }
1564
1303
  function registerSlot(slots, name, block) {
1565
- const isStatic = !name || name.isStatic;
1566
- if (isStatic) {
1567
- const staticSlots = ensureStaticSlots(slots);
1568
- staticSlots[name ? name.content : "default"] = block;
1569
- } else {
1570
- slots.push({
1571
- slotType: 1 /* DYNAMIC */,
1572
- name,
1573
- fn: block
1574
- });
1575
- }
1304
+ const isStatic = !name || name.isStatic;
1305
+ if (isStatic) {
1306
+ const staticSlots = ensureStaticSlots(slots);
1307
+ staticSlots[name ? name.content : "default"] = block;
1308
+ } else slots.push({
1309
+ slotType: IRSlotType.DYNAMIC,
1310
+ name,
1311
+ fn: block
1312
+ });
1576
1313
  }
1577
1314
  function registerDynamicSlot(allSlots, dynamic) {
1578
- allSlots.push(dynamic);
1315
+ allSlots.push(dynamic);
1579
1316
  }
1580
1317
  function hasStaticSlot(slots, name) {
1581
- return slots.some(
1582
- (slot) => slot.slotType === 0 /* STATIC */ ? !!slot.slots[name] : false
1583
- );
1318
+ return slots.some((slot) => slot.slotType === IRSlotType.STATIC ? !!slot.slots[name] : false);
1584
1319
  }
1585
1320
  function createSlotBlock(slotNode, dir, context) {
1586
- const block = newBlock(slotNode);
1587
- block.props = dir && dir.exp;
1588
- const exitBlock = context.enterBlock(block);
1589
- return [block, exitBlock];
1321
+ const block = newBlock(slotNode);
1322
+ block.props = dir && dir.exp;
1323
+ const exitBlock = context.enterBlock(block);
1324
+ return [block, exitBlock];
1590
1325
  }
1591
1326
 
1592
- // src/transforms/vSlots.ts
1593
-
1594
- var transformVSlots = (dir, node, context) => {
1595
- if (!isJSXComponent(node)) return;
1596
- if (_optionalChain([dir, 'access', _13 => _13.value, 'optionalAccess', _14 => _14.type]) === "JSXExpressionContainer") {
1597
- context.slots = [
1598
- {
1599
- slotType: 4 /* EXPRESSION */,
1600
- slots: resolveExpression(dir.value.expression, context)
1601
- }
1602
- ];
1603
- if (node.children.length) {
1604
- context.options.onError(
1605
- _compilerdom.createCompilerError.call(void 0,
1606
- _compilerdom.ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE,
1607
- resolveLocation(node.children[0].loc, context)
1608
- )
1609
- );
1610
- }
1611
- }
1327
+ //#endregion
1328
+ //#region src/transforms/vSlots.ts
1329
+ const transformVSlots = (dir, node, context) => {
1330
+ if (!isJSXComponent(node)) return;
1331
+ if (dir.value?.type === "JSXExpressionContainer") {
1332
+ context.slots = [{
1333
+ slotType: IRSlotType.EXPRESSION,
1334
+ slots: resolveExpression(dir.value.expression, context)
1335
+ }];
1336
+ if (node.children.length) context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, resolveLocation(node.children[0].loc, context)));
1337
+ }
1612
1338
  };
1613
1339
 
1614
- // src/transforms/vText.ts
1615
-
1616
- var transformVText = (dir, node, context) => {
1617
- return _compilervapor.transformVText.call(void 0,
1618
- resolveDirectiveNode(dir, context),
1619
- resolveNode(node, context),
1620
- context
1621
- );
1340
+ //#endregion
1341
+ //#region src/transforms/vText.ts
1342
+ const transformVText = (dir, node, context) => {
1343
+ let exp;
1344
+ const loc = resolveLocation(dir.loc, context);
1345
+ if (!dir.value) {
1346
+ context.options.onError((0, __vue_compiler_dom.createDOMCompilerError)(__vue_compiler_dom.DOMErrorCodes.X_V_TEXT_NO_EXPRESSION, loc));
1347
+ exp = EMPTY_EXPRESSION;
1348
+ } else exp = resolveExpression(dir.value, context);
1349
+ if (node.children.length) {
1350
+ context.options.onError((0, __vue_compiler_dom.createDOMCompilerError)(__vue_compiler_dom.DOMErrorCodes.X_V_TEXT_WITH_CHILDREN, loc));
1351
+ context.childrenTemplate.length = 0;
1352
+ }
1353
+ if ((0, __vue_shared.isVoidTag)(getText(node.openingElement.name, context))) return;
1354
+ const literal = getLiteralExpressionValue(exp);
1355
+ if (literal != null) context.childrenTemplate = [String(literal)];
1356
+ else {
1357
+ context.childrenTemplate = [" "];
1358
+ context.registerOperation({
1359
+ type: IRNodeTypes.GET_TEXT_CHILD,
1360
+ parent: context.reference()
1361
+ });
1362
+ context.registerEffect([exp], {
1363
+ type: IRNodeTypes.SET_TEXT,
1364
+ element: context.reference(),
1365
+ values: [exp],
1366
+ generated: true
1367
+ });
1368
+ }
1622
1369
  };
1623
1370
 
1624
- // src/compile.ts
1371
+ //#endregion
1372
+ //#region src/compile.ts
1625
1373
  function compile(source, options = {}) {
1626
- const resolvedOptions = _shared.extend.call(void 0, {}, options, {
1627
- inline: true,
1628
- prefixIdentifiers: false,
1629
- expressionPlugins: options.expressionPlugins || ["jsx"]
1630
- });
1631
- if (!resolvedOptions.source && _shared.isString.call(void 0, source)) {
1632
- resolvedOptions.source = source;
1633
- }
1634
- if (resolvedOptions.isTS) {
1635
- const { expressionPlugins } = resolvedOptions;
1636
- if (!expressionPlugins.includes("typescript")) {
1637
- resolvedOptions.expressionPlugins = [
1638
- ...expressionPlugins || [],
1639
- "typescript"
1640
- ];
1641
- }
1642
- }
1643
- const root = _shared.isString.call(void 0, source) ? _parser.parse.call(void 0, source, {
1644
- sourceType: "module",
1645
- plugins: resolvedOptions.expressionPlugins
1646
- }).program.body[0].expression : source;
1647
- const children = root.type === "JSXFragment" ? root.children : root.type === "JSXElement" ? [root] : [];
1648
- const ast = {
1649
- type: 0 /* ROOT */,
1650
- children,
1651
- source: resolvedOptions.source || ""
1652
- };
1653
- const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
1654
- const ir = transform(
1655
- ast,
1656
- _shared.extend.call(void 0, {}, resolvedOptions, {
1657
- nodeTransforms: [
1658
- ...nodeTransforms,
1659
- ...resolvedOptions.nodeTransforms || []
1660
- // user transforms
1661
- ],
1662
- directiveTransforms: _shared.extend.call(void 0,
1663
- {},
1664
- directiveTransforms,
1665
- resolvedOptions.directiveTransforms || {}
1666
- // user transforms
1667
- )
1668
- })
1669
- );
1670
- return _compilervapor.generate.call(void 0, ir, {
1671
- ...resolvedOptions,
1672
- customGenOperation
1673
- });
1374
+ const resolvedOptions = (0, __vue_shared.extend)({}, options, {
1375
+ inline: true,
1376
+ prefixIdentifiers: false,
1377
+ expressionPlugins: options.expressionPlugins || ["jsx"]
1378
+ });
1379
+ if (!resolvedOptions.source && (0, __vue_shared.isString)(source)) resolvedOptions.source = source;
1380
+ if (resolvedOptions.isTS) {
1381
+ const { expressionPlugins } = resolvedOptions;
1382
+ if (!expressionPlugins.includes("typescript")) resolvedOptions.expressionPlugins = [...expressionPlugins || [], "typescript"];
1383
+ }
1384
+ const root = (0, __vue_shared.isString)(source) ? (0, __babel_parser.parse)(source, {
1385
+ sourceType: "module",
1386
+ plugins: resolvedOptions.expressionPlugins
1387
+ }).program.body[0].expression : source;
1388
+ const children = root.type === "JSXFragment" ? root.children : root.type === "JSXElement" ? [root] : [];
1389
+ const ast = {
1390
+ type: IRNodeTypes.ROOT,
1391
+ children,
1392
+ source: resolvedOptions.source || ""
1393
+ };
1394
+ const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
1395
+ const ir = transform(ast, (0, __vue_shared.extend)({}, resolvedOptions, {
1396
+ nodeTransforms: [...nodeTransforms, ...resolvedOptions.nodeTransforms || []],
1397
+ directiveTransforms: (0, __vue_shared.extend)({}, directiveTransforms, resolvedOptions.directiveTransforms || {})
1398
+ }));
1399
+ return (0, __vue_compiler_vapor.generate)(ir, {
1400
+ ...resolvedOptions,
1401
+ customGenOperation
1402
+ });
1674
1403
  }
1675
1404
  function getBaseTransformPreset() {
1676
- return [
1677
- [
1678
- transformVOnce,
1679
- transformVIf,
1680
- transformVFor,
1681
- transformTemplateRef,
1682
- transformText,
1683
- transformElement,
1684
- transformVSlot,
1685
- transformChildren
1686
- ],
1687
- {
1688
- bind: transformVBind,
1689
- on: transformVOn,
1690
- model: transformVModel,
1691
- show: transformVShow,
1692
- html: transformVHtml,
1693
- text: transformVText,
1694
- slots: transformVSlots
1695
- }
1696
- ];
1405
+ return [[
1406
+ transformVOnce,
1407
+ transformVIf,
1408
+ transformVFor,
1409
+ transformTemplateRef,
1410
+ transformText,
1411
+ transformElement,
1412
+ transformVSlot,
1413
+ transformChildren
1414
+ ], {
1415
+ bind: transformVBind,
1416
+ on: transformVOn,
1417
+ model: transformVModel,
1418
+ show: transformVShow,
1419
+ html: transformVHtml,
1420
+ text: transformVText,
1421
+ slots: transformVSlots
1422
+ }];
1697
1423
  }
1698
1424
 
1699
-
1700
-
1701
-
1702
-
1703
-
1704
-
1705
-
1706
-
1707
-
1708
-
1709
-
1710
-
1711
-
1712
-
1713
-
1714
-
1715
-
1716
-
1717
-
1718
-
1719
-
1720
-
1721
-
1722
-
1723
-
1724
-
1725
-
1726
-
1727
- exports.DynamicFlag = DynamicFlag; exports.IRDynamicPropsKind = IRDynamicPropsKind; exports.IRNodeTypes = IRNodeTypes; exports.IRSlotType = IRSlotType; exports.TransformContext = TransformContext; exports.compile = compile; exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform; exports.generate = _compilervapor.generate; exports.isBlockOperation = isBlockOperation; exports.resolveDirectiveNode = resolveDirectiveNode; exports.resolveNode = resolveNode; exports.transform = transform; exports.transformChildren = transformChildren; exports.transformElement = transformElement; exports.transformNode = transformNode; exports.transformTemplateRef = transformTemplateRef; exports.transformText = transformText; exports.transformVBind = transformVBind; exports.transformVFor = transformVFor; exports.transformVHtml = transformVHtml; exports.transformVIf = transformVIf; exports.transformVModel = transformVModel; exports.transformVOn = transformVOn; exports.transformVOnce = transformVOnce; exports.transformVShow = transformVShow; exports.transformVSlot = transformVSlot; exports.transformVSlots = transformVSlots; exports.transformVText = transformVText;
1425
+ //#endregion
1426
+ exports.DynamicFlag = DynamicFlag
1427
+ exports.IRDynamicPropsKind = IRDynamicPropsKind
1428
+ exports.IRNodeTypes = IRNodeTypes
1429
+ exports.IRSlotType = IRSlotType
1430
+ exports.TransformContext = TransformContext
1431
+ exports.compile = compile
1432
+ exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform
1433
+ exports.generate = __vue_compiler_vapor.generate
1434
+ exports.isBlockOperation = isBlockOperation
1435
+ exports.transform = transform
1436
+ exports.transformChildren = transformChildren
1437
+ exports.transformElement = transformElement
1438
+ exports.transformNode = transformNode
1439
+ exports.transformTemplateRef = transformTemplateRef
1440
+ exports.transformText = transformText
1441
+ exports.transformVBind = transformVBind
1442
+ exports.transformVFor = transformVFor
1443
+ exports.transformVHtml = transformVHtml
1444
+ exports.transformVIf = transformVIf
1445
+ exports.transformVModel = transformVModel
1446
+ exports.transformVOn = transformVOn
1447
+ exports.transformVOnce = transformVOnce
1448
+ exports.transformVShow = transformVShow
1449
+ exports.transformVSlot = transformVSlot
1450
+ exports.transformVSlots = transformVSlots
1451
+ exports.transformVText = transformVText