@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(``);
14
16
  const TRANSITION = Symbol(``);
15
17
  const TRANSITION_GROUP = Symbol(``);
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,799 +2262,701 @@ 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
+ );
2293
+ }
2294
+ for (let length = maxCRNameLength; !value && length > 0; --length) {
2295
+ name = rawText.slice(1, 1 + length);
2296
+ value = namedCharacterReferences[name];
2280
2297
  }
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
- }
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);
2318
2310
  }
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
- }
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
- const { tag } = node;
2543
- const isCustomElement = context.isCustomElement(tag);
2544
- if (tag === 'input' ||
2545
- tag === 'textarea' ||
2546
- tag === 'select' ||
2547
- isCustomElement) {
2548
- let directiveToUse = V_MODEL_TEXT;
2549
- let isInvalidType = false;
2550
- if (tag === 'input' || isCustomElement) {
2551
- const type = compilerCore.findProp(node, `type`);
2552
- if (type) {
2553
- if (type.type === 7 /* NodeTypes.DIRECTIVE */) {
2554
- // :type="foo"
2555
- directiveToUse = V_MODEL_DYNAMIC;
2556
- }
2557
- else if (type.value) {
2558
- switch (type.value.content) {
2559
- case 'radio':
2560
- directiveToUse = V_MODEL_RADIO;
2561
- break;
2562
- case 'checkbox':
2563
- directiveToUse = V_MODEL_CHECKBOX;
2564
- break;
2565
- case 'file':
2566
- isInvalidType = true;
2567
- context.onError(createDOMCompilerError(57 /* DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
2568
- break;
2569
- }
2570
- }
2571
- }
2572
- else if (compilerCore.hasDynamicKeyVBind(node)) {
2573
- // element has bindings with dynamic keys, which can possibly contain
2574
- // "type".
2575
- directiveToUse = V_MODEL_DYNAMIC;
2576
- }
2577
- else ;
2578
- }
2579
- else if (tag === 'select') {
2580
- directiveToUse = V_MODEL_SELECT;
2581
- }
2582
- else ;
2583
- // inject runtime directive
2584
- // by returning the helper symbol via needRuntime
2585
- // the import will replaced a resolveDirective call.
2586
- if (!isInvalidType) {
2587
- baseResult.needRuntime = context.helper(directiveToUse);
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
+ const { tag } = node;
2542
+ const isCustomElement = context.isCustomElement(tag);
2543
+ if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
2544
+ let directiveToUse = V_MODEL_TEXT;
2545
+ let isInvalidType = false;
2546
+ if (tag === "input" || isCustomElement) {
2547
+ const type = compilerCore.findProp(node, `type`);
2548
+ if (type) {
2549
+ if (type.type === 7) {
2550
+ directiveToUse = V_MODEL_DYNAMIC;
2551
+ } else if (type.value) {
2552
+ switch (type.value.content) {
2553
+ case "radio":
2554
+ directiveToUse = V_MODEL_RADIO;
2555
+ break;
2556
+ case "checkbox":
2557
+ directiveToUse = V_MODEL_CHECKBOX;
2558
+ break;
2559
+ case "file":
2560
+ isInvalidType = true;
2561
+ context.onError(
2562
+ createDOMCompilerError(
2563
+ 57,
2564
+ dir.loc
2565
+ )
2566
+ );
2567
+ break;
2568
+ }
2588
2569
  }
2570
+ } else if (compilerCore.hasDynamicKeyVBind(node)) {
2571
+ directiveToUse = V_MODEL_DYNAMIC;
2572
+ } else ;
2573
+ } else if (tag === "select") {
2574
+ directiveToUse = V_MODEL_SELECT;
2575
+ } else ;
2576
+ if (!isInvalidType) {
2577
+ baseResult.needRuntime = context.helper(directiveToUse);
2589
2578
  }
2590
- else {
2591
- context.onError(createDOMCompilerError(55 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
2592
- }
2593
- // native vmodel doesn't need the `modelValue` props since they are also
2594
- // passed to the runtime as `binding.value`. removing it reduces code size.
2595
- baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
2596
- p.key.content === 'modelValue'));
2597
- return baseResult;
2579
+ } else {
2580
+ context.onError(
2581
+ createDOMCompilerError(
2582
+ 55,
2583
+ dir.loc
2584
+ )
2585
+ );
2586
+ }
2587
+ baseResult.props = baseResult.props.filter(
2588
+ (p) => !(p.key.type === 4 && p.key.content === "modelValue")
2589
+ );
2590
+ return baseResult;
2598
2591
  };
2599
2592
 
2600
- const isEventOptionModifier = /*#__PURE__*/ shared.makeMap(`passive,once,capture`);
2601
- const isNonKeyModifier = /*#__PURE__*/ shared.makeMap(
2602
- // event propagation management
2603
- `stop,prevent,self,` +
2604
- // system modifiers + exact
2605
- `ctrl,shift,alt,meta,exact,` +
2606
- // mouse
2607
- `middle`);
2608
- // left & right could be mouse or key modifiers based on event type
2609
- const maybeKeyModifier = /*#__PURE__*/ shared.makeMap('left,right');
2610
- const isKeyboardEvent = /*#__PURE__*/ shared.makeMap(`onkeyup,onkeydown,onkeypress`, true);
2593
+ const isEventOptionModifier = /* @__PURE__ */ shared.makeMap(`passive,once,capture`);
2594
+ const isNonKeyModifier = /* @__PURE__ */ shared.makeMap(
2595
+ // event propagation management
2596
+ `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
2597
+ );
2598
+ const maybeKeyModifier = /* @__PURE__ */ shared.makeMap("left,right");
2599
+ const isKeyboardEvent = /* @__PURE__ */ shared.makeMap(
2600
+ `onkeyup,onkeydown,onkeypress`,
2601
+ true
2602
+ );
2611
2603
  const resolveModifiers = (key, modifiers, context, loc) => {
2612
- const keyModifiers = [];
2613
- const nonKeyModifiers = [];
2614
- const eventOptionModifiers = [];
2615
- for (let i = 0; i < modifiers.length; i++) {
2616
- const modifier = modifiers[i];
2617
- if (modifier === 'native' &&
2618
- compilerCore.checkCompatEnabled("COMPILER_V_ON_NATIVE" /* CompilerDeprecationTypes.COMPILER_V_ON_NATIVE */, context, loc)) {
2619
- eventOptionModifiers.push(modifier);
2604
+ const keyModifiers = [];
2605
+ const nonKeyModifiers = [];
2606
+ const eventOptionModifiers = [];
2607
+ for (let i = 0; i < modifiers.length; i++) {
2608
+ const modifier = modifiers[i];
2609
+ if (modifier === "native" && compilerCore.checkCompatEnabled(
2610
+ "COMPILER_V_ON_NATIVE",
2611
+ context,
2612
+ loc
2613
+ )) {
2614
+ eventOptionModifiers.push(modifier);
2615
+ } else if (isEventOptionModifier(modifier)) {
2616
+ eventOptionModifiers.push(modifier);
2617
+ } else {
2618
+ if (maybeKeyModifier(modifier)) {
2619
+ if (compilerCore.isStaticExp(key)) {
2620
+ if (isKeyboardEvent(key.content)) {
2621
+ keyModifiers.push(modifier);
2622
+ } else {
2623
+ nonKeyModifiers.push(modifier);
2624
+ }
2625
+ } else {
2626
+ keyModifiers.push(modifier);
2627
+ nonKeyModifiers.push(modifier);
2620
2628
  }
2621
- else if (isEventOptionModifier(modifier)) {
2622
- // eventOptionModifiers: modifiers for addEventListener() options,
2623
- // e.g. .passive & .capture
2624
- eventOptionModifiers.push(modifier);
2625
- }
2626
- else {
2627
- // runtimeModifiers: modifiers that needs runtime guards
2628
- if (maybeKeyModifier(modifier)) {
2629
- if (compilerCore.isStaticExp(key)) {
2630
- if (isKeyboardEvent(key.content)) {
2631
- keyModifiers.push(modifier);
2632
- }
2633
- else {
2634
- nonKeyModifiers.push(modifier);
2635
- }
2636
- }
2637
- else {
2638
- keyModifiers.push(modifier);
2639
- nonKeyModifiers.push(modifier);
2640
- }
2641
- }
2642
- else {
2643
- if (isNonKeyModifier(modifier)) {
2644
- nonKeyModifiers.push(modifier);
2645
- }
2646
- else {
2647
- keyModifiers.push(modifier);
2648
- }
2649
- }
2629
+ } else {
2630
+ if (isNonKeyModifier(modifier)) {
2631
+ nonKeyModifiers.push(modifier);
2632
+ } else {
2633
+ keyModifiers.push(modifier);
2650
2634
  }
2635
+ }
2651
2636
  }
2652
- return {
2653
- keyModifiers,
2654
- nonKeyModifiers,
2655
- eventOptionModifiers
2656
- };
2637
+ }
2638
+ return {
2639
+ keyModifiers,
2640
+ nonKeyModifiers,
2641
+ eventOptionModifiers
2642
+ };
2657
2643
  };
2658
2644
  const transformClick = (key, event) => {
2659
- const isStaticClick = compilerCore.isStaticExp(key) && key.content.toLowerCase() === 'onclick';
2660
- return isStaticClick
2661
- ? compilerCore.createSimpleExpression(event, true)
2662
- : key.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */
2663
- ? compilerCore.createCompoundExpression([
2664
- `(`,
2665
- key,
2666
- `) === "onClick" ? "${event}" : (`,
2667
- key,
2668
- `)`
2669
- ])
2670
- : key;
2645
+ const isStaticClick = compilerCore.isStaticExp(key) && key.content.toLowerCase() === "onclick";
2646
+ return isStaticClick ? compilerCore.createSimpleExpression(event, true) : key.type !== 4 ? compilerCore.createCompoundExpression([
2647
+ `(`,
2648
+ key,
2649
+ `) === "onClick" ? "${event}" : (`,
2650
+ key,
2651
+ `)`
2652
+ ]) : key;
2671
2653
  };
2672
2654
  const transformOn = (dir, node, context) => {
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
- // normalize click.right and click.middle since they don't actually fire
2680
- if (nonKeyModifiers.includes('right')) {
2681
- key = transformClick(key, `onContextmenu`);
2682
- }
2683
- if (nonKeyModifiers.includes('middle')) {
2684
- key = transformClick(key, `onMouseup`);
2685
- }
2686
- if (nonKeyModifiers.length) {
2687
- handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
2688
- handlerExp,
2689
- JSON.stringify(nonKeyModifiers)
2690
- ]);
2691
- }
2692
- if (keyModifiers.length &&
2693
- // if event name is dynamic, always wrap with keys guard
2694
- (!compilerCore.isStaticExp(key) || isKeyboardEvent(key.content))) {
2695
- handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_KEYS), [
2696
- handlerExp,
2697
- JSON.stringify(keyModifiers)
2698
- ]);
2699
- }
2700
- if (eventOptionModifiers.length) {
2701
- const modifierPostfix = eventOptionModifiers.map(shared.capitalize).join('');
2702
- key = compilerCore.isStaticExp(key)
2703
- ? compilerCore.createSimpleExpression(`${key.content}${modifierPostfix}`, true)
2704
- : compilerCore.createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
2705
- }
2706
- return {
2707
- props: [compilerCore.createObjectProperty(key, handlerExp)]
2708
- };
2709
- });
2710
- };
2711
-
2712
- const transformShow = (dir, node, context) => {
2713
- const { exp, loc } = dir;
2714
- if (!exp) {
2715
- context.onError(createDOMCompilerError(59 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */, loc));
2655
+ return compilerCore.transformOn(dir, node, context, (baseResult) => {
2656
+ const { modifiers } = dir;
2657
+ if (!modifiers.length)
2658
+ return baseResult;
2659
+ let { key, value: handlerExp } = baseResult.props[0];
2660
+ const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
2661
+ if (nonKeyModifiers.includes("right")) {
2662
+ key = transformClick(key, `onContextmenu`);
2663
+ }
2664
+ if (nonKeyModifiers.includes("middle")) {
2665
+ key = transformClick(key, `onMouseup`);
2666
+ }
2667
+ if (nonKeyModifiers.length) {
2668
+ handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
2669
+ handlerExp,
2670
+ JSON.stringify(nonKeyModifiers)
2671
+ ]);
2672
+ }
2673
+ if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
2674
+ (!compilerCore.isStaticExp(key) || isKeyboardEvent(key.content))) {
2675
+ handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_KEYS), [
2676
+ handlerExp,
2677
+ JSON.stringify(keyModifiers)
2678
+ ]);
2679
+ }
2680
+ if (eventOptionModifiers.length) {
2681
+ const modifierPostfix = eventOptionModifiers.map(shared.capitalize).join("");
2682
+ key = compilerCore.isStaticExp(key) ? compilerCore.createSimpleExpression(`${key.content}${modifierPostfix}`, true) : compilerCore.createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
2716
2683
  }
2717
2684
  return {
2718
- props: [],
2719
- needRuntime: context.helper(V_SHOW)
2685
+ props: [compilerCore.createObjectProperty(key, handlerExp)]
2720
2686
  };
2687
+ });
2688
+ };
2689
+
2690
+ const transformShow = (dir, node, context) => {
2691
+ const { exp, loc } = dir;
2692
+ if (!exp) {
2693
+ context.onError(
2694
+ createDOMCompilerError(59, loc)
2695
+ );
2696
+ }
2697
+ return {
2698
+ props: [],
2699
+ needRuntime: context.helper(V_SHOW)
2700
+ };
2721
2701
  };
2722
2702
 
2723
- /**
2724
- * This module is Node-only.
2725
- */
2726
- /**
2727
- * Regex for replacing placeholders for embedded constant variables
2728
- * (e.g. import URL string constants generated by compiler-sfc)
2729
- */
2730
2703
  const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
2731
- /**
2732
- * Turn eligible hoisted static trees into stringified static nodes, e.g.
2733
- *
2734
- * ```js
2735
- * const _hoisted_1 = createStaticVNode(`<div class="foo">bar</div>`)
2736
- * ```
2737
- *
2738
- * A single static vnode can contain stringified content for **multiple**
2739
- * consecutive nodes (element and plain text), called a "chunk".
2740
- * `@vue/runtime-dom` will create the content via innerHTML in a hidden
2741
- * container element and insert all the nodes in place. The call must also
2742
- * provide the number of nodes contained in the chunk so that during hydration
2743
- * we can know how many nodes the static vnode should adopt.
2744
- *
2745
- * The optimization scans a children list that contains hoisted nodes, and
2746
- * tries to find the largest chunk of consecutive hoisted nodes before running
2747
- * into a non-hoisted node or the end of the list. A chunk is then converted
2748
- * into a single static vnode and replaces the hoisted expression of the first
2749
- * node in the chunk. Other nodes in the chunk are considered "merged" and
2750
- * therefore removed from both the hoist list and the children array.
2751
- *
2752
- * This optimization is only performed in Node.js.
2753
- */
2754
2704
  const stringifyStatic = (children, context, parent) => {
2755
- // bail stringification for slot content
2756
- if (context.scopes.vSlot > 0) {
2757
- return;
2758
- }
2759
- let nc = 0; // current node count
2760
- let ec = 0; // current element with binding count
2761
- const currentChunk = [];
2762
- const stringifyCurrentChunk = (currentIndex) => {
2763
- if (nc >= 20 /* StringifyThresholds.NODE_COUNT */ ||
2764
- ec >= 5 /* StringifyThresholds.ELEMENT_WITH_BINDING_COUNT */) {
2765
- // combine all currently eligible nodes into a single static vnode call
2766
- const staticCall = compilerCore.createCallExpression(context.helper(compilerCore.CREATE_STATIC), [
2767
- JSON.stringify(currentChunk.map(node => stringifyNode(node, context)).join('')).replace(expReplaceRE, `" + $1 + "`),
2768
- // the 2nd argument indicates the number of DOM nodes this static vnode
2769
- // will insert / hydrate
2770
- String(currentChunk.length)
2771
- ]);
2772
- // replace the first node's hoisted expression with the static vnode call
2773
- replaceHoist(currentChunk[0], staticCall, context);
2774
- if (currentChunk.length > 1) {
2775
- for (let i = 1; i < currentChunk.length; i++) {
2776
- // for the merged nodes, set their hoisted expression to null
2777
- replaceHoist(currentChunk[i], null, context);
2778
- }
2779
- // also remove merged nodes from children
2780
- const deleteCount = currentChunk.length - 1;
2781
- children.splice(currentIndex - currentChunk.length + 1, deleteCount);
2782
- return deleteCount;
2783
- }
2784
- }
2785
- return 0;
2786
- };
2787
- let i = 0;
2788
- for (; i < children.length; i++) {
2789
- const child = children[i];
2790
- const hoisted = getHoistedNode(child);
2791
- if (hoisted) {
2792
- // presence of hoisted means child must be a stringifiable node
2793
- const node = child;
2794
- const result = analyzeNode(node);
2795
- if (result) {
2796
- // node is stringifiable, record state
2797
- nc += result[0];
2798
- ec += result[1];
2799
- currentChunk.push(node);
2800
- continue;
2801
- }
2705
+ if (context.scopes.vSlot > 0) {
2706
+ return;
2707
+ }
2708
+ let nc = 0;
2709
+ let ec = 0;
2710
+ const currentChunk = [];
2711
+ const stringifyCurrentChunk = (currentIndex) => {
2712
+ if (nc >= 20 || ec >= 5) {
2713
+ const staticCall = compilerCore.createCallExpression(context.helper(compilerCore.CREATE_STATIC), [
2714
+ JSON.stringify(
2715
+ currentChunk.map((node) => stringifyNode(node, context)).join("")
2716
+ ).replace(expReplaceRE, `" + $1 + "`),
2717
+ // the 2nd argument indicates the number of DOM nodes this static vnode
2718
+ // will insert / hydrate
2719
+ String(currentChunk.length)
2720
+ ]);
2721
+ replaceHoist(currentChunk[0], staticCall, context);
2722
+ if (currentChunk.length > 1) {
2723
+ for (let i2 = 1; i2 < currentChunk.length; i2++) {
2724
+ replaceHoist(currentChunk[i2], null, context);
2802
2725
  }
2803
- // we only reach here if we ran into a node that is not stringifiable
2804
- // check if currently analyzed nodes meet criteria for stringification.
2805
- // adjust iteration index
2806
- i -= stringifyCurrentChunk(i);
2807
- // reset state
2808
- nc = 0;
2809
- ec = 0;
2810
- currentChunk.length = 0;
2726
+ const deleteCount = currentChunk.length - 1;
2727
+ children.splice(currentIndex - currentChunk.length + 1, deleteCount);
2728
+ return deleteCount;
2729
+ }
2730
+ }
2731
+ return 0;
2732
+ };
2733
+ let i = 0;
2734
+ for (; i < children.length; i++) {
2735
+ const child = children[i];
2736
+ const hoisted = getHoistedNode(child);
2737
+ if (hoisted) {
2738
+ const node = child;
2739
+ const result = analyzeNode(node);
2740
+ if (result) {
2741
+ nc += result[0];
2742
+ ec += result[1];
2743
+ currentChunk.push(node);
2744
+ continue;
2745
+ }
2811
2746
  }
2812
- // in case the last node was also stringifiable
2813
- stringifyCurrentChunk(i);
2747
+ i -= stringifyCurrentChunk(i);
2748
+ nc = 0;
2749
+ ec = 0;
2750
+ currentChunk.length = 0;
2751
+ }
2752
+ stringifyCurrentChunk(i);
2814
2753
  };
2815
- const getHoistedNode = (node) => ((node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 0 /* ElementTypes.ELEMENT */) ||
2816
- node.type == 12 /* NodeTypes.TEXT_CALL */) &&
2817
- node.codegenNode &&
2818
- node.codegenNode.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
2819
- node.codegenNode.hoisted;
2754
+ const getHoistedNode = (node) => (node.type === "element" && node.tagType === 0 || node.type == 12) && node.codegenNode && node.codegenNode.type === 4 && node.codegenNode.hoisted;
2820
2755
  const dataAriaRE = /^(data|aria)-/;
2821
2756
  const isStringifiableAttr = (name, ns) => {
2822
- return ((ns === 0 /* DOMNamespaces.HTML */
2823
- ? shared.isKnownHtmlAttr(name)
2824
- : ns === 1 /* DOMNamespaces.SVG */
2825
- ? shared.isKnownSvgAttr(name)
2826
- : false) || dataAriaRE.test(name));
2757
+ return (ns === 0 ? shared.isKnownHtmlAttr(name) : ns === 1 ? shared.isKnownSvgAttr(name) : false) || dataAriaRE.test(name);
2827
2758
  };
2828
2759
  const replaceHoist = (node, replacement, context) => {
2829
- const hoistToReplace = node.codegenNode.hoisted;
2830
- context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement;
2760
+ const hoistToReplace = node.codegenNode.hoisted;
2761
+ context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement;
2831
2762
  };
2832
- const isNonStringifiable = /*#__PURE__*/ shared.makeMap(`caption,thead,tr,th,tbody,td,tfoot,colgroup,col`);
2833
- /**
2834
- * for a hoisted node, analyze it and return:
2835
- * - false: bailed (contains non-stringifiable props or runtime constant)
2836
- * - [nc, ec] where
2837
- * - nc is the number of nodes inside
2838
- * - ec is the number of element with bindings inside
2839
- */
2763
+ const isNonStringifiable = /* @__PURE__ */ shared.makeMap(
2764
+ `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
2765
+ );
2840
2766
  function analyzeNode(node) {
2841
- if (node.type === 1 /* NodeTypes.ELEMENT */ && isNonStringifiable(node.tag)) {
2842
- return false;
2843
- }
2844
- if (node.type === 12 /* NodeTypes.TEXT_CALL */) {
2845
- return [1, 0];
2767
+ if (node.type === "element" && isNonStringifiable(node.tag)) {
2768
+ return false;
2769
+ }
2770
+ if (node.type === 12) {
2771
+ return [1, 0];
2772
+ }
2773
+ let nc = 1;
2774
+ let ec = node.props.length > 0 ? 1 : 0;
2775
+ let bailed = false;
2776
+ const bail = () => {
2777
+ bailed = true;
2778
+ return false;
2779
+ };
2780
+ function walk(node2) {
2781
+ for (let i = 0; i < node2.props.length; i++) {
2782
+ const p = node2.props[i];
2783
+ if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
2784
+ return bail();
2785
+ }
2786
+ if (p.type === 7 && p.name === "bind") {
2787
+ if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
2788
+ return bail();
2789
+ }
2790
+ if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
2791
+ return bail();
2792
+ }
2793
+ }
2846
2794
  }
2847
- let nc = 1; // node count
2848
- let ec = node.props.length > 0 ? 1 : 0; // element w/ binding count
2849
- let bailed = false;
2850
- const bail = () => {
2851
- bailed = true;
2852
- return false;
2853
- };
2854
- // TODO: check for cases where using innerHTML will result in different
2855
- // output compared to imperative node insertions.
2856
- // probably only need to check for most common case
2857
- // i.e. non-phrasing-content tags inside `<p>`
2858
- function walk(node) {
2859
- for (let i = 0; i < node.props.length; i++) {
2860
- const p = node.props[i];
2861
- // bail on non-attr bindings
2862
- if (p.type === 6 /* NodeTypes.ATTRIBUTE */ &&
2863
- !isStringifiableAttr(p.name, node.ns)) {
2864
- return bail();
2865
- }
2866
- if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'bind') {
2867
- // bail on non-attr bindings
2868
- if (p.arg &&
2869
- (p.arg.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */ ||
2870
- (p.arg.isStatic && !isStringifiableAttr(p.arg.content, node.ns)))) {
2871
- return bail();
2872
- }
2873
- if (p.exp &&
2874
- (p.exp.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */ ||
2875
- p.exp.constType < 3 /* ConstantTypes.CAN_STRINGIFY */)) {
2876
- return bail();
2877
- }
2878
- }
2795
+ for (let i = 0; i < node2.children.length; i++) {
2796
+ nc++;
2797
+ const child = node2.children[i];
2798
+ if (child.type === "element") {
2799
+ if (child.props.length > 0) {
2800
+ ec++;
2879
2801
  }
2880
- for (let i = 0; i < node.children.length; i++) {
2881
- nc++;
2882
- const child = node.children[i];
2883
- if (child.type === 1 /* NodeTypes.ELEMENT */) {
2884
- if (child.props.length > 0) {
2885
- ec++;
2886
- }
2887
- walk(child);
2888
- if (bailed) {
2889
- return false;
2890
- }
2891
- }
2802
+ walk(child);
2803
+ if (bailed) {
2804
+ return false;
2892
2805
  }
2893
- return true;
2806
+ }
2894
2807
  }
2895
- return walk(node) ? [nc, ec] : false;
2808
+ return true;
2809
+ }
2810
+ return walk(node) ? [nc, ec] : false;
2896
2811
  }
2897
2812
  function stringifyNode(node, context) {
2898
- if (shared.isString(node)) {
2899
- return node;
2900
- }
2901
- if (shared.isSymbol(node)) {
2902
- return ``;
2903
- }
2904
- switch (node.type) {
2905
- case 1 /* NodeTypes.ELEMENT */:
2906
- return stringifyElement(node, context);
2907
- case 2 /* NodeTypes.TEXT */:
2908
- return shared.escapeHtml(node.content);
2909
- case 3 /* NodeTypes.COMMENT */:
2910
- return `<!--${shared.escapeHtml(node.content)}-->`;
2911
- case 5 /* NodeTypes.INTERPOLATION */:
2912
- return shared.escapeHtml(shared.toDisplayString(evaluateConstant(node.content)));
2913
- case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
2914
- return shared.escapeHtml(evaluateConstant(node));
2915
- case 12 /* NodeTypes.TEXT_CALL */:
2916
- return stringifyNode(node.content, context);
2917
- default:
2918
- // static trees will not contain if/for nodes
2919
- return '';
2920
- }
2813
+ if (shared.isString(node)) {
2814
+ return node;
2815
+ }
2816
+ if (shared.isSymbol(node)) {
2817
+ return ``;
2818
+ }
2819
+ switch (node.type) {
2820
+ case "element":
2821
+ return stringifyElement(node, context);
2822
+ case "text":
2823
+ return shared.escapeHtml(node.content);
2824
+ case "comment":
2825
+ return `<!--${shared.escapeHtml(node.content)}-->`;
2826
+ case 5:
2827
+ return shared.escapeHtml(shared.toDisplayString(evaluateConstant(node.content)));
2828
+ case 8:
2829
+ return shared.escapeHtml(evaluateConstant(node));
2830
+ case 12:
2831
+ return stringifyNode(node.content, context);
2832
+ default:
2833
+ return "";
2834
+ }
2921
2835
  }
2922
2836
  function stringifyElement(node, context) {
2923
- let res = `<${node.tag}`;
2924
- let innerHTML = '';
2925
- for (let i = 0; i < node.props.length; i++) {
2926
- const p = node.props[i];
2927
- if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
2928
- res += ` ${p.name}`;
2929
- if (p.value) {
2930
- res += `="${shared.escapeHtml(p.value.content)}"`;
2931
- }
2837
+ let res = `<${node.tag}`;
2838
+ let innerHTML = "";
2839
+ for (let i = 0; i < node.props.length; i++) {
2840
+ const p = node.props[i];
2841
+ if (p.type === 6) {
2842
+ res += ` ${p.name}`;
2843
+ if (p.value) {
2844
+ res += `="${shared.escapeHtml(p.value.content)}"`;
2845
+ }
2846
+ } else if (p.type === 7) {
2847
+ if (p.name === "bind") {
2848
+ const exp = p.exp;
2849
+ if (exp.content[0] === "_") {
2850
+ res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
2851
+ continue;
2932
2852
  }
2933
- else if (p.type === 7 /* NodeTypes.DIRECTIVE */) {
2934
- if (p.name === 'bind') {
2935
- const exp = p.exp;
2936
- if (exp.content[0] === '_') {
2937
- // internally generated string constant references
2938
- // e.g. imported URL strings via compiler-sfc transformAssetUrl plugin
2939
- res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
2940
- continue;
2941
- }
2942
- // #6568
2943
- if (shared.isBooleanAttr(p.arg.content) &&
2944
- exp.content === 'false') {
2945
- continue;
2946
- }
2947
- // constant v-bind, e.g. :foo="1"
2948
- let evaluated = evaluateConstant(exp);
2949
- if (evaluated != null) {
2950
- const arg = p.arg && p.arg.content;
2951
- if (arg === 'class') {
2952
- evaluated = shared.normalizeClass(evaluated);
2953
- }
2954
- else if (arg === 'style') {
2955
- evaluated = shared.stringifyStyle(shared.normalizeStyle(evaluated));
2956
- }
2957
- res += ` ${p.arg.content}="${shared.escapeHtml(evaluated)}"`;
2958
- }
2959
- }
2960
- else if (p.name === 'html') {
2961
- // #5439 v-html with constant value
2962
- // not sure why would anyone do this but it can happen
2963
- innerHTML = evaluateConstant(p.exp);
2964
- }
2965
- else if (p.name === 'text') {
2966
- innerHTML = shared.escapeHtml(shared.toDisplayString(evaluateConstant(p.exp)));
2967
- }
2853
+ if (shared.isBooleanAttr(p.arg.content) && exp.content === "false") {
2854
+ continue;
2968
2855
  }
2969
- }
2970
- if (context.scopeId) {
2971
- res += ` ${context.scopeId}`;
2972
- }
2973
- res += `>`;
2974
- if (innerHTML) {
2975
- res += innerHTML;
2976
- }
2977
- else {
2978
- for (let i = 0; i < node.children.length; i++) {
2979
- res += stringifyNode(node.children[i], context);
2856
+ let evaluated = evaluateConstant(exp);
2857
+ if (evaluated != null) {
2858
+ const arg = p.arg && p.arg.content;
2859
+ if (arg === "class") {
2860
+ evaluated = shared.normalizeClass(evaluated);
2861
+ } else if (arg === "style") {
2862
+ evaluated = shared.stringifyStyle(shared.normalizeStyle(evaluated));
2863
+ }
2864
+ res += ` ${p.arg.content}="${shared.escapeHtml(
2865
+ evaluated
2866
+ )}"`;
2980
2867
  }
2868
+ } else if (p.name === "html") {
2869
+ innerHTML = evaluateConstant(p.exp);
2870
+ } else if (p.name === "text") {
2871
+ innerHTML = shared.escapeHtml(
2872
+ shared.toDisplayString(evaluateConstant(p.exp))
2873
+ );
2874
+ }
2981
2875
  }
2982
- if (!shared.isVoidTag(node.tag)) {
2983
- res += `</${node.tag}>`;
2876
+ }
2877
+ if (context.scopeId) {
2878
+ res += ` ${context.scopeId}`;
2879
+ }
2880
+ res += `>`;
2881
+ if (innerHTML) {
2882
+ res += innerHTML;
2883
+ } else {
2884
+ for (let i = 0; i < node.children.length; i++) {
2885
+ res += stringifyNode(node.children[i], context);
2984
2886
  }
2985
- return res;
2887
+ }
2888
+ if (!shared.isVoidTag(node.tag)) {
2889
+ res += `</${node.tag}>`;
2890
+ }
2891
+ return res;
2986
2892
  }
2987
- // __UNSAFE__
2988
- // Reason: eval.
2989
- // It's technically safe to eval because only constant expressions are possible
2990
- // here, e.g. `{{ 1 }}` or `{{ 'foo' }}`
2991
- // in addition, constant exps bail on presence of parens so you can't even
2992
- // run JSFuck in here. But we mark it unsafe for security review purposes.
2993
- // (see compiler-core/src/transforms/transformExpression)
2994
2893
  function evaluateConstant(exp) {
2995
- if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
2996
- return new Function(`return ${exp.content}`)();
2997
- }
2998
- else {
2999
- // compound
3000
- let res = ``;
3001
- exp.children.forEach(c => {
3002
- if (shared.isString(c) || shared.isSymbol(c)) {
3003
- return;
3004
- }
3005
- if (c.type === 2 /* NodeTypes.TEXT */) {
3006
- res += c.content;
3007
- }
3008
- else if (c.type === 5 /* NodeTypes.INTERPOLATION */) {
3009
- res += shared.toDisplayString(evaluateConstant(c.content));
3010
- }
3011
- else {
3012
- res += evaluateConstant(c);
3013
- }
3014
- });
3015
- return res;
3016
- }
2894
+ if (exp.type === 4) {
2895
+ return new Function(`return ${exp.content}`)();
2896
+ } else {
2897
+ let res = ``;
2898
+ exp.children.forEach((c) => {
2899
+ if (shared.isString(c) || shared.isSymbol(c)) {
2900
+ return;
2901
+ }
2902
+ if (c.type === "text") {
2903
+ res += c.content;
2904
+ } else if (c.type === 5) {
2905
+ res += shared.toDisplayString(evaluateConstant(c.content));
2906
+ } else {
2907
+ res += evaluateConstant(c);
2908
+ }
2909
+ });
2910
+ return res;
2911
+ }
3017
2912
  }
3018
2913
 
3019
2914
  const ignoreSideEffectTags = (node, context) => {
3020
- if (node.type === 1 /* NodeTypes.ELEMENT */ &&
3021
- node.tagType === 0 /* ElementTypes.ELEMENT */ &&
3022
- (node.tag === 'script' || node.tag === 'style')) {
3023
- context.onError(createDOMCompilerError(61 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
3024
- context.removeNode();
3025
- }
2915
+ if (node.type === "element" && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
2916
+ context.onError(
2917
+ createDOMCompilerError(61, node.loc)
2918
+ );
2919
+ context.removeNode();
2920
+ }
3026
2921
  };
3027
2922
 
3028
2923
  const DOMNodeTransforms = [
3029
- transformStyle,
3030
- ...([])
2924
+ transformStyle,
2925
+ ...[]
3031
2926
  ];
3032
2927
  const DOMDirectiveTransforms = {
3033
- cloak: compilerCore.noopDirectiveTransform,
3034
- html: transformVHtml,
3035
- text: transformVText,
3036
- model: transformModel,
3037
- on: transformOn,
3038
- show: transformShow
2928
+ cloak: compilerCore.noopDirectiveTransform,
2929
+ html: transformVHtml,
2930
+ text: transformVText,
2931
+ model: transformModel,
2932
+ // override compiler-core
2933
+ on: transformOn,
2934
+ // override compiler-core
2935
+ show: transformShow
3039
2936
  };
3040
2937
  function compile(template, options = {}) {
3041
- return compilerCore.baseCompile(template, shared.extend({}, parserOptions, options, {
3042
- nodeTransforms: [
3043
- // ignore <script> and <tag>
3044
- // this is not put inside DOMNodeTransforms because that list is used
3045
- // by compiler-ssr to generate vnode fallback branches
3046
- ignoreSideEffectTags,
3047
- ...DOMNodeTransforms,
3048
- ...(options.nodeTransforms || [])
3049
- ],
3050
- directiveTransforms: shared.extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
3051
- transformHoist: stringifyStatic
3052
- }));
2938
+ return compilerCore.baseCompile(
2939
+ template,
2940
+ shared.extend({}, parserOptions, options, {
2941
+ nodeTransforms: [
2942
+ // ignore <script> and <tag>
2943
+ // this is not put inside DOMNodeTransforms because that list is used
2944
+ // by compiler-ssr to generate vnode fallback branches
2945
+ ignoreSideEffectTags,
2946
+ ...DOMNodeTransforms,
2947
+ ...options.nodeTransforms || []
2948
+ ],
2949
+ directiveTransforms: shared.extend(
2950
+ {},
2951
+ DOMDirectiveTransforms,
2952
+ options.directiveTransforms || {}
2953
+ ),
2954
+ transformHoist: stringifyStatic
2955
+ })
2956
+ );
3053
2957
  }
3054
2958
  function parse(template, options = {}) {
3055
- return compilerCore.baseParse(template, shared.extend({}, parserOptions, options));
2959
+ return compilerCore.baseParse(template, shared.extend({}, parserOptions, options));
3056
2960
  }
3057
2961
 
3058
2962
  exports.DOMDirectiveTransforms = DOMDirectiveTransforms;