1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import * as Vue from 'vue';
|
9 | import { nextTick, setDevtoolsHook, Transition, BaseTransition, TransitionGroup, defineComponent, h, isRef, shallowReactive, reactive, ref, createApp, transformVNodeArgs, initDirectivesForSSR, createVNode, ssrContextKey, warn, Fragment, Static, Comment, Text, mergeProps, ssrUtils, computed } from 'vue';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | var extendStatics = function(d, b) {
|
28 | extendStatics = Object.setPrototypeOf ||
|
29 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
30 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
31 | return extendStatics(d, b);
|
32 | };
|
33 |
|
34 | function __extends(d, b) {
|
35 | if (typeof b !== "function" && b !== null)
|
36 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
37 | extendStatics(d, b);
|
38 | function __() { this.constructor = d; }
|
39 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
40 | }
|
41 |
|
42 | var __assign = function() {
|
43 | __assign = Object.assign || function __assign(t) {
|
44 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
45 | s = arguments[i];
|
46 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
47 | }
|
48 | return t;
|
49 | };
|
50 | return __assign.apply(this, arguments);
|
51 | };
|
52 |
|
53 | function __awaiter(thisArg, _arguments, P, generator) {
|
54 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
55 | return new (P || (P = Promise))(function (resolve, reject) {
|
56 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
57 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
58 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
59 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
60 | });
|
61 | }
|
62 |
|
63 | function __generator(thisArg, body) {
|
64 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
65 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
66 | function verb(n) { return function (v) { return step([n, v]); }; }
|
67 | function step(op) {
|
68 | if (f) throw new TypeError("Generator is already executing.");
|
69 | while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
70 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
71 | if (y = 0, t) op = [op[0] & 2, t.value];
|
72 | switch (op[0]) {
|
73 | case 0: case 1: t = op; break;
|
74 | case 4: _.label++; return { value: op[1], done: false };
|
75 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
76 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
77 | default:
|
78 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
79 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
80 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
81 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
82 | if (t[2]) _.ops.pop();
|
83 | _.trys.pop(); continue;
|
84 | }
|
85 | op = body.call(thisArg, _);
|
86 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
87 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
88 | }
|
89 | }
|
90 |
|
91 | function __spreadArray(to, from, pack) {
|
92 | if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
93 | if (ar || !(i in from)) {
|
94 | if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
95 | ar[i] = from[i];
|
96 | }
|
97 | }
|
98 | return to.concat(ar || Array.prototype.slice.call(from));
|
99 | }
|
100 |
|
101 | typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
102 | var e = new Error(message);
|
103 | return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
104 | };
|
105 |
|
106 | var Pluggable = (function () {
|
107 | function Pluggable() {
|
108 | this.installedPlugins = [];
|
109 | }
|
110 | Pluggable.prototype.install = function (handler, options) {
|
111 | if (typeof handler !== 'function') {
|
112 | console.error('plugin.install must receive a function');
|
113 | handler = function () { return ({}); };
|
114 | }
|
115 | this.installedPlugins.push({ handler: handler, options: options });
|
116 | };
|
117 | Pluggable.prototype.extend = function (instance) {
|
118 | var invokeSetup = function (_a) {
|
119 | var handler = _a.handler, options = _a.options;
|
120 | return handler(instance, options);
|
121 | };
|
122 | var bindProperty = function (_a) {
|
123 | var property = _a[0], value = _a[1];
|
124 | instance[property] =
|
125 | typeof value === 'function' ? value.bind(instance) : value;
|
126 | };
|
127 | var addAllPropertiesFromSetup = function (setupResult) {
|
128 | setupResult = typeof setupResult === 'object' ? setupResult : {};
|
129 | Object.entries(setupResult).forEach(bindProperty);
|
130 | };
|
131 | this.installedPlugins.map(invokeSetup).forEach(addAllPropertiesFromSetup);
|
132 | };
|
133 |
|
134 | Pluggable.prototype.reset = function () {
|
135 | this.installedPlugins = [];
|
136 | };
|
137 | return Pluggable;
|
138 | }());
|
139 | var config = {
|
140 | global: {
|
141 | stubs: {
|
142 | transition: true,
|
143 | 'transition-group': true
|
144 | },
|
145 | provide: {},
|
146 | components: {},
|
147 | config: {},
|
148 | directives: {},
|
149 | mixins: [],
|
150 | mocks: {},
|
151 | plugins: [],
|
152 | renderStubDefaultSlot: false
|
153 | },
|
154 | plugins: {
|
155 | VueWrapper: new Pluggable(),
|
156 | DOMWrapper: new Pluggable()
|
157 | }
|
158 | };
|
159 |
|
160 | function mergeStubs(target, source) {
|
161 | if (source.stubs) {
|
162 | if (Array.isArray(source.stubs)) {
|
163 | source.stubs.forEach(function (x) { return (target[x] = true); });
|
164 | }
|
165 | else {
|
166 | for (var _i = 0, _a = Object.entries(source.stubs); _i < _a.length; _i++) {
|
167 | var _b = _a[_i], k = _b[0], v = _b[1];
|
168 | target[k] = v;
|
169 | }
|
170 | }
|
171 | }
|
172 | }
|
173 |
|
174 |
|
175 | function mergeAppConfig(configGlobalConfig, mountGlobalConfig) {
|
176 | return __assign(__assign(__assign({}, configGlobalConfig), mountGlobalConfig), { globalProperties: __assign(__assign({}, configGlobalConfig === null || configGlobalConfig === void 0 ? void 0 : configGlobalConfig.globalProperties), mountGlobalConfig === null || mountGlobalConfig === void 0 ? void 0 : mountGlobalConfig.globalProperties) });
|
177 | }
|
178 | function mergeGlobalProperties(mountGlobal) {
|
179 | var _a, _b, _c;
|
180 | if (mountGlobal === void 0) { mountGlobal = {}; }
|
181 | var stubs = {};
|
182 | var configGlobal = (_a = config === null || config === void 0 ? void 0 : config.global) !== null && _a !== void 0 ? _a : {};
|
183 | mergeStubs(stubs, configGlobal);
|
184 | mergeStubs(stubs, mountGlobal);
|
185 | var renderStubDefaultSlot = (_c = (_b = mountGlobal.renderStubDefaultSlot) !== null && _b !== void 0 ? _b : (configGlobal.renderStubDefaultSlot || (config === null || config === void 0 ? void 0 : config.renderStubDefaultSlot))) !== null && _c !== void 0 ? _c : false;
|
186 | if (config.renderStubDefaultSlot === true) {
|
187 | console.warn('config.renderStubDefaultSlot is deprecated, use config.global.renderStubDefaultSlot instead');
|
188 | }
|
189 | return {
|
190 | mixins: __spreadArray(__spreadArray([], (configGlobal.mixins || []), true), (mountGlobal.mixins || []), true),
|
191 | plugins: __spreadArray(__spreadArray([], (configGlobal.plugins || []), true), (mountGlobal.plugins || []), true),
|
192 | stubs: stubs,
|
193 | components: __assign(__assign({}, configGlobal.components), mountGlobal.components),
|
194 | provide: __assign(__assign({}, configGlobal.provide), mountGlobal.provide),
|
195 | mocks: __assign(__assign({}, configGlobal.mocks), mountGlobal.mocks),
|
196 | config: mergeAppConfig(configGlobal.config, mountGlobal.config),
|
197 | directives: __assign(__assign({}, configGlobal.directives), mountGlobal.directives),
|
198 | renderStubDefaultSlot: renderStubDefaultSlot
|
199 | };
|
200 | }
|
201 | var isObject$1 = function (obj) {
|
202 | return !!obj && typeof obj === 'object';
|
203 | };
|
204 | function isClass(obj) {
|
205 | if (!(obj instanceof Object))
|
206 | return;
|
207 | var isCtorClass = obj.constructor && obj.constructor.toString().substring(0, 5) === 'class';
|
208 | if (!('prototype' in obj)) {
|
209 | return isCtorClass;
|
210 | }
|
211 | var prototype = obj.prototype;
|
212 | var isPrototypeCtorClass = prototype.constructor &&
|
213 | prototype.constructor.toString &&
|
214 | prototype.constructor.toString().substring(0, 5) === 'class';
|
215 | return isCtorClass || isPrototypeCtorClass;
|
216 | }
|
217 |
|
218 | var mergeDeep = function (target, source) {
|
219 | var _a;
|
220 | if (!isObject$1(target) || !isObject$1(source)) {
|
221 | return source;
|
222 | }
|
223 | Object.keys(source)
|
224 | .concat(isClass(source)
|
225 | ? Object.getOwnPropertyNames((_a = Object.getPrototypeOf(source)) !== null && _a !== void 0 ? _a : {})
|
226 | : Object.getOwnPropertyNames(source))
|
227 | .forEach(function (key) {
|
228 | var targetValue = target[key];
|
229 | var sourceValue = source[key];
|
230 | if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
|
231 | target[key] = sourceValue;
|
232 | }
|
233 | else if (sourceValue instanceof Date) {
|
234 | target[key] = sourceValue;
|
235 | }
|
236 | else if (isObject$1(targetValue) && isObject$1(sourceValue)) {
|
237 | target[key] = mergeDeep(Object.assign({}, targetValue), sourceValue);
|
238 | }
|
239 | else {
|
240 | target[key] = sourceValue;
|
241 | }
|
242 | });
|
243 | return target;
|
244 | };
|
245 | function isClassComponent(component) {
|
246 | return typeof component === 'function' && '__vccOpts' in component;
|
247 | }
|
248 | function isComponent$1(component) {
|
249 | return Boolean(component &&
|
250 | (typeof component === 'object' || typeof component === 'function'));
|
251 | }
|
252 | function isFunctionalComponent(component) {
|
253 | return typeof component === 'function' && !isClassComponent(component);
|
254 | }
|
255 | function isObjectComponent(component) {
|
256 | return Boolean(component && typeof component === 'object');
|
257 | }
|
258 | function textContent(element) {
|
259 | var _a, _b;
|
260 |
|
261 |
|
262 | return element.nodeType !== Node.COMMENT_NODE
|
263 | ? (_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : ''
|
264 | : '';
|
265 | }
|
266 | function hasOwnProperty(obj, prop) {
|
267 | return obj.hasOwnProperty(prop);
|
268 | }
|
269 | function isNotNullOrUndefined(obj) {
|
270 | return Boolean(obj);
|
271 | }
|
272 | function isRefSelector(selector) {
|
273 | return typeof selector === 'object' && 'ref' in selector;
|
274 | }
|
275 | function convertStubsToRecord(stubs) {
|
276 | if (Array.isArray(stubs)) {
|
277 |
|
278 | return stubs.reduce(function (acc, current) {
|
279 | acc[current] = true;
|
280 | return acc;
|
281 | }, {});
|
282 | }
|
283 | return stubs;
|
284 | }
|
285 | var isDirectiveKey = function (key) { return key.match(/^v[A-Z].*/); };
|
286 | function getComponentsFromStubs(stubs) {
|
287 | var normalizedStubs = convertStubsToRecord(stubs);
|
288 | return Object.fromEntries(Object.entries(normalizedStubs).filter(function (_a) {
|
289 | var key = _a[0];
|
290 | return !isDirectiveKey(key);
|
291 | }));
|
292 | }
|
293 | function getDirectivesFromStubs(stubs) {
|
294 | var normalizedStubs = convertStubsToRecord(stubs);
|
295 | return Object.fromEntries(Object.entries(normalizedStubs)
|
296 | .filter(function (_a) {
|
297 | var key = _a[0], value = _a[1];
|
298 | return isDirectiveKey(key) && value !== false;
|
299 | })
|
300 | .map(function (_a) {
|
301 | var key = _a[0], value = _a[1];
|
302 | return [key.substring(1), value];
|
303 | }));
|
304 | }
|
305 | function hasSetupState(vm) {
|
306 | return (vm &&
|
307 | vm.$.devtoolsRawSetupState);
|
308 | }
|
309 | function isScriptSetup(vm) {
|
310 | return (vm && vm.$.setupState.__isScriptSetup);
|
311 | }
|
312 | var _globalThis$1;
|
313 | var getGlobalThis$1 = function () {
|
314 | return (_globalThis$1 ||
|
315 | (_globalThis$1 =
|
316 | typeof globalThis !== 'undefined'
|
317 | ? globalThis
|
318 | : typeof self !== 'undefined'
|
319 | ? self
|
320 | : typeof window !== 'undefined'
|
321 | ? window
|
322 | : typeof global !== 'undefined'
|
323 | ? global
|
324 | : {}));
|
325 | };
|
326 |
|
327 | var ignorableKeyModifiers = [
|
328 | 'stop',
|
329 | 'prevent',
|
330 | 'self',
|
331 | 'exact',
|
332 | 'prevent',
|
333 | 'capture'
|
334 | ];
|
335 | var systemKeyModifiers = ['ctrl', 'shift', 'alt', 'meta'];
|
336 | var mouseKeyModifiers = ['left', 'middle', 'right'];
|
337 | var keyCodesByKeyName = {
|
338 | backspace: 8,
|
339 | tab: 9,
|
340 | enter: 13,
|
341 | esc: 27,
|
342 | space: 32,
|
343 | pageup: 33,
|
344 | pagedown: 34,
|
345 | end: 35,
|
346 | home: 36,
|
347 | left: 37,
|
348 | up: 38,
|
349 | right: 39,
|
350 | down: 40,
|
351 | insert: 45,
|
352 | delete: 46
|
353 | };
|
354 | var domEvents = {
|
355 | abort: {
|
356 | eventInterface: 'Event',
|
357 | bubbles: false,
|
358 | cancelable: false
|
359 | },
|
360 | afterprint: {
|
361 | eventInterface: 'Event',
|
362 | bubbles: false,
|
363 | cancelable: false
|
364 | },
|
365 | animationend: {
|
366 | eventInterface: 'AnimationEvent',
|
367 | bubbles: true,
|
368 | cancelable: false
|
369 | },
|
370 | animationiteration: {
|
371 | eventInterface: 'AnimationEvent',
|
372 | bubbles: true,
|
373 | cancelable: false
|
374 | },
|
375 | animationstart: {
|
376 | eventInterface: 'AnimationEvent',
|
377 | bubbles: true,
|
378 | cancelable: false
|
379 | },
|
380 | appinstalled: {
|
381 | eventInterface: 'Event',
|
382 | bubbles: false,
|
383 | cancelable: false
|
384 | },
|
385 | |
386 |
|
387 |
|
388 | audioprocess: {
|
389 | eventInterface: 'AudioProcessingEvent',
|
390 | bubbles: false,
|
391 | cancelable: false
|
392 | },
|
393 | audioend: {
|
394 | eventInterface: 'Event',
|
395 | bubbles: false,
|
396 | cancelable: false
|
397 | },
|
398 | audiostart: {
|
399 | eventInterface: 'Event',
|
400 | bubbles: false,
|
401 | cancelable: false
|
402 | },
|
403 | beforeprint: {
|
404 | eventInterface: 'Event',
|
405 | bubbles: false,
|
406 | cancelable: false
|
407 | },
|
408 | beforeunload: {
|
409 | eventInterface: 'BeforeUnloadEvent',
|
410 | bubbles: false,
|
411 | cancelable: true
|
412 | },
|
413 | beginEvent: {
|
414 | eventInterface: 'TimeEvent',
|
415 | bubbles: false,
|
416 | cancelable: false
|
417 | },
|
418 | blur: {
|
419 | eventInterface: 'FocusEvent',
|
420 | bubbles: false,
|
421 | cancelable: false
|
422 | },
|
423 | boundary: {
|
424 | eventInterface: 'SpeechSynthesisEvent',
|
425 | bubbles: false,
|
426 | cancelable: false
|
427 | },
|
428 | cached: {
|
429 | eventInterface: 'Event',
|
430 | bubbles: false,
|
431 | cancelable: false
|
432 | },
|
433 | canplay: {
|
434 | eventInterface: 'Event',
|
435 | bubbles: false,
|
436 | cancelable: false
|
437 | },
|
438 | canplaythrough: {
|
439 | eventInterface: 'Event',
|
440 | bubbles: false,
|
441 | cancelable: false
|
442 | },
|
443 | change: {
|
444 | eventInterface: 'Event',
|
445 | bubbles: true,
|
446 | cancelable: false
|
447 | },
|
448 | chargingchange: {
|
449 | eventInterface: 'Event',
|
450 | bubbles: false,
|
451 | cancelable: false
|
452 | },
|
453 | chargingtimechange: {
|
454 | eventInterface: 'Event',
|
455 | bubbles: false,
|
456 | cancelable: false
|
457 | },
|
458 | checking: {
|
459 | eventInterface: 'Event',
|
460 | bubbles: false,
|
461 | cancelable: false
|
462 | },
|
463 | click: {
|
464 | eventInterface: 'MouseEvent',
|
465 | bubbles: true,
|
466 | cancelable: true
|
467 | },
|
468 | close: {
|
469 | eventInterface: 'Event',
|
470 | bubbles: false,
|
471 | cancelable: false
|
472 | },
|
473 | complete: {
|
474 | eventInterface: 'OfflineAudioCompletionEvent',
|
475 | bubbles: false,
|
476 | cancelable: false
|
477 | },
|
478 | compositionend: {
|
479 | eventInterface: 'CompositionEvent',
|
480 | bubbles: true,
|
481 | cancelable: true
|
482 | },
|
483 | compositionstart: {
|
484 | eventInterface: 'CompositionEvent',
|
485 | bubbles: true,
|
486 | cancelable: true
|
487 | },
|
488 | compositionupdate: {
|
489 | eventInterface: 'CompositionEvent',
|
490 | bubbles: true,
|
491 | cancelable: false
|
492 | },
|
493 | contextmenu: {
|
494 | eventInterface: 'MouseEvent',
|
495 | bubbles: true,
|
496 | cancelable: true
|
497 | },
|
498 | copy: {
|
499 | eventInterface: 'ClipboardEvent',
|
500 | bubbles: true,
|
501 | cancelable: true
|
502 | },
|
503 | cut: {
|
504 | eventInterface: 'ClipboardEvent',
|
505 | bubbles: true,
|
506 | cancelable: true
|
507 | },
|
508 | dblclick: {
|
509 | eventInterface: 'MouseEvent',
|
510 | bubbles: true,
|
511 | cancelable: true
|
512 | },
|
513 | devicechange: {
|
514 | eventInterface: 'Event',
|
515 | bubbles: false,
|
516 | cancelable: false
|
517 | },
|
518 | devicelight: {
|
519 | eventInterface: 'DeviceLightEvent',
|
520 | bubbles: false,
|
521 | cancelable: false
|
522 | },
|
523 | devicemotion: {
|
524 | eventInterface: 'DeviceMotionEvent',
|
525 | bubbles: false,
|
526 | cancelable: false
|
527 | },
|
528 | deviceorientation: {
|
529 | eventInterface: 'DeviceOrientationEvent',
|
530 | bubbles: false,
|
531 | cancelable: false
|
532 | },
|
533 | deviceproximity: {
|
534 | eventInterface: 'DeviceProximityEvent',
|
535 | bubbles: false,
|
536 | cancelable: false
|
537 | },
|
538 | dischargingtimechange: {
|
539 | eventInterface: 'Event',
|
540 | bubbles: false,
|
541 | cancelable: false
|
542 | },
|
543 | DOMActivate: {
|
544 | eventInterface: 'UIEvent',
|
545 | bubbles: true,
|
546 | cancelable: true
|
547 | },
|
548 | DOMAttributeNameChanged: {
|
549 | eventInterface: 'MutationNameEvent',
|
550 | bubbles: true,
|
551 | cancelable: true
|
552 | },
|
553 | DOMAttrModified: {
|
554 | eventInterface: 'MutationEvent',
|
555 | bubbles: true,
|
556 | cancelable: true
|
557 | },
|
558 | DOMCharacterDataModified: {
|
559 | eventInterface: 'MutationEvent',
|
560 | bubbles: true,
|
561 | cancelable: true
|
562 | },
|
563 | DOMContentLoaded: {
|
564 | eventInterface: 'Event',
|
565 | bubbles: true,
|
566 | cancelable: true
|
567 | },
|
568 | DOMElementNameChanged: {
|
569 | eventInterface: 'MutationNameEvent',
|
570 | bubbles: true,
|
571 | cancelable: true
|
572 | },
|
573 | DOMFocusIn: {
|
574 | eventInterface: 'FocusEvent',
|
575 | bubbles: true,
|
576 | cancelable: true
|
577 | },
|
578 | DOMFocusOut: {
|
579 | eventInterface: 'FocusEvent',
|
580 | bubbles: true,
|
581 | cancelable: true
|
582 | },
|
583 | DOMNodeInserted: {
|
584 | eventInterface: 'MutationEvent',
|
585 | bubbles: true,
|
586 | cancelable: true
|
587 | },
|
588 | DOMNodeInsertedIntoDocument: {
|
589 | eventInterface: 'MutationEvent',
|
590 | bubbles: true,
|
591 | cancelable: true
|
592 | },
|
593 | DOMNodeRemoved: {
|
594 | eventInterface: 'MutationEvent',
|
595 | bubbles: true,
|
596 | cancelable: true
|
597 | },
|
598 | DOMNodeRemovedFromDocument: {
|
599 | eventInterface: 'MutationEvent',
|
600 | bubbles: true,
|
601 | cancelable: true
|
602 | },
|
603 | |
604 |
|
605 |
|
606 | DOMSubtreeModified: {
|
607 | eventInterface: 'MutationEvent',
|
608 | bubbles: true,
|
609 | cancelable: false
|
610 | },
|
611 | downloading: {
|
612 | eventInterface: 'Event',
|
613 | bubbles: false,
|
614 | cancelable: false
|
615 | },
|
616 | drag: {
|
617 | eventInterface: 'DragEvent',
|
618 | bubbles: true,
|
619 | cancelable: true
|
620 | },
|
621 | dragend: {
|
622 | eventInterface: 'DragEvent',
|
623 | bubbles: true,
|
624 | cancelable: false
|
625 | },
|
626 | dragenter: {
|
627 | eventInterface: 'DragEvent',
|
628 | bubbles: true,
|
629 | cancelable: true
|
630 | },
|
631 | dragleave: {
|
632 | eventInterface: 'DragEvent',
|
633 | bubbles: true,
|
634 | cancelable: false
|
635 | },
|
636 | dragover: {
|
637 | eventInterface: 'DragEvent',
|
638 | bubbles: true,
|
639 | cancelable: true
|
640 | },
|
641 | dragstart: {
|
642 | eventInterface: 'DragEvent',
|
643 | bubbles: true,
|
644 | cancelable: true
|
645 | },
|
646 | drop: {
|
647 | eventInterface: 'DragEvent',
|
648 | bubbles: true,
|
649 | cancelable: true
|
650 | },
|
651 | durationchange: {
|
652 | eventInterface: 'Event',
|
653 | bubbles: false,
|
654 | cancelable: false
|
655 | },
|
656 | emptied: {
|
657 | eventInterface: 'Event',
|
658 | bubbles: false,
|
659 | cancelable: false
|
660 | },
|
661 | end: {
|
662 | eventInterface: 'Event',
|
663 | bubbles: false,
|
664 | cancelable: false
|
665 | },
|
666 | ended: {
|
667 | eventInterface: 'Event',
|
668 | bubbles: false,
|
669 | cancelable: false
|
670 | },
|
671 | endEvent: {
|
672 | eventInterface: 'TimeEvent',
|
673 | bubbles: false,
|
674 | cancelable: false
|
675 | },
|
676 | error: {
|
677 | eventInterface: 'Event',
|
678 | bubbles: false,
|
679 | cancelable: false
|
680 | },
|
681 | focus: {
|
682 | eventInterface: 'FocusEvent',
|
683 | bubbles: false,
|
684 | cancelable: false
|
685 | },
|
686 | focusin: {
|
687 | eventInterface: 'FocusEvent',
|
688 | bubbles: true,
|
689 | cancelable: false
|
690 | },
|
691 | focusout: {
|
692 | eventInterface: 'FocusEvent',
|
693 | bubbles: true,
|
694 | cancelable: false
|
695 | },
|
696 | fullscreenchange: {
|
697 | eventInterface: 'Event',
|
698 | bubbles: true,
|
699 | cancelable: false
|
700 | },
|
701 | fullscreenerror: {
|
702 | eventInterface: 'Event',
|
703 | bubbles: true,
|
704 | cancelable: false
|
705 | },
|
706 | gamepadconnected: {
|
707 | eventInterface: 'GamepadEvent',
|
708 | bubbles: false,
|
709 | cancelable: false
|
710 | },
|
711 | gamepaddisconnected: {
|
712 | eventInterface: 'GamepadEvent',
|
713 | bubbles: false,
|
714 | cancelable: false
|
715 | },
|
716 | gotpointercapture: {
|
717 | eventInterface: 'PointerEvent',
|
718 | bubbles: false,
|
719 | cancelable: false
|
720 | },
|
721 | hashchange: {
|
722 | eventInterface: 'HashChangeEvent',
|
723 | bubbles: true,
|
724 | cancelable: false
|
725 | },
|
726 | lostpointercapture: {
|
727 | eventInterface: 'PointerEvent',
|
728 | bubbles: false,
|
729 | cancelable: false
|
730 | },
|
731 | input: {
|
732 | eventInterface: 'Event',
|
733 | bubbles: true,
|
734 | cancelable: false
|
735 | },
|
736 | invalid: {
|
737 | eventInterface: 'Event',
|
738 | cancelable: true,
|
739 | bubbles: false
|
740 | },
|
741 | keydown: {
|
742 | eventInterface: 'KeyboardEvent',
|
743 | bubbles: true,
|
744 | cancelable: true
|
745 | },
|
746 | keypress: {
|
747 | eventInterface: 'KeyboardEvent',
|
748 | bubbles: true,
|
749 | cancelable: true
|
750 | },
|
751 | keyup: {
|
752 | eventInterface: 'KeyboardEvent',
|
753 | bubbles: true,
|
754 | cancelable: true
|
755 | },
|
756 | languagechange: {
|
757 | eventInterface: 'Event',
|
758 | bubbles: false,
|
759 | cancelable: false
|
760 | },
|
761 | levelchange: {
|
762 | eventInterface: 'Event',
|
763 | bubbles: false,
|
764 | cancelable: false
|
765 | },
|
766 | load: {
|
767 | eventInterface: 'UIEvent',
|
768 | bubbles: false,
|
769 | cancelable: false
|
770 | },
|
771 | loadeddata: {
|
772 | eventInterface: 'Event',
|
773 | bubbles: false,
|
774 | cancelable: false
|
775 | },
|
776 | loadedmetadata: {
|
777 | eventInterface: 'Event',
|
778 | bubbles: false,
|
779 | cancelable: false
|
780 | },
|
781 | loadend: {
|
782 | eventInterface: 'ProgressEvent',
|
783 | bubbles: false,
|
784 | cancelable: false
|
785 | },
|
786 | loadstart: {
|
787 | eventInterface: 'ProgressEvent',
|
788 | bubbles: false,
|
789 | cancelable: false
|
790 | },
|
791 | mark: {
|
792 | eventInterface: 'SpeechSynthesisEvent',
|
793 | bubbles: false,
|
794 | cancelable: false
|
795 | },
|
796 | message: {
|
797 | eventInterface: 'MessageEvent',
|
798 | bubbles: false,
|
799 | cancelable: false
|
800 | },
|
801 | messageerror: {
|
802 | eventInterface: 'MessageEvent',
|
803 | bubbles: false,
|
804 | cancelable: false
|
805 | },
|
806 | mousedown: {
|
807 | eventInterface: 'MouseEvent',
|
808 | bubbles: true,
|
809 | cancelable: true
|
810 | },
|
811 | mouseenter: {
|
812 | eventInterface: 'MouseEvent',
|
813 | bubbles: false,
|
814 | cancelable: false
|
815 | },
|
816 | mouseleave: {
|
817 | eventInterface: 'MouseEvent',
|
818 | bubbles: false,
|
819 | cancelable: false
|
820 | },
|
821 | mousemove: {
|
822 | eventInterface: 'MouseEvent',
|
823 | bubbles: true,
|
824 | cancelable: true
|
825 | },
|
826 | mouseout: {
|
827 | eventInterface: 'MouseEvent',
|
828 | bubbles: true,
|
829 | cancelable: true
|
830 | },
|
831 | mouseover: {
|
832 | eventInterface: 'MouseEvent',
|
833 | bubbles: true,
|
834 | cancelable: true
|
835 | },
|
836 | mouseup: {
|
837 | eventInterface: 'MouseEvent',
|
838 | bubbles: true,
|
839 | cancelable: true
|
840 | },
|
841 | nomatch: {
|
842 | eventInterface: 'SpeechRecognitionEvent',
|
843 | bubbles: false,
|
844 | cancelable: false
|
845 | },
|
846 | notificationclick: {
|
847 | eventInterface: 'NotificationEvent',
|
848 | bubbles: false,
|
849 | cancelable: false
|
850 | },
|
851 | noupdate: {
|
852 | eventInterface: 'Event',
|
853 | bubbles: false,
|
854 | cancelable: false
|
855 | },
|
856 | obsolete: {
|
857 | eventInterface: 'Event',
|
858 | bubbles: false,
|
859 | cancelable: false
|
860 | },
|
861 | offline: {
|
862 | eventInterface: 'Event',
|
863 | bubbles: false,
|
864 | cancelable: false
|
865 | },
|
866 | online: {
|
867 | eventInterface: 'Event',
|
868 | bubbles: false,
|
869 | cancelable: false
|
870 | },
|
871 | open: {
|
872 | eventInterface: 'Event',
|
873 | bubbles: false,
|
874 | cancelable: false
|
875 | },
|
876 | orientationchange: {
|
877 | eventInterface: 'Event',
|
878 | bubbles: false,
|
879 | cancelable: false
|
880 | },
|
881 | pagehide: {
|
882 | eventInterface: 'PageTransitionEvent',
|
883 | bubbles: false,
|
884 | cancelable: false
|
885 | },
|
886 | pageshow: {
|
887 | eventInterface: 'PageTransitionEvent',
|
888 | bubbles: false,
|
889 | cancelable: false
|
890 | },
|
891 | paste: {
|
892 | eventInterface: 'ClipboardEvent',
|
893 | bubbles: true,
|
894 | cancelable: true
|
895 | },
|
896 | pause: {
|
897 | eventInterface: 'SpeechSynthesisEvent',
|
898 | bubbles: false,
|
899 | cancelable: false
|
900 | },
|
901 | pointercancel: {
|
902 | eventInterface: 'PointerEvent',
|
903 | bubbles: true,
|
904 | cancelable: false
|
905 | },
|
906 | pointerdown: {
|
907 | eventInterface: 'PointerEvent',
|
908 | bubbles: true,
|
909 | cancelable: true
|
910 | },
|
911 | pointerenter: {
|
912 | eventInterface: 'PointerEvent',
|
913 | bubbles: false,
|
914 | cancelable: false
|
915 | },
|
916 | pointerleave: {
|
917 | eventInterface: 'PointerEvent',
|
918 | bubbles: false,
|
919 | cancelable: false
|
920 | },
|
921 | pointerlockchange: {
|
922 | eventInterface: 'Event',
|
923 | bubbles: true,
|
924 | cancelable: false
|
925 | },
|
926 | pointerlockerror: {
|
927 | eventInterface: 'Event',
|
928 | bubbles: true,
|
929 | cancelable: false
|
930 | },
|
931 | pointermove: {
|
932 | eventInterface: 'PointerEvent',
|
933 | bubbles: true,
|
934 | cancelable: true
|
935 | },
|
936 | pointerout: {
|
937 | eventInterface: 'PointerEvent',
|
938 | bubbles: true,
|
939 | cancelable: true
|
940 | },
|
941 | pointerover: {
|
942 | eventInterface: 'PointerEvent',
|
943 | bubbles: true,
|
944 | cancelable: true
|
945 | },
|
946 | pointerup: {
|
947 | eventInterface: 'PointerEvent',
|
948 | bubbles: true,
|
949 | cancelable: true
|
950 | },
|
951 | play: {
|
952 | eventInterface: 'Event',
|
953 | bubbles: false,
|
954 | cancelable: false
|
955 | },
|
956 | playing: {
|
957 | eventInterface: 'Event',
|
958 | bubbles: false,
|
959 | cancelable: false
|
960 | },
|
961 | popstate: {
|
962 | eventInterface: 'PopStateEvent',
|
963 | bubbles: true,
|
964 | cancelable: false
|
965 | },
|
966 | progress: {
|
967 | eventInterface: 'ProgressEvent',
|
968 | bubbles: false,
|
969 | cancelable: false
|
970 | },
|
971 | push: {
|
972 | eventInterface: 'PushEvent',
|
973 | bubbles: false,
|
974 | cancelable: false
|
975 | },
|
976 | pushsubscriptionchange: {
|
977 | eventInterface: 'PushEvent',
|
978 | bubbles: false,
|
979 | cancelable: false
|
980 | },
|
981 | ratechange: {
|
982 | eventInterface: 'Event',
|
983 | bubbles: false,
|
984 | cancelable: false
|
985 | },
|
986 | readystatechange: {
|
987 | eventInterface: 'Event',
|
988 | bubbles: false,
|
989 | cancelable: false
|
990 | },
|
991 | repeatEvent: {
|
992 | eventInterface: 'TimeEvent',
|
993 | bubbles: false,
|
994 | cancelable: false
|
995 | },
|
996 | reset: {
|
997 | eventInterface: 'Event',
|
998 | bubbles: true,
|
999 | cancelable: true
|
1000 | },
|
1001 | resize: {
|
1002 | eventInterface: 'UIEvent',
|
1003 | bubbles: false,
|
1004 | cancelable: false
|
1005 | },
|
1006 | resourcetimingbufferfull: {
|
1007 | eventInterface: 'Performance',
|
1008 | bubbles: true,
|
1009 | cancelable: true
|
1010 | },
|
1011 | result: {
|
1012 | eventInterface: 'SpeechRecognitionEvent',
|
1013 | bubbles: false,
|
1014 | cancelable: false
|
1015 | },
|
1016 | resume: {
|
1017 | eventInterface: 'SpeechSynthesisEvent',
|
1018 | bubbles: false,
|
1019 | cancelable: false
|
1020 | },
|
1021 | scroll: {
|
1022 | eventInterface: 'UIEvent',
|
1023 | bubbles: false,
|
1024 | cancelable: false
|
1025 | },
|
1026 | seeked: {
|
1027 | eventInterface: 'Event',
|
1028 | bubbles: false,
|
1029 | cancelable: false
|
1030 | },
|
1031 | seeking: {
|
1032 | eventInterface: 'Event',
|
1033 | bubbles: false,
|
1034 | cancelable: false
|
1035 | },
|
1036 | select: {
|
1037 | eventInterface: 'UIEvent',
|
1038 | bubbles: true,
|
1039 | cancelable: false
|
1040 | },
|
1041 | selectstart: {
|
1042 | eventInterface: 'Event',
|
1043 | bubbles: true,
|
1044 | cancelable: true
|
1045 | },
|
1046 | selectionchange: {
|
1047 | eventInterface: 'Event',
|
1048 | bubbles: false,
|
1049 | cancelable: false
|
1050 | },
|
1051 | show: {
|
1052 | eventInterface: 'MouseEvent',
|
1053 | bubbles: false,
|
1054 | cancelable: false
|
1055 | },
|
1056 | slotchange: {
|
1057 | eventInterface: 'Event',
|
1058 | bubbles: true,
|
1059 | cancelable: false
|
1060 | },
|
1061 | soundend: {
|
1062 | eventInterface: 'Event',
|
1063 | bubbles: false,
|
1064 | cancelable: false
|
1065 | },
|
1066 | soundstart: {
|
1067 | eventInterface: 'Event',
|
1068 | bubbles: false,
|
1069 | cancelable: false
|
1070 | },
|
1071 | speechend: {
|
1072 | eventInterface: 'Event',
|
1073 | bubbles: false,
|
1074 | cancelable: false
|
1075 | },
|
1076 | speechstart: {
|
1077 | eventInterface: 'Event',
|
1078 | bubbles: false,
|
1079 | cancelable: false
|
1080 | },
|
1081 | stalled: {
|
1082 | eventInterface: 'Event',
|
1083 | bubbles: false,
|
1084 | cancelable: false
|
1085 | },
|
1086 | start: {
|
1087 | eventInterface: 'SpeechSynthesisEvent',
|
1088 | bubbles: false,
|
1089 | cancelable: false
|
1090 | },
|
1091 | storage: {
|
1092 | eventInterface: 'StorageEvent',
|
1093 | bubbles: false,
|
1094 | cancelable: false
|
1095 | },
|
1096 | submit: {
|
1097 | eventInterface: 'Event',
|
1098 | bubbles: true,
|
1099 | cancelable: true
|
1100 | },
|
1101 | success: {
|
1102 | eventInterface: 'Event',
|
1103 | bubbles: false,
|
1104 | cancelable: false
|
1105 | },
|
1106 | suspend: {
|
1107 | eventInterface: 'Event',
|
1108 | bubbles: false,
|
1109 | cancelable: false
|
1110 | },
|
1111 | SVGAbort: {
|
1112 | eventInterface: 'SVGEvent',
|
1113 | bubbles: true,
|
1114 | cancelable: false
|
1115 | },
|
1116 | SVGError: {
|
1117 | eventInterface: 'SVGEvent',
|
1118 | bubbles: true,
|
1119 | cancelable: false
|
1120 | },
|
1121 | SVGLoad: {
|
1122 | eventInterface: 'SVGEvent',
|
1123 | bubbles: false,
|
1124 | cancelable: false
|
1125 | },
|
1126 | SVGResize: {
|
1127 | eventInterface: 'SVGEvent',
|
1128 | bubbles: true,
|
1129 | cancelable: false
|
1130 | },
|
1131 | SVGScroll: {
|
1132 | eventInterface: 'SVGEvent',
|
1133 | bubbles: true,
|
1134 | cancelable: false
|
1135 | },
|
1136 | SVGUnload: {
|
1137 | eventInterface: 'SVGEvent',
|
1138 | bubbles: false,
|
1139 | cancelable: false
|
1140 | },
|
1141 | SVGZoom: {
|
1142 | eventInterface: 'SVGZoomEvent',
|
1143 | bubbles: true,
|
1144 | cancelable: false
|
1145 | },
|
1146 | timeout: {
|
1147 | eventInterface: 'ProgressEvent',
|
1148 | bubbles: false,
|
1149 | cancelable: false
|
1150 | },
|
1151 | timeupdate: {
|
1152 | eventInterface: 'Event',
|
1153 | bubbles: false,
|
1154 | cancelable: false
|
1155 | },
|
1156 | touchcancel: {
|
1157 | eventInterface: 'TouchEvent',
|
1158 | bubbles: true,
|
1159 | cancelable: false
|
1160 | },
|
1161 | touchend: {
|
1162 | eventInterface: 'TouchEvent',
|
1163 | bubbles: true,
|
1164 | cancelable: true
|
1165 | },
|
1166 | touchmove: {
|
1167 | eventInterface: 'TouchEvent',
|
1168 | bubbles: true,
|
1169 | cancelable: true
|
1170 | },
|
1171 | touchstart: {
|
1172 | eventInterface: 'TouchEvent',
|
1173 | bubbles: true,
|
1174 | cancelable: true
|
1175 | },
|
1176 | transitionend: {
|
1177 | eventInterface: 'TransitionEvent',
|
1178 | bubbles: true,
|
1179 | cancelable: true
|
1180 | },
|
1181 | unload: {
|
1182 | eventInterface: 'UIEvent',
|
1183 | bubbles: false,
|
1184 | cancelable: false
|
1185 | },
|
1186 | updateready: {
|
1187 | eventInterface: 'Event',
|
1188 | bubbles: false,
|
1189 | cancelable: false
|
1190 | },
|
1191 | userproximity: {
|
1192 | eventInterface: 'UserProximityEvent',
|
1193 | bubbles: false,
|
1194 | cancelable: false
|
1195 | },
|
1196 | voiceschanged: {
|
1197 | eventInterface: 'Event',
|
1198 | bubbles: false,
|
1199 | cancelable: false
|
1200 | },
|
1201 | visibilitychange: {
|
1202 | eventInterface: 'Event',
|
1203 | bubbles: true,
|
1204 | cancelable: false
|
1205 | },
|
1206 | volumechange: {
|
1207 | eventInterface: 'Event',
|
1208 | bubbles: false,
|
1209 | cancelable: false
|
1210 | },
|
1211 | waiting: {
|
1212 | eventInterface: 'Event',
|
1213 | bubbles: false,
|
1214 | cancelable: false
|
1215 | },
|
1216 | wheel: {
|
1217 | eventInterface: 'WheelEvent',
|
1218 | bubbles: true,
|
1219 | cancelable: true
|
1220 | }
|
1221 | };
|
1222 |
|
1223 |
|
1224 |
|
1225 |
|
1226 | function generateModifiers(modifiers, isOnClick) {
|
1227 | var keyModifiers = [];
|
1228 | var systemModifiers = [];
|
1229 | for (var i = 0; i < modifiers.length; i++) {
|
1230 | var modifier = modifiers[i];
|
1231 |
|
1232 | if (ignorableKeyModifiers.includes(modifier)) {
|
1233 | continue;
|
1234 | }
|
1235 |
|
1236 |
|
1237 | if (systemKeyModifiers.includes(modifier) ||
|
1238 | (mouseKeyModifiers.includes(modifier) &&
|
1239 | isOnClick)) {
|
1240 | systemModifiers.push(modifier);
|
1241 | }
|
1242 | else {
|
1243 | keyModifiers.push(modifier);
|
1244 | }
|
1245 | }
|
1246 | return {
|
1247 | keyModifiers: keyModifiers,
|
1248 | systemModifiers: systemModifiers
|
1249 | };
|
1250 | }
|
1251 | function getEventProperties(eventParams) {
|
1252 | var modifiers = eventParams.modifiers, _a = eventParams.options, options = _a === void 0 ? {} : _a, eventType = eventParams.eventType;
|
1253 | var isOnClick = eventType === 'click';
|
1254 | var _b = generateModifiers(modifiers, isOnClick), keyModifiers = _b.keyModifiers, systemModifiers = _b.systemModifiers;
|
1255 | if (isOnClick) {
|
1256 |
|
1257 | if (systemModifiers.includes('right')) {
|
1258 | eventType = 'contextmenu';
|
1259 | options.button = 2;
|
1260 |
|
1261 | }
|
1262 | else if (systemModifiers.includes('middle')) {
|
1263 | eventType = 'mouseup';
|
1264 | options.button = 1;
|
1265 | }
|
1266 | }
|
1267 | var meta = domEvents[eventType] || {
|
1268 | eventInterface: 'Event',
|
1269 | cancelable: true,
|
1270 | bubbles: true
|
1271 | };
|
1272 |
|
1273 |
|
1274 | var systemModifiersMeta = systemModifiers.reduce(function (all, key) {
|
1275 | all["".concat(key, "Key")] = true;
|
1276 | return all;
|
1277 | }, {});
|
1278 |
|
1279 | var keyCode = keyCodesByKeyName[keyModifiers[0]] ||
|
1280 | (options && (options.keyCode || options.code));
|
1281 | var eventProperties = __assign(__assign(__assign(__assign({}, systemModifiersMeta), options), { bubbles: meta.bubbles, cancelable: meta.cancelable,
|
1282 |
|
1283 | keyCode: keyCode, code: keyCode }), (keyModifiers[0] ? { key: keyModifiers[0] } : {}));
|
1284 | return {
|
1285 | eventProperties: eventProperties,
|
1286 | meta: meta,
|
1287 | eventType: eventType
|
1288 | };
|
1289 | }
|
1290 | function createEvent(eventParams) {
|
1291 | var _a = getEventProperties(eventParams), eventProperties = _a.eventProperties, meta = _a.meta, eventType = _a.eventType;
|
1292 |
|
1293 | var eventInterface = meta.eventInterface;
|
1294 | var metaEventInterface = window[eventInterface];
|
1295 | var SupportedEventInterface = typeof metaEventInterface === 'function' ? metaEventInterface : window.Event;
|
1296 | return new SupportedEventInterface(eventType,
|
1297 |
|
1298 |
|
1299 | eventProperties);
|
1300 | }
|
1301 | function createDOMEvent(eventString, options) {
|
1302 |
|
1303 | var _a = eventString.split('.'), eventType = _a[0], modifiers = _a.slice(1);
|
1304 | var eventParams = {
|
1305 | eventType: eventType,
|
1306 | modifiers: modifiers,
|
1307 | options: options
|
1308 | };
|
1309 | var event = createEvent(eventParams);
|
1310 | var eventPrototype = Object.getPrototypeOf(event);
|
1311 |
|
1312 | options &&
|
1313 | Object.keys(options).forEach(function (key) {
|
1314 | var propertyDescriptor = Object.getOwnPropertyDescriptor(eventPrototype, key);
|
1315 | var canSetProperty = !(propertyDescriptor && propertyDescriptor.set === undefined);
|
1316 | if (canSetProperty) {
|
1317 | event[key] = options[key];
|
1318 | }
|
1319 | });
|
1320 | return event;
|
1321 | }
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 | var stubs = new WeakMap();
|
1335 | function registerStub(_a) {
|
1336 | var source = _a.source, stub = _a.stub;
|
1337 | stubs.set(stub, source);
|
1338 | }
|
1339 | function getOriginalComponentFromStub(stub) {
|
1340 | return stubs.get(stub);
|
1341 | }
|
1342 |
|
1343 | var cacheStringFunction$1 = function (fn) {
|
1344 | var cache = Object.create(null);
|
1345 | return (function (str) {
|
1346 | var hit = cache[str];
|
1347 | return hit || (cache[str] = fn(str));
|
1348 | });
|
1349 | };
|
1350 | var camelizeRE$1 = /-(\w)/g;
|
1351 | var camelize$1 = cacheStringFunction$1(function (str) {
|
1352 | return str.replace(camelizeRE$1, function (_, c) { return (c ? c.toUpperCase() : ''); });
|
1353 | });
|
1354 | var capitalize$1 = cacheStringFunction$1(function (str) {
|
1355 | return str.charAt(0).toUpperCase() + str.slice(1);
|
1356 | });
|
1357 | var hyphenateRE$1 = /\B([A-Z])/g;
|
1358 | var hyphenate$1 = cacheStringFunction$1(function (str) {
|
1359 | return str.replace(hyphenateRE$1, '-$1').toLowerCase();
|
1360 | });
|
1361 |
|
1362 | function matchName(target, sourceName) {
|
1363 | var camelized = camelize$1(target);
|
1364 | var capitalized = capitalize$1(camelized);
|
1365 | return (!!sourceName &&
|
1366 | (sourceName === target ||
|
1367 | sourceName === camelized ||
|
1368 | sourceName === capitalized ||
|
1369 | capitalize$1(camelize$1(sourceName)) === capitalized));
|
1370 | }
|
1371 |
|
1372 | function isCompatEnabled$1(key) {
|
1373 | var _a, _b;
|
1374 | return (_b = (_a = Vue.compatUtils) === null || _a === void 0 ? void 0 : _a.isCompatEnabled(key)) !== null && _b !== void 0 ? _b : false;
|
1375 | }
|
1376 | function isLegacyExtendedComponent(component) {
|
1377 | if (!isCompatEnabled$1('GLOBAL_EXTEND') || typeof component !== 'function') {
|
1378 | return false;
|
1379 | }
|
1380 | return (hasOwnProperty(component, 'super') &&
|
1381 | component.super.extend({}).super === component.super);
|
1382 | }
|
1383 | function unwrapLegacyVueExtendComponent(selector) {
|
1384 | return isLegacyExtendedComponent(selector) ? selector.options : selector;
|
1385 | }
|
1386 | function isLegacyFunctionalComponent(component) {
|
1387 | return Boolean(component &&
|
1388 | typeof component === 'object' &&
|
1389 | hasOwnProperty(component, 'functional') &&
|
1390 | component.functional);
|
1391 | }
|
1392 |
|
1393 | var getComponentNameInSetup = function (instance, type) {
|
1394 | return Object.keys((instance === null || instance === void 0 ? void 0 : instance.setupState) || {}).find(function (key) { var _a; return ((_a = Object.getOwnPropertyDescriptor(instance.setupState, key)) === null || _a === void 0 ? void 0 : _a.value) === type; });
|
1395 | };
|
1396 | var getComponentRegisteredName = function (instance, type) {
|
1397 | if (!instance || !instance.parent)
|
1398 | return null;
|
1399 |
|
1400 | var registry = instance.type.components;
|
1401 | for (var key in registry) {
|
1402 | if (registry[key] === type) {
|
1403 | return key;
|
1404 | }
|
1405 | }
|
1406 |
|
1407 | return getComponentNameInSetup(instance.parent, type) || null;
|
1408 | };
|
1409 | var getComponentName = function (instance, type) {
|
1410 | if (isObjectComponent(type)) {
|
1411 | return (
|
1412 |
|
1413 |
|
1414 |
|
1415 | getComponentNameInSetup(instance, type) || type.name || type.__name || '');
|
1416 | }
|
1417 | if (isLegacyExtendedComponent(type)) {
|
1418 | return unwrapLegacyVueExtendComponent(type).name || '';
|
1419 | }
|
1420 | if (isFunctionalComponent(type)) {
|
1421 | return type.displayName || type.name;
|
1422 | }
|
1423 | return '';
|
1424 | };
|
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 |
|
1430 |
|
1431 |
|
1432 | function matches(node, rawSelector) {
|
1433 | var _a, _b, _c;
|
1434 | var selector = unwrapLegacyVueExtendComponent(rawSelector);
|
1435 |
|
1436 | if (!node.component)
|
1437 | return false;
|
1438 | var nodeType = node.type;
|
1439 | if (!isComponent$1(nodeType))
|
1440 | return false;
|
1441 | if (typeof selector === 'string') {
|
1442 | return (_b = (_a = node.el) === null || _a === void 0 ? void 0 : _a.matches) === null || _b === void 0 ? void 0 : _b.call(_a, selector);
|
1443 | }
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 | var nodeTypeCandidates = [
|
1450 | nodeType,
|
1451 | getOriginalComponentFromStub(nodeType)
|
1452 | ].filter(Boolean);
|
1453 |
|
1454 | var target = (_c = getOriginalComponentFromStub(selector)) !== null && _c !== void 0 ? _c : selector;
|
1455 | if (nodeTypeCandidates.includes(target)) {
|
1456 | return true;
|
1457 | }
|
1458 | var componentName;
|
1459 | componentName = getComponentName(node.component, nodeType);
|
1460 | var selectorName = selector.name;
|
1461 |
|
1462 | if (componentName && selectorName) {
|
1463 | return matchName(selectorName, componentName);
|
1464 | }
|
1465 | componentName =
|
1466 | getComponentRegisteredName(node.component, nodeType) || undefined;
|
1467 |
|
1468 | if (node.component.parent) {
|
1469 | var registry = node.component.parent.type.components;
|
1470 | for (var key in registry) {
|
1471 |
|
1472 | if (!selectorName && registry[key] === selector) {
|
1473 | selectorName = key;
|
1474 | }
|
1475 |
|
1476 | if (!componentName && registry[key] === nodeType) {
|
1477 | componentName = key;
|
1478 | }
|
1479 | }
|
1480 | }
|
1481 | if (selectorName && componentName) {
|
1482 | return matchName(selectorName, componentName);
|
1483 | }
|
1484 | return false;
|
1485 | }
|
1486 |
|
1487 |
|
1488 |
|
1489 |
|
1490 |
|
1491 | function nodesAsObject(value) {
|
1492 | return !!value && typeof value === 'object';
|
1493 | }
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 | function aggregateChildren(nodes, children) {
|
1500 | if (children && Array.isArray(children)) {
|
1501 | var reversedNodes = __spreadArray([], children, true).reverse().filter(nodesAsObject);
|
1502 | reversedNodes.forEach(function (node) {
|
1503 | if (Array.isArray(node)) {
|
1504 | aggregateChildren(nodes, node);
|
1505 | }
|
1506 | else {
|
1507 | nodes.unshift(node);
|
1508 | }
|
1509 | });
|
1510 | }
|
1511 | }
|
1512 | function findAllVNodes(vnode, selector) {
|
1513 | var matchingNodes = [];
|
1514 | var nodes = [vnode];
|
1515 | while (nodes.length) {
|
1516 | var node = nodes.shift();
|
1517 | aggregateChildren(nodes, node.children);
|
1518 | if (node.component) {
|
1519 | aggregateChildren(nodes, [node.component.subTree]);
|
1520 | }
|
1521 | if (node.suspense) {
|
1522 |
|
1523 | var activeBranch = node.suspense.activeBranch;
|
1524 | aggregateChildren(nodes, [activeBranch]);
|
1525 | }
|
1526 | if (matches(node, selector) && !matchingNodes.includes(node)) {
|
1527 | matchingNodes.push(node);
|
1528 | }
|
1529 | }
|
1530 | return matchingNodes;
|
1531 | }
|
1532 | function find(root, selector) {
|
1533 | var matchingVNodes = findAllVNodes(root, selector);
|
1534 | if (typeof selector === 'string') {
|
1535 |
|
1536 | matchingVNodes = matchingVNodes.filter(function (vnode) { var _a; return ((_a = vnode.component.parent) === null || _a === void 0 ? void 0 : _a.vnode.el) !== vnode.el; });
|
1537 | }
|
1538 | return matchingVNodes.map(function (vnode) { return vnode.component; });
|
1539 | }
|
1540 |
|
1541 | function createWrapperError(wrapperType) {
|
1542 | return new Proxy(Object.create(null), {
|
1543 | get: function (obj, prop) {
|
1544 | switch (prop) {
|
1545 | case 'then':
|
1546 |
|
1547 |
|
1548 | return;
|
1549 | case 'exists':
|
1550 | return function () { return false; };
|
1551 | default:
|
1552 | throw new Error("Cannot call ".concat(String(prop), " on an empty ").concat(wrapperType, "."));
|
1553 | }
|
1554 | }
|
1555 | });
|
1556 | }
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 |
|
1563 | function isStyleVisible(element) {
|
1564 | if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) {
|
1565 | return false;
|
1566 | }
|
1567 | var _a = getComputedStyle(element), display = _a.display, visibility = _a.visibility, opacity = _a.opacity;
|
1568 | return (display !== 'none' &&
|
1569 | visibility !== 'hidden' &&
|
1570 | visibility !== 'collapse' &&
|
1571 | opacity !== '0');
|
1572 | }
|
1573 | function isAttributeVisible(element) {
|
1574 | return (!element.hasAttribute('hidden') &&
|
1575 | (element.nodeName === 'DETAILS' ? element.hasAttribute('open') : true));
|
1576 | }
|
1577 | function isElementVisible(element) {
|
1578 | return (element.nodeName !== '#comment' &&
|
1579 | isStyleVisible(element) &&
|
1580 | isAttributeVisible(element) &&
|
1581 | (!element.parentElement || isElementVisible(element.parentElement)));
|
1582 | }
|
1583 |
|
1584 | function isElement(element) {
|
1585 | return element instanceof Element;
|
1586 | }
|
1587 |
|
1588 | var WrapperType;
|
1589 | (function (WrapperType) {
|
1590 | WrapperType[WrapperType["DOMWrapper"] = 0] = "DOMWrapper";
|
1591 | WrapperType[WrapperType["VueWrapper"] = 1] = "VueWrapper";
|
1592 | })(WrapperType || (WrapperType = {}));
|
1593 | var factories = {};
|
1594 | function registerFactory(type, fn) {
|
1595 | factories[type] = fn;
|
1596 | }
|
1597 | var createDOMWrapper = function (element) {
|
1598 | return factories[WrapperType.DOMWrapper](element);
|
1599 | };
|
1600 | var createVueWrapper = function (app, vm, setProps) {
|
1601 | return factories[WrapperType.VueWrapper](app, vm, setProps);
|
1602 | };
|
1603 |
|
1604 | function stringifyNode(node) {
|
1605 | return node instanceof Element
|
1606 | ? node.outerHTML
|
1607 | : new XMLSerializer().serializeToString(node);
|
1608 | }
|
1609 |
|
1610 | function getDefaultExportFromCjs (x) {
|
1611 | return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
1612 | }
|
1613 |
|
1614 | var js = {exports: {}};
|
1615 |
|
1616 | var src = {};
|
1617 |
|
1618 | var javascript = {exports: {}};
|
1619 |
|
1620 | var beautifier$2 = {};
|
1621 |
|
1622 | var output = {};
|
1623 |
|
1624 |
|
1625 |
|
1626 | var hasRequiredOutput;
|
1627 |
|
1628 | function requireOutput () {
|
1629 | if (hasRequiredOutput) return output;
|
1630 | hasRequiredOutput = 1;
|
1631 |
|
1632 | function OutputLine(parent) {
|
1633 | this.__parent = parent;
|
1634 | this.__character_count = 0;
|
1635 |
|
1636 | this.__indent_count = -1;
|
1637 | this.__alignment_count = 0;
|
1638 | this.__wrap_point_index = 0;
|
1639 | this.__wrap_point_character_count = 0;
|
1640 | this.__wrap_point_indent_count = -1;
|
1641 | this.__wrap_point_alignment_count = 0;
|
1642 |
|
1643 | this.__items = [];
|
1644 | }
|
1645 |
|
1646 | OutputLine.prototype.clone_empty = function() {
|
1647 | var line = new OutputLine(this.__parent);
|
1648 | line.set_indent(this.__indent_count, this.__alignment_count);
|
1649 | return line;
|
1650 | };
|
1651 |
|
1652 | OutputLine.prototype.item = function(index) {
|
1653 | if (index < 0) {
|
1654 | return this.__items[this.__items.length + index];
|
1655 | } else {
|
1656 | return this.__items[index];
|
1657 | }
|
1658 | };
|
1659 |
|
1660 | OutputLine.prototype.has_match = function(pattern) {
|
1661 | for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
|
1662 | if (this.__items[lastCheckedOutput].match(pattern)) {
|
1663 | return true;
|
1664 | }
|
1665 | }
|
1666 | return false;
|
1667 | };
|
1668 |
|
1669 | OutputLine.prototype.set_indent = function(indent, alignment) {
|
1670 | if (this.is_empty()) {
|
1671 | this.__indent_count = indent || 0;
|
1672 | this.__alignment_count = alignment || 0;
|
1673 | this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
|
1674 | }
|
1675 | };
|
1676 |
|
1677 | OutputLine.prototype._set_wrap_point = function() {
|
1678 | if (this.__parent.wrap_line_length) {
|
1679 | this.__wrap_point_index = this.__items.length;
|
1680 | this.__wrap_point_character_count = this.__character_count;
|
1681 | this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
|
1682 | this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
|
1683 | }
|
1684 | };
|
1685 |
|
1686 | OutputLine.prototype._should_wrap = function() {
|
1687 | return this.__wrap_point_index &&
|
1688 | this.__character_count > this.__parent.wrap_line_length &&
|
1689 | this.__wrap_point_character_count > this.__parent.next_line.__character_count;
|
1690 | };
|
1691 |
|
1692 | OutputLine.prototype._allow_wrap = function() {
|
1693 | if (this._should_wrap()) {
|
1694 | this.__parent.add_new_line();
|
1695 | var next = this.__parent.current_line;
|
1696 | next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
|
1697 | next.__items = this.__items.slice(this.__wrap_point_index);
|
1698 | this.__items = this.__items.slice(0, this.__wrap_point_index);
|
1699 |
|
1700 | next.__character_count += this.__character_count - this.__wrap_point_character_count;
|
1701 | this.__character_count = this.__wrap_point_character_count;
|
1702 |
|
1703 | if (next.__items[0] === " ") {
|
1704 | next.__items.splice(0, 1);
|
1705 | next.__character_count -= 1;
|
1706 | }
|
1707 | return true;
|
1708 | }
|
1709 | return false;
|
1710 | };
|
1711 |
|
1712 | OutputLine.prototype.is_empty = function() {
|
1713 | return this.__items.length === 0;
|
1714 | };
|
1715 |
|
1716 | OutputLine.prototype.last = function() {
|
1717 | if (!this.is_empty()) {
|
1718 | return this.__items[this.__items.length - 1];
|
1719 | } else {
|
1720 | return null;
|
1721 | }
|
1722 | };
|
1723 |
|
1724 | OutputLine.prototype.push = function(item) {
|
1725 | this.__items.push(item);
|
1726 | var last_newline_index = item.lastIndexOf('\n');
|
1727 | if (last_newline_index !== -1) {
|
1728 | this.__character_count = item.length - last_newline_index;
|
1729 | } else {
|
1730 | this.__character_count += item.length;
|
1731 | }
|
1732 | };
|
1733 |
|
1734 | OutputLine.prototype.pop = function() {
|
1735 | var item = null;
|
1736 | if (!this.is_empty()) {
|
1737 | item = this.__items.pop();
|
1738 | this.__character_count -= item.length;
|
1739 | }
|
1740 | return item;
|
1741 | };
|
1742 |
|
1743 |
|
1744 | OutputLine.prototype._remove_indent = function() {
|
1745 | if (this.__indent_count > 0) {
|
1746 | this.__indent_count -= 1;
|
1747 | this.__character_count -= this.__parent.indent_size;
|
1748 | }
|
1749 | };
|
1750 |
|
1751 | OutputLine.prototype._remove_wrap_indent = function() {
|
1752 | if (this.__wrap_point_indent_count > 0) {
|
1753 | this.__wrap_point_indent_count -= 1;
|
1754 | }
|
1755 | };
|
1756 | OutputLine.prototype.trim = function() {
|
1757 | while (this.last() === ' ') {
|
1758 | this.__items.pop();
|
1759 | this.__character_count -= 1;
|
1760 | }
|
1761 | };
|
1762 |
|
1763 | OutputLine.prototype.toString = function() {
|
1764 | var result = '';
|
1765 | if (this.is_empty()) {
|
1766 | if (this.__parent.indent_empty_lines) {
|
1767 | result = this.__parent.get_indent_string(this.__indent_count);
|
1768 | }
|
1769 | } else {
|
1770 | result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
|
1771 | result += this.__items.join('');
|
1772 | }
|
1773 | return result;
|
1774 | };
|
1775 |
|
1776 | function IndentStringCache(options, baseIndentString) {
|
1777 | this.__cache = [''];
|
1778 | this.__indent_size = options.indent_size;
|
1779 | this.__indent_string = options.indent_char;
|
1780 | if (!options.indent_with_tabs) {
|
1781 | this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
|
1782 | }
|
1783 |
|
1784 |
|
1785 | baseIndentString = baseIndentString || '';
|
1786 | if (options.indent_level > 0) {
|
1787 | baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
|
1788 | }
|
1789 |
|
1790 | this.__base_string = baseIndentString;
|
1791 | this.__base_string_length = baseIndentString.length;
|
1792 | }
|
1793 |
|
1794 | IndentStringCache.prototype.get_indent_size = function(indent, column) {
|
1795 | var result = this.__base_string_length;
|
1796 | column = column || 0;
|
1797 | if (indent < 0) {
|
1798 | result = 0;
|
1799 | }
|
1800 | result += indent * this.__indent_size;
|
1801 | result += column;
|
1802 | return result;
|
1803 | };
|
1804 |
|
1805 | IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
|
1806 | var result = this.__base_string;
|
1807 | column = column || 0;
|
1808 | if (indent_level < 0) {
|
1809 | indent_level = 0;
|
1810 | result = '';
|
1811 | }
|
1812 | column += indent_level * this.__indent_size;
|
1813 | this.__ensure_cache(column);
|
1814 | result += this.__cache[column];
|
1815 | return result;
|
1816 | };
|
1817 |
|
1818 | IndentStringCache.prototype.__ensure_cache = function(column) {
|
1819 | while (column >= this.__cache.length) {
|
1820 | this.__add_column();
|
1821 | }
|
1822 | };
|
1823 |
|
1824 | IndentStringCache.prototype.__add_column = function() {
|
1825 | var column = this.__cache.length;
|
1826 | var indent = 0;
|
1827 | var result = '';
|
1828 | if (this.__indent_size && column >= this.__indent_size) {
|
1829 | indent = Math.floor(column / this.__indent_size);
|
1830 | column -= indent * this.__indent_size;
|
1831 | result = new Array(indent + 1).join(this.__indent_string);
|
1832 | }
|
1833 | if (column) {
|
1834 | result += new Array(column + 1).join(' ');
|
1835 | }
|
1836 |
|
1837 | this.__cache.push(result);
|
1838 | };
|
1839 |
|
1840 | function Output(options, baseIndentString) {
|
1841 | this.__indent_cache = new IndentStringCache(options, baseIndentString);
|
1842 | this.raw = false;
|
1843 | this._end_with_newline = options.end_with_newline;
|
1844 | this.indent_size = options.indent_size;
|
1845 | this.wrap_line_length = options.wrap_line_length;
|
1846 | this.indent_empty_lines = options.indent_empty_lines;
|
1847 | this.__lines = [];
|
1848 | this.previous_line = null;
|
1849 | this.current_line = null;
|
1850 | this.next_line = new OutputLine(this);
|
1851 | this.space_before_token = false;
|
1852 | this.non_breaking_space = false;
|
1853 | this.previous_token_wrapped = false;
|
1854 |
|
1855 | this.__add_outputline();
|
1856 | }
|
1857 |
|
1858 | Output.prototype.__add_outputline = function() {
|
1859 | this.previous_line = this.current_line;
|
1860 | this.current_line = this.next_line.clone_empty();
|
1861 | this.__lines.push(this.current_line);
|
1862 | };
|
1863 |
|
1864 | Output.prototype.get_line_number = function() {
|
1865 | return this.__lines.length;
|
1866 | };
|
1867 |
|
1868 | Output.prototype.get_indent_string = function(indent, column) {
|
1869 | return this.__indent_cache.get_indent_string(indent, column);
|
1870 | };
|
1871 |
|
1872 | Output.prototype.get_indent_size = function(indent, column) {
|
1873 | return this.__indent_cache.get_indent_size(indent, column);
|
1874 | };
|
1875 |
|
1876 | Output.prototype.is_empty = function() {
|
1877 | return !this.previous_line && this.current_line.is_empty();
|
1878 | };
|
1879 |
|
1880 | Output.prototype.add_new_line = function(force_newline) {
|
1881 |
|
1882 |
|
1883 | if (this.is_empty() ||
|
1884 | (!force_newline && this.just_added_newline())) {
|
1885 | return false;
|
1886 | }
|
1887 |
|
1888 |
|
1889 |
|
1890 | if (!this.raw) {
|
1891 | this.__add_outputline();
|
1892 | }
|
1893 | return true;
|
1894 | };
|
1895 |
|
1896 | Output.prototype.get_code = function(eol) {
|
1897 | this.trim(true);
|
1898 |
|
1899 |
|
1900 |
|
1901 | var last_item = this.current_line.pop();
|
1902 | if (last_item) {
|
1903 | if (last_item[last_item.length - 1] === '\n') {
|
1904 | last_item = last_item.replace(/\n+$/g, '');
|
1905 | }
|
1906 | this.current_line.push(last_item);
|
1907 | }
|
1908 |
|
1909 | if (this._end_with_newline) {
|
1910 | this.__add_outputline();
|
1911 | }
|
1912 |
|
1913 | var sweet_code = this.__lines.join('\n');
|
1914 |
|
1915 | if (eol !== '\n') {
|
1916 | sweet_code = sweet_code.replace(/[\n]/g, eol);
|
1917 | }
|
1918 | return sweet_code;
|
1919 | };
|
1920 |
|
1921 | Output.prototype.set_wrap_point = function() {
|
1922 | this.current_line._set_wrap_point();
|
1923 | };
|
1924 |
|
1925 | Output.prototype.set_indent = function(indent, alignment) {
|
1926 | indent = indent || 0;
|
1927 | alignment = alignment || 0;
|
1928 |
|
1929 |
|
1930 | this.next_line.set_indent(indent, alignment);
|
1931 |
|
1932 |
|
1933 | if (this.__lines.length > 1) {
|
1934 | this.current_line.set_indent(indent, alignment);
|
1935 | return true;
|
1936 | }
|
1937 |
|
1938 | this.current_line.set_indent();
|
1939 | return false;
|
1940 | };
|
1941 |
|
1942 | Output.prototype.add_raw_token = function(token) {
|
1943 | for (var x = 0; x < token.newlines; x++) {
|
1944 | this.__add_outputline();
|
1945 | }
|
1946 | this.current_line.set_indent(-1);
|
1947 | this.current_line.push(token.whitespace_before);
|
1948 | this.current_line.push(token.text);
|
1949 | this.space_before_token = false;
|
1950 | this.non_breaking_space = false;
|
1951 | this.previous_token_wrapped = false;
|
1952 | };
|
1953 |
|
1954 | Output.prototype.add_token = function(printable_token) {
|
1955 | this.__add_space_before_token();
|
1956 | this.current_line.push(printable_token);
|
1957 | this.space_before_token = false;
|
1958 | this.non_breaking_space = false;
|
1959 | this.previous_token_wrapped = this.current_line._allow_wrap();
|
1960 | };
|
1961 |
|
1962 | Output.prototype.__add_space_before_token = function() {
|
1963 | if (this.space_before_token && !this.just_added_newline()) {
|
1964 | if (!this.non_breaking_space) {
|
1965 | this.set_wrap_point();
|
1966 | }
|
1967 | this.current_line.push(' ');
|
1968 | }
|
1969 | };
|
1970 |
|
1971 | Output.prototype.remove_indent = function(index) {
|
1972 | var output_length = this.__lines.length;
|
1973 | while (index < output_length) {
|
1974 | this.__lines[index]._remove_indent();
|
1975 | index++;
|
1976 | }
|
1977 | this.current_line._remove_wrap_indent();
|
1978 | };
|
1979 |
|
1980 | Output.prototype.trim = function(eat_newlines) {
|
1981 | eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
|
1982 |
|
1983 | this.current_line.trim();
|
1984 |
|
1985 | while (eat_newlines && this.__lines.length > 1 &&
|
1986 | this.current_line.is_empty()) {
|
1987 | this.__lines.pop();
|
1988 | this.current_line = this.__lines[this.__lines.length - 1];
|
1989 | this.current_line.trim();
|
1990 | }
|
1991 |
|
1992 | this.previous_line = this.__lines.length > 1 ?
|
1993 | this.__lines[this.__lines.length - 2] : null;
|
1994 | };
|
1995 |
|
1996 | Output.prototype.just_added_newline = function() {
|
1997 | return this.current_line.is_empty();
|
1998 | };
|
1999 |
|
2000 | Output.prototype.just_added_blankline = function() {
|
2001 | return this.is_empty() ||
|
2002 | (this.current_line.is_empty() && this.previous_line.is_empty());
|
2003 | };
|
2004 |
|
2005 | Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
|
2006 | var index = this.__lines.length - 2;
|
2007 | while (index >= 0) {
|
2008 | var potentialEmptyLine = this.__lines[index];
|
2009 | if (potentialEmptyLine.is_empty()) {
|
2010 | break;
|
2011 | } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
|
2012 | potentialEmptyLine.item(-1) !== ends_with) {
|
2013 | this.__lines.splice(index + 1, 0, new OutputLine(this));
|
2014 | this.previous_line = this.__lines[this.__lines.length - 2];
|
2015 | break;
|
2016 | }
|
2017 | index--;
|
2018 | }
|
2019 | };
|
2020 |
|
2021 | output.Output = Output;
|
2022 | return output;
|
2023 | }
|
2024 |
|
2025 | var token = {};
|
2026 |
|
2027 |
|
2028 |
|
2029 | var hasRequiredToken;
|
2030 |
|
2031 | function requireToken () {
|
2032 | if (hasRequiredToken) return token;
|
2033 | hasRequiredToken = 1;
|
2034 |
|
2035 | function Token(type, text, newlines, whitespace_before) {
|
2036 | this.type = type;
|
2037 | this.text = text;
|
2038 |
|
2039 |
|
2040 |
|
2041 |
|
2042 |
|
2043 | this.comments_before = null;
|
2044 |
|
2045 |
|
2046 |
|
2047 | this.newlines = newlines || 0;
|
2048 | this.whitespace_before = whitespace_before || '';
|
2049 | this.parent = null;
|
2050 | this.next = null;
|
2051 | this.previous = null;
|
2052 | this.opened = null;
|
2053 | this.closed = null;
|
2054 | this.directives = null;
|
2055 | }
|
2056 |
|
2057 |
|
2058 | token.Token = Token;
|
2059 | return token;
|
2060 | }
|
2061 |
|
2062 | var acorn = {};
|
2063 |
|
2064 |
|
2065 |
|
2066 | var hasRequiredAcorn;
|
2067 |
|
2068 | function requireAcorn () {
|
2069 | if (hasRequiredAcorn) return acorn;
|
2070 | hasRequiredAcorn = 1;
|
2071 | (function (exports) {
|
2072 |
|
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 |
|
2079 | var baseASCIIidentifierStartChars = "\\x23\\x24\\x40\\x41-\\x5a\\x5f\\x61-\\x7a";
|
2080 |
|
2081 |
|
2082 | var baseASCIIidentifierChars = "\\x24\\x30-\\x39\\x41-\\x5a\\x5f\\x61-\\x7a";
|
2083 |
|
2084 |
|
2085 |
|
2086 |
|
2087 |
|
2088 | var nonASCIIidentifierStartChars = "\\xaa\\xb5\\xba\\xc0-\\xd6\\xd8-\\xf6\\xf8-\\u02c1\\u02c6-\\u02d1\\u02e0-\\u02e4\\u02ec\\u02ee\\u0370-\\u0374\\u0376\\u0377\\u037a-\\u037d\\u0386\\u0388-\\u038a\\u038c\\u038e-\\u03a1\\u03a3-\\u03f5\\u03f7-\\u0481\\u048a-\\u0527\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05d0-\\u05ea\\u05f0-\\u05f2\\u0620-\\u064a\\u066e\\u066f\\u0671-\\u06d3\\u06d5\\u06e5\\u06e6\\u06ee\\u06ef\\u06fa-\\u06fc\\u06ff\\u0710\\u0712-\\u072f\\u074d-\\u07a5\\u07b1\\u07ca-\\u07ea\\u07f4\\u07f5\\u07fa\\u0800-\\u0815\\u081a\\u0824\\u0828\\u0840-\\u0858\\u08a0\\u08a2-\\u08ac\\u0904-\\u0939\\u093d\\u0950\\u0958-\\u0961\\u0971-\\u0977\\u0979-\\u097f\\u0985-\\u098c\\u098f\\u0990\\u0993-\\u09a8\\u09aa-\\u09b0\\u09b2\\u09b6-\\u09b9\\u09bd\\u09ce\\u09dc\\u09dd\\u09df-\\u09e1\\u09f0\\u09f1\\u0a05-\\u0a0a\\u0a0f\\u0a10\\u0a13-\\u0a28\\u0a2a-\\u0a30\\u0a32\\u0a33\\u0a35\\u0a36\\u0a38\\u0a39\\u0a59-\\u0a5c\\u0a5e\\u0a72-\\u0a74\\u0a85-\\u0a8d\\u0a8f-\\u0a91\\u0a93-\\u0aa8\\u0aaa-\\u0ab0\\u0ab2\\u0ab3\\u0ab5-\\u0ab9\\u0abd\\u0ad0\\u0ae0\\u0ae1\\u0b05-\\u0b0c\\u0b0f\\u0b10\\u0b13-\\u0b28\\u0b2a-\\u0b30\\u0b32\\u0b33\\u0b35-\\u0b39\\u0b3d\\u0b5c\\u0b5d\\u0b5f-\\u0b61\\u0b71\\u0b83\\u0b85-\\u0b8a\\u0b8e-\\u0b90\\u0b92-\\u0b95\\u0b99\\u0b9a\\u0b9c\\u0b9e\\u0b9f\\u0ba3\\u0ba4\\u0ba8-\\u0baa\\u0bae-\\u0bb9\\u0bd0\\u0c05-\\u0c0c\\u0c0e-\\u0c10\\u0c12-\\u0c28\\u0c2a-\\u0c33\\u0c35-\\u0c39\\u0c3d\\u0c58\\u0c59\\u0c60\\u0c61\\u0c85-\\u0c8c\\u0c8e-\\u0c90\\u0c92-\\u0ca8\\u0caa-\\u0cb3\\u0cb5-\\u0cb9\\u0cbd\\u0cde\\u0ce0\\u0ce1\\u0cf1\\u0cf2\\u0d05-\\u0d0c\\u0d0e-\\u0d10\\u0d12-\\u0d3a\\u0d3d\\u0d4e\\u0d60\\u0d61\\u0d7a-\\u0d7f\\u0d85-\\u0d96\\u0d9a-\\u0db1\\u0db3-\\u0dbb\\u0dbd\\u0dc0-\\u0dc6\\u0e01-\\u0e30\\u0e32\\u0e33\\u0e40-\\u0e46\\u0e81\\u0e82\\u0e84\\u0e87\\u0e88\\u0e8a\\u0e8d\\u0e94-\\u0e97\\u0e99-\\u0e9f\\u0ea1-\\u0ea3\\u0ea5\\u0ea7\\u0eaa\\u0eab\\u0ead-\\u0eb0\\u0eb2\\u0eb3\\u0ebd\\u0ec0-\\u0ec4\\u0ec6\\u0edc-\\u0edf\\u0f00\\u0f40-\\u0f47\\u0f49-\\u0f6c\\u0f88-\\u0f8c\\u1000-\\u102a\\u103f\\u1050-\\u1055\\u105a-\\u105d\\u1061\\u1065\\u1066\\u106e-\\u1070\\u1075-\\u1081\\u108e\\u10a0-\\u10c5\\u10c7\\u10cd\\u10d0-\\u10fa\\u10fc-\\u1248\\u124a-\\u124d\\u1250-\\u1256\\u1258\\u125a-\\u125d\\u1260-\\u1288\\u128a-\\u128d\\u1290-\\u12b0\\u12b2-\\u12b5\\u12b8-\\u12be\\u12c0\\u12c2-\\u12c5\\u12c8-\\u12d6\\u12d8-\\u1310\\u1312-\\u1315\\u1318-\\u135a\\u1380-\\u138f\\u13a0-\\u13f4\\u1401-\\u166c\\u166f-\\u167f\\u1681-\\u169a\\u16a0-\\u16ea\\u16ee-\\u16f0\\u1700-\\u170c\\u170e-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176c\\u176e-\\u1770\\u1780-\\u17b3\\u17d7\\u17dc\\u1820-\\u1877\\u1880-\\u18a8\\u18aa\\u18b0-\\u18f5\\u1900-\\u191c\\u1950-\\u196d\\u1970-\\u1974\\u1980-\\u19ab\\u19c1-\\u19c7\\u1a00-\\u1a16\\u1a20-\\u1a54\\u1aa7\\u1b05-\\u1b33\\u1b45-\\u1b4b\\u1b83-\\u1ba0\\u1bae\\u1baf\\u1bba-\\u1be5\\u1c00-\\u1c23\\u1c4d-\\u1c4f\\u1c5a-\\u1c7d\\u1ce9-\\u1cec\\u1cee-\\u1cf1\\u1cf5\\u1cf6\\u1d00-\\u1dbf\\u1e00-\\u1f15\\u1f18-\\u1f1d\\u1f20-\\u1f45\\u1f48-\\u1f4d\\u1f50-\\u1f57\\u1f59\\u1f5b\\u1f5d\\u1f5f-\\u1f7d\\u1f80-\\u1fb4\\u1fb6-\\u1fbc\\u1fbe\\u1fc2-\\u1fc4\\u1fc6-\\u1fcc\\u1fd0-\\u1fd3\\u1fd6-\\u1fdb\\u1fe0-\\u1fec\\u1ff2-\\u1ff4\\u1ff6-\\u1ffc\\u2071\\u207f\\u2090-\\u209c\\u2102\\u2107\\u210a-\\u2113\\u2115\\u2119-\\u211d\\u2124\\u2126\\u2128\\u212a-\\u212d\\u212f-\\u2139\\u213c-\\u213f\\u2145-\\u2149\\u214e\\u2160-\\u2188\\u2c00-\\u2c2e\\u2c30-\\u2c5e\\u2c60-\\u2ce4\\u2ceb-\\u2cee\\u2cf2\\u2cf3\\u2d00-\\u2d25\\u2d27\\u2d2d\\u2d30-\\u2d67\\u2d6f\\u2d80-\\u2d96\\u2da0-\\u2da6\\u2da8-\\u2dae\\u2db0-\\u2db6\\u2db8-\\u2dbe\\u2dc0-\\u2dc6\\u2dc8-\\u2dce\\u2dd0-\\u2dd6\\u2dd8-\\u2dde\\u2e2f\\u3005-\\u3007\\u3021-\\u3029\\u3031-\\u3035\\u3038-\\u303c\\u3041-\\u3096\\u309d-\\u309f\\u30a1-\\u30fa\\u30fc-\\u30ff\\u3105-\\u312d\\u3131-\\u318e\\u31a0-\\u31ba\\u31f0-\\u31ff\\u3400-\\u4db5\\u4e00-\\u9fcc\\ua000-\\ua48c\\ua4d0-\\ua4fd\\ua500-\\ua60c\\ua610-\\ua61f\\ua62a\\ua62b\\ua640-\\ua66e\\ua67f-\\ua697\\ua6a0-\\ua6ef\\ua717-\\ua71f\\ua722-\\ua788\\ua78b-\\ua78e\\ua790-\\ua793\\ua7a0-\\ua7aa\\ua7f8-\\ua801\\ua803-\\ua805\\ua807-\\ua80a\\ua80c-\\ua822\\ua840-\\ua873\\ua882-\\ua8b3\\ua8f2-\\ua8f7\\ua8fb\\ua90a-\\ua925\\ua930-\\ua946\\ua960-\\ua97c\\ua984-\\ua9b2\\ua9cf\\uaa00-\\uaa28\\uaa40-\\uaa42\\uaa44-\\uaa4b\\uaa60-\\uaa76\\uaa7a\\uaa80-\\uaaaf\\uaab1\\uaab5\\uaab6\\uaab9-\\uaabd\\uaac0\\uaac2\\uaadb-\\uaadd\\uaae0-\\uaaea\\uaaf2-\\uaaf4\\uab01-\\uab06\\uab09-\\uab0e\\uab11-\\uab16\\uab20-\\uab26\\uab28-\\uab2e\\uabc0-\\uabe2\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\uf900-\\ufa6d\\ufa70-\\ufad9\\ufb00-\\ufb06\\ufb13-\\ufb17\\ufb1d\\ufb1f-\\ufb28\\ufb2a-\\ufb36\\ufb38-\\ufb3c\\ufb3e\\ufb40\\ufb41\\ufb43\\ufb44\\ufb46-\\ufbb1\\ufbd3-\\ufd3d\\ufd50-\\ufd8f\\ufd92-\\ufdc7\\ufdf0-\\ufdfb\\ufe70-\\ufe74\\ufe76-\\ufefc\\uff21-\\uff3a\\uff41-\\uff5a\\uff66-\\uffbe\\uffc2-\\uffc7\\uffca-\\uffcf\\uffd2-\\uffd7\\uffda-\\uffdc";
|
2089 | var nonASCIIidentifierChars = "\\u0300-\\u036f\\u0483-\\u0487\\u0591-\\u05bd\\u05bf\\u05c1\\u05c2\\u05c4\\u05c5\\u05c7\\u0610-\\u061a\\u0620-\\u0649\\u0672-\\u06d3\\u06e7-\\u06e8\\u06fb-\\u06fc\\u0730-\\u074a\\u0800-\\u0814\\u081b-\\u0823\\u0825-\\u0827\\u0829-\\u082d\\u0840-\\u0857\\u08e4-\\u08fe\\u0900-\\u0903\\u093a-\\u093c\\u093e-\\u094f\\u0951-\\u0957\\u0962-\\u0963\\u0966-\\u096f\\u0981-\\u0983\\u09bc\\u09be-\\u09c4\\u09c7\\u09c8\\u09d7\\u09df-\\u09e0\\u0a01-\\u0a03\\u0a3c\\u0a3e-\\u0a42\\u0a47\\u0a48\\u0a4b-\\u0a4d\\u0a51\\u0a66-\\u0a71\\u0a75\\u0a81-\\u0a83\\u0abc\\u0abe-\\u0ac5\\u0ac7-\\u0ac9\\u0acb-\\u0acd\\u0ae2-\\u0ae3\\u0ae6-\\u0aef\\u0b01-\\u0b03\\u0b3c\\u0b3e-\\u0b44\\u0b47\\u0b48\\u0b4b-\\u0b4d\\u0b56\\u0b57\\u0b5f-\\u0b60\\u0b66-\\u0b6f\\u0b82\\u0bbe-\\u0bc2\\u0bc6-\\u0bc8\\u0bca-\\u0bcd\\u0bd7\\u0be6-\\u0bef\\u0c01-\\u0c03\\u0c46-\\u0c48\\u0c4a-\\u0c4d\\u0c55\\u0c56\\u0c62-\\u0c63\\u0c66-\\u0c6f\\u0c82\\u0c83\\u0cbc\\u0cbe-\\u0cc4\\u0cc6-\\u0cc8\\u0cca-\\u0ccd\\u0cd5\\u0cd6\\u0ce2-\\u0ce3\\u0ce6-\\u0cef\\u0d02\\u0d03\\u0d46-\\u0d48\\u0d57\\u0d62-\\u0d63\\u0d66-\\u0d6f\\u0d82\\u0d83\\u0dca\\u0dcf-\\u0dd4\\u0dd6\\u0dd8-\\u0ddf\\u0df2\\u0df3\\u0e34-\\u0e3a\\u0e40-\\u0e45\\u0e50-\\u0e59\\u0eb4-\\u0eb9\\u0ec8-\\u0ecd\\u0ed0-\\u0ed9\\u0f18\\u0f19\\u0f20-\\u0f29\\u0f35\\u0f37\\u0f39\\u0f41-\\u0f47\\u0f71-\\u0f84\\u0f86-\\u0f87\\u0f8d-\\u0f97\\u0f99-\\u0fbc\\u0fc6\\u1000-\\u1029\\u1040-\\u1049\\u1067-\\u106d\\u1071-\\u1074\\u1082-\\u108d\\u108f-\\u109d\\u135d-\\u135f\\u170e-\\u1710\\u1720-\\u1730\\u1740-\\u1750\\u1772\\u1773\\u1780-\\u17b2\\u17dd\\u17e0-\\u17e9\\u180b-\\u180d\\u1810-\\u1819\\u1920-\\u192b\\u1930-\\u193b\\u1951-\\u196d\\u19b0-\\u19c0\\u19c8-\\u19c9\\u19d0-\\u19d9\\u1a00-\\u1a15\\u1a20-\\u1a53\\u1a60-\\u1a7c\\u1a7f-\\u1a89\\u1a90-\\u1a99\\u1b46-\\u1b4b\\u1b50-\\u1b59\\u1b6b-\\u1b73\\u1bb0-\\u1bb9\\u1be6-\\u1bf3\\u1c00-\\u1c22\\u1c40-\\u1c49\\u1c5b-\\u1c7d\\u1cd0-\\u1cd2\\u1d00-\\u1dbe\\u1e01-\\u1f15\\u200c\\u200d\\u203f\\u2040\\u2054\\u20d0-\\u20dc\\u20e1\\u20e5-\\u20f0\\u2d81-\\u2d96\\u2de0-\\u2dff\\u3021-\\u3028\\u3099\\u309a\\ua640-\\ua66d\\ua674-\\ua67d\\ua69f\\ua6f0-\\ua6f1\\ua7f8-\\ua800\\ua806\\ua80b\\ua823-\\ua827\\ua880-\\ua881\\ua8b4-\\ua8c4\\ua8d0-\\ua8d9\\ua8f3-\\ua8f7\\ua900-\\ua909\\ua926-\\ua92d\\ua930-\\ua945\\ua980-\\ua983\\ua9b3-\\ua9c0\\uaa00-\\uaa27\\uaa40-\\uaa41\\uaa4c-\\uaa4d\\uaa50-\\uaa59\\uaa7b\\uaae0-\\uaae9\\uaaf2-\\uaaf3\\uabc0-\\uabe1\\uabec\\uabed\\uabf0-\\uabf9\\ufb20-\\ufb28\\ufe00-\\ufe0f\\ufe20-\\ufe26\\ufe33\\ufe34\\ufe4d-\\ufe4f\\uff10-\\uff19\\uff3f";
|
2090 |
|
2091 |
|
2092 |
|
2093 | var identifierStart = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "])";
|
2094 | var identifierChars = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])*";
|
2095 |
|
2096 | exports.identifier = new RegExp(identifierStart + identifierChars, 'g');
|
2097 | exports.identifierStart = new RegExp(identifierStart);
|
2098 | exports.identifierMatch = new RegExp("(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])+");
|
2099 |
|
2100 |
|
2101 |
|
2102 | exports.newline = /[\n\r\u2028\u2029]/;
|
2103 |
|
2104 |
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 | exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
|
2110 | exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
|
2111 | } (acorn));
|
2112 | return acorn;
|
2113 | }
|
2114 |
|
2115 | var options$3 = {};
|
2116 |
|
2117 | var options$2 = {};
|
2118 |
|
2119 |
|
2120 |
|
2121 | var hasRequiredOptions$3;
|
2122 |
|
2123 | function requireOptions$3 () {
|
2124 | if (hasRequiredOptions$3) return options$2;
|
2125 | hasRequiredOptions$3 = 1;
|
2126 |
|
2127 | function Options(options, merge_child_field) {
|
2128 | this.raw_options = _mergeOpts(options, merge_child_field);
|
2129 |
|
2130 |
|
2131 | this.disabled = this._get_boolean('disabled');
|
2132 |
|
2133 | this.eol = this._get_characters('eol', 'auto');
|
2134 | this.end_with_newline = this._get_boolean('end_with_newline');
|
2135 | this.indent_size = this._get_number('indent_size', 4);
|
2136 | this.indent_char = this._get_characters('indent_char', ' ');
|
2137 | this.indent_level = this._get_number('indent_level');
|
2138 |
|
2139 | this.preserve_newlines = this._get_boolean('preserve_newlines', true);
|
2140 | this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
|
2141 | if (!this.preserve_newlines) {
|
2142 | this.max_preserve_newlines = 0;
|
2143 | }
|
2144 |
|
2145 | this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
|
2146 | if (this.indent_with_tabs) {
|
2147 | this.indent_char = '\t';
|
2148 |
|
2149 |
|
2150 |
|
2151 |
|
2152 |
|
2153 |
|
2154 |
|
2155 |
|
2156 | if (this.indent_size === 1) {
|
2157 | this.indent_size = 4;
|
2158 | }
|
2159 | }
|
2160 |
|
2161 |
|
2162 | this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
|
2163 |
|
2164 | this.indent_empty_lines = this._get_boolean('indent_empty_lines');
|
2165 |
|
2166 |
|
2167 |
|
2168 |
|
2169 | this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
|
2170 | }
|
2171 |
|
2172 | Options.prototype._get_array = function(name, default_value) {
|
2173 | var option_value = this.raw_options[name];
|
2174 | var result = default_value || [];
|
2175 | if (typeof option_value === 'object') {
|
2176 | if (option_value !== null && typeof option_value.concat === 'function') {
|
2177 | result = option_value.concat();
|
2178 | }
|
2179 | } else if (typeof option_value === 'string') {
|
2180 | result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
|
2181 | }
|
2182 | return result;
|
2183 | };
|
2184 |
|
2185 | Options.prototype._get_boolean = function(name, default_value) {
|
2186 | var option_value = this.raw_options[name];
|
2187 | var result = option_value === undefined ? !!default_value : !!option_value;
|
2188 | return result;
|
2189 | };
|
2190 |
|
2191 | Options.prototype._get_characters = function(name, default_value) {
|
2192 | var option_value = this.raw_options[name];
|
2193 | var result = default_value || '';
|
2194 | if (typeof option_value === 'string') {
|
2195 | result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
|
2196 | }
|
2197 | return result;
|
2198 | };
|
2199 |
|
2200 | Options.prototype._get_number = function(name, default_value) {
|
2201 | var option_value = this.raw_options[name];
|
2202 | default_value = parseInt(default_value, 10);
|
2203 | if (isNaN(default_value)) {
|
2204 | default_value = 0;
|
2205 | }
|
2206 | var result = parseInt(option_value, 10);
|
2207 | if (isNaN(result)) {
|
2208 | result = default_value;
|
2209 | }
|
2210 | return result;
|
2211 | };
|
2212 |
|
2213 | Options.prototype._get_selection = function(name, selection_list, default_value) {
|
2214 | var result = this._get_selection_list(name, selection_list, default_value);
|
2215 | if (result.length !== 1) {
|
2216 | throw new Error(
|
2217 | "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
|
2218 | selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
|
2219 | }
|
2220 |
|
2221 | return result[0];
|
2222 | };
|
2223 |
|
2224 |
|
2225 | Options.prototype._get_selection_list = function(name, selection_list, default_value) {
|
2226 | if (!selection_list || selection_list.length === 0) {
|
2227 | throw new Error("Selection list cannot be empty.");
|
2228 | }
|
2229 |
|
2230 | default_value = default_value || [selection_list[0]];
|
2231 | if (!this._is_valid_selection(default_value, selection_list)) {
|
2232 | throw new Error("Invalid Default Value!");
|
2233 | }
|
2234 |
|
2235 | var result = this._get_array(name, default_value);
|
2236 | if (!this._is_valid_selection(result, selection_list)) {
|
2237 | throw new Error(
|
2238 | "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
|
2239 | selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
|
2240 | }
|
2241 |
|
2242 | return result;
|
2243 | };
|
2244 |
|
2245 | Options.prototype._is_valid_selection = function(result, selection_list) {
|
2246 | return result.length && selection_list.length &&
|
2247 | !result.some(function(item) { return selection_list.indexOf(item) === -1; });
|
2248 | };
|
2249 |
|
2250 |
|
2251 |
|
2252 |
|
2253 |
|
2254 |
|
2255 |
|
2256 | function _mergeOpts(allOptions, childFieldName) {
|
2257 | var finalOpts = {};
|
2258 | allOptions = _normalizeOpts(allOptions);
|
2259 | var name;
|
2260 |
|
2261 | for (name in allOptions) {
|
2262 | if (name !== childFieldName) {
|
2263 | finalOpts[name] = allOptions[name];
|
2264 | }
|
2265 | }
|
2266 |
|
2267 |
|
2268 | if (childFieldName && allOptions[childFieldName]) {
|
2269 | for (name in allOptions[childFieldName]) {
|
2270 | finalOpts[name] = allOptions[childFieldName][name];
|
2271 | }
|
2272 | }
|
2273 | return finalOpts;
|
2274 | }
|
2275 |
|
2276 | function _normalizeOpts(options) {
|
2277 | var convertedOpts = {};
|
2278 | var key;
|
2279 |
|
2280 | for (key in options) {
|
2281 | var newKey = key.replace(/-/g, "_");
|
2282 | convertedOpts[newKey] = options[key];
|
2283 | }
|
2284 | return convertedOpts;
|
2285 | }
|
2286 |
|
2287 | options$2.Options = Options;
|
2288 | options$2.normalizeOpts = _normalizeOpts;
|
2289 | options$2.mergeOpts = _mergeOpts;
|
2290 | return options$2;
|
2291 | }
|
2292 |
|
2293 |
|
2294 |
|
2295 | var hasRequiredOptions$2;
|
2296 |
|
2297 | function requireOptions$2 () {
|
2298 | if (hasRequiredOptions$2) return options$3;
|
2299 | hasRequiredOptions$2 = 1;
|
2300 |
|
2301 | var BaseOptions = requireOptions$3().Options;
|
2302 |
|
2303 | var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
|
2304 |
|
2305 | function Options(options) {
|
2306 | BaseOptions.call(this, options, 'js');
|
2307 |
|
2308 |
|
2309 | var raw_brace_style = this.raw_options.brace_style || null;
|
2310 | if (raw_brace_style === "expand-strict") {
|
2311 | this.raw_options.brace_style = "expand";
|
2312 | } else if (raw_brace_style === "collapse-preserve-inline") {
|
2313 | this.raw_options.brace_style = "collapse,preserve-inline";
|
2314 | } else if (this.raw_options.braces_on_own_line !== undefined) {
|
2315 | this.raw_options.brace_style = this.raw_options.braces_on_own_line ? "expand" : "collapse";
|
2316 |
|
2317 |
|
2318 | }
|
2319 |
|
2320 |
|
2321 |
|
2322 |
|
2323 | var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
|
2324 |
|
2325 | this.brace_preserve_inline = false;
|
2326 | this.brace_style = "collapse";
|
2327 |
|
2328 | for (var bs = 0; bs < brace_style_split.length; bs++) {
|
2329 | if (brace_style_split[bs] === "preserve-inline") {
|
2330 | this.brace_preserve_inline = true;
|
2331 | } else {
|
2332 | this.brace_style = brace_style_split[bs];
|
2333 | }
|
2334 | }
|
2335 |
|
2336 | this.unindent_chained_methods = this._get_boolean('unindent_chained_methods');
|
2337 | this.break_chained_methods = this._get_boolean('break_chained_methods');
|
2338 | this.space_in_paren = this._get_boolean('space_in_paren');
|
2339 | this.space_in_empty_paren = this._get_boolean('space_in_empty_paren');
|
2340 | this.jslint_happy = this._get_boolean('jslint_happy');
|
2341 | this.space_after_anon_function = this._get_boolean('space_after_anon_function');
|
2342 | this.space_after_named_function = this._get_boolean('space_after_named_function');
|
2343 | this.keep_array_indentation = this._get_boolean('keep_array_indentation');
|
2344 | this.space_before_conditional = this._get_boolean('space_before_conditional', true);
|
2345 | this.unescape_strings = this._get_boolean('unescape_strings');
|
2346 | this.e4x = this._get_boolean('e4x');
|
2347 | this.comma_first = this._get_boolean('comma_first');
|
2348 | this.operator_position = this._get_selection('operator_position', validPositionValues);
|
2349 |
|
2350 |
|
2351 | this.test_output_raw = this._get_boolean('test_output_raw');
|
2352 |
|
2353 |
|
2354 | if (this.jslint_happy) {
|
2355 | this.space_after_anon_function = true;
|
2356 | }
|
2357 |
|
2358 | }
|
2359 | Options.prototype = new BaseOptions();
|
2360 |
|
2361 |
|
2362 |
|
2363 | options$3.Options = Options;
|
2364 | return options$3;
|
2365 | }
|
2366 |
|
2367 | var tokenizer$3 = {};
|
2368 |
|
2369 | var inputscanner = {};
|
2370 |
|
2371 |
|
2372 |
|
2373 | var hasRequiredInputscanner;
|
2374 |
|
2375 | function requireInputscanner () {
|
2376 | if (hasRequiredInputscanner) return inputscanner;
|
2377 | hasRequiredInputscanner = 1;
|
2378 |
|
2379 | var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
|
2380 |
|
2381 | function InputScanner(input_string) {
|
2382 | this.__input = input_string || '';
|
2383 | this.__input_length = this.__input.length;
|
2384 | this.__position = 0;
|
2385 | }
|
2386 |
|
2387 | InputScanner.prototype.restart = function() {
|
2388 | this.__position = 0;
|
2389 | };
|
2390 |
|
2391 | InputScanner.prototype.back = function() {
|
2392 | if (this.__position > 0) {
|
2393 | this.__position -= 1;
|
2394 | }
|
2395 | };
|
2396 |
|
2397 | InputScanner.prototype.hasNext = function() {
|
2398 | return this.__position < this.__input_length;
|
2399 | };
|
2400 |
|
2401 | InputScanner.prototype.next = function() {
|
2402 | var val = null;
|
2403 | if (this.hasNext()) {
|
2404 | val = this.__input.charAt(this.__position);
|
2405 | this.__position += 1;
|
2406 | }
|
2407 | return val;
|
2408 | };
|
2409 |
|
2410 | InputScanner.prototype.peek = function(index) {
|
2411 | var val = null;
|
2412 | index = index || 0;
|
2413 | index += this.__position;
|
2414 | if (index >= 0 && index < this.__input_length) {
|
2415 | val = this.__input.charAt(index);
|
2416 | }
|
2417 | return val;
|
2418 | };
|
2419 |
|
2420 |
|
2421 |
|
2422 |
|
2423 |
|
2424 |
|
2425 |
|
2426 |
|
2427 | InputScanner.prototype.__match = function(pattern, index) {
|
2428 | pattern.lastIndex = index;
|
2429 | var pattern_match = pattern.exec(this.__input);
|
2430 |
|
2431 | if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
|
2432 | if (pattern_match.index !== index) {
|
2433 | pattern_match = null;
|
2434 | }
|
2435 | }
|
2436 |
|
2437 | return pattern_match;
|
2438 | };
|
2439 |
|
2440 | InputScanner.prototype.test = function(pattern, index) {
|
2441 | index = index || 0;
|
2442 | index += this.__position;
|
2443 |
|
2444 | if (index >= 0 && index < this.__input_length) {
|
2445 | return !!this.__match(pattern, index);
|
2446 | } else {
|
2447 | return false;
|
2448 | }
|
2449 | };
|
2450 |
|
2451 | InputScanner.prototype.testChar = function(pattern, index) {
|
2452 |
|
2453 | var val = this.peek(index);
|
2454 | pattern.lastIndex = 0;
|
2455 | return val !== null && pattern.test(val);
|
2456 | };
|
2457 |
|
2458 | InputScanner.prototype.match = function(pattern) {
|
2459 | var pattern_match = this.__match(pattern, this.__position);
|
2460 | if (pattern_match) {
|
2461 | this.__position += pattern_match[0].length;
|
2462 | } else {
|
2463 | pattern_match = null;
|
2464 | }
|
2465 | return pattern_match;
|
2466 | };
|
2467 |
|
2468 | InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
|
2469 | var val = '';
|
2470 | var match;
|
2471 | if (starting_pattern) {
|
2472 | match = this.match(starting_pattern);
|
2473 | if (match) {
|
2474 | val += match[0];
|
2475 | }
|
2476 | }
|
2477 | if (until_pattern && (match || !starting_pattern)) {
|
2478 | val += this.readUntil(until_pattern, until_after);
|
2479 | }
|
2480 | return val;
|
2481 | };
|
2482 |
|
2483 | InputScanner.prototype.readUntil = function(pattern, until_after) {
|
2484 | var val = '';
|
2485 | var match_index = this.__position;
|
2486 | pattern.lastIndex = this.__position;
|
2487 | var pattern_match = pattern.exec(this.__input);
|
2488 | if (pattern_match) {
|
2489 | match_index = pattern_match.index;
|
2490 | if (until_after) {
|
2491 | match_index += pattern_match[0].length;
|
2492 | }
|
2493 | } else {
|
2494 | match_index = this.__input_length;
|
2495 | }
|
2496 |
|
2497 | val = this.__input.substring(this.__position, match_index);
|
2498 | this.__position = match_index;
|
2499 | return val;
|
2500 | };
|
2501 |
|
2502 | InputScanner.prototype.readUntilAfter = function(pattern) {
|
2503 | return this.readUntil(pattern, true);
|
2504 | };
|
2505 |
|
2506 | InputScanner.prototype.get_regexp = function(pattern, match_from) {
|
2507 | var result = null;
|
2508 | var flags = 'g';
|
2509 | if (match_from && regexp_has_sticky) {
|
2510 | flags = 'y';
|
2511 | }
|
2512 |
|
2513 | if (typeof pattern === "string" && pattern !== '') {
|
2514 |
|
2515 | result = new RegExp(pattern, flags);
|
2516 | } else if (pattern) {
|
2517 | result = new RegExp(pattern.source, flags);
|
2518 | }
|
2519 | return result;
|
2520 | };
|
2521 |
|
2522 | InputScanner.prototype.get_literal_regexp = function(literal_string) {
|
2523 | return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
|
2524 | };
|
2525 |
|
2526 |
|
2527 | InputScanner.prototype.peekUntilAfter = function(pattern) {
|
2528 | var start = this.__position;
|
2529 | var val = this.readUntilAfter(pattern);
|
2530 | this.__position = start;
|
2531 | return val;
|
2532 | };
|
2533 |
|
2534 | InputScanner.prototype.lookBack = function(testVal) {
|
2535 | var start = this.__position - 1;
|
2536 | return start >= testVal.length && this.__input.substring(start - testVal.length, start)
|
2537 | .toLowerCase() === testVal;
|
2538 | };
|
2539 |
|
2540 | inputscanner.InputScanner = InputScanner;
|
2541 | return inputscanner;
|
2542 | }
|
2543 |
|
2544 | var tokenizer$2 = {};
|
2545 |
|
2546 | var tokenstream = {};
|
2547 |
|
2548 |
|
2549 |
|
2550 | var hasRequiredTokenstream;
|
2551 |
|
2552 | function requireTokenstream () {
|
2553 | if (hasRequiredTokenstream) return tokenstream;
|
2554 | hasRequiredTokenstream = 1;
|
2555 |
|
2556 | function TokenStream(parent_token) {
|
2557 |
|
2558 | this.__tokens = [];
|
2559 | this.__tokens_length = this.__tokens.length;
|
2560 | this.__position = 0;
|
2561 | this.__parent_token = parent_token;
|
2562 | }
|
2563 |
|
2564 | TokenStream.prototype.restart = function() {
|
2565 | this.__position = 0;
|
2566 | };
|
2567 |
|
2568 | TokenStream.prototype.isEmpty = function() {
|
2569 | return this.__tokens_length === 0;
|
2570 | };
|
2571 |
|
2572 | TokenStream.prototype.hasNext = function() {
|
2573 | return this.__position < this.__tokens_length;
|
2574 | };
|
2575 |
|
2576 | TokenStream.prototype.next = function() {
|
2577 | var val = null;
|
2578 | if (this.hasNext()) {
|
2579 | val = this.__tokens[this.__position];
|
2580 | this.__position += 1;
|
2581 | }
|
2582 | return val;
|
2583 | };
|
2584 |
|
2585 | TokenStream.prototype.peek = function(index) {
|
2586 | var val = null;
|
2587 | index = index || 0;
|
2588 | index += this.__position;
|
2589 | if (index >= 0 && index < this.__tokens_length) {
|
2590 | val = this.__tokens[index];
|
2591 | }
|
2592 | return val;
|
2593 | };
|
2594 |
|
2595 | TokenStream.prototype.add = function(token) {
|
2596 | if (this.__parent_token) {
|
2597 | token.parent = this.__parent_token;
|
2598 | }
|
2599 | this.__tokens.push(token);
|
2600 | this.__tokens_length += 1;
|
2601 | };
|
2602 |
|
2603 | tokenstream.TokenStream = TokenStream;
|
2604 | return tokenstream;
|
2605 | }
|
2606 |
|
2607 | var whitespacepattern = {};
|
2608 |
|
2609 | var pattern = {};
|
2610 |
|
2611 |
|
2612 |
|
2613 | var hasRequiredPattern;
|
2614 |
|
2615 | function requirePattern () {
|
2616 | if (hasRequiredPattern) return pattern;
|
2617 | hasRequiredPattern = 1;
|
2618 |
|
2619 | function Pattern(input_scanner, parent) {
|
2620 | this._input = input_scanner;
|
2621 | this._starting_pattern = null;
|
2622 | this._match_pattern = null;
|
2623 | this._until_pattern = null;
|
2624 | this._until_after = false;
|
2625 |
|
2626 | if (parent) {
|
2627 | this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true);
|
2628 | this._match_pattern = this._input.get_regexp(parent._match_pattern, true);
|
2629 | this._until_pattern = this._input.get_regexp(parent._until_pattern);
|
2630 | this._until_after = parent._until_after;
|
2631 | }
|
2632 | }
|
2633 |
|
2634 | Pattern.prototype.read = function() {
|
2635 | var result = this._input.read(this._starting_pattern);
|
2636 | if (!this._starting_pattern || result) {
|
2637 | result += this._input.read(this._match_pattern, this._until_pattern, this._until_after);
|
2638 | }
|
2639 | return result;
|
2640 | };
|
2641 |
|
2642 | Pattern.prototype.read_match = function() {
|
2643 | return this._input.match(this._match_pattern);
|
2644 | };
|
2645 |
|
2646 | Pattern.prototype.until_after = function(pattern) {
|
2647 | var result = this._create();
|
2648 | result._until_after = true;
|
2649 | result._until_pattern = this._input.get_regexp(pattern);
|
2650 | result._update();
|
2651 | return result;
|
2652 | };
|
2653 |
|
2654 | Pattern.prototype.until = function(pattern) {
|
2655 | var result = this._create();
|
2656 | result._until_after = false;
|
2657 | result._until_pattern = this._input.get_regexp(pattern);
|
2658 | result._update();
|
2659 | return result;
|
2660 | };
|
2661 |
|
2662 | Pattern.prototype.starting_with = function(pattern) {
|
2663 | var result = this._create();
|
2664 | result._starting_pattern = this._input.get_regexp(pattern, true);
|
2665 | result._update();
|
2666 | return result;
|
2667 | };
|
2668 |
|
2669 | Pattern.prototype.matching = function(pattern) {
|
2670 | var result = this._create();
|
2671 | result._match_pattern = this._input.get_regexp(pattern, true);
|
2672 | result._update();
|
2673 | return result;
|
2674 | };
|
2675 |
|
2676 | Pattern.prototype._create = function() {
|
2677 | return new Pattern(this._input, this);
|
2678 | };
|
2679 |
|
2680 | Pattern.prototype._update = function() {};
|
2681 |
|
2682 | pattern.Pattern = Pattern;
|
2683 | return pattern;
|
2684 | }
|
2685 |
|
2686 |
|
2687 |
|
2688 | var hasRequiredWhitespacepattern;
|
2689 |
|
2690 | function requireWhitespacepattern () {
|
2691 | if (hasRequiredWhitespacepattern) return whitespacepattern;
|
2692 | hasRequiredWhitespacepattern = 1;
|
2693 |
|
2694 | var Pattern = requirePattern().Pattern;
|
2695 |
|
2696 | function WhitespacePattern(input_scanner, parent) {
|
2697 | Pattern.call(this, input_scanner, parent);
|
2698 | if (parent) {
|
2699 | this._line_regexp = this._input.get_regexp(parent._line_regexp);
|
2700 | } else {
|
2701 | this.__set_whitespace_patterns('', '');
|
2702 | }
|
2703 |
|
2704 | this.newline_count = 0;
|
2705 | this.whitespace_before_token = '';
|
2706 | }
|
2707 | WhitespacePattern.prototype = new Pattern();
|
2708 |
|
2709 | WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) {
|
2710 | whitespace_chars += '\\t ';
|
2711 | newline_chars += '\\n\\r';
|
2712 |
|
2713 | this._match_pattern = this._input.get_regexp(
|
2714 | '[' + whitespace_chars + newline_chars + ']+', true);
|
2715 | this._newline_regexp = this._input.get_regexp(
|
2716 | '\\r\\n|[' + newline_chars + ']');
|
2717 | };
|
2718 |
|
2719 | WhitespacePattern.prototype.read = function() {
|
2720 | this.newline_count = 0;
|
2721 | this.whitespace_before_token = '';
|
2722 |
|
2723 | var resulting_string = this._input.read(this._match_pattern);
|
2724 | if (resulting_string === ' ') {
|
2725 | this.whitespace_before_token = ' ';
|
2726 | } else if (resulting_string) {
|
2727 | var matches = this.__split(this._newline_regexp, resulting_string);
|
2728 | this.newline_count = matches.length - 1;
|
2729 | this.whitespace_before_token = matches[this.newline_count];
|
2730 | }
|
2731 |
|
2732 | return resulting_string;
|
2733 | };
|
2734 |
|
2735 | WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) {
|
2736 | var result = this._create();
|
2737 | result.__set_whitespace_patterns(whitespace_chars, newline_chars);
|
2738 | result._update();
|
2739 | return result;
|
2740 | };
|
2741 |
|
2742 | WhitespacePattern.prototype._create = function() {
|
2743 | return new WhitespacePattern(this._input, this);
|
2744 | };
|
2745 |
|
2746 | WhitespacePattern.prototype.__split = function(regexp, input_string) {
|
2747 | regexp.lastIndex = 0;
|
2748 | var start_index = 0;
|
2749 | var result = [];
|
2750 | var next_match = regexp.exec(input_string);
|
2751 | while (next_match) {
|
2752 | result.push(input_string.substring(start_index, next_match.index));
|
2753 | start_index = next_match.index + next_match[0].length;
|
2754 | next_match = regexp.exec(input_string);
|
2755 | }
|
2756 |
|
2757 | if (start_index < input_string.length) {
|
2758 | result.push(input_string.substring(start_index, input_string.length));
|
2759 | } else {
|
2760 | result.push('');
|
2761 | }
|
2762 |
|
2763 | return result;
|
2764 | };
|
2765 |
|
2766 |
|
2767 |
|
2768 | whitespacepattern.WhitespacePattern = WhitespacePattern;
|
2769 | return whitespacepattern;
|
2770 | }
|
2771 |
|
2772 |
|
2773 |
|
2774 | var hasRequiredTokenizer$2;
|
2775 |
|
2776 | function requireTokenizer$2 () {
|
2777 | if (hasRequiredTokenizer$2) return tokenizer$2;
|
2778 | hasRequiredTokenizer$2 = 1;
|
2779 |
|
2780 | var InputScanner = requireInputscanner().InputScanner;
|
2781 | var Token = requireToken().Token;
|
2782 | var TokenStream = requireTokenstream().TokenStream;
|
2783 | var WhitespacePattern = requireWhitespacepattern().WhitespacePattern;
|
2784 |
|
2785 | var TOKEN = {
|
2786 | START: 'TK_START',
|
2787 | RAW: 'TK_RAW',
|
2788 | EOF: 'TK_EOF'
|
2789 | };
|
2790 |
|
2791 | var Tokenizer = function(input_string, options) {
|
2792 | this._input = new InputScanner(input_string);
|
2793 | this._options = options || {};
|
2794 | this.__tokens = null;
|
2795 |
|
2796 | this._patterns = {};
|
2797 | this._patterns.whitespace = new WhitespacePattern(this._input);
|
2798 | };
|
2799 |
|
2800 | Tokenizer.prototype.tokenize = function() {
|
2801 | this._input.restart();
|
2802 | this.__tokens = new TokenStream();
|
2803 |
|
2804 | this._reset();
|
2805 |
|
2806 | var current;
|
2807 | var previous = new Token(TOKEN.START, '');
|
2808 | var open_token = null;
|
2809 | var open_stack = [];
|
2810 | var comments = new TokenStream();
|
2811 |
|
2812 | while (previous.type !== TOKEN.EOF) {
|
2813 | current = this._get_next_token(previous, open_token);
|
2814 | while (this._is_comment(current)) {
|
2815 | comments.add(current);
|
2816 | current = this._get_next_token(previous, open_token);
|
2817 | }
|
2818 |
|
2819 | if (!comments.isEmpty()) {
|
2820 | current.comments_before = comments;
|
2821 | comments = new TokenStream();
|
2822 | }
|
2823 |
|
2824 | current.parent = open_token;
|
2825 |
|
2826 | if (this._is_opening(current)) {
|
2827 | open_stack.push(open_token);
|
2828 | open_token = current;
|
2829 | } else if (open_token && this._is_closing(current, open_token)) {
|
2830 | current.opened = open_token;
|
2831 | open_token.closed = current;
|
2832 | open_token = open_stack.pop();
|
2833 | current.parent = open_token;
|
2834 | }
|
2835 |
|
2836 | current.previous = previous;
|
2837 | previous.next = current;
|
2838 |
|
2839 | this.__tokens.add(current);
|
2840 | previous = current;
|
2841 | }
|
2842 |
|
2843 | return this.__tokens;
|
2844 | };
|
2845 |
|
2846 |
|
2847 | Tokenizer.prototype._is_first_token = function() {
|
2848 | return this.__tokens.isEmpty();
|
2849 | };
|
2850 |
|
2851 | Tokenizer.prototype._reset = function() {};
|
2852 |
|
2853 | Tokenizer.prototype._get_next_token = function(previous_token, open_token) {
|
2854 | this._readWhitespace();
|
2855 | var resulting_string = this._input.read(/.+/g);
|
2856 | if (resulting_string) {
|
2857 | return this._create_token(TOKEN.RAW, resulting_string);
|
2858 | } else {
|
2859 | return this._create_token(TOKEN.EOF, '');
|
2860 | }
|
2861 | };
|
2862 |
|
2863 | Tokenizer.prototype._is_comment = function(current_token) {
|
2864 | return false;
|
2865 | };
|
2866 |
|
2867 | Tokenizer.prototype._is_opening = function(current_token) {
|
2868 | return false;
|
2869 | };
|
2870 |
|
2871 | Tokenizer.prototype._is_closing = function(current_token, open_token) {
|
2872 | return false;
|
2873 | };
|
2874 |
|
2875 | Tokenizer.prototype._create_token = function(type, text) {
|
2876 | var token = new Token(type, text,
|
2877 | this._patterns.whitespace.newline_count,
|
2878 | this._patterns.whitespace.whitespace_before_token);
|
2879 | return token;
|
2880 | };
|
2881 |
|
2882 | Tokenizer.prototype._readWhitespace = function() {
|
2883 | return this._patterns.whitespace.read();
|
2884 | };
|
2885 |
|
2886 |
|
2887 |
|
2888 | tokenizer$2.Tokenizer = Tokenizer;
|
2889 | tokenizer$2.TOKEN = TOKEN;
|
2890 | return tokenizer$2;
|
2891 | }
|
2892 |
|
2893 | var directives = {};
|
2894 |
|
2895 |
|
2896 |
|
2897 | var hasRequiredDirectives;
|
2898 |
|
2899 | function requireDirectives () {
|
2900 | if (hasRequiredDirectives) return directives;
|
2901 | hasRequiredDirectives = 1;
|
2902 |
|
2903 | function Directives(start_block_pattern, end_block_pattern) {
|
2904 | start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
|
2905 | end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
|
2906 | this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
|
2907 | this.__directive_pattern = / (\w+)[:](\w+)/g;
|
2908 |
|
2909 | this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
|
2910 | }
|
2911 |
|
2912 | Directives.prototype.get_directives = function(text) {
|
2913 | if (!text.match(this.__directives_block_pattern)) {
|
2914 | return null;
|
2915 | }
|
2916 |
|
2917 | var directives = {};
|
2918 | this.__directive_pattern.lastIndex = 0;
|
2919 | var directive_match = this.__directive_pattern.exec(text);
|
2920 |
|
2921 | while (directive_match) {
|
2922 | directives[directive_match[1]] = directive_match[2];
|
2923 | directive_match = this.__directive_pattern.exec(text);
|
2924 | }
|
2925 |
|
2926 | return directives;
|
2927 | };
|
2928 |
|
2929 | Directives.prototype.readIgnored = function(input) {
|
2930 | return input.readUntilAfter(this.__directives_end_ignore_pattern);
|
2931 | };
|
2932 |
|
2933 |
|
2934 | directives.Directives = Directives;
|
2935 | return directives;
|
2936 | }
|
2937 |
|
2938 | var templatablepattern = {};
|
2939 |
|
2940 |
|
2941 |
|
2942 | var hasRequiredTemplatablepattern;
|
2943 |
|
2944 | function requireTemplatablepattern () {
|
2945 | if (hasRequiredTemplatablepattern) return templatablepattern;
|
2946 | hasRequiredTemplatablepattern = 1;
|
2947 |
|
2948 | var Pattern = requirePattern().Pattern;
|
2949 |
|
2950 |
|
2951 | var template_names = {
|
2952 | django: false,
|
2953 | erb: false,
|
2954 | handlebars: false,
|
2955 | php: false,
|
2956 | smarty: false
|
2957 | };
|
2958 |
|
2959 |
|
2960 |
|
2961 | function TemplatablePattern(input_scanner, parent) {
|
2962 | Pattern.call(this, input_scanner, parent);
|
2963 | this.__template_pattern = null;
|
2964 | this._disabled = Object.assign({}, template_names);
|
2965 | this._excluded = Object.assign({}, template_names);
|
2966 |
|
2967 | if (parent) {
|
2968 | this.__template_pattern = this._input.get_regexp(parent.__template_pattern);
|
2969 | this._excluded = Object.assign(this._excluded, parent._excluded);
|
2970 | this._disabled = Object.assign(this._disabled, parent._disabled);
|
2971 | }
|
2972 | var pattern = new Pattern(input_scanner);
|
2973 | this.__patterns = {
|
2974 | handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
|
2975 | handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
|
2976 | handlebars: pattern.starting_with(/{{/).until_after(/}}/),
|
2977 | php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/),
|
2978 | erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
|
2979 |
|
2980 | django: pattern.starting_with(/{%/).until_after(/%}/),
|
2981 | django_value: pattern.starting_with(/{{/).until_after(/}}/),
|
2982 | django_comment: pattern.starting_with(/{#/).until_after(/#}/),
|
2983 | smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/),
|
2984 | smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/),
|
2985 | smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/)
|
2986 | };
|
2987 | }
|
2988 | TemplatablePattern.prototype = new Pattern();
|
2989 |
|
2990 | TemplatablePattern.prototype._create = function() {
|
2991 | return new TemplatablePattern(this._input, this);
|
2992 | };
|
2993 |
|
2994 | TemplatablePattern.prototype._update = function() {
|
2995 | this.__set_templated_pattern();
|
2996 | };
|
2997 |
|
2998 | TemplatablePattern.prototype.disable = function(language) {
|
2999 | var result = this._create();
|
3000 | result._disabled[language] = true;
|
3001 | result._update();
|
3002 | return result;
|
3003 | };
|
3004 |
|
3005 | TemplatablePattern.prototype.read_options = function(options) {
|
3006 | var result = this._create();
|
3007 | for (var language in template_names) {
|
3008 | result._disabled[language] = options.templating.indexOf(language) === -1;
|
3009 | }
|
3010 | result._update();
|
3011 | return result;
|
3012 | };
|
3013 |
|
3014 | TemplatablePattern.prototype.exclude = function(language) {
|
3015 | var result = this._create();
|
3016 | result._excluded[language] = true;
|
3017 | result._update();
|
3018 | return result;
|
3019 | };
|
3020 |
|
3021 | TemplatablePattern.prototype.read = function() {
|
3022 | var result = '';
|
3023 | if (this._match_pattern) {
|
3024 | result = this._input.read(this._starting_pattern);
|
3025 | } else {
|
3026 | result = this._input.read(this._starting_pattern, this.__template_pattern);
|
3027 | }
|
3028 | var next = this._read_template();
|
3029 | while (next) {
|
3030 | if (this._match_pattern) {
|
3031 | next += this._input.read(this._match_pattern);
|
3032 | } else {
|
3033 | next += this._input.readUntil(this.__template_pattern);
|
3034 | }
|
3035 | result += next;
|
3036 | next = this._read_template();
|
3037 | }
|
3038 |
|
3039 | if (this._until_after) {
|
3040 | result += this._input.readUntilAfter(this._until_pattern);
|
3041 | }
|
3042 | return result;
|
3043 | };
|
3044 |
|
3045 | TemplatablePattern.prototype.__set_templated_pattern = function() {
|
3046 | var items = [];
|
3047 |
|
3048 | if (!this._disabled.php) {
|
3049 | items.push(this.__patterns.php._starting_pattern.source);
|
3050 | }
|
3051 | if (!this._disabled.handlebars) {
|
3052 | items.push(this.__patterns.handlebars._starting_pattern.source);
|
3053 | }
|
3054 | if (!this._disabled.erb) {
|
3055 | items.push(this.__patterns.erb._starting_pattern.source);
|
3056 | }
|
3057 | if (!this._disabled.django) {
|
3058 | items.push(this.__patterns.django._starting_pattern.source);
|
3059 |
|
3060 |
|
3061 | items.push(this.__patterns.django_value._starting_pattern.source);
|
3062 | items.push(this.__patterns.django_comment._starting_pattern.source);
|
3063 | }
|
3064 | if (!this._disabled.smarty) {
|
3065 | items.push(this.__patterns.smarty._starting_pattern.source);
|
3066 | }
|
3067 |
|
3068 | if (this._until_pattern) {
|
3069 | items.push(this._until_pattern.source);
|
3070 | }
|
3071 | this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')');
|
3072 | };
|
3073 |
|
3074 | TemplatablePattern.prototype._read_template = function() {
|
3075 | var resulting_string = '';
|
3076 | var c = this._input.peek();
|
3077 | if (c === '<') {
|
3078 | var peek1 = this._input.peek(1);
|
3079 |
|
3080 |
|
3081 |
|
3082 | if (!this._disabled.php && !this._excluded.php && peek1 === '?') {
|
3083 | resulting_string = resulting_string ||
|
3084 | this.__patterns.php.read();
|
3085 | }
|
3086 | if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') {
|
3087 | resulting_string = resulting_string ||
|
3088 | this.__patterns.erb.read();
|
3089 | }
|
3090 | } else if (c === '{') {
|
3091 | if (!this._disabled.handlebars && !this._excluded.handlebars) {
|
3092 | resulting_string = resulting_string ||
|
3093 | this.__patterns.handlebars_comment.read();
|
3094 | resulting_string = resulting_string ||
|
3095 | this.__patterns.handlebars_unescaped.read();
|
3096 | resulting_string = resulting_string ||
|
3097 | this.__patterns.handlebars.read();
|
3098 | }
|
3099 | if (!this._disabled.django) {
|
3100 |
|
3101 | if (!this._excluded.django && !this._excluded.handlebars) {
|
3102 | resulting_string = resulting_string ||
|
3103 | this.__patterns.django_value.read();
|
3104 | }
|
3105 | if (!this._excluded.django) {
|
3106 | resulting_string = resulting_string ||
|
3107 | this.__patterns.django_comment.read();
|
3108 | resulting_string = resulting_string ||
|
3109 | this.__patterns.django.read();
|
3110 | }
|
3111 | }
|
3112 | if (!this._disabled.smarty) {
|
3113 |
|
3114 | if (this._disabled.django && this._disabled.handlebars) {
|
3115 | resulting_string = resulting_string ||
|
3116 | this.__patterns.smarty_comment.read();
|
3117 | resulting_string = resulting_string ||
|
3118 | this.__patterns.smarty_literal.read();
|
3119 | resulting_string = resulting_string ||
|
3120 | this.__patterns.smarty.read();
|
3121 | }
|
3122 | }
|
3123 | }
|
3124 | return resulting_string;
|
3125 | };
|
3126 |
|
3127 |
|
3128 | templatablepattern.TemplatablePattern = TemplatablePattern;
|
3129 | return templatablepattern;
|
3130 | }
|
3131 |
|
3132 |
|
3133 |
|
3134 | var hasRequiredTokenizer$1;
|
3135 |
|
3136 | function requireTokenizer$1 () {
|
3137 | if (hasRequiredTokenizer$1) return tokenizer$3;
|
3138 | hasRequiredTokenizer$1 = 1;
|
3139 |
|
3140 | var InputScanner = requireInputscanner().InputScanner;
|
3141 | var BaseTokenizer = requireTokenizer$2().Tokenizer;
|
3142 | var BASETOKEN = requireTokenizer$2().TOKEN;
|
3143 | var Directives = requireDirectives().Directives;
|
3144 | var acorn = requireAcorn();
|
3145 | var Pattern = requirePattern().Pattern;
|
3146 | var TemplatablePattern = requireTemplatablepattern().TemplatablePattern;
|
3147 |
|
3148 |
|
3149 | function in_array(what, arr) {
|
3150 | return arr.indexOf(what) !== -1;
|
3151 | }
|
3152 |
|
3153 |
|
3154 | var TOKEN = {
|
3155 | START_EXPR: 'TK_START_EXPR',
|
3156 | END_EXPR: 'TK_END_EXPR',
|
3157 | START_BLOCK: 'TK_START_BLOCK',
|
3158 | END_BLOCK: 'TK_END_BLOCK',
|
3159 | WORD: 'TK_WORD',
|
3160 | RESERVED: 'TK_RESERVED',
|
3161 | SEMICOLON: 'TK_SEMICOLON',
|
3162 | STRING: 'TK_STRING',
|
3163 | EQUALS: 'TK_EQUALS',
|
3164 | OPERATOR: 'TK_OPERATOR',
|
3165 | COMMA: 'TK_COMMA',
|
3166 | BLOCK_COMMENT: 'TK_BLOCK_COMMENT',
|
3167 | COMMENT: 'TK_COMMENT',
|
3168 | DOT: 'TK_DOT',
|
3169 | UNKNOWN: 'TK_UNKNOWN',
|
3170 | START: BASETOKEN.START,
|
3171 | RAW: BASETOKEN.RAW,
|
3172 | EOF: BASETOKEN.EOF
|
3173 | };
|
3174 |
|
3175 |
|
3176 | var directives_core = new Directives(/\/\*/, /\*\
|
3177 |
|
3178 | var number_pattern = /0[xX][0123456789abcdefABCDEF_]*n?|0[oO][01234567_]*n?|0[bB][01_]*n?|\d[\d_]*n|(?:\.\d[\d_]*|\d[\d_]*\.?[\d_]*)(?:[eE][+-]?[\d_]+)?/;
|
3179 |
|
3180 | var digit = /[0-9]/;
|
3181 |
|
3182 |
|
3183 | var dot_pattern = /[^\d\.]/;
|
3184 |
|
3185 | var positionable_operators = (
|
3186 | ">>> === !== &&= ??= ||= " +
|
3187 | "<< && >= ** != == <= >> || ?? |> " +
|
3188 | "< / - + > : & % ? ^ | *").split(' ');
|
3189 |
|
3190 |
|
3191 |
|
3192 | var punct =
|
3193 | ">>>= " +
|
3194 | "... >>= <<= === >>> !== **= &&= ??= ||= " +
|
3195 | "=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
|
3196 | "= ! ? > < : / ^ - + * & % ~ |";
|
3197 |
|
3198 | punct = punct.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
|
3199 |
|
3200 | punct = '\\?\\.(?!\\d) ' + punct;
|
3201 | punct = punct.replace(/ /g, '|');
|
3202 |
|
3203 | var punct_pattern = new RegExp(punct);
|
3204 |
|
3205 |
|
3206 | var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
|
3207 | var reserved_words = line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as', 'class', 'extends']);
|
3208 | var reserved_word_pattern = new RegExp('^(?:' + reserved_words.join('|') + ')$');
|
3209 |
|
3210 |
|
3211 |
|
3212 | var in_html_comment;
|
3213 |
|
3214 | var Tokenizer = function(input_string, options) {
|
3215 | BaseTokenizer.call(this, input_string, options);
|
3216 |
|
3217 | this._patterns.whitespace = this._patterns.whitespace.matching(
|
3218 | /\u00A0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff/.source,
|
3219 | /\u2028\u2029/.source);
|
3220 |
|
3221 | var pattern_reader = new Pattern(this._input);
|
3222 | var templatable = new TemplatablePattern(this._input)
|
3223 | .read_options(this._options);
|
3224 |
|
3225 | this.__patterns = {
|
3226 | template: templatable,
|
3227 | identifier: templatable.starting_with(acorn.identifier).matching(acorn.identifierMatch),
|
3228 | number: pattern_reader.matching(number_pattern),
|
3229 | punct: pattern_reader.matching(punct_pattern),
|
3230 |
|
3231 | comment: pattern_reader.starting_with(/\/\//).until(/[\n\r\u2028\u2029]/),
|
3232 |
|
3233 | block_comment: pattern_reader.starting_with(/\/\*/).until_after(/\*\//),
|
3234 | html_comment_start: pattern_reader.matching(/<!--/),
|
3235 | html_comment_end: pattern_reader.matching(/-->/),
|
3236 | include: pattern_reader.starting_with(/#include/).until_after(acorn.lineBreak),
|
3237 | shebang: pattern_reader.starting_with(/#!/).until_after(acorn.lineBreak),
|
3238 | xml: pattern_reader.matching(/[\s\S]*?<(\/?)([-a-zA-Z:0-9_.]+|{[^}]+?}|!\[CDATA\[[^\]]*?\]\]|)(\s*{[^}]+?}|\s+[-a-zA-Z:0-9_.]+|\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{([^{}]|{[^}]+?})+?}))*\s*(\/?)\s*>/),
|
3239 | single_quote: templatable.until(/['\\\n\r\u2028\u2029]/),
|
3240 | double_quote: templatable.until(/["\\\n\r\u2028\u2029]/),
|
3241 | template_text: templatable.until(/[`\\$]/),
|
3242 | template_expression: templatable.until(/[`}\\]/)
|
3243 | };
|
3244 |
|
3245 | };
|
3246 | Tokenizer.prototype = new BaseTokenizer();
|
3247 |
|
3248 | Tokenizer.prototype._is_comment = function(current_token) {
|
3249 | return current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.BLOCK_COMMENT || current_token.type === TOKEN.UNKNOWN;
|
3250 | };
|
3251 |
|
3252 | Tokenizer.prototype._is_opening = function(current_token) {
|
3253 | return current_token.type === TOKEN.START_BLOCK || current_token.type === TOKEN.START_EXPR;
|
3254 | };
|
3255 |
|
3256 | Tokenizer.prototype._is_closing = function(current_token, open_token) {
|
3257 | return (current_token.type === TOKEN.END_BLOCK || current_token.type === TOKEN.END_EXPR) &&
|
3258 | (open_token && (
|
3259 | (current_token.text === ']' && open_token.text === '[') ||
|
3260 | (current_token.text === ')' && open_token.text === '(') ||
|
3261 | (current_token.text === '}' && open_token.text === '{')));
|
3262 | };
|
3263 |
|
3264 | Tokenizer.prototype._reset = function() {
|
3265 | in_html_comment = false;
|
3266 | };
|
3267 |
|
3268 | Tokenizer.prototype._get_next_token = function(previous_token, open_token) {
|
3269 | var token = null;
|
3270 | this._readWhitespace();
|
3271 | var c = this._input.peek();
|
3272 |
|
3273 | if (c === null) {
|
3274 | return this._create_token(TOKEN.EOF, '');
|
3275 | }
|
3276 |
|
3277 | token = token || this._read_non_javascript(c);
|
3278 | token = token || this._read_string(c);
|
3279 | token = token || this._read_pair(c, this._input.peek(1));
|
3280 | token = token || this._read_word(previous_token);
|
3281 | token = token || this._read_singles(c);
|
3282 | token = token || this._read_comment(c);
|
3283 | token = token || this._read_regexp(c, previous_token);
|
3284 | token = token || this._read_xml(c, previous_token);
|
3285 | token = token || this._read_punctuation();
|
3286 | token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
|
3287 |
|
3288 | return token;
|
3289 | };
|
3290 |
|
3291 | Tokenizer.prototype._read_word = function(previous_token) {
|
3292 | var resulting_string;
|
3293 | resulting_string = this.__patterns.identifier.read();
|
3294 | if (resulting_string !== '') {
|
3295 | resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
|
3296 | if (!(previous_token.type === TOKEN.DOT ||
|
3297 | (previous_token.type === TOKEN.RESERVED && (previous_token.text === 'set' || previous_token.text === 'get'))) &&
|
3298 | reserved_word_pattern.test(resulting_string)) {
|
3299 | if ((resulting_string === 'in' || resulting_string === 'of') &&
|
3300 | (previous_token.type === TOKEN.WORD || previous_token.type === TOKEN.STRING)) {
|
3301 | return this._create_token(TOKEN.OPERATOR, resulting_string);
|
3302 | }
|
3303 | return this._create_token(TOKEN.RESERVED, resulting_string);
|
3304 | }
|
3305 | return this._create_token(TOKEN.WORD, resulting_string);
|
3306 | }
|
3307 |
|
3308 | resulting_string = this.__patterns.number.read();
|
3309 | if (resulting_string !== '') {
|
3310 | return this._create_token(TOKEN.WORD, resulting_string);
|
3311 | }
|
3312 | };
|
3313 |
|
3314 | Tokenizer.prototype._read_singles = function(c) {
|
3315 | var token = null;
|
3316 | if (c === '(' || c === '[') {
|
3317 | token = this._create_token(TOKEN.START_EXPR, c);
|
3318 | } else if (c === ')' || c === ']') {
|
3319 | token = this._create_token(TOKEN.END_EXPR, c);
|
3320 | } else if (c === '{') {
|
3321 | token = this._create_token(TOKEN.START_BLOCK, c);
|
3322 | } else if (c === '}') {
|
3323 | token = this._create_token(TOKEN.END_BLOCK, c);
|
3324 | } else if (c === ';') {
|
3325 | token = this._create_token(TOKEN.SEMICOLON, c);
|
3326 | } else if (c === '.' && dot_pattern.test(this._input.peek(1))) {
|
3327 | token = this._create_token(TOKEN.DOT, c);
|
3328 | } else if (c === ',') {
|
3329 | token = this._create_token(TOKEN.COMMA, c);
|
3330 | }
|
3331 |
|
3332 | if (token) {
|
3333 | this._input.next();
|
3334 | }
|
3335 | return token;
|
3336 | };
|
3337 |
|
3338 | Tokenizer.prototype._read_pair = function(c, d) {
|
3339 | var token = null;
|
3340 | if (c === '#' && d === '{') {
|
3341 | token = this._create_token(TOKEN.START_BLOCK, c + d);
|
3342 | }
|
3343 |
|
3344 | if (token) {
|
3345 | this._input.next();
|
3346 | this._input.next();
|
3347 | }
|
3348 | return token;
|
3349 | };
|
3350 |
|
3351 | Tokenizer.prototype._read_punctuation = function() {
|
3352 | var resulting_string = this.__patterns.punct.read();
|
3353 |
|
3354 | if (resulting_string !== '') {
|
3355 | if (resulting_string === '=') {
|
3356 | return this._create_token(TOKEN.EQUALS, resulting_string);
|
3357 | } else if (resulting_string === '?.') {
|
3358 | return this._create_token(TOKEN.DOT, resulting_string);
|
3359 | } else {
|
3360 | return this._create_token(TOKEN.OPERATOR, resulting_string);
|
3361 | }
|
3362 | }
|
3363 | };
|
3364 |
|
3365 | Tokenizer.prototype._read_non_javascript = function(c) {
|
3366 | var resulting_string = '';
|
3367 |
|
3368 | if (c === '#') {
|
3369 | if (this._is_first_token()) {
|
3370 | resulting_string = this.__patterns.shebang.read();
|
3371 |
|
3372 | if (resulting_string) {
|
3373 | return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
|
3374 | }
|
3375 | }
|
3376 |
|
3377 |
|
3378 | resulting_string = this.__patterns.include.read();
|
3379 |
|
3380 | if (resulting_string) {
|
3381 | return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
|
3382 | }
|
3383 |
|
3384 | c = this._input.next();
|
3385 |
|
3386 |
|
3387 | var sharp = '#';
|
3388 | if (this._input.hasNext() && this._input.testChar(digit)) {
|
3389 | do {
|
3390 | c = this._input.next();
|
3391 | sharp += c;
|
3392 | } while (this._input.hasNext() && c !== '#' && c !== '=');
|
3393 | if (c === '#') ; else if (this._input.peek() === '[' && this._input.peek(1) === ']') {
|
3394 | sharp += '[]';
|
3395 | this._input.next();
|
3396 | this._input.next();
|
3397 | } else if (this._input.peek() === '{' && this._input.peek(1) === '}') {
|
3398 | sharp += '{}';
|
3399 | this._input.next();
|
3400 | this._input.next();
|
3401 | }
|
3402 | return this._create_token(TOKEN.WORD, sharp);
|
3403 | }
|
3404 |
|
3405 | this._input.back();
|
3406 |
|
3407 | } else if (c === '<' && this._is_first_token()) {
|
3408 | resulting_string = this.__patterns.html_comment_start.read();
|
3409 | if (resulting_string) {
|
3410 | while (this._input.hasNext() && !this._input.testChar(acorn.newline)) {
|
3411 | resulting_string += this._input.next();
|
3412 | }
|
3413 | in_html_comment = true;
|
3414 | return this._create_token(TOKEN.COMMENT, resulting_string);
|
3415 | }
|
3416 | } else if (in_html_comment && c === '-') {
|
3417 | resulting_string = this.__patterns.html_comment_end.read();
|
3418 | if (resulting_string) {
|
3419 | in_html_comment = false;
|
3420 | return this._create_token(TOKEN.COMMENT, resulting_string);
|
3421 | }
|
3422 | }
|
3423 |
|
3424 | return null;
|
3425 | };
|
3426 |
|
3427 | Tokenizer.prototype._read_comment = function(c) {
|
3428 | var token = null;
|
3429 | if (c === '/') {
|
3430 | var comment = '';
|
3431 | if (this._input.peek(1) === '*') {
|
3432 |
|
3433 | comment = this.__patterns.block_comment.read();
|
3434 | var directives = directives_core.get_directives(comment);
|
3435 | if (directives && directives.ignore === 'start') {
|
3436 | comment += directives_core.readIgnored(this._input);
|
3437 | }
|
3438 | comment = comment.replace(acorn.allLineBreaks, '\n');
|
3439 | token = this._create_token(TOKEN.BLOCK_COMMENT, comment);
|
3440 | token.directives = directives;
|
3441 | } else if (this._input.peek(1) === '/') {
|
3442 |
|
3443 | comment = this.__patterns.comment.read();
|
3444 | token = this._create_token(TOKEN.COMMENT, comment);
|
3445 | }
|
3446 | }
|
3447 | return token;
|
3448 | };
|
3449 |
|
3450 | Tokenizer.prototype._read_string = function(c) {
|
3451 | if (c === '`' || c === "'" || c === '"') {
|
3452 | var resulting_string = this._input.next();
|
3453 | this.has_char_escapes = false;
|
3454 |
|
3455 | if (c === '`') {
|
3456 | resulting_string += this._read_string_recursive('`', true, '${');
|
3457 | } else {
|
3458 | resulting_string += this._read_string_recursive(c);
|
3459 | }
|
3460 |
|
3461 | if (this.has_char_escapes && this._options.unescape_strings) {
|
3462 | resulting_string = unescape_string(resulting_string);
|
3463 | }
|
3464 |
|
3465 | if (this._input.peek() === c) {
|
3466 | resulting_string += this._input.next();
|
3467 | }
|
3468 |
|
3469 | resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
|
3470 |
|
3471 | return this._create_token(TOKEN.STRING, resulting_string);
|
3472 | }
|
3473 |
|
3474 | return null;
|
3475 | };
|
3476 |
|
3477 | Tokenizer.prototype._allow_regexp_or_xml = function(previous_token) {
|
3478 |
|
3479 | return (previous_token.type === TOKEN.RESERVED && in_array(previous_token.text, ['return', 'case', 'throw', 'else', 'do', 'typeof', 'yield'])) ||
|
3480 | (previous_token.type === TOKEN.END_EXPR && previous_token.text === ')' &&
|
3481 | previous_token.opened.previous.type === TOKEN.RESERVED && in_array(previous_token.opened.previous.text, ['if', 'while', 'for'])) ||
|
3482 | (in_array(previous_token.type, [TOKEN.COMMENT, TOKEN.START_EXPR, TOKEN.START_BLOCK, TOKEN.START,
|
3483 | TOKEN.END_BLOCK, TOKEN.OPERATOR, TOKEN.EQUALS, TOKEN.EOF, TOKEN.SEMICOLON, TOKEN.COMMA
|
3484 | ]));
|
3485 | };
|
3486 |
|
3487 | Tokenizer.prototype._read_regexp = function(c, previous_token) {
|
3488 |
|
3489 | if (c === '/' && this._allow_regexp_or_xml(previous_token)) {
|
3490 |
|
3491 |
|
3492 | var resulting_string = this._input.next();
|
3493 | var esc = false;
|
3494 |
|
3495 | var in_char_class = false;
|
3496 | while (this._input.hasNext() &&
|
3497 | ((esc || in_char_class || this._input.peek() !== c) &&
|
3498 | !this._input.testChar(acorn.newline))) {
|
3499 | resulting_string += this._input.peek();
|
3500 | if (!esc) {
|
3501 | esc = this._input.peek() === '\\';
|
3502 | if (this._input.peek() === '[') {
|
3503 | in_char_class = true;
|
3504 | } else if (this._input.peek() === ']') {
|
3505 | in_char_class = false;
|
3506 | }
|
3507 | } else {
|
3508 | esc = false;
|
3509 | }
|
3510 | this._input.next();
|
3511 | }
|
3512 |
|
3513 | if (this._input.peek() === c) {
|
3514 | resulting_string += this._input.next();
|
3515 |
|
3516 |
|
3517 |
|
3518 | resulting_string += this._input.read(acorn.identifier);
|
3519 | }
|
3520 | return this._create_token(TOKEN.STRING, resulting_string);
|
3521 | }
|
3522 | return null;
|
3523 | };
|
3524 |
|
3525 | Tokenizer.prototype._read_xml = function(c, previous_token) {
|
3526 |
|
3527 | if (this._options.e4x && c === "<" && this._allow_regexp_or_xml(previous_token)) {
|
3528 | var xmlStr = '';
|
3529 | var match = this.__patterns.xml.read_match();
|
3530 |
|
3531 |
|
3532 | if (match) {
|
3533 |
|
3534 | var rootTag = match[2].replace(/^{\s+/, '{').replace(/\s+}$/, '}');
|
3535 | var isCurlyRoot = rootTag.indexOf('{') === 0;
|
3536 | var depth = 0;
|
3537 | while (match) {
|
3538 | var isEndTag = !!match[1];
|
3539 | var tagName = match[2];
|
3540 | var isSingletonTag = (!!match[match.length - 1]) || (tagName.slice(0, 8) === "![CDATA[");
|
3541 | if (!isSingletonTag &&
|
3542 | (tagName === rootTag || (isCurlyRoot && tagName.replace(/^{\s+/, '{').replace(/\s+}$/, '}')))) {
|
3543 | if (isEndTag) {
|
3544 | --depth;
|
3545 | } else {
|
3546 | ++depth;
|
3547 | }
|
3548 | }
|
3549 | xmlStr += match[0];
|
3550 | if (depth <= 0) {
|
3551 | break;
|
3552 | }
|
3553 | match = this.__patterns.xml.read_match();
|
3554 | }
|
3555 |
|
3556 | if (!match) {
|
3557 | xmlStr += this._input.match(/[\s\S]*/g)[0];
|
3558 | }
|
3559 | xmlStr = xmlStr.replace(acorn.allLineBreaks, '\n');
|
3560 | return this._create_token(TOKEN.STRING, xmlStr);
|
3561 | }
|
3562 | }
|
3563 |
|
3564 | return null;
|
3565 | };
|
3566 |
|
3567 | function unescape_string(s) {
|
3568 |
|
3569 |
|
3570 |
|
3571 |
|
3572 |
|
3573 | var out = '',
|
3574 | escaped = 0;
|
3575 |
|
3576 | var input_scan = new InputScanner(s);
|
3577 | var matched = null;
|
3578 |
|
3579 | while (input_scan.hasNext()) {
|
3580 |
|
3581 |
|
3582 | matched = input_scan.match(/([\s]|[^\\]|\\\\)+/g);
|
3583 |
|
3584 | if (matched) {
|
3585 | out += matched[0];
|
3586 | }
|
3587 |
|
3588 | if (input_scan.peek() === '\\') {
|
3589 | input_scan.next();
|
3590 | if (input_scan.peek() === 'x') {
|
3591 | matched = input_scan.match(/x([0-9A-Fa-f]{2})/g);
|
3592 | } else if (input_scan.peek() === 'u') {
|
3593 | matched = input_scan.match(/u([0-9A-Fa-f]{4})/g);
|
3594 | } else {
|
3595 | out += '\\';
|
3596 | if (input_scan.hasNext()) {
|
3597 | out += input_scan.next();
|
3598 | }
|
3599 | continue;
|
3600 | }
|
3601 |
|
3602 |
|
3603 | if (!matched) {
|
3604 | return s;
|
3605 | }
|
3606 |
|
3607 | escaped = parseInt(matched[1], 16);
|
3608 |
|
3609 | if (escaped > 0x7e && escaped <= 0xff && matched[0].indexOf('x') === 0) {
|
3610 |
|
3611 |
|
3612 |
|
3613 | return s;
|
3614 | } else if (escaped >= 0x00 && escaped < 0x20) {
|
3615 |
|
3616 | out += '\\' + matched[0];
|
3617 | continue;
|
3618 | } else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
|
3619 |
|
3620 | out += '\\' + String.fromCharCode(escaped);
|
3621 | } else {
|
3622 | out += String.fromCharCode(escaped);
|
3623 | }
|
3624 | }
|
3625 | }
|
3626 |
|
3627 | return out;
|
3628 | }
|
3629 |
|
3630 |
|
3631 |
|
3632 | Tokenizer.prototype._read_string_recursive = function(delimiter, allow_unescaped_newlines, start_sub) {
|
3633 | var current_char;
|
3634 | var pattern;
|
3635 | if (delimiter === '\'') {
|
3636 | pattern = this.__patterns.single_quote;
|
3637 | } else if (delimiter === '"') {
|
3638 | pattern = this.__patterns.double_quote;
|
3639 | } else if (delimiter === '`') {
|
3640 | pattern = this.__patterns.template_text;
|
3641 | } else if (delimiter === '}') {
|
3642 | pattern = this.__patterns.template_expression;
|
3643 | }
|
3644 |
|
3645 | var resulting_string = pattern.read();
|
3646 | var next = '';
|
3647 | while (this._input.hasNext()) {
|
3648 | next = this._input.next();
|
3649 | if (next === delimiter ||
|
3650 | (!allow_unescaped_newlines && acorn.newline.test(next))) {
|
3651 | this._input.back();
|
3652 | break;
|
3653 | } else if (next === '\\' && this._input.hasNext()) {
|
3654 | current_char = this._input.peek();
|
3655 |
|
3656 | if (current_char === 'x' || current_char === 'u') {
|
3657 | this.has_char_escapes = true;
|
3658 | } else if (current_char === '\r' && this._input.peek(1) === '\n') {
|
3659 | this._input.next();
|
3660 | }
|
3661 | next += this._input.next();
|
3662 | } else if (start_sub) {
|
3663 | if (start_sub === '${' && next === '$' && this._input.peek() === '{') {
|
3664 | next += this._input.next();
|
3665 | }
|
3666 |
|
3667 | if (start_sub === next) {
|
3668 | if (delimiter === '`') {
|
3669 | next += this._read_string_recursive('}', allow_unescaped_newlines, '`');
|
3670 | } else {
|
3671 | next += this._read_string_recursive('`', allow_unescaped_newlines, '${');
|
3672 | }
|
3673 | if (this._input.hasNext()) {
|
3674 | next += this._input.next();
|
3675 | }
|
3676 | }
|
3677 | }
|
3678 | next += pattern.read();
|
3679 | resulting_string += next;
|
3680 | }
|
3681 |
|
3682 | return resulting_string;
|
3683 | };
|
3684 |
|
3685 | tokenizer$3.Tokenizer = Tokenizer;
|
3686 | tokenizer$3.TOKEN = TOKEN;
|
3687 | tokenizer$3.positionable_operators = positionable_operators.slice();
|
3688 | tokenizer$3.line_starters = line_starters.slice();
|
3689 | return tokenizer$3;
|
3690 | }
|
3691 |
|
3692 |
|
3693 |
|
3694 | var hasRequiredBeautifier$2;
|
3695 |
|
3696 | function requireBeautifier$2 () {
|
3697 | if (hasRequiredBeautifier$2) return beautifier$2;
|
3698 | hasRequiredBeautifier$2 = 1;
|
3699 |
|
3700 | var Output = requireOutput().Output;
|
3701 | var Token = requireToken().Token;
|
3702 | var acorn = requireAcorn();
|
3703 | var Options = requireOptions$2().Options;
|
3704 | var Tokenizer = requireTokenizer$1().Tokenizer;
|
3705 | var line_starters = requireTokenizer$1().line_starters;
|
3706 | var positionable_operators = requireTokenizer$1().positionable_operators;
|
3707 | var TOKEN = requireTokenizer$1().TOKEN;
|
3708 |
|
3709 |
|
3710 | function in_array(what, arr) {
|
3711 | return arr.indexOf(what) !== -1;
|
3712 | }
|
3713 |
|
3714 | function ltrim(s) {
|
3715 | return s.replace(/^\s+/g, '');
|
3716 | }
|
3717 |
|
3718 | function generateMapFromStrings(list) {
|
3719 | var result = {};
|
3720 | for (var x = 0; x < list.length; x++) {
|
3721 |
|
3722 | result[list[x].replace(/-/g, '_')] = list[x];
|
3723 | }
|
3724 | return result;
|
3725 | }
|
3726 |
|
3727 | function reserved_word(token, word) {
|
3728 | return token && token.type === TOKEN.RESERVED && token.text === word;
|
3729 | }
|
3730 |
|
3731 | function reserved_array(token, words) {
|
3732 | return token && token.type === TOKEN.RESERVED && in_array(token.text, words);
|
3733 | }
|
3734 |
|
3735 | var special_words = ['case', 'return', 'do', 'if', 'throw', 'else', 'await', 'break', 'continue', 'async'];
|
3736 |
|
3737 | var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
|
3738 |
|
3739 |
|
3740 | var OPERATOR_POSITION = generateMapFromStrings(validPositionValues);
|
3741 |
|
3742 | var OPERATOR_POSITION_BEFORE_OR_PRESERVE = [OPERATOR_POSITION.before_newline, OPERATOR_POSITION.preserve_newline];
|
3743 |
|
3744 | var MODE = {
|
3745 | BlockStatement: 'BlockStatement',
|
3746 | Statement: 'Statement',
|
3747 | ObjectLiteral: 'ObjectLiteral',
|
3748 | ArrayLiteral: 'ArrayLiteral',
|
3749 | ForInitializer: 'ForInitializer',
|
3750 | Conditional: 'Conditional',
|
3751 | Expression: 'Expression'
|
3752 | };
|
3753 |
|
3754 | function remove_redundant_indentation(output, frame) {
|
3755 |
|
3756 |
|
3757 |
|
3758 |
|
3759 |
|
3760 | if (frame.multiline_frame ||
|
3761 | frame.mode === MODE.ForInitializer ||
|
3762 | frame.mode === MODE.Conditional) {
|
3763 | return;
|
3764 | }
|
3765 |
|
3766 |
|
3767 | output.remove_indent(frame.start_line_index);
|
3768 | }
|
3769 |
|
3770 |
|
3771 |
|
3772 | function split_linebreaks(s) {
|
3773 |
|
3774 |
|
3775 | s = s.replace(acorn.allLineBreaks, '\n');
|
3776 | var out = [],
|
3777 | idx = s.indexOf("\n");
|
3778 | while (idx !== -1) {
|
3779 | out.push(s.substring(0, idx));
|
3780 | s = s.substring(idx + 1);
|
3781 | idx = s.indexOf("\n");
|
3782 | }
|
3783 | if (s.length) {
|
3784 | out.push(s);
|
3785 | }
|
3786 | return out;
|
3787 | }
|
3788 |
|
3789 | function is_array(mode) {
|
3790 | return mode === MODE.ArrayLiteral;
|
3791 | }
|
3792 |
|
3793 | function is_expression(mode) {
|
3794 | return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
|
3795 | }
|
3796 |
|
3797 | function all_lines_start_with(lines, c) {
|
3798 | for (var i = 0; i < lines.length; i++) {
|
3799 | var line = lines[i].trim();
|
3800 | if (line.charAt(0) !== c) {
|
3801 | return false;
|
3802 | }
|
3803 | }
|
3804 | return true;
|
3805 | }
|
3806 |
|
3807 | function each_line_matches_indent(lines, indent) {
|
3808 | var i = 0,
|
3809 | len = lines.length,
|
3810 | line;
|
3811 | for (; i < len; i++) {
|
3812 | line = lines[i];
|
3813 |
|
3814 | if (line && line.indexOf(indent) !== 0) {
|
3815 | return false;
|
3816 | }
|
3817 | }
|
3818 | return true;
|
3819 | }
|
3820 |
|
3821 |
|
3822 | function Beautifier(source_text, options) {
|
3823 | options = options || {};
|
3824 | this._source_text = source_text || '';
|
3825 |
|
3826 | this._output = null;
|
3827 | this._tokens = null;
|
3828 | this._last_last_text = null;
|
3829 | this._flags = null;
|
3830 | this._previous_flags = null;
|
3831 |
|
3832 | this._flag_store = null;
|
3833 | this._options = new Options(options);
|
3834 | }
|
3835 |
|
3836 | Beautifier.prototype.create_flags = function(flags_base, mode) {
|
3837 | var next_indent_level = 0;
|
3838 | if (flags_base) {
|
3839 | next_indent_level = flags_base.indentation_level;
|
3840 | if (!this._output.just_added_newline() &&
|
3841 | flags_base.line_indent_level > next_indent_level) {
|
3842 | next_indent_level = flags_base.line_indent_level;
|
3843 | }
|
3844 | }
|
3845 |
|
3846 | var next_flags = {
|
3847 | mode: mode,
|
3848 | parent: flags_base,
|
3849 | last_token: flags_base ? flags_base.last_token : new Token(TOKEN.START_BLOCK, ''),
|
3850 | last_word: flags_base ? flags_base.last_word : '',
|
3851 | declaration_statement: false,
|
3852 | declaration_assignment: false,
|
3853 | multiline_frame: false,
|
3854 | inline_frame: false,
|
3855 | if_block: false,
|
3856 | else_block: false,
|
3857 | class_start_block: false,
|
3858 | do_block: false,
|
3859 | do_while: false,
|
3860 | import_block: false,
|
3861 | in_case_statement: false,
|
3862 | in_case: false,
|
3863 | case_body: false,
|
3864 | case_block: false,
|
3865 | indentation_level: next_indent_level,
|
3866 | alignment: 0,
|
3867 | line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
|
3868 | start_line_index: this._output.get_line_number(),
|
3869 | ternary_depth: 0
|
3870 | };
|
3871 | return next_flags;
|
3872 | };
|
3873 |
|
3874 | Beautifier.prototype._reset = function(source_text) {
|
3875 | var baseIndentString = source_text.match(/^[\t ]*/)[0];
|
3876 |
|
3877 | this._last_last_text = '';
|
3878 | this._output = new Output(this._options, baseIndentString);
|
3879 |
|
3880 |
|
3881 | this._output.raw = this._options.test_output_raw;
|
3882 |
|
3883 |
|
3884 |
|
3885 |
|
3886 |
|
3887 |
|
3888 |
|
3889 |
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 | this._flag_store = [];
|
3895 | this.set_mode(MODE.BlockStatement);
|
3896 | var tokenizer = new Tokenizer(source_text, this._options);
|
3897 | this._tokens = tokenizer.tokenize();
|
3898 | return source_text;
|
3899 | };
|
3900 |
|
3901 | Beautifier.prototype.beautify = function() {
|
3902 |
|
3903 | if (this._options.disabled) {
|
3904 | return this._source_text;
|
3905 | }
|
3906 |
|
3907 | var sweet_code;
|
3908 | var source_text = this._reset(this._source_text);
|
3909 |
|
3910 | var eol = this._options.eol;
|
3911 | if (this._options.eol === 'auto') {
|
3912 | eol = '\n';
|
3913 | if (source_text && acorn.lineBreak.test(source_text || '')) {
|
3914 | eol = source_text.match(acorn.lineBreak)[0];
|
3915 | }
|
3916 | }
|
3917 |
|
3918 | var current_token = this._tokens.next();
|
3919 | while (current_token) {
|
3920 | this.handle_token(current_token);
|
3921 |
|
3922 | this._last_last_text = this._flags.last_token.text;
|
3923 | this._flags.last_token = current_token;
|
3924 |
|
3925 | current_token = this._tokens.next();
|
3926 | }
|
3927 |
|
3928 | sweet_code = this._output.get_code(eol);
|
3929 |
|
3930 | return sweet_code;
|
3931 | };
|
3932 |
|
3933 | Beautifier.prototype.handle_token = function(current_token, preserve_statement_flags) {
|
3934 | if (current_token.type === TOKEN.START_EXPR) {
|
3935 | this.handle_start_expr(current_token);
|
3936 | } else if (current_token.type === TOKEN.END_EXPR) {
|
3937 | this.handle_end_expr(current_token);
|
3938 | } else if (current_token.type === TOKEN.START_BLOCK) {
|
3939 | this.handle_start_block(current_token);
|
3940 | } else if (current_token.type === TOKEN.END_BLOCK) {
|
3941 | this.handle_end_block(current_token);
|
3942 | } else if (current_token.type === TOKEN.WORD) {
|
3943 | this.handle_word(current_token);
|
3944 | } else if (current_token.type === TOKEN.RESERVED) {
|
3945 | this.handle_word(current_token);
|
3946 | } else if (current_token.type === TOKEN.SEMICOLON) {
|
3947 | this.handle_semicolon(current_token);
|
3948 | } else if (current_token.type === TOKEN.STRING) {
|
3949 | this.handle_string(current_token);
|
3950 | } else if (current_token.type === TOKEN.EQUALS) {
|
3951 | this.handle_equals(current_token);
|
3952 | } else if (current_token.type === TOKEN.OPERATOR) {
|
3953 | this.handle_operator(current_token);
|
3954 | } else if (current_token.type === TOKEN.COMMA) {
|
3955 | this.handle_comma(current_token);
|
3956 | } else if (current_token.type === TOKEN.BLOCK_COMMENT) {
|
3957 | this.handle_block_comment(current_token, preserve_statement_flags);
|
3958 | } else if (current_token.type === TOKEN.COMMENT) {
|
3959 | this.handle_comment(current_token, preserve_statement_flags);
|
3960 | } else if (current_token.type === TOKEN.DOT) {
|
3961 | this.handle_dot(current_token);
|
3962 | } else if (current_token.type === TOKEN.EOF) {
|
3963 | this.handle_eof(current_token);
|
3964 | } else if (current_token.type === TOKEN.UNKNOWN) {
|
3965 | this.handle_unknown(current_token, preserve_statement_flags);
|
3966 | } else {
|
3967 | this.handle_unknown(current_token, preserve_statement_flags);
|
3968 | }
|
3969 | };
|
3970 |
|
3971 | Beautifier.prototype.handle_whitespace_and_comments = function(current_token, preserve_statement_flags) {
|
3972 | var newlines = current_token.newlines;
|
3973 | var keep_whitespace = this._options.keep_array_indentation && is_array(this._flags.mode);
|
3974 |
|
3975 | if (current_token.comments_before) {
|
3976 | var comment_token = current_token.comments_before.next();
|
3977 | while (comment_token) {
|
3978 |
|
3979 |
|
3980 |
|
3981 | this.handle_whitespace_and_comments(comment_token, preserve_statement_flags);
|
3982 | this.handle_token(comment_token, preserve_statement_flags);
|
3983 | comment_token = current_token.comments_before.next();
|
3984 | }
|
3985 | }
|
3986 |
|
3987 | if (keep_whitespace) {
|
3988 | for (var i = 0; i < newlines; i += 1) {
|
3989 | this.print_newline(i > 0, preserve_statement_flags);
|
3990 | }
|
3991 | } else {
|
3992 | if (this._options.max_preserve_newlines && newlines > this._options.max_preserve_newlines) {
|
3993 | newlines = this._options.max_preserve_newlines;
|
3994 | }
|
3995 |
|
3996 | if (this._options.preserve_newlines) {
|
3997 | if (newlines > 1) {
|
3998 | this.print_newline(false, preserve_statement_flags);
|
3999 | for (var j = 1; j < newlines; j += 1) {
|
4000 | this.print_newline(true, preserve_statement_flags);
|
4001 | }
|
4002 | }
|
4003 | }
|
4004 | }
|
4005 |
|
4006 | };
|
4007 |
|
4008 | var newline_restricted_tokens = ['async', 'break', 'continue', 'return', 'throw', 'yield'];
|
4009 |
|
4010 | Beautifier.prototype.allow_wrap_or_preserved_newline = function(current_token, force_linewrap) {
|
4011 | force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
|
4012 |
|
4013 |
|
4014 | if (this._output.just_added_newline()) {
|
4015 | return;
|
4016 | }
|
4017 |
|
4018 | var shouldPreserveOrForce = (this._options.preserve_newlines && current_token.newlines) || force_linewrap;
|
4019 | var operatorLogicApplies = in_array(this._flags.last_token.text, positionable_operators) ||
|
4020 | in_array(current_token.text, positionable_operators);
|
4021 |
|
4022 | if (operatorLogicApplies) {
|
4023 | var shouldPrintOperatorNewline = (
|
4024 | in_array(this._flags.last_token.text, positionable_operators) &&
|
4025 | in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)
|
4026 | ) ||
|
4027 | in_array(current_token.text, positionable_operators);
|
4028 | shouldPreserveOrForce = shouldPreserveOrForce && shouldPrintOperatorNewline;
|
4029 | }
|
4030 |
|
4031 | if (shouldPreserveOrForce) {
|
4032 | this.print_newline(false, true);
|
4033 | } else if (this._options.wrap_line_length) {
|
4034 | if (reserved_array(this._flags.last_token, newline_restricted_tokens)) {
|
4035 |
|
4036 |
|
4037 | return;
|
4038 | }
|
4039 | this._output.set_wrap_point();
|
4040 | }
|
4041 | };
|
4042 |
|
4043 | Beautifier.prototype.print_newline = function(force_newline, preserve_statement_flags) {
|
4044 | if (!preserve_statement_flags) {
|
4045 | if (this._flags.last_token.text !== ';' && this._flags.last_token.text !== ',' && this._flags.last_token.text !== '=' && (this._flags.last_token.type !== TOKEN.OPERATOR || this._flags.last_token.text === '--' || this._flags.last_token.text === '++')) {
|
4046 | var next_token = this._tokens.peek();
|
4047 | while (this._flags.mode === MODE.Statement &&
|
4048 | !(this._flags.if_block && reserved_word(next_token, 'else')) &&
|
4049 | !this._flags.do_block) {
|
4050 | this.restore_mode();
|
4051 | }
|
4052 | }
|
4053 | }
|
4054 |
|
4055 | if (this._output.add_new_line(force_newline)) {
|
4056 | this._flags.multiline_frame = true;
|
4057 | }
|
4058 | };
|
4059 |
|
4060 | Beautifier.prototype.print_token_line_indentation = function(current_token) {
|
4061 | if (this._output.just_added_newline()) {
|
4062 | if (this._options.keep_array_indentation &&
|
4063 | current_token.newlines &&
|
4064 | (current_token.text === '[' || is_array(this._flags.mode))) {
|
4065 | this._output.current_line.set_indent(-1);
|
4066 | this._output.current_line.push(current_token.whitespace_before);
|
4067 | this._output.space_before_token = false;
|
4068 | } else if (this._output.set_indent(this._flags.indentation_level, this._flags.alignment)) {
|
4069 | this._flags.line_indent_level = this._flags.indentation_level;
|
4070 | }
|
4071 | }
|
4072 | };
|
4073 |
|
4074 | Beautifier.prototype.print_token = function(current_token) {
|
4075 | if (this._output.raw) {
|
4076 | this._output.add_raw_token(current_token);
|
4077 | return;
|
4078 | }
|
4079 |
|
4080 | if (this._options.comma_first && current_token.previous && current_token.previous.type === TOKEN.COMMA &&
|
4081 | this._output.just_added_newline()) {
|
4082 | if (this._output.previous_line.last() === ',') {
|
4083 | var popped = this._output.previous_line.pop();
|
4084 |
|
4085 |
|
4086 | if (this._output.previous_line.is_empty()) {
|
4087 | this._output.previous_line.push(popped);
|
4088 | this._output.trim(true);
|
4089 | this._output.current_line.pop();
|
4090 | this._output.trim();
|
4091 | }
|
4092 |
|
4093 |
|
4094 | this.print_token_line_indentation(current_token);
|
4095 | this._output.add_token(',');
|
4096 | this._output.space_before_token = true;
|
4097 | }
|
4098 | }
|
4099 |
|
4100 | this.print_token_line_indentation(current_token);
|
4101 | this._output.non_breaking_space = true;
|
4102 | this._output.add_token(current_token.text);
|
4103 | if (this._output.previous_token_wrapped) {
|
4104 | this._flags.multiline_frame = true;
|
4105 | }
|
4106 | };
|
4107 |
|
4108 | Beautifier.prototype.indent = function() {
|
4109 | this._flags.indentation_level += 1;
|
4110 | this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
|
4111 | };
|
4112 |
|
4113 | Beautifier.prototype.deindent = function() {
|
4114 | if (this._flags.indentation_level > 0 &&
|
4115 | ((!this._flags.parent) || this._flags.indentation_level > this._flags.parent.indentation_level)) {
|
4116 | this._flags.indentation_level -= 1;
|
4117 | this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
|
4118 | }
|
4119 | };
|
4120 |
|
4121 | Beautifier.prototype.set_mode = function(mode) {
|
4122 | if (this._flags) {
|
4123 | this._flag_store.push(this._flags);
|
4124 | this._previous_flags = this._flags;
|
4125 | } else {
|
4126 | this._previous_flags = this.create_flags(null, mode);
|
4127 | }
|
4128 |
|
4129 | this._flags = this.create_flags(this._previous_flags, mode);
|
4130 | this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
|
4131 | };
|
4132 |
|
4133 |
|
4134 | Beautifier.prototype.restore_mode = function() {
|
4135 | if (this._flag_store.length > 0) {
|
4136 | this._previous_flags = this._flags;
|
4137 | this._flags = this._flag_store.pop();
|
4138 | if (this._previous_flags.mode === MODE.Statement) {
|
4139 | remove_redundant_indentation(this._output, this._previous_flags);
|
4140 | }
|
4141 | this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
|
4142 | }
|
4143 | };
|
4144 |
|
4145 | Beautifier.prototype.start_of_object_property = function() {
|
4146 | return this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement && (
|
4147 | (this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || (reserved_array(this._flags.last_token, ['get', 'set'])));
|
4148 | };
|
4149 |
|
4150 | Beautifier.prototype.start_of_statement = function(current_token) {
|
4151 | var start = false;
|
4152 | start = start || reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD;
|
4153 | start = start || reserved_word(this._flags.last_token, 'do');
|
4154 | start = start || (!(this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement)) && reserved_array(this._flags.last_token, newline_restricted_tokens) && !current_token.newlines;
|
4155 | start = start || reserved_word(this._flags.last_token, 'else') &&
|
4156 | !(reserved_word(current_token, 'if') && !current_token.comments_before);
|
4157 | start = start || (this._flags.last_token.type === TOKEN.END_EXPR && (this._previous_flags.mode === MODE.ForInitializer || this._previous_flags.mode === MODE.Conditional));
|
4158 | start = start || (this._flags.last_token.type === TOKEN.WORD && this._flags.mode === MODE.BlockStatement &&
|
4159 | !this._flags.in_case &&
|
4160 | !(current_token.text === '--' || current_token.text === '++') &&
|
4161 | this._last_last_text !== 'function' &&
|
4162 | current_token.type !== TOKEN.WORD && current_token.type !== TOKEN.RESERVED);
|
4163 | start = start || (this._flags.mode === MODE.ObjectLiteral && (
|
4164 | (this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || reserved_array(this._flags.last_token, ['get', 'set'])));
|
4165 |
|
4166 | if (start) {
|
4167 | this.set_mode(MODE.Statement);
|
4168 | this.indent();
|
4169 |
|
4170 | this.handle_whitespace_and_comments(current_token, true);
|
4171 |
|
4172 |
|
4173 |
|
4174 |
|
4175 | if (!this.start_of_object_property()) {
|
4176 | this.allow_wrap_or_preserved_newline(current_token,
|
4177 | reserved_array(current_token, ['do', 'for', 'if', 'while']));
|
4178 | }
|
4179 | return true;
|
4180 | }
|
4181 | return false;
|
4182 | };
|
4183 |
|
4184 | Beautifier.prototype.handle_start_expr = function(current_token) {
|
4185 |
|
4186 | if (!this.start_of_statement(current_token)) {
|
4187 | this.handle_whitespace_and_comments(current_token);
|
4188 | }
|
4189 |
|
4190 | var next_mode = MODE.Expression;
|
4191 | if (current_token.text === '[') {
|
4192 |
|
4193 | if (this._flags.last_token.type === TOKEN.WORD || this._flags.last_token.text === ')') {
|
4194 |
|
4195 |
|
4196 | if (reserved_array(this._flags.last_token, line_starters)) {
|
4197 | this._output.space_before_token = true;
|
4198 | }
|
4199 | this.print_token(current_token);
|
4200 | this.set_mode(next_mode);
|
4201 | this.indent();
|
4202 | if (this._options.space_in_paren) {
|
4203 | this._output.space_before_token = true;
|
4204 | }
|
4205 | return;
|
4206 | }
|
4207 |
|
4208 | next_mode = MODE.ArrayLiteral;
|
4209 | if (is_array(this._flags.mode)) {
|
4210 | if (this._flags.last_token.text === '[' ||
|
4211 | (this._flags.last_token.text === ',' && (this._last_last_text === ']' || this._last_last_text === '}'))) {
|
4212 |
|
4213 |
|
4214 | if (!this._options.keep_array_indentation) {
|
4215 | this.print_newline();
|
4216 | }
|
4217 | }
|
4218 | }
|
4219 |
|
4220 | if (!in_array(this._flags.last_token.type, [TOKEN.START_EXPR, TOKEN.END_EXPR, TOKEN.WORD, TOKEN.OPERATOR, TOKEN.DOT])) {
|
4221 | this._output.space_before_token = true;
|
4222 | }
|
4223 | } else {
|
4224 | if (this._flags.last_token.type === TOKEN.RESERVED) {
|
4225 | if (this._flags.last_token.text === 'for') {
|
4226 | this._output.space_before_token = this._options.space_before_conditional;
|
4227 | next_mode = MODE.ForInitializer;
|
4228 | } else if (in_array(this._flags.last_token.text, ['if', 'while', 'switch'])) {
|
4229 | this._output.space_before_token = this._options.space_before_conditional;
|
4230 | next_mode = MODE.Conditional;
|
4231 | } else if (in_array(this._flags.last_word, ['await', 'async'])) {
|
4232 |
|
4233 | this._output.space_before_token = true;
|
4234 | } else if (this._flags.last_token.text === 'import' && current_token.whitespace_before === '') {
|
4235 | this._output.space_before_token = false;
|
4236 | } else if (in_array(this._flags.last_token.text, line_starters) || this._flags.last_token.text === 'catch') {
|
4237 | this._output.space_before_token = true;
|
4238 | }
|
4239 | } else if (this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
|
4240 |
|
4241 |
|
4242 |
|
4243 | if (!this.start_of_object_property()) {
|
4244 | this.allow_wrap_or_preserved_newline(current_token);
|
4245 | }
|
4246 | } else if (this._flags.last_token.type === TOKEN.WORD) {
|
4247 | this._output.space_before_token = false;
|
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 |
|
4255 |
|
4256 |
|
4257 |
|
4258 | var peek_back_two = this._tokens.peek(-3);
|
4259 | if (this._options.space_after_named_function && peek_back_two) {
|
4260 |
|
4261 | var peek_back_three = this._tokens.peek(-4);
|
4262 | if (reserved_array(peek_back_two, ['async', 'function']) ||
|
4263 | (peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) {
|
4264 | this._output.space_before_token = true;
|
4265 | } else if (this._flags.mode === MODE.ObjectLiteral) {
|
4266 | if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
|
4267 | (peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
|
4268 | this._output.space_before_token = true;
|
4269 | }
|
4270 | } else if (this._flags.parent && this._flags.parent.class_start_block) {
|
4271 | this._output.space_before_token = true;
|
4272 | }
|
4273 | }
|
4274 | } else {
|
4275 |
|
4276 |
|
4277 |
|
4278 |
|
4279 | this.allow_wrap_or_preserved_newline(current_token);
|
4280 | }
|
4281 |
|
4282 |
|
4283 |
|
4284 |
|
4285 | if ((this._flags.last_token.type === TOKEN.RESERVED && (this._flags.last_word === 'function' || this._flags.last_word === 'typeof')) ||
|
4286 | (this._flags.last_token.text === '*' &&
|
4287 | (in_array(this._last_last_text, ['function', 'yield']) ||
|
4288 | (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
|
4289 | this._output.space_before_token = this._options.space_after_anon_function;
|
4290 | }
|
4291 | }
|
4292 |
|
4293 | if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) {
|
4294 | this.print_newline();
|
4295 | } else if (this._flags.last_token.type === TOKEN.END_EXPR || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.END_BLOCK || this._flags.last_token.text === '.' || this._flags.last_token.type === TOKEN.COMMA) {
|
4296 |
|
4297 |
|
4298 | this.allow_wrap_or_preserved_newline(current_token, current_token.newlines);
|
4299 | }
|
4300 |
|
4301 | this.print_token(current_token);
|
4302 | this.set_mode(next_mode);
|
4303 | if (this._options.space_in_paren) {
|
4304 | this._output.space_before_token = true;
|
4305 | }
|
4306 |
|
4307 |
|
4308 | this.indent();
|
4309 | };
|
4310 |
|
4311 | Beautifier.prototype.handle_end_expr = function(current_token) {
|
4312 |
|
4313 |
|
4314 | while (this._flags.mode === MODE.Statement) {
|
4315 | this.restore_mode();
|
4316 | }
|
4317 |
|
4318 | this.handle_whitespace_and_comments(current_token);
|
4319 |
|
4320 | if (this._flags.multiline_frame) {
|
4321 | this.allow_wrap_or_preserved_newline(current_token,
|
4322 | current_token.text === ']' && is_array(this._flags.mode) && !this._options.keep_array_indentation);
|
4323 | }
|
4324 |
|
4325 | if (this._options.space_in_paren) {
|
4326 | if (this._flags.last_token.type === TOKEN.START_EXPR && !this._options.space_in_empty_paren) {
|
4327 |
|
4328 | this._output.trim();
|
4329 | this._output.space_before_token = false;
|
4330 | } else {
|
4331 | this._output.space_before_token = true;
|
4332 | }
|
4333 | }
|
4334 | this.deindent();
|
4335 | this.print_token(current_token);
|
4336 | this.restore_mode();
|
4337 |
|
4338 | remove_redundant_indentation(this._output, this._previous_flags);
|
4339 |
|
4340 |
|
4341 | if (this._flags.do_while && this._previous_flags.mode === MODE.Conditional) {
|
4342 | this._previous_flags.mode = MODE.Expression;
|
4343 | this._flags.do_block = false;
|
4344 | this._flags.do_while = false;
|
4345 |
|
4346 | }
|
4347 | };
|
4348 |
|
4349 | Beautifier.prototype.handle_start_block = function(current_token) {
|
4350 | this.handle_whitespace_and_comments(current_token);
|
4351 |
|
4352 |
|
4353 | var next_token = this._tokens.peek();
|
4354 | var second_token = this._tokens.peek(1);
|
4355 | if (this._flags.last_word === 'switch' && this._flags.last_token.type === TOKEN.END_EXPR) {
|
4356 | this.set_mode(MODE.BlockStatement);
|
4357 | this._flags.in_case_statement = true;
|
4358 | } else if (this._flags.case_body) {
|
4359 | this.set_mode(MODE.BlockStatement);
|
4360 | } else if (second_token && (
|
4361 | (in_array(second_token.text, [':', ',']) && in_array(next_token.type, [TOKEN.STRING, TOKEN.WORD, TOKEN.RESERVED])) ||
|
4362 | (in_array(next_token.text, ['get', 'set', '...']) && in_array(second_token.type, [TOKEN.WORD, TOKEN.RESERVED]))
|
4363 | )) {
|
4364 |
|
4365 |
|
4366 | if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) {
|
4367 | this.set_mode(MODE.BlockStatement);
|
4368 | } else {
|
4369 | this.set_mode(MODE.ObjectLiteral);
|
4370 | }
|
4371 | } else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
|
4372 |
|
4373 | this.set_mode(MODE.BlockStatement);
|
4374 | } else if (in_array(this._flags.last_token.type, [TOKEN.EQUALS, TOKEN.START_EXPR, TOKEN.COMMA, TOKEN.OPERATOR]) ||
|
4375 | reserved_array(this._flags.last_token, ['return', 'throw', 'import', 'default'])
|
4376 | ) {
|
4377 |
|
4378 |
|
4379 |
|
4380 |
|
4381 | this.set_mode(MODE.ObjectLiteral);
|
4382 | } else {
|
4383 | this.set_mode(MODE.BlockStatement);
|
4384 | }
|
4385 |
|
4386 | if (this._flags.last_token) {
|
4387 | if (reserved_array(this._flags.last_token.previous, ['class', 'extends'])) {
|
4388 | this._flags.class_start_block = true;
|
4389 | }
|
4390 | }
|
4391 |
|
4392 | var empty_braces = !next_token.comments_before && next_token.text === '}';
|
4393 | var empty_anonymous_function = empty_braces && this._flags.last_word === 'function' &&
|
4394 | this._flags.last_token.type === TOKEN.END_EXPR;
|
4395 |
|
4396 | if (this._options.brace_preserve_inline)
|
4397 | {
|
4398 |
|
4399 | var index = 0;
|
4400 | var check_token = null;
|
4401 | this._flags.inline_frame = true;
|
4402 | do {
|
4403 | index += 1;
|
4404 | check_token = this._tokens.peek(index - 1);
|
4405 | if (check_token.newlines) {
|
4406 | this._flags.inline_frame = false;
|
4407 | break;
|
4408 | }
|
4409 | } while (check_token.type !== TOKEN.EOF &&
|
4410 | !(check_token.type === TOKEN.END_BLOCK && check_token.opened === current_token));
|
4411 | }
|
4412 |
|
4413 | if ((this._options.brace_style === "expand" ||
|
4414 | (this._options.brace_style === "none" && current_token.newlines)) &&
|
4415 | !this._flags.inline_frame) {
|
4416 | if (this._flags.last_token.type !== TOKEN.OPERATOR &&
|
4417 | (empty_anonymous_function ||
|
4418 | this._flags.last_token.type === TOKEN.EQUALS ||
|
4419 | (reserved_array(this._flags.last_token, special_words) && this._flags.last_token.text !== 'else'))) {
|
4420 | this._output.space_before_token = true;
|
4421 | } else {
|
4422 | this.print_newline(false, true);
|
4423 | }
|
4424 | } else {
|
4425 | if (is_array(this._previous_flags.mode) && (this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.COMMA)) {
|
4426 | if (this._flags.last_token.type === TOKEN.COMMA || this._options.space_in_paren) {
|
4427 | this._output.space_before_token = true;
|
4428 | }
|
4429 |
|
4430 | if (this._flags.last_token.type === TOKEN.COMMA || (this._flags.last_token.type === TOKEN.START_EXPR && this._flags.inline_frame)) {
|
4431 | this.allow_wrap_or_preserved_newline(current_token);
|
4432 | this._previous_flags.multiline_frame = this._previous_flags.multiline_frame || this._flags.multiline_frame;
|
4433 | this._flags.multiline_frame = false;
|
4434 | }
|
4435 | }
|
4436 | if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
|
4437 | if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
|
4438 | this.print_newline();
|
4439 | } else {
|
4440 | this._output.space_before_token = true;
|
4441 | }
|
4442 | }
|
4443 | }
|
4444 | this.print_token(current_token);
|
4445 | this.indent();
|
4446 |
|
4447 |
|
4448 | if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) {
|
4449 | this.print_newline();
|
4450 | }
|
4451 | };
|
4452 |
|
4453 | Beautifier.prototype.handle_end_block = function(current_token) {
|
4454 |
|
4455 | this.handle_whitespace_and_comments(current_token);
|
4456 |
|
4457 | while (this._flags.mode === MODE.Statement) {
|
4458 | this.restore_mode();
|
4459 | }
|
4460 |
|
4461 | var empty_braces = this._flags.last_token.type === TOKEN.START_BLOCK;
|
4462 |
|
4463 | if (this._flags.inline_frame && !empty_braces) {
|
4464 | this._output.space_before_token = true;
|
4465 | } else if (this._options.brace_style === "expand") {
|
4466 | if (!empty_braces) {
|
4467 | this.print_newline();
|
4468 | }
|
4469 | } else {
|
4470 |
|
4471 | if (!empty_braces) {
|
4472 | if (is_array(this._flags.mode) && this._options.keep_array_indentation) {
|
4473 |
|
4474 | this._options.keep_array_indentation = false;
|
4475 | this.print_newline();
|
4476 | this._options.keep_array_indentation = true;
|
4477 |
|
4478 | } else {
|
4479 | this.print_newline();
|
4480 | }
|
4481 | }
|
4482 | }
|
4483 | this.restore_mode();
|
4484 | this.print_token(current_token);
|
4485 | };
|
4486 |
|
4487 | Beautifier.prototype.handle_word = function(current_token) {
|
4488 | if (current_token.type === TOKEN.RESERVED) {
|
4489 | if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
|
4490 | current_token.type = TOKEN.WORD;
|
4491 | } else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) {
|
4492 | current_token.type = TOKEN.WORD;
|
4493 | } else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
|
4494 | current_token.type = TOKEN.WORD;
|
4495 | } else if (this._flags.mode === MODE.ObjectLiteral) {
|
4496 | var next_token = this._tokens.peek();
|
4497 | if (next_token.text === ':') {
|
4498 | current_token.type = TOKEN.WORD;
|
4499 | }
|
4500 | }
|
4501 | }
|
4502 |
|
4503 | if (this.start_of_statement(current_token)) {
|
4504 |
|
4505 | if (reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD) {
|
4506 | this._flags.declaration_statement = true;
|
4507 | }
|
4508 | } else if (current_token.newlines && !is_expression(this._flags.mode) &&
|
4509 | (this._flags.last_token.type !== TOKEN.OPERATOR || (this._flags.last_token.text === '--' || this._flags.last_token.text === '++')) &&
|
4510 | this._flags.last_token.type !== TOKEN.EQUALS &&
|
4511 | (this._options.preserve_newlines || !reserved_array(this._flags.last_token, ['var', 'let', 'const', 'set', 'get']))) {
|
4512 | this.handle_whitespace_and_comments(current_token);
|
4513 | this.print_newline();
|
4514 | } else {
|
4515 | this.handle_whitespace_and_comments(current_token);
|
4516 | }
|
4517 |
|
4518 | if (this._flags.do_block && !this._flags.do_while) {
|
4519 | if (reserved_word(current_token, 'while')) {
|
4520 |
|
4521 | this._output.space_before_token = true;
|
4522 | this.print_token(current_token);
|
4523 | this._output.space_before_token = true;
|
4524 | this._flags.do_while = true;
|
4525 | return;
|
4526 | } else {
|
4527 |
|
4528 |
|
4529 | this.print_newline();
|
4530 | this._flags.do_block = false;
|
4531 | }
|
4532 | }
|
4533 |
|
4534 |
|
4535 |
|
4536 |
|
4537 | if (this._flags.if_block) {
|
4538 | if (!this._flags.else_block && reserved_word(current_token, 'else')) {
|
4539 | this._flags.else_block = true;
|
4540 | } else {
|
4541 | while (this._flags.mode === MODE.Statement) {
|
4542 | this.restore_mode();
|
4543 | }
|
4544 | this._flags.if_block = false;
|
4545 | this._flags.else_block = false;
|
4546 | }
|
4547 | }
|
4548 |
|
4549 | if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) {
|
4550 | this.print_newline();
|
4551 | if (!this._flags.case_block && (this._flags.case_body || this._options.jslint_happy)) {
|
4552 |
|
4553 | this.deindent();
|
4554 | }
|
4555 | this._flags.case_body = false;
|
4556 |
|
4557 | this.print_token(current_token);
|
4558 | this._flags.in_case = true;
|
4559 | return;
|
4560 | }
|
4561 |
|
4562 | if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
|
4563 | if (!this.start_of_object_property()) {
|
4564 | this.allow_wrap_or_preserved_newline(current_token);
|
4565 | }
|
4566 | }
|
4567 |
|
4568 | if (reserved_word(current_token, 'function')) {
|
4569 | if (in_array(this._flags.last_token.text, ['}', ';']) ||
|
4570 | (this._output.just_added_newline() && !(in_array(this._flags.last_token.text, ['(', '[', '{', ':', '=', ',']) || this._flags.last_token.type === TOKEN.OPERATOR))) {
|
4571 |
|
4572 |
|
4573 | if (!this._output.just_added_blankline() && !current_token.comments_before) {
|
4574 | this.print_newline();
|
4575 | this.print_newline(true);
|
4576 | }
|
4577 | }
|
4578 | if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD) {
|
4579 | if (reserved_array(this._flags.last_token, ['get', 'set', 'new', 'export']) ||
|
4580 | reserved_array(this._flags.last_token, newline_restricted_tokens)) {
|
4581 | this._output.space_before_token = true;
|
4582 | } else if (reserved_word(this._flags.last_token, 'default') && this._last_last_text === 'export') {
|
4583 | this._output.space_before_token = true;
|
4584 | } else if (this._flags.last_token.text === 'declare') {
|
4585 |
|
4586 | this._output.space_before_token = true;
|
4587 | } else {
|
4588 | this.print_newline();
|
4589 | }
|
4590 | } else if (this._flags.last_token.type === TOKEN.OPERATOR || this._flags.last_token.text === '=') {
|
4591 |
|
4592 | this._output.space_before_token = true;
|
4593 | } else if (!this._flags.multiline_frame && (is_expression(this._flags.mode) || is_array(this._flags.mode))) ; else {
|
4594 | this.print_newline();
|
4595 | }
|
4596 |
|
4597 | this.print_token(current_token);
|
4598 | this._flags.last_word = current_token.text;
|
4599 | return;
|
4600 | }
|
4601 |
|
4602 | var prefix = 'NONE';
|
4603 |
|
4604 | if (this._flags.last_token.type === TOKEN.END_BLOCK) {
|
4605 |
|
4606 | if (this._previous_flags.inline_frame) {
|
4607 | prefix = 'SPACE';
|
4608 | } else if (!reserved_array(current_token, ['else', 'catch', 'finally', 'from'])) {
|
4609 | prefix = 'NEWLINE';
|
4610 | } else {
|
4611 | if (this._options.brace_style === "expand" ||
|
4612 | this._options.brace_style === "end-expand" ||
|
4613 | (this._options.brace_style === "none" && current_token.newlines)) {
|
4614 | prefix = 'NEWLINE';
|
4615 | } else {
|
4616 | prefix = 'SPACE';
|
4617 | this._output.space_before_token = true;
|
4618 | }
|
4619 | }
|
4620 | } else if (this._flags.last_token.type === TOKEN.SEMICOLON && this._flags.mode === MODE.BlockStatement) {
|
4621 |
|
4622 | prefix = 'NEWLINE';
|
4623 | } else if (this._flags.last_token.type === TOKEN.SEMICOLON && is_expression(this._flags.mode)) {
|
4624 | prefix = 'SPACE';
|
4625 | } else if (this._flags.last_token.type === TOKEN.STRING) {
|
4626 | prefix = 'NEWLINE';
|
4627 | } else if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD ||
|
4628 | (this._flags.last_token.text === '*' &&
|
4629 | (in_array(this._last_last_text, ['function', 'yield']) ||
|
4630 | (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
|
4631 | prefix = 'SPACE';
|
4632 | } else if (this._flags.last_token.type === TOKEN.START_BLOCK) {
|
4633 | if (this._flags.inline_frame) {
|
4634 | prefix = 'SPACE';
|
4635 | } else {
|
4636 | prefix = 'NEWLINE';
|
4637 | }
|
4638 | } else if (this._flags.last_token.type === TOKEN.END_EXPR) {
|
4639 | this._output.space_before_token = true;
|
4640 | prefix = 'NEWLINE';
|
4641 | }
|
4642 |
|
4643 | if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
|
4644 | if (this._flags.inline_frame || this._flags.last_token.text === 'else' || this._flags.last_token.text === 'export') {
|
4645 | prefix = 'SPACE';
|
4646 | } else {
|
4647 | prefix = 'NEWLINE';
|
4648 | }
|
4649 |
|
4650 | }
|
4651 |
|
4652 | if (reserved_array(current_token, ['else', 'catch', 'finally'])) {
|
4653 | if ((!(this._flags.last_token.type === TOKEN.END_BLOCK && this._previous_flags.mode === MODE.BlockStatement) ||
|
4654 | this._options.brace_style === "expand" ||
|
4655 | this._options.brace_style === "end-expand" ||
|
4656 | (this._options.brace_style === "none" && current_token.newlines)) &&
|
4657 | !this._flags.inline_frame) {
|
4658 | this.print_newline();
|
4659 | } else {
|
4660 | this._output.trim(true);
|
4661 | var line = this._output.current_line;
|
4662 |
|
4663 |
|
4664 | if (line.last() !== '}') {
|
4665 | this.print_newline();
|
4666 | }
|
4667 | this._output.space_before_token = true;
|
4668 | }
|
4669 | } else if (prefix === 'NEWLINE') {
|
4670 | if (reserved_array(this._flags.last_token, special_words)) {
|
4671 |
|
4672 | this._output.space_before_token = true;
|
4673 | } else if (this._flags.last_token.text === 'declare' && reserved_array(current_token, ['var', 'let', 'const'])) {
|
4674 |
|
4675 | this._output.space_before_token = true;
|
4676 | } else if (this._flags.last_token.type !== TOKEN.END_EXPR) {
|
4677 | if ((this._flags.last_token.type !== TOKEN.START_EXPR || !reserved_array(current_token, ['var', 'let', 'const'])) && this._flags.last_token.text !== ':') {
|
4678 |
|
4679 | if (reserved_word(current_token, 'if') && reserved_word(current_token.previous, 'else')) {
|
4680 |
|
4681 | this._output.space_before_token = true;
|
4682 | } else {
|
4683 | this.print_newline();
|
4684 | }
|
4685 | }
|
4686 | } else if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
|
4687 | this.print_newline();
|
4688 | }
|
4689 | } else if (this._flags.multiline_frame && is_array(this._flags.mode) && this._flags.last_token.text === ',' && this._last_last_text === '}') {
|
4690 | this.print_newline();
|
4691 | } else if (prefix === 'SPACE') {
|
4692 | this._output.space_before_token = true;
|
4693 | }
|
4694 | if (current_token.previous && (current_token.previous.type === TOKEN.WORD || current_token.previous.type === TOKEN.RESERVED)) {
|
4695 | this._output.space_before_token = true;
|
4696 | }
|
4697 | this.print_token(current_token);
|
4698 | this._flags.last_word = current_token.text;
|
4699 |
|
4700 | if (current_token.type === TOKEN.RESERVED) {
|
4701 | if (current_token.text === 'do') {
|
4702 | this._flags.do_block = true;
|
4703 | } else if (current_token.text === 'if') {
|
4704 | this._flags.if_block = true;
|
4705 | } else if (current_token.text === 'import') {
|
4706 | this._flags.import_block = true;
|
4707 | } else if (this._flags.import_block && reserved_word(current_token, 'from')) {
|
4708 | this._flags.import_block = false;
|
4709 | }
|
4710 | }
|
4711 | };
|
4712 |
|
4713 | Beautifier.prototype.handle_semicolon = function(current_token) {
|
4714 | if (this.start_of_statement(current_token)) {
|
4715 |
|
4716 |
|
4717 | this._output.space_before_token = false;
|
4718 | } else {
|
4719 | this.handle_whitespace_and_comments(current_token);
|
4720 | }
|
4721 |
|
4722 | var next_token = this._tokens.peek();
|
4723 | while (this._flags.mode === MODE.Statement &&
|
4724 | !(this._flags.if_block && reserved_word(next_token, 'else')) &&
|
4725 | !this._flags.do_block) {
|
4726 | this.restore_mode();
|
4727 | }
|
4728 |
|
4729 |
|
4730 | if (this._flags.import_block) {
|
4731 | this._flags.import_block = false;
|
4732 | }
|
4733 | this.print_token(current_token);
|
4734 | };
|
4735 |
|
4736 | Beautifier.prototype.handle_string = function(current_token) {
|
4737 | if (current_token.text.startsWith("`") && current_token.newlines === 0 && current_token.whitespace_before === '' && (current_token.previous.text === ')' || this._flags.last_token.type === TOKEN.WORD)) ; else if (this.start_of_statement(current_token)) {
|
4738 |
|
4739 |
|
4740 | this._output.space_before_token = true;
|
4741 | } else {
|
4742 | this.handle_whitespace_and_comments(current_token);
|
4743 | if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD || this._flags.inline_frame) {
|
4744 | this._output.space_before_token = true;
|
4745 | } else if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
|
4746 | if (!this.start_of_object_property()) {
|
4747 | this.allow_wrap_or_preserved_newline(current_token);
|
4748 | }
|
4749 | } else if ((current_token.text.startsWith("`") && this._flags.last_token.type === TOKEN.END_EXPR && (current_token.previous.text === ']' || current_token.previous.text === ')') && current_token.newlines === 0)) {
|
4750 | this._output.space_before_token = true;
|
4751 | } else {
|
4752 | this.print_newline();
|
4753 | }
|
4754 | }
|
4755 | this.print_token(current_token);
|
4756 | };
|
4757 |
|
4758 | Beautifier.prototype.handle_equals = function(current_token) {
|
4759 | if (this.start_of_statement(current_token)) ; else {
|
4760 | this.handle_whitespace_and_comments(current_token);
|
4761 | }
|
4762 |
|
4763 | if (this._flags.declaration_statement) {
|
4764 |
|
4765 | this._flags.declaration_assignment = true;
|
4766 | }
|
4767 | this._output.space_before_token = true;
|
4768 | this.print_token(current_token);
|
4769 | this._output.space_before_token = true;
|
4770 | };
|
4771 |
|
4772 | Beautifier.prototype.handle_comma = function(current_token) {
|
4773 | this.handle_whitespace_and_comments(current_token, true);
|
4774 |
|
4775 | this.print_token(current_token);
|
4776 | this._output.space_before_token = true;
|
4777 | if (this._flags.declaration_statement) {
|
4778 | if (is_expression(this._flags.parent.mode)) {
|
4779 |
|
4780 | this._flags.declaration_assignment = false;
|
4781 | }
|
4782 |
|
4783 | if (this._flags.declaration_assignment) {
|
4784 | this._flags.declaration_assignment = false;
|
4785 | this.print_newline(false, true);
|
4786 | } else if (this._options.comma_first) {
|
4787 |
|
4788 |
|
4789 | this.allow_wrap_or_preserved_newline(current_token);
|
4790 | }
|
4791 | } else if (this._flags.mode === MODE.ObjectLiteral ||
|
4792 | (this._flags.mode === MODE.Statement && this._flags.parent.mode === MODE.ObjectLiteral)) {
|
4793 | if (this._flags.mode === MODE.Statement) {
|
4794 | this.restore_mode();
|
4795 | }
|
4796 |
|
4797 | if (!this._flags.inline_frame) {
|
4798 | this.print_newline();
|
4799 | }
|
4800 | } else if (this._options.comma_first) {
|
4801 |
|
4802 |
|
4803 |
|
4804 | this.allow_wrap_or_preserved_newline(current_token);
|
4805 | }
|
4806 | };
|
4807 |
|
4808 | Beautifier.prototype.handle_operator = function(current_token) {
|
4809 | var isGeneratorAsterisk = current_token.text === '*' &&
|
4810 | (reserved_array(this._flags.last_token, ['function', 'yield']) ||
|
4811 | (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.COMMA, TOKEN.END_BLOCK, TOKEN.SEMICOLON]))
|
4812 | );
|
4813 | var isUnary = in_array(current_token.text, ['-', '+']) && (
|
4814 | in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.START_EXPR, TOKEN.EQUALS, TOKEN.OPERATOR]) ||
|
4815 | in_array(this._flags.last_token.text, line_starters) ||
|
4816 | this._flags.last_token.text === ','
|
4817 | );
|
4818 |
|
4819 | if (this.start_of_statement(current_token)) ; else {
|
4820 | var preserve_statement_flags = !isGeneratorAsterisk;
|
4821 | this.handle_whitespace_and_comments(current_token, preserve_statement_flags);
|
4822 | }
|
4823 |
|
4824 |
|
4825 | if (current_token.text === '*' && this._flags.last_token.type === TOKEN.DOT) {
|
4826 | this.print_token(current_token);
|
4827 | return;
|
4828 | }
|
4829 |
|
4830 | if (current_token.text === '::') {
|
4831 |
|
4832 | this.print_token(current_token);
|
4833 | return;
|
4834 | }
|
4835 |
|
4836 |
|
4837 |
|
4838 | if (this._flags.last_token.type === TOKEN.OPERATOR && in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) {
|
4839 | this.allow_wrap_or_preserved_newline(current_token);
|
4840 | }
|
4841 |
|
4842 | if (current_token.text === ':' && this._flags.in_case) {
|
4843 | this.print_token(current_token);
|
4844 |
|
4845 | this._flags.in_case = false;
|
4846 | this._flags.case_body = true;
|
4847 | if (this._tokens.peek().type !== TOKEN.START_BLOCK) {
|
4848 | this.indent();
|
4849 | this.print_newline();
|
4850 | this._flags.case_block = false;
|
4851 | } else {
|
4852 | this._flags.case_block = true;
|
4853 | this._output.space_before_token = true;
|
4854 | }
|
4855 | return;
|
4856 | }
|
4857 |
|
4858 | var space_before = true;
|
4859 | var space_after = true;
|
4860 | var in_ternary = false;
|
4861 | if (current_token.text === ':') {
|
4862 | if (this._flags.ternary_depth === 0) {
|
4863 |
|
4864 | space_before = false;
|
4865 | } else {
|
4866 | this._flags.ternary_depth -= 1;
|
4867 | in_ternary = true;
|
4868 | }
|
4869 | } else if (current_token.text === '?') {
|
4870 | this._flags.ternary_depth += 1;
|
4871 | }
|
4872 |
|
4873 |
|
4874 | if (!isUnary && !isGeneratorAsterisk && this._options.preserve_newlines && in_array(current_token.text, positionable_operators)) {
|
4875 | var isColon = current_token.text === ':';
|
4876 | var isTernaryColon = (isColon && in_ternary);
|
4877 | var isOtherColon = (isColon && !in_ternary);
|
4878 |
|
4879 | switch (this._options.operator_position) {
|
4880 | case OPERATOR_POSITION.before_newline:
|
4881 |
|
4882 | this._output.space_before_token = !isOtherColon;
|
4883 |
|
4884 | this.print_token(current_token);
|
4885 |
|
4886 | if (!isColon || isTernaryColon) {
|
4887 | this.allow_wrap_or_preserved_newline(current_token);
|
4888 | }
|
4889 |
|
4890 | this._output.space_before_token = true;
|
4891 | return;
|
4892 |
|
4893 | case OPERATOR_POSITION.after_newline:
|
4894 |
|
4895 |
|
4896 |
|
4897 | this._output.space_before_token = true;
|
4898 |
|
4899 | if (!isColon || isTernaryColon) {
|
4900 | if (this._tokens.peek().newlines) {
|
4901 | this.print_newline(false, true);
|
4902 | } else {
|
4903 | this.allow_wrap_or_preserved_newline(current_token);
|
4904 | }
|
4905 | } else {
|
4906 | this._output.space_before_token = false;
|
4907 | }
|
4908 |
|
4909 | this.print_token(current_token);
|
4910 |
|
4911 | this._output.space_before_token = true;
|
4912 | return;
|
4913 |
|
4914 | case OPERATOR_POSITION.preserve_newline:
|
4915 | if (!isOtherColon) {
|
4916 | this.allow_wrap_or_preserved_newline(current_token);
|
4917 | }
|
4918 |
|
4919 |
|
4920 |
|
4921 | space_before = !(this._output.just_added_newline() || isOtherColon);
|
4922 |
|
4923 | this._output.space_before_token = space_before;
|
4924 | this.print_token(current_token);
|
4925 | this._output.space_before_token = true;
|
4926 | return;
|
4927 | }
|
4928 | }
|
4929 |
|
4930 | if (isGeneratorAsterisk) {
|
4931 | this.allow_wrap_or_preserved_newline(current_token);
|
4932 | space_before = false;
|
4933 | var next_token = this._tokens.peek();
|
4934 | space_after = next_token && in_array(next_token.type, [TOKEN.WORD, TOKEN.RESERVED]);
|
4935 | } else if (current_token.text === '...') {
|
4936 | this.allow_wrap_or_preserved_newline(current_token);
|
4937 | space_before = this._flags.last_token.type === TOKEN.START_BLOCK;
|
4938 | space_after = false;
|
4939 | } else if (in_array(current_token.text, ['--', '++', '!', '~']) || isUnary) {
|
4940 |
|
4941 | if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR) {
|
4942 | this.allow_wrap_or_preserved_newline(current_token);
|
4943 | }
|
4944 |
|
4945 | space_before = false;
|
4946 | space_after = false;
|
4947 |
|
4948 |
|
4949 |
|
4950 | if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) {
|
4951 | var new_line_needed = reserved_array(this._flags.last_token, special_words) && current_token.newlines;
|
4952 | if (new_line_needed && (this._previous_flags.if_block || this._previous_flags.else_block)) {
|
4953 | this.restore_mode();
|
4954 | }
|
4955 | this.print_newline(new_line_needed, true);
|
4956 | }
|
4957 |
|
4958 | if (this._flags.last_token.text === ';' && is_expression(this._flags.mode)) {
|
4959 |
|
4960 |
|
4961 | space_before = true;
|
4962 | }
|
4963 |
|
4964 | if (this._flags.last_token.type === TOKEN.RESERVED) {
|
4965 | space_before = true;
|
4966 | } else if (this._flags.last_token.type === TOKEN.END_EXPR) {
|
4967 | space_before = !(this._flags.last_token.text === ']' && (current_token.text === '--' || current_token.text === '++'));
|
4968 | } else if (this._flags.last_token.type === TOKEN.OPERATOR) {
|
4969 |
|
4970 |
|
4971 | space_before = in_array(current_token.text, ['--', '-', '++', '+']) && in_array(this._flags.last_token.text, ['--', '-', '++', '+']);
|
4972 |
|
4973 |
|
4974 |
|
4975 |
|
4976 | if (in_array(current_token.text, ['+', '-']) && in_array(this._flags.last_token.text, ['--', '++'])) {
|
4977 | space_after = true;
|
4978 | }
|
4979 | }
|
4980 |
|
4981 |
|
4982 | if (((this._flags.mode === MODE.BlockStatement && !this._flags.inline_frame) || this._flags.mode === MODE.Statement) &&
|
4983 | (this._flags.last_token.text === '{' || this._flags.last_token.text === ';')) {
|
4984 |
|
4985 |
|
4986 | this.print_newline();
|
4987 | }
|
4988 | }
|
4989 |
|
4990 | this._output.space_before_token = this._output.space_before_token || space_before;
|
4991 | this.print_token(current_token);
|
4992 | this._output.space_before_token = space_after;
|
4993 | };
|
4994 |
|
4995 | Beautifier.prototype.handle_block_comment = function(current_token, preserve_statement_flags) {
|
4996 | if (this._output.raw) {
|
4997 | this._output.add_raw_token(current_token);
|
4998 | if (current_token.directives && current_token.directives.preserve === 'end') {
|
4999 |
|
5000 | this._output.raw = this._options.test_output_raw;
|
5001 | }
|
5002 | return;
|
5003 | }
|
5004 |
|
5005 | if (current_token.directives) {
|
5006 | this.print_newline(false, preserve_statement_flags);
|
5007 | this.print_token(current_token);
|
5008 | if (current_token.directives.preserve === 'start') {
|
5009 | this._output.raw = true;
|
5010 | }
|
5011 | this.print_newline(false, true);
|
5012 | return;
|
5013 | }
|
5014 |
|
5015 |
|
5016 | if (!acorn.newline.test(current_token.text) && !current_token.newlines) {
|
5017 | this._output.space_before_token = true;
|
5018 | this.print_token(current_token);
|
5019 | this._output.space_before_token = true;
|
5020 | return;
|
5021 | } else {
|
5022 | this.print_block_commment(current_token, preserve_statement_flags);
|
5023 | }
|
5024 | };
|
5025 |
|
5026 | Beautifier.prototype.print_block_commment = function(current_token, preserve_statement_flags) {
|
5027 | var lines = split_linebreaks(current_token.text);
|
5028 | var j;
|
5029 | var javadoc = false;
|
5030 | var starless = false;
|
5031 | var lastIndent = current_token.whitespace_before;
|
5032 | var lastIndentLength = lastIndent.length;
|
5033 |
|
5034 |
|
5035 | this.print_newline(false, preserve_statement_flags);
|
5036 |
|
5037 |
|
5038 | this.print_token_line_indentation(current_token);
|
5039 | this._output.add_token(lines[0]);
|
5040 | this.print_newline(false, preserve_statement_flags);
|
5041 |
|
5042 |
|
5043 | if (lines.length > 1) {
|
5044 | lines = lines.slice(1);
|
5045 | javadoc = all_lines_start_with(lines, '*');
|
5046 | starless = each_line_matches_indent(lines, lastIndent);
|
5047 |
|
5048 | if (javadoc) {
|
5049 | this._flags.alignment = 1;
|
5050 | }
|
5051 |
|
5052 | for (j = 0; j < lines.length; j++) {
|
5053 | if (javadoc) {
|
5054 |
|
5055 | this.print_token_line_indentation(current_token);
|
5056 | this._output.add_token(ltrim(lines[j]));
|
5057 | } else if (starless && lines[j]) {
|
5058 |
|
5059 | this.print_token_line_indentation(current_token);
|
5060 | this._output.add_token(lines[j].substring(lastIndentLength));
|
5061 | } else {
|
5062 |
|
5063 | this._output.current_line.set_indent(-1);
|
5064 | this._output.add_token(lines[j]);
|
5065 | }
|
5066 |
|
5067 |
|
5068 | this.print_newline(false, preserve_statement_flags);
|
5069 | }
|
5070 |
|
5071 | this._flags.alignment = 0;
|
5072 | }
|
5073 | };
|
5074 |
|
5075 |
|
5076 | Beautifier.prototype.handle_comment = function(current_token, preserve_statement_flags) {
|
5077 | if (current_token.newlines) {
|
5078 | this.print_newline(false, preserve_statement_flags);
|
5079 | } else {
|
5080 | this._output.trim(true);
|
5081 | }
|
5082 |
|
5083 | this._output.space_before_token = true;
|
5084 | this.print_token(current_token);
|
5085 | this.print_newline(false, preserve_statement_flags);
|
5086 | };
|
5087 |
|
5088 | Beautifier.prototype.handle_dot = function(current_token) {
|
5089 | if (this.start_of_statement(current_token)) ; else {
|
5090 | this.handle_whitespace_and_comments(current_token, true);
|
5091 | }
|
5092 |
|
5093 | if (this._flags.last_token.text.match('^[0-9]+$')) {
|
5094 | this._output.space_before_token = true;
|
5095 | }
|
5096 |
|
5097 | if (reserved_array(this._flags.last_token, special_words)) {
|
5098 | this._output.space_before_token = false;
|
5099 | } else {
|
5100 |
|
5101 |
|
5102 | this.allow_wrap_or_preserved_newline(current_token,
|
5103 | this._flags.last_token.text === ')' && this._options.break_chained_methods);
|
5104 | }
|
5105 |
|
5106 |
|
5107 |
|
5108 | if (this._options.unindent_chained_methods && this._output.just_added_newline()) {
|
5109 | this.deindent();
|
5110 | }
|
5111 |
|
5112 | this.print_token(current_token);
|
5113 | };
|
5114 |
|
5115 | Beautifier.prototype.handle_unknown = function(current_token, preserve_statement_flags) {
|
5116 | this.print_token(current_token);
|
5117 |
|
5118 | if (current_token.text[current_token.text.length - 1] === '\n') {
|
5119 | this.print_newline(false, preserve_statement_flags);
|
5120 | }
|
5121 | };
|
5122 |
|
5123 | Beautifier.prototype.handle_eof = function(current_token) {
|
5124 |
|
5125 | while (this._flags.mode === MODE.Statement) {
|
5126 | this.restore_mode();
|
5127 | }
|
5128 | this.handle_whitespace_and_comments(current_token);
|
5129 | };
|
5130 |
|
5131 | beautifier$2.Beautifier = Beautifier;
|
5132 | return beautifier$2;
|
5133 | }
|
5134 |
|
5135 |
|
5136 |
|
5137 | var hasRequiredJavascript;
|
5138 |
|
5139 | function requireJavascript () {
|
5140 | if (hasRequiredJavascript) return javascript.exports;
|
5141 | hasRequiredJavascript = 1;
|
5142 |
|
5143 | var Beautifier = requireBeautifier$2().Beautifier,
|
5144 | Options = requireOptions$2().Options;
|
5145 |
|
5146 | function js_beautify(js_source_text, options) {
|
5147 | var beautifier = new Beautifier(js_source_text, options);
|
5148 | return beautifier.beautify();
|
5149 | }
|
5150 |
|
5151 | javascript.exports = js_beautify;
|
5152 | javascript.exports.defaultOptions = function() {
|
5153 | return new Options();
|
5154 | };
|
5155 | return javascript.exports;
|
5156 | }
|
5157 |
|
5158 | var css = {exports: {}};
|
5159 |
|
5160 | var beautifier$1 = {};
|
5161 |
|
5162 | var options$1 = {};
|
5163 |
|
5164 |
|
5165 |
|
5166 | var hasRequiredOptions$1;
|
5167 |
|
5168 | function requireOptions$1 () {
|
5169 | if (hasRequiredOptions$1) return options$1;
|
5170 | hasRequiredOptions$1 = 1;
|
5171 |
|
5172 | var BaseOptions = requireOptions$3().Options;
|
5173 |
|
5174 | function Options(options) {
|
5175 | BaseOptions.call(this, options, 'css');
|
5176 |
|
5177 | this.selector_separator_newline = this._get_boolean('selector_separator_newline', true);
|
5178 | this.newline_between_rules = this._get_boolean('newline_between_rules', true);
|
5179 | var space_around_selector_separator = this._get_boolean('space_around_selector_separator');
|
5180 | this.space_around_combinator = this._get_boolean('space_around_combinator') || space_around_selector_separator;
|
5181 |
|
5182 | var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
|
5183 | this.brace_style = 'collapse';
|
5184 | for (var bs = 0; bs < brace_style_split.length; bs++) {
|
5185 | if (brace_style_split[bs] !== 'expand') {
|
5186 |
|
5187 | this.brace_style = 'collapse';
|
5188 | } else {
|
5189 | this.brace_style = brace_style_split[bs];
|
5190 | }
|
5191 | }
|
5192 | }
|
5193 | Options.prototype = new BaseOptions();
|
5194 |
|
5195 |
|
5196 |
|
5197 | options$1.Options = Options;
|
5198 | return options$1;
|
5199 | }
|
5200 |
|
5201 |
|
5202 |
|
5203 | var hasRequiredBeautifier$1;
|
5204 |
|
5205 | function requireBeautifier$1 () {
|
5206 | if (hasRequiredBeautifier$1) return beautifier$1;
|
5207 | hasRequiredBeautifier$1 = 1;
|
5208 |
|
5209 | var Options = requireOptions$1().Options;
|
5210 | var Output = requireOutput().Output;
|
5211 | var InputScanner = requireInputscanner().InputScanner;
|
5212 | var Directives = requireDirectives().Directives;
|
5213 |
|
5214 | var directives_core = new Directives(/\/\*/, /\*\
|
5215 |
|
5216 | var lineBreak = /\r\n|[\r\n]/;
|
5217 | var allLineBreaks = /\r\n|[\r\n]/g;
|
5218 |
|
5219 |
|
5220 | var whitespaceChar = /\s/;
|
5221 | var whitespacePattern = /(?:\s|\n)+/g;
|
5222 | var block_comment_pattern = /\/\*(?:[\s\S]*?)((?:\*\/)|$)/g;
|
5223 | var comment_pattern = /\/\/(?:[^\n\r\u2028\u2029]*)/g;
|
5224 |
|
5225 | function Beautifier(source_text, options) {
|
5226 | this._source_text = source_text || '';
|
5227 |
|
5228 |
|
5229 | this._options = new Options(options);
|
5230 | this._ch = null;
|
5231 | this._input = null;
|
5232 |
|
5233 |
|
5234 | this.NESTED_AT_RULE = {
|
5235 | "page": true,
|
5236 | "font-face": true,
|
5237 | "keyframes": true,
|
5238 |
|
5239 | "media": true,
|
5240 | "supports": true,
|
5241 | "document": true
|
5242 | };
|
5243 | this.CONDITIONAL_GROUP_RULE = {
|
5244 | "media": true,
|
5245 | "supports": true,
|
5246 | "document": true
|
5247 | };
|
5248 | this.NON_SEMICOLON_NEWLINE_PROPERTY = [
|
5249 | "grid-template-areas",
|
5250 | "grid-template"
|
5251 | ];
|
5252 |
|
5253 | }
|
5254 |
|
5255 | Beautifier.prototype.eatString = function(endChars) {
|
5256 | var result = '';
|
5257 | this._ch = this._input.next();
|
5258 | while (this._ch) {
|
5259 | result += this._ch;
|
5260 | if (this._ch === "\\") {
|
5261 | result += this._input.next();
|
5262 | } else if (endChars.indexOf(this._ch) !== -1 || this._ch === "\n") {
|
5263 | break;
|
5264 | }
|
5265 | this._ch = this._input.next();
|
5266 | }
|
5267 | return result;
|
5268 | };
|
5269 |
|
5270 |
|
5271 |
|
5272 |
|
5273 |
|
5274 | Beautifier.prototype.eatWhitespace = function(allowAtLeastOneNewLine) {
|
5275 | var result = whitespaceChar.test(this._input.peek());
|
5276 | var newline_count = 0;
|
5277 | while (whitespaceChar.test(this._input.peek())) {
|
5278 | this._ch = this._input.next();
|
5279 | if (allowAtLeastOneNewLine && this._ch === '\n') {
|
5280 | if (newline_count === 0 || newline_count < this._options.max_preserve_newlines) {
|
5281 | newline_count++;
|
5282 | this._output.add_new_line(true);
|
5283 | }
|
5284 | }
|
5285 | }
|
5286 | return result;
|
5287 | };
|
5288 |
|
5289 |
|
5290 |
|
5291 |
|
5292 | Beautifier.prototype.foundNestedPseudoClass = function() {
|
5293 | var openParen = 0;
|
5294 | var i = 1;
|
5295 | var ch = this._input.peek(i);
|
5296 | while (ch) {
|
5297 | if (ch === "{") {
|
5298 | return true;
|
5299 | } else if (ch === '(') {
|
5300 |
|
5301 | openParen += 1;
|
5302 | } else if (ch === ')') {
|
5303 | if (openParen === 0) {
|
5304 | return false;
|
5305 | }
|
5306 | openParen -= 1;
|
5307 | } else if (ch === ";" || ch === "}") {
|
5308 | return false;
|
5309 | }
|
5310 | i++;
|
5311 | ch = this._input.peek(i);
|
5312 | }
|
5313 | return false;
|
5314 | };
|
5315 |
|
5316 | Beautifier.prototype.print_string = function(output_string) {
|
5317 | this._output.set_indent(this._indentLevel);
|
5318 | this._output.non_breaking_space = true;
|
5319 | this._output.add_token(output_string);
|
5320 | };
|
5321 |
|
5322 | Beautifier.prototype.preserveSingleSpace = function(isAfterSpace) {
|
5323 | if (isAfterSpace) {
|
5324 | this._output.space_before_token = true;
|
5325 | }
|
5326 | };
|
5327 |
|
5328 | Beautifier.prototype.indent = function() {
|
5329 | this._indentLevel++;
|
5330 | };
|
5331 |
|
5332 | Beautifier.prototype.outdent = function() {
|
5333 | if (this._indentLevel > 0) {
|
5334 | this._indentLevel--;
|
5335 | }
|
5336 | };
|
5337 |
|
5338 |
|
5339 |
|
5340 | Beautifier.prototype.beautify = function() {
|
5341 | if (this._options.disabled) {
|
5342 | return this._source_text;
|
5343 | }
|
5344 |
|
5345 | var source_text = this._source_text;
|
5346 | var eol = this._options.eol;
|
5347 | if (eol === 'auto') {
|
5348 | eol = '\n';
|
5349 | if (source_text && lineBreak.test(source_text || '')) {
|
5350 | eol = source_text.match(lineBreak)[0];
|
5351 | }
|
5352 | }
|
5353 |
|
5354 |
|
5355 |
|
5356 | source_text = source_text.replace(allLineBreaks, '\n');
|
5357 |
|
5358 |
|
5359 | var baseIndentString = source_text.match(/^[\t ]*/)[0];
|
5360 |
|
5361 | this._output = new Output(this._options, baseIndentString);
|
5362 | this._input = new InputScanner(source_text);
|
5363 | this._indentLevel = 0;
|
5364 | this._nestedLevel = 0;
|
5365 |
|
5366 | this._ch = null;
|
5367 | var parenLevel = 0;
|
5368 |
|
5369 | var insideRule = false;
|
5370 |
|
5371 |
|
5372 | var insidePropertyValue = false;
|
5373 | var enteringConditionalGroup = false;
|
5374 | var insideNonNestedAtRule = false;
|
5375 | var insideScssMap = false;
|
5376 | var topCharacter = this._ch;
|
5377 | var insideNonSemiColonValues = false;
|
5378 | var whitespace;
|
5379 | var isAfterSpace;
|
5380 | var previous_ch;
|
5381 |
|
5382 | while (true) {
|
5383 | whitespace = this._input.read(whitespacePattern);
|
5384 | isAfterSpace = whitespace !== '';
|
5385 | previous_ch = topCharacter;
|
5386 | this._ch = this._input.next();
|
5387 | if (this._ch === '\\' && this._input.hasNext()) {
|
5388 | this._ch += this._input.next();
|
5389 | }
|
5390 | topCharacter = this._ch;
|
5391 |
|
5392 | if (!this._ch) {
|
5393 | break;
|
5394 | } else if (this._ch === '/' && this._input.peek() === '*') {
|
5395 |
|
5396 |
|
5397 |
|
5398 |
|
5399 |
|
5400 | this._output.add_new_line();
|
5401 | this._input.back();
|
5402 |
|
5403 | var comment = this._input.read(block_comment_pattern);
|
5404 |
|
5405 |
|
5406 | var directives = directives_core.get_directives(comment);
|
5407 | if (directives && directives.ignore === 'start') {
|
5408 | comment += directives_core.readIgnored(this._input);
|
5409 | }
|
5410 |
|
5411 | this.print_string(comment);
|
5412 |
|
5413 |
|
5414 | this.eatWhitespace(true);
|
5415 |
|
5416 |
|
5417 |
|
5418 | this._output.add_new_line();
|
5419 | } else if (this._ch === '/' && this._input.peek() === '/') {
|
5420 |
|
5421 |
|
5422 |
|
5423 | this._output.space_before_token = true;
|
5424 | this._input.back();
|
5425 | this.print_string(this._input.read(comment_pattern));
|
5426 |
|
5427 |
|
5428 | this.eatWhitespace(true);
|
5429 | } else if (this._ch === '$') {
|
5430 | this.preserveSingleSpace(isAfterSpace);
|
5431 |
|
5432 | this.print_string(this._ch);
|
5433 |
|
5434 |
|
5435 | var variable = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
|
5436 |
|
5437 | if (variable.match(/[ :]$/)) {
|
5438 |
|
5439 | variable = this.eatString(": ").replace(/\s$/, '');
|
5440 | this.print_string(variable);
|
5441 | this._output.space_before_token = true;
|
5442 | }
|
5443 |
|
5444 | variable = variable.replace(/\s$/, '');
|
5445 |
|
5446 |
|
5447 | if (parenLevel === 0 && variable.indexOf(':') !== -1) {
|
5448 | insidePropertyValue = true;
|
5449 | this.indent();
|
5450 | }
|
5451 | } else if (this._ch === '@') {
|
5452 | this.preserveSingleSpace(isAfterSpace);
|
5453 |
|
5454 |
|
5455 | if (this._input.peek() === '{') {
|
5456 | this.print_string(this._ch + this.eatString('}'));
|
5457 | } else {
|
5458 | this.print_string(this._ch);
|
5459 |
|
5460 |
|
5461 | var variableOrRule = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
|
5462 |
|
5463 | if (variableOrRule.match(/[ :]$/)) {
|
5464 |
|
5465 | variableOrRule = this.eatString(": ").replace(/\s$/, '');
|
5466 | this.print_string(variableOrRule);
|
5467 | this._output.space_before_token = true;
|
5468 | }
|
5469 |
|
5470 | variableOrRule = variableOrRule.replace(/\s$/, '');
|
5471 |
|
5472 |
|
5473 | if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
|
5474 | insidePropertyValue = true;
|
5475 | this.indent();
|
5476 |
|
5477 |
|
5478 | } else if (variableOrRule in this.NESTED_AT_RULE) {
|
5479 | this._nestedLevel += 1;
|
5480 | if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
|
5481 | enteringConditionalGroup = true;
|
5482 | }
|
5483 |
|
5484 |
|
5485 | } else if (parenLevel === 0 && !insidePropertyValue) {
|
5486 | insideNonNestedAtRule = true;
|
5487 | }
|
5488 | }
|
5489 | } else if (this._ch === '#' && this._input.peek() === '{') {
|
5490 | this.preserveSingleSpace(isAfterSpace);
|
5491 | this.print_string(this._ch + this.eatString('}'));
|
5492 | } else if (this._ch === '{') {
|
5493 | if (insidePropertyValue) {
|
5494 | insidePropertyValue = false;
|
5495 | this.outdent();
|
5496 | }
|
5497 |
|
5498 |
|
5499 | insideNonNestedAtRule = false;
|
5500 |
|
5501 |
|
5502 | if (enteringConditionalGroup) {
|
5503 | enteringConditionalGroup = false;
|
5504 | insideRule = (this._indentLevel >= this._nestedLevel);
|
5505 | } else {
|
5506 |
|
5507 | insideRule = (this._indentLevel >= this._nestedLevel - 1);
|
5508 | }
|
5509 | if (this._options.newline_between_rules && insideRule) {
|
5510 | if (this._output.previous_line && this._output.previous_line.item(-1) !== '{') {
|
5511 | this._output.ensure_empty_line_above('/', ',');
|
5512 | }
|
5513 | }
|
5514 |
|
5515 | this._output.space_before_token = true;
|
5516 |
|
5517 |
|
5518 | if (this._options.brace_style === 'expand') {
|
5519 | this._output.add_new_line();
|
5520 | this.print_string(this._ch);
|
5521 | this.indent();
|
5522 | this._output.set_indent(this._indentLevel);
|
5523 | } else {
|
5524 |
|
5525 | if (previous_ch === '(') {
|
5526 | this._output.space_before_token = false;
|
5527 | } else if (previous_ch !== ',') {
|
5528 | this.indent();
|
5529 | }
|
5530 | this.print_string(this._ch);
|
5531 | }
|
5532 |
|
5533 | this.eatWhitespace(true);
|
5534 | this._output.add_new_line();
|
5535 | } else if (this._ch === '}') {
|
5536 | this.outdent();
|
5537 | this._output.add_new_line();
|
5538 | if (previous_ch === '{') {
|
5539 | this._output.trim(true);
|
5540 | }
|
5541 |
|
5542 | if (insidePropertyValue) {
|
5543 | this.outdent();
|
5544 | insidePropertyValue = false;
|
5545 | }
|
5546 | this.print_string(this._ch);
|
5547 | insideRule = false;
|
5548 | if (this._nestedLevel) {
|
5549 | this._nestedLevel--;
|
5550 | }
|
5551 |
|
5552 | this.eatWhitespace(true);
|
5553 | this._output.add_new_line();
|
5554 |
|
5555 | if (this._options.newline_between_rules && !this._output.just_added_blankline()) {
|
5556 | if (this._input.peek() !== '}') {
|
5557 | this._output.add_new_line(true);
|
5558 | }
|
5559 | }
|
5560 | if (this._input.peek() === ')') {
|
5561 | this._output.trim(true);
|
5562 | if (this._options.brace_style === "expand") {
|
5563 | this._output.add_new_line(true);
|
5564 | }
|
5565 | }
|
5566 | } else if (this._ch === ":") {
|
5567 |
|
5568 | for (var i = 0; i < this.NON_SEMICOLON_NEWLINE_PROPERTY.length; i++) {
|
5569 | if (this._input.lookBack(this.NON_SEMICOLON_NEWLINE_PROPERTY[i])) {
|
5570 | insideNonSemiColonValues = true;
|
5571 | break;
|
5572 | }
|
5573 | }
|
5574 |
|
5575 | if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideNonNestedAtRule && parenLevel === 0) {
|
5576 |
|
5577 |
|
5578 |
|
5579 | this.print_string(':');
|
5580 | if (!insidePropertyValue) {
|
5581 | insidePropertyValue = true;
|
5582 | this._output.space_before_token = true;
|
5583 | this.eatWhitespace(true);
|
5584 | this.indent();
|
5585 | }
|
5586 | } else {
|
5587 |
|
5588 |
|
5589 |
|
5590 |
|
5591 | if (this._input.lookBack(" ")) {
|
5592 | this._output.space_before_token = true;
|
5593 | }
|
5594 | if (this._input.peek() === ":") {
|
5595 |
|
5596 | this._ch = this._input.next();
|
5597 | this.print_string("::");
|
5598 | } else {
|
5599 |
|
5600 | this.print_string(':');
|
5601 | }
|
5602 | }
|
5603 | } else if (this._ch === '"' || this._ch === '\'') {
|
5604 | var preserveQuoteSpace = previous_ch === '"' || previous_ch === '\'';
|
5605 | this.preserveSingleSpace(preserveQuoteSpace || isAfterSpace);
|
5606 | this.print_string(this._ch + this.eatString(this._ch));
|
5607 | this.eatWhitespace(true);
|
5608 | } else if (this._ch === ';') {
|
5609 | insideNonSemiColonValues = false;
|
5610 | if (parenLevel === 0) {
|
5611 | if (insidePropertyValue) {
|
5612 | this.outdent();
|
5613 | insidePropertyValue = false;
|
5614 | }
|
5615 | insideNonNestedAtRule = false;
|
5616 | this.print_string(this._ch);
|
5617 | this.eatWhitespace(true);
|
5618 |
|
5619 |
|
5620 |
|
5621 |
|
5622 |
|
5623 | if (this._input.peek() !== '/') {
|
5624 | this._output.add_new_line();
|
5625 | }
|
5626 | } else {
|
5627 | this.print_string(this._ch);
|
5628 | this.eatWhitespace(true);
|
5629 | this._output.space_before_token = true;
|
5630 | }
|
5631 | } else if (this._ch === '(') {
|
5632 | if (this._input.lookBack("url")) {
|
5633 | this.print_string(this._ch);
|
5634 | this.eatWhitespace();
|
5635 | parenLevel++;
|
5636 | this.indent();
|
5637 | this._ch = this._input.next();
|
5638 | if (this._ch === ')' || this._ch === '"' || this._ch === '\'') {
|
5639 | this._input.back();
|
5640 | } else if (this._ch) {
|
5641 | this.print_string(this._ch + this.eatString(')'));
|
5642 | if (parenLevel) {
|
5643 | parenLevel--;
|
5644 | this.outdent();
|
5645 | }
|
5646 | }
|
5647 | } else {
|
5648 | var space_needed = false;
|
5649 | if (this._input.lookBack("with")) {
|
5650 |
|
5651 | space_needed = true;
|
5652 | }
|
5653 | this.preserveSingleSpace(isAfterSpace || space_needed);
|
5654 | this.print_string(this._ch);
|
5655 |
|
5656 |
|
5657 | if (insidePropertyValue && previous_ch === "$" && this._options.selector_separator_newline) {
|
5658 | this._output.add_new_line();
|
5659 | insideScssMap = true;
|
5660 | } else {
|
5661 | this.eatWhitespace();
|
5662 | parenLevel++;
|
5663 | this.indent();
|
5664 | }
|
5665 | }
|
5666 | } else if (this._ch === ')') {
|
5667 | if (parenLevel) {
|
5668 | parenLevel--;
|
5669 | this.outdent();
|
5670 | }
|
5671 | if (insideScssMap && this._input.peek() === ";" && this._options.selector_separator_newline) {
|
5672 | insideScssMap = false;
|
5673 | this.outdent();
|
5674 | this._output.add_new_line();
|
5675 | }
|
5676 | this.print_string(this._ch);
|
5677 | } else if (this._ch === ',') {
|
5678 | this.print_string(this._ch);
|
5679 | this.eatWhitespace(true);
|
5680 | if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) {
|
5681 | this._output.add_new_line();
|
5682 | } else {
|
5683 | this._output.space_before_token = true;
|
5684 | }
|
5685 | } else if ((this._ch === '>' || this._ch === '+' || this._ch === '~') && !insidePropertyValue && parenLevel === 0) {
|
5686 |
|
5687 | if (this._options.space_around_combinator) {
|
5688 | this._output.space_before_token = true;
|
5689 | this.print_string(this._ch);
|
5690 | this._output.space_before_token = true;
|
5691 | } else {
|
5692 | this.print_string(this._ch);
|
5693 | this.eatWhitespace();
|
5694 |
|
5695 | if (this._ch && whitespaceChar.test(this._ch)) {
|
5696 | this._ch = '';
|
5697 | }
|
5698 | }
|
5699 | } else if (this._ch === ']') {
|
5700 | this.print_string(this._ch);
|
5701 | } else if (this._ch === '[') {
|
5702 | this.preserveSingleSpace(isAfterSpace);
|
5703 | this.print_string(this._ch);
|
5704 | } else if (this._ch === '=') {
|
5705 | this.eatWhitespace();
|
5706 | this.print_string('=');
|
5707 | if (whitespaceChar.test(this._ch)) {
|
5708 | this._ch = '';
|
5709 | }
|
5710 | } else if (this._ch === '!' && !this._input.lookBack("\\")) {
|
5711 | this._output.space_before_token = true;
|
5712 | this.print_string(this._ch);
|
5713 | } else {
|
5714 | var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
|
5715 | this.preserveSingleSpace(preserveAfterSpace || isAfterSpace);
|
5716 | this.print_string(this._ch);
|
5717 |
|
5718 | if (!this._output.just_added_newline() && this._input.peek() === '\n' && insideNonSemiColonValues) {
|
5719 | this._output.add_new_line();
|
5720 | }
|
5721 | }
|
5722 | }
|
5723 |
|
5724 | var sweetCode = this._output.get_code(eol);
|
5725 |
|
5726 | return sweetCode;
|
5727 | };
|
5728 |
|
5729 | beautifier$1.Beautifier = Beautifier;
|
5730 | return beautifier$1;
|
5731 | }
|
5732 |
|
5733 |
|
5734 |
|
5735 | var hasRequiredCss;
|
5736 |
|
5737 | function requireCss () {
|
5738 | if (hasRequiredCss) return css.exports;
|
5739 | hasRequiredCss = 1;
|
5740 |
|
5741 | var Beautifier = requireBeautifier$1().Beautifier,
|
5742 | Options = requireOptions$1().Options;
|
5743 |
|
5744 | function css_beautify(source_text, options) {
|
5745 | var beautifier = new Beautifier(source_text, options);
|
5746 | return beautifier.beautify();
|
5747 | }
|
5748 |
|
5749 | css.exports = css_beautify;
|
5750 | css.exports.defaultOptions = function() {
|
5751 | return new Options();
|
5752 | };
|
5753 | return css.exports;
|
5754 | }
|
5755 |
|
5756 | var html = {exports: {}};
|
5757 |
|
5758 | var beautifier = {};
|
5759 |
|
5760 | var options = {};
|
5761 |
|
5762 |
|
5763 |
|
5764 | var hasRequiredOptions;
|
5765 |
|
5766 | function requireOptions () {
|
5767 | if (hasRequiredOptions) return options;
|
5768 | hasRequiredOptions = 1;
|
5769 |
|
5770 | var BaseOptions = requireOptions$3().Options;
|
5771 |
|
5772 | function Options(options) {
|
5773 | BaseOptions.call(this, options, 'html');
|
5774 | if (this.templating.length === 1 && this.templating[0] === 'auto') {
|
5775 | this.templating = ['django', 'erb', 'handlebars', 'php'];
|
5776 | }
|
5777 |
|
5778 | this.indent_inner_html = this._get_boolean('indent_inner_html');
|
5779 | this.indent_body_inner_html = this._get_boolean('indent_body_inner_html', true);
|
5780 | this.indent_head_inner_html = this._get_boolean('indent_head_inner_html', true);
|
5781 |
|
5782 | this.indent_handlebars = this._get_boolean('indent_handlebars', true);
|
5783 | this.wrap_attributes = this._get_selection('wrap_attributes',
|
5784 | ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
|
5785 | this.wrap_attributes_min_attrs = this._get_number('wrap_attributes_min_attrs', 2);
|
5786 | this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
|
5787 | this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
|
5788 |
|
5789 |
|
5790 |
|
5791 |
|
5792 |
|
5793 | this.inline = this._get_array('inline', [
|
5794 | 'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite',
|
5795 | 'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img',
|
5796 | 'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'meter', 'noscript',
|
5797 | 'object', 'output', 'progress', 'q', 'ruby', 's', 'samp', 'select', 'small',
|
5798 | 'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
|
5799 | 'video', 'wbr', 'text',
|
5800 |
|
5801 | 'acronym', 'big', 'strike', 'tt'
|
5802 | ]);
|
5803 | this.inline_custom_elements = this._get_boolean('inline_custom_elements', true);
|
5804 | this.void_elements = this._get_array('void_elements', [
|
5805 |
|
5806 |
|
5807 | 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
|
5808 | 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
|
5809 |
|
5810 |
|
5811 |
|
5812 |
|
5813 | '!doctype', '?xml',
|
5814 |
|
5815 |
|
5816 |
|
5817 |
|
5818 | 'basefont', 'isindex'
|
5819 | ]);
|
5820 | this.unformatted = this._get_array('unformatted', []);
|
5821 | this.content_unformatted = this._get_array('content_unformatted', [
|
5822 | 'pre', 'textarea'
|
5823 | ]);
|
5824 | this.unformatted_content_delimiter = this._get_characters('unformatted_content_delimiter');
|
5825 | this.indent_scripts = this._get_selection('indent_scripts', ['normal', 'keep', 'separate']);
|
5826 |
|
5827 | }
|
5828 | Options.prototype = new BaseOptions();
|
5829 |
|
5830 |
|
5831 |
|
5832 | options.Options = Options;
|
5833 | return options;
|
5834 | }
|
5835 |
|
5836 | var tokenizer$1 = {};
|
5837 |
|
5838 |
|
5839 |
|
5840 | var hasRequiredTokenizer;
|
5841 |
|
5842 | function requireTokenizer () {
|
5843 | if (hasRequiredTokenizer) return tokenizer$1;
|
5844 | hasRequiredTokenizer = 1;
|
5845 |
|
5846 | var BaseTokenizer = requireTokenizer$2().Tokenizer;
|
5847 | var BASETOKEN = requireTokenizer$2().TOKEN;
|
5848 | var Directives = requireDirectives().Directives;
|
5849 | var TemplatablePattern = requireTemplatablepattern().TemplatablePattern;
|
5850 | var Pattern = requirePattern().Pattern;
|
5851 |
|
5852 | var TOKEN = {
|
5853 | TAG_OPEN: 'TK_TAG_OPEN',
|
5854 | TAG_CLOSE: 'TK_TAG_CLOSE',
|
5855 | ATTRIBUTE: 'TK_ATTRIBUTE',
|
5856 | EQUALS: 'TK_EQUALS',
|
5857 | VALUE: 'TK_VALUE',
|
5858 | COMMENT: 'TK_COMMENT',
|
5859 | TEXT: 'TK_TEXT',
|
5860 | UNKNOWN: 'TK_UNKNOWN',
|
5861 | START: BASETOKEN.START,
|
5862 | RAW: BASETOKEN.RAW,
|
5863 | EOF: BASETOKEN.EOF
|
5864 | };
|
5865 |
|
5866 | var directives_core = new Directives(/<\!--/, /-->/);
|
5867 |
|
5868 | var Tokenizer = function(input_string, options) {
|
5869 | BaseTokenizer.call(this, input_string, options);
|
5870 | this._current_tag_name = '';
|
5871 |
|
5872 |
|
5873 |
|
5874 | var templatable_reader = new TemplatablePattern(this._input).read_options(this._options);
|
5875 | var pattern_reader = new Pattern(this._input);
|
5876 |
|
5877 | this.__patterns = {
|
5878 | word: templatable_reader.until(/[\n\r\t <]/),
|
5879 | single_quote: templatable_reader.until_after(/'/),
|
5880 | double_quote: templatable_reader.until_after(/"/),
|
5881 | attribute: templatable_reader.until(/[\n\r\t =>]|\/>/),
|
5882 | element_name: templatable_reader.until(/[\n\r\t >\/]/),
|
5883 |
|
5884 | handlebars_comment: pattern_reader.starting_with(/{{!--/).until_after(/--}}/),
|
5885 | handlebars: pattern_reader.starting_with(/{{/).until_after(/}}/),
|
5886 | handlebars_open: pattern_reader.until(/[\n\r\t }]/),
|
5887 | handlebars_raw_close: pattern_reader.until(/}}/),
|
5888 | comment: pattern_reader.starting_with(/<!--/).until_after(/-->/),
|
5889 | cdata: pattern_reader.starting_with(/<!\[CDATA\[/).until_after(/]]>/),
|
5890 |
|
5891 | conditional_comment: pattern_reader.starting_with(/<!\[/).until_after(/]>/),
|
5892 | processing: pattern_reader.starting_with(/<\?/).until_after(/\?>/)
|
5893 | };
|
5894 |
|
5895 | if (this._options.indent_handlebars) {
|
5896 | this.__patterns.word = this.__patterns.word.exclude('handlebars');
|
5897 | }
|
5898 |
|
5899 | this._unformatted_content_delimiter = null;
|
5900 |
|
5901 | if (this._options.unformatted_content_delimiter) {
|
5902 | var literal_regexp = this._input.get_literal_regexp(this._options.unformatted_content_delimiter);
|
5903 | this.__patterns.unformatted_content_delimiter =
|
5904 | pattern_reader.matching(literal_regexp)
|
5905 | .until_after(literal_regexp);
|
5906 | }
|
5907 | };
|
5908 | Tokenizer.prototype = new BaseTokenizer();
|
5909 |
|
5910 | Tokenizer.prototype._is_comment = function(current_token) {
|
5911 | return false;
|
5912 | };
|
5913 |
|
5914 | Tokenizer.prototype._is_opening = function(current_token) {
|
5915 | return current_token.type === TOKEN.TAG_OPEN;
|
5916 | };
|
5917 |
|
5918 | Tokenizer.prototype._is_closing = function(current_token, open_token) {
|
5919 | return current_token.type === TOKEN.TAG_CLOSE &&
|
5920 | (open_token && (
|
5921 | ((current_token.text === '>' || current_token.text === '/>') && open_token.text[0] === '<') ||
|
5922 | (current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{')));
|
5923 | };
|
5924 |
|
5925 | Tokenizer.prototype._reset = function() {
|
5926 | this._current_tag_name = '';
|
5927 | };
|
5928 |
|
5929 | Tokenizer.prototype._get_next_token = function(previous_token, open_token) {
|
5930 | var token = null;
|
5931 | this._readWhitespace();
|
5932 | var c = this._input.peek();
|
5933 |
|
5934 | if (c === null) {
|
5935 | return this._create_token(TOKEN.EOF, '');
|
5936 | }
|
5937 |
|
5938 | token = token || this._read_open_handlebars(c, open_token);
|
5939 | token = token || this._read_attribute(c, previous_token, open_token);
|
5940 | token = token || this._read_close(c, open_token);
|
5941 | token = token || this._read_raw_content(c, previous_token, open_token);
|
5942 | token = token || this._read_content_word(c);
|
5943 | token = token || this._read_comment_or_cdata(c);
|
5944 | token = token || this._read_processing(c);
|
5945 | token = token || this._read_open(c, open_token);
|
5946 | token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
|
5947 |
|
5948 | return token;
|
5949 | };
|
5950 |
|
5951 | Tokenizer.prototype._read_comment_or_cdata = function(c) {
|
5952 | var token = null;
|
5953 | var resulting_string = null;
|
5954 | var directives = null;
|
5955 |
|
5956 | if (c === '<') {
|
5957 | var peek1 = this._input.peek(1);
|
5958 |
|
5959 |
|
5960 | if (peek1 === '!') {
|
5961 | resulting_string = this.__patterns.comment.read();
|
5962 |
|
5963 |
|
5964 | if (resulting_string) {
|
5965 | directives = directives_core.get_directives(resulting_string);
|
5966 | if (directives && directives.ignore === 'start') {
|
5967 | resulting_string += directives_core.readIgnored(this._input);
|
5968 | }
|
5969 | } else {
|
5970 | resulting_string = this.__patterns.cdata.read();
|
5971 | }
|
5972 | }
|
5973 |
|
5974 | if (resulting_string) {
|
5975 | token = this._create_token(TOKEN.COMMENT, resulting_string);
|
5976 | token.directives = directives;
|
5977 | }
|
5978 | }
|
5979 |
|
5980 | return token;
|
5981 | };
|
5982 |
|
5983 | Tokenizer.prototype._read_processing = function(c) {
|
5984 | var token = null;
|
5985 | var resulting_string = null;
|
5986 | var directives = null;
|
5987 |
|
5988 | if (c === '<') {
|
5989 | var peek1 = this._input.peek(1);
|
5990 | if (peek1 === '!' || peek1 === '?') {
|
5991 | resulting_string = this.__patterns.conditional_comment.read();
|
5992 | resulting_string = resulting_string || this.__patterns.processing.read();
|
5993 | }
|
5994 |
|
5995 | if (resulting_string) {
|
5996 | token = this._create_token(TOKEN.COMMENT, resulting_string);
|
5997 | token.directives = directives;
|
5998 | }
|
5999 | }
|
6000 |
|
6001 | return token;
|
6002 | };
|
6003 |
|
6004 | Tokenizer.prototype._read_open = function(c, open_token) {
|
6005 | var resulting_string = null;
|
6006 | var token = null;
|
6007 | if (!open_token) {
|
6008 | if (c === '<') {
|
6009 |
|
6010 | resulting_string = this._input.next();
|
6011 | if (this._input.peek() === '/') {
|
6012 | resulting_string += this._input.next();
|
6013 | }
|
6014 | resulting_string += this.__patterns.element_name.read();
|
6015 | token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
|
6016 | }
|
6017 | }
|
6018 | return token;
|
6019 | };
|
6020 |
|
6021 | Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
|
6022 | var resulting_string = null;
|
6023 | var token = null;
|
6024 | if (!open_token) {
|
6025 | if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
|
6026 | if (this._input.peek(2) === '!') {
|
6027 | resulting_string = this.__patterns.handlebars_comment.read();
|
6028 | resulting_string = resulting_string || this.__patterns.handlebars.read();
|
6029 | token = this._create_token(TOKEN.COMMENT, resulting_string);
|
6030 | } else {
|
6031 | resulting_string = this.__patterns.handlebars_open.read();
|
6032 | token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
|
6033 | }
|
6034 | }
|
6035 | }
|
6036 | return token;
|
6037 | };
|
6038 |
|
6039 |
|
6040 | Tokenizer.prototype._read_close = function(c, open_token) {
|
6041 | var resulting_string = null;
|
6042 | var token = null;
|
6043 | if (open_token) {
|
6044 | if (open_token.text[0] === '<' && (c === '>' || (c === '/' && this._input.peek(1) === '>'))) {
|
6045 | resulting_string = this._input.next();
|
6046 | if (c === '/') {
|
6047 | resulting_string += this._input.next();
|
6048 | }
|
6049 | token = this._create_token(TOKEN.TAG_CLOSE, resulting_string);
|
6050 | } else if (open_token.text[0] === '{' && c === '}' && this._input.peek(1) === '}') {
|
6051 | this._input.next();
|
6052 | this._input.next();
|
6053 | token = this._create_token(TOKEN.TAG_CLOSE, '}}');
|
6054 | }
|
6055 | }
|
6056 |
|
6057 | return token;
|
6058 | };
|
6059 |
|
6060 | Tokenizer.prototype._read_attribute = function(c, previous_token, open_token) {
|
6061 | var token = null;
|
6062 | var resulting_string = '';
|
6063 | if (open_token && open_token.text[0] === '<') {
|
6064 |
|
6065 | if (c === '=') {
|
6066 | token = this._create_token(TOKEN.EQUALS, this._input.next());
|
6067 | } else if (c === '"' || c === "'") {
|
6068 | var content = this._input.next();
|
6069 | if (c === '"') {
|
6070 | content += this.__patterns.double_quote.read();
|
6071 | } else {
|
6072 | content += this.__patterns.single_quote.read();
|
6073 | }
|
6074 | token = this._create_token(TOKEN.VALUE, content);
|
6075 | } else {
|
6076 | resulting_string = this.__patterns.attribute.read();
|
6077 |
|
6078 | if (resulting_string) {
|
6079 | if (previous_token.type === TOKEN.EQUALS) {
|
6080 | token = this._create_token(TOKEN.VALUE, resulting_string);
|
6081 | } else {
|
6082 | token = this._create_token(TOKEN.ATTRIBUTE, resulting_string);
|
6083 | }
|
6084 | }
|
6085 | }
|
6086 | }
|
6087 | return token;
|
6088 | };
|
6089 |
|
6090 | Tokenizer.prototype._is_content_unformatted = function(tag_name) {
|
6091 |
|
6092 |
|
6093 |
|
6094 | return this._options.void_elements.indexOf(tag_name) === -1 &&
|
6095 | (this._options.content_unformatted.indexOf(tag_name) !== -1 ||
|
6096 | this._options.unformatted.indexOf(tag_name) !== -1);
|
6097 | };
|
6098 |
|
6099 |
|
6100 | Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) {
|
6101 | var resulting_string = '';
|
6102 | if (open_token && open_token.text[0] === '{') {
|
6103 | resulting_string = this.__patterns.handlebars_raw_close.read();
|
6104 | } else if (previous_token.type === TOKEN.TAG_CLOSE &&
|
6105 | previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
|
6106 |
|
6107 | var tag_name = previous_token.opened.text.substr(1).toLowerCase();
|
6108 | if (tag_name === 'script' || tag_name === 'style') {
|
6109 |
|
6110 |
|
6111 | var token = this._read_comment_or_cdata(c);
|
6112 | if (token) {
|
6113 | token.type = TOKEN.TEXT;
|
6114 | return token;
|
6115 | }
|
6116 | resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
|
6117 | } else if (this._is_content_unformatted(tag_name)) {
|
6118 |
|
6119 | resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
|
6120 | }
|
6121 | }
|
6122 |
|
6123 | if (resulting_string) {
|
6124 | return this._create_token(TOKEN.TEXT, resulting_string);
|
6125 | }
|
6126 |
|
6127 | return null;
|
6128 | };
|
6129 |
|
6130 | Tokenizer.prototype._read_content_word = function(c) {
|
6131 | var resulting_string = '';
|
6132 | if (this._options.unformatted_content_delimiter) {
|
6133 | if (c === this._options.unformatted_content_delimiter[0]) {
|
6134 | resulting_string = this.__patterns.unformatted_content_delimiter.read();
|
6135 | }
|
6136 | }
|
6137 |
|
6138 | if (!resulting_string) {
|
6139 | resulting_string = this.__patterns.word.read();
|
6140 | }
|
6141 | if (resulting_string) {
|
6142 | return this._create_token(TOKEN.TEXT, resulting_string);
|
6143 | }
|
6144 | };
|
6145 |
|
6146 | tokenizer$1.Tokenizer = Tokenizer;
|
6147 | tokenizer$1.TOKEN = TOKEN;
|
6148 | return tokenizer$1;
|
6149 | }
|
6150 |
|
6151 |
|
6152 |
|
6153 | var hasRequiredBeautifier;
|
6154 |
|
6155 | function requireBeautifier () {
|
6156 | if (hasRequiredBeautifier) return beautifier;
|
6157 | hasRequiredBeautifier = 1;
|
6158 |
|
6159 | var Options = requireOptions().Options;
|
6160 | var Output = requireOutput().Output;
|
6161 | var Tokenizer = requireTokenizer().Tokenizer;
|
6162 | var TOKEN = requireTokenizer().TOKEN;
|
6163 |
|
6164 | var lineBreak = /\r\n|[\r\n]/;
|
6165 | var allLineBreaks = /\r\n|[\r\n]/g;
|
6166 |
|
6167 | var Printer = function(options, base_indent_string) {
|
6168 |
|
6169 | this.indent_level = 0;
|
6170 | this.alignment_size = 0;
|
6171 | this.max_preserve_newlines = options.max_preserve_newlines;
|
6172 | this.preserve_newlines = options.preserve_newlines;
|
6173 |
|
6174 | this._output = new Output(options, base_indent_string);
|
6175 |
|
6176 | };
|
6177 |
|
6178 | Printer.prototype.current_line_has_match = function(pattern) {
|
6179 | return this._output.current_line.has_match(pattern);
|
6180 | };
|
6181 |
|
6182 | Printer.prototype.set_space_before_token = function(value, non_breaking) {
|
6183 | this._output.space_before_token = value;
|
6184 | this._output.non_breaking_space = non_breaking;
|
6185 | };
|
6186 |
|
6187 | Printer.prototype.set_wrap_point = function() {
|
6188 | this._output.set_indent(this.indent_level, this.alignment_size);
|
6189 | this._output.set_wrap_point();
|
6190 | };
|
6191 |
|
6192 |
|
6193 | Printer.prototype.add_raw_token = function(token) {
|
6194 | this._output.add_raw_token(token);
|
6195 | };
|
6196 |
|
6197 | Printer.prototype.print_preserved_newlines = function(raw_token) {
|
6198 | var newlines = 0;
|
6199 | if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) {
|
6200 | newlines = raw_token.newlines ? 1 : 0;
|
6201 | }
|
6202 |
|
6203 | if (this.preserve_newlines) {
|
6204 | newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1;
|
6205 | }
|
6206 | for (var n = 0; n < newlines; n++) {
|
6207 | this.print_newline(n > 0);
|
6208 | }
|
6209 |
|
6210 | return newlines !== 0;
|
6211 | };
|
6212 |
|
6213 | Printer.prototype.traverse_whitespace = function(raw_token) {
|
6214 | if (raw_token.whitespace_before || raw_token.newlines) {
|
6215 | if (!this.print_preserved_newlines(raw_token)) {
|
6216 | this._output.space_before_token = true;
|
6217 | }
|
6218 | return true;
|
6219 | }
|
6220 | return false;
|
6221 | };
|
6222 |
|
6223 | Printer.prototype.previous_token_wrapped = function() {
|
6224 | return this._output.previous_token_wrapped;
|
6225 | };
|
6226 |
|
6227 | Printer.prototype.print_newline = function(force) {
|
6228 | this._output.add_new_line(force);
|
6229 | };
|
6230 |
|
6231 | Printer.prototype.print_token = function(token) {
|
6232 | if (token.text) {
|
6233 | this._output.set_indent(this.indent_level, this.alignment_size);
|
6234 | this._output.add_token(token.text);
|
6235 | }
|
6236 | };
|
6237 |
|
6238 | Printer.prototype.indent = function() {
|
6239 | this.indent_level++;
|
6240 | };
|
6241 |
|
6242 | Printer.prototype.get_full_indent = function(level) {
|
6243 | level = this.indent_level + (level || 0);
|
6244 | if (level < 1) {
|
6245 | return '';
|
6246 | }
|
6247 |
|
6248 | return this._output.get_indent_string(level);
|
6249 | };
|
6250 |
|
6251 | var get_type_attribute = function(start_token) {
|
6252 | var result = null;
|
6253 | var raw_token = start_token.next;
|
6254 |
|
6255 |
|
6256 | while (raw_token.type !== TOKEN.EOF && start_token.closed !== raw_token) {
|
6257 | if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') {
|
6258 | if (raw_token.next && raw_token.next.type === TOKEN.EQUALS &&
|
6259 | raw_token.next.next && raw_token.next.next.type === TOKEN.VALUE) {
|
6260 | result = raw_token.next.next.text;
|
6261 | }
|
6262 | break;
|
6263 | }
|
6264 | raw_token = raw_token.next;
|
6265 | }
|
6266 |
|
6267 | return result;
|
6268 | };
|
6269 |
|
6270 | var get_custom_beautifier_name = function(tag_check, raw_token) {
|
6271 | var typeAttribute = null;
|
6272 | var result = null;
|
6273 |
|
6274 | if (!raw_token.closed) {
|
6275 | return null;
|
6276 | }
|
6277 |
|
6278 | if (tag_check === 'script') {
|
6279 | typeAttribute = 'text/javascript';
|
6280 | } else if (tag_check === 'style') {
|
6281 | typeAttribute = 'text/css';
|
6282 | }
|
6283 |
|
6284 | typeAttribute = get_type_attribute(raw_token) || typeAttribute;
|
6285 |
|
6286 |
|
6287 |
|
6288 | if (typeAttribute.search('text/css') > -1) {
|
6289 | result = 'css';
|
6290 | } else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
|
6291 | result = 'javascript';
|
6292 | } else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
|
6293 | result = 'html';
|
6294 | } else if (typeAttribute.search(/test\/null/) > -1) {
|
6295 |
|
6296 | result = 'null';
|
6297 | }
|
6298 |
|
6299 | return result;
|
6300 | };
|
6301 |
|
6302 | function in_array(what, arr) {
|
6303 | return arr.indexOf(what) !== -1;
|
6304 | }
|
6305 |
|
6306 | function TagFrame(parent, parser_token, indent_level) {
|
6307 | this.parent = parent || null;
|
6308 | this.tag = parser_token ? parser_token.tag_name : '';
|
6309 | this.indent_level = indent_level || 0;
|
6310 | this.parser_token = parser_token || null;
|
6311 | }
|
6312 |
|
6313 | function TagStack(printer) {
|
6314 | this._printer = printer;
|
6315 | this._current_frame = null;
|
6316 | }
|
6317 |
|
6318 | TagStack.prototype.get_parser_token = function() {
|
6319 | return this._current_frame ? this._current_frame.parser_token : null;
|
6320 | };
|
6321 |
|
6322 | TagStack.prototype.record_tag = function(parser_token) {
|
6323 | var new_frame = new TagFrame(this._current_frame, parser_token, this._printer.indent_level);
|
6324 | this._current_frame = new_frame;
|
6325 | };
|
6326 |
|
6327 | TagStack.prototype._try_pop_frame = function(frame) {
|
6328 | var parser_token = null;
|
6329 |
|
6330 | if (frame) {
|
6331 | parser_token = frame.parser_token;
|
6332 | this._printer.indent_level = frame.indent_level;
|
6333 | this._current_frame = frame.parent;
|
6334 | }
|
6335 |
|
6336 | return parser_token;
|
6337 | };
|
6338 |
|
6339 | TagStack.prototype._get_frame = function(tag_list, stop_list) {
|
6340 | var frame = this._current_frame;
|
6341 |
|
6342 | while (frame) {
|
6343 | if (tag_list.indexOf(frame.tag) !== -1) {
|
6344 | break;
|
6345 | } else if (stop_list && stop_list.indexOf(frame.tag) !== -1) {
|
6346 | frame = null;
|
6347 | break;
|
6348 | }
|
6349 | frame = frame.parent;
|
6350 | }
|
6351 |
|
6352 | return frame;
|
6353 | };
|
6354 |
|
6355 | TagStack.prototype.try_pop = function(tag, stop_list) {
|
6356 | var frame = this._get_frame([tag], stop_list);
|
6357 | return this._try_pop_frame(frame);
|
6358 | };
|
6359 |
|
6360 | TagStack.prototype.indent_to_tag = function(tag_list) {
|
6361 | var frame = this._get_frame(tag_list);
|
6362 | if (frame) {
|
6363 | this._printer.indent_level = frame.indent_level;
|
6364 | }
|
6365 | };
|
6366 |
|
6367 | function Beautifier(source_text, options, js_beautify, css_beautify) {
|
6368 |
|
6369 | this._source_text = source_text || '';
|
6370 | options = options || {};
|
6371 | this._js_beautify = js_beautify;
|
6372 | this._css_beautify = css_beautify;
|
6373 | this._tag_stack = null;
|
6374 |
|
6375 |
|
6376 |
|
6377 | var optionHtml = new Options(options, 'html');
|
6378 |
|
6379 | this._options = optionHtml;
|
6380 |
|
6381 | this._is_wrap_attributes_force = this._options.wrap_attributes.substr(0, 'force'.length) === 'force';
|
6382 | this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
|
6383 | this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
|
6384 | this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
|
6385 | this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
|
6386 | this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
|
6387 | }
|
6388 |
|
6389 | Beautifier.prototype.beautify = function() {
|
6390 |
|
6391 |
|
6392 | if (this._options.disabled) {
|
6393 | return this._source_text;
|
6394 | }
|
6395 |
|
6396 | var source_text = this._source_text;
|
6397 | var eol = this._options.eol;
|
6398 | if (this._options.eol === 'auto') {
|
6399 | eol = '\n';
|
6400 | if (source_text && lineBreak.test(source_text)) {
|
6401 | eol = source_text.match(lineBreak)[0];
|
6402 | }
|
6403 | }
|
6404 |
|
6405 |
|
6406 | source_text = source_text.replace(allLineBreaks, '\n');
|
6407 |
|
6408 | var baseIndentString = source_text.match(/^[\t ]*/)[0];
|
6409 |
|
6410 | var last_token = {
|
6411 | text: '',
|
6412 | type: ''
|
6413 | };
|
6414 |
|
6415 | var last_tag_token = new TagOpenParserToken();
|
6416 |
|
6417 | var printer = new Printer(this._options, baseIndentString);
|
6418 | var tokens = new Tokenizer(source_text, this._options).tokenize();
|
6419 |
|
6420 | this._tag_stack = new TagStack(printer);
|
6421 |
|
6422 | var parser_token = null;
|
6423 | var raw_token = tokens.next();
|
6424 | while (raw_token.type !== TOKEN.EOF) {
|
6425 |
|
6426 | if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
|
6427 | parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token, tokens);
|
6428 | last_tag_token = parser_token;
|
6429 | } else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
|
6430 | (raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
|
6431 | parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, last_token);
|
6432 | } else if (raw_token.type === TOKEN.TAG_CLOSE) {
|
6433 | parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);
|
6434 | } else if (raw_token.type === TOKEN.TEXT) {
|
6435 | parser_token = this._handle_text(printer, raw_token, last_tag_token);
|
6436 | } else {
|
6437 |
|
6438 | printer.add_raw_token(raw_token);
|
6439 | }
|
6440 |
|
6441 | last_token = parser_token;
|
6442 |
|
6443 | raw_token = tokens.next();
|
6444 | }
|
6445 | var sweet_code = printer._output.get_code(eol);
|
6446 |
|
6447 | return sweet_code;
|
6448 | };
|
6449 |
|
6450 | Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
|
6451 | var parser_token = {
|
6452 | text: raw_token.text,
|
6453 | type: raw_token.type
|
6454 | };
|
6455 | printer.alignment_size = 0;
|
6456 | last_tag_token.tag_complete = true;
|
6457 |
|
6458 | printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
|
6459 | if (last_tag_token.is_unformatted) {
|
6460 | printer.add_raw_token(raw_token);
|
6461 | } else {
|
6462 | if (last_tag_token.tag_start_char === '<') {
|
6463 | printer.set_space_before_token(raw_token.text[0] === '/', true);
|
6464 | if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
|
6465 | printer.print_newline(false);
|
6466 | }
|
6467 | }
|
6468 | printer.print_token(raw_token);
|
6469 |
|
6470 | }
|
6471 |
|
6472 | if (last_tag_token.indent_content &&
|
6473 | !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
|
6474 | printer.indent();
|
6475 |
|
6476 |
|
6477 | last_tag_token.indent_content = false;
|
6478 | }
|
6479 |
|
6480 | if (!last_tag_token.is_inline_element &&
|
6481 | !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
|
6482 | printer.set_wrap_point();
|
6483 | }
|
6484 |
|
6485 | return parser_token;
|
6486 | };
|
6487 |
|
6488 | Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, last_token) {
|
6489 | var wrapped = last_tag_token.has_wrapped_attrs;
|
6490 | var parser_token = {
|
6491 | text: raw_token.text,
|
6492 | type: raw_token.type
|
6493 | };
|
6494 |
|
6495 | printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
|
6496 | if (last_tag_token.is_unformatted) {
|
6497 | printer.add_raw_token(raw_token);
|
6498 | } else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) {
|
6499 |
|
6500 | if (printer.print_preserved_newlines(raw_token)) {
|
6501 | raw_token.newlines = 0;
|
6502 | printer.add_raw_token(raw_token);
|
6503 | } else {
|
6504 | printer.print_token(raw_token);
|
6505 | }
|
6506 | } else {
|
6507 | if (raw_token.type === TOKEN.ATTRIBUTE) {
|
6508 | printer.set_space_before_token(true);
|
6509 | } else if (raw_token.type === TOKEN.EQUALS) {
|
6510 | printer.set_space_before_token(false);
|
6511 | } else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) {
|
6512 | printer.set_space_before_token(false);
|
6513 | }
|
6514 |
|
6515 | if (raw_token.type === TOKEN.ATTRIBUTE && last_tag_token.tag_start_char === '<') {
|
6516 | if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
|
6517 | printer.traverse_whitespace(raw_token);
|
6518 | wrapped = wrapped || raw_token.newlines !== 0;
|
6519 | }
|
6520 |
|
6521 |
|
6522 |
|
6523 |
|
6524 | if (this._is_wrap_attributes_force &&
|
6525 | last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
|
6526 | (last_token.type !== TOKEN.TAG_OPEN ||
|
6527 | this._is_wrap_attributes_force_expand_multiline)) {
|
6528 | printer.print_newline(false);
|
6529 | wrapped = true;
|
6530 | }
|
6531 | }
|
6532 | printer.print_token(raw_token);
|
6533 | wrapped = wrapped || printer.previous_token_wrapped();
|
6534 | last_tag_token.has_wrapped_attrs = wrapped;
|
6535 | }
|
6536 | return parser_token;
|
6537 | };
|
6538 |
|
6539 | Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
|
6540 | var parser_token = {
|
6541 | text: raw_token.text,
|
6542 | type: 'TK_CONTENT'
|
6543 | };
|
6544 | if (last_tag_token.custom_beautifier_name) {
|
6545 | this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
|
6546 | } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
|
6547 | printer.add_raw_token(raw_token);
|
6548 | } else {
|
6549 | printer.traverse_whitespace(raw_token);
|
6550 | printer.print_token(raw_token);
|
6551 | }
|
6552 | return parser_token;
|
6553 | };
|
6554 |
|
6555 | Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) {
|
6556 | var local = this;
|
6557 | if (raw_token.text !== '') {
|
6558 |
|
6559 | var text = raw_token.text,
|
6560 | _beautifier,
|
6561 | script_indent_level = 1,
|
6562 | pre = '',
|
6563 | post = '';
|
6564 | if (last_tag_token.custom_beautifier_name === 'javascript' && typeof this._js_beautify === 'function') {
|
6565 | _beautifier = this._js_beautify;
|
6566 | } else if (last_tag_token.custom_beautifier_name === 'css' && typeof this._css_beautify === 'function') {
|
6567 | _beautifier = this._css_beautify;
|
6568 | } else if (last_tag_token.custom_beautifier_name === 'html') {
|
6569 | _beautifier = function(html_source, options) {
|
6570 | var beautifier = new Beautifier(html_source, options, local._js_beautify, local._css_beautify);
|
6571 | return beautifier.beautify();
|
6572 | };
|
6573 | }
|
6574 |
|
6575 | if (this._options.indent_scripts === "keep") {
|
6576 | script_indent_level = 0;
|
6577 | } else if (this._options.indent_scripts === "separate") {
|
6578 | script_indent_level = -printer.indent_level;
|
6579 | }
|
6580 |
|
6581 | var indentation = printer.get_full_indent(script_indent_level);
|
6582 |
|
6583 |
|
6584 |
|
6585 | text = text.replace(/\n[ \t]*$/, '');
|
6586 |
|
6587 |
|
6588 | if (last_tag_token.custom_beautifier_name !== 'html' &&
|
6589 | text[0] === '<' && text.match(/^(<!--|<!\[CDATA\[)/)) {
|
6590 | var matched = /^(<!--[^\n]*|<!\[CDATA\[)(\n?)([ \t\n]*)([\s\S]*)(-->|]]>)$/.exec(text);
|
6591 |
|
6592 |
|
6593 | if (!matched) {
|
6594 | printer.add_raw_token(raw_token);
|
6595 | return;
|
6596 | }
|
6597 |
|
6598 | pre = indentation + matched[1] + '\n';
|
6599 | text = matched[4];
|
6600 | if (matched[5]) {
|
6601 | post = indentation + matched[5];
|
6602 | }
|
6603 |
|
6604 |
|
6605 |
|
6606 | text = text.replace(/\n[ \t]*$/, '');
|
6607 |
|
6608 | if (matched[2] || matched[3].indexOf('\n') !== -1) {
|
6609 |
|
6610 |
|
6611 | matched = matched[3].match(/[ \t]+$/);
|
6612 | if (matched) {
|
6613 | raw_token.whitespace_before = matched[0];
|
6614 | }
|
6615 | }
|
6616 | }
|
6617 |
|
6618 | if (text) {
|
6619 | if (_beautifier) {
|
6620 |
|
6621 |
|
6622 | var Child_options = function() {
|
6623 | this.eol = '\n';
|
6624 | };
|
6625 | Child_options.prototype = this._options.raw_options;
|
6626 | var child_options = new Child_options();
|
6627 | text = _beautifier(indentation + text, child_options);
|
6628 | } else {
|
6629 |
|
6630 | var white = raw_token.whitespace_before;
|
6631 | if (white) {
|
6632 | text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n');
|
6633 | }
|
6634 |
|
6635 | text = indentation + text.replace(/\n/g, '\n' + indentation);
|
6636 | }
|
6637 | }
|
6638 |
|
6639 | if (pre) {
|
6640 | if (!text) {
|
6641 | text = pre + post;
|
6642 | } else {
|
6643 | text = pre + text + '\n' + post;
|
6644 | }
|
6645 | }
|
6646 |
|
6647 | printer.print_newline(false);
|
6648 | if (text) {
|
6649 | raw_token.text = text;
|
6650 | raw_token.whitespace_before = '';
|
6651 | raw_token.newlines = 0;
|
6652 | printer.add_raw_token(raw_token);
|
6653 | printer.print_newline(true);
|
6654 | }
|
6655 | }
|
6656 | };
|
6657 |
|
6658 | Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token, tokens) {
|
6659 | var parser_token = this._get_tag_open_token(raw_token);
|
6660 |
|
6661 | if ((last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) &&
|
6662 | !last_tag_token.is_empty_element &&
|
6663 | raw_token.type === TOKEN.TAG_OPEN && !parser_token.is_start_tag) {
|
6664 |
|
6665 |
|
6666 | printer.add_raw_token(raw_token);
|
6667 | parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
|
6668 | } else {
|
6669 | printer.traverse_whitespace(raw_token);
|
6670 | this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
|
6671 | if (!parser_token.is_inline_element) {
|
6672 | printer.set_wrap_point();
|
6673 | }
|
6674 | printer.print_token(raw_token);
|
6675 | }
|
6676 |
|
6677 |
|
6678 | if (parser_token.is_start_tag && this._is_wrap_attributes_force) {
|
6679 | var peek_index = 0;
|
6680 | var peek_token;
|
6681 | do {
|
6682 | peek_token = tokens.peek(peek_index);
|
6683 | if (peek_token.type === TOKEN.ATTRIBUTE) {
|
6684 | parser_token.attr_count += 1;
|
6685 | }
|
6686 | peek_index += 1;
|
6687 | } while (peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
|
6688 | }
|
6689 |
|
6690 |
|
6691 | if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
|
6692 | parser_token.alignment_size = raw_token.text.length + 1;
|
6693 | }
|
6694 |
|
6695 | if (!parser_token.tag_complete && !parser_token.is_unformatted) {
|
6696 | printer.alignment_size = parser_token.alignment_size;
|
6697 | }
|
6698 |
|
6699 | return parser_token;
|
6700 | };
|
6701 |
|
6702 | var TagOpenParserToken = function(parent, raw_token) {
|
6703 | this.parent = parent || null;
|
6704 | this.text = '';
|
6705 | this.type = 'TK_TAG_OPEN';
|
6706 | this.tag_name = '';
|
6707 | this.is_inline_element = false;
|
6708 | this.is_unformatted = false;
|
6709 | this.is_content_unformatted = false;
|
6710 | this.is_empty_element = false;
|
6711 | this.is_start_tag = false;
|
6712 | this.is_end_tag = false;
|
6713 | this.indent_content = false;
|
6714 | this.multiline_content = false;
|
6715 | this.custom_beautifier_name = null;
|
6716 | this.start_tag_token = null;
|
6717 | this.attr_count = 0;
|
6718 | this.has_wrapped_attrs = false;
|
6719 | this.alignment_size = 0;
|
6720 | this.tag_complete = false;
|
6721 | this.tag_start_char = '';
|
6722 | this.tag_check = '';
|
6723 |
|
6724 | if (!raw_token) {
|
6725 | this.tag_complete = true;
|
6726 | } else {
|
6727 | var tag_check_match;
|
6728 |
|
6729 | this.tag_start_char = raw_token.text[0];
|
6730 | this.text = raw_token.text;
|
6731 |
|
6732 | if (this.tag_start_char === '<') {
|
6733 | tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
|
6734 | this.tag_check = tag_check_match ? tag_check_match[1] : '';
|
6735 | } else {
|
6736 | tag_check_match = raw_token.text.match(/^{{~?(?:[\^]|#\*?)?([^\s}]+)/);
|
6737 | this.tag_check = tag_check_match ? tag_check_match[1] : '';
|
6738 |
|
6739 |
|
6740 | if ((raw_token.text.startsWith('{{#>') || raw_token.text.startsWith('{{~#>')) && this.tag_check[0] === '>') {
|
6741 | if (this.tag_check === '>' && raw_token.next !== null) {
|
6742 | this.tag_check = raw_token.next.text.split(' ')[0];
|
6743 | } else {
|
6744 | this.tag_check = raw_token.text.split('>')[1];
|
6745 | }
|
6746 | }
|
6747 | }
|
6748 |
|
6749 | this.tag_check = this.tag_check.toLowerCase();
|
6750 |
|
6751 | if (raw_token.type === TOKEN.COMMENT) {
|
6752 | this.tag_complete = true;
|
6753 | }
|
6754 |
|
6755 | this.is_start_tag = this.tag_check.charAt(0) !== '/';
|
6756 | this.tag_name = !this.is_start_tag ? this.tag_check.substr(1) : this.tag_check;
|
6757 | this.is_end_tag = !this.is_start_tag ||
|
6758 | (raw_token.closed && raw_token.closed.text === '/>');
|
6759 |
|
6760 |
|
6761 | var handlebar_starts = 2;
|
6762 | if (this.tag_start_char === '{' && this.text.length >= 3) {
|
6763 | if (this.text.charAt(2) === '~') {
|
6764 | handlebar_starts = 3;
|
6765 | }
|
6766 | }
|
6767 |
|
6768 |
|
6769 | this.is_end_tag = this.is_end_tag ||
|
6770 | (this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
|
6771 | }
|
6772 | };
|
6773 |
|
6774 | Beautifier.prototype._get_tag_open_token = function(raw_token) {
|
6775 | var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
|
6776 |
|
6777 | parser_token.alignment_size = this._options.wrap_attributes_indent_size;
|
6778 |
|
6779 | parser_token.is_end_tag = parser_token.is_end_tag ||
|
6780 | in_array(parser_token.tag_check, this._options.void_elements);
|
6781 |
|
6782 | parser_token.is_empty_element = parser_token.tag_complete ||
|
6783 | (parser_token.is_start_tag && parser_token.is_end_tag);
|
6784 |
|
6785 | parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
|
6786 | parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
|
6787 | parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || (this._options.inline_custom_elements && parser_token.tag_name.includes("-")) || parser_token.tag_start_char === '{';
|
6788 |
|
6789 | return parser_token;
|
6790 | };
|
6791 |
|
6792 | Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_token, last_tag_token, last_token) {
|
6793 |
|
6794 | if (!parser_token.is_empty_element) {
|
6795 | if (parser_token.is_end_tag) {
|
6796 | parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
|
6797 | } else {
|
6798 |
|
6799 |
|
6800 | if (this._do_optional_end_element(parser_token)) {
|
6801 | if (!parser_token.is_inline_element) {
|
6802 | printer.print_newline(false);
|
6803 | }
|
6804 | }
|
6805 |
|
6806 | this._tag_stack.record_tag(parser_token);
|
6807 |
|
6808 | if ((parser_token.tag_name === 'script' || parser_token.tag_name === 'style') &&
|
6809 | !(parser_token.is_unformatted || parser_token.is_content_unformatted)) {
|
6810 | parser_token.custom_beautifier_name = get_custom_beautifier_name(parser_token.tag_check, raw_token);
|
6811 | }
|
6812 | }
|
6813 | }
|
6814 |
|
6815 | if (in_array(parser_token.tag_check, this._options.extra_liners)) {
|
6816 | printer.print_newline(false);
|
6817 | if (!printer._output.just_added_blankline()) {
|
6818 | printer.print_newline(true);
|
6819 | }
|
6820 | }
|
6821 |
|
6822 | if (parser_token.is_empty_element) {
|
6823 |
|
6824 |
|
6825 |
|
6826 | if (parser_token.tag_start_char === '{' && parser_token.tag_check === 'else') {
|
6827 | this._tag_stack.indent_to_tag(['if', 'unless', 'each']);
|
6828 | parser_token.indent_content = true;
|
6829 |
|
6830 | var foundIfOnCurrentLine = printer.current_line_has_match(/{{#if/);
|
6831 | if (!foundIfOnCurrentLine) {
|
6832 | printer.print_newline(false);
|
6833 | }
|
6834 | }
|
6835 |
|
6836 |
|
6837 | if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE &&
|
6838 | last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) ; else {
|
6839 | if (!(parser_token.is_inline_element || parser_token.is_unformatted)) {
|
6840 | printer.print_newline(false);
|
6841 | }
|
6842 | this._calcluate_parent_multiline(printer, parser_token);
|
6843 | }
|
6844 | } else if (parser_token.is_end_tag) {
|
6845 | var do_end_expand = false;
|
6846 |
|
6847 |
|
6848 | do_end_expand = parser_token.start_tag_token && parser_token.start_tag_token.multiline_content;
|
6849 | do_end_expand = do_end_expand || (!parser_token.is_inline_element &&
|
6850 | !(last_tag_token.is_inline_element || last_tag_token.is_unformatted) &&
|
6851 | !(last_token.type === TOKEN.TAG_CLOSE && parser_token.start_tag_token === last_tag_token) &&
|
6852 | last_token.type !== 'TK_CONTENT'
|
6853 | );
|
6854 |
|
6855 | if (parser_token.is_content_unformatted || parser_token.is_unformatted) {
|
6856 | do_end_expand = false;
|
6857 | }
|
6858 |
|
6859 | if (do_end_expand) {
|
6860 | printer.print_newline(false);
|
6861 | }
|
6862 | } else {
|
6863 | parser_token.indent_content = !parser_token.custom_beautifier_name;
|
6864 |
|
6865 | if (parser_token.tag_start_char === '<') {
|
6866 | if (parser_token.tag_name === 'html') {
|
6867 | parser_token.indent_content = this._options.indent_inner_html;
|
6868 | } else if (parser_token.tag_name === 'head') {
|
6869 | parser_token.indent_content = this._options.indent_head_inner_html;
|
6870 | } else if (parser_token.tag_name === 'body') {
|
6871 | parser_token.indent_content = this._options.indent_body_inner_html;
|
6872 | }
|
6873 | }
|
6874 |
|
6875 | if (!(parser_token.is_inline_element || parser_token.is_unformatted) &&
|
6876 | (last_token.type !== 'TK_CONTENT' || parser_token.is_content_unformatted)) {
|
6877 | printer.print_newline(false);
|
6878 | }
|
6879 |
|
6880 | this._calcluate_parent_multiline(printer, parser_token);
|
6881 | }
|
6882 | };
|
6883 |
|
6884 | Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_token) {
|
6885 | if (parser_token.parent && printer._output.just_added_newline() &&
|
6886 | !((parser_token.is_inline_element || parser_token.is_unformatted) && parser_token.parent.is_inline_element)) {
|
6887 | parser_token.parent.multiline_content = true;
|
6888 | }
|
6889 | };
|
6890 |
|
6891 |
|
6892 | var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
|
6893 | var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
|
6894 |
|
6895 | Beautifier.prototype._do_optional_end_element = function(parser_token) {
|
6896 | var result = null;
|
6897 |
|
6898 |
|
6899 |
|
6900 |
|
6901 | if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
|
6902 | return;
|
6903 |
|
6904 | }
|
6905 |
|
6906 | if (parser_token.tag_name === 'body') {
|
6907 |
|
6908 | result = result || this._tag_stack.try_pop('head');
|
6909 |
|
6910 |
|
6911 |
|
6912 |
|
6913 | } else if (parser_token.tag_name === 'li') {
|
6914 |
|
6915 | result = result || this._tag_stack.try_pop('li', ['ol', 'ul', 'menu']);
|
6916 |
|
6917 | } else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
|
6918 |
|
6919 |
|
6920 | result = result || this._tag_stack.try_pop('dt', ['dl']);
|
6921 | result = result || this._tag_stack.try_pop('dd', ['dl']);
|
6922 |
|
6923 |
|
6924 | } else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) {
|
6925 |
|
6926 |
|
6927 |
|
6928 |
|
6929 | var p_parent = parser_token.parent.parent;
|
6930 | if (!p_parent || p_parent_excludes.indexOf(p_parent.tag_name) === -1) {
|
6931 | result = result || this._tag_stack.try_pop('p');
|
6932 | }
|
6933 | } else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
|
6934 |
|
6935 |
|
6936 | result = result || this._tag_stack.try_pop('rt', ['ruby', 'rtc']);
|
6937 | result = result || this._tag_stack.try_pop('rp', ['ruby', 'rtc']);
|
6938 |
|
6939 | } else if (parser_token.tag_name === 'optgroup') {
|
6940 |
|
6941 |
|
6942 | result = result || this._tag_stack.try_pop('optgroup', ['select']);
|
6943 |
|
6944 |
|
6945 | } else if (parser_token.tag_name === 'option') {
|
6946 |
|
6947 | result = result || this._tag_stack.try_pop('option', ['select', 'datalist', 'optgroup']);
|
6948 |
|
6949 | } else if (parser_token.tag_name === 'colgroup') {
|
6950 |
|
6951 |
|
6952 | result = result || this._tag_stack.try_pop('caption', ['table']);
|
6953 |
|
6954 | } else if (parser_token.tag_name === 'thead') {
|
6955 |
|
6956 |
|
6957 | result = result || this._tag_stack.try_pop('caption', ['table']);
|
6958 | result = result || this._tag_stack.try_pop('colgroup', ['table']);
|
6959 |
|
6960 |
|
6961 |
|
6962 |
|
6963 | } else if (parser_token.tag_name === 'tbody' || parser_token.tag_name === 'tfoot') {
|
6964 |
|
6965 |
|
6966 |
|
6967 |
|
6968 | result = result || this._tag_stack.try_pop('caption', ['table']);
|
6969 | result = result || this._tag_stack.try_pop('colgroup', ['table']);
|
6970 | result = result || this._tag_stack.try_pop('thead', ['table']);
|
6971 | result = result || this._tag_stack.try_pop('tbody', ['table']);
|
6972 |
|
6973 |
|
6974 |
|
6975 |
|
6976 | } else if (parser_token.tag_name === 'tr') {
|
6977 |
|
6978 |
|
6979 |
|
6980 | result = result || this._tag_stack.try_pop('caption', ['table']);
|
6981 | result = result || this._tag_stack.try_pop('colgroup', ['table']);
|
6982 | result = result || this._tag_stack.try_pop('tr', ['table', 'thead', 'tbody', 'tfoot']);
|
6983 |
|
6984 | } else if (parser_token.tag_name === 'th' || parser_token.tag_name === 'td') {
|
6985 |
|
6986 |
|
6987 | result = result || this._tag_stack.try_pop('td', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
|
6988 | result = result || this._tag_stack.try_pop('th', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
|
6989 | }
|
6990 |
|
6991 |
|
6992 |
|
6993 |
|
6994 |
|
6995 |
|
6996 |
|
6997 | parser_token.parent = this._tag_stack.get_parser_token();
|
6998 |
|
6999 | return result;
|
7000 | };
|
7001 |
|
7002 | beautifier.Beautifier = Beautifier;
|
7003 | return beautifier;
|
7004 | }
|
7005 |
|
7006 |
|
7007 |
|
7008 | var hasRequiredHtml;
|
7009 |
|
7010 | function requireHtml () {
|
7011 | if (hasRequiredHtml) return html.exports;
|
7012 | hasRequiredHtml = 1;
|
7013 |
|
7014 | var Beautifier = requireBeautifier().Beautifier,
|
7015 | Options = requireOptions().Options;
|
7016 |
|
7017 | function style_html(html_source, options, js_beautify, css_beautify) {
|
7018 | var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
|
7019 | return beautifier.beautify();
|
7020 | }
|
7021 |
|
7022 | html.exports = style_html;
|
7023 | html.exports.defaultOptions = function() {
|
7024 | return new Options();
|
7025 | };
|
7026 | return html.exports;
|
7027 | }
|
7028 |
|
7029 |
|
7030 |
|
7031 | var hasRequiredSrc;
|
7032 |
|
7033 | function requireSrc () {
|
7034 | if (hasRequiredSrc) return src;
|
7035 | hasRequiredSrc = 1;
|
7036 |
|
7037 | var js_beautify = requireJavascript();
|
7038 | var css_beautify = requireCss();
|
7039 | var html_beautify = requireHtml();
|
7040 |
|
7041 | function style_html(html_source, options, js, css) {
|
7042 | js = js || js_beautify;
|
7043 | css = css || css_beautify;
|
7044 | return html_beautify(html_source, options, js, css);
|
7045 | }
|
7046 | style_html.defaultOptions = html_beautify.defaultOptions;
|
7047 |
|
7048 | src.js = js_beautify;
|
7049 | src.css = css_beautify;
|
7050 | src.html = style_html;
|
7051 | return src;
|
7052 | }
|
7053 |
|
7054 |
|
7055 |
|
7056 | (function (module) {
|
7057 |
|
7058 | |
7059 |
|
7060 |
|
7061 |
|
7062 |
|
7063 |
|
7064 |
|
7065 |
|
7066 |
|
7067 |
|
7068 |
|
7069 |
|
7070 |
|
7071 |
|
7072 |
|
7073 |
|
7074 | function get_beautify(js_beautify, css_beautify, html_beautify) {
|
7075 |
|
7076 | var beautify = function(src, config) {
|
7077 | return js_beautify.js_beautify(src, config);
|
7078 | };
|
7079 |
|
7080 |
|
7081 | beautify.js = js_beautify.js_beautify;
|
7082 | beautify.css = css_beautify.css_beautify;
|
7083 | beautify.html = html_beautify.html_beautify;
|
7084 |
|
7085 |
|
7086 | beautify.js_beautify = js_beautify.js_beautify;
|
7087 | beautify.css_beautify = css_beautify.css_beautify;
|
7088 | beautify.html_beautify = html_beautify.html_beautify;
|
7089 |
|
7090 | return beautify;
|
7091 | }
|
7092 |
|
7093 | {
|
7094 | (function(mod) {
|
7095 | var beautifier = requireSrc();
|
7096 | beautifier.js_beautify = beautifier.js;
|
7097 | beautifier.css_beautify = beautifier.css;
|
7098 | beautifier.html_beautify = beautifier.html;
|
7099 |
|
7100 | mod.exports = get_beautify(beautifier, beautifier, beautifier);
|
7101 |
|
7102 | })(module);
|
7103 | }
|
7104 | } (js));
|
7105 |
|
7106 | var jsExports = js.exports;
|
7107 | var beautify = getDefaultExportFromCjs(jsExports);
|
7108 |
|
7109 | var BaseWrapper = (function () {
|
7110 | function BaseWrapper(element) {
|
7111 | var _this = this;
|
7112 | this.isDisabled = function () {
|
7113 | var validTagsToBeDisabled = [
|
7114 | 'BUTTON',
|
7115 | 'COMMAND',
|
7116 | 'FIELDSET',
|
7117 | 'KEYGEN',
|
7118 | 'OPTGROUP',
|
7119 | 'OPTION',
|
7120 | 'SELECT',
|
7121 | 'TEXTAREA',
|
7122 | 'INPUT'
|
7123 | ];
|
7124 | var hasDisabledAttribute = _this.attributes().disabled !== undefined;
|
7125 | var elementCanBeDisabled = isElement(_this.element) &&
|
7126 | validTagsToBeDisabled.includes(_this.element.tagName);
|
7127 | return hasDisabledAttribute && elementCanBeDisabled;
|
7128 | };
|
7129 | this.wrapperElement = element;
|
7130 | }
|
7131 | Object.defineProperty(BaseWrapper.prototype, "element", {
|
7132 | get: function () {
|
7133 | return this.wrapperElement;
|
7134 | },
|
7135 | enumerable: false,
|
7136 | configurable: true
|
7137 | });
|
7138 | BaseWrapper.prototype.findAllDOMElements = function (selector) {
|
7139 | var elementRootNodes = this.getRootNodes().filter(isElement);
|
7140 | if (elementRootNodes.length === 0)
|
7141 | return [];
|
7142 | var result = __spreadArray([], elementRootNodes.filter(function (node) { return node.matches(selector); }), true);
|
7143 | elementRootNodes.forEach(function (rootNode) {
|
7144 | result.push.apply(result, Array.from(rootNode.querySelectorAll(selector)));
|
7145 | });
|
7146 | return result;
|
7147 | };
|
7148 | BaseWrapper.prototype.find = function (selector) {
|
7149 | if (typeof selector === 'object' && 'ref' in selector) {
|
7150 | var currentComponent = this.getCurrentComponent();
|
7151 | if (!currentComponent) {
|
7152 | return createWrapperError('DOMWrapper');
|
7153 | }
|
7154 | var result = currentComponent.refs[selector.ref];
|
7155 |
|
7156 | if (Array.isArray(result)) {
|
7157 | result = result.length ? result[0] : undefined;
|
7158 | }
|
7159 | if (result instanceof Node) {
|
7160 | return createDOMWrapper(result);
|
7161 | }
|
7162 | else {
|
7163 | return createWrapperError('DOMWrapper');
|
7164 | }
|
7165 | }
|
7166 | var elements = this.findAll(selector);
|
7167 | if (elements.length > 0) {
|
7168 | return elements[0];
|
7169 | }
|
7170 | return createWrapperError('DOMWrapper');
|
7171 | };
|
7172 | BaseWrapper.prototype.findComponent = function (selector) {
|
7173 | var currentComponent = this.getCurrentComponent();
|
7174 | if (!currentComponent) {
|
7175 | return createWrapperError('VueWrapper');
|
7176 | }
|
7177 | if (typeof selector === 'object' && 'ref' in selector) {
|
7178 | var result_1 = currentComponent.refs[selector.ref];
|
7179 |
|
7180 | if (Array.isArray(result_1)) {
|
7181 | result_1 = result_1.length ? result_1[0] : undefined;
|
7182 | }
|
7183 | if (result_1 && !(result_1 instanceof HTMLElement)) {
|
7184 | return createVueWrapper(null, result_1);
|
7185 | }
|
7186 | else {
|
7187 | return createWrapperError('VueWrapper');
|
7188 | }
|
7189 | }
|
7190 | if (matches(currentComponent.vnode, selector) &&
|
7191 | this.element.contains(currentComponent.vnode.el)) {
|
7192 | return createVueWrapper(null, currentComponent.subTree.component
|
7193 | ? currentComponent.subTree.component.proxy
|
7194 | : currentComponent.proxy);
|
7195 | }
|
7196 | var result = this.findAllComponents(selector)[0];
|
7197 | return result !== null && result !== void 0 ? result : createWrapperError('VueWrapper');
|
7198 | };
|
7199 | BaseWrapper.prototype.findAllComponents = function (selector) {
|
7200 | var currentComponent = this.getCurrentComponent();
|
7201 | if (!currentComponent) {
|
7202 | return [];
|
7203 | }
|
7204 | var results = find(currentComponent.subTree, selector);
|
7205 | return results.map(function (c) {
|
7206 | return c.proxy
|
7207 | ? createVueWrapper(null, c.proxy)
|
7208 | : createDOMWrapper(c.vnode.el);
|
7209 | });
|
7210 | };
|
7211 | BaseWrapper.prototype.html = function (options) {
|
7212 | var stringNodes = this.getRootNodes().map(function (node) { return stringifyNode(node); });
|
7213 | if (options === null || options === void 0 ? void 0 : options.raw)
|
7214 | return stringNodes.join('');
|
7215 | return stringNodes
|
7216 | .map(function (node) {
|
7217 | return beautify.html(node, {
|
7218 | unformatted: ['code', 'pre', 'em', 'strong', 'span'],
|
7219 | indent_inner_html: true,
|
7220 | indent_size: 2,
|
7221 | inline_custom_elements: false
|
7222 |
|
7223 | });
|
7224 | })
|
7225 | .join('\n');
|
7226 | };
|
7227 | BaseWrapper.prototype.classes = function (className) {
|
7228 | var classes = isElement(this.element)
|
7229 | ? Array.from(this.element.classList)
|
7230 | : [];
|
7231 | if (className)
|
7232 | return classes.includes(className);
|
7233 | return classes;
|
7234 | };
|
7235 | BaseWrapper.prototype.attributes = function (key) {
|
7236 | var attributeMap = {};
|
7237 | if (isElement(this.element)) {
|
7238 | var attributes = Array.from(this.element.attributes);
|
7239 | for (var _i = 0, attributes_1 = attributes; _i < attributes_1.length; _i++) {
|
7240 | var attribute = attributes_1[_i];
|
7241 | attributeMap[attribute.localName] = attribute.value;
|
7242 | }
|
7243 | }
|
7244 | return key ? attributeMap[key] : attributeMap;
|
7245 | };
|
7246 | BaseWrapper.prototype.text = function () {
|
7247 | return this.getRootNodes().map(textContent).join('');
|
7248 | };
|
7249 | BaseWrapper.prototype.exists = function () {
|
7250 | return true;
|
7251 | };
|
7252 | BaseWrapper.prototype.get = function (selector) {
|
7253 | var result = this.find(selector);
|
7254 | if (result.exists()) {
|
7255 | return result;
|
7256 | }
|
7257 | throw new Error("Unable to get ".concat(selector, " within: ").concat(this.html()));
|
7258 | };
|
7259 | BaseWrapper.prototype.getComponent = function (selector) {
|
7260 | var result = this.findComponent(selector);
|
7261 | if (result.exists()) {
|
7262 | return result;
|
7263 | }
|
7264 | var message = 'Unable to get ';
|
7265 | if (typeof selector === 'string') {
|
7266 | message += "component with selector ".concat(selector);
|
7267 | }
|
7268 | else if ('name' in selector) {
|
7269 | message += "component with name ".concat(selector.name);
|
7270 | }
|
7271 | else if ('ref' in selector) {
|
7272 | message += "component with ref ".concat(selector.ref);
|
7273 | }
|
7274 | else {
|
7275 | message += 'specified component';
|
7276 | }
|
7277 | message += " within: ".concat(this.html());
|
7278 | throw new Error(message);
|
7279 | };
|
7280 | BaseWrapper.prototype.isVisible = function () {
|
7281 | return isElement(this.element) && isElementVisible(this.element);
|
7282 | };
|
7283 | BaseWrapper.prototype.trigger = function (eventString, options) {
|
7284 | return __awaiter(this, void 0, void 0, function () {
|
7285 | var event_1;
|
7286 | return __generator(this, function (_a) {
|
7287 | if (options && options['target']) {
|
7288 | throw Error("[vue-test-utils]: you cannot set the target value of an event. See the notes section " +
|
7289 | "of the docs for more details\u2014" +
|
7290 | "https://vue-test-utils.vuejs.org/api/wrapper/trigger.html");
|
7291 | }
|
7292 | if (this.element && !this.isDisabled()) {
|
7293 | event_1 = createDOMEvent(eventString, options);
|
7294 |
|
7295 |
|
7296 |
|
7297 |
|
7298 |
|
7299 |
|
7300 | event_1._vts = Date.now() + 1;
|
7301 | this.element.dispatchEvent(event_1);
|
7302 | }
|
7303 | return [2 , nextTick()];
|
7304 | });
|
7305 | });
|
7306 | };
|
7307 | return BaseWrapper;
|
7308 | }());
|
7309 |
|
7310 | var DOMWrapper = (function (_super) {
|
7311 | __extends(DOMWrapper, _super);
|
7312 | function DOMWrapper(element) {
|
7313 | var _this = this;
|
7314 | if (!element) {
|
7315 | return createWrapperError('DOMWrapper');
|
7316 | }
|
7317 | _this = _super.call(this, element) || this;
|
7318 |
|
7319 | config.plugins.DOMWrapper.extend(_this);
|
7320 | return _this;
|
7321 | }
|
7322 | DOMWrapper.prototype.getRootNodes = function () {
|
7323 | return [this.wrapperElement];
|
7324 | };
|
7325 | DOMWrapper.prototype.getCurrentComponent = function () {
|
7326 | var _a;
|
7327 | var component = this.element.__vueParentComponent;
|
7328 | while (((_a = component === null || component === void 0 ? void 0 : component.parent) === null || _a === void 0 ? void 0 : _a.vnode.el) === this.element) {
|
7329 | component = component.parent;
|
7330 | }
|
7331 | return component;
|
7332 | };
|
7333 | DOMWrapper.prototype.find = function (selector) {
|
7334 | var result = _super.prototype.find.call(this, selector);
|
7335 | if (result.exists() && isRefSelector(selector)) {
|
7336 | return this.element.contains(result.element)
|
7337 | ? result
|
7338 | : createWrapperError('DOMWrapper');
|
7339 | }
|
7340 | return result;
|
7341 | };
|
7342 | DOMWrapper.prototype.findAll = function (selector) {
|
7343 | if (!(this.wrapperElement instanceof Element)) {
|
7344 | return [];
|
7345 | }
|
7346 | return Array.from(this.wrapperElement.querySelectorAll(selector), createDOMWrapper);
|
7347 | };
|
7348 | DOMWrapper.prototype.findAllComponents = function (selector) {
|
7349 | var _this = this;
|
7350 | var results = _super.prototype.findAllComponents.call(this, selector);
|
7351 | return results.filter(function (r) { return _this.element.contains(r.element); });
|
7352 | };
|
7353 | DOMWrapper.prototype.setChecked = function () {
|
7354 | return __awaiter(this, arguments, void 0, function (checked) {
|
7355 | var element, type;
|
7356 | if (checked === void 0) { checked = true; }
|
7357 | return __generator(this, function (_a) {
|
7358 | element = this.element;
|
7359 | type = this.attributes().type;
|
7360 | if (type === 'radio' && !checked) {
|
7361 | throw Error("wrapper.setChecked() cannot be called with parameter false on a '<input type=\"radio\" /> element.");
|
7362 | }
|
7363 |
|
7364 |
|
7365 |
|
7366 |
|
7367 | if (checked === element.checked) {
|
7368 | return [2 ];
|
7369 | }
|
7370 | element.checked = checked;
|
7371 | this.trigger('input');
|
7372 | return [2 , this.trigger('change')];
|
7373 | });
|
7374 | });
|
7375 | };
|
7376 | DOMWrapper.prototype.setValue = function (value) {
|
7377 | var element = this.element;
|
7378 | var tagName = element.tagName;
|
7379 | var type = this.attributes().type;
|
7380 | if (tagName === 'OPTION') {
|
7381 | this.setSelected();
|
7382 | return Promise.resolve();
|
7383 | }
|
7384 | else if (tagName === 'INPUT' && type === 'checkbox') {
|
7385 | return this.setChecked(value);
|
7386 | }
|
7387 | else if (tagName === 'INPUT' && type === 'radio') {
|
7388 | return this.setChecked(value);
|
7389 | }
|
7390 | else if (tagName === 'SELECT') {
|
7391 | if (Array.isArray(value)) {
|
7392 | var selectElement = element;
|
7393 | for (var i = 0; i < selectElement.options.length; i++) {
|
7394 | var option = selectElement.options[i];
|
7395 | option.selected = value.includes(option.value);
|
7396 | }
|
7397 | }
|
7398 | else {
|
7399 | element.value = value;
|
7400 | }
|
7401 | this.trigger('input');
|
7402 | return this.trigger('change');
|
7403 | }
|
7404 | else if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
|
7405 | element.value = value;
|
7406 | this.trigger('input');
|
7407 |
|
7408 | return this.trigger('change');
|
7409 | }
|
7410 | else {
|
7411 | throw Error("wrapper.setValue() cannot be called on ".concat(tagName));
|
7412 | }
|
7413 | };
|
7414 | DOMWrapper.prototype.setSelected = function () {
|
7415 | var element = this.element;
|
7416 | if (element.selected) {
|
7417 | return;
|
7418 | }
|
7419 |
|
7420 |
|
7421 | element.selected = true;
|
7422 | var parentElement = element.parentElement;
|
7423 | if (parentElement.tagName === 'OPTGROUP') {
|
7424 | parentElement = parentElement.parentElement;
|
7425 | }
|
7426 | var parentWrapper = new DOMWrapper(parentElement);
|
7427 | parentWrapper.trigger('input');
|
7428 | return parentWrapper.trigger('change');
|
7429 | };
|
7430 | return DOMWrapper;
|
7431 | }(BaseWrapper));
|
7432 | registerFactory(WrapperType.DOMWrapper, function (element) { return new DOMWrapper(element); });
|
7433 |
|
7434 | function getRootNodes(vnode) {
|
7435 | if (vnode.shapeFlag & 1 ) {
|
7436 | return [vnode.el];
|
7437 | }
|
7438 | else if (vnode.shapeFlag & 6 ) {
|
7439 | var subTree = vnode.component.subTree;
|
7440 | return getRootNodes(subTree);
|
7441 | }
|
7442 | else if (vnode.shapeFlag & 128 ) {
|
7443 | return getRootNodes(vnode.suspense.activeBranch);
|
7444 | }
|
7445 | else if (vnode.shapeFlag &
|
7446 | (8 | 64 )) {
|
7447 |
|
7448 | var result = [vnode.el];
|
7449 | if (vnode.anchor) {
|
7450 | var currentNode = result[0].nextSibling;
|
7451 | while (currentNode && currentNode.previousSibling !== vnode.anchor) {
|
7452 | result.push(currentNode);
|
7453 | currentNode = currentNode.nextSibling;
|
7454 | }
|
7455 | }
|
7456 | return result;
|
7457 | }
|
7458 | else if (vnode.shapeFlag & 16 ) {
|
7459 | var children = vnode.children.flat();
|
7460 | return children
|
7461 | .flatMap(function (vnode) { return getRootNodes(vnode); })
|
7462 | .filter(isNotNullOrUndefined);
|
7463 | }
|
7464 |
|
7465 |
|
7466 |
|
7467 |
|
7468 | return [];
|
7469 | }
|
7470 |
|
7471 | var events = {};
|
7472 | function emitted(vm, eventName) {
|
7473 | var cid = vm.$.uid;
|
7474 | var vmEvents = events[cid] || {};
|
7475 | if (eventName) {
|
7476 | return vmEvents ? vmEvents[eventName] : undefined;
|
7477 | }
|
7478 | return vmEvents;
|
7479 | }
|
7480 | var attachEmitListener = function () {
|
7481 | var target = getGlobalThis$1();
|
7482 |
|
7483 | if (target.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
|
7484 | var _emit_1 = target.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit;
|
7485 | target.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit = function (eventType) {
|
7486 | var payload = [];
|
7487 | for (var _i = 1; _i < arguments.length; _i++) {
|
7488 | payload[_i - 1] = arguments[_i];
|
7489 | }
|
7490 | _emit_1.call.apply(_emit_1, __spreadArray([target.__VUE_DEVTOOLS_GLOBAL_HOOK__, eventType], payload, false));
|
7491 | captureDevtoolsVueComponentEmitEvent(eventType, payload);
|
7492 | };
|
7493 | }
|
7494 | else {
|
7495 |
|
7496 | setDevtoolsHook(createDevTools(), {});
|
7497 | }
|
7498 | };
|
7499 | function captureDevtoolsVueComponentEmitEvent(eventType, payload) {
|
7500 | if (eventType === "component:emit" ) {
|
7501 | payload[0]; var componentVM = payload[1], event_1 = payload[2], eventArgs = payload[3];
|
7502 | recordEvent(componentVM, event_1, eventArgs);
|
7503 | }
|
7504 | }
|
7505 |
|
7506 | function createDevTools() {
|
7507 | return {
|
7508 | emit: function (eventType) {
|
7509 | var payload = [];
|
7510 | for (var _i = 1; _i < arguments.length; _i++) {
|
7511 | payload[_i - 1] = arguments[_i];
|
7512 | }
|
7513 | captureDevtoolsVueComponentEmitEvent(eventType, payload);
|
7514 | }
|
7515 | };
|
7516 | }
|
7517 | var recordEvent = function (vm, event, args) {
|
7518 |
|
7519 | var wrapperVm = vm;
|
7520 | while (typeof (wrapperVm === null || wrapperVm === void 0 ? void 0 : wrapperVm.type) === 'function')
|
7521 | wrapperVm = wrapperVm.parent;
|
7522 | var cid = wrapperVm.uid;
|
7523 | if (!(cid in events)) {
|
7524 | events[cid] = {};
|
7525 | }
|
7526 | if (!(event in events[cid])) {
|
7527 | events[cid][event] = [];
|
7528 | }
|
7529 |
|
7530 | events[cid][event].push(args);
|
7531 | };
|
7532 | var removeEventHistory = function (vm) {
|
7533 | var cid = vm.$.uid;
|
7534 | delete events[cid];
|
7535 | };
|
7536 |
|
7537 |
|
7538 |
|
7539 |
|
7540 |
|
7541 |
|
7542 | function createVMProxy(vm, setupState) {
|
7543 | return new Proxy(vm, {
|
7544 | get: function (vm, key, receiver) {
|
7545 | if (vm.$.exposed && vm.$.exposeProxy && key in vm.$.exposeProxy) {
|
7546 |
|
7547 | return Reflect.get(vm.$.exposeProxy, key, receiver);
|
7548 | }
|
7549 | else if (key in setupState) {
|
7550 |
|
7551 | return Reflect.get(setupState, key, receiver);
|
7552 | }
|
7553 | else if (key in vm.$.appContext.config.globalProperties) {
|
7554 |
|
7555 | return Reflect.get(vm.$.appContext.config.globalProperties, key, receiver);
|
7556 | }
|
7557 | else {
|
7558 |
|
7559 |
|
7560 | return vm.$.ctx[key];
|
7561 | }
|
7562 | },
|
7563 | set: function (vm, key, value, receiver) {
|
7564 | if (key in setupState) {
|
7565 | return Reflect.set(setupState, key, value, receiver);
|
7566 | }
|
7567 | else {
|
7568 | return Reflect.set(vm, key, value, receiver);
|
7569 | }
|
7570 | },
|
7571 | has: function (vm, property) {
|
7572 | return Reflect.has(setupState, property) || Reflect.has(vm, property);
|
7573 | },
|
7574 | defineProperty: function (vm, key, attributes) {
|
7575 | if (key in setupState) {
|
7576 | return Reflect.defineProperty(setupState, key, attributes);
|
7577 | }
|
7578 | else {
|
7579 | return Reflect.defineProperty(vm, key, attributes);
|
7580 | }
|
7581 | },
|
7582 | getOwnPropertyDescriptor: function (vm, property) {
|
7583 | if (property in setupState) {
|
7584 | return Reflect.getOwnPropertyDescriptor(setupState, property);
|
7585 | }
|
7586 | else {
|
7587 | return Reflect.getOwnPropertyDescriptor(vm, property);
|
7588 | }
|
7589 | },
|
7590 | deleteProperty: function (vm, property) {
|
7591 | if (property in setupState) {
|
7592 | return Reflect.deleteProperty(setupState, property);
|
7593 | }
|
7594 | else {
|
7595 | return Reflect.deleteProperty(vm, property);
|
7596 | }
|
7597 | }
|
7598 | });
|
7599 | }
|
7600 | var VueWrapper = (function (_super) {
|
7601 | __extends(VueWrapper, _super);
|
7602 | function VueWrapper(app, vm, setProps) {
|
7603 | var _this = _super.call(this, vm === null || vm === void 0 ? void 0 : vm.$el) || this;
|
7604 | _this.cleanUpCallbacks = [];
|
7605 | _this.__app = app;
|
7606 |
|
7607 | _this.rootVM = vm === null || vm === void 0 ? void 0 : vm.$root;
|
7608 |
|
7609 |
|
7610 |
|
7611 |
|
7612 |
|
7613 |
|
7614 |
|
7615 |
|
7616 | if (hasSetupState(vm)) {
|
7617 | _this.componentVM = createVMProxy(vm, vm.$.setupState);
|
7618 | }
|
7619 | else {
|
7620 | _this.componentVM = vm;
|
7621 | }
|
7622 | _this.__setProps = setProps;
|
7623 | _this.attachNativeEventListener();
|
7624 | config.plugins.VueWrapper.extend(_this);
|
7625 | return _this;
|
7626 | }
|
7627 | Object.defineProperty(VueWrapper.prototype, "hasMultipleRoots", {
|
7628 | get: function () {
|
7629 |
|
7630 |
|
7631 |
|
7632 |
|
7633 | var checkTree = function (subTree) {
|
7634 | var _a;
|
7635 |
|
7636 | if (subTree.shapeFlag === 16 )
|
7637 | return true;
|
7638 | if (subTree.shapeFlag & 4 ||
|
7639 | subTree.shapeFlag & 2 ) {
|
7640 |
|
7641 | if ((_a = subTree.component) === null || _a === void 0 ? void 0 : _a.subTree) {
|
7642 | return checkTree(subTree.component.subTree);
|
7643 | }
|
7644 |
|
7645 | if (subTree.shapeFlag & 16 ) {
|
7646 | return true;
|
7647 | }
|
7648 | }
|
7649 | return false;
|
7650 | };
|
7651 | return checkTree(this.vm.$.subTree);
|
7652 | },
|
7653 | enumerable: false,
|
7654 | configurable: true
|
7655 | });
|
7656 | VueWrapper.prototype.getRootNodes = function () {
|
7657 | return getRootNodes(this.vm.$.vnode);
|
7658 | };
|
7659 | Object.defineProperty(VueWrapper.prototype, "parentElement", {
|
7660 | get: function () {
|
7661 | return this.vm.$el.parentElement;
|
7662 | },
|
7663 | enumerable: false,
|
7664 | configurable: true
|
7665 | });
|
7666 | VueWrapper.prototype.getCurrentComponent = function () {
|
7667 | return this.vm.$;
|
7668 | };
|
7669 | VueWrapper.prototype.exists = function () {
|
7670 | return !this.getCurrentComponent().isUnmounted;
|
7671 | };
|
7672 | VueWrapper.prototype.findAll = function (selector) {
|
7673 | return this.findAllDOMElements(selector).map(createDOMWrapper);
|
7674 | };
|
7675 | VueWrapper.prototype.attachNativeEventListener = function () {
|
7676 | var vm = this.vm;
|
7677 | if (!vm)
|
7678 | return;
|
7679 | var emits = vm.$options.emits
|
7680 | ?
|
7681 | Array.isArray(vm.$options.emits)
|
7682 | ?
|
7683 | vm.$options.emits
|
7684 | :
|
7685 |
|
7686 | Object.keys(vm.$options.emits)
|
7687 | : [];
|
7688 | var elementRoots = this.getRootNodes().filter(function (node) { return node instanceof Element; });
|
7689 | if (elementRoots.length !== 1) {
|
7690 | return;
|
7691 | }
|
7692 | var element = elementRoots[0];
|
7693 | var _loop_1 = function (eventName) {
|
7694 |
|
7695 |
|
7696 |
|
7697 | if (emits.includes(eventName))
|
7698 | return "continue";
|
7699 | var eventListener = function () {
|
7700 | var args = [];
|
7701 | for (var _i = 0; _i < arguments.length; _i++) {
|
7702 | args[_i] = arguments[_i];
|
7703 | }
|
7704 | recordEvent(vm.$, eventName, args);
|
7705 | };
|
7706 | element.addEventListener(eventName, eventListener);
|
7707 | this_1.cleanUpCallbacks.push(function () {
|
7708 | element.removeEventListener(eventName, eventListener);
|
7709 | });
|
7710 | };
|
7711 | var this_1 = this;
|
7712 | for (var _i = 0, _a = Object.keys(domEvents); _i < _a.length; _i++) {
|
7713 | var eventName = _a[_i];
|
7714 | _loop_1(eventName);
|
7715 | }
|
7716 | };
|
7717 | Object.defineProperty(VueWrapper.prototype, "element", {
|
7718 | get: function () {
|
7719 |
|
7720 | return this.hasMultipleRoots ? this.parentElement : this.vm.$el;
|
7721 | },
|
7722 | enumerable: false,
|
7723 | configurable: true
|
7724 | });
|
7725 | Object.defineProperty(VueWrapper.prototype, "vm", {
|
7726 | get: function () {
|
7727 | return this.componentVM;
|
7728 | },
|
7729 | enumerable: false,
|
7730 | configurable: true
|
7731 | });
|
7732 | VueWrapper.prototype.props = function (selector) {
|
7733 | var props = this.componentVM.$props;
|
7734 | return selector ? props[selector] : props;
|
7735 | };
|
7736 | VueWrapper.prototype.emitted = function (eventName) {
|
7737 | return emitted(this.vm, eventName);
|
7738 | };
|
7739 | VueWrapper.prototype.isVisible = function () {
|
7740 | var domWrapper = createDOMWrapper(this.element);
|
7741 | return domWrapper.isVisible();
|
7742 | };
|
7743 | VueWrapper.prototype.setData = function (data) {
|
7744 | mergeDeep(this.componentVM.$data, data);
|
7745 | return nextTick();
|
7746 | };
|
7747 | VueWrapper.prototype.setProps = function (props) {
|
7748 |
|
7749 | if (this.vm.$parent !== this.rootVM || !this.__setProps) {
|
7750 | throw Error('You can only use setProps on your mounted component');
|
7751 | }
|
7752 | this.__setProps(props);
|
7753 | return nextTick();
|
7754 | };
|
7755 | VueWrapper.prototype.setValue = function (value, prop) {
|
7756 | var propEvent = prop || 'modelValue';
|
7757 | this.vm.$emit("update:".concat(propEvent), value);
|
7758 | return this.vm.$nextTick();
|
7759 | };
|
7760 | VueWrapper.prototype.unmount = function () {
|
7761 |
|
7762 | if (!this.__app) {
|
7763 | throw new Error("wrapper.unmount() can only be called by the root wrapper");
|
7764 | }
|
7765 |
|
7766 | removeEventHistory(this.vm);
|
7767 | this.cleanUpCallbacks.forEach(function (cb) { return cb(); });
|
7768 | this.cleanUpCallbacks = [];
|
7769 | this.__app.unmount();
|
7770 | };
|
7771 | return VueWrapper;
|
7772 | }(BaseWrapper));
|
7773 | registerFactory(WrapperType.VueWrapper, function (app, vm, setProps) { return new VueWrapper(app, vm, setProps); });
|
7774 |
|
7775 |
|
7776 |
|
7777 |
|
7778 |
|
7779 |
|
7780 |
|
7781 |
|
7782 | function makeMap(str, expectsLowerCase) {
|
7783 | const set = new Set(str.split(","));
|
7784 | return expectsLowerCase ? (val) => set.has(val.toLowerCase()) : (val) => set.has(val);
|
7785 | }
|
7786 |
|
7787 | const EMPTY_OBJ = Object.freeze({}) ;
|
7788 | const NOOP = () => {
|
7789 | };
|
7790 | const NO = () => false;
|
7791 | const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 &&
|
7792 | (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
|
7793 | const extend = Object.assign;
|
7794 | const isArray = Array.isArray;
|
7795 | const isFunction = (val) => typeof val === "function";
|
7796 | const isString = (val) => typeof val === "string";
|
7797 | const isSymbol = (val) => typeof val === "symbol";
|
7798 | const isObject = (val) => val !== null && typeof val === "object";
|
7799 | const isPromise = (val) => {
|
7800 | return (isObject(val) || isFunction(val)) && isFunction(val.then) && isFunction(val.catch);
|
7801 | };
|
7802 | const isReservedProp = makeMap(
|
7803 |
|
7804 | ",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"
|
7805 | );
|
7806 | const isBuiltInDirective = makeMap(
|
7807 | "bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"
|
7808 | );
|
7809 | const cacheStringFunction = (fn) => {
|
7810 | const cache = Object.create(null);
|
7811 | return (str) => {
|
7812 | const hit = cache[str];
|
7813 | return hit || (cache[str] = fn(str));
|
7814 | };
|
7815 | };
|
7816 | const camelizeRE = /-(\w)/g;
|
7817 | const camelize = cacheStringFunction((str) => {
|
7818 | return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
7819 | });
|
7820 | const hyphenateRE = /\B([A-Z])/g;
|
7821 | const hyphenate = cacheStringFunction(
|
7822 | (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
|
7823 | );
|
7824 | const capitalize = cacheStringFunction((str) => {
|
7825 | return str.charAt(0).toUpperCase() + str.slice(1);
|
7826 | });
|
7827 | const toHandlerKey = cacheStringFunction((str) => {
|
7828 | const s = str ? `on${capitalize(str)}` : ``;
|
7829 | return s;
|
7830 | });
|
7831 | let _globalThis;
|
7832 | const getGlobalThis = () => {
|
7833 | return _globalThis || (_globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {});
|
7834 | };
|
7835 | const PatchFlagNames = {
|
7836 | [1]: `TEXT`,
|
7837 | [2]: `CLASS`,
|
7838 | [4]: `STYLE`,
|
7839 | [8]: `PROPS`,
|
7840 | [16]: `FULL_PROPS`,
|
7841 | [32]: `NEED_HYDRATION`,
|
7842 | [64]: `STABLE_FRAGMENT`,
|
7843 | [128]: `KEYED_FRAGMENT`,
|
7844 | [256]: `UNKEYED_FRAGMENT`,
|
7845 | [512]: `NEED_PATCH`,
|
7846 | [1024]: `DYNAMIC_SLOTS`,
|
7847 | [2048]: `DEV_ROOT_FRAGMENT`,
|
7848 | [-1]: `HOISTED`,
|
7849 | [-2]: `BAIL`
|
7850 | };
|
7851 | const slotFlagsText = {
|
7852 | [1]: "STABLE",
|
7853 | [2]: "DYNAMIC",
|
7854 | [3]: "FORWARDED"
|
7855 | };
|
7856 |
|
7857 | function normalizeStyle(value) {
|
7858 | if (isArray(value)) {
|
7859 | const res = {};
|
7860 | for (let i = 0; i < value.length; i++) {
|
7861 | const item = value[i];
|
7862 | const normalized = isString(item) ? parseStringStyle(item) : normalizeStyle(item);
|
7863 | if (normalized) {
|
7864 | for (const key in normalized) {
|
7865 | res[key] = normalized[key];
|
7866 | }
|
7867 | }
|
7868 | }
|
7869 | return res;
|
7870 | } else if (isString(value) || isObject(value)) {
|
7871 | return value;
|
7872 | }
|
7873 | }
|
7874 | const listDelimiterRE = /;(?![^(]*\))/g;
|
7875 | const propertyDelimiterRE = /:([^]+)/;
|
7876 | const styleCommentRE = /\/\*[^]*?\*\//g;
|
7877 | function parseStringStyle(cssText) {
|
7878 | const ret = {};
|
7879 | cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
|
7880 | if (item) {
|
7881 | const tmp = item.split(propertyDelimiterRE);
|
7882 | tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
|
7883 | }
|
7884 | });
|
7885 | return ret;
|
7886 | }
|
7887 | function stringifyStyle(styles) {
|
7888 | let ret = "";
|
7889 | if (!styles || isString(styles)) {
|
7890 | return ret;
|
7891 | }
|
7892 | for (const key in styles) {
|
7893 | const value = styles[key];
|
7894 | const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
|
7895 | if (isString(value) || typeof value === "number") {
|
7896 | ret += `${normalizedKey}:${value};`;
|
7897 | }
|
7898 | }
|
7899 | return ret;
|
7900 | }
|
7901 | function normalizeClass(value) {
|
7902 | let res = "";
|
7903 | if (isString(value)) {
|
7904 | res = value;
|
7905 | } else if (isArray(value)) {
|
7906 | for (let i = 0; i < value.length; i++) {
|
7907 | const normalized = normalizeClass(value[i]);
|
7908 | if (normalized) {
|
7909 | res += normalized + " ";
|
7910 | }
|
7911 | }
|
7912 | } else if (isObject(value)) {
|
7913 | for (const name in value) {
|
7914 | if (value[name]) {
|
7915 | res += name + " ";
|
7916 | }
|
7917 | }
|
7918 | }
|
7919 | return res.trim();
|
7920 | }
|
7921 |
|
7922 | const HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot";
|
7923 | const SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
|
7924 | const MATH_TAGS = "annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics";
|
7925 | const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
|
7926 | const isHTMLTag = makeMap(HTML_TAGS);
|
7927 | const isSVGTag = makeMap(SVG_TAGS);
|
7928 | const isMathMLTag = makeMap(MATH_TAGS);
|
7929 | const isVoidTag = makeMap(VOID_TAGS);
|
7930 |
|
7931 | const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
|
7932 | const isBooleanAttr = makeMap(
|
7933 | specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`
|
7934 | );
|
7935 | function includeBooleanAttr(value) {
|
7936 | return !!value || value === "";
|
7937 | }
|
7938 | const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/;
|
7939 | const attrValidationCache = {};
|
7940 | function isSSRSafeAttrName(name) {
|
7941 | if (attrValidationCache.hasOwnProperty(name)) {
|
7942 | return attrValidationCache[name];
|
7943 | }
|
7944 | const isUnsafe = unsafeAttrCharRE.test(name);
|
7945 | if (isUnsafe) {
|
7946 | console.error(`unsafe attribute name: ${name}`);
|
7947 | }
|
7948 | return attrValidationCache[name] = !isUnsafe;
|
7949 | }
|
7950 | const propsToAttrMap = {
|
7951 | acceptCharset: "accept-charset",
|
7952 | className: "class",
|
7953 | htmlFor: "for",
|
7954 | httpEquiv: "http-equiv"
|
7955 | };
|
7956 | function isRenderableAttrValue(value) {
|
7957 | if (value == null) {
|
7958 | return false;
|
7959 | }
|
7960 | const type = typeof value;
|
7961 | return type === "string" || type === "number" || type === "boolean";
|
7962 | }
|
7963 |
|
7964 | const escapeRE = /["'&<>]/;
|
7965 | function escapeHtml(string) {
|
7966 | const str = "" + string;
|
7967 | const match = escapeRE.exec(str);
|
7968 | if (!match) {
|
7969 | return str;
|
7970 | }
|
7971 | let html = "";
|
7972 | let escaped;
|
7973 | let index;
|
7974 | let lastIndex = 0;
|
7975 | for (index = match.index; index < str.length; index++) {
|
7976 | switch (str.charCodeAt(index)) {
|
7977 | case 34:
|
7978 | escaped = """;
|
7979 | break;
|
7980 | case 38:
|
7981 | escaped = "&";
|
7982 | break;
|
7983 | case 39:
|
7984 | escaped = "'";
|
7985 | break;
|
7986 | case 60:
|
7987 | escaped = "<";
|
7988 | break;
|
7989 | case 62:
|
7990 | escaped = ">";
|
7991 | break;
|
7992 | default:
|
7993 | continue;
|
7994 | }
|
7995 | if (lastIndex !== index) {
|
7996 | html += str.slice(lastIndex, index);
|
7997 | }
|
7998 | lastIndex = index + 1;
|
7999 | html += escaped;
|
8000 | }
|
8001 | return lastIndex !== index ? html + str.slice(lastIndex, index) : html;
|
8002 | }
|
8003 | const commentStripRE = /^-?>|<!--|-->|--!>|<!-$/g;
|
8004 | function escapeHtmlComment(src) {
|
8005 | return src.replace(commentStripRE, "");
|
8006 | }
|
8007 |
|
8008 |
|
8009 |
|
8010 |
|
8011 |
|
8012 |
|
8013 |
|
8014 | const FRAGMENT = Symbol(`Fragment` );
|
8015 | const TELEPORT = Symbol(`Teleport` );
|
8016 | const SUSPENSE = Symbol(`Suspense` );
|
8017 | const KEEP_ALIVE = Symbol(`KeepAlive` );
|
8018 | const BASE_TRANSITION = Symbol(`BaseTransition` );
|
8019 | const OPEN_BLOCK = Symbol(`openBlock` );
|
8020 | const CREATE_BLOCK = Symbol(`createBlock` );
|
8021 | const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
|
8022 | const CREATE_VNODE = Symbol(`createVNode` );
|
8023 | const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
|
8024 | const CREATE_COMMENT = Symbol(`createCommentVNode` );
|
8025 | const CREATE_TEXT = Symbol(`createTextVNode` );
|
8026 | const CREATE_STATIC = Symbol(`createStaticVNode` );
|
8027 | const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
|
8028 | const RESOLVE_DYNAMIC_COMPONENT = Symbol(
|
8029 | `resolveDynamicComponent`
|
8030 | );
|
8031 | const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
|
8032 | const RESOLVE_FILTER = Symbol(`resolveFilter` );
|
8033 | const WITH_DIRECTIVES = Symbol(`withDirectives` );
|
8034 | const RENDER_LIST = Symbol(`renderList` );
|
8035 | const RENDER_SLOT = Symbol(`renderSlot` );
|
8036 | const CREATE_SLOTS = Symbol(`createSlots` );
|
8037 | const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
|
8038 | const MERGE_PROPS = Symbol(`mergeProps` );
|
8039 | const NORMALIZE_CLASS = Symbol(`normalizeClass` );
|
8040 | const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
|
8041 | const NORMALIZE_PROPS = Symbol(`normalizeProps` );
|
8042 | const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
|
8043 | const TO_HANDLERS = Symbol(`toHandlers` );
|
8044 | const CAMELIZE = Symbol(`camelize` );
|
8045 | const CAPITALIZE = Symbol(`capitalize` );
|
8046 | const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
|
8047 | const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
|
8048 | const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
|
8049 | const POP_SCOPE_ID = Symbol(`popScopeId` );
|
8050 | const WITH_CTX = Symbol(`withCtx` );
|
8051 | const UNREF = Symbol(`unref` );
|
8052 | const IS_REF = Symbol(`isRef` );
|
8053 | const WITH_MEMO = Symbol(`withMemo` );
|
8054 | const IS_MEMO_SAME = Symbol(`isMemoSame` );
|
8055 | const helperNameMap = {
|
8056 | [FRAGMENT]: `Fragment`,
|
8057 | [TELEPORT]: `Teleport`,
|
8058 | [SUSPENSE]: `Suspense`,
|
8059 | [KEEP_ALIVE]: `KeepAlive`,
|
8060 | [BASE_TRANSITION]: `BaseTransition`,
|
8061 | [OPEN_BLOCK]: `openBlock`,
|
8062 | [CREATE_BLOCK]: `createBlock`,
|
8063 | [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
|
8064 | [CREATE_VNODE]: `createVNode`,
|
8065 | [CREATE_ELEMENT_VNODE]: `createElementVNode`,
|
8066 | [CREATE_COMMENT]: `createCommentVNode`,
|
8067 | [CREATE_TEXT]: `createTextVNode`,
|
8068 | [CREATE_STATIC]: `createStaticVNode`,
|
8069 | [RESOLVE_COMPONENT]: `resolveComponent`,
|
8070 | [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
|
8071 | [RESOLVE_DIRECTIVE]: `resolveDirective`,
|
8072 | [RESOLVE_FILTER]: `resolveFilter`,
|
8073 | [WITH_DIRECTIVES]: `withDirectives`,
|
8074 | [RENDER_LIST]: `renderList`,
|
8075 | [RENDER_SLOT]: `renderSlot`,
|
8076 | [CREATE_SLOTS]: `createSlots`,
|
8077 | [TO_DISPLAY_STRING]: `toDisplayString`,
|
8078 | [MERGE_PROPS]: `mergeProps`,
|
8079 | [NORMALIZE_CLASS]: `normalizeClass`,
|
8080 | [NORMALIZE_STYLE]: `normalizeStyle`,
|
8081 | [NORMALIZE_PROPS]: `normalizeProps`,
|
8082 | [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
|
8083 | [TO_HANDLERS]: `toHandlers`,
|
8084 | [CAMELIZE]: `camelize`,
|
8085 | [CAPITALIZE]: `capitalize`,
|
8086 | [TO_HANDLER_KEY]: `toHandlerKey`,
|
8087 | [SET_BLOCK_TRACKING]: `setBlockTracking`,
|
8088 | [PUSH_SCOPE_ID]: `pushScopeId`,
|
8089 | [POP_SCOPE_ID]: `popScopeId`,
|
8090 | [WITH_CTX]: `withCtx`,
|
8091 | [UNREF]: `unref`,
|
8092 | [IS_REF]: `isRef`,
|
8093 | [WITH_MEMO]: `withMemo`,
|
8094 | [IS_MEMO_SAME]: `isMemoSame`
|
8095 | };
|
8096 | function registerRuntimeHelpers(helpers) {
|
8097 | Object.getOwnPropertySymbols(helpers).forEach((s) => {
|
8098 | helperNameMap[s] = helpers[s];
|
8099 | });
|
8100 | }
|
8101 | const locStub = {
|
8102 | start: { line: 1, column: 1, offset: 0 },
|
8103 | end: { line: 1, column: 1, offset: 0 },
|
8104 | source: ""
|
8105 | };
|
8106 | function createRoot(children, source = "") {
|
8107 | return {
|
8108 | type: 0,
|
8109 | source,
|
8110 | children,
|
8111 | helpers: new Set(),
|
8112 | components: [],
|
8113 | directives: [],
|
8114 | hoists: [],
|
8115 | imports: [],
|
8116 | cached: 0,
|
8117 | temps: 0,
|
8118 | codegenNode: void 0,
|
8119 | loc: locStub
|
8120 | };
|
8121 | }
|
8122 | function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
|
8123 | if (context) {
|
8124 | if (isBlock) {
|
8125 | context.helper(OPEN_BLOCK);
|
8126 | context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
|
8127 | } else {
|
8128 | context.helper(getVNodeHelper(context.inSSR, isComponent));
|
8129 | }
|
8130 | if (directives) {
|
8131 | context.helper(WITH_DIRECTIVES);
|
8132 | }
|
8133 | }
|
8134 | return {
|
8135 | type: 13,
|
8136 | tag,
|
8137 | props,
|
8138 | children,
|
8139 | patchFlag,
|
8140 | dynamicProps,
|
8141 | directives,
|
8142 | isBlock,
|
8143 | disableTracking,
|
8144 | isComponent,
|
8145 | loc
|
8146 | };
|
8147 | }
|
8148 | function createArrayExpression(elements, loc = locStub) {
|
8149 | return {
|
8150 | type: 17,
|
8151 | loc,
|
8152 | elements
|
8153 | };
|
8154 | }
|
8155 | function createObjectExpression(properties, loc = locStub) {
|
8156 | return {
|
8157 | type: 15,
|
8158 | loc,
|
8159 | properties
|
8160 | };
|
8161 | }
|
8162 | function createObjectProperty(key, value) {
|
8163 | return {
|
8164 | type: 16,
|
8165 | loc: locStub,
|
8166 | key: isString(key) ? createSimpleExpression(key, true) : key,
|
8167 | value
|
8168 | };
|
8169 | }
|
8170 | function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
|
8171 | return {
|
8172 | type: 4,
|
8173 | loc,
|
8174 | content,
|
8175 | isStatic,
|
8176 | constType: isStatic ? 3 : constType
|
8177 | };
|
8178 | }
|
8179 | function createCompoundExpression(children, loc = locStub) {
|
8180 | return {
|
8181 | type: 8,
|
8182 | loc,
|
8183 | children
|
8184 | };
|
8185 | }
|
8186 | function createCallExpression(callee, args = [], loc = locStub) {
|
8187 | return {
|
8188 | type: 14,
|
8189 | loc,
|
8190 | callee,
|
8191 | arguments: args
|
8192 | };
|
8193 | }
|
8194 | function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
|
8195 | return {
|
8196 | type: 18,
|
8197 | params,
|
8198 | returns,
|
8199 | newline,
|
8200 | isSlot,
|
8201 | loc
|
8202 | };
|
8203 | }
|
8204 | function createConditionalExpression(test, consequent, alternate, newline = true) {
|
8205 | return {
|
8206 | type: 19,
|
8207 | test,
|
8208 | consequent,
|
8209 | alternate,
|
8210 | newline,
|
8211 | loc: locStub
|
8212 | };
|
8213 | }
|
8214 | function createCacheExpression(index, value, isVNode = false) {
|
8215 | return {
|
8216 | type: 20,
|
8217 | index,
|
8218 | value,
|
8219 | isVNode,
|
8220 | loc: locStub
|
8221 | };
|
8222 | }
|
8223 | function createBlockStatement(body) {
|
8224 | return {
|
8225 | type: 21,
|
8226 | body,
|
8227 | loc: locStub
|
8228 | };
|
8229 | }
|
8230 | function getVNodeHelper(ssr, isComponent) {
|
8231 | return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
|
8232 | }
|
8233 | function getVNodeBlockHelper(ssr, isComponent) {
|
8234 | return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
|
8235 | }
|
8236 | function convertToBlock(node, { helper, removeHelper, inSSR }) {
|
8237 | if (!node.isBlock) {
|
8238 | node.isBlock = true;
|
8239 | removeHelper(getVNodeHelper(inSSR, node.isComponent));
|
8240 | helper(OPEN_BLOCK);
|
8241 | helper(getVNodeBlockHelper(inSSR, node.isComponent));
|
8242 | }
|
8243 | }
|
8244 |
|
8245 | const defaultDelimitersOpen = new Uint8Array([123, 123]);
|
8246 | const defaultDelimitersClose = new Uint8Array([125, 125]);
|
8247 | function isTagStartChar(c) {
|
8248 | return c >= 97 && c <= 122 || c >= 65 && c <= 90;
|
8249 | }
|
8250 | function isWhitespace(c) {
|
8251 | return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
|
8252 | }
|
8253 | function isEndOfTagSection(c) {
|
8254 | return c === 47 || c === 62 || isWhitespace(c);
|
8255 | }
|
8256 | function toCharCodes(str) {
|
8257 | const ret = new Uint8Array(str.length);
|
8258 | for (let i = 0; i < str.length; i++) {
|
8259 | ret[i] = str.charCodeAt(i);
|
8260 | }
|
8261 | return ret;
|
8262 | }
|
8263 | const Sequences = {
|
8264 | Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
|
8265 |
|
8266 | CdataEnd: new Uint8Array([93, 93, 62]),
|
8267 |
|
8268 | CommentEnd: new Uint8Array([45, 45, 62]),
|
8269 |
|
8270 | ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
|
8271 |
|
8272 | StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
|
8273 |
|
8274 | TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
|
8275 |
|
8276 | TextareaEnd: new Uint8Array([
|
8277 | 60,
|
8278 | 47,
|
8279 | 116,
|
8280 | 101,
|
8281 | 120,
|
8282 | 116,
|
8283 | 97,
|
8284 | 114,
|
8285 | 101,
|
8286 | 97
|
8287 | ])
|
8288 |
|
8289 | };
|
8290 | class Tokenizer {
|
8291 | constructor(stack, cbs) {
|
8292 | this.stack = stack;
|
8293 | this.cbs = cbs;
|
8294 |
|
8295 | this.state = 1;
|
8296 |
|
8297 | this.buffer = "";
|
8298 |
|
8299 | this.sectionStart = 0;
|
8300 |
|
8301 | this.index = 0;
|
8302 |
|
8303 | this.entityStart = 0;
|
8304 |
|
8305 | this.baseState = 1;
|
8306 |
|
8307 | this.inRCDATA = false;
|
8308 |
|
8309 | this.inXML = false;
|
8310 |
|
8311 | this.inVPre = false;
|
8312 |
|
8313 | this.newlines = [];
|
8314 | this.mode = 0;
|
8315 | this.delimiterOpen = defaultDelimitersOpen;
|
8316 | this.delimiterClose = defaultDelimitersClose;
|
8317 | this.delimiterIndex = -1;
|
8318 | this.currentSequence = void 0;
|
8319 | this.sequenceIndex = 0;
|
8320 | }
|
8321 | get inSFCRoot() {
|
8322 | return this.mode === 2 && this.stack.length === 0;
|
8323 | }
|
8324 | reset() {
|
8325 | this.state = 1;
|
8326 | this.mode = 0;
|
8327 | this.buffer = "";
|
8328 | this.sectionStart = 0;
|
8329 | this.index = 0;
|
8330 | this.baseState = 1;
|
8331 | this.inRCDATA = false;
|
8332 | this.currentSequence = void 0;
|
8333 | this.newlines.length = 0;
|
8334 | this.delimiterOpen = defaultDelimitersOpen;
|
8335 | this.delimiterClose = defaultDelimitersClose;
|
8336 | }
|
8337 | |
8338 |
|
8339 |
|
8340 |
|
8341 |
|
8342 |
|
8343 | getPos(index) {
|
8344 | let line = 1;
|
8345 | let column = index + 1;
|
8346 | for (let i = this.newlines.length - 1; i >= 0; i--) {
|
8347 | const newlineIndex = this.newlines[i];
|
8348 | if (index > newlineIndex) {
|
8349 | line = i + 2;
|
8350 | column = index - newlineIndex;
|
8351 | break;
|
8352 | }
|
8353 | }
|
8354 | return {
|
8355 | column,
|
8356 | line,
|
8357 | offset: index
|
8358 | };
|
8359 | }
|
8360 | peek() {
|
8361 | return this.buffer.charCodeAt(this.index + 1);
|
8362 | }
|
8363 | stateText(c) {
|
8364 | if (c === 60) {
|
8365 | if (this.index > this.sectionStart) {
|
8366 | this.cbs.ontext(this.sectionStart, this.index);
|
8367 | }
|
8368 | this.state = 5;
|
8369 | this.sectionStart = this.index;
|
8370 | } else if (!this.inVPre && c === this.delimiterOpen[0]) {
|
8371 | this.state = 2;
|
8372 | this.delimiterIndex = 0;
|
8373 | this.stateInterpolationOpen(c);
|
8374 | }
|
8375 | }
|
8376 | stateInterpolationOpen(c) {
|
8377 | if (c === this.delimiterOpen[this.delimiterIndex]) {
|
8378 | if (this.delimiterIndex === this.delimiterOpen.length - 1) {
|
8379 | const start = this.index + 1 - this.delimiterOpen.length;
|
8380 | if (start > this.sectionStart) {
|
8381 | this.cbs.ontext(this.sectionStart, start);
|
8382 | }
|
8383 | this.state = 3;
|
8384 | this.sectionStart = start;
|
8385 | } else {
|
8386 | this.delimiterIndex++;
|
8387 | }
|
8388 | } else if (this.inRCDATA) {
|
8389 | this.state = 32;
|
8390 | this.stateInRCDATA(c);
|
8391 | } else {
|
8392 | this.state = 1;
|
8393 | this.stateText(c);
|
8394 | }
|
8395 | }
|
8396 | stateInterpolation(c) {
|
8397 | if (c === this.delimiterClose[0]) {
|
8398 | this.state = 4;
|
8399 | this.delimiterIndex = 0;
|
8400 | this.stateInterpolationClose(c);
|
8401 | }
|
8402 | }
|
8403 | stateInterpolationClose(c) {
|
8404 | if (c === this.delimiterClose[this.delimiterIndex]) {
|
8405 | if (this.delimiterIndex === this.delimiterClose.length - 1) {
|
8406 | this.cbs.oninterpolation(this.sectionStart, this.index + 1);
|
8407 | if (this.inRCDATA) {
|
8408 | this.state = 32;
|
8409 | } else {
|
8410 | this.state = 1;
|
8411 | }
|
8412 | this.sectionStart = this.index + 1;
|
8413 | } else {
|
8414 | this.delimiterIndex++;
|
8415 | }
|
8416 | } else {
|
8417 | this.state = 3;
|
8418 | this.stateInterpolation(c);
|
8419 | }
|
8420 | }
|
8421 | stateSpecialStartSequence(c) {
|
8422 | const isEnd = this.sequenceIndex === this.currentSequence.length;
|
8423 | const isMatch = isEnd ? (
|
8424 |
|
8425 | isEndOfTagSection(c)
|
8426 | ) : (
|
8427 |
|
8428 | (c | 32) === this.currentSequence[this.sequenceIndex]
|
8429 | );
|
8430 | if (!isMatch) {
|
8431 | this.inRCDATA = false;
|
8432 | } else if (!isEnd) {
|
8433 | this.sequenceIndex++;
|
8434 | return;
|
8435 | }
|
8436 | this.sequenceIndex = 0;
|
8437 | this.state = 6;
|
8438 | this.stateInTagName(c);
|
8439 | }
|
8440 |
|
8441 | stateInRCDATA(c) {
|
8442 | if (this.sequenceIndex === this.currentSequence.length) {
|
8443 | if (c === 62 || isWhitespace(c)) {
|
8444 | const endOfText = this.index - this.currentSequence.length;
|
8445 | if (this.sectionStart < endOfText) {
|
8446 | const actualIndex = this.index;
|
8447 | this.index = endOfText;
|
8448 | this.cbs.ontext(this.sectionStart, endOfText);
|
8449 | this.index = actualIndex;
|
8450 | }
|
8451 | this.sectionStart = endOfText + 2;
|
8452 | this.stateInClosingTagName(c);
|
8453 | this.inRCDATA = false;
|
8454 | return;
|
8455 | }
|
8456 | this.sequenceIndex = 0;
|
8457 | }
|
8458 | if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
|
8459 | this.sequenceIndex += 1;
|
8460 | } else if (this.sequenceIndex === 0) {
|
8461 | if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
|
8462 | if (c === this.delimiterOpen[0]) {
|
8463 | this.state = 2;
|
8464 | this.delimiterIndex = 0;
|
8465 | this.stateInterpolationOpen(c);
|
8466 | }
|
8467 | } else if (this.fastForwardTo(60)) {
|
8468 | this.sequenceIndex = 1;
|
8469 | }
|
8470 | } else {
|
8471 | this.sequenceIndex = Number(c === 60);
|
8472 | }
|
8473 | }
|
8474 | stateCDATASequence(c) {
|
8475 | if (c === Sequences.Cdata[this.sequenceIndex]) {
|
8476 | if (++this.sequenceIndex === Sequences.Cdata.length) {
|
8477 | this.state = 28;
|
8478 | this.currentSequence = Sequences.CdataEnd;
|
8479 | this.sequenceIndex = 0;
|
8480 | this.sectionStart = this.index + 1;
|
8481 | }
|
8482 | } else {
|
8483 | this.sequenceIndex = 0;
|
8484 | this.state = 23;
|
8485 | this.stateInDeclaration(c);
|
8486 | }
|
8487 | }
|
8488 | |
8489 |
|
8490 |
|
8491 |
|
8492 |
|
8493 |
|
8494 | fastForwardTo(c) {
|
8495 | while (++this.index < this.buffer.length) {
|
8496 | const cc = this.buffer.charCodeAt(this.index);
|
8497 | if (cc === 10) {
|
8498 | this.newlines.push(this.index);
|
8499 | }
|
8500 | if (cc === c) {
|
8501 | return true;
|
8502 | }
|
8503 | }
|
8504 | this.index = this.buffer.length - 1;
|
8505 | return false;
|
8506 | }
|
8507 | |
8508 |
|
8509 |
|
8510 |
|
8511 |
|
8512 |
|
8513 |
|
8514 |
|
8515 | stateInCommentLike(c) {
|
8516 | if (c === this.currentSequence[this.sequenceIndex]) {
|
8517 | if (++this.sequenceIndex === this.currentSequence.length) {
|
8518 | if (this.currentSequence === Sequences.CdataEnd) {
|
8519 | this.cbs.oncdata(this.sectionStart, this.index - 2);
|
8520 | } else {
|
8521 | this.cbs.oncomment(this.sectionStart, this.index - 2);
|
8522 | }
|
8523 | this.sequenceIndex = 0;
|
8524 | this.sectionStart = this.index + 1;
|
8525 | this.state = 1;
|
8526 | }
|
8527 | } else if (this.sequenceIndex === 0) {
|
8528 | if (this.fastForwardTo(this.currentSequence[0])) {
|
8529 | this.sequenceIndex = 1;
|
8530 | }
|
8531 | } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
|
8532 | this.sequenceIndex = 0;
|
8533 | }
|
8534 | }
|
8535 | startSpecial(sequence, offset) {
|
8536 | this.enterRCDATA(sequence, offset);
|
8537 | this.state = 31;
|
8538 | }
|
8539 | enterRCDATA(sequence, offset) {
|
8540 | this.inRCDATA = true;
|
8541 | this.currentSequence = sequence;
|
8542 | this.sequenceIndex = offset;
|
8543 | }
|
8544 | stateBeforeTagName(c) {
|
8545 | if (c === 33) {
|
8546 | this.state = 22;
|
8547 | this.sectionStart = this.index + 1;
|
8548 | } else if (c === 63) {
|
8549 | this.state = 24;
|
8550 | this.sectionStart = this.index + 1;
|
8551 | } else if (isTagStartChar(c)) {
|
8552 | this.sectionStart = this.index;
|
8553 | if (this.mode === 0) {
|
8554 | this.state = 6;
|
8555 | } else if (this.inSFCRoot) {
|
8556 | this.state = 34;
|
8557 | } else if (!this.inXML) {
|
8558 | if (c === 116) {
|
8559 | this.state = 30;
|
8560 | } else {
|
8561 | this.state = c === 115 ? 29 : 6;
|
8562 | }
|
8563 | } else {
|
8564 | this.state = 6;
|
8565 | }
|
8566 | } else if (c === 47) {
|
8567 | this.state = 8;
|
8568 | } else {
|
8569 | this.state = 1;
|
8570 | this.stateText(c);
|
8571 | }
|
8572 | }
|
8573 | stateInTagName(c) {
|
8574 | if (isEndOfTagSection(c)) {
|
8575 | this.handleTagName(c);
|
8576 | }
|
8577 | }
|
8578 | stateInSFCRootTagName(c) {
|
8579 | if (isEndOfTagSection(c)) {
|
8580 | const tag = this.buffer.slice(this.sectionStart, this.index);
|
8581 | if (tag !== "template") {
|
8582 | this.enterRCDATA(toCharCodes(`</` + tag), 0);
|
8583 | }
|
8584 | this.handleTagName(c);
|
8585 | }
|
8586 | }
|
8587 | handleTagName(c) {
|
8588 | this.cbs.onopentagname(this.sectionStart, this.index);
|
8589 | this.sectionStart = -1;
|
8590 | this.state = 11;
|
8591 | this.stateBeforeAttrName(c);
|
8592 | }
|
8593 | stateBeforeClosingTagName(c) {
|
8594 | if (isWhitespace(c)) ; else if (c === 62) {
|
8595 | {
|
8596 | this.cbs.onerr(14, this.index);
|
8597 | }
|
8598 | this.state = 1;
|
8599 | this.sectionStart = this.index + 1;
|
8600 | } else {
|
8601 | this.state = isTagStartChar(c) ? 9 : 27;
|
8602 | this.sectionStart = this.index;
|
8603 | }
|
8604 | }
|
8605 | stateInClosingTagName(c) {
|
8606 | if (c === 62 || isWhitespace(c)) {
|
8607 | this.cbs.onclosetag(this.sectionStart, this.index);
|
8608 | this.sectionStart = -1;
|
8609 | this.state = 10;
|
8610 | this.stateAfterClosingTagName(c);
|
8611 | }
|
8612 | }
|
8613 | stateAfterClosingTagName(c) {
|
8614 | if (c === 62) {
|
8615 | this.state = 1;
|
8616 | this.sectionStart = this.index + 1;
|
8617 | }
|
8618 | }
|
8619 | stateBeforeAttrName(c) {
|
8620 | if (c === 62) {
|
8621 | this.cbs.onopentagend(this.index);
|
8622 | if (this.inRCDATA) {
|
8623 | this.state = 32;
|
8624 | } else {
|
8625 | this.state = 1;
|
8626 | }
|
8627 | this.sectionStart = this.index + 1;
|
8628 | } else if (c === 47) {
|
8629 | this.state = 7;
|
8630 | if (this.peek() !== 62) {
|
8631 | this.cbs.onerr(22, this.index);
|
8632 | }
|
8633 | } else if (c === 60 && this.peek() === 47) {
|
8634 | this.cbs.onopentagend(this.index);
|
8635 | this.state = 5;
|
8636 | this.sectionStart = this.index;
|
8637 | } else if (!isWhitespace(c)) {
|
8638 | if (c === 61) {
|
8639 | this.cbs.onerr(
|
8640 | 19,
|
8641 | this.index
|
8642 | );
|
8643 | }
|
8644 | this.handleAttrStart(c);
|
8645 | }
|
8646 | }
|
8647 | handleAttrStart(c) {
|
8648 | if (c === 118 && this.peek() === 45) {
|
8649 | this.state = 13;
|
8650 | this.sectionStart = this.index;
|
8651 | } else if (c === 46 || c === 58 || c === 64 || c === 35) {
|
8652 | this.cbs.ondirname(this.index, this.index + 1);
|
8653 | this.state = 14;
|
8654 | this.sectionStart = this.index + 1;
|
8655 | } else {
|
8656 | this.state = 12;
|
8657 | this.sectionStart = this.index;
|
8658 | }
|
8659 | }
|
8660 | stateInSelfClosingTag(c) {
|
8661 | if (c === 62) {
|
8662 | this.cbs.onselfclosingtag(this.index);
|
8663 | this.state = 1;
|
8664 | this.sectionStart = this.index + 1;
|
8665 | this.inRCDATA = false;
|
8666 | } else if (!isWhitespace(c)) {
|
8667 | this.state = 11;
|
8668 | this.stateBeforeAttrName(c);
|
8669 | }
|
8670 | }
|
8671 | stateInAttrName(c) {
|
8672 | if (c === 61 || isEndOfTagSection(c)) {
|
8673 | this.cbs.onattribname(this.sectionStart, this.index);
|
8674 | this.handleAttrNameEnd(c);
|
8675 | } else if ((c === 34 || c === 39 || c === 60)) {
|
8676 | this.cbs.onerr(
|
8677 | 17,
|
8678 | this.index
|
8679 | );
|
8680 | }
|
8681 | }
|
8682 | stateInDirName(c) {
|
8683 | if (c === 61 || isEndOfTagSection(c)) {
|
8684 | this.cbs.ondirname(this.sectionStart, this.index);
|
8685 | this.handleAttrNameEnd(c);
|
8686 | } else if (c === 58) {
|
8687 | this.cbs.ondirname(this.sectionStart, this.index);
|
8688 | this.state = 14;
|
8689 | this.sectionStart = this.index + 1;
|
8690 | } else if (c === 46) {
|
8691 | this.cbs.ondirname(this.sectionStart, this.index);
|
8692 | this.state = 16;
|
8693 | this.sectionStart = this.index + 1;
|
8694 | }
|
8695 | }
|
8696 | stateInDirArg(c) {
|
8697 | if (c === 61 || isEndOfTagSection(c)) {
|
8698 | this.cbs.ondirarg(this.sectionStart, this.index);
|
8699 | this.handleAttrNameEnd(c);
|
8700 | } else if (c === 91) {
|
8701 | this.state = 15;
|
8702 | } else if (c === 46) {
|
8703 | this.cbs.ondirarg(this.sectionStart, this.index);
|
8704 | this.state = 16;
|
8705 | this.sectionStart = this.index + 1;
|
8706 | }
|
8707 | }
|
8708 | stateInDynamicDirArg(c) {
|
8709 | if (c === 93) {
|
8710 | this.state = 14;
|
8711 | } else if (c === 61 || isEndOfTagSection(c)) {
|
8712 | this.cbs.ondirarg(this.sectionStart, this.index + 1);
|
8713 | this.handleAttrNameEnd(c);
|
8714 | {
|
8715 | this.cbs.onerr(
|
8716 | 27,
|
8717 | this.index
|
8718 | );
|
8719 | }
|
8720 | }
|
8721 | }
|
8722 | stateInDirModifier(c) {
|
8723 | if (c === 61 || isEndOfTagSection(c)) {
|
8724 | this.cbs.ondirmodifier(this.sectionStart, this.index);
|
8725 | this.handleAttrNameEnd(c);
|
8726 | } else if (c === 46) {
|
8727 | this.cbs.ondirmodifier(this.sectionStart, this.index);
|
8728 | this.sectionStart = this.index + 1;
|
8729 | }
|
8730 | }
|
8731 | handleAttrNameEnd(c) {
|
8732 | this.sectionStart = this.index;
|
8733 | this.state = 17;
|
8734 | this.cbs.onattribnameend(this.index);
|
8735 | this.stateAfterAttrName(c);
|
8736 | }
|
8737 | stateAfterAttrName(c) {
|
8738 | if (c === 61) {
|
8739 | this.state = 18;
|
8740 | } else if (c === 47 || c === 62) {
|
8741 | this.cbs.onattribend(0, this.sectionStart);
|
8742 | this.sectionStart = -1;
|
8743 | this.state = 11;
|
8744 | this.stateBeforeAttrName(c);
|
8745 | } else if (!isWhitespace(c)) {
|
8746 | this.cbs.onattribend(0, this.sectionStart);
|
8747 | this.handleAttrStart(c);
|
8748 | }
|
8749 | }
|
8750 | stateBeforeAttrValue(c) {
|
8751 | if (c === 34) {
|
8752 | this.state = 19;
|
8753 | this.sectionStart = this.index + 1;
|
8754 | } else if (c === 39) {
|
8755 | this.state = 20;
|
8756 | this.sectionStart = this.index + 1;
|
8757 | } else if (!isWhitespace(c)) {
|
8758 | this.sectionStart = this.index;
|
8759 | this.state = 21;
|
8760 | this.stateInAttrValueNoQuotes(c);
|
8761 | }
|
8762 | }
|
8763 | handleInAttrValue(c, quote) {
|
8764 | if (c === quote || this.fastForwardTo(quote)) {
|
8765 | this.cbs.onattribdata(this.sectionStart, this.index);
|
8766 | this.sectionStart = -1;
|
8767 | this.cbs.onattribend(
|
8768 | quote === 34 ? 3 : 2,
|
8769 | this.index + 1
|
8770 | );
|
8771 | this.state = 11;
|
8772 | }
|
8773 | }
|
8774 | stateInAttrValueDoubleQuotes(c) {
|
8775 | this.handleInAttrValue(c, 34);
|
8776 | }
|
8777 | stateInAttrValueSingleQuotes(c) {
|
8778 | this.handleInAttrValue(c, 39);
|
8779 | }
|
8780 | stateInAttrValueNoQuotes(c) {
|
8781 | if (isWhitespace(c) || c === 62) {
|
8782 | this.cbs.onattribdata(this.sectionStart, this.index);
|
8783 | this.sectionStart = -1;
|
8784 | this.cbs.onattribend(1, this.index);
|
8785 | this.state = 11;
|
8786 | this.stateBeforeAttrName(c);
|
8787 | } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
|
8788 | this.cbs.onerr(
|
8789 | 18,
|
8790 | this.index
|
8791 | );
|
8792 | } else ;
|
8793 | }
|
8794 | stateBeforeDeclaration(c) {
|
8795 | if (c === 91) {
|
8796 | this.state = 26;
|
8797 | this.sequenceIndex = 0;
|
8798 | } else {
|
8799 | this.state = c === 45 ? 25 : 23;
|
8800 | }
|
8801 | }
|
8802 | stateInDeclaration(c) {
|
8803 | if (c === 62 || this.fastForwardTo(62)) {
|
8804 | this.state = 1;
|
8805 | this.sectionStart = this.index + 1;
|
8806 | }
|
8807 | }
|
8808 | stateInProcessingInstruction(c) {
|
8809 | if (c === 62 || this.fastForwardTo(62)) {
|
8810 | this.cbs.onprocessinginstruction(this.sectionStart, this.index);
|
8811 | this.state = 1;
|
8812 | this.sectionStart = this.index + 1;
|
8813 | }
|
8814 | }
|
8815 | stateBeforeComment(c) {
|
8816 | if (c === 45) {
|
8817 | this.state = 28;
|
8818 | this.currentSequence = Sequences.CommentEnd;
|
8819 | this.sequenceIndex = 2;
|
8820 | this.sectionStart = this.index + 1;
|
8821 | } else {
|
8822 | this.state = 23;
|
8823 | }
|
8824 | }
|
8825 | stateInSpecialComment(c) {
|
8826 | if (c === 62 || this.fastForwardTo(62)) {
|
8827 | this.cbs.oncomment(this.sectionStart, this.index);
|
8828 | this.state = 1;
|
8829 | this.sectionStart = this.index + 1;
|
8830 | }
|
8831 | }
|
8832 | stateBeforeSpecialS(c) {
|
8833 | if (c === Sequences.ScriptEnd[3]) {
|
8834 | this.startSpecial(Sequences.ScriptEnd, 4);
|
8835 | } else if (c === Sequences.StyleEnd[3]) {
|
8836 | this.startSpecial(Sequences.StyleEnd, 4);
|
8837 | } else {
|
8838 | this.state = 6;
|
8839 | this.stateInTagName(c);
|
8840 | }
|
8841 | }
|
8842 | stateBeforeSpecialT(c) {
|
8843 | if (c === Sequences.TitleEnd[3]) {
|
8844 | this.startSpecial(Sequences.TitleEnd, 4);
|
8845 | } else if (c === Sequences.TextareaEnd[3]) {
|
8846 | this.startSpecial(Sequences.TextareaEnd, 4);
|
8847 | } else {
|
8848 | this.state = 6;
|
8849 | this.stateInTagName(c);
|
8850 | }
|
8851 | }
|
8852 | startEntity() {
|
8853 | }
|
8854 | stateInEntity() {
|
8855 | }
|
8856 | |
8857 |
|
8858 |
|
8859 |
|
8860 |
|
8861 | parse(input) {
|
8862 | this.buffer = input;
|
8863 | while (this.index < this.buffer.length) {
|
8864 | const c = this.buffer.charCodeAt(this.index);
|
8865 | if (c === 10) {
|
8866 | this.newlines.push(this.index);
|
8867 | }
|
8868 | switch (this.state) {
|
8869 | case 1: {
|
8870 | this.stateText(c);
|
8871 | break;
|
8872 | }
|
8873 | case 2: {
|
8874 | this.stateInterpolationOpen(c);
|
8875 | break;
|
8876 | }
|
8877 | case 3: {
|
8878 | this.stateInterpolation(c);
|
8879 | break;
|
8880 | }
|
8881 | case 4: {
|
8882 | this.stateInterpolationClose(c);
|
8883 | break;
|
8884 | }
|
8885 | case 31: {
|
8886 | this.stateSpecialStartSequence(c);
|
8887 | break;
|
8888 | }
|
8889 | case 32: {
|
8890 | this.stateInRCDATA(c);
|
8891 | break;
|
8892 | }
|
8893 | case 26: {
|
8894 | this.stateCDATASequence(c);
|
8895 | break;
|
8896 | }
|
8897 | case 19: {
|
8898 | this.stateInAttrValueDoubleQuotes(c);
|
8899 | break;
|
8900 | }
|
8901 | case 12: {
|
8902 | this.stateInAttrName(c);
|
8903 | break;
|
8904 | }
|
8905 | case 13: {
|
8906 | this.stateInDirName(c);
|
8907 | break;
|
8908 | }
|
8909 | case 14: {
|
8910 | this.stateInDirArg(c);
|
8911 | break;
|
8912 | }
|
8913 | case 15: {
|
8914 | this.stateInDynamicDirArg(c);
|
8915 | break;
|
8916 | }
|
8917 | case 16: {
|
8918 | this.stateInDirModifier(c);
|
8919 | break;
|
8920 | }
|
8921 | case 28: {
|
8922 | this.stateInCommentLike(c);
|
8923 | break;
|
8924 | }
|
8925 | case 27: {
|
8926 | this.stateInSpecialComment(c);
|
8927 | break;
|
8928 | }
|
8929 | case 11: {
|
8930 | this.stateBeforeAttrName(c);
|
8931 | break;
|
8932 | }
|
8933 | case 6: {
|
8934 | this.stateInTagName(c);
|
8935 | break;
|
8936 | }
|
8937 | case 34: {
|
8938 | this.stateInSFCRootTagName(c);
|
8939 | break;
|
8940 | }
|
8941 | case 9: {
|
8942 | this.stateInClosingTagName(c);
|
8943 | break;
|
8944 | }
|
8945 | case 5: {
|
8946 | this.stateBeforeTagName(c);
|
8947 | break;
|
8948 | }
|
8949 | case 17: {
|
8950 | this.stateAfterAttrName(c);
|
8951 | break;
|
8952 | }
|
8953 | case 20: {
|
8954 | this.stateInAttrValueSingleQuotes(c);
|
8955 | break;
|
8956 | }
|
8957 | case 18: {
|
8958 | this.stateBeforeAttrValue(c);
|
8959 | break;
|
8960 | }
|
8961 | case 8: {
|
8962 | this.stateBeforeClosingTagName(c);
|
8963 | break;
|
8964 | }
|
8965 | case 10: {
|
8966 | this.stateAfterClosingTagName(c);
|
8967 | break;
|
8968 | }
|
8969 | case 29: {
|
8970 | this.stateBeforeSpecialS(c);
|
8971 | break;
|
8972 | }
|
8973 | case 30: {
|
8974 | this.stateBeforeSpecialT(c);
|
8975 | break;
|
8976 | }
|
8977 | case 21: {
|
8978 | this.stateInAttrValueNoQuotes(c);
|
8979 | break;
|
8980 | }
|
8981 | case 7: {
|
8982 | this.stateInSelfClosingTag(c);
|
8983 | break;
|
8984 | }
|
8985 | case 23: {
|
8986 | this.stateInDeclaration(c);
|
8987 | break;
|
8988 | }
|
8989 | case 22: {
|
8990 | this.stateBeforeDeclaration(c);
|
8991 | break;
|
8992 | }
|
8993 | case 25: {
|
8994 | this.stateBeforeComment(c);
|
8995 | break;
|
8996 | }
|
8997 | case 24: {
|
8998 | this.stateInProcessingInstruction(c);
|
8999 | break;
|
9000 | }
|
9001 | case 33: {
|
9002 | this.stateInEntity();
|
9003 | break;
|
9004 | }
|
9005 | }
|
9006 | this.index++;
|
9007 | }
|
9008 | this.cleanup();
|
9009 | this.finish();
|
9010 | }
|
9011 | |
9012 |
|
9013 |
|
9014 | cleanup() {
|
9015 | if (this.sectionStart !== this.index) {
|
9016 | if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
|
9017 | this.cbs.ontext(this.sectionStart, this.index);
|
9018 | this.sectionStart = this.index;
|
9019 | } else if (this.state === 19 || this.state === 20 || this.state === 21) {
|
9020 | this.cbs.onattribdata(this.sectionStart, this.index);
|
9021 | this.sectionStart = this.index;
|
9022 | }
|
9023 | }
|
9024 | }
|
9025 | finish() {
|
9026 | this.handleTrailingData();
|
9027 | this.cbs.onend();
|
9028 | }
|
9029 |
|
9030 | handleTrailingData() {
|
9031 | const endIndex = this.buffer.length;
|
9032 | if (this.sectionStart >= endIndex) {
|
9033 | return;
|
9034 | }
|
9035 | if (this.state === 28) {
|
9036 | if (this.currentSequence === Sequences.CdataEnd) {
|
9037 | this.cbs.oncdata(this.sectionStart, endIndex);
|
9038 | } else {
|
9039 | this.cbs.oncomment(this.sectionStart, endIndex);
|
9040 | }
|
9041 | } else if (this.state === 6 || this.state === 11 || this.state === 18 || this.state === 17 || this.state === 12 || this.state === 13 || this.state === 14 || this.state === 15 || this.state === 16 || this.state === 20 || this.state === 19 || this.state === 21 || this.state === 9) ; else {
|
9042 | this.cbs.ontext(this.sectionStart, endIndex);
|
9043 | }
|
9044 | }
|
9045 | emitCodePoint(cp, consumed) {
|
9046 | }
|
9047 | }
|
9048 | const deprecationData = {
|
9049 | ["COMPILER_IS_ON_ELEMENT"]: {
|
9050 | message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`,
|
9051 | link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
|
9052 | },
|
9053 | ["COMPILER_V_BIND_SYNC"]: {
|
9054 | message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`,
|
9055 | link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
|
9056 | },
|
9057 | ["COMPILER_V_BIND_OBJECT_ORDER"]: {
|
9058 | message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.`,
|
9059 | link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
|
9060 | },
|
9061 | ["COMPILER_V_ON_NATIVE"]: {
|
9062 | message: `.native modifier for v-on has been removed as is no longer necessary.`,
|
9063 | link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
|
9064 | },
|
9065 | ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
|
9066 | message: `v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.`,
|
9067 | link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
|
9068 | },
|
9069 | ["COMPILER_NATIVE_TEMPLATE"]: {
|
9070 | message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
|
9071 | },
|
9072 | ["COMPILER_INLINE_TEMPLATE"]: {
|
9073 | message: `"inline-template" has been removed in Vue 3.`,
|
9074 | link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
|
9075 | },
|
9076 | ["COMPILER_FILTERS"]: {
|
9077 | message: `filters have been removed in Vue 3. The "|" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.`,
|
9078 | link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
|
9079 | }
|
9080 | };
|
9081 | function getCompatValue(key, { compatConfig }) {
|
9082 | const value = compatConfig && compatConfig[key];
|
9083 | if (key === "MODE") {
|
9084 | return value || 3;
|
9085 | } else {
|
9086 | return value;
|
9087 | }
|
9088 | }
|
9089 | function isCompatEnabled(key, context) {
|
9090 | const mode = getCompatValue("MODE", context);
|
9091 | const value = getCompatValue(key, context);
|
9092 | return mode === 3 ? value === true : value !== false;
|
9093 | }
|
9094 | function checkCompatEnabled(key, context, loc, ...args) {
|
9095 | const enabled = isCompatEnabled(key, context);
|
9096 | if (enabled) {
|
9097 | warnDeprecation(key, context, loc, ...args);
|
9098 | }
|
9099 | return enabled;
|
9100 | }
|
9101 | function warnDeprecation(key, context, loc, ...args) {
|
9102 | const val = getCompatValue(key, context);
|
9103 | if (val === "suppress-warning") {
|
9104 | return;
|
9105 | }
|
9106 | const { message, link } = deprecationData[key];
|
9107 | const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
|
9108 | Details: ${link}` : ``}`;
|
9109 | const err = new SyntaxError(msg);
|
9110 | err.code = key;
|
9111 | if (loc)
|
9112 | err.loc = loc;
|
9113 | context.onWarn(err);
|
9114 | }
|
9115 |
|
9116 | function defaultOnError(error) {
|
9117 | throw error;
|
9118 | }
|
9119 | function defaultOnWarn(msg) {
|
9120 | console.warn(`[Vue warn] ${msg.message}`);
|
9121 | }
|
9122 | function createCompilerError(code, loc, messages, additionalMessage) {
|
9123 | const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
|
9124 | const error = new SyntaxError(String(msg));
|
9125 | error.code = code;
|
9126 | error.loc = loc;
|
9127 | return error;
|
9128 | }
|
9129 | const errorMessages = {
|
9130 |
|
9131 | [0]: "Illegal comment.",
|
9132 | [1]: "CDATA section is allowed only in XML context.",
|
9133 | [2]: "Duplicate attribute.",
|
9134 | [3]: "End tag cannot have attributes.",
|
9135 | [4]: "Illegal '/' in tags.",
|
9136 | [5]: "Unexpected EOF in tag.",
|
9137 | [6]: "Unexpected EOF in CDATA section.",
|
9138 | [7]: "Unexpected EOF in comment.",
|
9139 | [8]: "Unexpected EOF in script.",
|
9140 | [9]: "Unexpected EOF in tag.",
|
9141 | [10]: "Incorrectly closed comment.",
|
9142 | [11]: "Incorrectly opened comment.",
|
9143 | [12]: "Illegal tag name. Use '<' to print '<'.",
|
9144 | [13]: "Attribute value was expected.",
|
9145 | [14]: "End tag name was expected.",
|
9146 | [15]: "Whitespace was expected.",
|
9147 | [16]: "Unexpected '<!--' in comment.",
|
9148 | [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
|
9149 | [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
|
9150 | [19]: "Attribute name cannot start with '='.",
|
9151 | [21]: "'<?' is allowed only in XML context.",
|
9152 | [20]: `Unexpected null character.`,
|
9153 | [22]: "Illegal '/' in tags.",
|
9154 |
|
9155 | [23]: "Invalid end tag.",
|
9156 | [24]: "Element is missing end tag.",
|
9157 | [25]: "Interpolation end sign was not found.",
|
9158 | [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
|
9159 | [26]: "Legal directive name was expected.",
|
9160 |
|
9161 | [28]: `v-if/v-else-if is missing expression.`,
|
9162 | [29]: `v-if/else branches must use unique keys.`,
|
9163 | [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
9164 | [31]: `v-for is missing expression.`,
|
9165 | [32]: `v-for has invalid expression.`,
|
9166 | [33]: `<template v-for> key should be placed on the <template> tag.`,
|
9167 | [34]: `v-bind is missing expression.`,
|
9168 | [52]: `v-bind with same-name shorthand only allows static argument.`,
|
9169 | [35]: `v-on is missing expression.`,
|
9170 | [36]: `Unexpected custom directive on <slot> outlet.`,
|
9171 | [37]: `Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.`,
|
9172 | [38]: `Duplicate slot names found. `,
|
9173 | [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
|
9174 | [40]: `v-slot can only be used on components or <template> tags.`,
|
9175 | [41]: `v-model is missing expression.`,
|
9176 | [42]: `v-model value must be a valid JavaScript member expression.`,
|
9177 | [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
|
9178 | [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
|
9179 | Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
|
9180 | [45]: `Error parsing JavaScript expression: `,
|
9181 | [46]: `<KeepAlive> expects exactly one child component.`,
|
9182 | [51]: `@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.`,
|
9183 |
|
9184 | [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
9185 | [48]: `ES module mode is not supported in this build of compiler.`,
|
9186 | [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
9187 | [50]: `"scopeId" option is only supported in module mode.`,
|
9188 |
|
9189 | [53]: ``
|
9190 | };
|
9191 |
|
9192 | const isStaticExp = (p) => p.type === 4 && p.isStatic;
|
9193 | function isCoreComponent(tag) {
|
9194 | switch (tag) {
|
9195 | case "Teleport":
|
9196 | case "teleport":
|
9197 | return TELEPORT;
|
9198 | case "Suspense":
|
9199 | case "suspense":
|
9200 | return SUSPENSE;
|
9201 | case "KeepAlive":
|
9202 | case "keep-alive":
|
9203 | return KEEP_ALIVE;
|
9204 | case "BaseTransition":
|
9205 | case "base-transition":
|
9206 | return BASE_TRANSITION;
|
9207 | }
|
9208 | }
|
9209 | const nonIdentifierRE = /^\d|[^\$\w]/;
|
9210 | const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
|
9211 | const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
|
9212 | const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
|
9213 | const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
|
9214 | const isMemberExpressionBrowser = (path) => {
|
9215 | path = path.trim().replace(whitespaceRE, (s) => s.trim());
|
9216 | let state = 0 ;
|
9217 | let stateStack = [];
|
9218 | let currentOpenBracketCount = 0;
|
9219 | let currentOpenParensCount = 0;
|
9220 | let currentStringType = null;
|
9221 | for (let i = 0; i < path.length; i++) {
|
9222 | const char = path.charAt(i);
|
9223 | switch (state) {
|
9224 | case 0 :
|
9225 | if (char === "[") {
|
9226 | stateStack.push(state);
|
9227 | state = 1 ;
|
9228 | currentOpenBracketCount++;
|
9229 | } else if (char === "(") {
|
9230 | stateStack.push(state);
|
9231 | state = 2 ;
|
9232 | currentOpenParensCount++;
|
9233 | } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
|
9234 | return false;
|
9235 | }
|
9236 | break;
|
9237 | case 1 :
|
9238 | if (char === `'` || char === `"` || char === "`") {
|
9239 | stateStack.push(state);
|
9240 | state = 3 ;
|
9241 | currentStringType = char;
|
9242 | } else if (char === `[`) {
|
9243 | currentOpenBracketCount++;
|
9244 | } else if (char === `]`) {
|
9245 | if (!--currentOpenBracketCount) {
|
9246 | state = stateStack.pop();
|
9247 | }
|
9248 | }
|
9249 | break;
|
9250 | case 2 :
|
9251 | if (char === `'` || char === `"` || char === "`") {
|
9252 | stateStack.push(state);
|
9253 | state = 3 ;
|
9254 | currentStringType = char;
|
9255 | } else if (char === `(`) {
|
9256 | currentOpenParensCount++;
|
9257 | } else if (char === `)`) {
|
9258 | if (i === path.length - 1) {
|
9259 | return false;
|
9260 | }
|
9261 | if (!--currentOpenParensCount) {
|
9262 | state = stateStack.pop();
|
9263 | }
|
9264 | }
|
9265 | break;
|
9266 | case 3 :
|
9267 | if (char === currentStringType) {
|
9268 | state = stateStack.pop();
|
9269 | currentStringType = null;
|
9270 | }
|
9271 | break;
|
9272 | }
|
9273 | }
|
9274 | return !currentOpenBracketCount && !currentOpenParensCount;
|
9275 | };
|
9276 | const isMemberExpression = isMemberExpressionBrowser ;
|
9277 | function assert(condition, msg) {
|
9278 | if (!condition) {
|
9279 | throw new Error(msg || `unexpected compiler condition`);
|
9280 | }
|
9281 | }
|
9282 | function findDir(node, name, allowEmpty = false) {
|
9283 | for (let i = 0; i < node.props.length; i++) {
|
9284 | const p = node.props[i];
|
9285 | if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) {
|
9286 | return p;
|
9287 | }
|
9288 | }
|
9289 | }
|
9290 | function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
|
9291 | for (let i = 0; i < node.props.length; i++) {
|
9292 | const p = node.props[i];
|
9293 | if (p.type === 6) {
|
9294 | if (dynamicOnly)
|
9295 | continue;
|
9296 | if (p.name === name && (p.value || allowEmpty)) {
|
9297 | return p;
|
9298 | }
|
9299 | } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
|
9300 | return p;
|
9301 | }
|
9302 | }
|
9303 | }
|
9304 | function isStaticArgOf(arg, name) {
|
9305 | return !!(arg && isStaticExp(arg) && arg.content === name);
|
9306 | }
|
9307 | function hasDynamicKeyVBind(node) {
|
9308 | return node.props.some(
|
9309 | (p) => p.type === 7 && p.name === "bind" && (!p.arg ||
|
9310 | p.arg.type !== 4 ||
|
9311 | !p.arg.isStatic)
|
9312 |
|
9313 | );
|
9314 | }
|
9315 | function isText$1(node) {
|
9316 | return node.type === 5 || node.type === 2;
|
9317 | }
|
9318 | function isVSlot(p) {
|
9319 | return p.type === 7 && p.name === "slot";
|
9320 | }
|
9321 | function isTemplateNode(node) {
|
9322 | return node.type === 1 && node.tagType === 3;
|
9323 | }
|
9324 | function isSlotOutlet(node) {
|
9325 | return node.type === 1 && node.tagType === 2;
|
9326 | }
|
9327 | const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
|
9328 | function getUnnormalizedProps(props, callPath = []) {
|
9329 | if (props && !isString(props) && props.type === 14) {
|
9330 | const callee = props.callee;
|
9331 | if (!isString(callee) && propsHelperSet.has(callee)) {
|
9332 | return getUnnormalizedProps(
|
9333 | props.arguments[0],
|
9334 | callPath.concat(props)
|
9335 | );
|
9336 | }
|
9337 | }
|
9338 | return [props, callPath];
|
9339 | }
|
9340 | function injectProp(node, prop, context) {
|
9341 | let propsWithInjection;
|
9342 | let props = node.type === 13 ? node.props : node.arguments[2];
|
9343 | let callPath = [];
|
9344 | let parentCall;
|
9345 | if (props && !isString(props) && props.type === 14) {
|
9346 | const ret = getUnnormalizedProps(props);
|
9347 | props = ret[0];
|
9348 | callPath = ret[1];
|
9349 | parentCall = callPath[callPath.length - 1];
|
9350 | }
|
9351 | if (props == null || isString(props)) {
|
9352 | propsWithInjection = createObjectExpression([prop]);
|
9353 | } else if (props.type === 14) {
|
9354 | const first = props.arguments[0];
|
9355 | if (!isString(first) && first.type === 15) {
|
9356 | if (!hasProp(prop, first)) {
|
9357 | first.properties.unshift(prop);
|
9358 | }
|
9359 | } else {
|
9360 | if (props.callee === TO_HANDLERS) {
|
9361 | propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
|
9362 | createObjectExpression([prop]),
|
9363 | props
|
9364 | ]);
|
9365 | } else {
|
9366 | props.arguments.unshift(createObjectExpression([prop]));
|
9367 | }
|
9368 | }
|
9369 | !propsWithInjection && (propsWithInjection = props);
|
9370 | } else if (props.type === 15) {
|
9371 | if (!hasProp(prop, props)) {
|
9372 | props.properties.unshift(prop);
|
9373 | }
|
9374 | propsWithInjection = props;
|
9375 | } else {
|
9376 | propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
|
9377 | createObjectExpression([prop]),
|
9378 | props
|
9379 | ]);
|
9380 | if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
|
9381 | parentCall = callPath[callPath.length - 2];
|
9382 | }
|
9383 | }
|
9384 | if (node.type === 13) {
|
9385 | if (parentCall) {
|
9386 | parentCall.arguments[0] = propsWithInjection;
|
9387 | } else {
|
9388 | node.props = propsWithInjection;
|
9389 | }
|
9390 | } else {
|
9391 | if (parentCall) {
|
9392 | parentCall.arguments[0] = propsWithInjection;
|
9393 | } else {
|
9394 | node.arguments[2] = propsWithInjection;
|
9395 | }
|
9396 | }
|
9397 | }
|
9398 | function hasProp(prop, props) {
|
9399 | let result = false;
|
9400 | if (prop.key.type === 4) {
|
9401 | const propKeyName = prop.key.content;
|
9402 | result = props.properties.some(
|
9403 | (p) => p.key.type === 4 && p.key.content === propKeyName
|
9404 | );
|
9405 | }
|
9406 | return result;
|
9407 | }
|
9408 | function toValidAssetId(name, type) {
|
9409 | return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
|
9410 | return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
|
9411 | })}`;
|
9412 | }
|
9413 | function getMemoedVNodeCall(node) {
|
9414 | if (node.type === 14 && node.callee === WITH_MEMO) {
|
9415 | return node.arguments[1].returns;
|
9416 | } else {
|
9417 | return node;
|
9418 | }
|
9419 | }
|
9420 | const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
|
9421 |
|
9422 | const defaultParserOptions = {
|
9423 | parseMode: "base",
|
9424 | ns: 0,
|
9425 | delimiters: [`{{`, `}}`],
|
9426 | getNamespace: () => 0,
|
9427 | isVoidTag: NO,
|
9428 | isPreTag: NO,
|
9429 | isCustomElement: NO,
|
9430 | onError: defaultOnError,
|
9431 | onWarn: defaultOnWarn,
|
9432 | comments: !!(true !== "production"),
|
9433 | prefixIdentifiers: false
|
9434 | };
|
9435 | let currentOptions = defaultParserOptions;
|
9436 | let currentRoot = null;
|
9437 | let currentInput = "";
|
9438 | let currentOpenTag = null;
|
9439 | let currentProp = null;
|
9440 | let currentAttrValue = "";
|
9441 | let currentAttrStartIndex = -1;
|
9442 | let currentAttrEndIndex = -1;
|
9443 | let inPre = 0;
|
9444 | let inVPre = false;
|
9445 | let currentVPreBoundary = null;
|
9446 | const stack = [];
|
9447 | const tokenizer = new Tokenizer(stack, {
|
9448 | onerr: emitError,
|
9449 | ontext(start, end) {
|
9450 | onText(getSlice(start, end), start, end);
|
9451 | },
|
9452 | ontextentity(char, start, end) {
|
9453 | onText(char, start, end);
|
9454 | },
|
9455 | oninterpolation(start, end) {
|
9456 | if (inVPre) {
|
9457 | return onText(getSlice(start, end), start, end);
|
9458 | }
|
9459 | let innerStart = start + tokenizer.delimiterOpen.length;
|
9460 | let innerEnd = end - tokenizer.delimiterClose.length;
|
9461 | while (isWhitespace(currentInput.charCodeAt(innerStart))) {
|
9462 | innerStart++;
|
9463 | }
|
9464 | while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
|
9465 | innerEnd--;
|
9466 | }
|
9467 | let exp = getSlice(innerStart, innerEnd);
|
9468 | if (exp.includes("&")) {
|
9469 | {
|
9470 | exp = currentOptions.decodeEntities(exp, false);
|
9471 | }
|
9472 | }
|
9473 | addNode({
|
9474 | type: 5,
|
9475 | content: createExp(exp, false, getLoc(innerStart, innerEnd)),
|
9476 | loc: getLoc(start, end)
|
9477 | });
|
9478 | },
|
9479 | onopentagname(start, end) {
|
9480 | const name = getSlice(start, end);
|
9481 | currentOpenTag = {
|
9482 | type: 1,
|
9483 | tag: name,
|
9484 | ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
|
9485 | tagType: 0,
|
9486 |
|
9487 | props: [],
|
9488 | children: [],
|
9489 | loc: getLoc(start - 1, end),
|
9490 | codegenNode: void 0
|
9491 | };
|
9492 | },
|
9493 | onopentagend(end) {
|
9494 | endOpenTag(end);
|
9495 | },
|
9496 | onclosetag(start, end) {
|
9497 | const name = getSlice(start, end);
|
9498 | if (!currentOptions.isVoidTag(name)) {
|
9499 | let found = false;
|
9500 | for (let i = 0; i < stack.length; i++) {
|
9501 | const e = stack[i];
|
9502 | if (e.tag.toLowerCase() === name.toLowerCase()) {
|
9503 | found = true;
|
9504 | if (i > 0) {
|
9505 | emitError(24, stack[0].loc.start.offset);
|
9506 | }
|
9507 | for (let j = 0; j <= i; j++) {
|
9508 | const el = stack.shift();
|
9509 | onCloseTag(el, end, j < i);
|
9510 | }
|
9511 | break;
|
9512 | }
|
9513 | }
|
9514 | if (!found) {
|
9515 | emitError(23, backTrack(start, 60));
|
9516 | }
|
9517 | }
|
9518 | },
|
9519 | onselfclosingtag(end) {
|
9520 | const name = currentOpenTag.tag;
|
9521 | currentOpenTag.isSelfClosing = true;
|
9522 | endOpenTag(end);
|
9523 | if (stack[0] && stack[0].tag === name) {
|
9524 | onCloseTag(stack.shift(), end);
|
9525 | }
|
9526 | },
|
9527 | onattribname(start, end) {
|
9528 | currentProp = {
|
9529 | type: 6,
|
9530 | name: getSlice(start, end),
|
9531 | nameLoc: getLoc(start, end),
|
9532 | value: void 0,
|
9533 | loc: getLoc(start)
|
9534 | };
|
9535 | },
|
9536 | ondirname(start, end) {
|
9537 | const raw = getSlice(start, end);
|
9538 | const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
|
9539 | if (!inVPre && name === "") {
|
9540 | emitError(26, start);
|
9541 | }
|
9542 | if (inVPre || name === "") {
|
9543 | currentProp = {
|
9544 | type: 6,
|
9545 | name: raw,
|
9546 | nameLoc: getLoc(start, end),
|
9547 | value: void 0,
|
9548 | loc: getLoc(start)
|
9549 | };
|
9550 | } else {
|
9551 | currentProp = {
|
9552 | type: 7,
|
9553 | name,
|
9554 | rawName: raw,
|
9555 | exp: void 0,
|
9556 | arg: void 0,
|
9557 | modifiers: raw === "." ? ["prop"] : [],
|
9558 | loc: getLoc(start)
|
9559 | };
|
9560 | if (name === "pre") {
|
9561 | inVPre = tokenizer.inVPre = true;
|
9562 | currentVPreBoundary = currentOpenTag;
|
9563 | const props = currentOpenTag.props;
|
9564 | for (let i = 0; i < props.length; i++) {
|
9565 | if (props[i].type === 7) {
|
9566 | props[i] = dirToAttr(props[i]);
|
9567 | }
|
9568 | }
|
9569 | }
|
9570 | }
|
9571 | },
|
9572 | ondirarg(start, end) {
|
9573 | if (start === end)
|
9574 | return;
|
9575 | const arg = getSlice(start, end);
|
9576 | if (inVPre) {
|
9577 | currentProp.name += arg;
|
9578 | setLocEnd(currentProp.nameLoc, end);
|
9579 | } else {
|
9580 | const isStatic = arg[0] !== `[`;
|
9581 | currentProp.arg = createExp(
|
9582 | isStatic ? arg : arg.slice(1, -1),
|
9583 | isStatic,
|
9584 | getLoc(start, end),
|
9585 | isStatic ? 3 : 0
|
9586 | );
|
9587 | }
|
9588 | },
|
9589 | ondirmodifier(start, end) {
|
9590 | const mod = getSlice(start, end);
|
9591 | if (inVPre) {
|
9592 | currentProp.name += "." + mod;
|
9593 | setLocEnd(currentProp.nameLoc, end);
|
9594 | } else if (currentProp.name === "slot") {
|
9595 | const arg = currentProp.arg;
|
9596 | if (arg) {
|
9597 | arg.content += "." + mod;
|
9598 | setLocEnd(arg.loc, end);
|
9599 | }
|
9600 | } else {
|
9601 | currentProp.modifiers.push(mod);
|
9602 | }
|
9603 | },
|
9604 | onattribdata(start, end) {
|
9605 | currentAttrValue += getSlice(start, end);
|
9606 | if (currentAttrStartIndex < 0)
|
9607 | currentAttrStartIndex = start;
|
9608 | currentAttrEndIndex = end;
|
9609 | },
|
9610 | onattribentity(char, start, end) {
|
9611 | currentAttrValue += char;
|
9612 | if (currentAttrStartIndex < 0)
|
9613 | currentAttrStartIndex = start;
|
9614 | currentAttrEndIndex = end;
|
9615 | },
|
9616 | onattribnameend(end) {
|
9617 | const start = currentProp.loc.start.offset;
|
9618 | const name = getSlice(start, end);
|
9619 | if (currentProp.type === 7) {
|
9620 | currentProp.rawName = name;
|
9621 | }
|
9622 | if (currentOpenTag.props.some(
|
9623 | (p) => (p.type === 7 ? p.rawName : p.name) === name
|
9624 | )) {
|
9625 | emitError(2, start);
|
9626 | }
|
9627 | },
|
9628 | onattribend(quote, end) {
|
9629 | if (currentOpenTag && currentProp) {
|
9630 | setLocEnd(currentProp.loc, end);
|
9631 | if (quote !== 0) {
|
9632 | if (currentAttrValue.includes("&")) {
|
9633 | currentAttrValue = currentOptions.decodeEntities(
|
9634 | currentAttrValue,
|
9635 | true
|
9636 | );
|
9637 | }
|
9638 | if (currentProp.type === 6) {
|
9639 | if (currentProp.name === "class") {
|
9640 | currentAttrValue = condense(currentAttrValue).trim();
|
9641 | }
|
9642 | if (quote === 1 && !currentAttrValue) {
|
9643 | emitError(13, end);
|
9644 | }
|
9645 | currentProp.value = {
|
9646 | type: 2,
|
9647 | content: currentAttrValue,
|
9648 | loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
|
9649 | };
|
9650 | if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
|
9651 | tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
|
9652 | }
|
9653 | } else {
|
9654 | let expParseMode = 0 ;
|
9655 | currentProp.exp = createExp(
|
9656 | currentAttrValue,
|
9657 | false,
|
9658 | getLoc(currentAttrStartIndex, currentAttrEndIndex),
|
9659 | 0,
|
9660 | expParseMode
|
9661 | );
|
9662 | if (currentProp.name === "for") {
|
9663 | currentProp.forParseResult = parseForExpression(currentProp.exp);
|
9664 | }
|
9665 | let syncIndex = -1;
|
9666 | if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.indexOf("sync")) > -1 && checkCompatEnabled(
|
9667 | "COMPILER_V_BIND_SYNC",
|
9668 | currentOptions,
|
9669 | currentProp.loc,
|
9670 | currentProp.rawName
|
9671 | )) {
|
9672 | currentProp.name = "model";
|
9673 | currentProp.modifiers.splice(syncIndex, 1);
|
9674 | }
|
9675 | }
|
9676 | }
|
9677 | if (currentProp.type !== 7 || currentProp.name !== "pre") {
|
9678 | currentOpenTag.props.push(currentProp);
|
9679 | }
|
9680 | }
|
9681 | currentAttrValue = "";
|
9682 | currentAttrStartIndex = currentAttrEndIndex = -1;
|
9683 | },
|
9684 | oncomment(start, end) {
|
9685 | if (currentOptions.comments) {
|
9686 | addNode({
|
9687 | type: 3,
|
9688 | content: getSlice(start, end),
|
9689 | loc: getLoc(start - 4, end + 3)
|
9690 | });
|
9691 | }
|
9692 | },
|
9693 | onend() {
|
9694 | const end = currentInput.length;
|
9695 | if (tokenizer.state !== 1) {
|
9696 | switch (tokenizer.state) {
|
9697 | case 5:
|
9698 | case 8:
|
9699 | emitError(5, end);
|
9700 | break;
|
9701 | case 3:
|
9702 | case 4:
|
9703 | emitError(
|
9704 | 25,
|
9705 | tokenizer.sectionStart
|
9706 | );
|
9707 | break;
|
9708 | case 28:
|
9709 | if (tokenizer.currentSequence === Sequences.CdataEnd) {
|
9710 | emitError(6, end);
|
9711 | } else {
|
9712 | emitError(7, end);
|
9713 | }
|
9714 | break;
|
9715 | case 6:
|
9716 | case 7:
|
9717 | case 9:
|
9718 | case 11:
|
9719 | case 12:
|
9720 | case 13:
|
9721 | case 14:
|
9722 | case 15:
|
9723 | case 16:
|
9724 | case 17:
|
9725 | case 18:
|
9726 | case 19:
|
9727 | case 20:
|
9728 | case 21:
|
9729 | emitError(9, end);
|
9730 | break;
|
9731 | }
|
9732 | }
|
9733 | for (let index = 0; index < stack.length; index++) {
|
9734 | onCloseTag(stack[index], end - 1);
|
9735 | emitError(24, stack[index].loc.start.offset);
|
9736 | }
|
9737 | },
|
9738 | oncdata(start, end) {
|
9739 | if (stack[0].ns !== 0) {
|
9740 | onText(getSlice(start, end), start, end);
|
9741 | } else {
|
9742 | emitError(1, start - 9);
|
9743 | }
|
9744 | },
|
9745 | onprocessinginstruction(start) {
|
9746 | if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
|
9747 | emitError(
|
9748 | 21,
|
9749 | start - 1
|
9750 | );
|
9751 | }
|
9752 | }
|
9753 | });
|
9754 | const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
|
9755 | const stripParensRE = /^\(|\)$/g;
|
9756 | function parseForExpression(input) {
|
9757 | const loc = input.loc;
|
9758 | const exp = input.content;
|
9759 | const inMatch = exp.match(forAliasRE);
|
9760 | if (!inMatch)
|
9761 | return;
|
9762 | const [, LHS, RHS] = inMatch;
|
9763 | const createAliasExpression = (content, offset, asParam = false) => {
|
9764 | const start = loc.start.offset + offset;
|
9765 | const end = start + content.length;
|
9766 | return createExp(
|
9767 | content,
|
9768 | false,
|
9769 | getLoc(start, end),
|
9770 | 0,
|
9771 | asParam ? 1 : 0
|
9772 | );
|
9773 | };
|
9774 | const result = {
|
9775 | source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
|
9776 | value: void 0,
|
9777 | key: void 0,
|
9778 | index: void 0,
|
9779 | finalized: false
|
9780 | };
|
9781 | let valueContent = LHS.trim().replace(stripParensRE, "").trim();
|
9782 | const trimmedOffset = LHS.indexOf(valueContent);
|
9783 | const iteratorMatch = valueContent.match(forIteratorRE);
|
9784 | if (iteratorMatch) {
|
9785 | valueContent = valueContent.replace(forIteratorRE, "").trim();
|
9786 | const keyContent = iteratorMatch[1].trim();
|
9787 | let keyOffset;
|
9788 | if (keyContent) {
|
9789 | keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
|
9790 | result.key = createAliasExpression(keyContent, keyOffset, true);
|
9791 | }
|
9792 | if (iteratorMatch[2]) {
|
9793 | const indexContent = iteratorMatch[2].trim();
|
9794 | if (indexContent) {
|
9795 | result.index = createAliasExpression(
|
9796 | indexContent,
|
9797 | exp.indexOf(
|
9798 | indexContent,
|
9799 | result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
|
9800 | ),
|
9801 | true
|
9802 | );
|
9803 | }
|
9804 | }
|
9805 | }
|
9806 | if (valueContent) {
|
9807 | result.value = createAliasExpression(valueContent, trimmedOffset, true);
|
9808 | }
|
9809 | return result;
|
9810 | }
|
9811 | function getSlice(start, end) {
|
9812 | return currentInput.slice(start, end);
|
9813 | }
|
9814 | function endOpenTag(end) {
|
9815 | if (tokenizer.inSFCRoot) {
|
9816 | currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
|
9817 | }
|
9818 | addNode(currentOpenTag);
|
9819 | const { tag, ns } = currentOpenTag;
|
9820 | if (ns === 0 && currentOptions.isPreTag(tag)) {
|
9821 | inPre++;
|
9822 | }
|
9823 | if (currentOptions.isVoidTag(tag)) {
|
9824 | onCloseTag(currentOpenTag, end);
|
9825 | } else {
|
9826 | stack.unshift(currentOpenTag);
|
9827 | if (ns === 1 || ns === 2) {
|
9828 | tokenizer.inXML = true;
|
9829 | }
|
9830 | }
|
9831 | currentOpenTag = null;
|
9832 | }
|
9833 | function onText(content, start, end) {
|
9834 | {
|
9835 | const tag = stack[0] && stack[0].tag;
|
9836 | if (tag !== "script" && tag !== "style" && content.includes("&")) {
|
9837 | content = currentOptions.decodeEntities(content, false);
|
9838 | }
|
9839 | }
|
9840 | const parent = stack[0] || currentRoot;
|
9841 | const lastNode = parent.children[parent.children.length - 1];
|
9842 | if (lastNode && lastNode.type === 2) {
|
9843 | lastNode.content += content;
|
9844 | setLocEnd(lastNode.loc, end);
|
9845 | } else {
|
9846 | parent.children.push({
|
9847 | type: 2,
|
9848 | content,
|
9849 | loc: getLoc(start, end)
|
9850 | });
|
9851 | }
|
9852 | }
|
9853 | function onCloseTag(el, end, isImplied = false) {
|
9854 | if (isImplied) {
|
9855 | setLocEnd(el.loc, backTrack(end, 60));
|
9856 | } else {
|
9857 | setLocEnd(el.loc, lookAhead(end, 62) + 1);
|
9858 | }
|
9859 | if (tokenizer.inSFCRoot) {
|
9860 | if (el.children.length) {
|
9861 | el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
|
9862 | } else {
|
9863 | el.innerLoc.end = extend({}, el.innerLoc.start);
|
9864 | }
|
9865 | el.innerLoc.source = getSlice(
|
9866 | el.innerLoc.start.offset,
|
9867 | el.innerLoc.end.offset
|
9868 | );
|
9869 | }
|
9870 | const { tag, ns } = el;
|
9871 | if (!inVPre) {
|
9872 | if (tag === "slot") {
|
9873 | el.tagType = 2;
|
9874 | } else if (isFragmentTemplate(el)) {
|
9875 | el.tagType = 3;
|
9876 | } else if (isComponent(el)) {
|
9877 | el.tagType = 1;
|
9878 | }
|
9879 | }
|
9880 | if (!tokenizer.inRCDATA) {
|
9881 | el.children = condenseWhitespace(el.children, el.tag);
|
9882 | }
|
9883 | if (ns === 0 && currentOptions.isPreTag(tag)) {
|
9884 | inPre--;
|
9885 | }
|
9886 | if (currentVPreBoundary === el) {
|
9887 | inVPre = tokenizer.inVPre = false;
|
9888 | currentVPreBoundary = null;
|
9889 | }
|
9890 | if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
|
9891 | tokenizer.inXML = false;
|
9892 | }
|
9893 | {
|
9894 | const props = el.props;
|
9895 | if (isCompatEnabled(
|
9896 | "COMPILER_V_IF_V_FOR_PRECEDENCE",
|
9897 | currentOptions
|
9898 | )) {
|
9899 | let hasIf = false;
|
9900 | let hasFor = false;
|
9901 | for (let i = 0; i < props.length; i++) {
|
9902 | const p = props[i];
|
9903 | if (p.type === 7) {
|
9904 | if (p.name === "if") {
|
9905 | hasIf = true;
|
9906 | } else if (p.name === "for") {
|
9907 | hasFor = true;
|
9908 | }
|
9909 | }
|
9910 | if (hasIf && hasFor) {
|
9911 | warnDeprecation(
|
9912 | "COMPILER_V_IF_V_FOR_PRECEDENCE",
|
9913 | currentOptions,
|
9914 | el.loc
|
9915 | );
|
9916 | break;
|
9917 | }
|
9918 | }
|
9919 | }
|
9920 | if (!tokenizer.inSFCRoot && isCompatEnabled(
|
9921 | "COMPILER_NATIVE_TEMPLATE",
|
9922 | currentOptions
|
9923 | ) && el.tag === "template" && !isFragmentTemplate(el)) {
|
9924 | warnDeprecation(
|
9925 | "COMPILER_NATIVE_TEMPLATE",
|
9926 | currentOptions,
|
9927 | el.loc
|
9928 | );
|
9929 | const parent = stack[0] || currentRoot;
|
9930 | const index = parent.children.indexOf(el);
|
9931 | parent.children.splice(index, 1, ...el.children);
|
9932 | }
|
9933 | const inlineTemplateProp = props.find(
|
9934 | (p) => p.type === 6 && p.name === "inline-template"
|
9935 | );
|
9936 | if (inlineTemplateProp && checkCompatEnabled(
|
9937 | "COMPILER_INLINE_TEMPLATE",
|
9938 | currentOptions,
|
9939 | inlineTemplateProp.loc
|
9940 | ) && el.children.length) {
|
9941 | inlineTemplateProp.value = {
|
9942 | type: 2,
|
9943 | content: getSlice(
|
9944 | el.children[0].loc.start.offset,
|
9945 | el.children[el.children.length - 1].loc.end.offset
|
9946 | ),
|
9947 | loc: inlineTemplateProp.loc
|
9948 | };
|
9949 | }
|
9950 | }
|
9951 | }
|
9952 | function lookAhead(index, c) {
|
9953 | let i = index;
|
9954 | while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1)
|
9955 | i++;
|
9956 | return i;
|
9957 | }
|
9958 | function backTrack(index, c) {
|
9959 | let i = index;
|
9960 | while (currentInput.charCodeAt(i) !== c && i >= 0)
|
9961 | i--;
|
9962 | return i;
|
9963 | }
|
9964 | const specialTemplateDir = new Set(["if", "else", "else-if", "for", "slot"]);
|
9965 | function isFragmentTemplate({ tag, props }) {
|
9966 | if (tag === "template") {
|
9967 | for (let i = 0; i < props.length; i++) {
|
9968 | if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
|
9969 | return true;
|
9970 | }
|
9971 | }
|
9972 | }
|
9973 | return false;
|
9974 | }
|
9975 | function isComponent({ tag, props }) {
|
9976 | if (currentOptions.isCustomElement(tag)) {
|
9977 | return false;
|
9978 | }
|
9979 | if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
|
9980 | return true;
|
9981 | }
|
9982 | for (let i = 0; i < props.length; i++) {
|
9983 | const p = props[i];
|
9984 | if (p.type === 6) {
|
9985 | if (p.name === "is" && p.value) {
|
9986 | if (p.value.content.startsWith("vue:")) {
|
9987 | return true;
|
9988 | } else if (checkCompatEnabled(
|
9989 | "COMPILER_IS_ON_ELEMENT",
|
9990 | currentOptions,
|
9991 | p.loc
|
9992 | )) {
|
9993 | return true;
|
9994 | }
|
9995 | }
|
9996 | } else if (
|
9997 | p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
|
9998 | "COMPILER_IS_ON_ELEMENT",
|
9999 | currentOptions,
|
10000 | p.loc
|
10001 | )) {
|
10002 | return true;
|
10003 | }
|
10004 | }
|
10005 | return false;
|
10006 | }
|
10007 | function isUpperCase(c) {
|
10008 | return c > 64 && c < 91;
|
10009 | }
|
10010 | const windowsNewlineRE = /\r\n/g;
|
10011 | function condenseWhitespace(nodes, tag) {
|
10012 | const shouldCondense = currentOptions.whitespace !== "preserve";
|
10013 | let removedWhitespace = false;
|
10014 | for (let i = 0; i < nodes.length; i++) {
|
10015 | const node = nodes[i];
|
10016 | if (node.type === 2) {
|
10017 | if (!inPre) {
|
10018 | if (isAllWhitespace(node.content)) {
|
10019 | const prev = nodes[i - 1] && nodes[i - 1].type;
|
10020 | const next = nodes[i + 1] && nodes[i + 1].type;
|
10021 | if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
|
10022 | removedWhitespace = true;
|
10023 | nodes[i] = null;
|
10024 | } else {
|
10025 | node.content = " ";
|
10026 | }
|
10027 | } else if (shouldCondense) {
|
10028 | node.content = condense(node.content);
|
10029 | }
|
10030 | } else {
|
10031 | node.content = node.content.replace(windowsNewlineRE, "\n");
|
10032 | }
|
10033 | }
|
10034 | }
|
10035 | if (inPre && tag && currentOptions.isPreTag(tag)) {
|
10036 | const first = nodes[0];
|
10037 | if (first && first.type === 2) {
|
10038 | first.content = first.content.replace(/^\r?\n/, "");
|
10039 | }
|
10040 | }
|
10041 | return removedWhitespace ? nodes.filter(Boolean) : nodes;
|
10042 | }
|
10043 | function isAllWhitespace(str) {
|
10044 | for (let i = 0; i < str.length; i++) {
|
10045 | if (!isWhitespace(str.charCodeAt(i))) {
|
10046 | return false;
|
10047 | }
|
10048 | }
|
10049 | return true;
|
10050 | }
|
10051 | function hasNewlineChar(str) {
|
10052 | for (let i = 0; i < str.length; i++) {
|
10053 | const c = str.charCodeAt(i);
|
10054 | if (c === 10 || c === 13) {
|
10055 | return true;
|
10056 | }
|
10057 | }
|
10058 | return false;
|
10059 | }
|
10060 | function condense(str) {
|
10061 | let ret = "";
|
10062 | let prevCharIsWhitespace = false;
|
10063 | for (let i = 0; i < str.length; i++) {
|
10064 | if (isWhitespace(str.charCodeAt(i))) {
|
10065 | if (!prevCharIsWhitespace) {
|
10066 | ret += " ";
|
10067 | prevCharIsWhitespace = true;
|
10068 | }
|
10069 | } else {
|
10070 | ret += str[i];
|
10071 | prevCharIsWhitespace = false;
|
10072 | }
|
10073 | }
|
10074 | return ret;
|
10075 | }
|
10076 | function addNode(node) {
|
10077 | (stack[0] || currentRoot).children.push(node);
|
10078 | }
|
10079 | function getLoc(start, end) {
|
10080 | return {
|
10081 | start: tokenizer.getPos(start),
|
10082 |
|
10083 | end: end == null ? end : tokenizer.getPos(end),
|
10084 |
|
10085 | source: end == null ? end : getSlice(start, end)
|
10086 | };
|
10087 | }
|
10088 | function setLocEnd(loc, end) {
|
10089 | loc.end = tokenizer.getPos(end);
|
10090 | loc.source = getSlice(loc.start.offset, end);
|
10091 | }
|
10092 | function dirToAttr(dir) {
|
10093 | const attr = {
|
10094 | type: 6,
|
10095 | name: dir.rawName,
|
10096 | nameLoc: getLoc(
|
10097 | dir.loc.start.offset,
|
10098 | dir.loc.start.offset + dir.rawName.length
|
10099 | ),
|
10100 | value: void 0,
|
10101 | loc: dir.loc
|
10102 | };
|
10103 | if (dir.exp) {
|
10104 | const loc = dir.exp.loc;
|
10105 | if (loc.end.offset < dir.loc.end.offset) {
|
10106 | loc.start.offset--;
|
10107 | loc.start.column--;
|
10108 | loc.end.offset++;
|
10109 | loc.end.column++;
|
10110 | }
|
10111 | attr.value = {
|
10112 | type: 2,
|
10113 | content: dir.exp.content,
|
10114 | loc
|
10115 | };
|
10116 | }
|
10117 | return attr;
|
10118 | }
|
10119 | function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
|
10120 | const exp = createSimpleExpression(content, isStatic, loc, constType);
|
10121 | return exp;
|
10122 | }
|
10123 | function emitError(code, index, message) {
|
10124 | currentOptions.onError(
|
10125 | createCompilerError(code, getLoc(index, index), void 0, message)
|
10126 | );
|
10127 | }
|
10128 | function reset() {
|
10129 | tokenizer.reset();
|
10130 | currentOpenTag = null;
|
10131 | currentProp = null;
|
10132 | currentAttrValue = "";
|
10133 | currentAttrStartIndex = -1;
|
10134 | currentAttrEndIndex = -1;
|
10135 | stack.length = 0;
|
10136 | }
|
10137 | function baseParse(input, options) {
|
10138 | reset();
|
10139 | currentInput = input;
|
10140 | currentOptions = extend({}, defaultParserOptions);
|
10141 | if (options) {
|
10142 | let key;
|
10143 | for (key in options) {
|
10144 | if (options[key] != null) {
|
10145 | currentOptions[key] = options[key];
|
10146 | }
|
10147 | }
|
10148 | }
|
10149 | {
|
10150 | if (!currentOptions.decodeEntities) {
|
10151 | throw new Error(
|
10152 | `[@vue/compiler-core] decodeEntities option is required in browser builds.`
|
10153 | );
|
10154 | }
|
10155 | }
|
10156 | tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
|
10157 | tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
|
10158 | const delimiters = options && options.delimiters;
|
10159 | if (delimiters) {
|
10160 | tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
|
10161 | tokenizer.delimiterClose = toCharCodes(delimiters[1]);
|
10162 | }
|
10163 | const root = currentRoot = createRoot([], input);
|
10164 | tokenizer.parse(currentInput);
|
10165 | root.loc = getLoc(0, input.length);
|
10166 | root.children = condenseWhitespace(root.children);
|
10167 | currentRoot = null;
|
10168 | return root;
|
10169 | }
|
10170 |
|
10171 | function hoistStatic(root, context) {
|
10172 | walk(
|
10173 | root,
|
10174 | context,
|
10175 |
|
10176 |
|
10177 | isSingleElementRoot(root, root.children[0])
|
10178 | );
|
10179 | }
|
10180 | function isSingleElementRoot(root, child) {
|
10181 | const { children } = root;
|
10182 | return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
|
10183 | }
|
10184 | function walk(node, context, doNotHoistNode = false) {
|
10185 | const { children } = node;
|
10186 | const originalCount = children.length;
|
10187 | let hoistedCount = 0;
|
10188 | for (let i = 0; i < children.length; i++) {
|
10189 | const child = children[i];
|
10190 | if (child.type === 1 && child.tagType === 0) {
|
10191 | const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
|
10192 | if (constantType > 0) {
|
10193 | if (constantType >= 2) {
|
10194 | child.codegenNode.patchFlag = -1 + (` /* HOISTED */` );
|
10195 | child.codegenNode = context.hoist(child.codegenNode);
|
10196 | hoistedCount++;
|
10197 | continue;
|
10198 | }
|
10199 | } else {
|
10200 | const codegenNode = child.codegenNode;
|
10201 | if (codegenNode.type === 13) {
|
10202 | const flag = getPatchFlag(codegenNode);
|
10203 | if ((!flag || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
|
10204 | const props = getNodeProps(child);
|
10205 | if (props) {
|
10206 | codegenNode.props = context.hoist(props);
|
10207 | }
|
10208 | }
|
10209 | if (codegenNode.dynamicProps) {
|
10210 | codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
|
10211 | }
|
10212 | }
|
10213 | }
|
10214 | }
|
10215 | if (child.type === 1) {
|
10216 | const isComponent = child.tagType === 1;
|
10217 | if (isComponent) {
|
10218 | context.scopes.vSlot++;
|
10219 | }
|
10220 | walk(child, context);
|
10221 | if (isComponent) {
|
10222 | context.scopes.vSlot--;
|
10223 | }
|
10224 | } else if (child.type === 11) {
|
10225 | walk(child, context, child.children.length === 1);
|
10226 | } else if (child.type === 9) {
|
10227 | for (let i2 = 0; i2 < child.branches.length; i2++) {
|
10228 | walk(
|
10229 | child.branches[i2],
|
10230 | context,
|
10231 | child.branches[i2].children.length === 1
|
10232 | );
|
10233 | }
|
10234 | }
|
10235 | }
|
10236 | if (hoistedCount && context.transformHoist) {
|
10237 | context.transformHoist(children, context, node);
|
10238 | }
|
10239 | if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
|
10240 | const hoisted = context.hoist(
|
10241 | createArrayExpression(node.codegenNode.children)
|
10242 | );
|
10243 | if (context.hmr) {
|
10244 | hoisted.content = `[...${hoisted.content}]`;
|
10245 | }
|
10246 | node.codegenNode.children = hoisted;
|
10247 | }
|
10248 | }
|
10249 | function getConstantType(node, context) {
|
10250 | const { constantCache } = context;
|
10251 | switch (node.type) {
|
10252 | case 1:
|
10253 | if (node.tagType !== 0) {
|
10254 | return 0;
|
10255 | }
|
10256 | const cached = constantCache.get(node);
|
10257 | if (cached !== void 0) {
|
10258 | return cached;
|
10259 | }
|
10260 | const codegenNode = node.codegenNode;
|
10261 | if (codegenNode.type !== 13) {
|
10262 | return 0;
|
10263 | }
|
10264 | if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
|
10265 | return 0;
|
10266 | }
|
10267 | const flag = getPatchFlag(codegenNode);
|
10268 | if (!flag) {
|
10269 | let returnType2 = 3;
|
10270 | const generatedPropsType = getGeneratedPropsConstantType(node, context);
|
10271 | if (generatedPropsType === 0) {
|
10272 | constantCache.set(node, 0);
|
10273 | return 0;
|
10274 | }
|
10275 | if (generatedPropsType < returnType2) {
|
10276 | returnType2 = generatedPropsType;
|
10277 | }
|
10278 | for (let i = 0; i < node.children.length; i++) {
|
10279 | const childType = getConstantType(node.children[i], context);
|
10280 | if (childType === 0) {
|
10281 | constantCache.set(node, 0);
|
10282 | return 0;
|
10283 | }
|
10284 | if (childType < returnType2) {
|
10285 | returnType2 = childType;
|
10286 | }
|
10287 | }
|
10288 | if (returnType2 > 1) {
|
10289 | for (let i = 0; i < node.props.length; i++) {
|
10290 | const p = node.props[i];
|
10291 | if (p.type === 7 && p.name === "bind" && p.exp) {
|
10292 | const expType = getConstantType(p.exp, context);
|
10293 | if (expType === 0) {
|
10294 | constantCache.set(node, 0);
|
10295 | return 0;
|
10296 | }
|
10297 | if (expType < returnType2) {
|
10298 | returnType2 = expType;
|
10299 | }
|
10300 | }
|
10301 | }
|
10302 | }
|
10303 | if (codegenNode.isBlock) {
|
10304 | for (let i = 0; i < node.props.length; i++) {
|
10305 | const p = node.props[i];
|
10306 | if (p.type === 7) {
|
10307 | constantCache.set(node, 0);
|
10308 | return 0;
|
10309 | }
|
10310 | }
|
10311 | context.removeHelper(OPEN_BLOCK);
|
10312 | context.removeHelper(
|
10313 | getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
|
10314 | );
|
10315 | codegenNode.isBlock = false;
|
10316 | context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
|
10317 | }
|
10318 | constantCache.set(node, returnType2);
|
10319 | return returnType2;
|
10320 | } else {
|
10321 | constantCache.set(node, 0);
|
10322 | return 0;
|
10323 | }
|
10324 | case 2:
|
10325 | case 3:
|
10326 | return 3;
|
10327 | case 9:
|
10328 | case 11:
|
10329 | case 10:
|
10330 | return 0;
|
10331 | case 5:
|
10332 | case 12:
|
10333 | return getConstantType(node.content, context);
|
10334 | case 4:
|
10335 | return node.constType;
|
10336 | case 8:
|
10337 | let returnType = 3;
|
10338 | for (let i = 0; i < node.children.length; i++) {
|
10339 | const child = node.children[i];
|
10340 | if (isString(child) || isSymbol(child)) {
|
10341 | continue;
|
10342 | }
|
10343 | const childType = getConstantType(child, context);
|
10344 | if (childType === 0) {
|
10345 | return 0;
|
10346 | } else if (childType < returnType) {
|
10347 | returnType = childType;
|
10348 | }
|
10349 | }
|
10350 | return returnType;
|
10351 | default:
|
10352 | return 0;
|
10353 | }
|
10354 | }
|
10355 | const allowHoistedHelperSet = new Set([
|
10356 | NORMALIZE_CLASS,
|
10357 | NORMALIZE_STYLE,
|
10358 | NORMALIZE_PROPS,
|
10359 | GUARD_REACTIVE_PROPS
|
10360 | ]);
|
10361 | function getConstantTypeOfHelperCall(value, context) {
|
10362 | if (value.type === 14 && !isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
|
10363 | const arg = value.arguments[0];
|
10364 | if (arg.type === 4) {
|
10365 | return getConstantType(arg, context);
|
10366 | } else if (arg.type === 14) {
|
10367 | return getConstantTypeOfHelperCall(arg, context);
|
10368 | }
|
10369 | }
|
10370 | return 0;
|
10371 | }
|
10372 | function getGeneratedPropsConstantType(node, context) {
|
10373 | let returnType = 3;
|
10374 | const props = getNodeProps(node);
|
10375 | if (props && props.type === 15) {
|
10376 | const { properties } = props;
|
10377 | for (let i = 0; i < properties.length; i++) {
|
10378 | const { key, value } = properties[i];
|
10379 | const keyType = getConstantType(key, context);
|
10380 | if (keyType === 0) {
|
10381 | return keyType;
|
10382 | }
|
10383 | if (keyType < returnType) {
|
10384 | returnType = keyType;
|
10385 | }
|
10386 | let valueType;
|
10387 | if (value.type === 4) {
|
10388 | valueType = getConstantType(value, context);
|
10389 | } else if (value.type === 14) {
|
10390 | valueType = getConstantTypeOfHelperCall(value, context);
|
10391 | } else {
|
10392 | valueType = 0;
|
10393 | }
|
10394 | if (valueType === 0) {
|
10395 | return valueType;
|
10396 | }
|
10397 | if (valueType < returnType) {
|
10398 | returnType = valueType;
|
10399 | }
|
10400 | }
|
10401 | }
|
10402 | return returnType;
|
10403 | }
|
10404 | function getNodeProps(node) {
|
10405 | const codegenNode = node.codegenNode;
|
10406 | if (codegenNode.type === 13) {
|
10407 | return codegenNode.props;
|
10408 | }
|
10409 | }
|
10410 | function getPatchFlag(node) {
|
10411 | const flag = node.patchFlag;
|
10412 | return flag ? parseInt(flag, 10) : void 0;
|
10413 | }
|
10414 |
|
10415 | function createTransformContext(root, {
|
10416 | filename = "",
|
10417 | prefixIdentifiers = false,
|
10418 | hoistStatic: hoistStatic2 = false,
|
10419 | hmr = false,
|
10420 | cacheHandlers = false,
|
10421 | nodeTransforms = [],
|
10422 | directiveTransforms = {},
|
10423 | transformHoist = null,
|
10424 | isBuiltInComponent = NOOP,
|
10425 | isCustomElement = NOOP,
|
10426 | expressionPlugins = [],
|
10427 | scopeId = null,
|
10428 | slotted = true,
|
10429 | ssr = false,
|
10430 | inSSR = false,
|
10431 | ssrCssVars = ``,
|
10432 | bindingMetadata = EMPTY_OBJ,
|
10433 | inline = false,
|
10434 | isTS = false,
|
10435 | onError = defaultOnError,
|
10436 | onWarn = defaultOnWarn,
|
10437 | compatConfig
|
10438 | }) {
|
10439 | const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
|
10440 | const context = {
|
10441 |
|
10442 | filename,
|
10443 | selfName: nameMatch && capitalize(camelize(nameMatch[1])),
|
10444 | prefixIdentifiers,
|
10445 | hoistStatic: hoistStatic2,
|
10446 | hmr,
|
10447 | cacheHandlers,
|
10448 | nodeTransforms,
|
10449 | directiveTransforms,
|
10450 | transformHoist,
|
10451 | isBuiltInComponent,
|
10452 | isCustomElement,
|
10453 | expressionPlugins,
|
10454 | scopeId,
|
10455 | slotted,
|
10456 | ssr,
|
10457 | inSSR,
|
10458 | ssrCssVars,
|
10459 | bindingMetadata,
|
10460 | inline,
|
10461 | isTS,
|
10462 | onError,
|
10463 | onWarn,
|
10464 | compatConfig,
|
10465 |
|
10466 | root,
|
10467 | helpers: new Map(),
|
10468 | components: new Set(),
|
10469 | directives: new Set(),
|
10470 | hoists: [],
|
10471 | imports: [],
|
10472 | constantCache: new WeakMap(),
|
10473 | temps: 0,
|
10474 | cached: 0,
|
10475 | identifiers: Object.create(null),
|
10476 | scopes: {
|
10477 | vFor: 0,
|
10478 | vSlot: 0,
|
10479 | vPre: 0,
|
10480 | vOnce: 0
|
10481 | },
|
10482 | parent: null,
|
10483 | grandParent: null,
|
10484 | currentNode: root,
|
10485 | childIndex: 0,
|
10486 | inVOnce: false,
|
10487 |
|
10488 | helper(name) {
|
10489 | const count = context.helpers.get(name) || 0;
|
10490 | context.helpers.set(name, count + 1);
|
10491 | return name;
|
10492 | },
|
10493 | removeHelper(name) {
|
10494 | const count = context.helpers.get(name);
|
10495 | if (count) {
|
10496 | const currentCount = count - 1;
|
10497 | if (!currentCount) {
|
10498 | context.helpers.delete(name);
|
10499 | } else {
|
10500 | context.helpers.set(name, currentCount);
|
10501 | }
|
10502 | }
|
10503 | },
|
10504 | helperString(name) {
|
10505 | return `_${helperNameMap[context.helper(name)]}`;
|
10506 | },
|
10507 | replaceNode(node) {
|
10508 | {
|
10509 | if (!context.currentNode) {
|
10510 | throw new Error(`Node being replaced is already removed.`);
|
10511 | }
|
10512 | if (!context.parent) {
|
10513 | throw new Error(`Cannot replace root node.`);
|
10514 | }
|
10515 | }
|
10516 | context.parent.children[context.childIndex] = context.currentNode = node;
|
10517 | },
|
10518 | removeNode(node) {
|
10519 | if (!context.parent) {
|
10520 | throw new Error(`Cannot remove root node.`);
|
10521 | }
|
10522 | const list = context.parent.children;
|
10523 | const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
|
10524 | if (removalIndex < 0) {
|
10525 | throw new Error(`node being removed is not a child of current parent`);
|
10526 | }
|
10527 | if (!node || node === context.currentNode) {
|
10528 | context.currentNode = null;
|
10529 | context.onNodeRemoved();
|
10530 | } else {
|
10531 | if (context.childIndex > removalIndex) {
|
10532 | context.childIndex--;
|
10533 | context.onNodeRemoved();
|
10534 | }
|
10535 | }
|
10536 | context.parent.children.splice(removalIndex, 1);
|
10537 | },
|
10538 | onNodeRemoved: NOOP,
|
10539 | addIdentifiers(exp) {
|
10540 | },
|
10541 | removeIdentifiers(exp) {
|
10542 | },
|
10543 | hoist(exp) {
|
10544 | if (isString(exp))
|
10545 | exp = createSimpleExpression(exp);
|
10546 | context.hoists.push(exp);
|
10547 | const identifier = createSimpleExpression(
|
10548 | `_hoisted_${context.hoists.length}`,
|
10549 | false,
|
10550 | exp.loc,
|
10551 | 2
|
10552 | );
|
10553 | identifier.hoisted = exp;
|
10554 | return identifier;
|
10555 | },
|
10556 | cache(exp, isVNode = false) {
|
10557 | return createCacheExpression(context.cached++, exp, isVNode);
|
10558 | }
|
10559 | };
|
10560 | {
|
10561 | context.filters = new Set();
|
10562 | }
|
10563 | return context;
|
10564 | }
|
10565 | function transform(root, options) {
|
10566 | const context = createTransformContext(root, options);
|
10567 | traverseNode(root, context);
|
10568 | if (options.hoistStatic) {
|
10569 | hoistStatic(root, context);
|
10570 | }
|
10571 | if (!options.ssr) {
|
10572 | createRootCodegen(root, context);
|
10573 | }
|
10574 | root.helpers = new Set([...context.helpers.keys()]);
|
10575 | root.components = [...context.components];
|
10576 | root.directives = [...context.directives];
|
10577 | root.imports = context.imports;
|
10578 | root.hoists = context.hoists;
|
10579 | root.temps = context.temps;
|
10580 | root.cached = context.cached;
|
10581 | root.transformed = true;
|
10582 | {
|
10583 | root.filters = [...context.filters];
|
10584 | }
|
10585 | }
|
10586 | function createRootCodegen(root, context) {
|
10587 | const { helper } = context;
|
10588 | const { children } = root;
|
10589 | if (children.length === 1) {
|
10590 | const child = children[0];
|
10591 | if (isSingleElementRoot(root, child) && child.codegenNode) {
|
10592 | const codegenNode = child.codegenNode;
|
10593 | if (codegenNode.type === 13) {
|
10594 | convertToBlock(codegenNode, context);
|
10595 | }
|
10596 | root.codegenNode = codegenNode;
|
10597 | } else {
|
10598 | root.codegenNode = child;
|
10599 | }
|
10600 | } else if (children.length > 1) {
|
10601 | let patchFlag = 64;
|
10602 | let patchFlagText = PatchFlagNames[64];
|
10603 | if (children.filter((c) => c.type !== 3).length === 1) {
|
10604 | patchFlag |= 2048;
|
10605 | patchFlagText += `, ${PatchFlagNames[2048]}`;
|
10606 | }
|
10607 | root.codegenNode = createVNodeCall(
|
10608 | context,
|
10609 | helper(FRAGMENT),
|
10610 | void 0,
|
10611 | root.children,
|
10612 | patchFlag + (` /* ${patchFlagText} */` ),
|
10613 | void 0,
|
10614 | void 0,
|
10615 | true,
|
10616 | void 0,
|
10617 | false
|
10618 | );
|
10619 | } else ;
|
10620 | }
|
10621 | function traverseChildren(parent, context) {
|
10622 | let i = 0;
|
10623 | const nodeRemoved = () => {
|
10624 | i--;
|
10625 | };
|
10626 | for (; i < parent.children.length; i++) {
|
10627 | const child = parent.children[i];
|
10628 | if (isString(child))
|
10629 | continue;
|
10630 | context.grandParent = context.parent;
|
10631 | context.parent = parent;
|
10632 | context.childIndex = i;
|
10633 | context.onNodeRemoved = nodeRemoved;
|
10634 | traverseNode(child, context);
|
10635 | }
|
10636 | }
|
10637 | function traverseNode(node, context) {
|
10638 | context.currentNode = node;
|
10639 | const { nodeTransforms } = context;
|
10640 | const exitFns = [];
|
10641 | for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
|
10642 | const onExit = nodeTransforms[i2](node, context);
|
10643 | if (onExit) {
|
10644 | if (isArray(onExit)) {
|
10645 | exitFns.push(...onExit);
|
10646 | } else {
|
10647 | exitFns.push(onExit);
|
10648 | }
|
10649 | }
|
10650 | if (!context.currentNode) {
|
10651 | return;
|
10652 | } else {
|
10653 | node = context.currentNode;
|
10654 | }
|
10655 | }
|
10656 | switch (node.type) {
|
10657 | case 3:
|
10658 | if (!context.ssr) {
|
10659 | context.helper(CREATE_COMMENT);
|
10660 | }
|
10661 | break;
|
10662 | case 5:
|
10663 | if (!context.ssr) {
|
10664 | context.helper(TO_DISPLAY_STRING);
|
10665 | }
|
10666 | break;
|
10667 | case 9:
|
10668 | for (let i2 = 0; i2 < node.branches.length; i2++) {
|
10669 | traverseNode(node.branches[i2], context);
|
10670 | }
|
10671 | break;
|
10672 | case 10:
|
10673 | case 11:
|
10674 | case 1:
|
10675 | case 0:
|
10676 | traverseChildren(node, context);
|
10677 | break;
|
10678 | }
|
10679 | context.currentNode = node;
|
10680 | let i = exitFns.length;
|
10681 | while (i--) {
|
10682 | exitFns[i]();
|
10683 | }
|
10684 | }
|
10685 | function createStructuralDirectiveTransform(name, fn) {
|
10686 | const matches = isString(name) ? (n) => n === name : (n) => name.test(n);
|
10687 | return (node, context) => {
|
10688 | if (node.type === 1) {
|
10689 | const { props } = node;
|
10690 | if (node.tagType === 3 && props.some(isVSlot)) {
|
10691 | return;
|
10692 | }
|
10693 | const exitFns = [];
|
10694 | for (let i = 0; i < props.length; i++) {
|
10695 | const prop = props[i];
|
10696 | if (prop.type === 7 && matches(prop.name)) {
|
10697 | props.splice(i, 1);
|
10698 | i--;
|
10699 | const onExit = fn(node, prop, context);
|
10700 | if (onExit)
|
10701 | exitFns.push(onExit);
|
10702 | }
|
10703 | }
|
10704 | return exitFns;
|
10705 | }
|
10706 | };
|
10707 | }
|
10708 |
|
10709 | const PURE_ANNOTATION = `/*#__PURE__*/`;
|
10710 | const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
|
10711 | function createCodegenContext(ast, {
|
10712 | mode = "function",
|
10713 | prefixIdentifiers = mode === "module",
|
10714 | sourceMap = false,
|
10715 | filename = `template.vue.html`,
|
10716 | scopeId = null,
|
10717 | optimizeImports = false,
|
10718 | runtimeGlobalName = `Vue`,
|
10719 | runtimeModuleName = `vue`,
|
10720 | ssrRuntimeModuleName = "vue/server-renderer",
|
10721 | ssr = false,
|
10722 | isTS = false,
|
10723 | inSSR = false
|
10724 | }) {
|
10725 | const context = {
|
10726 | mode,
|
10727 | prefixIdentifiers,
|
10728 | sourceMap,
|
10729 | filename,
|
10730 | scopeId,
|
10731 | optimizeImports,
|
10732 | runtimeGlobalName,
|
10733 | runtimeModuleName,
|
10734 | ssrRuntimeModuleName,
|
10735 | ssr,
|
10736 | isTS,
|
10737 | inSSR,
|
10738 | source: ast.source,
|
10739 | code: ``,
|
10740 | column: 1,
|
10741 | line: 1,
|
10742 | offset: 0,
|
10743 | indentLevel: 0,
|
10744 | pure: false,
|
10745 | map: void 0,
|
10746 | helper(key) {
|
10747 | return `_${helperNameMap[key]}`;
|
10748 | },
|
10749 | push(code, newlineIndex = -2 , node) {
|
10750 | context.code += code;
|
10751 | },
|
10752 | indent() {
|
10753 | newline(++context.indentLevel);
|
10754 | },
|
10755 | deindent(withoutNewLine = false) {
|
10756 | if (withoutNewLine) {
|
10757 | --context.indentLevel;
|
10758 | } else {
|
10759 | newline(--context.indentLevel);
|
10760 | }
|
10761 | },
|
10762 | newline() {
|
10763 | newline(context.indentLevel);
|
10764 | }
|
10765 | };
|
10766 | function newline(n) {
|
10767 | context.push("\n" + ` `.repeat(n), 0 );
|
10768 | }
|
10769 | return context;
|
10770 | }
|
10771 | function generate(ast, options = {}) {
|
10772 | const context = createCodegenContext(ast, options);
|
10773 | if (options.onContextCreated)
|
10774 | options.onContextCreated(context);
|
10775 | const {
|
10776 | mode,
|
10777 | push,
|
10778 | prefixIdentifiers,
|
10779 | indent,
|
10780 | deindent,
|
10781 | newline,
|
10782 | scopeId,
|
10783 | ssr
|
10784 | } = context;
|
10785 | const helpers = Array.from(ast.helpers);
|
10786 | const hasHelpers = helpers.length > 0;
|
10787 | const useWithBlock = !prefixIdentifiers && mode !== "module";
|
10788 | const preambleContext = context;
|
10789 | {
|
10790 | genFunctionPreamble(ast, preambleContext);
|
10791 | }
|
10792 | const functionName = ssr ? `ssrRender` : `render`;
|
10793 | const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
|
10794 | const signature = args.join(", ");
|
10795 | {
|
10796 | push(`function ${functionName}(${signature}) {`);
|
10797 | }
|
10798 | indent();
|
10799 | if (useWithBlock) {
|
10800 | push(`with (_ctx) {`);
|
10801 | indent();
|
10802 | if (hasHelpers) {
|
10803 | push(
|
10804 | `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
|
10805 | `,
|
10806 | -1
|
10807 | );
|
10808 | newline();
|
10809 | }
|
10810 | }
|
10811 | if (ast.components.length) {
|
10812 | genAssets(ast.components, "component", context);
|
10813 | if (ast.directives.length || ast.temps > 0) {
|
10814 | newline();
|
10815 | }
|
10816 | }
|
10817 | if (ast.directives.length) {
|
10818 | genAssets(ast.directives, "directive", context);
|
10819 | if (ast.temps > 0) {
|
10820 | newline();
|
10821 | }
|
10822 | }
|
10823 | if (ast.filters && ast.filters.length) {
|
10824 | newline();
|
10825 | genAssets(ast.filters, "filter", context);
|
10826 | newline();
|
10827 | }
|
10828 | if (ast.temps > 0) {
|
10829 | push(`let `);
|
10830 | for (let i = 0; i < ast.temps; i++) {
|
10831 | push(`${i > 0 ? `, ` : ``}_temp${i}`);
|
10832 | }
|
10833 | }
|
10834 | if (ast.components.length || ast.directives.length || ast.temps) {
|
10835 | push(`
|
10836 | `, 0 );
|
10837 | newline();
|
10838 | }
|
10839 | if (!ssr) {
|
10840 | push(`return `);
|
10841 | }
|
10842 | if (ast.codegenNode) {
|
10843 | genNode(ast.codegenNode, context);
|
10844 | } else {
|
10845 | push(`null`);
|
10846 | }
|
10847 | if (useWithBlock) {
|
10848 | deindent();
|
10849 | push(`}`);
|
10850 | }
|
10851 | deindent();
|
10852 | push(`}`);
|
10853 | return {
|
10854 | ast,
|
10855 | code: context.code,
|
10856 | preamble: ``,
|
10857 | map: context.map ? context.map.toJSON() : void 0
|
10858 | };
|
10859 | }
|
10860 | function genFunctionPreamble(ast, context) {
|
10861 | const {
|
10862 | ssr,
|
10863 | prefixIdentifiers,
|
10864 | push,
|
10865 | newline,
|
10866 | runtimeModuleName,
|
10867 | runtimeGlobalName,
|
10868 | ssrRuntimeModuleName
|
10869 | } = context;
|
10870 | const VueBinding = runtimeGlobalName;
|
10871 | const helpers = Array.from(ast.helpers);
|
10872 | if (helpers.length > 0) {
|
10873 | {
|
10874 | push(`const _Vue = ${VueBinding}
|
10875 | `, -1 );
|
10876 | if (ast.hoists.length) {
|
10877 | const staticHelpers = [
|
10878 | CREATE_VNODE,
|
10879 | CREATE_ELEMENT_VNODE,
|
10880 | CREATE_COMMENT,
|
10881 | CREATE_TEXT,
|
10882 | CREATE_STATIC
|
10883 | ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
|
10884 | push(`const { ${staticHelpers} } = _Vue
|
10885 | `, -1 );
|
10886 | }
|
10887 | }
|
10888 | }
|
10889 | genHoists(ast.hoists, context);
|
10890 | newline();
|
10891 | push(`return `);
|
10892 | }
|
10893 | function genAssets(assets, type, { helper, push, newline, isTS }) {
|
10894 | const resolver = helper(
|
10895 | type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
|
10896 | );
|
10897 | for (let i = 0; i < assets.length; i++) {
|
10898 | let id = assets[i];
|
10899 | const maybeSelfReference = id.endsWith("__self");
|
10900 | if (maybeSelfReference) {
|
10901 | id = id.slice(0, -6);
|
10902 | }
|
10903 | push(
|
10904 | `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
|
10905 | );
|
10906 | if (i < assets.length - 1) {
|
10907 | newline();
|
10908 | }
|
10909 | }
|
10910 | }
|
10911 | function genHoists(hoists, context) {
|
10912 | if (!hoists.length) {
|
10913 | return;
|
10914 | }
|
10915 | context.pure = true;
|
10916 | const { push, newline, helper, scopeId, mode } = context;
|
10917 | newline();
|
10918 | for (let i = 0; i < hoists.length; i++) {
|
10919 | const exp = hoists[i];
|
10920 | if (exp) {
|
10921 | push(
|
10922 | `const _hoisted_${i + 1} = ${``}`
|
10923 | );
|
10924 | genNode(exp, context);
|
10925 | newline();
|
10926 | }
|
10927 | }
|
10928 | context.pure = false;
|
10929 | }
|
10930 | function isText(n) {
|
10931 | return isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
|
10932 | }
|
10933 | function genNodeListAsArray(nodes, context) {
|
10934 | const multilines = nodes.length > 3 || nodes.some((n) => isArray(n) || !isText(n));
|
10935 | context.push(`[`);
|
10936 | multilines && context.indent();
|
10937 | genNodeList(nodes, context, multilines);
|
10938 | multilines && context.deindent();
|
10939 | context.push(`]`);
|
10940 | }
|
10941 | function genNodeList(nodes, context, multilines = false, comma = true) {
|
10942 | const { push, newline } = context;
|
10943 | for (let i = 0; i < nodes.length; i++) {
|
10944 | const node = nodes[i];
|
10945 | if (isString(node)) {
|
10946 | push(node, -3 );
|
10947 | } else if (isArray(node)) {
|
10948 | genNodeListAsArray(node, context);
|
10949 | } else {
|
10950 | genNode(node, context);
|
10951 | }
|
10952 | if (i < nodes.length - 1) {
|
10953 | if (multilines) {
|
10954 | comma && push(",");
|
10955 | newline();
|
10956 | } else {
|
10957 | comma && push(", ");
|
10958 | }
|
10959 | }
|
10960 | }
|
10961 | }
|
10962 | function genNode(node, context) {
|
10963 | if (isString(node)) {
|
10964 | context.push(node, -3 );
|
10965 | return;
|
10966 | }
|
10967 | if (isSymbol(node)) {
|
10968 | context.push(context.helper(node));
|
10969 | return;
|
10970 | }
|
10971 | switch (node.type) {
|
10972 | case 1:
|
10973 | case 9:
|
10974 | case 11:
|
10975 | assert(
|
10976 | node.codegenNode != null,
|
10977 | `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
|
10978 | );
|
10979 | genNode(node.codegenNode, context);
|
10980 | break;
|
10981 | case 2:
|
10982 | genText(node, context);
|
10983 | break;
|
10984 | case 4:
|
10985 | genExpression(node, context);
|
10986 | break;
|
10987 | case 5:
|
10988 | genInterpolation(node, context);
|
10989 | break;
|
10990 | case 12:
|
10991 | genNode(node.codegenNode, context);
|
10992 | break;
|
10993 | case 8:
|
10994 | genCompoundExpression(node, context);
|
10995 | break;
|
10996 | case 3:
|
10997 | genComment(node, context);
|
10998 | break;
|
10999 | case 13:
|
11000 | genVNodeCall(node, context);
|
11001 | break;
|
11002 | case 14:
|
11003 | genCallExpression(node, context);
|
11004 | break;
|
11005 | case 15:
|
11006 | genObjectExpression(node, context);
|
11007 | break;
|
11008 | case 17:
|
11009 | genArrayExpression(node, context);
|
11010 | break;
|
11011 | case 18:
|
11012 | genFunctionExpression(node, context);
|
11013 | break;
|
11014 | case 19:
|
11015 | genConditionalExpression(node, context);
|
11016 | break;
|
11017 | case 20:
|
11018 | genCacheExpression(node, context);
|
11019 | break;
|
11020 | case 21:
|
11021 | genNodeList(node.body, context, true, false);
|
11022 | break;
|
11023 | case 22:
|
11024 | break;
|
11025 | case 23:
|
11026 | break;
|
11027 | case 24:
|
11028 | break;
|
11029 | case 25:
|
11030 | break;
|
11031 | case 26:
|
11032 | break;
|
11033 | case 10:
|
11034 | break;
|
11035 | default:
|
11036 | {
|
11037 | assert(false, `unhandled codegen node type: ${node.type}`);
|
11038 | const exhaustiveCheck = node;
|
11039 | return exhaustiveCheck;
|
11040 | }
|
11041 | }
|
11042 | }
|
11043 | function genText(node, context) {
|
11044 | context.push(JSON.stringify(node.content), -3 , node);
|
11045 | }
|
11046 | function genExpression(node, context) {
|
11047 | const { content, isStatic } = node;
|
11048 | context.push(
|
11049 | isStatic ? JSON.stringify(content) : content,
|
11050 | -3 ,
|
11051 | node
|
11052 | );
|
11053 | }
|
11054 | function genInterpolation(node, context) {
|
11055 | const { push, helper, pure } = context;
|
11056 | if (pure)
|
11057 | push(PURE_ANNOTATION);
|
11058 | push(`${helper(TO_DISPLAY_STRING)}(`);
|
11059 | genNode(node.content, context);
|
11060 | push(`)`);
|
11061 | }
|
11062 | function genCompoundExpression(node, context) {
|
11063 | for (let i = 0; i < node.children.length; i++) {
|
11064 | const child = node.children[i];
|
11065 | if (isString(child)) {
|
11066 | context.push(child, -3 );
|
11067 | } else {
|
11068 | genNode(child, context);
|
11069 | }
|
11070 | }
|
11071 | }
|
11072 | function genExpressionAsPropertyKey(node, context) {
|
11073 | const { push } = context;
|
11074 | if (node.type === 8) {
|
11075 | push(`[`);
|
11076 | genCompoundExpression(node, context);
|
11077 | push(`]`);
|
11078 | } else if (node.isStatic) {
|
11079 | const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
|
11080 | push(text, -2 , node);
|
11081 | } else {
|
11082 | push(`[${node.content}]`, -3 , node);
|
11083 | }
|
11084 | }
|
11085 | function genComment(node, context) {
|
11086 | const { push, helper, pure } = context;
|
11087 | if (pure) {
|
11088 | push(PURE_ANNOTATION);
|
11089 | }
|
11090 | push(
|
11091 | `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
|
11092 | -3 ,
|
11093 | node
|
11094 | );
|
11095 | }
|
11096 | function genVNodeCall(node, context) {
|
11097 | const { push, helper, pure } = context;
|
11098 | const {
|
11099 | tag,
|
11100 | props,
|
11101 | children,
|
11102 | patchFlag,
|
11103 | dynamicProps,
|
11104 | directives,
|
11105 | isBlock,
|
11106 | disableTracking,
|
11107 | isComponent
|
11108 | } = node;
|
11109 | if (directives) {
|
11110 | push(helper(WITH_DIRECTIVES) + `(`);
|
11111 | }
|
11112 | if (isBlock) {
|
11113 | push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
|
11114 | }
|
11115 | if (pure) {
|
11116 | push(PURE_ANNOTATION);
|
11117 | }
|
11118 | const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
|
11119 | push(helper(callHelper) + `(`, -2 , node);
|
11120 | genNodeList(
|
11121 | genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
|
11122 | context
|
11123 | );
|
11124 | push(`)`);
|
11125 | if (isBlock) {
|
11126 | push(`)`);
|
11127 | }
|
11128 | if (directives) {
|
11129 | push(`, `);
|
11130 | genNode(directives, context);
|
11131 | push(`)`);
|
11132 | }
|
11133 | }
|
11134 | function genNullableArgs(args) {
|
11135 | let i = args.length;
|
11136 | while (i--) {
|
11137 | if (args[i] != null)
|
11138 | break;
|
11139 | }
|
11140 | return args.slice(0, i + 1).map((arg) => arg || `null`);
|
11141 | }
|
11142 | function genCallExpression(node, context) {
|
11143 | const { push, helper, pure } = context;
|
11144 | const callee = isString(node.callee) ? node.callee : helper(node.callee);
|
11145 | if (pure) {
|
11146 | push(PURE_ANNOTATION);
|
11147 | }
|
11148 | push(callee + `(`, -2 , node);
|
11149 | genNodeList(node.arguments, context);
|
11150 | push(`)`);
|
11151 | }
|
11152 | function genObjectExpression(node, context) {
|
11153 | const { push, indent, deindent, newline } = context;
|
11154 | const { properties } = node;
|
11155 | if (!properties.length) {
|
11156 | push(`{}`, -2 , node);
|
11157 | return;
|
11158 | }
|
11159 | const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
|
11160 | push(multilines ? `{` : `{ `);
|
11161 | multilines && indent();
|
11162 | for (let i = 0; i < properties.length; i++) {
|
11163 | const { key, value } = properties[i];
|
11164 | genExpressionAsPropertyKey(key, context);
|
11165 | push(`: `);
|
11166 | genNode(value, context);
|
11167 | if (i < properties.length - 1) {
|
11168 | push(`,`);
|
11169 | newline();
|
11170 | }
|
11171 | }
|
11172 | multilines && deindent();
|
11173 | push(multilines ? `}` : ` }`);
|
11174 | }
|
11175 | function genArrayExpression(node, context) {
|
11176 | genNodeListAsArray(node.elements, context);
|
11177 | }
|
11178 | function genFunctionExpression(node, context) {
|
11179 | const { push, indent, deindent } = context;
|
11180 | const { params, returns, body, newline, isSlot } = node;
|
11181 | if (isSlot) {
|
11182 | push(`_${helperNameMap[WITH_CTX]}(`);
|
11183 | }
|
11184 | push(`(`, -2 , node);
|
11185 | if (isArray(params)) {
|
11186 | genNodeList(params, context);
|
11187 | } else if (params) {
|
11188 | genNode(params, context);
|
11189 | }
|
11190 | push(`) => `);
|
11191 | if (newline || body) {
|
11192 | push(`{`);
|
11193 | indent();
|
11194 | }
|
11195 | if (returns) {
|
11196 | if (newline) {
|
11197 | push(`return `);
|
11198 | }
|
11199 | if (isArray(returns)) {
|
11200 | genNodeListAsArray(returns, context);
|
11201 | } else {
|
11202 | genNode(returns, context);
|
11203 | }
|
11204 | } else if (body) {
|
11205 | genNode(body, context);
|
11206 | }
|
11207 | if (newline || body) {
|
11208 | deindent();
|
11209 | push(`}`);
|
11210 | }
|
11211 | if (isSlot) {
|
11212 | if (node.isNonScopedSlot) {
|
11213 | push(`, undefined, true`);
|
11214 | }
|
11215 | push(`)`);
|
11216 | }
|
11217 | }
|
11218 | function genConditionalExpression(node, context) {
|
11219 | const { test, consequent, alternate, newline: needNewline } = node;
|
11220 | const { push, indent, deindent, newline } = context;
|
11221 | if (test.type === 4) {
|
11222 | const needsParens = !isSimpleIdentifier(test.content);
|
11223 | needsParens && push(`(`);
|
11224 | genExpression(test, context);
|
11225 | needsParens && push(`)`);
|
11226 | } else {
|
11227 | push(`(`);
|
11228 | genNode(test, context);
|
11229 | push(`)`);
|
11230 | }
|
11231 | needNewline && indent();
|
11232 | context.indentLevel++;
|
11233 | needNewline || push(` `);
|
11234 | push(`? `);
|
11235 | genNode(consequent, context);
|
11236 | context.indentLevel--;
|
11237 | needNewline && newline();
|
11238 | needNewline || push(` `);
|
11239 | push(`: `);
|
11240 | const isNested = alternate.type === 19;
|
11241 | if (!isNested) {
|
11242 | context.indentLevel++;
|
11243 | }
|
11244 | genNode(alternate, context);
|
11245 | if (!isNested) {
|
11246 | context.indentLevel--;
|
11247 | }
|
11248 | needNewline && deindent(
|
11249 | true
|
11250 |
|
11251 | );
|
11252 | }
|
11253 | function genCacheExpression(node, context) {
|
11254 | const { push, helper, indent, deindent, newline } = context;
|
11255 | push(`_cache[${node.index}] || (`);
|
11256 | if (node.isVNode) {
|
11257 | indent();
|
11258 | push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
|
11259 | newline();
|
11260 | }
|
11261 | push(`_cache[${node.index}] = `);
|
11262 | genNode(node.value, context);
|
11263 | if (node.isVNode) {
|
11264 | push(`,`);
|
11265 | newline();
|
11266 | push(`${helper(SET_BLOCK_TRACKING)}(1),`);
|
11267 | newline();
|
11268 | push(`_cache[${node.index}]`);
|
11269 | deindent();
|
11270 | }
|
11271 | push(`)`);
|
11272 | }
|
11273 |
|
11274 | const prohibitedKeywordRE = new RegExp(
|
11275 | "\\b" + "arguments,await,break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,finally,for,function,if,import,let,new,return,super,switch,throw,try,var,void,while,with,yield".split(",").join("\\b|\\b") + "\\b"
|
11276 | );
|
11277 | const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
|
11278 | function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
|
11279 | const exp = node.content;
|
11280 | if (!exp.trim()) {
|
11281 | return;
|
11282 | }
|
11283 | try {
|
11284 | new Function(
|
11285 | asRawStatements ? ` ${exp} ` : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`
|
11286 | );
|
11287 | } catch (e) {
|
11288 | let message = e.message;
|
11289 | const keywordMatch = exp.replace(stripStringRE, "").match(prohibitedKeywordRE);
|
11290 | if (keywordMatch) {
|
11291 | message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
|
11292 | }
|
11293 | context.onError(
|
11294 | createCompilerError(
|
11295 | 45,
|
11296 | node.loc,
|
11297 | void 0,
|
11298 | message
|
11299 | )
|
11300 | );
|
11301 | }
|
11302 | }
|
11303 |
|
11304 | const transformExpression = (node, context) => {
|
11305 | if (node.type === 5) {
|
11306 | node.content = processExpression(
|
11307 | node.content,
|
11308 | context
|
11309 | );
|
11310 | } else if (node.type === 1) {
|
11311 | for (let i = 0; i < node.props.length; i++) {
|
11312 | const dir = node.props[i];
|
11313 | if (dir.type === 7 && dir.name !== "for") {
|
11314 | const exp = dir.exp;
|
11315 | const arg = dir.arg;
|
11316 | if (exp && exp.type === 4 && !(dir.name === "on" && arg)) {
|
11317 | dir.exp = processExpression(
|
11318 | exp,
|
11319 | context,
|
11320 |
|
11321 | dir.name === "slot"
|
11322 | );
|
11323 | }
|
11324 | if (arg && arg.type === 4 && !arg.isStatic) {
|
11325 | dir.arg = processExpression(arg, context);
|
11326 | }
|
11327 | }
|
11328 | }
|
11329 | }
|
11330 | };
|
11331 | function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
11332 | {
|
11333 | {
|
11334 | validateBrowserExpression(node, context, asParams, asRawStatements);
|
11335 | }
|
11336 | return node;
|
11337 | }
|
11338 | }
|
11339 |
|
11340 | const transformIf = createStructuralDirectiveTransform(
|
11341 | /^(if|else|else-if)$/,
|
11342 | (node, dir, context) => {
|
11343 | return processIf(node, dir, context, (ifNode, branch, isRoot) => {
|
11344 | const siblings = context.parent.children;
|
11345 | let i = siblings.indexOf(ifNode);
|
11346 | let key = 0;
|
11347 | while (i-- >= 0) {
|
11348 | const sibling = siblings[i];
|
11349 | if (sibling && sibling.type === 9) {
|
11350 | key += sibling.branches.length;
|
11351 | }
|
11352 | }
|
11353 | return () => {
|
11354 | if (isRoot) {
|
11355 | ifNode.codegenNode = createCodegenNodeForBranch(
|
11356 | branch,
|
11357 | key,
|
11358 | context
|
11359 | );
|
11360 | } else {
|
11361 | const parentCondition = getParentCondition(ifNode.codegenNode);
|
11362 | parentCondition.alternate = createCodegenNodeForBranch(
|
11363 | branch,
|
11364 | key + ifNode.branches.length - 1,
|
11365 | context
|
11366 | );
|
11367 | }
|
11368 | };
|
11369 | });
|
11370 | }
|
11371 | );
|
11372 | function processIf(node, dir, context, processCodegen) {
|
11373 | if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
|
11374 | const loc = dir.exp ? dir.exp.loc : node.loc;
|
11375 | context.onError(
|
11376 | createCompilerError(28, dir.loc)
|
11377 | );
|
11378 | dir.exp = createSimpleExpression(`true`, false, loc);
|
11379 | }
|
11380 | if (dir.exp) {
|
11381 | validateBrowserExpression(dir.exp, context);
|
11382 | }
|
11383 | if (dir.name === "if") {
|
11384 | const branch = createIfBranch(node, dir);
|
11385 | const ifNode = {
|
11386 | type: 9,
|
11387 | loc: node.loc,
|
11388 | branches: [branch]
|
11389 | };
|
11390 | context.replaceNode(ifNode);
|
11391 | if (processCodegen) {
|
11392 | return processCodegen(ifNode, branch, true);
|
11393 | }
|
11394 | } else {
|
11395 | const siblings = context.parent.children;
|
11396 | const comments = [];
|
11397 | let i = siblings.indexOf(node);
|
11398 | while (i-- >= -1) {
|
11399 | const sibling = siblings[i];
|
11400 | if (sibling && sibling.type === 3) {
|
11401 | context.removeNode(sibling);
|
11402 | comments.unshift(sibling);
|
11403 | continue;
|
11404 | }
|
11405 | if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
|
11406 | context.removeNode(sibling);
|
11407 | continue;
|
11408 | }
|
11409 | if (sibling && sibling.type === 9) {
|
11410 | if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
|
11411 | context.onError(
|
11412 | createCompilerError(30, node.loc)
|
11413 | );
|
11414 | }
|
11415 | context.removeNode();
|
11416 | const branch = createIfBranch(node, dir);
|
11417 | if (comments.length &&
|
11418 | !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
|
11419 | branch.children = [...comments, ...branch.children];
|
11420 | }
|
11421 | {
|
11422 | const key = branch.userKey;
|
11423 | if (key) {
|
11424 | sibling.branches.forEach(({ userKey }) => {
|
11425 | if (isSameKey(userKey, key)) {
|
11426 | context.onError(
|
11427 | createCompilerError(
|
11428 | 29,
|
11429 | branch.userKey.loc
|
11430 | )
|
11431 | );
|
11432 | }
|
11433 | });
|
11434 | }
|
11435 | }
|
11436 | sibling.branches.push(branch);
|
11437 | const onExit = processCodegen && processCodegen(sibling, branch, false);
|
11438 | traverseNode(branch, context);
|
11439 | if (onExit)
|
11440 | onExit();
|
11441 | context.currentNode = null;
|
11442 | } else {
|
11443 | context.onError(
|
11444 | createCompilerError(30, node.loc)
|
11445 | );
|
11446 | }
|
11447 | break;
|
11448 | }
|
11449 | }
|
11450 | }
|
11451 | function createIfBranch(node, dir) {
|
11452 | const isTemplateIf = node.tagType === 3;
|
11453 | return {
|
11454 | type: 10,
|
11455 | loc: node.loc,
|
11456 | condition: dir.name === "else" ? void 0 : dir.exp,
|
11457 | children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
|
11458 | userKey: findProp(node, `key`),
|
11459 | isTemplateIf
|
11460 | };
|
11461 | }
|
11462 | function createCodegenNodeForBranch(branch, keyIndex, context) {
|
11463 | if (branch.condition) {
|
11464 | return createConditionalExpression(
|
11465 | branch.condition,
|
11466 | createChildrenCodegenNode(branch, keyIndex, context),
|
11467 |
|
11468 |
|
11469 | createCallExpression(context.helper(CREATE_COMMENT), [
|
11470 | '"v-if"' ,
|
11471 | "true"
|
11472 | ])
|
11473 | );
|
11474 | } else {
|
11475 | return createChildrenCodegenNode(branch, keyIndex, context);
|
11476 | }
|
11477 | }
|
11478 | function createChildrenCodegenNode(branch, keyIndex, context) {
|
11479 | const { helper } = context;
|
11480 | const keyProperty = createObjectProperty(
|
11481 | `key`,
|
11482 | createSimpleExpression(
|
11483 | `${keyIndex}`,
|
11484 | false,
|
11485 | locStub,
|
11486 | 2
|
11487 | )
|
11488 | );
|
11489 | const { children } = branch;
|
11490 | const firstChild = children[0];
|
11491 | const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
|
11492 | if (needFragmentWrapper) {
|
11493 | if (children.length === 1 && firstChild.type === 11) {
|
11494 | const vnodeCall = firstChild.codegenNode;
|
11495 | injectProp(vnodeCall, keyProperty, context);
|
11496 | return vnodeCall;
|
11497 | } else {
|
11498 | let patchFlag = 64;
|
11499 | let patchFlagText = PatchFlagNames[64];
|
11500 | if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
|
11501 | patchFlag |= 2048;
|
11502 | patchFlagText += `, ${PatchFlagNames[2048]}`;
|
11503 | }
|
11504 | return createVNodeCall(
|
11505 | context,
|
11506 | helper(FRAGMENT),
|
11507 | createObjectExpression([keyProperty]),
|
11508 | children,
|
11509 | patchFlag + (` /* ${patchFlagText} */` ),
|
11510 | void 0,
|
11511 | void 0,
|
11512 | true,
|
11513 | false,
|
11514 | false,
|
11515 | branch.loc
|
11516 | );
|
11517 | }
|
11518 | } else {
|
11519 | const ret = firstChild.codegenNode;
|
11520 | const vnodeCall = getMemoedVNodeCall(ret);
|
11521 | if (vnodeCall.type === 13) {
|
11522 | convertToBlock(vnodeCall, context);
|
11523 | }
|
11524 | injectProp(vnodeCall, keyProperty, context);
|
11525 | return ret;
|
11526 | }
|
11527 | }
|
11528 | function isSameKey(a, b) {
|
11529 | if (!a || a.type !== b.type) {
|
11530 | return false;
|
11531 | }
|
11532 | if (a.type === 6) {
|
11533 | if (a.value.content !== b.value.content) {
|
11534 | return false;
|
11535 | }
|
11536 | } else {
|
11537 | const exp = a.exp;
|
11538 | const branchExp = b.exp;
|
11539 | if (exp.type !== branchExp.type) {
|
11540 | return false;
|
11541 | }
|
11542 | if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
|
11543 | return false;
|
11544 | }
|
11545 | }
|
11546 | return true;
|
11547 | }
|
11548 | function getParentCondition(node) {
|
11549 | while (true) {
|
11550 | if (node.type === 19) {
|
11551 | if (node.alternate.type === 19) {
|
11552 | node = node.alternate;
|
11553 | } else {
|
11554 | return node;
|
11555 | }
|
11556 | } else if (node.type === 20) {
|
11557 | node = node.value;
|
11558 | }
|
11559 | }
|
11560 | }
|
11561 |
|
11562 | const transformFor = createStructuralDirectiveTransform(
|
11563 | "for",
|
11564 | (node, dir, context) => {
|
11565 | const { helper, removeHelper } = context;
|
11566 | return processFor(node, dir, context, (forNode) => {
|
11567 | const renderExp = createCallExpression(helper(RENDER_LIST), [
|
11568 | forNode.source
|
11569 | ]);
|
11570 | const isTemplate = isTemplateNode(node);
|
11571 | const memo = findDir(node, "memo");
|
11572 | const keyProp = findProp(node, `key`);
|
11573 | const keyExp = keyProp && (keyProp.type === 6 ? createSimpleExpression(keyProp.value.content, true) : keyProp.exp);
|
11574 | const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
|
11575 | const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
|
11576 | const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
|
11577 | forNode.codegenNode = createVNodeCall(
|
11578 | context,
|
11579 | helper(FRAGMENT),
|
11580 | void 0,
|
11581 | renderExp,
|
11582 | fragmentFlag + (` /* ${PatchFlagNames[fragmentFlag]} */` ),
|
11583 | void 0,
|
11584 | void 0,
|
11585 | true,
|
11586 | !isStableFragment,
|
11587 | false,
|
11588 | node.loc
|
11589 | );
|
11590 | return () => {
|
11591 | let childBlock;
|
11592 | const { children } = forNode;
|
11593 | if (isTemplate) {
|
11594 | node.children.some((c) => {
|
11595 | if (c.type === 1) {
|
11596 | const key = findProp(c, "key");
|
11597 | if (key) {
|
11598 | context.onError(
|
11599 | createCompilerError(
|
11600 | 33,
|
11601 | key.loc
|
11602 | )
|
11603 | );
|
11604 | return true;
|
11605 | }
|
11606 | }
|
11607 | });
|
11608 | }
|
11609 | const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
|
11610 | const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
|
11611 | if (slotOutlet) {
|
11612 | childBlock = slotOutlet.codegenNode;
|
11613 | if (isTemplate && keyProperty) {
|
11614 | injectProp(childBlock, keyProperty, context);
|
11615 | }
|
11616 | } else if (needFragmentWrapper) {
|
11617 | childBlock = createVNodeCall(
|
11618 | context,
|
11619 | helper(FRAGMENT),
|
11620 | keyProperty ? createObjectExpression([keyProperty]) : void 0,
|
11621 | node.children,
|
11622 | 64 + (` /* ${PatchFlagNames[64]} */` ),
|
11623 | void 0,
|
11624 | void 0,
|
11625 | true,
|
11626 | void 0,
|
11627 | false
|
11628 | );
|
11629 | } else {
|
11630 | childBlock = children[0].codegenNode;
|
11631 | if (isTemplate && keyProperty) {
|
11632 | injectProp(childBlock, keyProperty, context);
|
11633 | }
|
11634 | if (childBlock.isBlock !== !isStableFragment) {
|
11635 | if (childBlock.isBlock) {
|
11636 | removeHelper(OPEN_BLOCK);
|
11637 | removeHelper(
|
11638 | getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
|
11639 | );
|
11640 | } else {
|
11641 | removeHelper(
|
11642 | getVNodeHelper(context.inSSR, childBlock.isComponent)
|
11643 | );
|
11644 | }
|
11645 | }
|
11646 | childBlock.isBlock = !isStableFragment;
|
11647 | if (childBlock.isBlock) {
|
11648 | helper(OPEN_BLOCK);
|
11649 | helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
|
11650 | } else {
|
11651 | helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
|
11652 | }
|
11653 | }
|
11654 | if (memo) {
|
11655 | const loop = createFunctionExpression(
|
11656 | createForLoopParams(forNode.parseResult, [
|
11657 | createSimpleExpression(`_cached`)
|
11658 | ])
|
11659 | );
|
11660 | loop.body = createBlockStatement([
|
11661 | createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
|
11662 | createCompoundExpression([
|
11663 | `if (_cached`,
|
11664 | ...keyExp ? [` && _cached.key === `, keyExp] : [],
|
11665 | ` && ${context.helperString(
|
11666 | IS_MEMO_SAME
|
11667 | )}(_cached, _memo)) return _cached`
|
11668 | ]),
|
11669 | createCompoundExpression([`const _item = `, childBlock]),
|
11670 | createSimpleExpression(`_item.memo = _memo`),
|
11671 | createSimpleExpression(`return _item`)
|
11672 | ]);
|
11673 | renderExp.arguments.push(
|
11674 | loop,
|
11675 | createSimpleExpression(`_cache`),
|
11676 | createSimpleExpression(String(context.cached++))
|
11677 | );
|
11678 | } else {
|
11679 | renderExp.arguments.push(
|
11680 | createFunctionExpression(
|
11681 | createForLoopParams(forNode.parseResult),
|
11682 | childBlock,
|
11683 | true
|
11684 | )
|
11685 | );
|
11686 | }
|
11687 | };
|
11688 | });
|
11689 | }
|
11690 | );
|
11691 | function processFor(node, dir, context, processCodegen) {
|
11692 | if (!dir.exp) {
|
11693 | context.onError(
|
11694 | createCompilerError(31, dir.loc)
|
11695 | );
|
11696 | return;
|
11697 | }
|
11698 | const parseResult = dir.forParseResult;
|
11699 | if (!parseResult) {
|
11700 | context.onError(
|
11701 | createCompilerError(32, dir.loc)
|
11702 | );
|
11703 | return;
|
11704 | }
|
11705 | finalizeForParseResult(parseResult, context);
|
11706 | const { addIdentifiers, removeIdentifiers, scopes } = context;
|
11707 | const { source, value, key, index } = parseResult;
|
11708 | const forNode = {
|
11709 | type: 11,
|
11710 | loc: dir.loc,
|
11711 | source,
|
11712 | valueAlias: value,
|
11713 | keyAlias: key,
|
11714 | objectIndexAlias: index,
|
11715 | parseResult,
|
11716 | children: isTemplateNode(node) ? node.children : [node]
|
11717 | };
|
11718 | context.replaceNode(forNode);
|
11719 | scopes.vFor++;
|
11720 | const onExit = processCodegen && processCodegen(forNode);
|
11721 | return () => {
|
11722 | scopes.vFor--;
|
11723 | if (onExit)
|
11724 | onExit();
|
11725 | };
|
11726 | }
|
11727 | function finalizeForParseResult(result, context) {
|
11728 | if (result.finalized)
|
11729 | return;
|
11730 | {
|
11731 | validateBrowserExpression(result.source, context);
|
11732 | if (result.key) {
|
11733 | validateBrowserExpression(
|
11734 | result.key,
|
11735 | context,
|
11736 | true
|
11737 | );
|
11738 | }
|
11739 | if (result.index) {
|
11740 | validateBrowserExpression(
|
11741 | result.index,
|
11742 | context,
|
11743 | true
|
11744 | );
|
11745 | }
|
11746 | if (result.value) {
|
11747 | validateBrowserExpression(
|
11748 | result.value,
|
11749 | context,
|
11750 | true
|
11751 | );
|
11752 | }
|
11753 | }
|
11754 | result.finalized = true;
|
11755 | }
|
11756 | function createForLoopParams({ value, key, index }, memoArgs = []) {
|
11757 | return createParamsList([value, key, index, ...memoArgs]);
|
11758 | }
|
11759 | function createParamsList(args) {
|
11760 | let i = args.length;
|
11761 | while (i--) {
|
11762 | if (args[i])
|
11763 | break;
|
11764 | }
|
11765 | return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
|
11766 | }
|
11767 |
|
11768 | const defaultFallback = createSimpleExpression(`undefined`, false);
|
11769 | const trackSlotScopes = (node, context) => {
|
11770 | if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
|
11771 | const vSlot = findDir(node, "slot");
|
11772 | if (vSlot) {
|
11773 | vSlot.exp;
|
11774 | context.scopes.vSlot++;
|
11775 | return () => {
|
11776 | context.scopes.vSlot--;
|
11777 | };
|
11778 | }
|
11779 | }
|
11780 | };
|
11781 | const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
|
11782 | props,
|
11783 | children,
|
11784 | false,
|
11785 | true,
|
11786 | children.length ? children[0].loc : loc
|
11787 | );
|
11788 | function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
11789 | context.helper(WITH_CTX);
|
11790 | const { children, loc } = node;
|
11791 | const slotsProperties = [];
|
11792 | const dynamicSlots = [];
|
11793 | let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
|
11794 | const onComponentSlot = findDir(node, "slot", true);
|
11795 | if (onComponentSlot) {
|
11796 | const { arg, exp } = onComponentSlot;
|
11797 | if (arg && !isStaticExp(arg)) {
|
11798 | hasDynamicSlots = true;
|
11799 | }
|
11800 | slotsProperties.push(
|
11801 | createObjectProperty(
|
11802 | arg || createSimpleExpression("default", true),
|
11803 | buildSlotFn(exp, void 0, children, loc)
|
11804 | )
|
11805 | );
|
11806 | }
|
11807 | let hasTemplateSlots = false;
|
11808 | let hasNamedDefaultSlot = false;
|
11809 | const implicitDefaultChildren = [];
|
11810 | const seenSlotNames = new Set();
|
11811 | let conditionalBranchIndex = 0;
|
11812 | for (let i = 0; i < children.length; i++) {
|
11813 | const slotElement = children[i];
|
11814 | let slotDir;
|
11815 | if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
|
11816 | if (slotElement.type !== 3) {
|
11817 | implicitDefaultChildren.push(slotElement);
|
11818 | }
|
11819 | continue;
|
11820 | }
|
11821 | if (onComponentSlot) {
|
11822 | context.onError(
|
11823 | createCompilerError(37, slotDir.loc)
|
11824 | );
|
11825 | break;
|
11826 | }
|
11827 | hasTemplateSlots = true;
|
11828 | const { children: slotChildren, loc: slotLoc } = slotElement;
|
11829 | const {
|
11830 | arg: slotName = createSimpleExpression(`default`, true),
|
11831 | exp: slotProps,
|
11832 | loc: dirLoc
|
11833 | } = slotDir;
|
11834 | let staticSlotName;
|
11835 | if (isStaticExp(slotName)) {
|
11836 | staticSlotName = slotName ? slotName.content : `default`;
|
11837 | } else {
|
11838 | hasDynamicSlots = true;
|
11839 | }
|
11840 | const vFor = findDir(slotElement, "for");
|
11841 | const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
|
11842 | let vIf;
|
11843 | let vElse;
|
11844 | if (vIf = findDir(slotElement, "if")) {
|
11845 | hasDynamicSlots = true;
|
11846 | dynamicSlots.push(
|
11847 | createConditionalExpression(
|
11848 | vIf.exp,
|
11849 | buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
|
11850 | defaultFallback
|
11851 | )
|
11852 | );
|
11853 | } else if (vElse = findDir(
|
11854 | slotElement,
|
11855 | /^else(-if)?$/,
|
11856 | true
|
11857 |
|
11858 | )) {
|
11859 | let j = i;
|
11860 | let prev;
|
11861 | while (j--) {
|
11862 | prev = children[j];
|
11863 | if (prev.type !== 3) {
|
11864 | break;
|
11865 | }
|
11866 | }
|
11867 | if (prev && isTemplateNode(prev) && findDir(prev, "if")) {
|
11868 | children.splice(i, 1);
|
11869 | i--;
|
11870 | let conditional = dynamicSlots[dynamicSlots.length - 1];
|
11871 | while (conditional.alternate.type === 19) {
|
11872 | conditional = conditional.alternate;
|
11873 | }
|
11874 | conditional.alternate = vElse.exp ? createConditionalExpression(
|
11875 | vElse.exp,
|
11876 | buildDynamicSlot(
|
11877 | slotName,
|
11878 | slotFunction,
|
11879 | conditionalBranchIndex++
|
11880 | ),
|
11881 | defaultFallback
|
11882 | ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
|
11883 | } else {
|
11884 | context.onError(
|
11885 | createCompilerError(30, vElse.loc)
|
11886 | );
|
11887 | }
|
11888 | } else if (vFor) {
|
11889 | hasDynamicSlots = true;
|
11890 | const parseResult = vFor.forParseResult;
|
11891 | if (parseResult) {
|
11892 | finalizeForParseResult(parseResult, context);
|
11893 | dynamicSlots.push(
|
11894 | createCallExpression(context.helper(RENDER_LIST), [
|
11895 | parseResult.source,
|
11896 | createFunctionExpression(
|
11897 | createForLoopParams(parseResult),
|
11898 | buildDynamicSlot(slotName, slotFunction),
|
11899 | true
|
11900 | )
|
11901 | ])
|
11902 | );
|
11903 | } else {
|
11904 | context.onError(
|
11905 | createCompilerError(
|
11906 | 32,
|
11907 | vFor.loc
|
11908 | )
|
11909 | );
|
11910 | }
|
11911 | } else {
|
11912 | if (staticSlotName) {
|
11913 | if (seenSlotNames.has(staticSlotName)) {
|
11914 | context.onError(
|
11915 | createCompilerError(
|
11916 | 38,
|
11917 | dirLoc
|
11918 | )
|
11919 | );
|
11920 | continue;
|
11921 | }
|
11922 | seenSlotNames.add(staticSlotName);
|
11923 | if (staticSlotName === "default") {
|
11924 | hasNamedDefaultSlot = true;
|
11925 | }
|
11926 | }
|
11927 | slotsProperties.push(createObjectProperty(slotName, slotFunction));
|
11928 | }
|
11929 | }
|
11930 | if (!onComponentSlot) {
|
11931 | const buildDefaultSlotProperty = (props, children2) => {
|
11932 | const fn = buildSlotFn(props, void 0, children2, loc);
|
11933 | if (context.compatConfig) {
|
11934 | fn.isNonScopedSlot = true;
|
11935 | }
|
11936 | return createObjectProperty(`default`, fn);
|
11937 | };
|
11938 | if (!hasTemplateSlots) {
|
11939 | slotsProperties.push(buildDefaultSlotProperty(void 0, children));
|
11940 | } else if (implicitDefaultChildren.length &&
|
11941 |
|
11942 |
|
11943 | implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
|
11944 | if (hasNamedDefaultSlot) {
|
11945 | context.onError(
|
11946 | createCompilerError(
|
11947 | 39,
|
11948 | implicitDefaultChildren[0].loc
|
11949 | )
|
11950 | );
|
11951 | } else {
|
11952 | slotsProperties.push(
|
11953 | buildDefaultSlotProperty(void 0, implicitDefaultChildren)
|
11954 | );
|
11955 | }
|
11956 | }
|
11957 | }
|
11958 | const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
|
11959 | let slots = createObjectExpression(
|
11960 | slotsProperties.concat(
|
11961 | createObjectProperty(
|
11962 | `_`,
|
11963 |
|
11964 |
|
11965 | createSimpleExpression(
|
11966 | slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
|
11967 | false
|
11968 | )
|
11969 | )
|
11970 | ),
|
11971 | loc
|
11972 | );
|
11973 | if (dynamicSlots.length) {
|
11974 | slots = createCallExpression(context.helper(CREATE_SLOTS), [
|
11975 | slots,
|
11976 | createArrayExpression(dynamicSlots)
|
11977 | ]);
|
11978 | }
|
11979 | return {
|
11980 | slots,
|
11981 | hasDynamicSlots
|
11982 | };
|
11983 | }
|
11984 | function buildDynamicSlot(name, fn, index) {
|
11985 | const props = [
|
11986 | createObjectProperty(`name`, name),
|
11987 | createObjectProperty(`fn`, fn)
|
11988 | ];
|
11989 | if (index != null) {
|
11990 | props.push(
|
11991 | createObjectProperty(`key`, createSimpleExpression(String(index), true))
|
11992 | );
|
11993 | }
|
11994 | return createObjectExpression(props);
|
11995 | }
|
11996 | function hasForwardedSlots(children) {
|
11997 | for (let i = 0; i < children.length; i++) {
|
11998 | const child = children[i];
|
11999 | switch (child.type) {
|
12000 | case 1:
|
12001 | if (child.tagType === 2 || hasForwardedSlots(child.children)) {
|
12002 | return true;
|
12003 | }
|
12004 | break;
|
12005 | case 9:
|
12006 | if (hasForwardedSlots(child.branches))
|
12007 | return true;
|
12008 | break;
|
12009 | case 10:
|
12010 | case 11:
|
12011 | if (hasForwardedSlots(child.children))
|
12012 | return true;
|
12013 | break;
|
12014 | }
|
12015 | }
|
12016 | return false;
|
12017 | }
|
12018 | function isNonWhitespaceContent(node) {
|
12019 | if (node.type !== 2 && node.type !== 12)
|
12020 | return true;
|
12021 | return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
|
12022 | }
|
12023 |
|
12024 | const directiveImportMap = new WeakMap();
|
12025 | const transformElement = (node, context) => {
|
12026 | return function postTransformElement() {
|
12027 | node = context.currentNode;
|
12028 | if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
|
12029 | return;
|
12030 | }
|
12031 | const { tag, props } = node;
|
12032 | const isComponent = node.tagType === 1;
|
12033 | let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
|
12034 | const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
|
12035 | let vnodeProps;
|
12036 | let vnodeChildren;
|
12037 | let vnodePatchFlag;
|
12038 | let patchFlag = 0;
|
12039 | let vnodeDynamicProps;
|
12040 | let dynamicPropNames;
|
12041 | let vnodeDirectives;
|
12042 | let shouldUseBlock = (
|
12043 |
|
12044 | isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent &&
|
12045 |
|
12046 |
|
12047 |
|
12048 | (tag === "svg" || tag === "foreignObject")
|
12049 | );
|
12050 | if (props.length > 0) {
|
12051 | const propsBuildResult = buildProps(
|
12052 | node,
|
12053 | context,
|
12054 | void 0,
|
12055 | isComponent,
|
12056 | isDynamicComponent
|
12057 | );
|
12058 | vnodeProps = propsBuildResult.props;
|
12059 | patchFlag = propsBuildResult.patchFlag;
|
12060 | dynamicPropNames = propsBuildResult.dynamicPropNames;
|
12061 | const directives = propsBuildResult.directives;
|
12062 | vnodeDirectives = directives && directives.length ? createArrayExpression(
|
12063 | directives.map((dir) => buildDirectiveArgs(dir, context))
|
12064 | ) : void 0;
|
12065 | if (propsBuildResult.shouldUseBlock) {
|
12066 | shouldUseBlock = true;
|
12067 | }
|
12068 | }
|
12069 | if (node.children.length > 0) {
|
12070 | if (vnodeTag === KEEP_ALIVE) {
|
12071 | shouldUseBlock = true;
|
12072 | patchFlag |= 1024;
|
12073 | if (node.children.length > 1) {
|
12074 | context.onError(
|
12075 | createCompilerError(46, {
|
12076 | start: node.children[0].loc.start,
|
12077 | end: node.children[node.children.length - 1].loc.end,
|
12078 | source: ""
|
12079 | })
|
12080 | );
|
12081 | }
|
12082 | }
|
12083 | const shouldBuildAsSlots = isComponent &&
|
12084 | vnodeTag !== TELEPORT &&
|
12085 | vnodeTag !== KEEP_ALIVE;
|
12086 | if (shouldBuildAsSlots) {
|
12087 | const { slots, hasDynamicSlots } = buildSlots(node, context);
|
12088 | vnodeChildren = slots;
|
12089 | if (hasDynamicSlots) {
|
12090 | patchFlag |= 1024;
|
12091 | }
|
12092 | } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
|
12093 | const child = node.children[0];
|
12094 | const type = child.type;
|
12095 | const hasDynamicTextChild = type === 5 || type === 8;
|
12096 | if (hasDynamicTextChild && getConstantType(child, context) === 0) {
|
12097 | patchFlag |= 1;
|
12098 | }
|
12099 | if (hasDynamicTextChild || type === 2) {
|
12100 | vnodeChildren = child;
|
12101 | } else {
|
12102 | vnodeChildren = node.children;
|
12103 | }
|
12104 | } else {
|
12105 | vnodeChildren = node.children;
|
12106 | }
|
12107 | }
|
12108 | if (patchFlag !== 0) {
|
12109 | {
|
12110 | if (patchFlag < 0) {
|
12111 | vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
|
12112 | } else {
|
12113 | const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
|
12114 | vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
|
12115 | }
|
12116 | }
|
12117 | if (dynamicPropNames && dynamicPropNames.length) {
|
12118 | vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
|
12119 | }
|
12120 | }
|
12121 | node.codegenNode = createVNodeCall(
|
12122 | context,
|
12123 | vnodeTag,
|
12124 | vnodeProps,
|
12125 | vnodeChildren,
|
12126 | vnodePatchFlag,
|
12127 | vnodeDynamicProps,
|
12128 | vnodeDirectives,
|
12129 | !!shouldUseBlock,
|
12130 | false,
|
12131 | isComponent,
|
12132 | node.loc
|
12133 | );
|
12134 | };
|
12135 | };
|
12136 | function resolveComponentType(node, context, ssr = false) {
|
12137 | let { tag } = node;
|
12138 | const isExplicitDynamic = isComponentTag(tag);
|
12139 | const isProp = findProp(
|
12140 | node,
|
12141 | "is",
|
12142 | false,
|
12143 | true
|
12144 |
|
12145 | );
|
12146 | if (isProp) {
|
12147 | if (isExplicitDynamic || isCompatEnabled(
|
12148 | "COMPILER_IS_ON_ELEMENT",
|
12149 | context
|
12150 | )) {
|
12151 | let exp;
|
12152 | if (isProp.type === 6) {
|
12153 | exp = isProp.value && createSimpleExpression(isProp.value.content, true);
|
12154 | } else {
|
12155 | exp = isProp.exp;
|
12156 | if (!exp) {
|
12157 | exp = createSimpleExpression(`is`, false, isProp.loc);
|
12158 | }
|
12159 | }
|
12160 | if (exp) {
|
12161 | return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
|
12162 | exp
|
12163 | ]);
|
12164 | }
|
12165 | } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
|
12166 | tag = isProp.value.content.slice(4);
|
12167 | }
|
12168 | }
|
12169 | const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
|
12170 | if (builtIn) {
|
12171 | if (!ssr)
|
12172 | context.helper(builtIn);
|
12173 | return builtIn;
|
12174 | }
|
12175 | context.helper(RESOLVE_COMPONENT);
|
12176 | context.components.add(tag);
|
12177 | return toValidAssetId(tag, `component`);
|
12178 | }
|
12179 | function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
|
12180 | const { tag, loc: elementLoc, children } = node;
|
12181 | let properties = [];
|
12182 | const mergeArgs = [];
|
12183 | const runtimeDirectives = [];
|
12184 | const hasChildren = children.length > 0;
|
12185 | let shouldUseBlock = false;
|
12186 | let patchFlag = 0;
|
12187 | let hasRef = false;
|
12188 | let hasClassBinding = false;
|
12189 | let hasStyleBinding = false;
|
12190 | let hasHydrationEventBinding = false;
|
12191 | let hasDynamicKeys = false;
|
12192 | let hasVnodeHook = false;
|
12193 | const dynamicPropNames = [];
|
12194 | const pushMergeArg = (arg) => {
|
12195 | if (properties.length) {
|
12196 | mergeArgs.push(
|
12197 | createObjectExpression(dedupeProperties(properties), elementLoc)
|
12198 | );
|
12199 | properties = [];
|
12200 | }
|
12201 | if (arg)
|
12202 | mergeArgs.push(arg);
|
12203 | };
|
12204 | const pushRefVForMarker = () => {
|
12205 | if (context.scopes.vFor > 0) {
|
12206 | properties.push(
|
12207 | createObjectProperty(
|
12208 | createSimpleExpression("ref_for", true),
|
12209 | createSimpleExpression("true")
|
12210 | )
|
12211 | );
|
12212 | }
|
12213 | };
|
12214 | const analyzePatchFlag = ({ key, value }) => {
|
12215 | if (isStaticExp(key)) {
|
12216 | const name = key.content;
|
12217 | const isEventHandler = isOn(name);
|
12218 | if (isEventHandler && (!isComponent || isDynamicComponent) &&
|
12219 |
|
12220 | name.toLowerCase() !== "onclick" &&
|
12221 | name !== "onUpdate:modelValue" &&
|
12222 | !isReservedProp(name)) {
|
12223 | hasHydrationEventBinding = true;
|
12224 | }
|
12225 | if (isEventHandler && isReservedProp(name)) {
|
12226 | hasVnodeHook = true;
|
12227 | }
|
12228 | if (isEventHandler && value.type === 14) {
|
12229 | value = value.arguments[0];
|
12230 | }
|
12231 | if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
|
12232 | return;
|
12233 | }
|
12234 | if (name === "ref") {
|
12235 | hasRef = true;
|
12236 | } else if (name === "class") {
|
12237 | hasClassBinding = true;
|
12238 | } else if (name === "style") {
|
12239 | hasStyleBinding = true;
|
12240 | } else if (name !== "key" && !dynamicPropNames.includes(name)) {
|
12241 | dynamicPropNames.push(name);
|
12242 | }
|
12243 | if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
|
12244 | dynamicPropNames.push(name);
|
12245 | }
|
12246 | } else {
|
12247 | hasDynamicKeys = true;
|
12248 | }
|
12249 | };
|
12250 | for (let i = 0; i < props.length; i++) {
|
12251 | const prop = props[i];
|
12252 | if (prop.type === 6) {
|
12253 | const { loc, name, nameLoc, value } = prop;
|
12254 | let isStatic = true;
|
12255 | if (name === "ref") {
|
12256 | hasRef = true;
|
12257 | pushRefVForMarker();
|
12258 | }
|
12259 | if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
|
12260 | "COMPILER_IS_ON_ELEMENT",
|
12261 | context
|
12262 | ))) {
|
12263 | continue;
|
12264 | }
|
12265 | properties.push(
|
12266 | createObjectProperty(
|
12267 | createSimpleExpression(name, true, nameLoc),
|
12268 | createSimpleExpression(
|
12269 | value ? value.content : "",
|
12270 | isStatic,
|
12271 | value ? value.loc : loc
|
12272 | )
|
12273 | )
|
12274 | );
|
12275 | } else {
|
12276 | const { name, arg, exp, loc, modifiers } = prop;
|
12277 | const isVBind = name === "bind";
|
12278 | const isVOn = name === "on";
|
12279 | if (name === "slot") {
|
12280 | if (!isComponent) {
|
12281 | context.onError(
|
12282 | createCompilerError(40, loc)
|
12283 | );
|
12284 | }
|
12285 | continue;
|
12286 | }
|
12287 | if (name === "once" || name === "memo") {
|
12288 | continue;
|
12289 | }
|
12290 | if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
|
12291 | "COMPILER_IS_ON_ELEMENT",
|
12292 | context
|
12293 | ))) {
|
12294 | continue;
|
12295 | }
|
12296 | if (isVOn && ssr) {
|
12297 | continue;
|
12298 | }
|
12299 | if (
|
12300 |
|
12301 | isVBind && isStaticArgOf(arg, "key") ||
|
12302 |
|
12303 | isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
|
12304 | ) {
|
12305 | shouldUseBlock = true;
|
12306 | }
|
12307 | if (isVBind && isStaticArgOf(arg, "ref")) {
|
12308 | pushRefVForMarker();
|
12309 | }
|
12310 | if (!arg && (isVBind || isVOn)) {
|
12311 | hasDynamicKeys = true;
|
12312 | if (exp) {
|
12313 | if (isVBind) {
|
12314 | pushRefVForMarker();
|
12315 | pushMergeArg();
|
12316 | {
|
12317 | {
|
12318 | const hasOverridableKeys = mergeArgs.some((arg2) => {
|
12319 | if (arg2.type === 15) {
|
12320 | return arg2.properties.some(({ key }) => {
|
12321 | if (key.type !== 4 || !key.isStatic) {
|
12322 | return true;
|
12323 | }
|
12324 | return key.content !== "class" && key.content !== "style" && !isOn(key.content);
|
12325 | });
|
12326 | } else {
|
12327 | return true;
|
12328 | }
|
12329 | });
|
12330 | if (hasOverridableKeys) {
|
12331 | checkCompatEnabled(
|
12332 | "COMPILER_V_BIND_OBJECT_ORDER",
|
12333 | context,
|
12334 | loc
|
12335 | );
|
12336 | }
|
12337 | }
|
12338 | if (isCompatEnabled(
|
12339 | "COMPILER_V_BIND_OBJECT_ORDER",
|
12340 | context
|
12341 | )) {
|
12342 | mergeArgs.unshift(exp);
|
12343 | continue;
|
12344 | }
|
12345 | }
|
12346 | mergeArgs.push(exp);
|
12347 | } else {
|
12348 | pushMergeArg({
|
12349 | type: 14,
|
12350 | loc,
|
12351 | callee: context.helper(TO_HANDLERS),
|
12352 | arguments: isComponent ? [exp] : [exp, `true`]
|
12353 | });
|
12354 | }
|
12355 | } else {
|
12356 | context.onError(
|
12357 | createCompilerError(
|
12358 | isVBind ? 34 : 35,
|
12359 | loc
|
12360 | )
|
12361 | );
|
12362 | }
|
12363 | continue;
|
12364 | }
|
12365 | if (isVBind && modifiers.includes("prop")) {
|
12366 | patchFlag |= 32;
|
12367 | }
|
12368 | const directiveTransform = context.directiveTransforms[name];
|
12369 | if (directiveTransform) {
|
12370 | const { props: props2, needRuntime } = directiveTransform(prop, node, context);
|
12371 | !ssr && props2.forEach(analyzePatchFlag);
|
12372 | if (isVOn && arg && !isStaticExp(arg)) {
|
12373 | pushMergeArg(createObjectExpression(props2, elementLoc));
|
12374 | } else {
|
12375 | properties.push(...props2);
|
12376 | }
|
12377 | if (needRuntime) {
|
12378 | runtimeDirectives.push(prop);
|
12379 | if (isSymbol(needRuntime)) {
|
12380 | directiveImportMap.set(prop, needRuntime);
|
12381 | }
|
12382 | }
|
12383 | } else if (!isBuiltInDirective(name)) {
|
12384 | runtimeDirectives.push(prop);
|
12385 | if (hasChildren) {
|
12386 | shouldUseBlock = true;
|
12387 | }
|
12388 | }
|
12389 | }
|
12390 | }
|
12391 | let propsExpression = void 0;
|
12392 | if (mergeArgs.length) {
|
12393 | pushMergeArg();
|
12394 | if (mergeArgs.length > 1) {
|
12395 | propsExpression = createCallExpression(
|
12396 | context.helper(MERGE_PROPS),
|
12397 | mergeArgs,
|
12398 | elementLoc
|
12399 | );
|
12400 | } else {
|
12401 | propsExpression = mergeArgs[0];
|
12402 | }
|
12403 | } else if (properties.length) {
|
12404 | propsExpression = createObjectExpression(
|
12405 | dedupeProperties(properties),
|
12406 | elementLoc
|
12407 | );
|
12408 | }
|
12409 | if (hasDynamicKeys) {
|
12410 | patchFlag |= 16;
|
12411 | } else {
|
12412 | if (hasClassBinding && !isComponent) {
|
12413 | patchFlag |= 2;
|
12414 | }
|
12415 | if (hasStyleBinding && !isComponent) {
|
12416 | patchFlag |= 4;
|
12417 | }
|
12418 | if (dynamicPropNames.length) {
|
12419 | patchFlag |= 8;
|
12420 | }
|
12421 | if (hasHydrationEventBinding) {
|
12422 | patchFlag |= 32;
|
12423 | }
|
12424 | }
|
12425 | if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
|
12426 | patchFlag |= 512;
|
12427 | }
|
12428 | if (!context.inSSR && propsExpression) {
|
12429 | switch (propsExpression.type) {
|
12430 | case 15:
|
12431 | let classKeyIndex = -1;
|
12432 | let styleKeyIndex = -1;
|
12433 | let hasDynamicKey = false;
|
12434 | for (let i = 0; i < propsExpression.properties.length; i++) {
|
12435 | const key = propsExpression.properties[i].key;
|
12436 | if (isStaticExp(key)) {
|
12437 | if (key.content === "class") {
|
12438 | classKeyIndex = i;
|
12439 | } else if (key.content === "style") {
|
12440 | styleKeyIndex = i;
|
12441 | }
|
12442 | } else if (!key.isHandlerKey) {
|
12443 | hasDynamicKey = true;
|
12444 | }
|
12445 | }
|
12446 | const classProp = propsExpression.properties[classKeyIndex];
|
12447 | const styleProp = propsExpression.properties[styleKeyIndex];
|
12448 | if (!hasDynamicKey) {
|
12449 | if (classProp && !isStaticExp(classProp.value)) {
|
12450 | classProp.value = createCallExpression(
|
12451 | context.helper(NORMALIZE_CLASS),
|
12452 | [classProp.value]
|
12453 | );
|
12454 | }
|
12455 | if (styleProp &&
|
12456 |
|
12457 | (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` ||
|
12458 |
|
12459 | styleProp.value.type === 17)) {
|
12460 | styleProp.value = createCallExpression(
|
12461 | context.helper(NORMALIZE_STYLE),
|
12462 | [styleProp.value]
|
12463 | );
|
12464 | }
|
12465 | } else {
|
12466 | propsExpression = createCallExpression(
|
12467 | context.helper(NORMALIZE_PROPS),
|
12468 | [propsExpression]
|
12469 | );
|
12470 | }
|
12471 | break;
|
12472 | case 14:
|
12473 | break;
|
12474 | default:
|
12475 | propsExpression = createCallExpression(
|
12476 | context.helper(NORMALIZE_PROPS),
|
12477 | [
|
12478 | createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
|
12479 | propsExpression
|
12480 | ])
|
12481 | ]
|
12482 | );
|
12483 | break;
|
12484 | }
|
12485 | }
|
12486 | return {
|
12487 | props: propsExpression,
|
12488 | directives: runtimeDirectives,
|
12489 | patchFlag,
|
12490 | dynamicPropNames,
|
12491 | shouldUseBlock
|
12492 | };
|
12493 | }
|
12494 | function dedupeProperties(properties) {
|
12495 | const knownProps = new Map();
|
12496 | const deduped = [];
|
12497 | for (let i = 0; i < properties.length; i++) {
|
12498 | const prop = properties[i];
|
12499 | if (prop.key.type === 8 || !prop.key.isStatic) {
|
12500 | deduped.push(prop);
|
12501 | continue;
|
12502 | }
|
12503 | const name = prop.key.content;
|
12504 | const existing = knownProps.get(name);
|
12505 | if (existing) {
|
12506 | if (name === "style" || name === "class" || isOn(name)) {
|
12507 | mergeAsArray(existing, prop);
|
12508 | }
|
12509 | } else {
|
12510 | knownProps.set(name, prop);
|
12511 | deduped.push(prop);
|
12512 | }
|
12513 | }
|
12514 | return deduped;
|
12515 | }
|
12516 | function mergeAsArray(existing, incoming) {
|
12517 | if (existing.value.type === 17) {
|
12518 | existing.value.elements.push(incoming.value);
|
12519 | } else {
|
12520 | existing.value = createArrayExpression(
|
12521 | [existing.value, incoming.value],
|
12522 | existing.loc
|
12523 | );
|
12524 | }
|
12525 | }
|
12526 | function buildDirectiveArgs(dir, context) {
|
12527 | const dirArgs = [];
|
12528 | const runtime = directiveImportMap.get(dir);
|
12529 | if (runtime) {
|
12530 | dirArgs.push(context.helperString(runtime));
|
12531 | } else {
|
12532 | {
|
12533 | context.helper(RESOLVE_DIRECTIVE);
|
12534 | context.directives.add(dir.name);
|
12535 | dirArgs.push(toValidAssetId(dir.name, `directive`));
|
12536 | }
|
12537 | }
|
12538 | const { loc } = dir;
|
12539 | if (dir.exp)
|
12540 | dirArgs.push(dir.exp);
|
12541 | if (dir.arg) {
|
12542 | if (!dir.exp) {
|
12543 | dirArgs.push(`void 0`);
|
12544 | }
|
12545 | dirArgs.push(dir.arg);
|
12546 | }
|
12547 | if (Object.keys(dir.modifiers).length) {
|
12548 | if (!dir.arg) {
|
12549 | if (!dir.exp) {
|
12550 | dirArgs.push(`void 0`);
|
12551 | }
|
12552 | dirArgs.push(`void 0`);
|
12553 | }
|
12554 | const trueExpression = createSimpleExpression(`true`, false, loc);
|
12555 | dirArgs.push(
|
12556 | createObjectExpression(
|
12557 | dir.modifiers.map(
|
12558 | (modifier) => createObjectProperty(modifier, trueExpression)
|
12559 | ),
|
12560 | loc
|
12561 | )
|
12562 | );
|
12563 | }
|
12564 | return createArrayExpression(dirArgs, dir.loc);
|
12565 | }
|
12566 | function stringifyDynamicPropNames(props) {
|
12567 | let propsNamesString = `[`;
|
12568 | for (let i = 0, l = props.length; i < l; i++) {
|
12569 | propsNamesString += JSON.stringify(props[i]);
|
12570 | if (i < l - 1)
|
12571 | propsNamesString += ", ";
|
12572 | }
|
12573 | return propsNamesString + `]`;
|
12574 | }
|
12575 | function isComponentTag(tag) {
|
12576 | return tag === "component" || tag === "Component";
|
12577 | }
|
12578 |
|
12579 | const transformSlotOutlet = (node, context) => {
|
12580 | if (isSlotOutlet(node)) {
|
12581 | const { children, loc } = node;
|
12582 | const { slotName, slotProps } = processSlotOutlet(node, context);
|
12583 | const slotArgs = [
|
12584 | context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
|
12585 | slotName,
|
12586 | "{}",
|
12587 | "undefined",
|
12588 | "true"
|
12589 | ];
|
12590 | let expectedLen = 2;
|
12591 | if (slotProps) {
|
12592 | slotArgs[2] = slotProps;
|
12593 | expectedLen = 3;
|
12594 | }
|
12595 | if (children.length) {
|
12596 | slotArgs[3] = createFunctionExpression([], children, false, false, loc);
|
12597 | expectedLen = 4;
|
12598 | }
|
12599 | if (context.scopeId && !context.slotted) {
|
12600 | expectedLen = 5;
|
12601 | }
|
12602 | slotArgs.splice(expectedLen);
|
12603 | node.codegenNode = createCallExpression(
|
12604 | context.helper(RENDER_SLOT),
|
12605 | slotArgs,
|
12606 | loc
|
12607 | );
|
12608 | }
|
12609 | };
|
12610 | function processSlotOutlet(node, context) {
|
12611 | let slotName = `"default"`;
|
12612 | let slotProps = void 0;
|
12613 | const nonNameProps = [];
|
12614 | for (let i = 0; i < node.props.length; i++) {
|
12615 | const p = node.props[i];
|
12616 | if (p.type === 6) {
|
12617 | if (p.value) {
|
12618 | if (p.name === "name") {
|
12619 | slotName = JSON.stringify(p.value.content);
|
12620 | } else {
|
12621 | p.name = camelize(p.name);
|
12622 | nonNameProps.push(p);
|
12623 | }
|
12624 | }
|
12625 | } else {
|
12626 | if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
|
12627 | if (p.exp) {
|
12628 | slotName = p.exp;
|
12629 | } else if (p.arg && p.arg.type === 4) {
|
12630 | const name = camelize(p.arg.content);
|
12631 | slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
|
12632 | }
|
12633 | } else {
|
12634 | if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
|
12635 | p.arg.content = camelize(p.arg.content);
|
12636 | }
|
12637 | nonNameProps.push(p);
|
12638 | }
|
12639 | }
|
12640 | }
|
12641 | if (nonNameProps.length > 0) {
|
12642 | const { props, directives } = buildProps(
|
12643 | node,
|
12644 | context,
|
12645 | nonNameProps,
|
12646 | false,
|
12647 | false
|
12648 | );
|
12649 | slotProps = props;
|
12650 | if (directives.length) {
|
12651 | context.onError(
|
12652 | createCompilerError(
|
12653 | 36,
|
12654 | directives[0].loc
|
12655 | )
|
12656 | );
|
12657 | }
|
12658 | }
|
12659 | return {
|
12660 | slotName,
|
12661 | slotProps
|
12662 | };
|
12663 | }
|
12664 |
|
12665 | const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
12666 | const transformOn$1 = (dir, node, context, augmentor) => {
|
12667 | const { loc, modifiers, arg } = dir;
|
12668 | if (!dir.exp && !modifiers.length) {
|
12669 | context.onError(createCompilerError(35, loc));
|
12670 | }
|
12671 | let eventName;
|
12672 | if (arg.type === 4) {
|
12673 | if (arg.isStatic) {
|
12674 | let rawName = arg.content;
|
12675 | if (rawName.startsWith("vnode")) {
|
12676 | context.onError(createCompilerError(51, arg.loc));
|
12677 | }
|
12678 | if (rawName.startsWith("vue:")) {
|
12679 | rawName = `vnode-${rawName.slice(4)}`;
|
12680 | }
|
12681 | const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
|
12682 |
|
12683 |
|
12684 | toHandlerKey(camelize(rawName))
|
12685 | ) : (
|
12686 |
|
12687 |
|
12688 | `on:${rawName}`
|
12689 | );
|
12690 | eventName = createSimpleExpression(eventString, true, arg.loc);
|
12691 | } else {
|
12692 | eventName = createCompoundExpression([
|
12693 | `${context.helperString(TO_HANDLER_KEY)}(`,
|
12694 | arg,
|
12695 | `)`
|
12696 | ]);
|
12697 | }
|
12698 | } else {
|
12699 | eventName = arg;
|
12700 | eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
|
12701 | eventName.children.push(`)`);
|
12702 | }
|
12703 | let exp = dir.exp;
|
12704 | if (exp && !exp.content.trim()) {
|
12705 | exp = void 0;
|
12706 | }
|
12707 | let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
|
12708 | if (exp) {
|
12709 | const isMemberExp = isMemberExpression(exp.content);
|
12710 | const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
|
12711 | const hasMultipleStatements = exp.content.includes(`;`);
|
12712 | {
|
12713 | validateBrowserExpression(
|
12714 | exp,
|
12715 | context,
|
12716 | false,
|
12717 | hasMultipleStatements
|
12718 | );
|
12719 | }
|
12720 | if (isInlineStatement || shouldCache && isMemberExp) {
|
12721 | exp = createCompoundExpression([
|
12722 | `${isInlineStatement ? `$event` : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
|
12723 | exp,
|
12724 | hasMultipleStatements ? `}` : `)`
|
12725 | ]);
|
12726 | }
|
12727 | }
|
12728 | let ret = {
|
12729 | props: [
|
12730 | createObjectProperty(
|
12731 | eventName,
|
12732 | exp || createSimpleExpression(`() => {}`, false, loc)
|
12733 | )
|
12734 | ]
|
12735 | };
|
12736 | if (augmentor) {
|
12737 | ret = augmentor(ret);
|
12738 | }
|
12739 | if (shouldCache) {
|
12740 | ret.props[0].value = context.cache(ret.props[0].value);
|
12741 | }
|
12742 | ret.props.forEach((p) => p.key.isHandlerKey = true);
|
12743 | return ret;
|
12744 | };
|
12745 |
|
12746 | const transformBind = (dir, _node, context) => {
|
12747 | const { modifiers, loc } = dir;
|
12748 | const arg = dir.arg;
|
12749 | let { exp } = dir;
|
12750 | if (exp && exp.type === 4 && !exp.content.trim()) {
|
12751 | {
|
12752 | exp = void 0;
|
12753 | }
|
12754 | }
|
12755 | if (!exp) {
|
12756 | if (arg.type !== 4 || !arg.isStatic) {
|
12757 | context.onError(
|
12758 | createCompilerError(
|
12759 | 52,
|
12760 | arg.loc
|
12761 | )
|
12762 | );
|
12763 | return {
|
12764 | props: [
|
12765 | createObjectProperty(arg, createSimpleExpression("", true, loc))
|
12766 | ]
|
12767 | };
|
12768 | }
|
12769 | const propName = camelize(arg.content);
|
12770 | exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
|
12771 | }
|
12772 | if (arg.type !== 4) {
|
12773 | arg.children.unshift(`(`);
|
12774 | arg.children.push(`) || ""`);
|
12775 | } else if (!arg.isStatic) {
|
12776 | arg.content = `${arg.content} || ""`;
|
12777 | }
|
12778 | if (modifiers.includes("camel")) {
|
12779 | if (arg.type === 4) {
|
12780 | if (arg.isStatic) {
|
12781 | arg.content = camelize(arg.content);
|
12782 | } else {
|
12783 | arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
|
12784 | }
|
12785 | } else {
|
12786 | arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
|
12787 | arg.children.push(`)`);
|
12788 | }
|
12789 | }
|
12790 | if (!context.inSSR) {
|
12791 | if (modifiers.includes("prop")) {
|
12792 | injectPrefix(arg, ".");
|
12793 | }
|
12794 | if (modifiers.includes("attr")) {
|
12795 | injectPrefix(arg, "^");
|
12796 | }
|
12797 | }
|
12798 | return {
|
12799 | props: [createObjectProperty(arg, exp)]
|
12800 | };
|
12801 | };
|
12802 | const injectPrefix = (arg, prefix) => {
|
12803 | if (arg.type === 4) {
|
12804 | if (arg.isStatic) {
|
12805 | arg.content = prefix + arg.content;
|
12806 | } else {
|
12807 | arg.content = `\`${prefix}\${${arg.content}}\``;
|
12808 | }
|
12809 | } else {
|
12810 | arg.children.unshift(`'${prefix}' + (`);
|
12811 | arg.children.push(`)`);
|
12812 | }
|
12813 | };
|
12814 |
|
12815 | const transformText = (node, context) => {
|
12816 | if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
|
12817 | return () => {
|
12818 | const children = node.children;
|
12819 | let currentContainer = void 0;
|
12820 | let hasText = false;
|
12821 | for (let i = 0; i < children.length; i++) {
|
12822 | const child = children[i];
|
12823 | if (isText$1(child)) {
|
12824 | hasText = true;
|
12825 | for (let j = i + 1; j < children.length; j++) {
|
12826 | const next = children[j];
|
12827 | if (isText$1(next)) {
|
12828 | if (!currentContainer) {
|
12829 | currentContainer = children[i] = createCompoundExpression(
|
12830 | [child],
|
12831 | child.loc
|
12832 | );
|
12833 | }
|
12834 | currentContainer.children.push(` + `, next);
|
12835 | children.splice(j, 1);
|
12836 | j--;
|
12837 | } else {
|
12838 | currentContainer = void 0;
|
12839 | break;
|
12840 | }
|
12841 | }
|
12842 | }
|
12843 | }
|
12844 | if (!hasText ||
|
12845 |
|
12846 |
|
12847 |
|
12848 | children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 &&
|
12849 |
|
12850 |
|
12851 |
|
12852 |
|
12853 | !node.props.find(
|
12854 | (p) => p.type === 7 && !context.directiveTransforms[p.name]
|
12855 | ) &&
|
12856 |
|
12857 |
|
12858 | !(node.tag === "template"))) {
|
12859 | return;
|
12860 | }
|
12861 | for (let i = 0; i < children.length; i++) {
|
12862 | const child = children[i];
|
12863 | if (isText$1(child) || child.type === 8) {
|
12864 | const callArgs = [];
|
12865 | if (child.type !== 2 || child.content !== " ") {
|
12866 | callArgs.push(child);
|
12867 | }
|
12868 | if (!context.ssr && getConstantType(child, context) === 0) {
|
12869 | callArgs.push(
|
12870 | 1 + (` /* ${PatchFlagNames[1]} */` )
|
12871 | );
|
12872 | }
|
12873 | children[i] = {
|
12874 | type: 12,
|
12875 | content: child,
|
12876 | loc: child.loc,
|
12877 | codegenNode: createCallExpression(
|
12878 | context.helper(CREATE_TEXT),
|
12879 | callArgs
|
12880 | )
|
12881 | };
|
12882 | }
|
12883 | }
|
12884 | };
|
12885 | }
|
12886 | };
|
12887 |
|
12888 | const seen$1 = new WeakSet();
|
12889 | const transformOnce = (node, context) => {
|
12890 | if (node.type === 1 && findDir(node, "once", true)) {
|
12891 | if (seen$1.has(node) || context.inVOnce || context.inSSR) {
|
12892 | return;
|
12893 | }
|
12894 | seen$1.add(node);
|
12895 | context.inVOnce = true;
|
12896 | context.helper(SET_BLOCK_TRACKING);
|
12897 | return () => {
|
12898 | context.inVOnce = false;
|
12899 | const cur = context.currentNode;
|
12900 | if (cur.codegenNode) {
|
12901 | cur.codegenNode = context.cache(
|
12902 | cur.codegenNode,
|
12903 | true
|
12904 |
|
12905 | );
|
12906 | }
|
12907 | };
|
12908 | }
|
12909 | };
|
12910 |
|
12911 | const transformModel$1 = (dir, node, context) => {
|
12912 | const { exp, arg } = dir;
|
12913 | if (!exp) {
|
12914 | context.onError(
|
12915 | createCompilerError(41, dir.loc)
|
12916 | );
|
12917 | return createTransformProps();
|
12918 | }
|
12919 | const rawExp = exp.loc.source;
|
12920 | const expString = exp.type === 4 ? exp.content : rawExp;
|
12921 | const bindingType = context.bindingMetadata[rawExp];
|
12922 | if (bindingType === "props" || bindingType === "props-aliased") {
|
12923 | context.onError(createCompilerError(44, exp.loc));
|
12924 | return createTransformProps();
|
12925 | }
|
12926 | const maybeRef = false;
|
12927 | if (!expString.trim() || !isMemberExpression(expString) && !maybeRef) {
|
12928 | context.onError(
|
12929 | createCompilerError(42, exp.loc)
|
12930 | );
|
12931 | return createTransformProps();
|
12932 | }
|
12933 | const propName = arg ? arg : createSimpleExpression("modelValue", true);
|
12934 | const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
|
12935 | let assignmentExp;
|
12936 | const eventArg = context.isTS ? `($event: any)` : `$event`;
|
12937 | {
|
12938 | assignmentExp = createCompoundExpression([
|
12939 | `${eventArg} => ((`,
|
12940 | exp,
|
12941 | `) = $event)`
|
12942 | ]);
|
12943 | }
|
12944 | const props = [
|
12945 |
|
12946 | createObjectProperty(propName, dir.exp),
|
12947 |
|
12948 | createObjectProperty(eventName, assignmentExp)
|
12949 | ];
|
12950 | if (dir.modifiers.length && node.tagType === 1) {
|
12951 | const modifiers = dir.modifiers.map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
|
12952 | const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
|
12953 | props.push(
|
12954 | createObjectProperty(
|
12955 | modifiersKey,
|
12956 | createSimpleExpression(
|
12957 | `{ ${modifiers} }`,
|
12958 | false,
|
12959 | dir.loc,
|
12960 | 2
|
12961 | )
|
12962 | )
|
12963 | );
|
12964 | }
|
12965 | return createTransformProps(props);
|
12966 | };
|
12967 | function createTransformProps(props = []) {
|
12968 | return { props };
|
12969 | }
|
12970 |
|
12971 | const validDivisionCharRE = /[\w).+\-_$\]]/;
|
12972 | const transformFilter = (node, context) => {
|
12973 | if (!isCompatEnabled("COMPILER_FILTERS", context)) {
|
12974 | return;
|
12975 | }
|
12976 | if (node.type === 5) {
|
12977 | rewriteFilter(node.content, context);
|
12978 | }
|
12979 | if (node.type === 1) {
|
12980 | node.props.forEach((prop) => {
|
12981 | if (prop.type === 7 && prop.name !== "for" && prop.exp) {
|
12982 | rewriteFilter(prop.exp, context);
|
12983 | }
|
12984 | });
|
12985 | }
|
12986 | };
|
12987 | function rewriteFilter(node, context) {
|
12988 | if (node.type === 4) {
|
12989 | parseFilter(node, context);
|
12990 | } else {
|
12991 | for (let i = 0; i < node.children.length; i++) {
|
12992 | const child = node.children[i];
|
12993 | if (typeof child !== "object")
|
12994 | continue;
|
12995 | if (child.type === 4) {
|
12996 | parseFilter(child, context);
|
12997 | } else if (child.type === 8) {
|
12998 | rewriteFilter(node, context);
|
12999 | } else if (child.type === 5) {
|
13000 | rewriteFilter(child.content, context);
|
13001 | }
|
13002 | }
|
13003 | }
|
13004 | }
|
13005 | function parseFilter(node, context) {
|
13006 | const exp = node.content;
|
13007 | let inSingle = false;
|
13008 | let inDouble = false;
|
13009 | let inTemplateString = false;
|
13010 | let inRegex = false;
|
13011 | let curly = 0;
|
13012 | let square = 0;
|
13013 | let paren = 0;
|
13014 | let lastFilterIndex = 0;
|
13015 | let c, prev, i, expression, filters = [];
|
13016 | for (i = 0; i < exp.length; i++) {
|
13017 | prev = c;
|
13018 | c = exp.charCodeAt(i);
|
13019 | if (inSingle) {
|
13020 | if (c === 39 && prev !== 92)
|
13021 | inSingle = false;
|
13022 | } else if (inDouble) {
|
13023 | if (c === 34 && prev !== 92)
|
13024 | inDouble = false;
|
13025 | } else if (inTemplateString) {
|
13026 | if (c === 96 && prev !== 92)
|
13027 | inTemplateString = false;
|
13028 | } else if (inRegex) {
|
13029 | if (c === 47 && prev !== 92)
|
13030 | inRegex = false;
|
13031 | } else if (c === 124 &&
|
13032 | exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
|
13033 | if (expression === void 0) {
|
13034 | lastFilterIndex = i + 1;
|
13035 | expression = exp.slice(0, i).trim();
|
13036 | } else {
|
13037 | pushFilter();
|
13038 | }
|
13039 | } else {
|
13040 | switch (c) {
|
13041 | case 34:
|
13042 | inDouble = true;
|
13043 | break;
|
13044 | case 39:
|
13045 | inSingle = true;
|
13046 | break;
|
13047 | case 96:
|
13048 | inTemplateString = true;
|
13049 | break;
|
13050 | case 40:
|
13051 | paren++;
|
13052 | break;
|
13053 | case 41:
|
13054 | paren--;
|
13055 | break;
|
13056 | case 91:
|
13057 | square++;
|
13058 | break;
|
13059 | case 93:
|
13060 | square--;
|
13061 | break;
|
13062 | case 123:
|
13063 | curly++;
|
13064 | break;
|
13065 | case 125:
|
13066 | curly--;
|
13067 | break;
|
13068 | }
|
13069 | if (c === 47) {
|
13070 | let j = i - 1;
|
13071 | let p;
|
13072 | for (; j >= 0; j--) {
|
13073 | p = exp.charAt(j);
|
13074 | if (p !== " ")
|
13075 | break;
|
13076 | }
|
13077 | if (!p || !validDivisionCharRE.test(p)) {
|
13078 | inRegex = true;
|
13079 | }
|
13080 | }
|
13081 | }
|
13082 | }
|
13083 | if (expression === void 0) {
|
13084 | expression = exp.slice(0, i).trim();
|
13085 | } else if (lastFilterIndex !== 0) {
|
13086 | pushFilter();
|
13087 | }
|
13088 | function pushFilter() {
|
13089 | filters.push(exp.slice(lastFilterIndex, i).trim());
|
13090 | lastFilterIndex = i + 1;
|
13091 | }
|
13092 | if (filters.length) {
|
13093 | warnDeprecation(
|
13094 | "COMPILER_FILTERS",
|
13095 | context,
|
13096 | node.loc
|
13097 | );
|
13098 | for (i = 0; i < filters.length; i++) {
|
13099 | expression = wrapFilter(expression, filters[i], context);
|
13100 | }
|
13101 | node.content = expression;
|
13102 | }
|
13103 | }
|
13104 | function wrapFilter(exp, filter, context) {
|
13105 | context.helper(RESOLVE_FILTER);
|
13106 | const i = filter.indexOf("(");
|
13107 | if (i < 0) {
|
13108 | context.filters.add(filter);
|
13109 | return `${toValidAssetId(filter, "filter")}(${exp})`;
|
13110 | } else {
|
13111 | const name = filter.slice(0, i);
|
13112 | const args = filter.slice(i + 1);
|
13113 | context.filters.add(name);
|
13114 | return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
|
13115 | }
|
13116 | }
|
13117 |
|
13118 | const seen = new WeakSet();
|
13119 | const transformMemo = (node, context) => {
|
13120 | if (node.type === 1) {
|
13121 | const dir = findDir(node, "memo");
|
13122 | if (!dir || seen.has(node)) {
|
13123 | return;
|
13124 | }
|
13125 | seen.add(node);
|
13126 | return () => {
|
13127 | const codegenNode = node.codegenNode || context.currentNode.codegenNode;
|
13128 | if (codegenNode && codegenNode.type === 13) {
|
13129 | if (node.tagType !== 1) {
|
13130 | convertToBlock(codegenNode, context);
|
13131 | }
|
13132 | node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
|
13133 | dir.exp,
|
13134 | createFunctionExpression(void 0, codegenNode),
|
13135 | `_cache`,
|
13136 | String(context.cached++)
|
13137 | ]);
|
13138 | }
|
13139 | };
|
13140 | }
|
13141 | };
|
13142 |
|
13143 | function getBaseTransformPreset(prefixIdentifiers) {
|
13144 | return [
|
13145 | [
|
13146 | transformOnce,
|
13147 | transformIf,
|
13148 | transformMemo,
|
13149 | transformFor,
|
13150 | ...[transformFilter] ,
|
13151 | ...[transformExpression] ,
|
13152 | transformSlotOutlet,
|
13153 | transformElement,
|
13154 | trackSlotScopes,
|
13155 | transformText
|
13156 | ],
|
13157 | {
|
13158 | on: transformOn$1,
|
13159 | bind: transformBind,
|
13160 | model: transformModel$1
|
13161 | }
|
13162 | ];
|
13163 | }
|
13164 | function baseCompile(source, options = {}) {
|
13165 | const onError = options.onError || defaultOnError;
|
13166 | const isModuleMode = options.mode === "module";
|
13167 | {
|
13168 | if (options.prefixIdentifiers === true) {
|
13169 | onError(createCompilerError(47));
|
13170 | } else if (isModuleMode) {
|
13171 | onError(createCompilerError(48));
|
13172 | }
|
13173 | }
|
13174 | const prefixIdentifiers = false;
|
13175 | if (options.cacheHandlers) {
|
13176 | onError(createCompilerError(49));
|
13177 | }
|
13178 | if (options.scopeId && !isModuleMode) {
|
13179 | onError(createCompilerError(50));
|
13180 | }
|
13181 | const resolvedOptions = extend({}, options, {
|
13182 | prefixIdentifiers
|
13183 | });
|
13184 | const ast = isString(source) ? baseParse(source, resolvedOptions) : source;
|
13185 | const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
|
13186 | transform(
|
13187 | ast,
|
13188 | extend({}, resolvedOptions, {
|
13189 | nodeTransforms: [
|
13190 | ...nodeTransforms,
|
13191 | ...options.nodeTransforms || []
|
13192 |
|
13193 | ],
|
13194 | directiveTransforms: extend(
|
13195 | {},
|
13196 | directiveTransforms,
|
13197 | options.directiveTransforms || {}
|
13198 |
|
13199 | )
|
13200 | })
|
13201 | );
|
13202 | return generate(ast, resolvedOptions);
|
13203 | }
|
13204 |
|
13205 | const noopDirectiveTransform = () => ({ props: [] });
|
13206 |
|
13207 |
|
13208 |
|
13209 |
|
13210 |
|
13211 |
|
13212 |
|
13213 | const V_MODEL_RADIO = Symbol(`vModelRadio` );
|
13214 | const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
|
13215 | const V_MODEL_TEXT = Symbol(`vModelText` );
|
13216 | const V_MODEL_SELECT = Symbol(`vModelSelect` );
|
13217 | const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
|
13218 | const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
|
13219 | const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
|
13220 | const V_SHOW = Symbol(`vShow` );
|
13221 | const TRANSITION = Symbol(`Transition` );
|
13222 | const TRANSITION_GROUP = Symbol(`TransitionGroup` );
|
13223 | registerRuntimeHelpers({
|
13224 | [V_MODEL_RADIO]: `vModelRadio`,
|
13225 | [V_MODEL_CHECKBOX]: `vModelCheckbox`,
|
13226 | [V_MODEL_TEXT]: `vModelText`,
|
13227 | [V_MODEL_SELECT]: `vModelSelect`,
|
13228 | [V_MODEL_DYNAMIC]: `vModelDynamic`,
|
13229 | [V_ON_WITH_MODIFIERS]: `withModifiers`,
|
13230 | [V_ON_WITH_KEYS]: `withKeys`,
|
13231 | [V_SHOW]: `vShow`,
|
13232 | [TRANSITION]: `Transition`,
|
13233 | [TRANSITION_GROUP]: `TransitionGroup`
|
13234 | });
|
13235 |
|
13236 | let decoder;
|
13237 | function decodeHtmlBrowser(raw, asAttr = false) {
|
13238 | if (!decoder) {
|
13239 | decoder = document.createElement("div");
|
13240 | }
|
13241 | if (asAttr) {
|
13242 | decoder.innerHTML = `<div foo="${raw.replace(/"/g, """)}">`;
|
13243 | return decoder.children[0].getAttribute("foo");
|
13244 | } else {
|
13245 | decoder.innerHTML = raw;
|
13246 | return decoder.textContent;
|
13247 | }
|
13248 | }
|
13249 |
|
13250 | const parserOptions = {
|
13251 | parseMode: "html",
|
13252 | isVoidTag,
|
13253 | isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
|
13254 | isPreTag: (tag) => tag === "pre",
|
13255 | decodeEntities: decodeHtmlBrowser ,
|
13256 | isBuiltInComponent: (tag) => {
|
13257 | if (tag === "Transition" || tag === "transition") {
|
13258 | return TRANSITION;
|
13259 | } else if (tag === "TransitionGroup" || tag === "transition-group") {
|
13260 | return TRANSITION_GROUP;
|
13261 | }
|
13262 | },
|
13263 |
|
13264 | getNamespace(tag, parent, rootNamespace) {
|
13265 | let ns = parent ? parent.ns : rootNamespace;
|
13266 | if (parent && ns === 2) {
|
13267 | if (parent.tag === "annotation-xml") {
|
13268 | if (tag === "svg") {
|
13269 | return 1;
|
13270 | }
|
13271 | if (parent.props.some(
|
13272 | (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
|
13273 | )) {
|
13274 | ns = 0;
|
13275 | }
|
13276 | } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
|
13277 | ns = 0;
|
13278 | }
|
13279 | } else if (parent && ns === 1) {
|
13280 | if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
|
13281 | ns = 0;
|
13282 | }
|
13283 | }
|
13284 | if (ns === 0) {
|
13285 | if (tag === "svg") {
|
13286 | return 1;
|
13287 | }
|
13288 | if (tag === "math") {
|
13289 | return 2;
|
13290 | }
|
13291 | }
|
13292 | return ns;
|
13293 | }
|
13294 | };
|
13295 |
|
13296 | const transformStyle = (node) => {
|
13297 | if (node.type === 1) {
|
13298 | node.props.forEach((p, i) => {
|
13299 | if (p.type === 6 && p.name === "style" && p.value) {
|
13300 | node.props[i] = {
|
13301 | type: 7,
|
13302 | name: `bind`,
|
13303 | arg: createSimpleExpression(`style`, true, p.loc),
|
13304 | exp: parseInlineCSS(p.value.content, p.loc),
|
13305 | modifiers: [],
|
13306 | loc: p.loc
|
13307 | };
|
13308 | }
|
13309 | });
|
13310 | }
|
13311 | };
|
13312 | const parseInlineCSS = (cssText, loc) => {
|
13313 | const normalized = parseStringStyle(cssText);
|
13314 | return createSimpleExpression(
|
13315 | JSON.stringify(normalized),
|
13316 | false,
|
13317 | loc,
|
13318 | 3
|
13319 | );
|
13320 | };
|
13321 |
|
13322 | function createDOMCompilerError(code, loc) {
|
13323 | return createCompilerError(
|
13324 | code,
|
13325 | loc,
|
13326 | DOMErrorMessages
|
13327 | );
|
13328 | }
|
13329 | const DOMErrorMessages = {
|
13330 | [53]: `v-html is missing expression.`,
|
13331 | [54]: `v-html will override element children.`,
|
13332 | [55]: `v-text is missing expression.`,
|
13333 | [56]: `v-text will override element children.`,
|
13334 | [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
13335 | [58]: `v-model argument is not supported on plain elements.`,
|
13336 | [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
|
13337 | [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
13338 | [61]: `v-show is missing expression.`,
|
13339 | [62]: `<Transition> expects exactly one child element or component.`,
|
13340 | [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
|
13341 | };
|
13342 |
|
13343 | const transformVHtml = (dir, node, context) => {
|
13344 | const { exp, loc } = dir;
|
13345 | if (!exp) {
|
13346 | context.onError(
|
13347 | createDOMCompilerError(53, loc)
|
13348 | );
|
13349 | }
|
13350 | if (node.children.length) {
|
13351 | context.onError(
|
13352 | createDOMCompilerError(54, loc)
|
13353 | );
|
13354 | node.children.length = 0;
|
13355 | }
|
13356 | return {
|
13357 | props: [
|
13358 | createObjectProperty(
|
13359 | createSimpleExpression(`innerHTML`, true, loc),
|
13360 | exp || createSimpleExpression("", true)
|
13361 | )
|
13362 | ]
|
13363 | };
|
13364 | };
|
13365 |
|
13366 | const transformVText = (dir, node, context) => {
|
13367 | const { exp, loc } = dir;
|
13368 | if (!exp) {
|
13369 | context.onError(
|
13370 | createDOMCompilerError(55, loc)
|
13371 | );
|
13372 | }
|
13373 | if (node.children.length) {
|
13374 | context.onError(
|
13375 | createDOMCompilerError(56, loc)
|
13376 | );
|
13377 | node.children.length = 0;
|
13378 | }
|
13379 | return {
|
13380 | props: [
|
13381 | createObjectProperty(
|
13382 | createSimpleExpression(`textContent`, true),
|
13383 | exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
|
13384 | context.helperString(TO_DISPLAY_STRING),
|
13385 | [exp],
|
13386 | loc
|
13387 | ) : createSimpleExpression("", true)
|
13388 | )
|
13389 | ]
|
13390 | };
|
13391 | };
|
13392 |
|
13393 | const transformModel = (dir, node, context) => {
|
13394 | const baseResult = transformModel$1(dir, node, context);
|
13395 | if (!baseResult.props.length || node.tagType === 1) {
|
13396 | return baseResult;
|
13397 | }
|
13398 | if (dir.arg) {
|
13399 | context.onError(
|
13400 | createDOMCompilerError(
|
13401 | 58,
|
13402 | dir.arg.loc
|
13403 | )
|
13404 | );
|
13405 | }
|
13406 | function checkDuplicatedValue() {
|
13407 | const value = findDir(node, "bind");
|
13408 | if (value && isStaticArgOf(value.arg, "value")) {
|
13409 | context.onError(
|
13410 | createDOMCompilerError(
|
13411 | 60,
|
13412 | value.loc
|
13413 | )
|
13414 | );
|
13415 | }
|
13416 | }
|
13417 | const { tag } = node;
|
13418 | const isCustomElement = context.isCustomElement(tag);
|
13419 | if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
|
13420 | let directiveToUse = V_MODEL_TEXT;
|
13421 | let isInvalidType = false;
|
13422 | if (tag === "input" || isCustomElement) {
|
13423 | const type = findProp(node, `type`);
|
13424 | if (type) {
|
13425 | if (type.type === 7) {
|
13426 | directiveToUse = V_MODEL_DYNAMIC;
|
13427 | } else if (type.value) {
|
13428 | switch (type.value.content) {
|
13429 | case "radio":
|
13430 | directiveToUse = V_MODEL_RADIO;
|
13431 | break;
|
13432 | case "checkbox":
|
13433 | directiveToUse = V_MODEL_CHECKBOX;
|
13434 | break;
|
13435 | case "file":
|
13436 | isInvalidType = true;
|
13437 | context.onError(
|
13438 | createDOMCompilerError(
|
13439 | 59,
|
13440 | dir.loc
|
13441 | )
|
13442 | );
|
13443 | break;
|
13444 | default:
|
13445 | checkDuplicatedValue();
|
13446 | break;
|
13447 | }
|
13448 | }
|
13449 | } else if (hasDynamicKeyVBind(node)) {
|
13450 | directiveToUse = V_MODEL_DYNAMIC;
|
13451 | } else {
|
13452 | checkDuplicatedValue();
|
13453 | }
|
13454 | } else if (tag === "select") {
|
13455 | directiveToUse = V_MODEL_SELECT;
|
13456 | } else {
|
13457 | checkDuplicatedValue();
|
13458 | }
|
13459 | if (!isInvalidType) {
|
13460 | baseResult.needRuntime = context.helper(directiveToUse);
|
13461 | }
|
13462 | } else {
|
13463 | context.onError(
|
13464 | createDOMCompilerError(
|
13465 | 57,
|
13466 | dir.loc
|
13467 | )
|
13468 | );
|
13469 | }
|
13470 | baseResult.props = baseResult.props.filter(
|
13471 | (p) => !(p.key.type === 4 && p.key.content === "modelValue")
|
13472 | );
|
13473 | return baseResult;
|
13474 | };
|
13475 |
|
13476 | const isEventOptionModifier = makeMap(`passive,once,capture`);
|
13477 | const isNonKeyModifier = makeMap(
|
13478 |
|
13479 | `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
|
13480 | );
|
13481 | const maybeKeyModifier = makeMap("left,right");
|
13482 | const isKeyboardEvent = makeMap(
|
13483 | `onkeyup,onkeydown,onkeypress`,
|
13484 | true
|
13485 | );
|
13486 | const resolveModifiers = (key, modifiers, context, loc) => {
|
13487 | const keyModifiers = [];
|
13488 | const nonKeyModifiers = [];
|
13489 | const eventOptionModifiers = [];
|
13490 | for (let i = 0; i < modifiers.length; i++) {
|
13491 | const modifier = modifiers[i];
|
13492 | if (modifier === "native" && checkCompatEnabled(
|
13493 | "COMPILER_V_ON_NATIVE",
|
13494 | context,
|
13495 | loc
|
13496 | )) {
|
13497 | eventOptionModifiers.push(modifier);
|
13498 | } else if (isEventOptionModifier(modifier)) {
|
13499 | eventOptionModifiers.push(modifier);
|
13500 | } else {
|
13501 | if (maybeKeyModifier(modifier)) {
|
13502 | if (isStaticExp(key)) {
|
13503 | if (isKeyboardEvent(key.content)) {
|
13504 | keyModifiers.push(modifier);
|
13505 | } else {
|
13506 | nonKeyModifiers.push(modifier);
|
13507 | }
|
13508 | } else {
|
13509 | keyModifiers.push(modifier);
|
13510 | nonKeyModifiers.push(modifier);
|
13511 | }
|
13512 | } else {
|
13513 | if (isNonKeyModifier(modifier)) {
|
13514 | nonKeyModifiers.push(modifier);
|
13515 | } else {
|
13516 | keyModifiers.push(modifier);
|
13517 | }
|
13518 | }
|
13519 | }
|
13520 | }
|
13521 | return {
|
13522 | keyModifiers,
|
13523 | nonKeyModifiers,
|
13524 | eventOptionModifiers
|
13525 | };
|
13526 | };
|
13527 | const transformClick = (key, event) => {
|
13528 | const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
|
13529 | return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
|
13530 | `(`,
|
13531 | key,
|
13532 | `) === "onClick" ? "${event}" : (`,
|
13533 | key,
|
13534 | `)`
|
13535 | ]) : key;
|
13536 | };
|
13537 | const transformOn = (dir, node, context) => {
|
13538 | return transformOn$1(dir, node, context, (baseResult) => {
|
13539 | const { modifiers } = dir;
|
13540 | if (!modifiers.length)
|
13541 | return baseResult;
|
13542 | let { key, value: handlerExp } = baseResult.props[0];
|
13543 | const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
|
13544 | if (nonKeyModifiers.includes("right")) {
|
13545 | key = transformClick(key, `onContextmenu`);
|
13546 | }
|
13547 | if (nonKeyModifiers.includes("middle")) {
|
13548 | key = transformClick(key, `onMouseup`);
|
13549 | }
|
13550 | if (nonKeyModifiers.length) {
|
13551 | handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
|
13552 | handlerExp,
|
13553 | JSON.stringify(nonKeyModifiers)
|
13554 | ]);
|
13555 | }
|
13556 | if (keyModifiers.length &&
|
13557 | (!isStaticExp(key) || isKeyboardEvent(key.content))) {
|
13558 | handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
|
13559 | handlerExp,
|
13560 | JSON.stringify(keyModifiers)
|
13561 | ]);
|
13562 | }
|
13563 | if (eventOptionModifiers.length) {
|
13564 | const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
|
13565 | key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
|
13566 | }
|
13567 | return {
|
13568 | props: [createObjectProperty(key, handlerExp)]
|
13569 | };
|
13570 | });
|
13571 | };
|
13572 |
|
13573 | const transformShow = (dir, node, context) => {
|
13574 | const { exp, loc } = dir;
|
13575 | if (!exp) {
|
13576 | context.onError(
|
13577 | createDOMCompilerError(61, loc)
|
13578 | );
|
13579 | }
|
13580 | return {
|
13581 | props: [],
|
13582 | needRuntime: context.helper(V_SHOW)
|
13583 | };
|
13584 | };
|
13585 |
|
13586 | const transformTransition = (node, context) => {
|
13587 | if (node.type === 1 && node.tagType === 1) {
|
13588 | const component = context.isBuiltInComponent(node.tag);
|
13589 | if (component === TRANSITION) {
|
13590 | return () => {
|
13591 | if (!node.children.length) {
|
13592 | return;
|
13593 | }
|
13594 | if (hasMultipleChildren(node)) {
|
13595 | context.onError(
|
13596 | createDOMCompilerError(
|
13597 | 62,
|
13598 | {
|
13599 | start: node.children[0].loc.start,
|
13600 | end: node.children[node.children.length - 1].loc.end,
|
13601 | source: ""
|
13602 | }
|
13603 | )
|
13604 | );
|
13605 | }
|
13606 | const child = node.children[0];
|
13607 | if (child.type === 1) {
|
13608 | for (const p of child.props) {
|
13609 | if (p.type === 7 && p.name === "show") {
|
13610 | node.props.push({
|
13611 | type: 6,
|
13612 | name: "persisted",
|
13613 | nameLoc: node.loc,
|
13614 | value: void 0,
|
13615 | loc: node.loc
|
13616 | });
|
13617 | }
|
13618 | }
|
13619 | }
|
13620 | };
|
13621 | }
|
13622 | }
|
13623 | };
|
13624 | function hasMultipleChildren(node) {
|
13625 | const children = node.children = node.children.filter(
|
13626 | (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
|
13627 | );
|
13628 | const child = children[0];
|
13629 | return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
|
13630 | }
|
13631 |
|
13632 | const ignoreSideEffectTags = (node, context) => {
|
13633 | if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
|
13634 | context.onError(
|
13635 | createDOMCompilerError(
|
13636 | 63,
|
13637 | node.loc
|
13638 | )
|
13639 | );
|
13640 | context.removeNode();
|
13641 | }
|
13642 | };
|
13643 |
|
13644 | const DOMNodeTransforms = [
|
13645 | transformStyle,
|
13646 | ...[transformTransition]
|
13647 | ];
|
13648 | const DOMDirectiveTransforms = {
|
13649 | cloak: noopDirectiveTransform,
|
13650 | html: transformVHtml,
|
13651 | text: transformVText,
|
13652 | model: transformModel,
|
13653 |
|
13654 | on: transformOn,
|
13655 |
|
13656 | show: transformShow
|
13657 | };
|
13658 | function compile(src, options = {}) {
|
13659 | return baseCompile(
|
13660 | src,
|
13661 | extend({}, parserOptions, options, {
|
13662 | nodeTransforms: [
|
13663 |
|
13664 |
|
13665 |
|
13666 | ignoreSideEffectTags,
|
13667 | ...DOMNodeTransforms,
|
13668 | ...options.nodeTransforms || []
|
13669 | ],
|
13670 | directiveTransforms: extend(
|
13671 | {},
|
13672 | DOMDirectiveTransforms,
|
13673 | options.directiveTransforms || {}
|
13674 | ),
|
13675 | transformHoist: null
|
13676 | })
|
13677 | );
|
13678 | }
|
13679 |
|
13680 | function processSlot(source, Vue$1) {
|
13681 | if (source === void 0) { source = ''; }
|
13682 | if (Vue$1 === void 0) { Vue$1 = Vue; }
|
13683 | var template = source.trim();
|
13684 | var hasWrappingTemplate = template && template.startsWith('<template');
|
13685 |
|
13686 | if (!hasWrappingTemplate) {
|
13687 | template = "<template #default=\"params\">".concat(template, "</template>");
|
13688 | }
|
13689 |
|
13690 |
|
13691 |
|
13692 |
|
13693 |
|
13694 |
|
13695 |
|
13696 |
|
13697 | var code = compile("<transition>".concat(template, "</transition>"), {
|
13698 | mode: 'function',
|
13699 | prefixIdentifiers: true
|
13700 | }).code;
|
13701 | var createRenderFunction = new Function('Vue', "'use strict';\n".concat(code) );
|
13702 | var renderFn = createRenderFunction(Vue$1);
|
13703 | return function (ctx) {
|
13704 | if (ctx === void 0) { ctx = {}; }
|
13705 | var result = renderFn(ctx);
|
13706 | var slotName = Object.keys(result.children)[0];
|
13707 | return result.children[slotName](ctx);
|
13708 | };
|
13709 | }
|
13710 |
|
13711 | var isTeleport = function (type) { return type.__isTeleport; };
|
13712 | var isKeepAlive = function (type) { return type.__isKeepAlive; };
|
13713 | var isRootComponent = function (rootComponents, type, instance) {
|
13714 | return !!(!instance ||
|
13715 |
|
13716 | (rootComponents.component === type && !(instance === null || instance === void 0 ? void 0 : instance.parent)) ||
|
13717 |
|
13718 | (rootComponents.functional && rootComponents.functional === type));
|
13719 | };
|
13720 | var createVNodeTransformer = function (_a) {
|
13721 | var rootComponents = _a.rootComponents, transformers = _a.transformers;
|
13722 | var transformationCache = new WeakMap();
|
13723 | return function (args, instance) {
|
13724 | var originalType = args[0], props = args[1], children = args[2], restVNodeArgs = args.slice(3);
|
13725 | if (!isComponent$1(originalType)) {
|
13726 | return __spreadArray([originalType, props, children], restVNodeArgs, true);
|
13727 | }
|
13728 | var componentType = originalType;
|
13729 | var cachedTransformation = transformationCache.get(originalType);
|
13730 | if (cachedTransformation &&
|
13731 |
|
13732 | !isRootComponent(rootComponents, componentType, instance) &&
|
13733 | !isTeleport(originalType) &&
|
13734 | !isKeepAlive(originalType)) {
|
13735 | return __spreadArray([cachedTransformation, props, children], restVNodeArgs, true);
|
13736 | }
|
13737 | var transformedType = transformers.reduce(function (type, transformer) { return transformer(type, instance); }, componentType);
|
13738 | if (originalType !== transformedType) {
|
13739 | transformationCache.set(originalType, transformedType);
|
13740 | registerStub({ source: originalType, stub: transformedType });
|
13741 |
|
13742 |
|
13743 | if (isTeleport(originalType) || isKeepAlive(originalType)) {
|
13744 | return __spreadArray([transformedType, props, function () { return children; }], restVNodeArgs, true);
|
13745 | }
|
13746 | }
|
13747 | return __spreadArray([transformedType, props, children], restVNodeArgs, true);
|
13748 | };
|
13749 | };
|
13750 |
|
13751 | var normalizeStubProps = function (props) {
|
13752 |
|
13753 | var $props = props;
|
13754 | return Object.keys($props).reduce(function (acc, key) {
|
13755 | var _a, _b, _c;
|
13756 | var _d;
|
13757 | if (typeof $props[key] === 'symbol') {
|
13758 | return __assign(__assign({}, acc), (_a = {}, _a[key] = [(_d = $props[key]) === null || _d === void 0 ? void 0 : _d.toString()], _a));
|
13759 | }
|
13760 | if (typeof $props[key] === 'function') {
|
13761 | return __assign(__assign({}, acc), (_b = {}, _b[key] = ['[Function]'], _b));
|
13762 | }
|
13763 | return __assign(__assign({}, acc), (_c = {}, _c[key] = $props[key], _c));
|
13764 | }, {});
|
13765 | };
|
13766 | var clearAndUpper = function (text) { return text.replace(/-/, '').toUpperCase(); };
|
13767 | var kebabToPascalCase = function (tag) {
|
13768 | return tag.replace(/(^\w|-\w)/g, clearAndUpper);
|
13769 | };
|
13770 | var DEFAULT_STUBS = {
|
13771 | teleport: isTeleport,
|
13772 | 'keep-alive': isKeepAlive,
|
13773 | transition: function (type) { return type === Transition || type === BaseTransition; },
|
13774 | 'transition-group': function (type) { return type === TransitionGroup; }
|
13775 | };
|
13776 | var createDefaultStub = function (kebabTag, predicate, type, stubs) {
|
13777 | var pascalTag = kebabToPascalCase(kebabTag);
|
13778 | if (predicate(type) && (pascalTag in stubs || kebabTag in stubs)) {
|
13779 | if (kebabTag in stubs && stubs[kebabTag] === false)
|
13780 | return type;
|
13781 | if (pascalTag in stubs && stubs[pascalTag] === false)
|
13782 | return type;
|
13783 | if (stubs[kebabTag] === true || stubs[pascalTag] === true) {
|
13784 | return createStub({
|
13785 | name: kebabTag,
|
13786 | type: type,
|
13787 | renderStubDefaultSlot: true
|
13788 | });
|
13789 | }
|
13790 | }
|
13791 | };
|
13792 | var createStub = function (_a) {
|
13793 | var name = _a.name, type = _a.type, renderStubDefaultSlot = _a.renderStubDefaultSlot;
|
13794 | var anonName = 'anonymous-stub';
|
13795 | var tag = name ? "".concat(hyphenate$1(name), "-stub") : anonName;
|
13796 | var componentOptions = type
|
13797 | ? unwrapLegacyVueExtendComponent(type) || {}
|
13798 | : {};
|
13799 | var stub = defineComponent({
|
13800 | name: name || anonName,
|
13801 | props: componentOptions.props || {},
|
13802 |
|
13803 |
|
13804 | model: componentOptions.model,
|
13805 | setup: function (props, _a) {
|
13806 | var slots = _a.slots;
|
13807 | return function () {
|
13808 |
|
13809 |
|
13810 |
|
13811 |
|
13812 |
|
13813 |
|
13814 |
|
13815 |
|
13816 | var stubProps = normalizeStubProps(props);
|
13817 |
|
13818 | if (renderStubDefaultSlot && slots.default) {
|
13819 |
|
13820 |
|
13821 | return h(tag, stubProps, slots.default({}));
|
13822 | }
|
13823 | return h(tag, stubProps);
|
13824 | };
|
13825 | }
|
13826 | });
|
13827 | var asyncLoader = type.__asyncLoader;
|
13828 | if (asyncLoader) {
|
13829 | asyncLoader().then(function () {
|
13830 | registerStub({
|
13831 | source: type.__asyncResolved,
|
13832 | stub: stub
|
13833 | });
|
13834 | });
|
13835 | }
|
13836 | return stub;
|
13837 | };
|
13838 | var resolveComponentStubByName = function (componentName, stubs) {
|
13839 | for (var _i = 0, _a = Object.entries(stubs); _i < _a.length; _i++) {
|
13840 | var _b = _a[_i], stubKey = _b[0], value = _b[1];
|
13841 | if (matchName(componentName, stubKey)) {
|
13842 | return value;
|
13843 | }
|
13844 | }
|
13845 | };
|
13846 | function createStubComponentsTransformer(_a) {
|
13847 | var rootComponents = _a.rootComponents, _b = _a.stubs, stubs = _b === void 0 ? {} : _b, _c = _a.shallow, shallow = _c === void 0 ? false : _c, _d = _a.renderStubDefaultSlot, renderStubDefaultSlot = _d === void 0 ? false : _d;
|
13848 | return function componentsTransformer(type, instance) {
|
13849 | var _a, _b, _c;
|
13850 | for (var tag in DEFAULT_STUBS) {
|
13851 | var predicate = DEFAULT_STUBS[tag];
|
13852 | var defaultStub = createDefaultStub(tag, predicate, type, stubs);
|
13853 | if (defaultStub)
|
13854 | return defaultStub;
|
13855 | }
|
13856 |
|
13857 | if (isRootComponent(rootComponents, type, instance)) {
|
13858 | return type;
|
13859 | }
|
13860 | var registeredName = getComponentRegisteredName(instance, type);
|
13861 | var componentName = getComponentName(instance, type);
|
13862 | var stub = null;
|
13863 | var name = null;
|
13864 |
|
13865 | if (registeredName) {
|
13866 | stub = resolveComponentStubByName(registeredName, stubs);
|
13867 | if (stub) {
|
13868 | name = registeredName;
|
13869 | }
|
13870 | }
|
13871 |
|
13872 | if (!stub && componentName) {
|
13873 | stub = resolveComponentStubByName(componentName, stubs);
|
13874 | if (stub) {
|
13875 | name = componentName;
|
13876 | }
|
13877 | }
|
13878 |
|
13879 | if (isComponent$1(stub)) {
|
13880 | var unwrappedStub = unwrapLegacyVueExtendComponent(stub);
|
13881 | var stubFn_1 = isFunctionalComponent(unwrappedStub) ? unwrappedStub : null;
|
13882 |
|
13883 |
|
13884 |
|
13885 | registerStub({ source: type, stub: stub });
|
13886 | var specializedStubComponent = stubFn_1
|
13887 | ? function () {
|
13888 | var args = [];
|
13889 | for (var _i = 0; _i < arguments.length; _i++) {
|
13890 | args[_i] = arguments[_i];
|
13891 | }
|
13892 | return stubFn_1.apply(void 0, args);
|
13893 | }
|
13894 | : __assign({}, unwrappedStub);
|
13895 | specializedStubComponent.props = unwrappedStub.props;
|
13896 | return specializedStubComponent;
|
13897 | }
|
13898 | if (stub === false) {
|
13899 |
|
13900 | return type;
|
13901 | }
|
13902 |
|
13903 |
|
13904 |
|
13905 | if (stub === true || shallow) {
|
13906 |
|
13907 | var stubName = name || registeredName || componentName;
|
13908 | return ((_c = (_b = (_a = config.plugins).createStubs) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
13909 | name: stubName,
|
13910 | component: type,
|
13911 | registerStub: registerStub
|
13912 | })) !== null && _c !== void 0 ? _c : createStub({
|
13913 | name: stubName,
|
13914 | type: type,
|
13915 | renderStubDefaultSlot: renderStubDefaultSlot
|
13916 | }));
|
13917 | }
|
13918 | return type;
|
13919 | };
|
13920 | }
|
13921 |
|
13922 | var noop = function () { };
|
13923 | function createStubDirectivesTransformer(_a) {
|
13924 | var _b = _a.directives, directives = _b === void 0 ? {} : _b;
|
13925 | if (Object.keys(directives).length === 0) {
|
13926 | return function (type) { return type; };
|
13927 | }
|
13928 | return function directivesTransformer(type) {
|
13929 | if (isObjectComponent(type) && type.directives) {
|
13930 |
|
13931 |
|
13932 | var directivesToPatch = Object.keys(type.directives).filter(function (key) { return key in directives; });
|
13933 | if (!directivesToPatch.length) {
|
13934 | return type;
|
13935 | }
|
13936 | var replacementDirectives = Object.fromEntries(directivesToPatch.map(function (name) {
|
13937 | var directive = directives[name];
|
13938 | return [name, typeof directive === 'boolean' ? noop : directive];
|
13939 | }));
|
13940 | return __assign(__assign({}, type), { directives: __assign(__assign({}, type.directives), replacementDirectives) });
|
13941 | }
|
13942 | return type;
|
13943 | };
|
13944 | }
|
13945 |
|
13946 |
|
13947 |
|
13948 |
|
13949 |
|
13950 |
|
13951 |
|
13952 |
|
13953 |
|
13954 | var deeplyCheckForRef = function (r, visitedObjects) {
|
13955 | if (isRef(r))
|
13956 | return true;
|
13957 | if (!isObject$1(r))
|
13958 | return false;
|
13959 | if (visitedObjects.has(r))
|
13960 | return false;
|
13961 | visitedObjects.set(r, true);
|
13962 | return Object.values(r).some(function (val) { return deeplyCheckForRef(val, visitedObjects); });
|
13963 | };
|
13964 |
|
13965 |
|
13966 |
|
13967 |
|
13968 |
|
13969 |
|
13970 |
|
13971 |
|
13972 |
|
13973 | var isDeepRef = function (r) {
|
13974 | var visitedObjects = new WeakMap();
|
13975 | return deeplyCheckForRef(r, visitedObjects);
|
13976 | };
|
13977 |
|
13978 | var MOUNT_OPTIONS = [
|
13979 | 'attachTo',
|
13980 | 'attrs',
|
13981 | 'data',
|
13982 | 'props',
|
13983 | 'slots',
|
13984 | 'global',
|
13985 | 'shallow'
|
13986 | ];
|
13987 | function getInstanceOptions(options) {
|
13988 | if (options.methods) {
|
13989 | console.warn("Passing a `methods` option to mount was deprecated on Vue Test Utils v1, and it won't have any effect on v2. For additional info: https://vue-test-utils.vuejs.org/upgrading-to-v1/#setmethods-and-mountingoptions-methods");
|
13990 | delete options.methods;
|
13991 | }
|
13992 | var resultOptions = __assign({}, options);
|
13993 | for (var _i = 0, _a = Object.keys(options); _i < _a.length; _i++) {
|
13994 | var key = _a[_i];
|
13995 | if (MOUNT_OPTIONS.includes(key)) {
|
13996 | delete resultOptions[key];
|
13997 | }
|
13998 | }
|
13999 | return resultOptions;
|
14000 | }
|
14001 |
|
14002 | function createInstance(inputComponent, options) {
|
14003 |
|
14004 | var originalComponent = unwrapLegacyVueExtendComponent(inputComponent);
|
14005 | var component;
|
14006 | var instanceOptions = getInstanceOptions(options !== null && options !== void 0 ? options : {});
|
14007 | var rootComponents = {};
|
14008 | if (isFunctionalComponent(originalComponent) ||
|
14009 | isLegacyFunctionalComponent(originalComponent)) {
|
14010 | component = defineComponent(__assign({ compatConfig: {
|
14011 | MODE: 3,
|
14012 | INSTANCE_LISTENERS: false,
|
14013 | INSTANCE_ATTRS_CLASS_STYLE: false,
|
14014 | COMPONENT_FUNCTIONAL: isLegacyFunctionalComponent(originalComponent)
|
14015 | ? 'suppress-warning'
|
14016 | : false
|
14017 | }, props: originalComponent.props || {}, setup: function (props, _a) {
|
14018 | var attrs = _a.attrs, slots = _a.slots;
|
14019 | return function () {
|
14020 | return h(originalComponent, __assign(__assign({}, props), attrs), slots);
|
14021 | };
|
14022 | } }, instanceOptions));
|
14023 | rootComponents.functional = originalComponent;
|
14024 | }
|
14025 | else if (isObjectComponent(originalComponent)) {
|
14026 | component = __assign(__assign({}, originalComponent), instanceOptions);
|
14027 | }
|
14028 | else {
|
14029 | component = originalComponent;
|
14030 | }
|
14031 | rootComponents.component = component;
|
14032 |
|
14033 |
|
14034 | registerStub({ source: originalComponent, stub: component });
|
14035 | function slotToFunction(slot) {
|
14036 | switch (typeof slot) {
|
14037 | case 'function':
|
14038 | return slot;
|
14039 | case 'object':
|
14040 | return function () { return h(slot); };
|
14041 | case 'string':
|
14042 | return processSlot(slot);
|
14043 | default:
|
14044 | throw Error("Invalid slot received.");
|
14045 | }
|
14046 | }
|
14047 |
|
14048 | var slots = (options === null || options === void 0 ? void 0 : options.slots) &&
|
14049 | Object.entries(options.slots).reduce(function (acc, _a) {
|
14050 | var name = _a[0], slot = _a[1];
|
14051 | if (Array.isArray(slot)) {
|
14052 | var normalized_1 = slot.map(slotToFunction);
|
14053 | acc[name] = function (args) { return normalized_1.map(function (f) { return f(args); }); };
|
14054 | return acc;
|
14055 | }
|
14056 | acc[name] = slotToFunction(slot);
|
14057 | return acc;
|
14058 | }, {});
|
14059 |
|
14060 | if (options === null || options === void 0 ? void 0 : options.data) {
|
14061 | var providedData_1 = options.data();
|
14062 | if (isObjectComponent(originalComponent)) {
|
14063 |
|
14064 | var objectComponent = component;
|
14065 | var originalDataFn_1 = originalComponent.data || (function () { return ({}); });
|
14066 | objectComponent.data = function (vm) { return (__assign(__assign({}, originalDataFn_1.call(vm, vm)), providedData_1)); };
|
14067 | }
|
14068 | else {
|
14069 | throw new Error('data() option is not supported on functional and class components');
|
14070 | }
|
14071 | }
|
14072 | var MOUNT_COMPONENT_REF = 'VTU_COMPONENT';
|
14073 |
|
14074 |
|
14075 | var refs = shallowReactive({});
|
14076 | var props = reactive({});
|
14077 | Object.entries(__assign(__assign(__assign(__assign({}, options === null || options === void 0 ? void 0 : options.attrs), options === null || options === void 0 ? void 0 : options.propsData), options === null || options === void 0 ? void 0 : options.props), { ref: MOUNT_COMPONENT_REF })).forEach(function (_a) {
|
14078 | var k = _a[0], v = _a[1];
|
14079 | if (isDeepRef(v)) {
|
14080 | refs[k] = v;
|
14081 | }
|
14082 | else {
|
14083 | props[k] = v;
|
14084 | }
|
14085 | });
|
14086 | var global = mergeGlobalProperties(options === null || options === void 0 ? void 0 : options.global);
|
14087 | if (isObjectComponent(component)) {
|
14088 | component.components = __assign(__assign({}, component.components), global.components);
|
14089 | }
|
14090 | var componentRef = ref(null);
|
14091 |
|
14092 | var Parent = defineComponent({
|
14093 | name: 'VTU_ROOT',
|
14094 | setup: function () {
|
14095 | var _a;
|
14096 | return _a = {},
|
14097 | _a[MOUNT_COMPONENT_REF] = componentRef,
|
14098 | _a;
|
14099 | },
|
14100 | render: function () {
|
14101 | return h(component, __assign(__assign({}, props), refs), slots);
|
14102 | }
|
14103 | });
|
14104 |
|
14105 | var app = createApp(Parent);
|
14106 |
|
14107 |
|
14108 | attachEmitListener();
|
14109 |
|
14110 | if (global === null || global === void 0 ? void 0 : global.mocks) {
|
14111 | var mixin = {
|
14112 | beforeCreate: function () {
|
14113 |
|
14114 |
|
14115 |
|
14116 |
|
14117 |
|
14118 |
|
14119 |
|
14120 | if (isScriptSetup(this)) {
|
14121 |
|
14122 | for (var _i = 0, _a = Object.entries(global.mocks); _i < _a.length; _i++) {
|
14123 | var _b = _a[_i], k = _b[0], v = _b[1];
|
14124 |
|
14125 | try {
|
14126 | this.$.setupState[k] = v;
|
14127 |
|
14128 | }
|
14129 | catch (e) { }
|
14130 | }
|
14131 | this.$.proxy = new Proxy(this.$.proxy, {
|
14132 | get: function (target, key) {
|
14133 | if (key in global.mocks) {
|
14134 | return global.mocks[key];
|
14135 | }
|
14136 | return target[key];
|
14137 | }
|
14138 | });
|
14139 | }
|
14140 | else {
|
14141 | for (var _c = 0, _d = Object.entries(global.mocks); _c < _d.length; _c++) {
|
14142 | var _e = _d[_c], k = _e[0], v = _e[1];
|
14143 | this[k] = v;
|
14144 | }
|
14145 | }
|
14146 | }
|
14147 | };
|
14148 | app.mixin(mixin);
|
14149 | }
|
14150 |
|
14151 | if (global.config) {
|
14152 | for (var _i = 0, _a = Object.entries(global.config); _i < _a.length; _i++) {
|
14153 | var _b = _a[_i], k = _b[0], v = _b[1];
|
14154 | app.config[k] = isObject$1(app.config[k])
|
14155 | ? Object.assign(app.config[k], v)
|
14156 | : v;
|
14157 | }
|
14158 | }
|
14159 |
|
14160 | if (global.provide) {
|
14161 | for (var _c = 0, _d = Reflect.ownKeys(global.provide); _c < _d.length; _c++) {
|
14162 | var key = _d[_c];
|
14163 |
|
14164 | app.provide(key, global.provide[key]);
|
14165 | }
|
14166 | }
|
14167 |
|
14168 | if (global.plugins) {
|
14169 | for (var _e = 0, _f = global.plugins; _e < _f.length; _e++) {
|
14170 | var plugin = _f[_e];
|
14171 | if (Array.isArray(plugin)) {
|
14172 | app.use.apply(app, __spreadArray([plugin[0]], plugin.slice(1), false));
|
14173 | continue;
|
14174 | }
|
14175 | app.use(plugin);
|
14176 | }
|
14177 | }
|
14178 |
|
14179 | if (global.mixins) {
|
14180 | for (var _g = 0, _h = global.mixins; _g < _h.length; _g++) {
|
14181 | var mixin = _h[_g];
|
14182 | app.mixin(mixin);
|
14183 | }
|
14184 | }
|
14185 | if (global.components) {
|
14186 | for (var _j = 0, _k = Object.keys(global.components); _j < _k.length; _j++) {
|
14187 | var key = _k[_j];
|
14188 |
|
14189 | if (!(key in global.stubs)) {
|
14190 | app.component(key, global.components[key]);
|
14191 | }
|
14192 | }
|
14193 | }
|
14194 | if (global.directives) {
|
14195 | for (var _l = 0, _m = Object.keys(global.directives); _l < _m.length; _l++) {
|
14196 | var key = _m[_l];
|
14197 | app.directive(key, global.directives[key]);
|
14198 | }
|
14199 | }
|
14200 |
|
14201 |
|
14202 |
|
14203 | transformVNodeArgs(createVNodeTransformer({
|
14204 | rootComponents: rootComponents,
|
14205 | transformers: [
|
14206 | createStubComponentsTransformer({
|
14207 | rootComponents: rootComponents,
|
14208 | stubs: getComponentsFromStubs(global.stubs),
|
14209 | shallow: options === null || options === void 0 ? void 0 : options.shallow,
|
14210 | renderStubDefaultSlot: global.renderStubDefaultSlot
|
14211 | }),
|
14212 | createStubDirectivesTransformer({
|
14213 | directives: getDirectivesFromStubs(global.stubs)
|
14214 | })
|
14215 | ]
|
14216 | }));
|
14217 |
|
14218 |
|
14219 |
|
14220 |
|
14221 |
|
14222 |
|
14223 |
|
14224 |
|
14225 |
|
14226 |
|
14227 | if (global === null || global === void 0 ? void 0 : global.stubs) {
|
14228 | for (var _o = 0, _p = Object.keys(getComponentsFromStubs(global.stubs)); _o < _p.length; _o++) {
|
14229 | var name_1 = _p[_o];
|
14230 | if (!app.component(name_1)) {
|
14231 | app.component(name_1, { name: name_1 });
|
14232 | }
|
14233 | }
|
14234 | }
|
14235 | return {
|
14236 | app: app,
|
14237 | props: props,
|
14238 | componentRef: componentRef
|
14239 | };
|
14240 | }
|
14241 |
|
14242 | var isEnabled = false;
|
14243 | var wrapperInstances = [];
|
14244 | function disableAutoUnmount() {
|
14245 | isEnabled = false;
|
14246 | wrapperInstances.length = 0;
|
14247 | }
|
14248 | function enableAutoUnmount(hook) {
|
14249 | if (isEnabled) {
|
14250 | throw new Error('enableAutoUnmount cannot be called more than once');
|
14251 | }
|
14252 | isEnabled = true;
|
14253 | hook(function () {
|
14254 | wrapperInstances.forEach(function (wrapper) {
|
14255 | wrapper.unmount();
|
14256 | });
|
14257 | wrapperInstances.length = 0;
|
14258 | });
|
14259 | }
|
14260 | function trackInstance(wrapper) {
|
14261 | if (!isEnabled)
|
14262 | return;
|
14263 | wrapperInstances.push(wrapper);
|
14264 | }
|
14265 |
|
14266 |
|
14267 | function mount(inputComponent, options) {
|
14268 | var _a = createInstance(inputComponent, options), app = _a.app, props = _a.props, componentRef = _a.componentRef;
|
14269 | var setProps = function (newProps) {
|
14270 | for (var _i = 0, _a = Object.entries(newProps); _i < _a.length; _i++) {
|
14271 | var _b = _a[_i], k = _b[0], v = _b[1];
|
14272 | props[k] = v;
|
14273 | }
|
14274 | return vm.$nextTick();
|
14275 | };
|
14276 |
|
14277 | var originalErrorHandler = app.config.errorHandler;
|
14278 | var errorsOnMount = [];
|
14279 | app.config.errorHandler = function (err, instance, info) {
|
14280 | errorsOnMount.push(err);
|
14281 | return originalErrorHandler === null || originalErrorHandler === void 0 ? void 0 : originalErrorHandler(err, instance, info);
|
14282 | };
|
14283 |
|
14284 | var el = document.createElement('div');
|
14285 | if (options === null || options === void 0 ? void 0 : options.attachTo) {
|
14286 | var to = void 0;
|
14287 | if (typeof options.attachTo === 'string') {
|
14288 | to = document.querySelector(options.attachTo);
|
14289 | if (!to) {
|
14290 | throw new Error("Unable to find the element matching the selector ".concat(options.attachTo, " given as the `attachTo` option"));
|
14291 | }
|
14292 | }
|
14293 | else {
|
14294 | to = options.attachTo;
|
14295 | }
|
14296 | to.appendChild(el);
|
14297 | }
|
14298 | var vm = app.mount(el);
|
14299 | if (errorsOnMount.length) {
|
14300 |
|
14301 | throw errorsOnMount[0];
|
14302 | }
|
14303 | app.config.errorHandler = originalErrorHandler;
|
14304 | var appRef = componentRef.value;
|
14305 |
|
14306 |
|
14307 | if (!app.hasOwnProperty) {
|
14308 | appRef.hasOwnProperty = function (property) {
|
14309 | return Reflect.has(appRef, property);
|
14310 | };
|
14311 | }
|
14312 | var wrapper = createVueWrapper(app, appRef, setProps);
|
14313 | trackInstance(wrapper);
|
14314 | return wrapper;
|
14315 | }
|
14316 | var shallowMount = function (component, options) {
|
14317 | return mount(component, __assign(__assign({}, options), { shallow: true }));
|
14318 | };
|
14319 |
|
14320 |
|
14321 |
|
14322 |
|
14323 |
|
14324 |
|
14325 |
|
14326 | const shouldIgnoreProp = makeMap(
|
14327 | `,key,ref,innerHTML,textContent,ref_key,ref_for`
|
14328 | );
|
14329 | function ssrRenderAttrs(props, tag) {
|
14330 | let ret = "";
|
14331 | for (const key in props) {
|
14332 | if (shouldIgnoreProp(key) || isOn(key) || tag === "textarea" && key === "value") {
|
14333 | continue;
|
14334 | }
|
14335 | const value = props[key];
|
14336 | if (key === "class") {
|
14337 | ret += ` class="${ssrRenderClass(value)}"`;
|
14338 | } else if (key === "style") {
|
14339 | ret += ` style="${ssrRenderStyle(value)}"`;
|
14340 | } else {
|
14341 | ret += ssrRenderDynamicAttr(key, value, tag);
|
14342 | }
|
14343 | }
|
14344 | return ret;
|
14345 | }
|
14346 | function ssrRenderDynamicAttr(key, value, tag) {
|
14347 | if (!isRenderableAttrValue(value)) {
|
14348 | return ``;
|
14349 | }
|
14350 | const attrKey = tag && (tag.indexOf("-") > 0 || isSVGTag(tag)) ? key : propsToAttrMap[key] || key.toLowerCase();
|
14351 | if (isBooleanAttr(attrKey)) {
|
14352 | return includeBooleanAttr(value) ? ` ${attrKey}` : ``;
|
14353 | } else if (isSSRSafeAttrName(attrKey)) {
|
14354 | return value === "" ? ` ${attrKey}` : ` ${attrKey}="${escapeHtml(value)}"`;
|
14355 | } else {
|
14356 | console.warn(
|
14357 | `[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`
|
14358 | );
|
14359 | return ``;
|
14360 | }
|
14361 | }
|
14362 | function ssrRenderClass(raw) {
|
14363 | return escapeHtml(normalizeClass(raw));
|
14364 | }
|
14365 | function ssrRenderStyle(raw) {
|
14366 | if (!raw) {
|
14367 | return "";
|
14368 | }
|
14369 | if (isString(raw)) {
|
14370 | return escapeHtml(raw);
|
14371 | }
|
14372 | const styles = normalizeStyle(raw);
|
14373 | return escapeHtml(stringifyStyle(styles));
|
14374 | }
|
14375 |
|
14376 | function ssrRenderTeleport(parentPush, contentRenderFn, target, disabled, parentComponent) {
|
14377 | parentPush("<!--teleport start-->");
|
14378 | const context = parentComponent.appContext.provides[ssrContextKey];
|
14379 | const teleportBuffers = context.__teleportBuffers || (context.__teleportBuffers = {});
|
14380 | const targetBuffer = teleportBuffers[target] || (teleportBuffers[target] = []);
|
14381 | const bufferIndex = targetBuffer.length;
|
14382 | let teleportContent;
|
14383 | if (disabled) {
|
14384 | contentRenderFn(parentPush);
|
14385 | teleportContent = `<!--teleport anchor-->`;
|
14386 | } else {
|
14387 | const { getBuffer, push } = createBuffer();
|
14388 | contentRenderFn(push);
|
14389 | push(`<!--teleport anchor-->`);
|
14390 | teleportContent = getBuffer();
|
14391 | }
|
14392 | targetBuffer.splice(bufferIndex, 0, teleportContent);
|
14393 | parentPush("<!--teleport end-->");
|
14394 | }
|
14395 |
|
14396 | {
|
14397 | const g = getGlobalThis();
|
14398 | const registerGlobalSetter = (key, setter) => {
|
14399 | let setters;
|
14400 | if (!(setters = g[key]))
|
14401 | setters = g[key] = [];
|
14402 | setters.push(setter);
|
14403 | return (v) => {
|
14404 | if (setters.length > 1)
|
14405 | setters.forEach((set) => set(v));
|
14406 | else
|
14407 | setters[0](v);
|
14408 | };
|
14409 | };
|
14410 | registerGlobalSetter(
|
14411 | `__VUE_INSTANCE_SETTERS__`,
|
14412 | (v) => v
|
14413 | );
|
14414 | registerGlobalSetter(
|
14415 | `__VUE_SSR_SETTERS__`,
|
14416 | (v) => v
|
14417 | );
|
14418 | }
|
14419 |
|
14420 | function ssrCompile(template, instance) {
|
14421 | {
|
14422 | throw new Error(
|
14423 | `On-the-fly template compilation is not supported in the ESM build of @vue/server-renderer. All templates must be pre-compiled into render functions.`
|
14424 | );
|
14425 | }
|
14426 | }
|
14427 |
|
14428 | const {
|
14429 | createComponentInstance,
|
14430 | setCurrentRenderingInstance,
|
14431 | setupComponent,
|
14432 | renderComponentRoot,
|
14433 | normalizeVNode
|
14434 | } = ssrUtils;
|
14435 | function createBuffer() {
|
14436 | let appendable = false;
|
14437 | const buffer = [];
|
14438 | return {
|
14439 | getBuffer() {
|
14440 | return buffer;
|
14441 | },
|
14442 | push(item) {
|
14443 | const isStringItem = isString(item);
|
14444 | if (appendable && isStringItem) {
|
14445 | buffer[buffer.length - 1] += item;
|
14446 | } else {
|
14447 | buffer.push(item);
|
14448 | }
|
14449 | appendable = isStringItem;
|
14450 | if (isPromise(item) || isArray(item) && item.hasAsync) {
|
14451 | buffer.hasAsync = true;
|
14452 | }
|
14453 | }
|
14454 | };
|
14455 | }
|
14456 | function renderComponentVNode(vnode, parentComponent = null, slotScopeId) {
|
14457 | const instance = createComponentInstance(vnode, parentComponent, null);
|
14458 | const res = setupComponent(
|
14459 | instance,
|
14460 | true
|
14461 |
|
14462 | );
|
14463 | const hasAsyncSetup = isPromise(res);
|
14464 | const prefetches = instance.sp;
|
14465 | if (hasAsyncSetup || prefetches) {
|
14466 | let p = hasAsyncSetup ? res : Promise.resolve();
|
14467 | if (prefetches) {
|
14468 | p = p.then(
|
14469 | () => Promise.all(
|
14470 | prefetches.map((prefetch) => prefetch.call(instance.proxy))
|
14471 | )
|
14472 | ).catch(NOOP);
|
14473 | }
|
14474 | return p.then(() => renderComponentSubTree(instance, slotScopeId));
|
14475 | } else {
|
14476 | return renderComponentSubTree(instance, slotScopeId);
|
14477 | }
|
14478 | }
|
14479 | function renderComponentSubTree(instance, slotScopeId) {
|
14480 | const comp = instance.type;
|
14481 | const { getBuffer, push } = createBuffer();
|
14482 | if (isFunction(comp)) {
|
14483 | let root = renderComponentRoot(instance);
|
14484 | if (!comp.props) {
|
14485 | for (const key in instance.attrs) {
|
14486 | if (key.startsWith(`data-v-`)) {
|
14487 | (root.props || (root.props = {}))[key] = ``;
|
14488 | }
|
14489 | }
|
14490 | }
|
14491 | renderVNode(push, instance.subTree = root, instance, slotScopeId);
|
14492 | } else {
|
14493 | if ((!instance.render || instance.render === NOOP) && !instance.ssrRender && !comp.ssrRender && isString(comp.template)) {
|
14494 | comp.ssrRender = ssrCompile(comp.template);
|
14495 | }
|
14496 | for (const e of instance.scope.effects) {
|
14497 | if (e.computed) {
|
14498 | e.computed._dirty = true;
|
14499 | e.computed._cacheable = true;
|
14500 | }
|
14501 | }
|
14502 | const ssrRender = instance.ssrRender || comp.ssrRender;
|
14503 | if (ssrRender) {
|
14504 | let attrs = instance.inheritAttrs !== false ? instance.attrs : void 0;
|
14505 | let hasCloned = false;
|
14506 | let cur = instance;
|
14507 | while (true) {
|
14508 | const scopeId = cur.vnode.scopeId;
|
14509 | if (scopeId) {
|
14510 | if (!hasCloned) {
|
14511 | attrs = { ...attrs };
|
14512 | hasCloned = true;
|
14513 | }
|
14514 | attrs[scopeId] = "";
|
14515 | }
|
14516 | const parent = cur.parent;
|
14517 | if (parent && parent.subTree && parent.subTree === cur.vnode) {
|
14518 | cur = parent;
|
14519 | } else {
|
14520 | break;
|
14521 | }
|
14522 | }
|
14523 | if (slotScopeId) {
|
14524 | if (!hasCloned)
|
14525 | attrs = { ...attrs };
|
14526 | attrs[slotScopeId.trim()] = "";
|
14527 | }
|
14528 | const prev = setCurrentRenderingInstance(instance);
|
14529 | try {
|
14530 | ssrRender(
|
14531 | instance.proxy,
|
14532 | push,
|
14533 | instance,
|
14534 | attrs,
|
14535 |
|
14536 | instance.props,
|
14537 | instance.setupState,
|
14538 | instance.data,
|
14539 | instance.ctx
|
14540 | );
|
14541 | } finally {
|
14542 | setCurrentRenderingInstance(prev);
|
14543 | }
|
14544 | } else if (instance.render && instance.render !== NOOP) {
|
14545 | renderVNode(
|
14546 | push,
|
14547 | instance.subTree = renderComponentRoot(instance),
|
14548 | instance,
|
14549 | slotScopeId
|
14550 | );
|
14551 | } else {
|
14552 | const componentName = comp.name || comp.__file || `<Anonymous>`;
|
14553 | warn(`Component ${componentName} is missing template or render function.`);
|
14554 | push(`<!---->`);
|
14555 | }
|
14556 | }
|
14557 | return getBuffer();
|
14558 | }
|
14559 | function renderVNode(push, vnode, parentComponent, slotScopeId) {
|
14560 | const { type, shapeFlag, children } = vnode;
|
14561 | switch (type) {
|
14562 | case Text:
|
14563 | push(escapeHtml(children));
|
14564 | break;
|
14565 | case Comment:
|
14566 | push(
|
14567 | children ? `<!--${escapeHtmlComment(children)}-->` : `<!---->`
|
14568 | );
|
14569 | break;
|
14570 | case Static:
|
14571 | push(children);
|
14572 | break;
|
14573 | case Fragment:
|
14574 | if (vnode.slotScopeIds) {
|
14575 | slotScopeId = (slotScopeId ? slotScopeId + " " : "") + vnode.slotScopeIds.join(" ");
|
14576 | }
|
14577 | push(`<!--[-->`);
|
14578 | renderVNodeChildren(
|
14579 | push,
|
14580 | children,
|
14581 | parentComponent,
|
14582 | slotScopeId
|
14583 | );
|
14584 | push(`<!--]-->`);
|
14585 | break;
|
14586 | default:
|
14587 | if (shapeFlag & 1) {
|
14588 | renderElementVNode(push, vnode, parentComponent, slotScopeId);
|
14589 | } else if (shapeFlag & 6) {
|
14590 | push(renderComponentVNode(vnode, parentComponent, slotScopeId));
|
14591 | } else if (shapeFlag & 64) {
|
14592 | renderTeleportVNode(push, vnode, parentComponent, slotScopeId);
|
14593 | } else if (shapeFlag & 128) {
|
14594 | renderVNode(push, vnode.ssContent, parentComponent, slotScopeId);
|
14595 | } else {
|
14596 | warn(
|
14597 | "[@vue/server-renderer] Invalid VNode type:",
|
14598 | type,
|
14599 | `(${typeof type})`
|
14600 | );
|
14601 | }
|
14602 | }
|
14603 | }
|
14604 | function renderVNodeChildren(push, children, parentComponent, slotScopeId) {
|
14605 | for (let i = 0; i < children.length; i++) {
|
14606 | renderVNode(push, normalizeVNode(children[i]), parentComponent, slotScopeId);
|
14607 | }
|
14608 | }
|
14609 | function renderElementVNode(push, vnode, parentComponent, slotScopeId) {
|
14610 | const tag = vnode.type;
|
14611 | let { props, children, shapeFlag, scopeId, dirs } = vnode;
|
14612 | let openTag = `<${tag}`;
|
14613 | if (dirs) {
|
14614 | props = applySSRDirectives(vnode, props, dirs);
|
14615 | }
|
14616 | if (props) {
|
14617 | openTag += ssrRenderAttrs(props, tag);
|
14618 | }
|
14619 | if (scopeId) {
|
14620 | openTag += ` ${scopeId}`;
|
14621 | }
|
14622 | let curParent = parentComponent;
|
14623 | let curVnode = vnode;
|
14624 | while (curParent && curVnode === curParent.subTree) {
|
14625 | curVnode = curParent.vnode;
|
14626 | if (curVnode.scopeId) {
|
14627 | openTag += ` ${curVnode.scopeId}`;
|
14628 | }
|
14629 | curParent = curParent.parent;
|
14630 | }
|
14631 | if (slotScopeId) {
|
14632 | openTag += ` ${slotScopeId}`;
|
14633 | }
|
14634 | push(openTag + `>`);
|
14635 | if (!isVoidTag(tag)) {
|
14636 | let hasChildrenOverride = false;
|
14637 | if (props) {
|
14638 | if (props.innerHTML) {
|
14639 | hasChildrenOverride = true;
|
14640 | push(props.innerHTML);
|
14641 | } else if (props.textContent) {
|
14642 | hasChildrenOverride = true;
|
14643 | push(escapeHtml(props.textContent));
|
14644 | } else if (tag === "textarea" && props.value) {
|
14645 | hasChildrenOverride = true;
|
14646 | push(escapeHtml(props.value));
|
14647 | }
|
14648 | }
|
14649 | if (!hasChildrenOverride) {
|
14650 | if (shapeFlag & 8) {
|
14651 | push(escapeHtml(children));
|
14652 | } else if (shapeFlag & 16) {
|
14653 | renderVNodeChildren(
|
14654 | push,
|
14655 | children,
|
14656 | parentComponent,
|
14657 | slotScopeId
|
14658 | );
|
14659 | }
|
14660 | }
|
14661 | push(`</${tag}>`);
|
14662 | }
|
14663 | }
|
14664 | function applySSRDirectives(vnode, rawProps, dirs) {
|
14665 | const toMerge = [];
|
14666 | for (let i = 0; i < dirs.length; i++) {
|
14667 | const binding = dirs[i];
|
14668 | const {
|
14669 | dir: { getSSRProps }
|
14670 | } = binding;
|
14671 | if (getSSRProps) {
|
14672 | const props = getSSRProps(binding, vnode);
|
14673 | if (props)
|
14674 | toMerge.push(props);
|
14675 | }
|
14676 | }
|
14677 | return mergeProps(rawProps || {}, ...toMerge);
|
14678 | }
|
14679 | function renderTeleportVNode(push, vnode, parentComponent, slotScopeId) {
|
14680 | const target = vnode.props && vnode.props.to;
|
14681 | const disabled = vnode.props && vnode.props.disabled;
|
14682 | if (!target) {
|
14683 | if (!disabled) {
|
14684 | warn(`[@vue/server-renderer] Teleport is missing target prop.`);
|
14685 | }
|
14686 | return [];
|
14687 | }
|
14688 | if (!isString(target)) {
|
14689 | warn(
|
14690 | `[@vue/server-renderer] Teleport target must be a query selector string.`
|
14691 | );
|
14692 | return [];
|
14693 | }
|
14694 | ssrRenderTeleport(
|
14695 | push,
|
14696 | (push2) => {
|
14697 | renderVNodeChildren(
|
14698 | push2,
|
14699 | vnode.children,
|
14700 | parentComponent,
|
14701 | slotScopeId
|
14702 | );
|
14703 | },
|
14704 | target,
|
14705 | disabled || disabled === "",
|
14706 | parentComponent
|
14707 | );
|
14708 | }
|
14709 |
|
14710 | const { isVNode: isVNode$1 } = ssrUtils;
|
14711 | async function unrollBuffer$1(buffer) {
|
14712 | if (buffer.hasAsync) {
|
14713 | let ret = "";
|
14714 | for (let i = 0; i < buffer.length; i++) {
|
14715 | let item = buffer[i];
|
14716 | if (isPromise(item)) {
|
14717 | item = await item;
|
14718 | }
|
14719 | if (isString(item)) {
|
14720 | ret += item;
|
14721 | } else {
|
14722 | ret += await unrollBuffer$1(item);
|
14723 | }
|
14724 | }
|
14725 | return ret;
|
14726 | } else {
|
14727 | return unrollBufferSync$1(buffer);
|
14728 | }
|
14729 | }
|
14730 | function unrollBufferSync$1(buffer) {
|
14731 | let ret = "";
|
14732 | for (let i = 0; i < buffer.length; i++) {
|
14733 | let item = buffer[i];
|
14734 | if (isString(item)) {
|
14735 | ret += item;
|
14736 | } else {
|
14737 | ret += unrollBufferSync$1(item);
|
14738 | }
|
14739 | }
|
14740 | return ret;
|
14741 | }
|
14742 | async function renderToString$1(input, context = {}) {
|
14743 | if (isVNode$1(input)) {
|
14744 | return renderToString$1(createApp({ render: () => input }), context);
|
14745 | }
|
14746 | const vnode = createVNode(input._component, input._props);
|
14747 | vnode.appContext = input._context;
|
14748 | input.provide(ssrContextKey, context);
|
14749 | const buffer = await renderComponentVNode(vnode);
|
14750 | const result = await unrollBuffer$1(buffer);
|
14751 | await resolveTeleports(context);
|
14752 | if (context.__watcherHandles) {
|
14753 | for (const unwatch of context.__watcherHandles) {
|
14754 | unwatch();
|
14755 | }
|
14756 | }
|
14757 | return result;
|
14758 | }
|
14759 | async function resolveTeleports(context) {
|
14760 | if (context.__teleportBuffers) {
|
14761 | context.teleports = context.teleports || {};
|
14762 | for (const key in context.__teleportBuffers) {
|
14763 | context.teleports[key] = await unrollBuffer$1(
|
14764 | await Promise.all([context.__teleportBuffers[key]])
|
14765 | );
|
14766 | }
|
14767 | }
|
14768 | }
|
14769 |
|
14770 | initDirectivesForSSR();
|
14771 |
|
14772 | function renderToString(component, options) {
|
14773 | if (options === null || options === void 0 ? void 0 : options.attachTo) {
|
14774 | console.warn('attachTo option is not available for renderToString');
|
14775 | }
|
14776 | var app = createInstance(component, options).app;
|
14777 | return renderToString$1(app);
|
14778 | }
|
14779 |
|
14780 |
|
14781 | var defaultRoute = {
|
14782 | path: '/',
|
14783 | name: undefined,
|
14784 | redirectedFrom: undefined,
|
14785 | params: {},
|
14786 | query: {},
|
14787 | hash: '',
|
14788 | fullPath: '/',
|
14789 | matched: [],
|
14790 | meta: {},
|
14791 | href: '/'
|
14792 | };
|
14793 |
|
14794 | var RouterLinkStub = defineComponent({
|
14795 | name: 'RouterLinkStub',
|
14796 | compatConfig: { MODE: 3 },
|
14797 | props: {
|
14798 | to: {
|
14799 | type: [String, Object],
|
14800 | required: true
|
14801 | },
|
14802 | custom: {
|
14803 | type: Boolean,
|
14804 | default: false
|
14805 | }
|
14806 | },
|
14807 | render: function () {
|
14808 | var _this = this;
|
14809 | var _a, _b;
|
14810 | var route = computed(function () { return defaultRoute; });
|
14811 |
|
14812 | var children = (_b = (_a = this.$slots) === null || _a === void 0 ? void 0 : _a.default) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
14813 | route: route,
|
14814 | href: computed(function () { return route.value.href; }),
|
14815 | isActive: computed(function () { return false; }),
|
14816 | isExactActive: computed(function () { return false; }),
|
14817 | navigate: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
14818 | return [2 ];
|
14819 | }); }); }
|
14820 | });
|
14821 | return this.custom ? children : h('a', undefined, children);
|
14822 | }
|
14823 | });
|
14824 |
|
14825 | var scheduler = typeof setImmediate === 'function' ? setImmediate : setTimeout;
|
14826 |
|
14827 | function flushPromises() {
|
14828 | return new Promise(function (resolve) {
|
14829 | scheduler(resolve, 0);
|
14830 | });
|
14831 | }
|
14832 |
|
14833 | export { BaseWrapper, DOMWrapper, RouterLinkStub, VueWrapper, config, createWrapperError, disableAutoUnmount, enableAutoUnmount, flushPromises, mount, renderToString, shallowMount };
|