@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.
@@ -89,6 +89,90 @@ function registerRuntimeHelpers(helpers) {
89
89
  });
90
90
  }
91
91
 
92
+ const Namespaces = {
93
+ "HTML": 0,
94
+ "0": "HTML",
95
+ "SVG": 1,
96
+ "1": "SVG",
97
+ "MATH_ML": 2,
98
+ "2": "MATH_ML"
99
+ };
100
+ const NodeTypes = {
101
+ "ROOT": 0,
102
+ "0": "ROOT",
103
+ "ELEMENT": 1,
104
+ "1": "ELEMENT",
105
+ "TEXT": 2,
106
+ "2": "TEXT",
107
+ "COMMENT": 3,
108
+ "3": "COMMENT",
109
+ "SIMPLE_EXPRESSION": 4,
110
+ "4": "SIMPLE_EXPRESSION",
111
+ "INTERPOLATION": 5,
112
+ "5": "INTERPOLATION",
113
+ "ATTRIBUTE": 6,
114
+ "6": "ATTRIBUTE",
115
+ "DIRECTIVE": 7,
116
+ "7": "DIRECTIVE",
117
+ "COMPOUND_EXPRESSION": 8,
118
+ "8": "COMPOUND_EXPRESSION",
119
+ "IF": 9,
120
+ "9": "IF",
121
+ "IF_BRANCH": 10,
122
+ "10": "IF_BRANCH",
123
+ "FOR": 11,
124
+ "11": "FOR",
125
+ "TEXT_CALL": 12,
126
+ "12": "TEXT_CALL",
127
+ "VNODE_CALL": 13,
128
+ "13": "VNODE_CALL",
129
+ "JS_CALL_EXPRESSION": 14,
130
+ "14": "JS_CALL_EXPRESSION",
131
+ "JS_OBJECT_EXPRESSION": 15,
132
+ "15": "JS_OBJECT_EXPRESSION",
133
+ "JS_PROPERTY": 16,
134
+ "16": "JS_PROPERTY",
135
+ "JS_ARRAY_EXPRESSION": 17,
136
+ "17": "JS_ARRAY_EXPRESSION",
137
+ "JS_FUNCTION_EXPRESSION": 18,
138
+ "18": "JS_FUNCTION_EXPRESSION",
139
+ "JS_CONDITIONAL_EXPRESSION": 19,
140
+ "19": "JS_CONDITIONAL_EXPRESSION",
141
+ "JS_CACHE_EXPRESSION": 20,
142
+ "20": "JS_CACHE_EXPRESSION",
143
+ "JS_BLOCK_STATEMENT": 21,
144
+ "21": "JS_BLOCK_STATEMENT",
145
+ "JS_TEMPLATE_LITERAL": 22,
146
+ "22": "JS_TEMPLATE_LITERAL",
147
+ "JS_IF_STATEMENT": 23,
148
+ "23": "JS_IF_STATEMENT",
149
+ "JS_ASSIGNMENT_EXPRESSION": 24,
150
+ "24": "JS_ASSIGNMENT_EXPRESSION",
151
+ "JS_SEQUENCE_EXPRESSION": 25,
152
+ "25": "JS_SEQUENCE_EXPRESSION",
153
+ "JS_RETURN_STATEMENT": 26,
154
+ "26": "JS_RETURN_STATEMENT"
155
+ };
156
+ const ElementTypes = {
157
+ "ELEMENT": 0,
158
+ "0": "ELEMENT",
159
+ "COMPONENT": 1,
160
+ "1": "COMPONENT",
161
+ "SLOT": 2,
162
+ "2": "SLOT",
163
+ "TEMPLATE": 3,
164
+ "3": "TEMPLATE"
165
+ };
166
+ const ConstantTypes = {
167
+ "NOT_CONSTANT": 0,
168
+ "0": "NOT_CONSTANT",
169
+ "CAN_SKIP_PATCH": 1,
170
+ "1": "CAN_SKIP_PATCH",
171
+ "CAN_HOIST": 2,
172
+ "2": "CAN_HOIST",
173
+ "CAN_STRINGIFY": 3,
174
+ "3": "CAN_STRINGIFY"
175
+ };
92
176
  const locStub = {
93
177
  start: { line: 1, column: 1, offset: 0 },
94
178
  end: { line: 1, column: 1, offset: 0 },
@@ -343,7 +427,9 @@ class Tokenizer {
343
427
  this.inRCDATA = false;
344
428
  /** For disabling RCDATA tags handling */
345
429
  this.inXML = false;
346
- /** Reocrd newline positions for fast line / column calculation */
430
+ /** For disabling interpolation parsing in v-pre */
431
+ this.inVPre = false;
432
+ /** Record newline positions for fast line / column calculation */
347
433
  this.newlines = [];
348
434
  this.mode = 0;
349
435
  this.delimiterOpen = defaultDelimitersOpen;
@@ -362,6 +448,7 @@ class Tokenizer {
362
448
  this.sectionStart = 0;
363
449
  this.index = 0;
364
450
  this.baseState = 1;
451
+ this.inRCDATA = false;
365
452
  this.currentSequence = void 0;
366
453
  this.newlines.length = 0;
367
454
  this.delimiterOpen = defaultDelimitersOpen;
@@ -400,7 +487,7 @@ class Tokenizer {
400
487
  }
401
488
  this.state = 5;
402
489
  this.sectionStart = this.index;
403
- } else if (c === this.delimiterOpen[0]) {
490
+ } else if (!this.inVPre && c === this.delimiterOpen[0]) {
404
491
  this.state = 2;
405
492
  this.delimiterIndex = 0;
406
493
  this.stateInterpolationOpen(c);
@@ -1082,6 +1169,16 @@ class Tokenizer {
1082
1169
  }
1083
1170
  }
1084
1171
 
1172
+ const CompilerDeprecationTypes = {
1173
+ "COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT",
1174
+ "COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC",
1175
+ "COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER",
1176
+ "COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE",
1177
+ "COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE",
1178
+ "COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE",
1179
+ "COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE",
1180
+ "COMPILER_FILTERS": "COMPILER_FILTER"
1181
+ };
1085
1182
  const deprecationData = {
1086
1183
  ["COMPILER_IS_ON_ELEMENT"]: {
1087
1184
  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:".`,
@@ -1163,6 +1260,114 @@ function createCompilerError(code, loc, messages, additionalMessage) {
1163
1260
  error.loc = loc;
1164
1261
  return error;
1165
1262
  }
1263
+ const ErrorCodes = {
1264
+ "ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
1265
+ "0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
1266
+ "CDATA_IN_HTML_CONTENT": 1,
1267
+ "1": "CDATA_IN_HTML_CONTENT",
1268
+ "DUPLICATE_ATTRIBUTE": 2,
1269
+ "2": "DUPLICATE_ATTRIBUTE",
1270
+ "END_TAG_WITH_ATTRIBUTES": 3,
1271
+ "3": "END_TAG_WITH_ATTRIBUTES",
1272
+ "END_TAG_WITH_TRAILING_SOLIDUS": 4,
1273
+ "4": "END_TAG_WITH_TRAILING_SOLIDUS",
1274
+ "EOF_BEFORE_TAG_NAME": 5,
1275
+ "5": "EOF_BEFORE_TAG_NAME",
1276
+ "EOF_IN_CDATA": 6,
1277
+ "6": "EOF_IN_CDATA",
1278
+ "EOF_IN_COMMENT": 7,
1279
+ "7": "EOF_IN_COMMENT",
1280
+ "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
1281
+ "8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
1282
+ "EOF_IN_TAG": 9,
1283
+ "9": "EOF_IN_TAG",
1284
+ "INCORRECTLY_CLOSED_COMMENT": 10,
1285
+ "10": "INCORRECTLY_CLOSED_COMMENT",
1286
+ "INCORRECTLY_OPENED_COMMENT": 11,
1287
+ "11": "INCORRECTLY_OPENED_COMMENT",
1288
+ "INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
1289
+ "12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
1290
+ "MISSING_ATTRIBUTE_VALUE": 13,
1291
+ "13": "MISSING_ATTRIBUTE_VALUE",
1292
+ "MISSING_END_TAG_NAME": 14,
1293
+ "14": "MISSING_END_TAG_NAME",
1294
+ "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
1295
+ "15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
1296
+ "NESTED_COMMENT": 16,
1297
+ "16": "NESTED_COMMENT",
1298
+ "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
1299
+ "17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
1300
+ "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
1301
+ "18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
1302
+ "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
1303
+ "19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
1304
+ "UNEXPECTED_NULL_CHARACTER": 20,
1305
+ "20": "UNEXPECTED_NULL_CHARACTER",
1306
+ "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
1307
+ "21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
1308
+ "UNEXPECTED_SOLIDUS_IN_TAG": 22,
1309
+ "22": "UNEXPECTED_SOLIDUS_IN_TAG",
1310
+ "X_INVALID_END_TAG": 23,
1311
+ "23": "X_INVALID_END_TAG",
1312
+ "X_MISSING_END_TAG": 24,
1313
+ "24": "X_MISSING_END_TAG",
1314
+ "X_MISSING_INTERPOLATION_END": 25,
1315
+ "25": "X_MISSING_INTERPOLATION_END",
1316
+ "X_MISSING_DIRECTIVE_NAME": 26,
1317
+ "26": "X_MISSING_DIRECTIVE_NAME",
1318
+ "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
1319
+ "27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
1320
+ "X_V_IF_NO_EXPRESSION": 28,
1321
+ "28": "X_V_IF_NO_EXPRESSION",
1322
+ "X_V_IF_SAME_KEY": 29,
1323
+ "29": "X_V_IF_SAME_KEY",
1324
+ "X_V_ELSE_NO_ADJACENT_IF": 30,
1325
+ "30": "X_V_ELSE_NO_ADJACENT_IF",
1326
+ "X_V_FOR_NO_EXPRESSION": 31,
1327
+ "31": "X_V_FOR_NO_EXPRESSION",
1328
+ "X_V_FOR_MALFORMED_EXPRESSION": 32,
1329
+ "32": "X_V_FOR_MALFORMED_EXPRESSION",
1330
+ "X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
1331
+ "33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
1332
+ "X_V_BIND_NO_EXPRESSION": 34,
1333
+ "34": "X_V_BIND_NO_EXPRESSION",
1334
+ "X_V_ON_NO_EXPRESSION": 35,
1335
+ "35": "X_V_ON_NO_EXPRESSION",
1336
+ "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
1337
+ "36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
1338
+ "X_V_SLOT_MIXED_SLOT_USAGE": 37,
1339
+ "37": "X_V_SLOT_MIXED_SLOT_USAGE",
1340
+ "X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
1341
+ "38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
1342
+ "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
1343
+ "39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
1344
+ "X_V_SLOT_MISPLACED": 40,
1345
+ "40": "X_V_SLOT_MISPLACED",
1346
+ "X_V_MODEL_NO_EXPRESSION": 41,
1347
+ "41": "X_V_MODEL_NO_EXPRESSION",
1348
+ "X_V_MODEL_MALFORMED_EXPRESSION": 42,
1349
+ "42": "X_V_MODEL_MALFORMED_EXPRESSION",
1350
+ "X_V_MODEL_ON_SCOPE_VARIABLE": 43,
1351
+ "43": "X_V_MODEL_ON_SCOPE_VARIABLE",
1352
+ "X_V_MODEL_ON_PROPS": 44,
1353
+ "44": "X_V_MODEL_ON_PROPS",
1354
+ "X_INVALID_EXPRESSION": 45,
1355
+ "45": "X_INVALID_EXPRESSION",
1356
+ "X_KEEP_ALIVE_INVALID_CHILDREN": 46,
1357
+ "46": "X_KEEP_ALIVE_INVALID_CHILDREN",
1358
+ "X_PREFIX_ID_NOT_SUPPORTED": 47,
1359
+ "47": "X_PREFIX_ID_NOT_SUPPORTED",
1360
+ "X_MODULE_MODE_NOT_SUPPORTED": 48,
1361
+ "48": "X_MODULE_MODE_NOT_SUPPORTED",
1362
+ "X_CACHE_HANDLER_NOT_SUPPORTED": 49,
1363
+ "49": "X_CACHE_HANDLER_NOT_SUPPORTED",
1364
+ "X_SCOPE_ID_NOT_SUPPORTED": 50,
1365
+ "50": "X_SCOPE_ID_NOT_SUPPORTED",
1366
+ "X_VNODE_HOOKS": 51,
1367
+ "51": "X_VNODE_HOOKS",
1368
+ "__EXTEND_POINT__": 52,
1369
+ "52": "__EXTEND_POINT__"
1370
+ };
1166
1371
  const errorMessages = {
1167
1372
  // parse errors
1168
1373
  [0]: "Illegal comment.",
@@ -1215,17 +1420,133 @@ const errorMessages = {
1215
1420
  Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
1216
1421
  [45]: `Error parsing JavaScript expression: `,
1217
1422
  [46]: `<KeepAlive> expects exactly one child component.`,
1423
+ [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.`,
1218
1424
  // generic errors
1219
1425
  [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
1220
1426
  [48]: `ES module mode is not supported in this build of compiler.`,
1221
1427
  [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
1222
1428
  [50]: `"scopeId" option is only supported in module mode.`,
1223
- // deprecations
1224
- [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.`,
1225
- [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
1226
1429
  // just to fulfill types
1227
- [53]: ``
1430
+ [52]: ``
1431
+ };
1432
+
1433
+ function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
1434
+ {
1435
+ return;
1436
+ }
1437
+ }
1438
+ function isReferencedIdentifier(id, parent, parentStack) {
1439
+ {
1440
+ return false;
1441
+ }
1442
+ }
1443
+ function isInDestructureAssignment(parent, parentStack) {
1444
+ if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
1445
+ let i = parentStack.length;
1446
+ while (i--) {
1447
+ const p = parentStack[i];
1448
+ if (p.type === "AssignmentExpression") {
1449
+ return true;
1450
+ } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
1451
+ break;
1452
+ }
1453
+ }
1454
+ }
1455
+ return false;
1456
+ }
1457
+ function walkFunctionParams(node, onIdent) {
1458
+ for (const p of node.params) {
1459
+ for (const id of extractIdentifiers(p)) {
1460
+ onIdent(id);
1461
+ }
1462
+ }
1463
+ }
1464
+ function walkBlockDeclarations(block, onIdent) {
1465
+ for (const stmt of block.body) {
1466
+ if (stmt.type === "VariableDeclaration") {
1467
+ if (stmt.declare)
1468
+ continue;
1469
+ for (const decl of stmt.declarations) {
1470
+ for (const id of extractIdentifiers(decl.id)) {
1471
+ onIdent(id);
1472
+ }
1473
+ }
1474
+ } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
1475
+ if (stmt.declare || !stmt.id)
1476
+ continue;
1477
+ onIdent(stmt.id);
1478
+ } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
1479
+ const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
1480
+ if (variable && variable.type === "VariableDeclaration") {
1481
+ for (const decl of variable.declarations) {
1482
+ for (const id of extractIdentifiers(decl.id)) {
1483
+ onIdent(id);
1484
+ }
1485
+ }
1486
+ }
1487
+ }
1488
+ }
1489
+ }
1490
+ function extractIdentifiers(param, nodes = []) {
1491
+ switch (param.type) {
1492
+ case "Identifier":
1493
+ nodes.push(param);
1494
+ break;
1495
+ case "MemberExpression":
1496
+ let object = param;
1497
+ while (object.type === "MemberExpression") {
1498
+ object = object.object;
1499
+ }
1500
+ nodes.push(object);
1501
+ break;
1502
+ case "ObjectPattern":
1503
+ for (const prop of param.properties) {
1504
+ if (prop.type === "RestElement") {
1505
+ extractIdentifiers(prop.argument, nodes);
1506
+ } else {
1507
+ extractIdentifiers(prop.value, nodes);
1508
+ }
1509
+ }
1510
+ break;
1511
+ case "ArrayPattern":
1512
+ param.elements.forEach((element) => {
1513
+ if (element)
1514
+ extractIdentifiers(element, nodes);
1515
+ });
1516
+ break;
1517
+ case "RestElement":
1518
+ extractIdentifiers(param.argument, nodes);
1519
+ break;
1520
+ case "AssignmentPattern":
1521
+ extractIdentifiers(param.left, nodes);
1522
+ break;
1523
+ }
1524
+ return nodes;
1525
+ }
1526
+ const isFunctionType = (node) => {
1527
+ return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
1228
1528
  };
1529
+ const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
1530
+ const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
1531
+ const TS_NODE_TYPES = [
1532
+ "TSAsExpression",
1533
+ // foo as number
1534
+ "TSTypeAssertion",
1535
+ // (<number>foo)
1536
+ "TSNonNullExpression",
1537
+ // foo!
1538
+ "TSInstantiationExpression",
1539
+ // foo<string>
1540
+ "TSSatisfiesExpression"
1541
+ // foo satisfies T
1542
+ ];
1543
+ function unwrapTSNode(node) {
1544
+ if (TS_NODE_TYPES.includes(node.type)) {
1545
+ return unwrapTSNode(node.expression);
1546
+ } else {
1547
+ return node;
1548
+ }
1549
+ }
1229
1550
 
1230
1551
  const isStaticExp = (p) => p.type === 4 && p.isStatic;
1231
1552
  function isCoreComponent(tag) {
@@ -1533,7 +1854,8 @@ const defaultParserOptions = {
1533
1854
  isCustomElement: NO,
1534
1855
  onError: defaultOnError,
1535
1856
  onWarn: defaultOnWarn,
1536
- comments: !!(process.env.NODE_ENV !== "production")
1857
+ comments: !!(process.env.NODE_ENV !== "production"),
1858
+ prefixIdentifiers: false
1537
1859
  };
1538
1860
  let currentOptions = defaultParserOptions;
1539
1861
  let currentRoot = null;
@@ -1575,7 +1897,7 @@ const tokenizer = new Tokenizer(stack, {
1575
1897
  }
1576
1898
  addNode({
1577
1899
  type: 5,
1578
- content: createSimpleExpression(exp, false, getLoc(innerStart, innerEnd)),
1900
+ content: createExp(exp, false, getLoc(innerStart, innerEnd)),
1579
1901
  loc: getLoc(start, end)
1580
1902
  });
1581
1903
  },
@@ -1668,7 +1990,7 @@ const tokenizer = new Tokenizer(stack, {
1668
1990
  loc: getLoc(start)
1669
1991
  };
1670
1992
  if (name === "pre") {
1671
- inVPre = true;
1993
+ inVPre = tokenizer.inVPre = true;
1672
1994
  currentVPreBoundary = currentOpenTag;
1673
1995
  const props = currentOpenTag.props;
1674
1996
  for (let i = 0; i < props.length; i++) {
@@ -1688,7 +2010,7 @@ const tokenizer = new Tokenizer(stack, {
1688
2010
  setLocEnd(currentProp.nameLoc, end);
1689
2011
  } else {
1690
2012
  const isStatic = arg[0] !== `[`;
1691
- currentProp.arg = createSimpleExpression(
2013
+ currentProp.arg = createExp(
1692
2014
  isStatic ? arg : arg.slice(1, -1),
1693
2015
  isStatic,
1694
2016
  getLoc(start, end),
@@ -1761,10 +2083,13 @@ const tokenizer = new Tokenizer(stack, {
1761
2083
  tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
1762
2084
  }
1763
2085
  } else {
1764
- currentProp.exp = createSimpleExpression(
2086
+ let expParseMode = 0 /* Normal */;
2087
+ currentProp.exp = createExp(
1765
2088
  currentAttrValue,
1766
2089
  false,
1767
- getLoc(currentAttrStartIndex, currentAttrEndIndex)
2090
+ getLoc(currentAttrStartIndex, currentAttrEndIndex),
2091
+ 0,
2092
+ expParseMode
1768
2093
  );
1769
2094
  if (currentProp.name === "for") {
1770
2095
  currentProp.forParseResult = parseForExpression(currentProp.exp);
@@ -1867,10 +2192,16 @@ function parseForExpression(input) {
1867
2192
  if (!inMatch)
1868
2193
  return;
1869
2194
  const [, LHS, RHS] = inMatch;
1870
- const createAliasExpression = (content, offset) => {
2195
+ const createAliasExpression = (content, offset, asParam = false) => {
1871
2196
  const start = loc.start.offset + offset;
1872
2197
  const end = start + content.length;
1873
- return createSimpleExpression(content, false, getLoc(start, end));
2198
+ return createExp(
2199
+ content,
2200
+ false,
2201
+ getLoc(start, end),
2202
+ 0,
2203
+ asParam ? 1 /* Params */ : 0 /* Normal */
2204
+ );
1874
2205
  };
1875
2206
  const result = {
1876
2207
  source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
@@ -1888,7 +2219,7 @@ function parseForExpression(input) {
1888
2219
  let keyOffset;
1889
2220
  if (keyContent) {
1890
2221
  keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
1891
- result.key = createAliasExpression(keyContent, keyOffset);
2222
+ result.key = createAliasExpression(keyContent, keyOffset, true);
1892
2223
  }
1893
2224
  if (iteratorMatch[2]) {
1894
2225
  const indexContent = iteratorMatch[2].trim();
@@ -1898,13 +2229,14 @@ function parseForExpression(input) {
1898
2229
  exp.indexOf(
1899
2230
  indexContent,
1900
2231
  result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
1901
- )
2232
+ ),
2233
+ true
1902
2234
  );
1903
2235
  }
1904
2236
  }
1905
2237
  }
1906
2238
  if (valueContent) {
1907
- result.value = createAliasExpression(valueContent, trimmedOffset);
2239
+ result.value = createAliasExpression(valueContent, trimmedOffset, true);
1908
2240
  }
1909
2241
  return result;
1910
2242
  }
@@ -1982,7 +2314,7 @@ function onCloseTag(el, end, isImplied = false) {
1982
2314
  inPre--;
1983
2315
  }
1984
2316
  if (currentVPreBoundary === el) {
1985
- inVPre = false;
2317
+ inVPre = tokenizer.inVPre = false;
1986
2318
  currentVPreBoundary = null;
1987
2319
  }
1988
2320
  if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
@@ -2217,8 +2549,14 @@ function dirToAttr(dir) {
2217
2549
  }
2218
2550
  return attr;
2219
2551
  }
2220
- function emitError(code, index) {
2221
- currentOptions.onError(createCompilerError(code, getLoc(index, index)));
2552
+ function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
2553
+ const exp = createSimpleExpression(content, isStatic, loc, constType);
2554
+ return exp;
2555
+ }
2556
+ function emitError(code, index, message) {
2557
+ currentOptions.onError(
2558
+ createCompilerError(code, getLoc(index, index), void 0, message)
2559
+ );
2222
2560
  }
2223
2561
  function reset() {
2224
2562
  tokenizer.reset();
@@ -2249,6 +2587,7 @@ function baseParse(input, options) {
2249
2587
  }
2250
2588
  }
2251
2589
  tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
2590
+ tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
2252
2591
  const delimiters = options == null ? void 0 : options.delimiters;
2253
2592
  if (delimiters) {
2254
2593
  tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
@@ -2534,6 +2873,7 @@ function createTransformContext(root, {
2534
2873
  const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
2535
2874
  const context = {
2536
2875
  // options
2876
+ filename,
2537
2877
  selfName: nameMatch && capitalize(camelize(nameMatch[1])),
2538
2878
  prefixIdentifiers,
2539
2879
  hoistStatic: hoistStatic2,
@@ -3366,117 +3706,6 @@ function genCacheExpression(node, context) {
3366
3706
  push(`)`);
3367
3707
  }
3368
3708
 
3369
- function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
3370
- {
3371
- return;
3372
- }
3373
- }
3374
- function isReferencedIdentifier(id, parent, parentStack) {
3375
- {
3376
- return false;
3377
- }
3378
- }
3379
- function isInDestructureAssignment(parent, parentStack) {
3380
- if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
3381
- let i = parentStack.length;
3382
- while (i--) {
3383
- const p = parentStack[i];
3384
- if (p.type === "AssignmentExpression") {
3385
- return true;
3386
- } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
3387
- break;
3388
- }
3389
- }
3390
- }
3391
- return false;
3392
- }
3393
- function walkFunctionParams(node, onIdent) {
3394
- for (const p of node.params) {
3395
- for (const id of extractIdentifiers(p)) {
3396
- onIdent(id);
3397
- }
3398
- }
3399
- }
3400
- function walkBlockDeclarations(block, onIdent) {
3401
- for (const stmt of block.body) {
3402
- if (stmt.type === "VariableDeclaration") {
3403
- if (stmt.declare)
3404
- continue;
3405
- for (const decl of stmt.declarations) {
3406
- for (const id of extractIdentifiers(decl.id)) {
3407
- onIdent(id);
3408
- }
3409
- }
3410
- } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
3411
- if (stmt.declare || !stmt.id)
3412
- continue;
3413
- onIdent(stmt.id);
3414
- } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
3415
- const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
3416
- if (variable && variable.type === "VariableDeclaration") {
3417
- for (const decl of variable.declarations) {
3418
- for (const id of extractIdentifiers(decl.id)) {
3419
- onIdent(id);
3420
- }
3421
- }
3422
- }
3423
- }
3424
- }
3425
- }
3426
- function extractIdentifiers(param, nodes = []) {
3427
- switch (param.type) {
3428
- case "Identifier":
3429
- nodes.push(param);
3430
- break;
3431
- case "MemberExpression":
3432
- let object = param;
3433
- while (object.type === "MemberExpression") {
3434
- object = object.object;
3435
- }
3436
- nodes.push(object);
3437
- break;
3438
- case "ObjectPattern":
3439
- for (const prop of param.properties) {
3440
- if (prop.type === "RestElement") {
3441
- extractIdentifiers(prop.argument, nodes);
3442
- } else {
3443
- extractIdentifiers(prop.value, nodes);
3444
- }
3445
- }
3446
- break;
3447
- case "ArrayPattern":
3448
- param.elements.forEach((element) => {
3449
- if (element)
3450
- extractIdentifiers(element, nodes);
3451
- });
3452
- break;
3453
- case "RestElement":
3454
- extractIdentifiers(param.argument, nodes);
3455
- break;
3456
- case "AssignmentPattern":
3457
- extractIdentifiers(param.left, nodes);
3458
- break;
3459
- }
3460
- return nodes;
3461
- }
3462
- const isFunctionType = (node) => {
3463
- return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
3464
- };
3465
- const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
3466
- const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
3467
- const TS_NODE_TYPES = [
3468
- "TSAsExpression",
3469
- // foo as number
3470
- "TSTypeAssertion",
3471
- // (<number>foo)
3472
- "TSNonNullExpression",
3473
- // foo!
3474
- "TSInstantiationExpression",
3475
- // foo<string>
3476
- "TSSatisfiesExpression"
3477
- // foo satisfies T
3478
- ];
3479
-
3480
3709
  const prohibitedKeywordRE = new RegExp(
3481
3710
  "\\b" + "arguments,await,break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,finally,for,function,if,import,let,new,return,super,switch,throw,try,var,void,while,with,yield".split(",").join("\\b|\\b") + "\\b"
3482
3711
  );
@@ -4437,6 +4666,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4437
4666
  if (isEventHandler && isReservedProp(name)) {
4438
4667
  hasVnodeHook = true;
4439
4668
  }
4669
+ if (isEventHandler && value.type === 14) {
4670
+ value = value.arguments[0];
4671
+ }
4440
4672
  if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
4441
4673
  return;
4442
4674
  }
@@ -4889,9 +5121,7 @@ const transformOn = (dir, node, context, augmentor) => {
4889
5121
  if (arg.isStatic) {
4890
5122
  let rawName = arg.content;
4891
5123
  if (!!(process.env.NODE_ENV !== "production") && rawName.startsWith("vnode")) {
4892
- context.onWarn(
4893
- createCompilerError(51, arg.loc)
4894
- );
5124
+ context.onError(createCompilerError(51, arg.loc));
4895
5125
  }
4896
5126
  if (rawName.startsWith("vue:")) {
4897
5127
  rawName = `vnode-${rawName.slice(4)}`;
@@ -5384,12 +5614,14 @@ function baseCompile(source, options = {}) {
5384
5614
  if (options.scopeId && !isModuleMode) {
5385
5615
  onError(createCompilerError(50));
5386
5616
  }
5387
- const ast = isString(source) ? baseParse(source, options) : source;
5617
+ const resolvedOptions = extend({}, options, {
5618
+ prefixIdentifiers
5619
+ });
5620
+ const ast = isString(source) ? baseParse(source, resolvedOptions) : source;
5388
5621
  const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
5389
5622
  transform(
5390
5623
  ast,
5391
- extend({}, options, {
5392
- prefixIdentifiers,
5624
+ extend({}, resolvedOptions, {
5393
5625
  nodeTransforms: [
5394
5626
  ...nodeTransforms,
5395
5627
  ...options.nodeTransforms || []
@@ -5403,14 +5635,22 @@ function baseCompile(source, options = {}) {
5403
5635
  )
5404
5636
  })
5405
5637
  );
5406
- return generate(
5407
- ast,
5408
- extend({}, options, {
5409
- prefixIdentifiers
5410
- })
5411
- );
5638
+ return generate(ast, resolvedOptions);
5412
5639
  }
5413
5640
 
5641
+ const BindingTypes = {
5642
+ "DATA": "data",
5643
+ "PROPS": "props",
5644
+ "PROPS_ALIASED": "props-aliased",
5645
+ "SETUP_LET": "setup-let",
5646
+ "SETUP_CONST": "setup-const",
5647
+ "SETUP_REACTIVE_CONST": "setup-reactive-const",
5648
+ "SETUP_MAYBE_REF": "setup-maybe-ref",
5649
+ "SETUP_REF": "setup-ref",
5650
+ "OPTIONS": "options",
5651
+ "LITERAL_CONST": "literal-const"
5652
+ };
5653
+
5414
5654
  const noopDirectiveTransform = () => ({ props: [] });
5415
5655
 
5416
- export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TS_NODE_TYPES, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, errorMessages, extractIdentifiers, findDir, findProp, forAliasRE, generate, getBaseTransformPreset, getConstantType, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isCoreComponent, isFunctionType, isInDestructureAssignment, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText$1 as isText, isVSlot, locStub, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, traverseNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };
5656
+ export { BASE_TRANSITION, BindingTypes, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, CompilerDeprecationTypes, ConstantTypes, ElementTypes, ErrorCodes, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, Namespaces, NodeTypes, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TS_NODE_TYPES, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, errorMessages, extractIdentifiers, findDir, findProp, forAliasRE, generate, getBaseTransformPreset, getConstantType, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isCoreComponent, isFunctionType, isInDestructureAssignment, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText$1 as isText, isVSlot, locStub, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, traverseNode, unwrapTSNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };