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