@vue/compiler-vapor 3.6.0-alpha.3 → 3.6.0-alpha.4

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-vapor v3.6.0-alpha.3
2
+ * @vue/compiler-vapor v3.6.0-alpha.4
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -11,7 +11,6 @@ var compilerDom = require('@vue/compiler-dom');
11
11
  var shared = require('@vue/shared');
12
12
  var sourceMapJs = require('source-map-js');
13
13
  var parser = require('@babel/parser');
14
- var types = require('@babel/types');
15
14
  var estreeWalker = require('estree-walker');
16
15
 
17
16
  const newDynamic = () => ({
@@ -66,26 +65,45 @@ function isStaticExpression(node, bindings) {
66
65
  if (node.ast) {
67
66
  return compilerDom.isConstantNode(node.ast, bindings);
68
67
  } else if (node.ast === null) {
68
+ if (!node.isStatic && (node.content === "true" || node.content === "false")) {
69
+ return true;
70
+ }
69
71
  const type = bindings[node.content];
70
72
  return type === "literal-const";
71
73
  }
72
74
  return false;
73
75
  }
74
- function resolveExpression(exp) {
76
+ function resolveExpression(exp, isComponent) {
75
77
  if (!exp.isStatic) {
76
- const value = getLiteralExpressionValue(exp);
78
+ const value = getLiteralExpressionValue(exp, isComponent);
77
79
  if (value !== null) {
78
- return compilerDom.createSimpleExpression("" + value, true, exp.loc);
80
+ return compilerDom.createSimpleExpression(value, true, exp.loc);
79
81
  }
80
82
  }
81
83
  return exp;
82
84
  }
83
- function getLiteralExpressionValue(exp) {
85
+ function getLiteralExpressionValue(exp, excludeNumber) {
84
86
  if (exp.ast) {
85
87
  if (exp.ast.type === "StringLiteral") {
86
88
  return exp.ast.value;
87
- } else if (exp.ast.type === "TemplateLiteral" && exp.ast.expressions.length === 0) {
88
- return exp.ast.quasis[0].value.cooked;
89
+ } else if (!excludeNumber && (exp.ast.type === "NumericLiteral" || exp.ast.type === "BigIntLiteral")) {
90
+ return String(exp.ast.value);
91
+ } else if (exp.ast.type === "TemplateLiteral") {
92
+ let result = "";
93
+ for (const [index, quasi] of exp.ast.quasis.entries()) {
94
+ result += quasi.value.cooked;
95
+ if (exp.ast.expressions[index]) {
96
+ let expressionValue = getLiteralExpressionValue({
97
+ ast: exp.ast.expressions[index]
98
+ });
99
+ if (expressionValue == null) {
100
+ return null;
101
+ } else {
102
+ result += expressionValue;
103
+ }
104
+ }
105
+ }
106
+ return result;
89
107
  }
90
108
  }
91
109
  return exp.isStatic ? exp.content : null;
@@ -125,6 +143,7 @@ function isBuiltInComponent(tag) {
125
143
  }
126
144
  }
127
145
 
146
+ const generatedVarRE = /^[nxr](\d+)$/;
128
147
  class TransformContext {
129
148
  constructor(ir, node, options = {}) {
130
149
  this.ir = ir;
@@ -136,6 +155,7 @@ class TransformContext {
136
155
  this.template = "";
137
156
  this.childrenTemplate = [];
138
157
  this.dynamic = this.ir.block.dynamic;
158
+ this.imports = [];
139
159
  this.inVOnce = false;
140
160
  this.inVFor = 0;
141
161
  this.comment = [];
@@ -143,10 +163,16 @@ class TransformContext {
143
163
  this.directive = this.ir.directive;
144
164
  this.slots = [];
145
165
  this.globalId = 0;
146
- this.increaseId = () => this.globalId++;
166
+ this.nextIdMap = null;
167
+ this.increaseId = () => {
168
+ const id = getNextId(this.nextIdMap, this.globalId);
169
+ this.globalId = getNextId(this.nextIdMap, id + 1);
170
+ return id;
171
+ };
147
172
  this.options = shared.extend({}, defaultOptions, options);
148
173
  this.root = this;
149
174
  if (options.filename) this.selfName = compilerDom.getSelfName(options.filename);
175
+ this.initNextIdMap();
150
176
  }
151
177
  enterBlock(ir, isVFor = false) {
152
178
  const { block, template, dynamic, childrenTemplate, slots } = this;
@@ -166,18 +192,33 @@ class TransformContext {
166
192
  isVFor && this.inVFor--;
167
193
  };
168
194
  }
195
+ initNextIdMap() {
196
+ const binding = this.root.options.bindingMetadata;
197
+ if (!binding) return;
198
+ const keys = Object.keys(binding);
199
+ if (keys.length === 0) return;
200
+ const numbers = /* @__PURE__ */ new Set();
201
+ for (const name of keys) {
202
+ const m = generatedVarRE.exec(name);
203
+ if (m) numbers.add(Number(m[1]));
204
+ }
205
+ if (numbers.size === 0) return;
206
+ this.globalId = getNextId(this.nextIdMap = buildNextIdMap(numbers), 0);
207
+ }
169
208
  reference() {
170
209
  if (this.dynamic.id !== void 0) return this.dynamic.id;
171
210
  this.dynamic.flags |= 1;
172
211
  return this.dynamic.id = this.increaseId();
173
212
  }
174
213
  pushTemplate(content) {
175
- const existing = this.ir.template.findIndex(
176
- (template) => template === content
177
- );
178
- if (existing !== -1) return existing;
179
- this.ir.template.push(content);
180
- return this.ir.template.length - 1;
214
+ const existingIndex = this.ir.templateIndexMap.get(content);
215
+ if (existingIndex !== void 0) {
216
+ return existingIndex;
217
+ }
218
+ const newIndex = this.ir.template.size;
219
+ this.ir.template.set(content, this.node.ns);
220
+ this.ir.templateIndexMap.set(content, newIndex);
221
+ return newIndex;
181
222
  }
182
223
  registerTemplate() {
183
224
  if (!this.template) return -1;
@@ -239,7 +280,8 @@ function transform(node, options = {}) {
239
280
  type: 0,
240
281
  node,
241
282
  source: node.source,
242
- template: [],
283
+ template: /* @__PURE__ */ new Map(),
284
+ templateIndexMap: /* @__PURE__ */ new Map(),
243
285
  component: /* @__PURE__ */ new Set(),
244
286
  directive: /* @__PURE__ */ new Set(),
245
287
  block: newBlock(node),
@@ -247,6 +289,7 @@ function transform(node, options = {}) {
247
289
  };
248
290
  const context = new TransformContext(ir, node, options);
249
291
  transformNode(context);
292
+ ir.node.imports = context.imports;
250
293
  return ir;
251
294
  }
252
295
  function transformNode(context) {
@@ -300,7 +343,32 @@ function createStructuralDirectiveTransform(name, fn) {
300
343
  }
301
344
  };
302
345
  }
346
+ function buildNextIdMap(nums) {
347
+ const map = /* @__PURE__ */ new Map();
348
+ const arr = Array.from(new Set(nums)).sort((a, b) => a - b);
349
+ if (arr.length === 0) return map;
350
+ for (let i = 0; i < arr.length; i++) {
351
+ let start = arr[i];
352
+ let end = start;
353
+ while (i + 1 < arr.length && arr[i + 1] === end + 1) {
354
+ i++;
355
+ end = arr[i];
356
+ }
357
+ for (let v = start; v <= end; v++) map.set(v, end + 1);
358
+ }
359
+ return map;
360
+ }
361
+ function getNextId(map, n) {
362
+ if (map && map.has(n)) return map.get(n);
363
+ return n;
364
+ }
303
365
 
366
+ const IMPORT_EXP_START = "__IMPORT_EXP_START__";
367
+ const IMPORT_EXP_END = "__IMPORT_EXP_END__";
368
+ const IMPORT_EXPR_RE = new RegExp(
369
+ `${IMPORT_EXP_START}(.*?)${IMPORT_EXP_END}`,
370
+ "g"
371
+ );
304
372
  const NEWLINE = Symbol(`newline` );
305
373
  const LF = Symbol(`line feed` );
306
374
  const INDENT_START = Symbol(`indent start` );
@@ -543,15 +611,12 @@ function genExpression(node, context, assignment) {
543
611
  let hasMemberExpression = false;
544
612
  if (ids.length) {
545
613
  const [frag, push] = buildCodeFragment();
546
- const isTSNode = ast && compilerDom.TS_NODE_TYPES.includes(ast.type);
547
614
  ids.sort((a, b) => a.start - b.start).forEach((id, i) => {
548
615
  const start = id.start - 1;
549
616
  const end = id.end - 1;
550
617
  const last = ids[i - 1];
551
- if (!(isTSNode && i === 0)) {
552
- const leadingText = content.slice(last ? last.end - 1 : 0, start);
553
- if (leadingText.length) push([leadingText, -3]);
554
- }
618
+ const leadingText = content.slice(last ? last.end - 1 : 0, start);
619
+ if (leadingText.length) push([leadingText, -3]);
555
620
  const source = content.slice(start, end);
556
621
  const parentStack2 = parentStackMap.get(id);
557
622
  const parent = parentStack2[parentStack2.length - 1];
@@ -571,7 +636,7 @@ function genExpression(node, context, assignment) {
571
636
  parentStack2
572
637
  )
573
638
  );
574
- if (i === ids.length - 1 && end < content.length && !isTSNode) {
639
+ if (i === ids.length - 1 && end < content.length) {
575
640
  push([content.slice(end), -3]);
576
641
  }
577
642
  });
@@ -953,7 +1018,11 @@ function genSetEvent(oper, context) {
953
1018
  const { helper } = context;
954
1019
  const { element, key, keyOverride, value, modifiers, delegate, effect } = oper;
955
1020
  const name = genName();
956
- const handler = genEventHandler(context, value, modifiers);
1021
+ const handler = [
1022
+ `${context.helper("createInvoker")}(`,
1023
+ ...genEventHandler(context, value, modifiers),
1024
+ `)`
1025
+ ];
957
1026
  const eventOptions = genEventOptions();
958
1027
  if (delegate) {
959
1028
  context.delegates.add(key.content);
@@ -1014,7 +1083,14 @@ function genEventHandler(context, value, modifiers = { nonKeys: [], keys: [] },
1014
1083
  if (compilerDom.isMemberExpression(value, context.options)) {
1015
1084
  handlerExp = genExpression(value, context);
1016
1085
  if (!isConstantBinding(value, context) && !extraWrap) {
1017
- handlerExp = [`e => `, ...handlerExp, `(e)`];
1086
+ const isTSNode = value.ast && compilerDom.TS_NODE_TYPES.includes(value.ast.type);
1087
+ handlerExp = [
1088
+ `e => `,
1089
+ isTSNode ? "(" : "",
1090
+ ...handlerExp,
1091
+ isTSNode ? ")" : "",
1092
+ `(e)`
1093
+ ];
1018
1094
  }
1019
1095
  } else if (compilerDom.isFnExpression(value, context.options)) {
1020
1096
  handlerExp = genExpression(value, context);
@@ -1300,12 +1376,12 @@ function matchPatterns(render, keyProp, idMap) {
1300
1376
  const keyOnlyBindingPatterns = [];
1301
1377
  render.effect = render.effect.filter((effect) => {
1302
1378
  if (keyProp !== void 0) {
1303
- const selector = matchSelectorPattern(effect, keyProp.ast, idMap);
1379
+ const selector = matchSelectorPattern(effect, keyProp.content, idMap);
1304
1380
  if (selector) {
1305
1381
  selectorPatterns.push(selector);
1306
1382
  return false;
1307
1383
  }
1308
- const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.ast);
1384
+ const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
1309
1385
  if (keyOnly) {
1310
1386
  keyOnlyBindingPatterns.push(keyOnly);
1311
1387
  return false;
@@ -1318,19 +1394,19 @@ function matchPatterns(render, keyProp, idMap) {
1318
1394
  selectorPatterns
1319
1395
  };
1320
1396
  }
1321
- function matchKeyOnlyBindingPattern(effect, keyAst) {
1397
+ function matchKeyOnlyBindingPattern(effect, key) {
1322
1398
  if (effect.expressions.length === 1) {
1323
- const ast = effect.expressions[0].ast;
1399
+ const { ast, content } = effect.expressions[0];
1324
1400
  if (typeof ast === "object" && ast !== null) {
1325
- if (isKeyOnlyBinding(ast, keyAst)) {
1401
+ if (isKeyOnlyBinding(ast, key, content)) {
1326
1402
  return { effect };
1327
1403
  }
1328
1404
  }
1329
1405
  }
1330
1406
  }
1331
- function matchSelectorPattern(effect, keyAst, idMap) {
1407
+ function matchSelectorPattern(effect, key, idMap) {
1332
1408
  if (effect.expressions.length === 1) {
1333
- const ast = effect.expressions[0].ast;
1409
+ const { ast, content } = effect.expressions[0];
1334
1410
  if (typeof ast === "object" && ast) {
1335
1411
  const matcheds = [];
1336
1412
  estreeWalker.walk(ast, {
@@ -1341,10 +1417,10 @@ function matchSelectorPattern(effect, keyAst, idMap) {
1341
1417
  [left, right],
1342
1418
  [right, left]
1343
1419
  ]) {
1344
- const aIsKey = isKeyOnlyBinding(a, keyAst);
1345
- const bIsKey = isKeyOnlyBinding(b, keyAst);
1420
+ const aIsKey = isKeyOnlyBinding(a, key, content);
1421
+ const bIsKey = isKeyOnlyBinding(b, key, content);
1346
1422
  const bVars = analyzeVariableScopes(b, idMap);
1347
- if (aIsKey && !bIsKey && !bVars.locals.length) {
1423
+ if (aIsKey && !bIsKey && !bVars.length) {
1348
1424
  matcheds.push([a, b]);
1349
1425
  }
1350
1426
  }
@@ -1352,21 +1428,17 @@ function matchSelectorPattern(effect, keyAst, idMap) {
1352
1428
  }
1353
1429
  });
1354
1430
  if (matcheds.length === 1) {
1355
- const [key, selector] = matcheds[0];
1431
+ const [key2, selector] = matcheds[0];
1356
1432
  const content2 = effect.expressions[0].content;
1357
1433
  let hasExtraId = false;
1358
- const parentStackMap = /* @__PURE__ */ new Map();
1359
- const parentStack = [];
1360
1434
  compilerDom.walkIdentifiers(
1361
1435
  ast,
1362
1436
  (id) => {
1363
- if (id.start !== key.start && id.start !== selector.start) {
1437
+ if (id.start !== key2.start && id.start !== selector.start) {
1364
1438
  hasExtraId = true;
1365
1439
  }
1366
- parentStackMap.set(id, parentStack.slice());
1367
1440
  },
1368
- false,
1369
- parentStack
1441
+ false
1370
1442
  );
1371
1443
  if (!hasExtraId) {
1372
1444
  const name = content2.slice(selector.start - 1, selector.end - 1);
@@ -1386,47 +1458,17 @@ function matchSelectorPattern(effect, keyAst, idMap) {
1386
1458
  }
1387
1459
  }
1388
1460
  }
1389
- const content = effect.expressions[0].content;
1390
- if (typeof ast === "object" && ast && ast.type === "ConditionalExpression" && ast.test.type === "BinaryExpression" && ast.test.operator === "===" && ast.test.left.type !== "PrivateName" && compilerDom.isStaticNode(ast.consequent) && compilerDom.isStaticNode(ast.alternate)) {
1391
- const left = ast.test.left;
1392
- const right = ast.test.right;
1393
- for (const [a, b] of [
1394
- [left, right],
1395
- [right, left]
1396
- ]) {
1397
- const aIsKey = isKeyOnlyBinding(a, keyAst);
1398
- const bIsKey = isKeyOnlyBinding(b, keyAst);
1399
- const bVars = analyzeVariableScopes(b, idMap);
1400
- if (aIsKey && !bIsKey && !bVars.locals.length) {
1401
- return {
1402
- effect,
1403
- // @ts-expect-error
1404
- selector: {
1405
- content: content.slice(b.start - 1, b.end - 1),
1406
- ast: b,
1407
- loc: b.loc,
1408
- isStatic: false
1409
- }
1410
- };
1411
- }
1412
- }
1413
- }
1414
1461
  }
1415
1462
  }
1416
1463
  function analyzeVariableScopes(ast, idMap) {
1417
- let globals = [];
1418
1464
  let locals = [];
1419
1465
  const ids = [];
1420
- const parentStackMap = /* @__PURE__ */ new Map();
1421
- const parentStack = [];
1422
1466
  compilerDom.walkIdentifiers(
1423
1467
  ast,
1424
1468
  (id) => {
1425
1469
  ids.push(id);
1426
- parentStackMap.set(id, parentStack.slice());
1427
1470
  },
1428
- false,
1429
- parentStack
1471
+ false
1430
1472
  );
1431
1473
  for (const id of ids) {
1432
1474
  if (shared.isGloballyAllowed(id.name)) {
@@ -1434,17 +1476,15 @@ function analyzeVariableScopes(ast, idMap) {
1434
1476
  }
1435
1477
  if (idMap[id.name]) {
1436
1478
  locals.push(id.name);
1437
- } else {
1438
- globals.push(id.name);
1439
1479
  }
1440
1480
  }
1441
- return { globals, locals };
1481
+ return locals;
1442
1482
  }
1443
- function isKeyOnlyBinding(expr, keyAst) {
1483
+ function isKeyOnlyBinding(expr, key, source) {
1444
1484
  let only = true;
1445
1485
  estreeWalker.walk(expr, {
1446
1486
  enter(node) {
1447
- if (types.isNodesEquivalent(node, keyAst)) {
1487
+ if (source.slice(node.start - 1, node.end - 1) === key) {
1448
1488
  this.skip();
1449
1489
  return;
1450
1490
  }
@@ -1509,7 +1549,8 @@ const helpers = {
1509
1549
  setValue: { name: "setValue" },
1510
1550
  setAttr: { name: "setAttr", needKey: true },
1511
1551
  setProp: { name: "setProp", needKey: true },
1512
- setDOMProp: { name: "setDOMProp", needKey: true }};
1552
+ setDOMProp: { name: "setDOMProp", needKey: true }
1553
+ };
1513
1554
  function genSetProp(oper, context) {
1514
1555
  const { helper } = context;
1515
1556
  const {
@@ -1524,12 +1565,14 @@ function genSetProp(oper, context) {
1524
1565
  [helper(resolvedHelper.name), null],
1525
1566
  `n${oper.element}`,
1526
1567
  resolvedHelper.needKey ? genExpression(key, context) : false,
1527
- propValue
1568
+ propValue,
1569
+ resolvedHelper.isSVG && "true"
1528
1570
  )
1529
1571
  ];
1530
1572
  }
1531
1573
  function genDynamicProps$1(oper, context) {
1532
1574
  const { helper } = context;
1575
+ const isSVG = shared.isSVGTag(oper.tag);
1533
1576
  const values = oper.props.map(
1534
1577
  (props) => Array.isArray(props) ? genLiteralObjectProps(props, context) : props.kind === 1 ? genLiteralObjectProps([props], context) : genExpression(props.value, context)
1535
1578
  );
@@ -1539,7 +1582,8 @@ function genDynamicProps$1(oper, context) {
1539
1582
  helper("setDynamicProps"),
1540
1583
  `n${oper.element}`,
1541
1584
  genMulti(DELIMITERS_ARRAY, ...values),
1542
- oper.root && "true"
1585
+ oper.root && "true",
1586
+ isSVG && "true"
1543
1587
  )
1544
1588
  ];
1545
1589
  }
@@ -1592,6 +1636,10 @@ function genPropValue(values, context) {
1592
1636
  }
1593
1637
  function getRuntimeHelper(tag, key, modifier) {
1594
1638
  const tagName = tag.toUpperCase();
1639
+ const isSVG = shared.isSVGTag(tag);
1640
+ if (isSVG) {
1641
+ return shared.extend({ isSVG: true }, helpers.setAttr);
1642
+ }
1595
1643
  if (modifier) {
1596
1644
  if (modifier === ".") {
1597
1645
  return getSpecialHelper(key, tagName) || helpers.setDOMProp;
@@ -1606,9 +1654,6 @@ function getRuntimeHelper(tag, key, modifier) {
1606
1654
  if (/aria[A-Z]/.test(key)) {
1607
1655
  return helpers.setDOMProp;
1608
1656
  }
1609
- if (shared.isSVGTag(tag)) {
1610
- return helpers.setAttr;
1611
- }
1612
1657
  if (shared.shouldSetAsAttr(tagName, key) || key.includes("-")) {
1613
1658
  return helpers.setAttr;
1614
1659
  }
@@ -1675,7 +1720,7 @@ function genSetText(oper, context) {
1675
1720
  function combineValues(values, context, jsx) {
1676
1721
  return values.flatMap((value, i) => {
1677
1722
  let exp = genExpression(value, context);
1678
- if (!jsx && getLiteralExpressionValue(value) == null) {
1723
+ if (!jsx && getLiteralExpressionValue(value, true) == null) {
1679
1724
  exp = genCall(context.helper("toDisplayString"), exp);
1680
1725
  }
1681
1726
  if (i > 0) {
@@ -1818,7 +1863,7 @@ function genCreateComponent(operation, context) {
1818
1863
  ...inlineHandlers,
1819
1864
  `const n${operation.id} = `,
1820
1865
  ...genCall(
1821
- operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"),
1866
+ operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.isCustomElement ? helper("createPlainElement") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"),
1822
1867
  tag,
1823
1868
  rawProps,
1824
1869
  rawSlots,
@@ -1828,7 +1873,9 @@ function genCreateComponent(operation, context) {
1828
1873
  ...genDirectivesForElement(operation.id, context)
1829
1874
  ];
1830
1875
  function genTag() {
1831
- if (operation.dynamic) {
1876
+ if (operation.isCustomElement) {
1877
+ return JSON.stringify(operation.tag);
1878
+ } else if (operation.dynamic) {
1832
1879
  if (operation.dynamic.isStatic) {
1833
1880
  return genCall(
1834
1881
  helper("resolveDynamicComponent"),
@@ -1955,7 +2002,7 @@ function genModelEvent(prop, context) {
1955
2002
  function genModelModifiers(prop, context) {
1956
2003
  const { key, modelModifiers } = prop;
1957
2004
  if (!modelModifiers || !modelModifiers.length) return [];
1958
- const modifiersKey = key.isStatic ? key.content === "modelValue" ? [`modelModifiers`] : [`${key.content}Modifiers`] : ["[", ...genExpression(key, context), ' + "Modifiers"]'];
2005
+ const modifiersKey = key.isStatic ? [shared.getModifierPropName(key.content)] : ["[", ...genExpression(key, context), ' + "Modifiers"]'];
1959
2006
  const modifiersVal = genDirectiveModifiers(modelModifiers);
1960
2007
  return [",", NEWLINE, ...modifiersKey, `: () => ({ ${modifiersVal} })`];
1961
2008
  }
@@ -2116,10 +2163,7 @@ function genSlotBlockWithProps(oper, context) {
2116
2163
  `}`
2117
2164
  ];
2118
2165
  }
2119
- if (node.type === 1 && // Not a real component
2120
- !isTeleportTag(node.tag) && // Needs to determine whether to activate/deactivate based on instance.parent being KeepAlive
2121
- !isKeepAliveTag(node.tag) && // Slot updates need to trigger TransitionGroup's onBeforeUpdate/onUpdated hook
2122
- !isTransitionGroupTag(node.tag)) {
2166
+ if (node.type === 1) {
2123
2167
  blockFn = [`${context.helper("withVaporCtx")}(`, ...blockFn, `)`];
2124
2168
  }
2125
2169
  return blockFn;
@@ -2142,8 +2186,6 @@ function genSlotOutlet(oper, context) {
2142
2186
  nameExpr,
2143
2187
  genRawProps(oper.props, context) || "null",
2144
2188
  fallbackArg,
2145
- noSlotted && "undefined",
2146
- // instance
2147
2189
  noSlotted && "true"
2148
2190
  // noSlotted
2149
2191
  )
@@ -2277,19 +2319,29 @@ function genInsertionState(operation, context) {
2277
2319
  ];
2278
2320
  }
2279
2321
 
2280
- function genTemplates(templates, rootIndex, { helper }) {
2281
- return templates.map(
2282
- (template, i) => `const t${i} = ${helper("template")}(${JSON.stringify(
2283
- template
2284
- )}${i === rootIndex ? ", true" : ""})
2322
+ function genTemplates(templates, rootIndex, context) {
2323
+ const result = [];
2324
+ let i = 0;
2325
+ templates.forEach((ns, template) => {
2326
+ result.push(
2327
+ `const ${context.tName(i)} = ${context.helper("template")}(${JSON.stringify(
2328
+ template
2329
+ ).replace(
2330
+ // replace import expressions with string concatenation
2331
+ IMPORT_EXPR_RE,
2332
+ `" + $1 + "`
2333
+ )}${i === rootIndex ? ", true" : ns ? ", false" : ""}${ns ? `, ${ns}` : ""})
2285
2334
  `
2286
- ).join("");
2335
+ );
2336
+ i++;
2337
+ });
2338
+ return result.join("");
2287
2339
  }
2288
2340
  function genSelf(dynamic, context) {
2289
2341
  const [frag, push] = buildCodeFragment();
2290
2342
  const { id, template, operation, hasDynamicChild } = dynamic;
2291
2343
  if (id !== void 0 && template !== void 0) {
2292
- push(NEWLINE, `const n${id} = t${template}()`);
2344
+ push(NEWLINE, `const n${id} = ${context.tName(template)}()`);
2293
2345
  push(...genDirectivesForElement(id, context));
2294
2346
  }
2295
2347
  if (operation) {
@@ -2324,7 +2376,7 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`) {
2324
2376
  }
2325
2377
  const elementIndex = index + offset;
2326
2378
  const logicalIndex = elementIndex - ifBranchCount + prependCount;
2327
- const variable = id === void 0 ? `p${context.block.tempId++}` : `n${id}`;
2379
+ const variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
2328
2380
  pushBlock(NEWLINE, `const ${variable} = `);
2329
2381
  if (prev) {
2330
2382
  if (elementIndex - prev[1] === 1) {
@@ -2442,18 +2494,34 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
2442
2494
  }
2443
2495
  }
2444
2496
 
2497
+ const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
2445
2498
  class CodegenContext {
2446
2499
  constructor(ir, options) {
2447
2500
  this.ir = ir;
2448
- this.helpers = /* @__PURE__ */ new Set([]);
2501
+ this.bindingNames = /* @__PURE__ */ new Set();
2502
+ this.helpers = /* @__PURE__ */ new Map();
2449
2503
  this.helper = (name) => {
2450
- this.helpers.add(name);
2451
- return `_${name}`;
2504
+ if (this.helpers.has(name)) {
2505
+ return this.helpers.get(name);
2506
+ }
2507
+ const base = `_${name}`;
2508
+ if (this.bindingNames.size === 0 || !this.bindingNames.has(base)) {
2509
+ this.helpers.set(name, base);
2510
+ return base;
2511
+ }
2512
+ const map = this.nextIdMap.get(base);
2513
+ const alias = `${base}${getNextId(map, 1)}`;
2514
+ this.helpers.set(name, alias);
2515
+ return alias;
2452
2516
  };
2453
2517
  this.delegates = /* @__PURE__ */ new Set();
2454
2518
  this.identifiers = /* @__PURE__ */ Object.create(null);
2455
2519
  this.seenInlineHandlerNames = /* @__PURE__ */ Object.create(null);
2456
2520
  this.scopeLevel = 0;
2521
+ this.templateVars = /* @__PURE__ */ new Map();
2522
+ this.nextIdMap = /* @__PURE__ */ new Map();
2523
+ this.lastIdMap = /* @__PURE__ */ new Map();
2524
+ this.lastTIndex = -1;
2457
2525
  const defaultOptions = {
2458
2526
  mode: "module",
2459
2527
  prefixIdentifiers: true,
@@ -2472,6 +2540,10 @@ class CodegenContext {
2472
2540
  };
2473
2541
  this.options = shared.extend(defaultOptions, options);
2474
2542
  this.block = ir.block;
2543
+ this.bindingNames = new Set(
2544
+ this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []
2545
+ );
2546
+ this.initNextIdMap();
2475
2547
  }
2476
2548
  withId(fn, map) {
2477
2549
  const { identifiers } = this;
@@ -2492,11 +2564,47 @@ class CodegenContext {
2492
2564
  enterScope() {
2493
2565
  return [this.scopeLevel++, () => this.scopeLevel--];
2494
2566
  }
2567
+ initNextIdMap() {
2568
+ if (this.bindingNames.size === 0) return;
2569
+ const map = /* @__PURE__ */ new Map();
2570
+ for (const name of this.bindingNames) {
2571
+ const m = idWithTrailingDigitsRE.exec(name);
2572
+ if (!m) continue;
2573
+ const prefix = m[1];
2574
+ const num = Number(m[2]);
2575
+ let set = map.get(prefix);
2576
+ if (!set) map.set(prefix, set = /* @__PURE__ */ new Set());
2577
+ set.add(num);
2578
+ }
2579
+ for (const [prefix, nums] of map) {
2580
+ this.nextIdMap.set(prefix, buildNextIdMap(nums));
2581
+ }
2582
+ }
2583
+ tName(i) {
2584
+ let name = this.templateVars.get(i);
2585
+ if (name) return name;
2586
+ const map = this.nextIdMap.get("t");
2587
+ let lastId = this.lastIdMap.get("t") || -1;
2588
+ for (let j = this.lastTIndex + 1; j <= i; j++) {
2589
+ this.templateVars.set(
2590
+ j,
2591
+ name = `t${lastId = getNextId(map, Math.max(j, lastId + 1))}`
2592
+ );
2593
+ }
2594
+ this.lastIdMap.set("t", lastId);
2595
+ this.lastTIndex = i;
2596
+ return name;
2597
+ }
2598
+ pName(i) {
2599
+ const map = this.nextIdMap.get("p");
2600
+ let lastId = this.lastIdMap.get("p") || -1;
2601
+ this.lastIdMap.set("p", lastId = getNextId(map, Math.max(i, lastId + 1)));
2602
+ return `p${lastId}`;
2603
+ }
2495
2604
  }
2496
2605
  function generate(ir, options = {}) {
2497
2606
  const [frag, push] = buildCodeFragment();
2498
2607
  const context = new CodegenContext(ir, options);
2499
- const { helpers } = context;
2500
2608
  const { inline, bindingMetadata } = options;
2501
2609
  const functionName = "render";
2502
2610
  const args = ["_ctx"];
@@ -2523,7 +2631,7 @@ function generate(ir, options = {}) {
2523
2631
  }
2524
2632
  const delegates = genDelegates(context);
2525
2633
  const templates = genTemplates(ir.template, ir.rootTemplateIndex, context);
2526
- const imports = genHelperImports(context);
2634
+ const imports = genHelperImports(context) + genAssetImports(context);
2527
2635
  const preamble = imports + templates + delegates;
2528
2636
  const newlineCount = [...preamble].filter((c) => c === "\n").length;
2529
2637
  if (newlineCount && !inline) {
@@ -2538,7 +2646,7 @@ function generate(ir, options = {}) {
2538
2646
  ast: ir,
2539
2647
  preamble,
2540
2648
  map: map && map.toJSON(),
2541
- helpers
2649
+ helpers: new Set(Array.from(context.helpers.keys()))
2542
2650
  };
2543
2651
  }
2544
2652
  function genDelegates({ delegates, helper }) {
@@ -2547,10 +2655,21 @@ function genDelegates({ delegates, helper }) {
2547
2655
  ...Array.from(delegates).map((v) => `"${v}"`)
2548
2656
  ).join("") + "\n" : "";
2549
2657
  }
2550
- function genHelperImports({ helpers, helper, options }) {
2658
+ function genHelperImports({ helpers, options }) {
2551
2659
  let imports = "";
2552
2660
  if (helpers.size) {
2553
- imports += `import { ${[...helpers].map((h) => `${h} as _${h}`).join(", ")} } from '${options.runtimeModuleName}';
2661
+ imports += `import { ${Array.from(helpers).map(([h, alias]) => `${h} as ${alias}`).join(", ")} } from '${options.runtimeModuleName}';
2662
+ `;
2663
+ }
2664
+ return imports;
2665
+ }
2666
+ function genAssetImports({ ir }) {
2667
+ const assetImports = ir.node.imports;
2668
+ let imports = "";
2669
+ for (const assetImport of assetImports) {
2670
+ const exp = assetImport.exp;
2671
+ const name = exp.content;
2672
+ imports += `import ${name} from '${assetImport.path}';
2554
2673
  `;
2555
2674
  }
2556
2675
  return imports;
@@ -2662,7 +2781,8 @@ const transformElement = (node, context) => {
2662
2781
  ({ node } = context);
2663
2782
  if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1)))
2664
2783
  return;
2665
- const isComponent = node.tagType === 1;
2784
+ const isCustomElement = !!context.options.isCustomElement(node.tag);
2785
+ const isComponent = node.tagType === 1 || isCustomElement;
2666
2786
  const isDynamicComponent = isComponentTag(node.tag);
2667
2787
  const propsResult = buildProps(
2668
2788
  node,
@@ -2675,14 +2795,15 @@ const transformElement = (node, context) => {
2675
2795
  while (parent && parent.parent && parent.node.type === 1 && parent.node.tagType === 3) {
2676
2796
  parent = parent.parent;
2677
2797
  }
2678
- const singleRoot = context.root === parent && parent.node.children.filter((child) => child.type !== 3).length === 1;
2798
+ const singleRoot = context.root === parent && parent.node.children.filter((child) => child.type !== 3).length === 1 || isCustomElement;
2679
2799
  if (isComponent) {
2680
2800
  transformComponentElement(
2681
2801
  node,
2682
2802
  propsResult,
2683
2803
  singleRoot,
2684
2804
  context,
2685
- isDynamicComponent
2805
+ isDynamicComponent,
2806
+ isCustomElement
2686
2807
  );
2687
2808
  } else {
2688
2809
  transformNativeElement(
@@ -2695,11 +2816,11 @@ const transformElement = (node, context) => {
2695
2816
  }
2696
2817
  };
2697
2818
  };
2698
- function transformComponentElement(node, propsResult, singleRoot, context, isDynamicComponent) {
2819
+ function transformComponentElement(node, propsResult, singleRoot, context, isDynamicComponent, isCustomElement) {
2699
2820
  const dynamicComponent = isDynamicComponent ? resolveDynamicComponent(node) : void 0;
2700
2821
  let { tag } = node;
2701
2822
  let asset = true;
2702
- if (!dynamicComponent) {
2823
+ if (!dynamicComponent && !isCustomElement) {
2703
2824
  const fromSetup = resolveSetupReference(tag, context);
2704
2825
  if (fromSetup) {
2705
2826
  tag = fromSetup;
@@ -2735,7 +2856,8 @@ function transformComponentElement(node, propsResult, singleRoot, context, isDyn
2735
2856
  root: singleRoot && !context.inVFor,
2736
2857
  slots: [...context.slots],
2737
2858
  once: context.inVOnce,
2738
- dynamic: dynamicComponent
2859
+ dynamic: dynamicComponent,
2860
+ isCustomElement
2739
2861
  };
2740
2862
  context.slots = [];
2741
2863
  }
@@ -2782,16 +2904,22 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
2782
2904
  type: 3,
2783
2905
  element: context.reference(),
2784
2906
  props: dynamicArgs,
2785
- root: singleRoot
2907
+ root: singleRoot,
2908
+ tag
2786
2909
  },
2787
2910
  getEffectIndex
2788
2911
  );
2789
2912
  } else {
2790
2913
  for (const prop of propsResult[1]) {
2791
2914
  const { key, values } = prop;
2792
- if (key.isStatic && values.length === 1 && values[0].isStatic && !dynamicKeys.includes(key.content)) {
2915
+ if (context.imports.some(
2916
+ (imported) => values[0].content.includes(imported.exp.content)
2917
+ )) {
2918
+ template += ` ${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
2919
+ } else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
2793
2920
  template += ` ${key.content}`;
2794
- if (values[0].content) template += `="${values[0].content}"`;
2921
+ if (values[0].content)
2922
+ template += `="${values[0].content === "''" ? "" : values[0].content}"`;
2795
2923
  } else {
2796
2924
  dynamicProps.push(key.content);
2797
2925
  context.registerEffect(
@@ -2813,7 +2941,7 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
2813
2941
  template += `</${tag}>`;
2814
2942
  }
2815
2943
  if (singleRoot) {
2816
- context.ir.rootTemplateIndex = context.ir.template.length;
2944
+ context.ir.rootTemplateIndex = context.ir.template.size;
2817
2945
  }
2818
2946
  if (context.parent && context.parent.node.type === 1 && !compilerDom.isValidHTMLNesting(context.parent.node.tag, tag)) {
2819
2947
  context.reference();
@@ -3068,7 +3196,8 @@ const transformVBind = (dir, node, context) => {
3068
3196
  );
3069
3197
  exp = compilerDom.createSimpleExpression("", true, loc);
3070
3198
  }
3071
- exp = resolveExpression(exp);
3199
+ const isComponent = node.tagType === 1;
3200
+ exp = resolveExpression(exp, isComponent);
3072
3201
  arg = resolveExpression(arg);
3073
3202
  if (arg.isStatic && isReservedProp(arg.content)) return;
3074
3203
  let camel = false;
@@ -3274,30 +3403,18 @@ function processInterpolation(context) {
3274
3403
  }
3275
3404
  context.template += " ";
3276
3405
  const id = context.reference();
3277
- if (values.length === 0) {
3406
+ if (values.length === 0 || values.every((v) => getLiteralExpressionValue(v) != null) && parentNode.type !== 0) {
3278
3407
  return;
3279
3408
  }
3280
- const nonConstantExps = values.filter((v) => !isConstantExpression(v));
3281
- const isStatic = !nonConstantExps.length || nonConstantExps.every(
3282
- (e) => isStaticExpression(e, context.options.bindingMetadata)
3283
- ) || context.inVOnce;
3284
- if (isStatic) {
3285
- context.registerOperation({
3286
- type: 4,
3287
- element: id,
3288
- values
3289
- });
3290
- } else {
3291
- context.registerEffect(values, {
3292
- type: 4,
3293
- element: id,
3294
- values
3295
- });
3296
- }
3409
+ context.registerEffect(values, {
3410
+ type: 4,
3411
+ element: id,
3412
+ values
3413
+ });
3297
3414
  }
3298
3415
  function processTextContainer(children, context) {
3299
3416
  const values = processTextLikeChildren(children, context);
3300
- const literals = values.map(getLiteralExpressionValue);
3417
+ const literals = values.map((value) => getLiteralExpressionValue(value));
3301
3418
  if (literals.every((l) => l != null)) {
3302
3419
  context.childrenTemplate = literals.map((l) => shared.escapeHtml(String(l)));
3303
3420
  } else {
@@ -3550,7 +3667,7 @@ function processIf(node, dir, context) {
3550
3667
  id: -1,
3551
3668
  condition: dir.exp,
3552
3669
  positive: branch,
3553
- once: context.inVOnce
3670
+ once: context.inVOnce || isStaticExpression(dir.exp, context.options.bindingMetadata)
3554
3671
  };
3555
3672
  }
3556
3673
  return () => onExit();