@vue/compiler-dom 3.2.46 → 3.3.0-alpha.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.
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var compilerCore = require('@vue/compiler-core');
4
6
  var shared = require('@vue/shared');
5
7
 
@@ -14,16 +16,16 @@ const V_SHOW = Symbol(`vShow` );
14
16
  const TRANSITION = Symbol(`Transition` );
15
17
  const TRANSITION_GROUP = Symbol(`TransitionGroup` );
16
18
  compilerCore.registerRuntimeHelpers({
17
- [V_MODEL_RADIO]: `vModelRadio`,
18
- [V_MODEL_CHECKBOX]: `vModelCheckbox`,
19
- [V_MODEL_TEXT]: `vModelText`,
20
- [V_MODEL_SELECT]: `vModelSelect`,
21
- [V_MODEL_DYNAMIC]: `vModelDynamic`,
22
- [V_ON_WITH_MODIFIERS]: `withModifiers`,
23
- [V_ON_WITH_KEYS]: `withKeys`,
24
- [V_SHOW]: `vShow`,
25
- [TRANSITION]: `Transition`,
26
- [TRANSITION_GROUP]: `TransitionGroup`
19
+ [V_MODEL_RADIO]: `vModelRadio`,
20
+ [V_MODEL_CHECKBOX]: `vModelCheckbox`,
21
+ [V_MODEL_TEXT]: `vModelText`,
22
+ [V_MODEL_SELECT]: `vModelSelect`,
23
+ [V_MODEL_DYNAMIC]: `vModelDynamic`,
24
+ [V_ON_WITH_MODIFIERS]: `withModifiers`,
25
+ [V_ON_WITH_KEYS]: `withKeys`,
26
+ [V_SHOW]: `vShow`,
27
+ [TRANSITION]: `Transition`,
28
+ [TRANSITION_GROUP]: `TransitionGroup`
27
29
  });
28
30
 
