@vue/compiler-core 3.4.0-alpha.3 → 3.4.0-beta.1

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.
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var shared = require('@vue/shared');
6
6
  var decode_js = require('entities/lib/decode.js');
7
7
  var parser = require('@babel/parser');
8
- var sourceMapJs = require('source-map-js');
9
8
  var estreeWalker = require('estree-walker');
9
+ var sourceMapJs = require('source-map-js');
10
10
 
11
11
  const FRAGMENT = Symbol(`Fragment` );
12
12
  const TELEPORT = Symbol(`Teleport` );
@@ -96,6 +96,90 @@ function registerRuntimeHelpers(helpers) {
96
96
  });
97
97
  }
98
98
 
99
+ const Namespaces = {
100
+ "HTML": 0,
101
+ "0": "HTML",
102
+ "SVG": 1,
103
+ "1": "SVG",
104
+ "MATH_ML": 2,
105
+ "2": "MATH_ML"
106
+ };
107
+ const NodeTypes = {
108
+ "ROOT": 0,
109
+ "0": "ROOT",
110
+ "ELEMENT": 1,
111
+ "1": "ELEMENT",
112
+ "TEXT": 2,
113
+ "2": "TEXT",
114
+ "COMMENT": 3,
115
+ "3": "COMMENT",
116
+ "SIMPLE_EXPRESSION": 4,
117
+ "4": "SIMPLE_EXPRESSION",
118
+ "INTERPOLATION": 5,
119
+ "5": "INTERPOLATION",
120
+ "ATTRIBUTE": 6,
121
+ "6": "ATTRIBUTE",
122
+ "DIRECTIVE": 7,
123
+ "7": "DIRECTIVE",
124
+ "COMPOUND_EXPRESSION": 8,
125
+ "8": "COMPOUND_EXPRESSION",
126
+ "IF": 9,
127
+ "9": "IF",
128
+ "IF_BRANCH": 10,
129
+ "10": "IF_BRANCH",
130
+ "FOR": 11,
131
+ "11": "FOR",
132
+ "TEXT_CALL": 12,
133
+ "12": "TEXT_CALL",
134
+ "VNODE_CALL": 13,
135
+ "13": "VNODE_CALL",
136
+ "JS_CALL_EXPRESSION": 14,
137
+ "14": "JS_CALL_EXPRESSION",
138
+ "JS_OBJECT_EXPRESSION": 15,
139
+ "15": "JS_OBJECT_EXPRESSION",
140
+ "JS_PROPERTY": 16,
141
+ "16": "JS_PROPERTY",
142
+ "JS_ARRAY_EXPRESSION": 17,
143
+ "17": "JS_ARRAY_EXPRESSION",
144
+ "JS_FUNCTION_EXPRESSION": 18,
145
+ "18": "JS_FUNCTION_EXPRESSION",
146
+ "JS_CONDITIONAL_EXPRESSION": 19,
147
+ "19": "JS_CONDITIONAL_EXPRESSION",
148
+ "JS_CACHE_EXPRESSION": 20,
149
+ "20": "JS_CACHE_EXPRESSION",
150
+ "JS_BLOCK_STATEMENT": 21,
151
+ "21": "JS_BLOCK_STATEMENT",
152
+ "JS_TEMPLATE_LITERAL": 22,
153
+ "22": "JS_TEMPLATE_LITERAL",
154
+ "JS_IF_STATEMENT": 23,
155
+ "23": "JS_IF_STATEMENT",
156
+ "JS_ASSIGNMENT_EXPRESSION": 24,
157
+ "24": "JS_ASSIGNMENT_EXPRESSION",
158
+ "JS_SEQUENCE_EXPRESSION": 25,
159
+ "25": "JS_SEQUENCE_EXPRESSION",
160
+ "JS_RETURN_STATEMENT": 26,
161
+ "26": "JS_RETURN_STATEMENT"
162
+ };
163
+ const ElementTypes = {
164
+ "ELEMENT": 0,
165
+ "0": "ELEMENT",
166
+ "COMPONENT": 1,
167
+ "1": "COMPONENT",
168
+ "SLOT": 2,
169
+ "2": "SLOT",
170
+ "TEMPLATE": 3,
171
+ "3": "TEMPLATE"
172
+ };
173
+ const ConstantTypes = {
174
+ "NOT_CONSTANT": 0,
175
+ "0": "NOT_CONSTANT",
176
+ "CAN_SKIP_PATCH": 1,
177
+ "1": "CAN_SKIP_PATCH",
178
+ "CAN_HOIST": 2,
179
+ "2": "CAN_HOIST",
180
+ "CAN_STRINGIFY": 3,
181
+ "3": "CAN_STRINGIFY"
182
+ };
99
183
  const locStub = {
100
184
  start: { line: 1, column: 1, offset: 0 },
101
185
  end: { line: 1, column: 1, offset: 0 },
@@ -350,7 +434,9 @@ class Tokenizer {
350
434
  this.inRCDATA = false;
351
435
  /** For disabling RCDATA tags handling */
352
436
  this.inXML = false;
353
- /** Reocrd newline positions for fast line / column calculation */
437
+ /** For disabling interpolation parsing in v-pre */
438
+ this.inVPre = false;
439
+ /** Record newline positions for fast line / column calculation */
354
440
  this.newlines = [];
355
441
  this.mode = 0;
356
442
  this.delimiterOpen = defaultDelimitersOpen;
@@ -375,6 +461,7 @@ class Tokenizer {
375
461
  this.sectionStart = 0;
376
462
  this.index = 0;
377
463
  this.baseState = 1;
464
+ this.inRCDATA = false;
378
465
  this.currentSequence = void 0;
379
466
  this.newlines.length = 0;
380
467
  this.delimiterOpen = defaultDelimitersOpen;
@@ -415,7 +502,7 @@ class Tokenizer {
415
502
  this.sectionStart = this.index;
416
503
  } else if (c === 38) {
417
504
  this.startEntity();
418
- } else if (c === this.delimiterOpen[0]) {
505
+ } else if (!this.inVPre && c === this.delimiterOpen[0]) {
419
506
  this.state = 2;
420
507
  this.delimiterIndex = 0;
421
508
  this.stateInterpolationOpen(c);
@@ -1151,6 +1238,16 @@ class Tokenizer {
1151
1238
  }
1152
1239
  }
1153
1240
 
1241
+ const CompilerDeprecationTypes = {
1242
+ "COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT",
1243
+ "COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC",
1244
+ "COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER",
1245
+ "COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE",
1246
+ "COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE",
1247
+ "COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE",
1248
+ "COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE",
1249
+ "COMPILER_FILTERS": "COMPILER_FILTER"
1250
+ };
1154
1251
  const deprecationData = {
1155
1252
  ["COMPILER_IS_ON_ELEMENT"]: {
1156
1253
  message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`,
@@ -1232,6 +1329,114 @@ function createCompilerError(code, loc, messages, additionalMessage) {
1232
1329
  error.loc = loc;
1233
1330
  return error;
1234
1331
  }
1332
+ const ErrorCodes = {
1333
+ "ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
1334
+ "0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
1335
+ "CDATA_IN_HTML_CONTENT": 1,
1336
+ "1": "CDATA_IN_HTML_CONTENT",
1337
+ "DUPLICATE_ATTRIBUTE": 2,
1338
+ "2": "DUPLICATE_ATTRIBUTE",
1339
+ "END_TAG_WITH_ATTRIBUTES": 3,
1340
+ "3": "END_TAG_WITH_ATTRIBUTES",
1341
+ "END_TAG_WITH_TRAILING_SOLIDUS": 4,
1342
+ "4": "END_TAG_WITH_TRAILING_SOLIDUS",
1343
+ "EOF_BEFORE_TAG_NAME": 5,
1344
+ "5": "EOF_BEFORE_TAG_NAME",
1345
+ "EOF_IN_CDATA": 6,
1346
+ "6": "EOF_IN_CDATA",
1347
+ "EOF_IN_COMMENT": 7,
1348
+ "7": "EOF_IN_COMMENT",
1349
+ "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
1350
+ "8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
1351
+ "EOF_IN_TAG": 9,
1352
+ "9": "EOF_IN_TAG",
1353
+ "INCORRECTLY_CLOSED_COMMENT": 10,
1354
+ "10": "INCORRECTLY_CLOSED_COMMENT",
1355
+ "INCORRECTLY_OPENED_COMMENT": 11,
1356
+ "11": "INCORRECTLY_OPENED_COMMENT",
1357
+ "INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
1358
+ "12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
1359
+ "MISSING_ATTRIBUTE_VALUE": 13,
1360
+ "13": "MISSING_ATTRIBUTE_VALUE",
1361
+ "MISSING_END_TAG_NAME": 14,
1362
+ "14": "MISSING_END_TAG_NAME",
1363
+ "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
1364
+ "15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
1365
+ "NESTED_COMMENT": 16,
1366
+ "16": "NESTED_COMMENT",
1367
+ "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
1368
+ "17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
1369
+ "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
1370
+ "18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
1371
+ "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
1372
+ "19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
1373
+ "UNEXPECTED_NULL_CHARACTER": 20,
1374
+ "20": "UNEXPECTED_NULL_CHARACTER",
1375
+ "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
1376
+ "21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
1377
+ "UNEXPECTED_SOLIDUS_IN_TAG": 22,
1378
+ "22": "UNEXPECTED_SOLIDUS_IN_TAG",
1379
+ "X_INVALID_END_TAG": 23,
1380
+ "23": "X_INVALID_END_TAG",
1381
+ "X_MISSING_END_TAG": 24,
1382
+ "24": "X_MISSING_END_TAG",
1383
+ "X_MISSING_INTERPOLATION_END": 25,
1384
+ "25": "X_MISSING_INTERPOLATION_END",
1385
+ "X_MISSING_DIRECTIVE_NAME": 26,
1386
+ "26": "X_MISSING_DIRECTIVE_NAME",
1387
+ "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
1388
+ "27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
1389
+ "X_V_IF_NO_EXPRESSION": 28,
1390
+ "28": "X_V_IF_NO_EXPRESSION",
1391
+ "X_V_IF_SAME_KEY": 29,
1392
+ "29": "X_V_IF_SAME_KEY",
1393
+ "X_V_ELSE_NO_ADJACENT_IF": 30,
1394
+ "30": "X_V_ELSE_NO_ADJACENT_IF",
1395
+ "X_V_FOR_NO_EXPRESSION": 31,
1396
+ "31": "X_V_FOR_NO_EXPRESSION",
1397
+ "X_V_FOR_MALFORMED_EXPRESSION": 32,
1398
+ "32": "X_V_FOR_MALFORMED_EXPRESSION",
1399
+ "X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
1400
+ "33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
1401
+ "X_V_BIND_NO_EXPRESSION": 34,
1402
+ "34": "X_V_BIND_NO_EXPRESSION",
1403
+ "X_V_ON_NO_EXPRESSION": 35,
1404
+ "35": "X_V_ON_NO_EXPRESSION",
1405
+ "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
1406
+ "36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
1407
+ "X_V_SLOT_MIXED_SLOT_USAGE": 37,
1408
+ "37": "X_V_SLOT_MIXED_SLOT_USAGE",
1409
+ "X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
1410
+ "38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
1411
+ "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
1412
+ "39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
1413
+ "X_V_SLOT_MISPLACED": 40,
1414
+ "40": "X_V_SLOT_MISPLACED",
1415
+ "X_V_MODEL_NO_EXPRESSION": 41,
1416
+ "41": "X_V_MODEL_NO_EXPRESSION",
1417
+ "X_V_MODEL_MALFORMED_EXPRESSION": 42,
1418
+ "42": "X_V_MODEL_MALFORMED_EXPRESSION",
1419
+ "X_V_MODEL_ON_SCOPE_VARIABLE": 43,
1420
+ "43": "X_V_MODEL_ON_SCOPE_VARIABLE",
1421
+ "X_V_MODEL_ON_PROPS": 44,
1422
+ "44": "X_V_MODEL_ON_PROPS",
1423
+ "X_INVALID_EXPRESSION": 45,
1424
+ "45": "X_INVALID_EXPRESSION",
1425
+ "X_KEEP_ALIVE_INVALID_CHILDREN": 46,
1426
+ "46": "X_KEEP_ALIVE_INVALID_CHILDREN",
1427
+ "X_PREFIX_ID_NOT_SUPPORTED": 47,
1428
+ "47": "X_PREFIX_ID_NOT_SUPPORTED",
1429
+ "X_MODULE_MODE_NOT_SUPPORTED": 48,
1430
+ "48": "X_MODULE_MODE_NOT_SUPPORTED",
1431
+ "X_CACHE_HANDLER_NOT_SUPPORTED": 49,
1432
+ "49": "X_CACHE_HANDLER_NOT_SUPPORTED",
1433
+ "X_SCOPE_ID_NOT_SUPPORTED": 50,
1434
+ "50": "X_SCOPE_ID_NOT_SUPPORTED",
1435
+ "X_VNODE_HOOKS": 51,
1436
+ "51": "X_VNODE_HOOKS",
1437
+ "__EXTEND_POINT__": 52,
1438
+ "52": "__EXTEND_POINT__"
1439
+ };
1235
1440
  const errorMessages = {
1236
1441
  // parse errors
1237
1442
  [0]: "Illegal comment.",
@@ -1284,18 +1489,281 @@ const errorMessages = {
1284
1489
  Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
1285
1490
  [45]: `Error parsing JavaScript expression: `,
1286
1491
  [46]: `<KeepAlive> expects exactly one child component.`,
1492
+ [51]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`,
1287
1493
  // generic errors
1288
1494
  [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
1289
1495
  [48]: `ES module mode is not supported in this build of compiler.`,
1290
1496
  [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
1291
1497
  [50]: `"scopeId" option is only supported in module mode.`,
1292
- // deprecations
1293
- [51]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`,
1294
- [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
1295
1498
  // just to fulfill types
1296
- [53]: ``
1499
+ [52]: ``
1297
1500
  };
1298
1501
 
1502
+ function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
1503
+ const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
1504
+ estreeWalker.walk(root, {
1505
+ enter(node, parent) {
1506
+ parent && parentStack.push(parent);
1507
+ if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
1508
+ return this.skip();
1509
+ }
1510
+ if (node.type === "Identifier") {
1511
+ const isLocal = !!knownIds[node.name];
1512
+ const isRefed = isReferencedIdentifier(node, parent, parentStack);
1513
+ if (includeAll || isRefed && !isLocal) {
1514
+ onIdentifier(node, parent, parentStack, isRefed, isLocal);
1515
+ }
1516
+ } else if (node.type === "ObjectProperty" && parent.type === "ObjectPattern") {
1517
+ node.inPattern = true;
1518
+ } else if (isFunctionType(node)) {
1519
+ walkFunctionParams(node, (id) => markScopeIdentifier(node, id, knownIds));
1520
+ } else if (node.type === "BlockStatement") {
1521
+ walkBlockDeclarations(
1522
+ node,
1523
+ (id) => markScopeIdentifier(node, id, knownIds)
1524
+ );
1525
+ }
1526
+ },
1527
+ leave(node, parent) {
1528
+ parent && parentStack.pop();
1529
+ if (node !== rootExp && node.scopeIds) {
1530
+ for (const id of node.scopeIds) {
1531
+ knownIds[id]--;
1532
+ if (knownIds[id] === 0) {
1533
+ delete knownIds[id];
1534
+ }
1535
+ }
1536
+ }
1537
+ }
1538
+ });
1539
+ }
1540
+ function isReferencedIdentifier(id, parent, parentStack) {
1541
+ if (!parent) {
1542
+ return true;
1543
+ }
1544
+ if (id.name === "arguments") {
1545
+ return false;
1546
+ }
1547
+ if (isReferenced(id, parent)) {
1548
+ return true;
1549
+ }
1550
+ switch (parent.type) {
1551
+ case "AssignmentExpression":
1552
+ case "AssignmentPattern":
1553
+ return true;
1554
+ case "ObjectPattern":
1555
+ case "ArrayPattern":
1556
+ return isInDestructureAssignment(parent, parentStack);
1557
+ }
1558
+ return false;
1559
+ }
1560
+ function isInDestructureAssignment(parent, parentStack) {
1561
+ if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
1562
+ let i = parentStack.length;
1563
+ while (i--) {
1564
+ const p = parentStack[i];
1565
+ if (p.type === "AssignmentExpression") {
1566
+ return true;
1567
+ } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
1568
+ break;
1569
+ }
1570
+ }
1571
+ }
1572
+ return false;
1573
+ }
1574
+ function walkFunctionParams(node, onIdent) {
1575
+ for (const p of node.params) {
1576
+ for (const id of extractIdentifiers(p)) {
1577
+ onIdent(id);
1578
+ }
1579
+ }
1580
+ }
1581
+ function walkBlockDeclarations(block, onIdent) {
1582
+ for (const stmt of block.body) {
1583
+ if (stmt.type === "VariableDeclaration") {
1584
+ if (stmt.declare)
1585
+ continue;
1586
+ for (const decl of stmt.declarations) {
1587
+ for (const id of extractIdentifiers(decl.id)) {
1588
+ onIdent(id);
1589
+ }
1590
+ }
1591
+ } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
1592
+ if (stmt.declare || !stmt.id)
1593
+ continue;
1594
+ onIdent(stmt.id);
1595
+ } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
1596
+ const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
1597
+ if (variable && variable.type === "VariableDeclaration") {
1598
+ for (const decl of variable.declarations) {
1599
+ for (const id of extractIdentifiers(decl.id)) {
1600
+ onIdent(id);
1601
+ }
1602
+ }
1603
+ }
1604
+ }
1605
+ }
1606
+ }
1607
+ function extractIdentifiers(param, nodes = []) {
1608
+ switch (param.type) {
1609
+ case "Identifier":
1610
+ nodes.push(param);
1611
+ break;
1612
+ case "MemberExpression":
1613
+ let object = param;
1614
+ while (object.type === "MemberExpression") {
1615
+ object = object.object;
1616
+ }
1617
+ nodes.push(object);
1618
+ break;
1619
+ case "ObjectPattern":
1620
+ for (const prop of param.properties) {
1621
+ if (prop.type === "RestElement") {
1622
+ extractIdentifiers(prop.argument, nodes);
1623
+ } else {
1624
+ extractIdentifiers(prop.value, nodes);
1625
+ }
1626
+ }
1627
+ break;
1628
+ case "ArrayPattern":
1629
+ param.elements.forEach((element) => {
1630
+ if (element)
1631
+ extractIdentifiers(element, nodes);
1632
+ });
1633
+ break;
1634
+ case "RestElement":
1635
+ extractIdentifiers(param.argument, nodes);
1636
+ break;
1637
+ case "AssignmentPattern":
1638
+ extractIdentifiers(param.left, nodes);
1639
+ break;
1640
+ }
1641
+ return nodes;
1642
+ }
1643
+ function markScopeIdentifier(node, child, knownIds) {
1644
+ const { name } = child;
1645
+ if (node.scopeIds && node.scopeIds.has(name)) {
1646
+ return;
1647
+ }
1648
+ if (name in knownIds) {
1649
+ knownIds[name]++;
1650
+ } else {
1651
+ knownIds[name] = 1;
1652
+ }
1653
+ (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
1654
+ }
1655
+ const isFunctionType = (node) => {
1656
+ return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
1657
+ };
1658
+ const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
1659
+ const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
1660
+ function isReferenced(node, parent, grandparent) {
1661
+ switch (parent.type) {
1662
+ case "MemberExpression":
1663
+ case "OptionalMemberExpression":
1664
+ if (parent.property === node) {
1665
+ return !!parent.computed;
1666
+ }
1667
+ return parent.object === node;
1668
+ case "JSXMemberExpression":
1669
+ return parent.object === node;
1670
+ case "VariableDeclarator":
1671
+ return parent.init === node;
1672
+ case "ArrowFunctionExpression":
1673
+ return parent.body === node;
1674
+ case "PrivateName":
1675
+ return false;
1676
+ case "ClassMethod":
1677
+ case "ClassPrivateMethod":
1678
+ case "ObjectMethod":
1679
+ if (parent.key === node) {
1680
+ return !!parent.computed;
1681
+ }
1682
+ return false;
1683
+ case "ObjectProperty":
1684
+ if (parent.key === node) {
1685
+ return !!parent.computed;
1686
+ }
1687
+ return !grandparent || grandparent.type !== "ObjectPattern";
1688
+ case "ClassProperty":
1689
+ if (parent.key === node) {
1690
+ return !!parent.computed;
1691
+ }
1692
+ return true;
1693
+ case "ClassPrivateProperty":
1694
+ return parent.key !== node;
1695
+ case "ClassDeclaration":
1696
+ case "ClassExpression":
1697
+ return parent.superClass === node;
1698
+ case "AssignmentExpression":
1699
+ return parent.right === node;
1700
+ case "AssignmentPattern":
1701
+ return parent.right === node;
1702
+ case "LabeledStatement":
1703
+ return false;
1704
+ case "CatchClause":
1705
+ return false;
1706
+ case "RestElement":
1707
+ return false;
1708
+ case "BreakStatement":
1709
+ case "ContinueStatement":
1710
+ return false;
1711
+ case "FunctionDeclaration":
1712
+ case "FunctionExpression":
1713
+ return false;
1714
+ case "ExportNamespaceSpecifier":
1715
+ case "ExportDefaultSpecifier":
1716
+ return false;
1717
+ case "ExportSpecifier":
1718
+ if (grandparent == null ? void 0 : grandparent.source) {
1719
+ return false;
1720
+ }
1721
+ return parent.local === node;
1722
+ case "ImportDefaultSpecifier":
1723
+ case "ImportNamespaceSpecifier":
1724
+ case "ImportSpecifier":
1725
+ return false;
1726
+ case "ImportAttribute":
1727
+ return false;
1728
+ case "JSXAttribute":
1729
+ return false;
1730
+ case "ObjectPattern":
1731
+ case "ArrayPattern":
1732
+ return false;
1733
+ case "MetaProperty":
1734
+ return false;
1735
+ case "ObjectTypeProperty":
1736
+ return parent.key !== node;
1737
+ case "TSEnumMember":
1738
+ return parent.id !== node;
1739
+ case "TSPropertySignature":
1740
+ if (parent.key === node) {
1741
+ return !!parent.computed;
1742
+ }
1743
+ return true;
1744
+ }
1745
+ return true;
1746
+ }
1747
+ const TS_NODE_TYPES = [
1748
+ "TSAsExpression",
1749
+ // foo as number
1750
+ "TSTypeAssertion",
1751
+ // (<number>foo)
1752
+ "TSNonNullExpression",
1753
+ // foo!
1754
+ "TSInstantiationExpression",
1755
+ // foo<string>
1756
+ "TSSatisfiesExpression"
1757
+ // foo satisfies T
1758
+ ];
1759
+ function unwrapTSNode(node) {
1760
+ if (TS_NODE_TYPES.includes(node.type)) {
1761
+ return unwrapTSNode(node.expression);
1762
+ } else {
1763
+ return node;
1764
+ }
1765
+ }
1766
+
1299
1767
  const isStaticExp = (p) => p.type === 4 && p.isStatic;
1300
1768
  function isCoreComponent(tag) {
1301
1769
  switch (tag) {
@@ -1385,9 +1853,7 @@ const isMemberExpressionNode = (path, context) => {
1385
1853
  let ret = parser.parseExpression(path, {
1386
1854
  plugins: context.expressionPlugins
1387
1855
  });
1388
- if (ret.type === "TSAsExpression" || ret.type === "TSTypeAssertion") {
1389
- ret = ret.expression;
1390
- }
1856
+ ret = unwrapTSNode(ret);
1391
1857
  return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier";
1392
1858
  } catch (e) {
1393
1859
  return false;
@@ -1613,7 +2079,8 @@ const defaultParserOptions = {
1613
2079
  isCustomElement: shared.NO,
1614
2080
  onError: defaultOnError,
1615
2081
  onWarn: defaultOnWarn,
1616
- comments: true
2082
+ comments: true,
2083
+ prefixIdentifiers: false
1617
2084
  };
1618
2085
  let currentOptions = defaultParserOptions;
1619
2086
  let currentRoot = null;
@@ -1655,7 +2122,7 @@ const tokenizer = new Tokenizer(stack, {
1655
2122
  }
1656
2123
  addNode({
1657
2124
  type: 5,
1658
- content: createSimpleExpression(exp, false, getLoc(innerStart, innerEnd)),
2125
+ content: createExp(exp, false, getLoc(innerStart, innerEnd)),
1659
2126
  loc: getLoc(start, end)
1660
2127
  });
1661
2128
  },
@@ -1748,7 +2215,7 @@ const tokenizer = new Tokenizer(stack, {
1748
2215
  loc: getLoc(start)
1749
2216
  };
1750
2217
  if (name === "pre") {
1751
- inVPre = true;
2218
+ inVPre = tokenizer.inVPre = true;
1752
2219
  currentVPreBoundary = currentOpenTag;
1753
2220
  const props = currentOpenTag.props;
1754
2221
  for (let i = 0; i < props.length; i++) {
@@ -1768,7 +2235,7 @@ const tokenizer = new Tokenizer(stack, {
1768
2235
  setLocEnd(currentProp.nameLoc, end);
1769
2236
  } else {
1770
2237
  const isStatic = arg[0] !== `[`;
1771
- currentProp.arg = createSimpleExpression(
2238
+ currentProp.arg = createExp(
1772
2239
  isStatic ? arg : arg.slice(1, -1),
1773
2240
  isStatic,
1774
2241
  getLoc(start, end),
@@ -1835,10 +2302,22 @@ const tokenizer = new Tokenizer(stack, {
1835
2302
  tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
1836
2303
  }
1837
2304
  } else {
1838
- currentProp.exp = createSimpleExpression(
2305
+ let expParseMode = 0 /* Normal */;
2306
+ {
2307
+ if (currentProp.name === "for") {
2308
+ expParseMode = 3 /* Skip */;
2309
+ } else if (currentProp.name === "slot") {
2310
+ expParseMode = 1 /* Params */;
2311
+ } else if (currentProp.name === "on" && currentAttrValue.includes(";")) {
2312
+ expParseMode = 2 /* Statements */;
2313
+ }
2314
+ }
2315
+ currentProp.exp = createExp(
1839
2316
  currentAttrValue,
1840
2317
  false,
1841
- getLoc(currentAttrStartIndex, currentAttrEndIndex)
2318
+ getLoc(currentAttrStartIndex, currentAttrEndIndex),
2319
+ 0,
2320
+ expParseMode
1842
2321
  );
1843
2322
  if (currentProp.name === "for") {
1844
2323
  currentProp.forParseResult = parseForExpression(currentProp.exp);
@@ -1941,10 +2420,16 @@ function parseForExpression(input) {
1941
2420
  if (!inMatch)
1942
2421
  return;
1943
2422
  const [, LHS, RHS] = inMatch;
1944
- const createAliasExpression = (content, offset) => {
2423
+ const createAliasExpression = (content, offset, asParam = false) => {
1945
2424
  const start = loc.start.offset + offset;
1946
2425
  const end = start + content.length;
1947
- return createSimpleExpression(content, false, getLoc(start, end));
2426
+ return createExp(
2427
+ content,
2428
+ false,
2429
+ getLoc(start, end),
2430
+ 0,
2431
+ asParam ? 1 /* Params */ : 0 /* Normal */
2432
+ );
1948
2433
  };
1949
2434
  const result = {
1950
2435
  source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
@@ -1962,7 +2447,7 @@ function parseForExpression(input) {
1962
2447
  let keyOffset;
1963
2448
  if (keyContent) {
1964
2449
  keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
1965
- result.key = createAliasExpression(keyContent, keyOffset);
2450
+ result.key = createAliasExpression(keyContent, keyOffset, true);
1966
2451
  }
1967
2452
  if (iteratorMatch[2]) {
1968
2453
  const indexContent = iteratorMatch[2].trim();
@@ -1972,13 +2457,14 @@ function parseForExpression(input) {
1972
2457
  exp.indexOf(
1973
2458
  indexContent,
1974
2459
  result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
1975
- )
2460
+ ),
2461
+ true
1976
2462
  );
1977
2463
  }
1978
2464
  }
1979
2465
  }
1980
2466
  if (valueContent) {
1981
- result.value = createAliasExpression(valueContent, trimmedOffset);
2467
+ result.value = createAliasExpression(valueContent, trimmedOffset, true);
1982
2468
  }
1983
2469
  return result;
1984
2470
  }
@@ -2049,7 +2535,7 @@ function onCloseTag(el, end, isImplied = false) {
2049
2535
  inPre--;
2050
2536
  }
2051
2537
  if (currentVPreBoundary === el) {
2052
- inVPre = false;
2538
+ inVPre = tokenizer.inVPre = false;
2053
2539
  currentVPreBoundary = null;
2054
2540
  }
2055
2541
  if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
@@ -2284,8 +2770,36 @@ function dirToAttr(dir) {
2284
2770
  }
2285
2771
  return attr;
2286
2772
  }
2287
- function emitError(code, index) {
2288
- currentOptions.onError(createCompilerError(code, getLoc(index, index)));
2773
+ function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
2774
+ const exp = createSimpleExpression(content, isStatic, loc, constType);
2775
+ if (!isStatic && currentOptions.prefixIdentifiers && parseMode !== 3 /* Skip */ && content.trim()) {
2776
+ if (isSimpleIdentifier(content)) {
2777
+ exp.ast = null;
2778
+ return exp;
2779
+ }
2780
+ try {
2781
+ const plugins = currentOptions.expressionPlugins;
2782
+ const options = {
2783
+ plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
2784
+ };
2785
+ if (parseMode === 2 /* Statements */) {
2786
+ exp.ast = parser.parse(` ${content} `, options).program;
2787
+ } else if (parseMode === 1 /* Params */) {
2788
+ exp.ast = parser.parseExpression(`(${content})=>{}`, options);
2789
+ } else {
2790
+ exp.ast = parser.parseExpression(`(${content})`, options);
2791
+ }
2792
+ } catch (e) {
2793
+ exp.ast = false;
2794
+ emitError(45, loc.start.offset, e.message);
2795
+ }
2796
+ }
2797
+ return exp;
2798
+ }
2799
+ function emitError(code, index, message) {
2800
+ currentOptions.onError(
2801
+ createCompilerError(code, getLoc(index, index), void 0, message)
2802
+ );
2289
2803
  }
2290
2804
  function reset() {
2291
2805
  tokenizer.reset();
@@ -2316,6 +2830,7 @@ function baseParse(input, options) {
2316
2830
  }
2317
2831
  }
2318
2832
  tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
2833
+ tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
2319
2834
  const delimiters = options == null ? void 0 : options.delimiters;
2320
2835
  if (delimiters) {
2321
2836
  tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
@@ -2600,6 +3115,7 @@ function createTransformContext(root, {
2600
3115
  const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
2601
3116
  const context = {
2602
3117
  // options
3118
+ filename,
2603
3119
  selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
2604
3120
  prefixIdentifiers,
2605
3121
  hoistStatic: hoistStatic2,
@@ -3604,332 +4120,74 @@ function genCacheExpression(node, context) {
3604
4120
  push(`,`);
3605
4121
  newline();
3606
4122
  push(`${helper(SET_BLOCK_TRACKING)}(1),`);
3607
- newline();
3608
- push(`_cache[${node.index}]`);
3609
- deindent();
3610
- }
3611
- push(`)`);
3612
- }
3613
- function genTemplateLiteral(node, context) {
3614
- const { push, indent, deindent } = context;
3615
- push("`");
3616
- const l = node.elements.length;
3617
- const multilines = l > 3;
3618
- for (let i = 0; i < l; i++) {
3619
- const e = node.elements[i];
3620
- if (shared.isString(e)) {
3621
- push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
3622
- } else {
3623
- push("${");
3624
- if (multilines)
3625
- indent();
3626
- genNode(e, context);
3627
- if (multilines)
3628
- deindent();
3629
- push("}");
3630
- }
3631
- }
3632
- push("`");
3633
- }
3634
- function genIfStatement(node, context) {
3635
- const { push, indent, deindent } = context;
3636
- const { test, consequent, alternate } = node;
3637
- push(`if (`);
3638
- genNode(test, context);
3639
- push(`) {`);
3640
- indent();
3641
- genNode(consequent, context);
3642
- deindent();
3643
- push(`}`);
3644
- if (alternate) {
3645
- push(` else `);
3646
- if (alternate.type === 23) {
3647
- genIfStatement(alternate, context);
3648
- } else {
3649
- push(`{`);
3650
- indent();
3651
- genNode(alternate, context);
3652
- deindent();
3653
- push(`}`);
3654
- }
3655
- }
3656
- }
3657
- function genAssignmentExpression(node, context) {
3658
- genNode(node.left, context);
3659
- context.push(` = `);
3660
- genNode(node.right, context);
3661
- }
3662
- function genSequenceExpression(node, context) {
3663
- context.push(`(`);
3664
- genNodeList(node.expressions, context);
3665
- context.push(`)`);
3666
- }
3667
- function genReturnStatement({ returns }, context) {
3668
- context.push(`return `);
3669
- if (shared.isArray(returns)) {
3670
- genNodeListAsArray(returns, context);
3671
- } else {
3672
- genNode(returns, context);
3673
- }
3674
- }
3675
-
3676
- function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
3677
- const rootExp = root.type === "Program" && root.body[0].type === "ExpressionStatement" && root.body[0].expression;
3678
- estreeWalker.walk(root, {
3679
- enter(node, parent) {
3680
- parent && parentStack.push(parent);
3681
- if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
3682
- return this.skip();
3683
- }
3684
- if (node.type === "Identifier") {
3685
- const isLocal = !!knownIds[node.name];
3686
- const isRefed = isReferencedIdentifier(node, parent, parentStack);
3687
- if (includeAll || isRefed && !isLocal) {
3688
- onIdentifier(node, parent, parentStack, isRefed, isLocal);
3689
- }
3690
- } else if (node.type === "ObjectProperty" && parent.type === "ObjectPattern") {
3691
- node.inPattern = true;
3692
- } else if (isFunctionType(node)) {
3693
- walkFunctionParams(node, (id) => markScopeIdentifier(node, id, knownIds));
3694
- } else if (node.type === "BlockStatement") {
3695
- walkBlockDeclarations(
3696
- node,
3697
- (id) => markScopeIdentifier(node, id, knownIds)
3698
- );
3699
- }
3700
- },
3701
- leave(node, parent) {
3702
- parent && parentStack.pop();
3703
- if (node !== rootExp && node.scopeIds) {
3704
- for (const id of node.scopeIds) {
3705
- knownIds[id]--;
3706
- if (knownIds[id] === 0) {
3707
- delete knownIds[id];
3708
- }
3709
- }
3710
- }
3711
- }
3712
- });
3713
- }
3714
- function isReferencedIdentifier(id, parent, parentStack) {
3715
- if (!parent) {
3716
- return true;
3717
- }
3718
- if (id.name === "arguments") {
3719
- return false;
3720
- }
3721
- if (isReferenced(id, parent)) {
3722
- return true;
3723
- }
3724
- switch (parent.type) {
3725
- case "AssignmentExpression":
3726
- case "AssignmentPattern":
3727
- return true;
3728
- case "ObjectPattern":
3729
- case "ArrayPattern":
3730
- return isInDestructureAssignment(parent, parentStack);
3731
- }
3732
- return false;
3733
- }
3734
- function isInDestructureAssignment(parent, parentStack) {
3735
- if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
3736
- let i = parentStack.length;
3737
- while (i--) {
3738
- const p = parentStack[i];
3739
- if (p.type === "AssignmentExpression") {
3740
- return true;
3741
- } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
3742
- break;
3743
- }
3744
- }
4123
+ newline();
4124
+ push(`_cache[${node.index}]`);
4125
+ deindent();
3745
4126
  }
3746
- return false;
4127
+ push(`)`);
3747
4128
  }
3748
- function walkFunctionParams(node, onIdent) {
3749
- for (const p of node.params) {
3750
- for (const id of extractIdentifiers(p)) {
3751
- onIdent(id);
4129
+ function genTemplateLiteral(node, context) {
4130
+ const { push, indent, deindent } = context;
4131
+ push("`");
4132
+ const l = node.elements.length;
4133
+ const multilines = l > 3;
4134
+ for (let i = 0; i < l; i++) {
4135
+ const e = node.elements[i];
4136
+ if (shared.isString(e)) {
4137
+ push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
4138
+ } else {
4139
+ push("${");
4140
+ if (multilines)
4141
+ indent();
4142
+ genNode(e, context);
4143
+ if (multilines)
4144
+ deindent();
4145
+ push("}");
3752
4146
  }
3753
4147
  }
4148
+ push("`");
3754
4149
  }
3755
- function walkBlockDeclarations(block, onIdent) {
3756
- for (const stmt of block.body) {
3757
- if (stmt.type === "VariableDeclaration") {
3758
- if (stmt.declare)
3759
- continue;
3760
- for (const decl of stmt.declarations) {
3761
- for (const id of extractIdentifiers(decl.id)) {
3762
- onIdent(id);
3763
- }
3764
- }
3765
- } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
3766
- if (stmt.declare || !stmt.id)
3767
- continue;
3768
- onIdent(stmt.id);
3769
- } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
3770
- const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
3771
- if (variable && variable.type === "VariableDeclaration") {
3772
- for (const decl of variable.declarations) {
3773
- for (const id of extractIdentifiers(decl.id)) {
3774
- onIdent(id);
3775
- }
3776
- }
3777
- }
4150
+ function genIfStatement(node, context) {
4151
+ const { push, indent, deindent } = context;
4152
+ const { test, consequent, alternate } = node;
4153
+ push(`if (`);
4154
+ genNode(test, context);
4155
+ push(`) {`);
4156
+ indent();
4157
+ genNode(consequent, context);
4158
+ deindent();
4159
+ push(`}`);
4160
+ if (alternate) {
4161
+ push(` else `);
4162
+ if (alternate.type === 23) {
4163
+ genIfStatement(alternate, context);
4164
+ } else {
4165
+ push(`{`);
4166
+ indent();
4167
+ genNode(alternate, context);
4168
+ deindent();
4169
+ push(`}`);
3778
4170
  }
3779
4171
  }
3780
4172
  }
3781
- function extractIdentifiers(param, nodes = []) {
3782
- switch (param.type) {
3783
- case "Identifier":
3784
- nodes.push(param);
3785
- break;
3786
- case "MemberExpression":
3787
- let object = param;
3788
- while (object.type === "MemberExpression") {
3789
- object = object.object;
3790
- }
3791
- nodes.push(object);
3792
- break;
3793
- case "ObjectPattern":
3794
- for (const prop of param.properties) {
3795
- if (prop.type === "RestElement") {
3796
- extractIdentifiers(prop.argument, nodes);
3797
- } else {
3798
- extractIdentifiers(prop.value, nodes);
3799
- }
3800
- }
3801
- break;
3802
- case "ArrayPattern":
3803
- param.elements.forEach((element) => {
3804
- if (element)
3805
- extractIdentifiers(element, nodes);
3806
- });
3807
- break;
3808
- case "RestElement":
3809
- extractIdentifiers(param.argument, nodes);
3810
- break;
3811
- case "AssignmentPattern":
3812
- extractIdentifiers(param.left, nodes);
3813
- break;
3814
- }
3815
- return nodes;
4173
+ function genAssignmentExpression(node, context) {
4174
+ genNode(node.left, context);
4175
+ context.push(` = `);
4176
+ genNode(node.right, context);
3816
4177
  }
3817
- function markScopeIdentifier(node, child, knownIds) {
3818
- const { name } = child;
3819
- if (node.scopeIds && node.scopeIds.has(name)) {
3820
- return;
3821
- }
3822
- if (name in knownIds) {
3823
- knownIds[name]++;
3824
- } else {
3825
- knownIds[name] = 1;
3826
- }
3827
- (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
4178
+ function genSequenceExpression(node, context) {
4179
+ context.push(`(`);
4180
+ genNodeList(node.expressions, context);
4181
+ context.push(`)`);
3828
4182
  }
3829
- const isFunctionType = (node) => {
3830
- return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
3831
- };
3832
- const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
3833
- const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
3834
- function isReferenced(node, parent, grandparent) {
3835
- switch (parent.type) {
3836
- case "MemberExpression":
3837
- case "OptionalMemberExpression":
3838
- if (parent.property === node) {
3839
- return !!parent.computed;
3840
- }
3841
- return parent.object === node;
3842
- case "JSXMemberExpression":
3843
- return parent.object === node;
3844
- case "VariableDeclarator":
3845
- return parent.init === node;
3846
- case "ArrowFunctionExpression":
3847
- return parent.body === node;
3848
- case "PrivateName":
3849
- return false;
3850
- case "ClassMethod":
3851
- case "ClassPrivateMethod":
3852
- case "ObjectMethod":
3853
- if (parent.key === node) {
3854
- return !!parent.computed;
3855
- }
3856
- return false;
3857
- case "ObjectProperty":
3858
- if (parent.key === node) {
3859
- return !!parent.computed;
3860
- }
3861
- return !grandparent || grandparent.type !== "ObjectPattern";
3862
- case "ClassProperty":
3863
- if (parent.key === node) {
3864
- return !!parent.computed;
3865
- }
3866
- return true;
3867
- case "ClassPrivateProperty":
3868
- return parent.key !== node;
3869
- case "ClassDeclaration":
3870
- case "ClassExpression":
3871
- return parent.superClass === node;
3872
- case "AssignmentExpression":
3873
- return parent.right === node;
3874
- case "AssignmentPattern":
3875
- return parent.right === node;
3876
- case "LabeledStatement":
3877
- return false;
3878
- case "CatchClause":
3879
- return false;
3880
- case "RestElement":
3881
- return false;
3882
- case "BreakStatement":
3883
- case "ContinueStatement":
3884
- return false;
3885
- case "FunctionDeclaration":
3886
- case "FunctionExpression":
3887
- return false;
3888
- case "ExportNamespaceSpecifier":
3889
- case "ExportDefaultSpecifier":
3890
- return false;
3891
- case "ExportSpecifier":
3892
- if (grandparent == null ? void 0 : grandparent.source) {
3893
- return false;
3894
- }
3895
- return parent.local === node;
3896
- case "ImportDefaultSpecifier":
3897
- case "ImportNamespaceSpecifier":
3898
- case "ImportSpecifier":
3899
- return false;
3900
- case "ImportAttribute":
3901
- return false;
3902
- case "JSXAttribute":
3903
- return false;
3904
- case "ObjectPattern":
3905
- case "ArrayPattern":
3906
- return false;
3907
- case "MetaProperty":
3908
- return false;
3909
- case "ObjectTypeProperty":
3910
- return parent.key !== node;
3911
- case "TSEnumMember":
3912
- return parent.id !== node;
3913
- case "TSPropertySignature":
3914
- if (parent.key === node) {
3915
- return !!parent.computed;
3916
- }
3917
- return true;
4183
+ function genReturnStatement({ returns }, context) {
4184
+ context.push(`return `);
4185
+ if (shared.isArray(returns)) {
4186
+ genNodeListAsArray(returns, context);
4187
+ } else {
4188
+ genNode(returns, context);
3918
4189
  }
3919
- return true;
3920
4190
  }
3921
- const TS_NODE_TYPES = [
3922
- "TSAsExpression",
3923
- // foo as number
3924
- "TSTypeAssertion",
3925
- // (<number>foo)
3926
- "TSNonNullExpression",
3927
- // foo!
3928
- "TSInstantiationExpression",
3929
- // foo<string>
3930
- "TSSatisfiesExpression"
3931
- // foo satisfies T
3932
- ];
3933
4191
 
3934
4192
  const isLiteralWhitelisted = /* @__PURE__ */ shared.makeMap("true,false,null,this");
3935
4193
  const constantBailRE = /\w\s*\(|\.[^\d]/;
@@ -4023,7 +4281,11 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
4023
4281
  };
4024
4282
  const rawExp = node.content;
4025
4283
  const bailConstant = constantBailRE.test(rawExp);
4026
- if (isSimpleIdentifier(rawExp)) {
4284
+ let ast = node.ast;
4285
+ if (ast === false) {
4286
+ return node;
4287
+ }
4288
+ if (ast === null || !ast && isSimpleIdentifier(rawExp)) {
4027
4289
  const isScopeVarReference = context.identifiers[rawExp];
4028
4290
  const isAllowedGlobal = shared.isGloballyAllowed(rawExp);
4029
4291
  const isLiteral = isLiteralWhitelisted(rawExp);
@@ -4041,22 +4303,23 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
4041
4303
  }
4042
4304
  return node;
4043
4305
  }
4044
- let ast;
4045
- const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
4046
- try {
4047
- ast = parser.parse(source, {
4048
- plugins: context.expressionPlugins
4049
- }).program;
4050
- } catch (e) {
4051
- context.onError(
4052
- createCompilerError(
4053
- 45,
4054
- node.loc,
4055
- void 0,
4056
- e.message
4057
- )
4058
- );
4059
- return node;
4306
+ if (!ast) {
4307
+ const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
4308
+ try {
4309
+ ast = parser.parse(source, {
4310
+ plugins: context.expressionPlugins
4311
+ }).program;
4312
+ } catch (e) {
4313
+ context.onError(
4314
+ createCompilerError(
4315
+ 45,
4316
+ node.loc,
4317
+ void 0,
4318
+ e.message
4319
+ )
4320
+ );
4321
+ return node;
4322
+ }
4060
4323
  }
4061
4324
  const ids = [];
4062
4325
  const parentStack = [];
@@ -4099,15 +4362,15 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
4099
4362
  if (leadingText.length || id.prefix) {
4100
4363
  children.push(leadingText + (id.prefix || ``));
4101
4364
  }
4102
- const source2 = rawExp.slice(start, end);
4365
+ const source = rawExp.slice(start, end);
4103
4366
  children.push(
4104
4367
  createSimpleExpression(
4105
4368
  id.name,
4106
4369
  false,
4107
4370
  {
4108
- start: advancePositionWithClone(node.loc.start, source2, start),
4109
- end: advancePositionWithClone(node.loc.start, source2, end),
4110
- source: source2
4371
+ start: advancePositionWithClone(node.loc.start, source, start),
4372
+ end: advancePositionWithClone(node.loc.start, source, end),
4373
+ source
4111
4374
  },
4112
4375
  id.isConstant ? 3 : 0
4113
4376
  )
@@ -4119,6 +4382,7 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
4119
4382
  let ret;
4120
4383
  if (children.length) {
4121
4384
  ret = createCompoundExpression(children, node.loc);
4385
+ ret.ast = ast;
4122
4386
  } else {
4123
4387
  ret = node;
4124
4388
  ret.constType = bailConstant ? 0 : 3;
@@ -5078,6 +5342,10 @@ function resolveSetupReference(name, context) {
5078
5342
  `${context.helperString(UNREF)}(${fromMaybeRef})`
5079
5343
  ) : `$setup[${JSON.stringify(fromMaybeRef)}]`;
5080
5344
  }
5345
+ const fromProps = checkType("props");
5346
+ if (fromProps) {
5347
+ return `${context.helperString(UNREF)}(${context.inline ? "__props" : "$props"}[${JSON.stringify(fromProps)}])`;
5348
+ }
5081
5349
  }
5082
5350
  function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
5083
5351
  const { tag, loc: elementLoc, children } = node;
@@ -5118,6 +5386,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
5118
5386
  if (isEventHandler && shared.isReservedProp(name)) {
5119
5387
  hasVnodeHook = true;
5120
5388
  }
5389
+ if (isEventHandler && value.type === 14) {
5390
+ value = value.arguments[0];
5391
+ }
5121
5392
  if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
5122
5393
  return;
5123
5394
  }
@@ -5585,9 +5856,7 @@ const transformOn = (dir, node, context, augmentor) => {
5585
5856
  if (arg.isStatic) {
5586
5857
  let rawName = arg.content;
5587
5858
  if (rawName.startsWith("vnode")) {
5588
- context.onWarn(
5589
- createCompilerError(51, arg.loc)
5590
- );
5859
+ context.onError(createCompilerError(51, arg.loc));
5591
5860
  }
5592
5861
  if (rawName.startsWith("vue:")) {
5593
5862
  rawName = `vnode-${rawName.slice(4)}`;
@@ -6126,7 +6395,10 @@ function baseCompile(source, options = {}) {
6126
6395
  if (options.scopeId && !isModuleMode) {
6127
6396
  onError(createCompilerError(50));
6128
6397
  }
6129
- const ast = shared.isString(source) ? baseParse(source, options) : source;
6398
+ const resolvedOptions = shared.extend({}, options, {
6399
+ prefixIdentifiers
6400
+ });
6401
+ const ast = shared.isString(source) ? baseParse(source, resolvedOptions) : source;
6130
6402
  const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
6131
6403
  if (options.isTS) {
6132
6404
  const { expressionPlugins } = options;
@@ -6136,8 +6408,7 @@ function baseCompile(source, options = {}) {
6136
6408
  }
6137
6409
  transform(
6138
6410
  ast,
6139
- shared.extend({}, options, {
6140
- prefixIdentifiers,
6411
+ shared.extend({}, resolvedOptions, {
6141
6412
  nodeTransforms: [
6142
6413
  ...nodeTransforms,
6143
6414
  ...options.nodeTransforms || []
@@ -6151,18 +6422,27 @@ function baseCompile(source, options = {}) {
6151
6422
  )
6152
6423
  })
6153
6424
  );
6154
- return generate(
6155
- ast,
6156
- shared.extend({}, options, {
6157
- prefixIdentifiers
6158
- })
6159
- );
6425
+ return generate(ast, resolvedOptions);
6160
6426
  }
6161
6427
 
6428
+ const BindingTypes = {
6429
+ "DATA": "data",
6430
+ "PROPS": "props",
6431
+ "PROPS_ALIASED": "props-aliased",
6432
+ "SETUP_LET": "setup-let",
6433
+ "SETUP_CONST": "setup-const",
6434
+ "SETUP_REACTIVE_CONST": "setup-reactive-const",
6435
+ "SETUP_MAYBE_REF": "setup-maybe-ref",
6436
+ "SETUP_REF": "setup-ref",
6437
+ "OPTIONS": "options",
6438
+ "LITERAL_CONST": "literal-const"
6439
+ };
6440
+
6162
6441
  const noopDirectiveTransform = () => ({ props: [] });
6163
6442
 
6164
6443
  exports.generateCodeFrame = shared.generateCodeFrame;
6165
6444
  exports.BASE_TRANSITION = BASE_TRANSITION;
6445
+ exports.BindingTypes = BindingTypes;
6166
6446
  exports.CAMELIZE = CAMELIZE;
6167
6447
  exports.CAPITALIZE = CAPITALIZE;
6168
6448
  exports.CREATE_BLOCK = CREATE_BLOCK;
@@ -6173,6 +6453,10 @@ exports.CREATE_SLOTS = CREATE_SLOTS;
6173
6453
  exports.CREATE_STATIC = CREATE_STATIC;
6174
6454
  exports.CREATE_TEXT = CREATE_TEXT;
6175
6455
  exports.CREATE_VNODE = CREATE_VNODE;
6456
+ exports.CompilerDeprecationTypes = CompilerDeprecationTypes;
6457
+ exports.ConstantTypes = ConstantTypes;
6458
+ exports.ElementTypes = ElementTypes;
6459
+ exports.ErrorCodes = ErrorCodes;
6176
6460
  exports.FRAGMENT = FRAGMENT;
6177
6461
  exports.GUARD_REACTIVE_PROPS = GUARD_REACTIVE_PROPS;
6178
6462
  exports.IS_MEMO_SAME = IS_MEMO_SAME;
@@ -6182,6 +6466,8 @@ exports.MERGE_PROPS = MERGE_PROPS;
6182
6466
  exports.NORMALIZE_CLASS = NORMALIZE_CLASS;
6183
6467
  exports.NORMALIZE_PROPS = NORMALIZE_PROPS;
6184
6468
  exports.NORMALIZE_STYLE = NORMALIZE_STYLE;
6469
+ exports.Namespaces = Namespaces;
6470
+ exports.NodeTypes = NodeTypes;
6185
6471
  exports.OPEN_BLOCK = OPEN_BLOCK;
6186
6472
  exports.POP_SCOPE_ID = POP_SCOPE_ID;
6187
6473
  exports.PUSH_SCOPE_ID = PUSH_SCOPE_ID;
@@ -6284,6 +6570,7 @@ exports.transformExpression = transformExpression;
6284
6570
  exports.transformModel = transformModel;
6285
6571
  exports.transformOn = transformOn;
6286
6572
  exports.traverseNode = traverseNode;
6573
+ exports.unwrapTSNode = unwrapTSNode;
6287
6574
  exports.walkBlockDeclarations = walkBlockDeclarations;
6288
6575
  exports.walkFunctionParams = walkFunctionParams;
6289
6576
  exports.walkIdentifiers = walkIdentifiers;