29
31
  var namedCharacterReferences = {
@@ -2260,861 +2262,764 @@ var namedCharacterReferences = {
2260
2262
  "CounterClockwiseContourIntegral;": "∳"
2261
2263
  };
2262
2264
 
2263
- // lazy compute this to make this file tree-shakable for browser
2264
2265
  let maxCRNameLength;
2265
2266
  const decodeHtml = (rawText, asAttr) => {
2266
- let offset = 0;
2267
- const end = rawText.length;
2268
- let decodedText = '';
2269
- function advance(length) {
2270
- offset += length;
2271
- rawText = rawText.slice(length);
2267
+ let offset = 0;
2268
+ const end = rawText.length;
2269
+ let decodedText = "";
2270
+ function advance(length) {
2271
+ offset += length;
2272
+ rawText = rawText.slice(length);
2273
+ }
2274
+ while (offset < end) {
2275
+ const head = /&(?:#x?)?/i.exec(rawText);
2276
+ if (!head || offset + head.index >= end) {
2277
+ const remaining = end - offset;
2278
+ decodedText += rawText.slice(0, remaining);
2279
+ advance(remaining);
2280
+ break;
2272
2281
  }
2273
- while (offset < end) {
2274
- const head = /&(?:#x?)?/i.exec(rawText);
2275
- if (!head || offset + head.index >= end) {
2276
- const remaining = end - offset;
2277
- decodedText += rawText.slice(0, remaining);
2278
- advance(remaining);
2279
- break;
2282
+ decodedText += rawText.slice(0, head.index);
2283
+ advance(head.index);
2284
+ if (head[0] === "&") {
2285
+ let name = "";
2286
+ let value = void 0;
2287
+ if (/[0-9a-z]/i.test(rawText[1])) {
2288
+ if (!maxCRNameLength) {
2289
+ maxCRNameLength = Object.keys(namedCharacterReferences).reduce(
2290
+ (max, name2) => Math.max(max, name2.length),
2291
+ 0
2292
+ );
2280
2293
  }
2281
- // Advance to the "&".
2282
- decodedText += rawText.slice(0, head.index);
2283
- advance(head.index);
2284
- if (head[0] === '&') {
2285
- // Named character reference.
2286
- let name = '';
2287
- let value = undefined;
2288
- if (/[0-9a-z]/i.test(rawText[1])) {
2289
- if (!maxCRNameLength) {
2290
- maxCRNameLength = Object.keys(namedCharacterReferences).reduce((max, name) => Math.max(max, name.length), 0);
2291
- }
2292
- for (let length = maxCRNameLength; !value && length > 0; --length) {
2293
- name = rawText.slice(1, 1 + length);
2294
- value = namedCharacterReferences[name];
2295
- }
2296
- if (value) {
2297
- const semi = name.endsWith(';');
2298
- if (asAttr &&
2299
- !semi &&
2300
- /[=a-z0-9]/i.test(rawText[name.length + 1] || '')) {
2301
- decodedText += '&' + name;
2302
- advance(1 + name.length);
2303
- }
2304
- else {
2305
- decodedText += value;
2306
- advance(1 + name.length);
2307
- }
2308
- }
2309
- else {
2310
- decodedText += '&' + name;
2311
- advance(1 + name.length);
2312
- }
2313
- }
2314
- else {
2315
- decodedText += '&';
2316
- advance(1);
2317
- }
2294
+ for (let length = maxCRNameLength; !value && length > 0; --length) {
2295
+ name = rawText.slice(1, 1 + length);
2296
+ value = namedCharacterReferences[name];
2318
2297
  }
2319
- else {
2320
- // Numeric character reference.
2321
- const hex = head[0] === '&#x';
2322
- const pattern = hex ? /^&#x([0-9a-f]+);?/i : /^&#([0-9]+);?/;
2323
- const body = pattern.exec(rawText);
2324
- if (!body) {
2325
- decodedText += head[0];
2326
- advance(head[0].length);
2327
- }
2328
- else {
2329
- // https://html.spec.whatwg.org/multipage/parsing.html#numeric-character-reference-end-state
2330
- let cp = Number.parseInt(body[1], hex ? 16 : 10);
2331
- if (cp === 0) {
2332
- cp = 0xfffd;
2333
- }
2334
- else if (cp > 0x10ffff) {
2335
- cp = 0xfffd;
2336
- }
2337
- else if (cp >= 0xd800 && cp <= 0xdfff) {
2338
- cp = 0xfffd;
2339
- }
2340
- else if ((cp >= 0xfdd0 && cp <= 0xfdef) || (cp & 0xfffe) === 0xfffe) ;
2341
- else if ((cp >= 0x01 && cp <= 0x08) ||
2342
- cp === 0x0b ||
2343
- (cp >= 0x0d && cp <= 0x1f) ||
2344
- (cp >= 0x7f && cp <= 0x9f)) {
2345
- cp = CCR_REPLACEMENTS[cp] || cp;
2346
- }
2347
- decodedText += String.fromCodePoint(cp);
2348
- advance(body[0].length);
2349
- }
2298
+ if (value) {
2299
+ const semi = name.endsWith(";");
2300
+ if (asAttr && !semi && /[=a-z0-9]/i.test(rawText[name.length + 1] || "")) {
2301
+ decodedText += "&" + name;
2302
+ advance(1 + name.length);
2303
+ } else {
2304
+ decodedText += value;
2305
+ advance(1 + name.length);
2306
+ }
2307
+ } else {
2308
+ decodedText += "&" + name;
2309
+ advance(1 + name.length);
2310
+ }
2311
+ } else {
2312
+ decodedText += "&";
2313
+ advance(1);
2314
+ }
2315
+ } else {
2316
+ const hex = head[0] === "&#x";
2317
+ const pattern = hex ? /^&#x([0-9a-f]+);?/i : /^&#([0-9]+);?/;
2318
+ const body = pattern.exec(rawText);
2319
+ if (!body) {
2320
+ decodedText += head[0];
2321
+ advance(head[0].length);
2322
+ } else {
2323
+ let cp = Number.parseInt(body[1], hex ? 16 : 10);
2324
+ if (cp === 0) {
2325
+ cp = 65533;
2326
+ } else if (cp > 1114111) {
2327
+ cp = 65533;
2328
+ } else if (cp >= 55296 && cp <= 57343) {
2329
+ cp = 65533;
2330
+ } else if (cp >= 64976 && cp <= 65007 || (cp & 65534) === 65534) ; else if (cp >= 1 && cp <= 8 || cp === 11 || cp >= 13 && cp <= 31 || cp >= 127 && cp <= 159) {
2331
+ cp = CCR_REPLACEMENTS[cp] || cp;
2350
2332
  }
2333
+ decodedText += String.fromCodePoint(cp);
2334
+ advance(body[0].length);
2335
+ }
2351
2336
  }
2352
- return decodedText;
2337
+ }
2338
+ return decodedText;
2353
2339
  };
2354
- // https://html.spec.whatwg.org/multipage/parsing.html#numeric-character-reference-end-state
2355
2340
  const CCR_REPLACEMENTS = {
2356
- 0x80: 0x20ac,
2357
- 0x82: 0x201a,
2358
- 0x83: 0x0192,
2359
- 0x84: 0x201e,
2360
- 0x85: 0x2026,
2361
- 0x86: 0x2020,
2362
- 0x87: 0x2021,
2363
- 0x88: 0x02c6,
2364
- 0x89: 0x2030,
2365
- 0x8a: 0x0160,
2366
- 0x8b: 0x2039,
2367
- 0x8c: 0x0152,
2368
- 0x8e: 0x017d,
2369
- 0x91: 0x2018,
2370
- 0x92: 0x2019,
2371
- 0x93: 0x201c,
2372
- 0x94: 0x201d,
2373
- 0x95: 0x2022,
2374
- 0x96: 0x2013,
2375
- 0x97: 0x2014,
2376
- 0x98: 0x02dc,
2377
- 0x99: 0x2122,
2378
- 0x9a: 0x0161,
2379
- 0x9b: 0x203a,
2380
- 0x9c: 0x0153,
2381
- 0x9e: 0x017e,
2382
- 0x9f: 0x0178
2341
+ 128: 8364,
2342
+ 130: 8218,
2343
+ 131: 402,
2344
+ 132: 8222,
2345
+ 133: 8230,
2346
+ 134: 8224,
2347
+ 135: 8225,
2348
+ 136: 710,
2349
+ 137: 8240,
2350
+ 138: 352,
2351
+ 139: 8249,
2352
+ 140: 338,
2353
+ 142: 381,
2354
+ 145: 8216,
2355
+ 146: 8217,
2356
+ 147: 8220,
2357
+ 148: 8221,
2358
+ 149: 8226,
2359
+ 150: 8211,
2360
+ 151: 8212,
2361
+ 152: 732,
2362
+ 153: 8482,
2363
+ 154: 353,
2364
+ 155: 8250,
2365
+ 156: 339,
2366
+ 158: 382,
2367
+ 159: 376
2383
2368
  };
2384
2369
 
2385
- const isRawTextContainer = /*#__PURE__*/ shared.makeMap('style,iframe,script,noscript', true);
2370
+ const isRawTextContainer = /* @__PURE__ */ shared.makeMap(
2371
+ "style,iframe,script,noscript",
2372
+ true
2373
+ );
2386
2374
  const parserOptions = {
2387
- isVoidTag: shared.isVoidTag,
2388
- isNativeTag: tag => shared.isHTMLTag(tag) || shared.isSVGTag(tag),
2389
- isPreTag: tag => tag === 'pre',
2390
- decodeEntities: decodeHtml,
2391
- isBuiltInComponent: (tag) => {
2392
- if (compilerCore.isBuiltInType(tag, `Transition`)) {
2393
- return TRANSITION;
2394
- }
2395
- else if (compilerCore.isBuiltInType(tag, `TransitionGroup`)) {
2396
- return TRANSITION_GROUP;
2397
- }
2398
- },
2399
- // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
2400
- getNamespace(tag, parent) {
2401
- let ns = parent ? parent.ns : 0 /* DOMNamespaces.HTML */;
2402
- if (parent && ns === 2 /* DOMNamespaces.MATH_ML */) {
2403
- if (parent.tag === 'annotation-xml') {
2404
- if (tag === 'svg') {
2405
- return 1 /* DOMNamespaces.SVG */;
2406
- }
2407
- if (parent.props.some(a => a.type === 6 /* NodeTypes.ATTRIBUTE */ &&
2408
- a.name === 'encoding' &&
2409
- a.value != null &&
2410
- (a.value.content === 'text/html' ||
2411
- a.value.content === 'application/xhtml+xml'))) {
2412
- ns = 0 /* DOMNamespaces.HTML */;
2413
- }
2414
- }
2415
- else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
2416
- tag !== 'mglyph' &&
2417
- tag !== 'malignmark') {
2418
- ns = 0 /* DOMNamespaces.HTML */;
2419
- }
2420
- }
2421
- else if (parent && ns === 1 /* DOMNamespaces.SVG */) {
2422
- if (parent.tag === 'foreignObject' ||
2423
- parent.tag === 'desc' ||
2424
- parent.tag === 'title') {
2425
- ns = 0 /* DOMNamespaces.HTML */;
2426
- }
2427
- }
2428
- if (ns === 0 /* DOMNamespaces.HTML */) {
2429
- if (tag === 'svg') {
2430
- return 1 /* DOMNamespaces.SVG */;
2431
- }
2432
- if (tag === 'math') {
2433
- return 2 /* DOMNamespaces.MATH_ML */;
2434
- }
2375
+ isVoidTag: shared.isVoidTag,
2376
+ isNativeTag: (tag) => shared.isHTMLTag(tag) || shared.isSVGTag(tag),
2377
+ isPreTag: (tag) => tag === "pre",
2378
+ decodeEntities: decodeHtml,
2379
+ isBuiltInComponent: (tag) => {
2380
+ if (compilerCore.isBuiltInType(tag, `Transition`)) {
2381
+ return TRANSITION;
2382
+ } else if (compilerCore.isBuiltInType(tag, `TransitionGroup`)) {
2383
+ return TRANSITION_GROUP;
2384
+ }
2385
+ },
2386
+ // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
2387
+ getNamespace(tag, parent) {
2388
+ let ns = parent ? parent.ns : 0;
2389
+ if (parent && ns === 2) {
2390
+ if (parent.tag === "annotation-xml") {
2391
+ if (tag === "svg") {
2392
+ return 1;
2435
2393
  }
2436
- return ns;
2437
- },
2438
- // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
2439
- getTextMode({ tag, ns }) {
2440
- if (ns === 0 /* DOMNamespaces.HTML */) {
2441
- if (tag === 'textarea' || tag === 'title') {
2442
- return 1 /* TextModes.RCDATA */;
2443
- }
2444
- if (isRawTextContainer(tag)) {
2445
- return 2 /* TextModes.RAWTEXT */;
2446
- }
2394
+ if (parent.props.some(
2395
+ (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
2396
+ )) {
2397
+ ns = 0;
2447
2398
  }
2448
- return 0 /* TextModes.DATA */;
2399
+ } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
2400
+ ns = 0;
2401
+ }
2402
+ } else if (parent && ns === 1) {
2403
+ if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
2404
+ ns = 0;
2405
+ }
2406
+ }
2407
+ if (ns === 0) {
2408
+ if (tag === "svg") {
2409
+ return 1;
2410
+ }
2411
+ if (tag === "math") {
2412
+ return 2;
2413
+ }
2414
+ }
2415
+ return ns;
2416
+ },
2417
+ // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
2418
+ getTextMode({ tag, ns }) {
2419
+ if (ns === 0) {
2420
+ if (tag === "textarea" || tag === "title") {
2421
+ return 1;
2422
+ }
2423
+ if (isRawTextContainer(tag)) {
2424
+ return 2;
2425
+ }
2449
2426
  }
2427
+ return 0;
2428
+ }
2450
2429
  };
2451
2430
 
2452
- // Parse inline CSS strings for static style attributes into an object.
2453
- // This is a NodeTransform since it works on the static `style` attribute and
2454
- // converts it into a dynamic equivalent:
2455
- // style="color: red" -> :style='{ "color": "red" }'
2456
- // It is then processed by `transformElement` and included in the generated
2457
- // props.
2458
- const transformStyle = node => {
2459
- if (node.type === 1 /* NodeTypes.ELEMENT */) {
2460
- node.props.forEach((p, i) => {
2461
- if (p.type === 6 /* NodeTypes.ATTRIBUTE */ && p.name === 'style' && p.value) {
2462
- // replace p with an expression node
2463
- node.props[i] = {
2464
- type: 7 /* NodeTypes.DIRECTIVE */,
2465
- name: `bind`,
2466
- arg: compilerCore.createSimpleExpression(`style`, true, p.loc),
2467
- exp: parseInlineCSS(p.value.content, p.loc),
2468
- modifiers: [],
2469
- loc: p.loc
2470
- };
2471
- }
2472
- });
2473
- }
2431
+ const transformStyle = (node) => {
2432
+ if (node.type === "element") {
2433
+ node.props.forEach((p, i) => {
2434
+ if (p.type === 6 && p.name === "style" && p.value) {
2435
+ node.props[i] = {
2436
+ type: 7,
2437
+ name: `bind`,
2438
+ arg: compilerCore.createSimpleExpression(`style`, true, p.loc),
2439
+ exp: parseInlineCSS(p.value.content, p.loc),
2440
+ modifiers: [],
2441
+ loc: p.loc
2442
+ };
2443
+ }
2444
+ });
2445
+ }
2474
2446
  };
2475
2447
  const parseInlineCSS = (cssText, loc) => {
2476
- const normalized = shared.parseStringStyle(cssText);
2477
- return compilerCore.createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
2448
+ const normalized = shared.parseStringStyle(cssText);
2449
+ return compilerCore.createSimpleExpression(
2450
+ JSON.stringify(normalized),
2451
+ false,
2452
+ loc,
2453
+ 3
2454
+ );
2478
2455
  };
2479
2456
 
2480
2457
  function createDOMCompilerError(code, loc) {
2481
- return compilerCore.createCompilerError(code, loc, DOMErrorMessages );
2458
+ return compilerCore.createCompilerError(
2459
+ code,
2460
+ loc,
2461
+ DOMErrorMessages
2462
+ );
2482
2463
  }
2483
2464
  const DOMErrorMessages = {
2484
- [51 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
2485
- [52 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
2486
- [53 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
2487
- [54 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
2488
- [55 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
2489
- [56 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
2490
- [57 /* DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT */]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
2491
- [58 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
2492
- [59 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
2493
- [60 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
2494
- [61 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
2465
+ [51]: `v-html is missing expression.`,
2466
+ [52]: `v-html will override element children.`,
2467
+ [53]: `v-text is missing expression.`,
2468
+ [54]: `v-text will override element children.`,
2469
+ [55]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
2470
+ [56]: `v-model argument is not supported on plain elements.`,
2471
+ [57]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
2472
+ [58]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
2473
+ [59]: `v-show is missing expression.`,
2474
+ [60]: `<Transition> expects exactly one child element or component.`,
2475
+ [61]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
2495
2476
  };
2496
2477
 
2497
2478
  const transformVHtml = (dir, node, context) => {
2498
- const { exp, loc } = dir;
2499
- if (!exp) {
2500
- context.onError(createDOMCompilerError(51 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */, loc));
2501
- }
2502
- if (node.children.length) {
2503
- context.onError(createDOMCompilerError(52 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */, loc));
2504
- node.children.length = 0;
2505
- }
2506
- return {
2507
- props: [
2508
- compilerCore.createObjectProperty(compilerCore.createSimpleExpression(`innerHTML`, true, loc), exp || compilerCore.createSimpleExpression('', true))
2509
- ]
2510
- };
2479
+ const { exp, loc } = dir;
2480
+ if (!exp) {
2481
+ context.onError(
2482
+ createDOMCompilerError(51, loc)
2483
+ );
2484
+ }
2485
+ if (node.children.length) {
2486
+ context.onError(
2487
+ createDOMCompilerError(52, loc)
2488
+ );
2489
+ node.children.length = 0;
2490
+ }
2491
+ return {
2492
+ props: [
2493
+ compilerCore.createObjectProperty(
2494
+ compilerCore.createSimpleExpression(`innerHTML`, true, loc),
2495
+ exp || compilerCore.createSimpleExpression("", true)
2496
+ )
2497
+ ]
2498
+ };
2511
2499
  };
2512
2500
 
2513
2501
  const transformVText = (dir, node, context) => {
2514
- const { exp, loc } = dir;
2515
- if (!exp) {
2516
- context.onError(createDOMCompilerError(53 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */, loc));
2517
- }
2518
- if (node.children.length) {
2519
- context.onError(createDOMCompilerError(54 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */, loc));
2520
- node.children.length = 0;
2521
- }
2522
- return {
2523
- props: [
2524
- compilerCore.createObjectProperty(compilerCore.createSimpleExpression(`textContent`, true), exp
2525
- ? compilerCore.getConstantType(exp, context) > 0
2526
- ? exp
2527
- : compilerCore.createCallExpression(context.helperString(compilerCore.TO_DISPLAY_STRING), [exp], loc)
2528
- : compilerCore.createSimpleExpression('', true))
2529
- ]
2530
- };
2502
+ const { exp, loc } = dir;
2503
+ if (!exp) {
2504
+ context.onError(
2505
+ createDOMCompilerError(53, loc)
2506
+ );
2507
+ }
2508
+ if (node.children.length) {
2509
+ context.onError(
2510
+ createDOMCompilerError(54, loc)
2511
+ );
2512
+ node.children.length = 0;
2513
+ }
2514
+ return {
2515
+ props: [
2516
+ compilerCore.createObjectProperty(
2517
+ compilerCore.createSimpleExpression(`textContent`, true),
2518
+ exp ? compilerCore.getConstantType(exp, context) > 0 ? exp : compilerCore.createCallExpression(
2519
+ context.helperString(compilerCore.TO_DISPLAY_STRING),
2520
+ [exp],
2521
+ loc
2522
+ ) : compilerCore.createSimpleExpression("", true)
2523
+ )
2524
+ ]
2525
+ };
2531
2526
  };
2532
2527
 
2533
2528
  const transformModel = (dir, node, context) => {
2534
- const baseResult = compilerCore.transformModel(dir, node, context);
2535
- // base transform has errors OR component v-model (only need props)
2536
- if (!baseResult.props.length || node.tagType === 1 /* ElementTypes.COMPONENT */) {
2537
- return baseResult;
2538
- }
2539
- if (dir.arg) {
2540
- context.onError(createDOMCompilerError(56 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
2541
- }
2542
- function checkDuplicatedValue() {
2543
- const value = compilerCore.findProp(node, 'value');
2544
- if (value) {
2545
- context.onError(createDOMCompilerError(58 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
2546
- }
2529
+ const baseResult = compilerCore.transformModel(dir, node, context);
2530
+ if (!baseResult.props.length || node.tagType === 1) {
2531
+ return baseResult;
2532
+ }
2533
+ if (dir.arg) {
2534
+ context.onError(
2535
+ createDOMCompilerError(
2536
+ 56,
2537
+ dir.arg.loc
2538
+ )
2539
+ );
2540
+ }
2541
+ function checkDuplicatedValue() {
2542
+ const value = compilerCore.findProp(node, "value");
2543
+ if (value) {
2544
+ context.onError(
2545
+ createDOMCompilerError(
2546
+ 58,
2547
+ value.loc
2548
+ )
2549
+ );
2547
2550
  }
2548
- const { tag } = node;
2549
- const isCustomElement = context.isCustomElement(tag);
2550
- if (tag === 'input' ||
2551
- tag === 'textarea' ||
2552
- tag === 'select' ||
2553
- isCustomElement) {
2554
- let directiveToUse = V_MODEL_TEXT;
2555
- let isInvalidType = false;
2556
- if (tag === 'input' || isCustomElement) {
2557
- const type = compilerCore.findProp(node, `type`);
2558
- if (type) {
2559
- if (type.type === 7 /* NodeTypes.DIRECTIVE */) {
2560
- // :type="foo"
2561
- directiveToUse = V_MODEL_DYNAMIC;
2562
- }
2563
- else if (type.value) {
2564
- switch (type.value.content) {
2565
- case 'radio':
2566
- directiveToUse = V_MODEL_RADIO;
2567
- break;
2568
- case 'checkbox':
2569
- directiveToUse = V_MODEL_CHECKBOX;
2570
- break;
2571
- case 'file':
2572
- isInvalidType = true;
2573
- context.onError(createDOMCompilerError(57 /* DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
2574
- break;
2575
- default:
2576
- // text type
2577
- checkDuplicatedValue();
2578
- break;
2579
- }
2580
- }
2581
- }
2582
- else if (compilerCore.hasDynamicKeyVBind(node)) {
2583
- // element has bindings with dynamic keys, which can possibly contain
2584
- // "type".
2585
- directiveToUse = V_MODEL_DYNAMIC;
2586
- }
2587
- else {
2588
- // text type
2589
- checkDuplicatedValue();
2590
- }
2591
- }
2592
- else if (tag === 'select') {
2593
- directiveToUse = V_MODEL_SELECT;
2594
- }
2595
- else {
2596
- // textarea
2597
- checkDuplicatedValue();
2598
- }
2599
- // inject runtime directive
2600
- // by returning the helper symbol via needRuntime
2601
- // the import will replaced a resolveDirective call.
2602
- if (!isInvalidType) {
2603
- baseResult.needRuntime = context.helper(directiveToUse);
2551
+ }
2552
+ const { tag } = node;
2553
+ const isCustomElement = context.isCustomElement(tag);
2554
+ if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
2555
+ let directiveToUse = V_MODEL_TEXT;
2556
+ let isInvalidType = false;
2557
+ if (tag === "input" || isCustomElement) {
2558
+ const type = compilerCore.findProp(node, `type`);
2559
+ if (type) {
2560
+ if (type.type === 7) {
2561
+ directiveToUse = V_MODEL_DYNAMIC;
2562
+ } else if (type.value) {
2563
+ switch (type.value.content) {
2564
+ case "radio":
2565
+ directiveToUse = V_MODEL_RADIO;
2566
+ break;
2567
+ case "checkbox":
2568
+ directiveToUse = V_MODEL_CHECKBOX;
2569
+ break;
2570
+ case "file":
2571
+ isInvalidType = true;
2572
+ context.onError(
2573
+ createDOMCompilerError(
2574
+ 57,
2575
+ dir.loc
2576
+ )
2577
+ );
2578
+ break;
2579
+ default:
2580
+ checkDuplicatedValue();
2581
+ break;
2582
+ }
2604
2583
  }
2584
+ } else if (compilerCore.hasDynamicKeyVBind(node)) {
2585
+ directiveToUse = V_MODEL_DYNAMIC;
2586
+ } else {
2587
+ checkDuplicatedValue();
2588
+ }
2589
+ } else if (tag === "select") {
2590
+ directiveToUse = V_MODEL_SELECT;
2591
+ } else {
2592
+ checkDuplicatedValue();
2605
2593
  }
2606
- else {
2607
- context.onError(createDOMCompilerError(55 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
2594
+ if (!isInvalidType) {
2595
+ baseResult.needRuntime = context.helper(directiveToUse);
2608
2596
  }
2609
- // native vmodel doesn't need the `modelValue` props since they are also
2610
- // passed to the runtime as `binding.value`. removing it reduces code size.
2611
- baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
2612
- p.key.content === 'modelValue'));
2613
- return baseResult;
2597
+ } else {
2598
+ context.onError(
2599
+ createDOMCompilerError(
2600
+ 55,
2601
+ dir.loc
2602
+ )
2603
+ );
2604
+ }
2605
+ baseResult.props = baseResult.props.filter(
2606
+ (p) => !(p.key.type === 4 && p.key.content === "modelValue")
2607
+ );
2608
+ return baseResult;
2614
2609
  };
2615
2610
 
2616
- const isEventOptionModifier = /*#__PURE__*/ shared.makeMap(`passive,once,capture`);
2617
- const isNonKeyModifier = /*#__PURE__*/ shared.makeMap(
2618
- // event propagation management
2619
- `stop,prevent,self,` +
2620
- // system modifiers + exact
2621
- `ctrl,shift,alt,meta,exact,` +
2622
- // mouse
2623
- `middle`);
2624
- // left & right could be mouse or key modifiers based on event type
2625
- const maybeKeyModifier = /*#__PURE__*/ shared.makeMap('left,right');
2626
- const isKeyboardEvent = /*#__PURE__*/ shared.makeMap(`onkeyup,onkeydown,onkeypress`, true);
2611
+ const isEventOptionModifier = /* @__PURE__ */ shared.makeMap(`passive,once,capture`);
2612
+ const isNonKeyModifier = /* @__PURE__ */ shared.makeMap(
2613
+ // event propagation management
2614
+ `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
2615
+ );
2616
+ const maybeKeyModifier = /* @__PURE__ */ shared.makeMap("left,right");
2617
+ const isKeyboardEvent = /* @__PURE__ */ shared.makeMap(
2618
+ `onkeyup,onkeydown,onkeypress`,
2619
+ true
2620
+ );
2627
2621
  const resolveModifiers = (key, modifiers, context, loc) => {
2628
- const keyModifiers = [];
2629
- const nonKeyModifiers = [];
2630
- const eventOptionModifiers = [];
2631
- for (let i = 0; i < modifiers.length; i++) {
2632
- const modifier = modifiers[i];
2633
- if (modifier === 'native' &&
2634
- compilerCore.checkCompatEnabled("COMPILER_V_ON_NATIVE" /* CompilerDeprecationTypes.COMPILER_V_ON_NATIVE */, context, loc)) {
2635
- eventOptionModifiers.push(modifier);
2622
+ const keyModifiers = [];
2623
+ const nonKeyModifiers = [];
2624
+ const eventOptionModifiers = [];
2625
+ for (let i = 0; i < modifiers.length; i++) {
2626
+ const modifier = modifiers[i];
2627
+ if (modifier === "native" && compilerCore.checkCompatEnabled(
2628
+ "COMPILER_V_ON_NATIVE",
2629
+ context,
2630
+ loc
2631
+ )) {
2632
+ eventOptionModifiers.push(modifier);
2633
+ } else if (isEventOptionModifier(modifier)) {
2634
+ eventOptionModifiers.push(modifier);
2635
+ } else {
2636
+ if (maybeKeyModifier(modifier)) {
2637
+ if (compilerCore.isStaticExp(key)) {
2638
+ if (isKeyboardEvent(key.content)) {
2639
+ keyModifiers.push(modifier);
2640
+ } else {
2641
+ nonKeyModifiers.push(modifier);
2642
+ }
2643
+ } else {
2644
+ keyModifiers.push(modifier);
2645
+ nonKeyModifiers.push(modifier);
2636
2646
  }
2637
- else if (isEventOptionModifier(modifier)) {
2638
- // eventOptionModifiers: modifiers for addEventListener() options,
2639
- // e.g. .passive & .capture
2640
- eventOptionModifiers.push(modifier);
2641
- }
2642
- else {
2643
- // runtimeModifiers: modifiers that needs runtime guards
2644
- if (maybeKeyModifier(modifier)) {
2645
- if (compilerCore.isStaticExp(key)) {
2646
- if (isKeyboardEvent(key.content)) {
2647
- keyModifiers.push(modifier);
2648
- }
2649
- else {
2650
- nonKeyModifiers.push(modifier);
2651
- }
2652
- }
2653
- else {
2654
- keyModifiers.push(modifier);
2655
- nonKeyModifiers.push(modifier);
2656
- }
2657
- }
2658
- else {
2659
- if (isNonKeyModifier(modifier)) {
2660
- nonKeyModifiers.push(modifier);
2661
- }
2662
- else {
2663
- keyModifiers.push(modifier);
2664
- }
2665
- }
2647
+ } else {
2648
+ if (isNonKeyModifier(modifier)) {
2649
+ nonKeyModifiers.push(modifier);
2650
+ } else {
2651
+ keyModifiers.push(modifier);
2666
2652
  }
2653
+ }
2667
2654
  }
2668
- return {
2669
- keyModifiers,
2670
- nonKeyModifiers,
2671
- eventOptionModifiers
2672
- };
2655
+ }
2656
+ return {
2657
+ keyModifiers,
2658
+ nonKeyModifiers,
2659
+ eventOptionModifiers
2660
+ };
2673
2661
  };
2674
2662
  const transformClick = (key, event) => {
2675
- const isStaticClick = compilerCore.isStaticExp(key) && key.content.toLowerCase() === 'onclick';
2676
- return isStaticClick
2677
- ? compilerCore.createSimpleExpression(event, true)
2678
- : key.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */
2679
- ? compilerCore.createCompoundExpression([
2680
- `(`,
2681
- key,
2682
- `) === "onClick" ? "${event}" : (`,
2683
- key,
2684
- `)`
2685
- ])
2686
- : key;
2663
+ const isStaticClick = compilerCore.isStaticExp(key) && key.content.toLowerCase() === "onclick";
2664
+ return isStaticClick ? compilerCore.createSimpleExpression(event, true) : key.type !== 4 ? compilerCore.createCompoundExpression([
2665
+ `(`,
2666
+ key,
2667
+ `) === "onClick" ? "${event}" : (`,
2668
+ key,
2669
+ `)`
2670
+ ]) : key;
2687
2671
  };
2688
2672
  const transformOn = (dir, node, context) => {
2689
- return compilerCore.transformOn(dir, node, context, baseResult => {
2690
- const { modifiers } = dir;
2691
- if (!modifiers.length)
2692
- return baseResult;
2693
- let { key, value: handlerExp } = baseResult.props[0];
2694
- const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
2695
- // normalize click.right and click.middle since they don't actually fire
2696
- if (nonKeyModifiers.includes('right')) {
2697
- key = transformClick(key, `onContextmenu`);
2698
- }
2699
- if (nonKeyModifiers.includes('middle')) {
2700
- key = transformClick(key, `onMouseup`);
2701
- }
2702
- if (nonKeyModifiers.length) {
2703
- handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
2704
- handlerExp,
2705
- JSON.stringify(nonKeyModifiers)
2706
- ]);
2707
- }
2708
- if (keyModifiers.length &&
2709
- // if event name is dynamic, always wrap with keys guard
2710
- (!compilerCore.isStaticExp(key) || isKeyboardEvent(key.content))) {
2711
- handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_KEYS), [
2712
- handlerExp,
2713
- JSON.stringify(keyModifiers)
2714
- ]);
2715
- }
2716
- if (eventOptionModifiers.length) {
2717
- const modifierPostfix = eventOptionModifiers.map(shared.capitalize).join('');
2718
- key = compilerCore.isStaticExp(key)
2719
- ? compilerCore.createSimpleExpression(`${key.content}${modifierPostfix}`, true)
2720
- : compilerCore.createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
2721
- }
2722
- return {
2723
- props: [compilerCore.createObjectProperty(key, handlerExp)]
2724
- };
2725
- });
2726
- };
2727
-
2728
- const transformShow = (dir, node, context) => {
2729
- const { exp, loc } = dir;
2730
- if (!exp) {
2731
- context.onError(createDOMCompilerError(59 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */, loc));
2673
+ return compilerCore.transformOn(dir, node, context, (baseResult) => {
2674
+ const { modifiers } = dir;
2675
+ if (!modifiers.length)
2676
+ return baseResult;
2677
+ let { key, value: handlerExp } = baseResult.props[0];
2678
+ const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
2679
+ if (nonKeyModifiers.includes("right")) {
2680
+ key = transformClick(key, `onContextmenu`);
2681
+ }
2682
+ if (nonKeyModifiers.includes("middle")) {
2683
+ key = transformClick(key, `onMouseup`);
2684
+ }
2685
+ if (nonKeyModifiers.length) {
2686
+ handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
2687
+ handlerExp,
2688
+ JSON.stringify(nonKeyModifiers)
2689
+ ]);
2690
+ }
2691
+ if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
2692
+ (!compilerCore.isStaticExp(key) || isKeyboardEvent(key.content))) {
2693
+ handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_KEYS), [
2694
+ handlerExp,
2695
+ JSON.stringify(keyModifiers)
2696
+ ]);
2697
+ }
2698
+ if (eventOptionModifiers.length) {
2699
+ const modifierPostfix = eventOptionModifiers.map(shared.capitalize).join("");
2700
+ key = compilerCore.isStaticExp(key) ? compilerCore.createSimpleExpression(`${key.content}${modifierPostfix}`, true) : compilerCore.createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
2732
2701
  }
2733
2702
  return {
2734
- props: [],
2735
- needRuntime: context.helper(V_SHOW)
2703
+ props: [compilerCore.createObjectProperty(key, handlerExp)]
2736
2704
  };
2705
+ });
2706
+ };
2707
+
2708
+ const transformShow = (dir, node, context) => {
2709
+ const { exp, loc } = dir;
2710
+ if (!exp) {
2711
+ context.onError(
2712
+ createDOMCompilerError(59, loc)
2713
+ );
2714
+ }
2715
+ return {
2716
+ props: [],
2717
+ needRuntime: context.helper(V_SHOW)
2718
+ };
2737
2719
  };
2738
2720
 
2739
2721
  const transformTransition = (node, context) => {
2740
- if (node.type === 1 /* NodeTypes.ELEMENT */ &&
2741
- node.tagType === 1 /* ElementTypes.COMPONENT */) {
2742
- const component = context.isBuiltInComponent(node.tag);
2743
- if (component === TRANSITION) {
2744
- return () => {
2745
- if (!node.children.length) {
2746
- return;
2747
- }
2748
- // warn multiple transition children
2749
- if (hasMultipleChildren(node)) {
2750
- context.onError(createDOMCompilerError(60 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */, {
2751
- start: node.children[0].loc.start,
2752
- end: node.children[node.children.length - 1].loc.end,
2753
- source: ''
2754
- }));
2755
- }
2756
- // check if it's s single child w/ v-show
2757
- // if yes, inject "persisted: true" to the transition props
2758
- const child = node.children[0];
2759
- if (child.type === 1 /* NodeTypes.ELEMENT */) {
2760
- for (const p of child.props) {
2761
- if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'show') {
2762
- node.props.push({
2763
- type: 6 /* NodeTypes.ATTRIBUTE */,
2764
- name: 'persisted',
2765
- value: undefined,
2766
- loc: node.loc
2767
- });
2768
- }
2769
- }
2770
- }
2771
- };
2722
+ if (node.type === "element" && node.tagType === 1) {
2723
+ const component = context.isBuiltInComponent(node.tag);
2724
+ if (component === TRANSITION) {
2725
+ return () => {
2726
+ if (!node.children.length) {
2727
+ return;
2728
+ }
2729
+ if (hasMultipleChildren(node)) {
2730
+ context.onError(
2731
+ createDOMCompilerError(
2732
+ 60,
2733
+ {
2734
+ start: node.children[0].loc.start,
2735
+ end: node.children[node.children.length - 1].loc.end,
2736
+ source: ""
2737
+ }
2738
+ )
2739
+ );
2740
+ }
2741
+ const child = node.children[0];
2742
+ if (child.type === "element") {
2743
+ for (const p of child.props) {
2744
+ if (p.type === 7 && p.name === "show") {
2745
+ node.props.push({
2746
+ type: 6,
2747
+ name: "persisted",
2748
+ value: void 0,
2749
+ loc: node.loc
2750
+ });
2751
+ }
2752
+ }
2772
2753
  }
2754
+ };
2773
2755
  }
2756
+ }
2774
2757
  };
2775
2758
  function hasMultipleChildren(node) {
2776
- // #1352 filter out potential comment nodes.
2777
- const children = (node.children = node.children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */ &&
2778
- !(c.type === 2 /* NodeTypes.TEXT */ && !c.content.trim())));
2779
- const child = children[0];
2780
- return (children.length !== 1 ||
2781
- child.type === 11 /* NodeTypes.FOR */ ||
2782
- (child.type === 9 /* NodeTypes.IF */ && child.branches.some(hasMultipleChildren)));
2759
+ const children = node.children = node.children.filter(
2760
+ (c) => c.type !== "comment" && !(c.type === "text" && !c.content.trim())
2761
+ );
2762
+ const child = children[0];
2763
+ return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
2783
2764
  }
2784
2765
 
2785
- /**
2786
- * This module is Node-only.
2787
- */
2788
- /**
2789
- * Regex for replacing placeholders for embedded constant variables
2790
- * (e.g. import URL string constants generated by compiler-sfc)
2791
- */
2792
2766
  const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
2793
- /**
2794
- * Turn eligible hoisted static trees into stringified static nodes, e.g.
2795
- *
2796
- * ```js
2797
- * const _hoisted_1 = createStaticVNode(`<div class="foo">bar</div>`)
2798
- * ```
2799
- *
2800
- * A single static vnode can contain stringified content for **multiple**
2801
- * consecutive nodes (element and plain text), called a "chunk".
2802
- * `@vue/runtime-dom` will create the content via innerHTML in a hidden
2803
- * container element and insert all the nodes in place. The call must also
2804
- * provide the number of nodes contained in the chunk so that during hydration
2805
- * we can know how many nodes the static vnode should adopt.
2806
- *
2807
- * The optimization scans a children list that contains hoisted nodes, and
2808
- * tries to find the largest chunk of consecutive hoisted nodes before running
2809
- * into a non-hoisted node or the end of the list. A chunk is then converted
2810
- * into a single static vnode and replaces the hoisted expression of the first
2811
- * node in the chunk. Other nodes in the chunk are considered "merged" and
2812
- * therefore removed from both the hoist list and the children array.
2813
- *
2814
- * This optimization is only performed in Node.js.
2815
- */
2816
2767
  const stringifyStatic = (children, context, parent) => {
2817
- // bail stringification for slot content
2818
- if (context.scopes.vSlot > 0) {
2819
- return;
2820
- }
2821
- let nc = 0; // current node count
2822
- let ec = 0; // current element with binding count
2823
- const currentChunk = [];
2824
- const stringifyCurrentChunk = (currentIndex) => {
2825
- if (nc >= 20 /* StringifyThresholds.NODE_COUNT */ ||
2826
- ec >= 5 /* StringifyThresholds.ELEMENT_WITH_BINDING_COUNT */) {
2827
- // combine all currently eligible nodes into a single static vnode call
2828
- const staticCall = compilerCore.createCallExpression(context.helper(compilerCore.CREATE_STATIC), [
2829
- JSON.stringify(currentChunk.map(node => stringifyNode(node, context)).join('')).replace(expReplaceRE, `" + $1 + "`),
2830
- // the 2nd argument indicates the number of DOM nodes this static vnode
2831
- // will insert / hydrate
2832
- String(currentChunk.length)
2833
- ]);
2834
- // replace the first node's hoisted expression with the static vnode call
2835
- replaceHoist(currentChunk[0], staticCall, context);
2836
- if (currentChunk.length > 1) {
2837
- for (let i = 1; i < currentChunk.length; i++) {
2838
- // for the merged nodes, set their hoisted expression to null
2839
- replaceHoist(currentChunk[i], null, context);
2840
- }
2841
- // also remove merged nodes from children
2842
- const deleteCount = currentChunk.length - 1;
2843
- children.splice(currentIndex - currentChunk.length + 1, deleteCount);
2844
- return deleteCount;
2845
- }
2768
+ if (context.scopes.vSlot > 0) {
2769
+ return;
2770
+ }
2771
+ let nc = 0;
2772
+ let ec = 0;
2773
+ const currentChunk = [];
2774
+ const stringifyCurrentChunk = (currentIndex) => {
2775
+ if (nc >= 20 || ec >= 5) {
2776
+ const staticCall = compilerCore.createCallExpression(context.helper(compilerCore.CREATE_STATIC), [
2777
+ JSON.stringify(
2778
+ currentChunk.map((node) => stringifyNode(node, context)).join("")
2779
+ ).replace(expReplaceRE, `" + $1 + "`),
2780
+ // the 2nd argument indicates the number of DOM nodes this static vnode
2781
+ // will insert / hydrate
2782
+ String(currentChunk.length)
2783
+ ]);
2784
+ replaceHoist(currentChunk[0], staticCall, context);
2785
+ if (currentChunk.length > 1) {
2786
+ for (let i2 = 1; i2 < currentChunk.length; i2++) {
2787
+ replaceHoist(currentChunk[i2], null, context);
2846
2788
  }
2847
- return 0;
2848
- };
2849
- let i = 0;
2850
- for (; i < children.length; i++) {
2851
- const child = children[i];
2852
- const hoisted = getHoistedNode(child);
2853
- if (hoisted) {
2854
- // presence of hoisted means child must be a stringifiable node
2855
- const node = child;
2856
- const result = analyzeNode(node);
2857
- if (result) {
2858
- // node is stringifiable, record state
2859
- nc += result[0];
2860
- ec += result[1];
2861
- currentChunk.push(node);
2862
- continue;
2863
- }
2864
- }
2865
- // we only reach here if we ran into a node that is not stringifiable
2866
- // check if currently analyzed nodes meet criteria for stringification.
2867
- // adjust iteration index
2868
- i -= stringifyCurrentChunk(i);
2869
- // reset state
2870
- nc = 0;
2871
- ec = 0;
2872
- currentChunk.length = 0;
2789
+ const deleteCount = currentChunk.length - 1;
2790
+ children.splice(currentIndex - currentChunk.length + 1, deleteCount);
2791
+ return deleteCount;
2792
+ }
2873
2793
  }
2874
- // in case the last node was also stringifiable
2875
- stringifyCurrentChunk(i);
2794
+ return 0;
2795
+ };
2796
+ let i = 0;
2797
+ for (; i < children.length; i++) {
2798
+ const child = children[i];
2799
+ const hoisted = getHoistedNode(child);
2800
+ if (hoisted) {
2801
+ const node = child;
2802
+ const result = analyzeNode(node);
2803
+ if (result) {
2804
+ nc += result[0];
2805
+ ec += result[1];
2806
+ currentChunk.push(node);
2807
+ continue;
2808
+ }
2809
+ }
2810
+ i -= stringifyCurrentChunk(i);
2811
+ nc = 0;
2812
+ ec = 0;
2813
+ currentChunk.length = 0;
2814
+ }
2815
+ stringifyCurrentChunk(i);
2876
2816
  };
2877
- const getHoistedNode = (node) => ((node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 0 /* ElementTypes.ELEMENT */) ||
2878
- node.type == 12 /* NodeTypes.TEXT_CALL */) &&
2879
- node.codegenNode &&
2880
- node.codegenNode.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
2881
- node.codegenNode.hoisted;
2817
+ const getHoistedNode = (node) => (node.type === "element" && node.tagType === 0 || node.type == 12) && node.codegenNode && node.codegenNode.type === 4 && node.codegenNode.hoisted;
2882
2818
  const dataAriaRE = /^(data|aria)-/;
2883
2819
  const isStringifiableAttr = (name, ns) => {
2884
- return ((ns === 0 /* DOMNamespaces.HTML */
2885
- ? shared.isKnownHtmlAttr(name)
2886
- : ns === 1 /* DOMNamespaces.SVG */
2887
- ? shared.isKnownSvgAttr(name)
2888
- : false) || dataAriaRE.test(name));
2820
+ return (ns === 0 ? shared.isKnownHtmlAttr(name) : ns === 1 ? shared.isKnownSvgAttr(name) : false) || dataAriaRE.test(name);
2889
2821
  };
2890
2822
  const replaceHoist = (node, replacement, context) => {
2891
- const hoistToReplace = node.codegenNode.hoisted;
2892
- context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement;
2823
+ const hoistToReplace = node.codegenNode.hoisted;
2824
+ context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement;
2893
2825
  };
2894
- const isNonStringifiable = /*#__PURE__*/ shared.makeMap(`caption,thead,tr,th,tbody,td,tfoot,colgroup,col`);
2895
- /**
2896
- * for a hoisted node, analyze it and return:
2897
- * - false: bailed (contains non-stringifiable props or runtime constant)
2898
- * - [nc, ec] where
2899
- * - nc is the number of nodes inside
2900
- * - ec is the number of element with bindings inside
2901
- */
2826
+ const isNonStringifiable = /* @__PURE__ */ shared.makeMap(
2827
+ `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
2828
+ );
2902
2829
  function analyzeNode(node) {
2903
- if (node.type === 1 /* NodeTypes.ELEMENT */ && isNonStringifiable(node.tag)) {
2904
- return false;
2905
- }
2906
- if (node.type === 12 /* NodeTypes.TEXT_CALL */) {
2907
- return [1, 0];
2830
+ if (node.type === "element" && isNonStringifiable(node.tag)) {
2831
+ return false;
2832
+ }
2833
+ if (node.type === 12) {
2834
+ return [1, 0];
2835
+ }
2836
+ let nc = 1;
2837
+ let ec = node.props.length > 0 ? 1 : 0;
2838
+ let bailed = false;
2839
+ const bail = () => {
2840
+ bailed = true;
2841
+ return false;
2842
+ };
2843
+ function walk(node2) {
2844
+ for (let i = 0; i < node2.props.length; i++) {
2845
+ const p = node2.props[i];
2846
+ if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
2847
+ return bail();
2848
+ }
2849
+ if (p.type === 7 && p.name === "bind") {
2850
+ if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
2851
+ return bail();
2852
+ }
2853
+ if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
2854
+ return bail();
2855
+ }
2856
+ }
2908
2857
  }
2909
- let nc = 1; // node count
2910
- let ec = node.props.length > 0 ? 1 : 0; // element w/ binding count
2911
- let bailed = false;
2912
- const bail = () => {
2913
- bailed = true;
2914
- return false;
2915
- };
2916
- // TODO: check for cases where using innerHTML will result in different
2917
- // output compared to imperative node insertions.
2918
- // probably only need to check for most common case
2919
- // i.e. non-phrasing-content tags inside `<p>`
2920
- function walk(node) {
2921
- for (let i = 0; i < node.props.length; i++) {
2922
- const p = node.props[i];
2923
- // bail on non-attr bindings
2924
- if (p.type === 6 /* NodeTypes.ATTRIBUTE */ &&
2925
- !isStringifiableAttr(p.name, node.ns)) {
2926
- return bail();
2927
- }
2928
- if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'bind') {
2929
- // bail on non-attr bindings
2930
- if (p.arg &&
2931
- (p.arg.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */ ||
2932
- (p.arg.isStatic && !isStringifiableAttr(p.arg.content, node.ns)))) {
2933
- return bail();
2934
- }
2935
- if (p.exp &&
2936
- (p.exp.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */ ||
2937
- p.exp.constType < 3 /* ConstantTypes.CAN_STRINGIFY */)) {
2938
- return bail();
2939
- }
2940
- }
2858
+ for (let i = 0; i < node2.children.length; i++) {
2859
+ nc++;
2860
+ const child = node2.children[i];
2861
+ if (child.type === "element") {
2862
+ if (child.props.length > 0) {
2863
+ ec++;
2941
2864
  }
2942
- for (let i = 0; i < node.children.length; i++) {
2943
- nc++;
2944
- const child = node.children[i];
2945
- if (child.type === 1 /* NodeTypes.ELEMENT */) {
2946
- if (child.props.length > 0) {
2947
- ec++;
2948
- }
2949
- walk(child);
2950
- if (bailed) {
2951
- return false;
2952
- }
2953
- }
2865
+ walk(child);
2866
+ if (bailed) {
2867
+ return false;
2954
2868
  }
2955
- return true;
2869
+ }
2956
2870
  }
2957
- return walk(node) ? [nc, ec] : false;
2871
+ return true;
2872
+ }
2873
+ return walk(node) ? [nc, ec] : false;
2958
2874
  }
2959
2875
  function stringifyNode(node, context) {
2960
- if (shared.isString(node)) {
2961
- return node;
2962
- }
2963
- if (shared.isSymbol(node)) {
2964
- return ``;
2965
- }
2966
- switch (node.type) {
2967
- case 1 /* NodeTypes.ELEMENT */:
2968
- return stringifyElement(node, context);
2969
- case 2 /* NodeTypes.TEXT */:
2970
- return shared.escapeHtml(node.content);
2971
- case 3 /* NodeTypes.COMMENT */:
2972
- return `<!--${shared.escapeHtml(node.content)}-->`;
2973
- case 5 /* NodeTypes.INTERPOLATION */:
2974
- return shared.escapeHtml(shared.toDisplayString(evaluateConstant(node.content)));
2975
- case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
2976
- return shared.escapeHtml(evaluateConstant(node));
2977
- case 12 /* NodeTypes.TEXT_CALL */:
2978
- return stringifyNode(node.content, context);
2979
- default:
2980
- // static trees will not contain if/for nodes
2981
- return '';
2982
- }
2876
+ if (shared.isString(node)) {
2877
+ return node;
2878
+ }
2879
+ if (shared.isSymbol(node)) {
2880
+ return ``;
2881
+ }
2882
+ switch (node.type) {
2883
+ case "element":
2884
+ return stringifyElement(node, context);
2885
+ case "text":
2886
+ return shared.escapeHtml(node.content);
2887
+ case "comment":
2888
+ return `<!--${shared.escapeHtml(node.content)}-->`;
2889
+ case 5:
2890
+ return shared.escapeHtml(shared.toDisplayString(evaluateConstant(node.content)));
2891
+ case 8:
2892
+ return shared.escapeHtml(evaluateConstant(node));
2893
+ case 12:
2894
+ return stringifyNode(node.content, context);
2895
+ default:
2896
+ return "";
2897
+ }
2983
2898
  }
2984
2899
  function stringifyElement(node, context) {
2985
- let res = `<${node.tag}`;
2986
- let innerHTML = '';
2987
- for (let i = 0; i < node.props.length; i++) {
2988
- const p = node.props[i];
2989
- if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
2990
- res += ` ${p.name}`;
2991
- if (p.value) {
2992
- res += `="${shared.escapeHtml(p.value.content)}"`;
2993
- }
2900
+ let res = `<${node.tag}`;
2901
+ let innerHTML = "";
2902
+ for (let i = 0; i < node.props.length; i++) {
2903
+ const p = node.props[i];
2904
+ if (p.type === 6) {
2905
+ res += ` ${p.name}`;
2906
+ if (p.value) {
2907
+ res += `="${shared.escapeHtml(p.value.content)}"`;
2908
+ }
2909
+ } else if (p.type === 7) {
2910
+ if (p.name === "bind") {
2911
+ const exp = p.exp;
2912
+ if (exp.content[0] === "_") {
2913
+ res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
2914
+ continue;
2994
2915
  }
2995
- else if (p.type === 7 /* NodeTypes.DIRECTIVE */) {
2996
- if (p.name === 'bind') {
2997
- const exp = p.exp;
2998
- if (exp.content[0] === '_') {
2999
- // internally generated string constant references
3000
- // e.g. imported URL strings via compiler-sfc transformAssetUrl plugin
3001
- res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
3002
- continue;
3003
- }
3004
- // #6568
3005
- if (shared.isBooleanAttr(p.arg.content) &&
3006
- exp.content === 'false') {
3007
- continue;
3008
- }
3009
- // constant v-bind, e.g. :foo="1"
3010
- let evaluated = evaluateConstant(exp);
3011
- if (evaluated != null) {
3012
- const arg = p.arg && p.arg.content;
3013
- if (arg === 'class') {
3014
- evaluated = shared.normalizeClass(evaluated);
3015
- }
3016
- else if (arg === 'style') {
3017
- evaluated = shared.stringifyStyle(shared.normalizeStyle(evaluated));
3018
- }
3019
- res += ` ${p.arg.content}="${shared.escapeHtml(evaluated)}"`;
3020
- }
3021
- }
3022
- else if (p.name === 'html') {
3023
- // #5439 v-html with constant value
3024
- // not sure why would anyone do this but it can happen
3025
- innerHTML = evaluateConstant(p.exp);
3026
- }
3027
- else if (p.name === 'text') {
3028
- innerHTML = shared.escapeHtml(shared.toDisplayString(evaluateConstant(p.exp)));
3029
- }
2916
+ if (shared.isBooleanAttr(p.arg.content) && exp.content === "false") {
2917
+ continue;
3030
2918
  }
3031
- }
3032
- if (context.scopeId) {
3033
- res += ` ${context.scopeId}`;
3034
- }
3035
- res += `>`;
3036
- if (innerHTML) {
3037
- res += innerHTML;
3038
- }
3039
- else {
3040
- for (let i = 0; i < node.children.length; i++) {
3041
- res += stringifyNode(node.children[i], context);
2919
+ let evaluated = evaluateConstant(exp);
2920
+ if (evaluated != null) {
2921
+ const arg = p.arg && p.arg.content;
2922
+ if (arg === "class") {
2923
+ evaluated = shared.normalizeClass(evaluated);
2924
+ } else if (arg === "style") {
2925
+ evaluated = shared.stringifyStyle(shared.normalizeStyle(evaluated));
2926
+ }
2927
+ res += ` ${p.arg.content}="${shared.escapeHtml(
2928
+ evaluated
2929
+ )}"`;
3042
2930
  }
2931
+ } else if (p.name === "html") {
2932
+ innerHTML = evaluateConstant(p.exp);
2933
+ } else if (p.name === "text") {
2934
+ innerHTML = shared.escapeHtml(
2935
+ shared.toDisplayString(evaluateConstant(p.exp))
2936
+ );
2937
+ }
3043
2938
  }
3044
- if (!shared.isVoidTag(node.tag)) {
3045
- res += `</${node.tag}>`;
2939
+ }
2940
+ if (context.scopeId) {
2941
+ res += ` ${context.scopeId}`;
2942
+ }
2943
+ res += `>`;
2944
+ if (innerHTML) {
2945
+ res += innerHTML;
2946
+ } else {
2947
+ for (let i = 0; i < node.children.length; i++) {
2948
+ res += stringifyNode(node.children[i], context);
3046
2949
  }
3047
- return res;
2950
+ }
2951
+ if (!shared.isVoidTag(node.tag)) {
2952
+ res += `</${node.tag}>`;
2953
+ }
2954
+ return res;
3048
2955
  }
3049
- // __UNSAFE__
3050
- // Reason: eval.
3051
- // It's technically safe to eval because only constant expressions are possible
3052
- // here, e.g. `{{ 1 }}` or `{{ 'foo' }}`
3053
- // in addition, constant exps bail on presence of parens so you can't even
3054
- // run JSFuck in here. But we mark it unsafe for security review purposes.
3055
- // (see compiler-core/src/transforms/transformExpression)
3056
2956
  function evaluateConstant(exp) {
3057
- if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
3058
- return new Function(`return ${exp.content}`)();
3059
- }
3060
- else {
3061
- // compound
3062
- let res = ``;
3063
- exp.children.forEach(c => {
3064
- if (shared.isString(c) || shared.isSymbol(c)) {
3065
- return;
3066
- }
3067
- if (c.type === 2 /* NodeTypes.TEXT */) {
3068
- res += c.content;
3069
- }
3070
- else if (c.type === 5 /* NodeTypes.INTERPOLATION */) {
3071
- res += shared.toDisplayString(evaluateConstant(c.content));
3072
- }
3073
- else {
3074
- res += evaluateConstant(c);
3075
- }
3076
- });
3077
- return res;
3078
- }
2957
+ if (exp.type === 4) {
2958
+ return new Function(`return ${exp.content}`)();
2959
+ } else {
2960
+ let res = ``;
2961
+ exp.children.forEach((c) => {
2962
+ if (shared.isString(c) || shared.isSymbol(c)) {
2963
+ return;
2964
+ }
2965
+ if (c.type === "text") {
2966
+ res += c.content;
2967
+ } else if (c.type === 5) {
2968
+ res += shared.toDisplayString(evaluateConstant(c.content));
2969
+ } else {
2970
+ res += evaluateConstant(c);
2971
+ }
2972
+ });
2973
+ return res;
2974
+ }
3079
2975
  }
3080
2976
 
3081
2977
  const ignoreSideEffectTags = (node, context) => {
3082
- if (node.type === 1 /* NodeTypes.ELEMENT */ &&
3083
- node.tagType === 0 /* ElementTypes.ELEMENT */ &&
3084
- (node.tag === 'script' || node.tag === 'style')) {
3085
- context.onError(createDOMCompilerError(61 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
3086
- context.removeNode();
3087
- }
2978
+ if (node.type === "element" && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
2979
+ context.onError(
2980
+ createDOMCompilerError(61, node.loc)
2981
+ );
2982
+ context.removeNode();
2983
+ }
3088
2984
  };
3089
2985
 
3090
2986
  const DOMNodeTransforms = [
3091
- transformStyle,
3092
- ...([transformTransition] )
2987
+ transformStyle,
2988
+ ...[transformTransition]
3093
2989
  ];
3094
2990
  const DOMDirectiveTransforms = {
3095
- cloak: compilerCore.noopDirectiveTransform,
3096
- html: transformVHtml,
3097
- text: transformVText,
3098
- model: transformModel,
3099
- on: transformOn,
3100
- show: transformShow
2991
+ cloak: compilerCore.noopDirectiveTransform,
2992
+ html: transformVHtml,
2993
+ text: transformVText,
2994
+ model: transformModel,
2995
+ // override compiler-core
2996
+ on: transformOn,
2997
+ // override compiler-core
2998
+ show: transformShow
3101
2999
  };
3102
3000
  function compile(template, options = {}) {
3103
- return compilerCore.baseCompile(template, shared.extend({}, parserOptions, options, {
3104
- nodeTransforms: [
3105
- // ignore <script> and <tag>
3106
- // this is not put inside DOMNodeTransforms because that list is used
3107
- // by compiler-ssr to generate vnode fallback branches
3108
- ignoreSideEffectTags,
3109
- ...DOMNodeTransforms,
3110
- ...(options.nodeTransforms || [])
3111
- ],
3112
- directiveTransforms: shared.extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
3113
- transformHoist: stringifyStatic
3114
- }));
3001
+ return compilerCore.baseCompile(
3002
+ template,
3003
+ shared.extend({}, parserOptions, options, {
3004
+ nodeTransforms: [
3005
+ // ignore <script> and <tag>
3006
+ // this is not put inside DOMNodeTransforms because that list is used
3007
+ // by compiler-ssr to generate vnode fallback branches
3008
+ ignoreSideEffectTags,
3009
+ ...DOMNodeTransforms,
3010
+ ...options.nodeTransforms || []
3011
+ ],
3012
+ directiveTransforms: shared.extend(
3013
+ {},
3014
+ DOMDirectiveTransforms,
3015
+ options.directiveTransforms || {}
3016
+ ),
3017
+ transformHoist: stringifyStatic
3018
+ })
3019
+ );
3115
3020
  }
3116
3021
  function parse(template, options = {}) {
3117
- return compilerCore.baseParse(template, shared.extend({}, parserOptions, options));
3022
+ return compilerCore.baseParse(template, shared.extend({}, parserOptions, options));
3118
3023
  }
3119
3024
 
3120
3025
  exports.DOMDirectiveTransforms = DOMDirectiveTransforms;