1 | import { DEBUG } from '@glimmer/env';
|
2 |
|
3 | const EMPTY_ARRAY = Object.freeze([]);
|
4 | function emptyArray() {
|
5 | return EMPTY_ARRAY;
|
6 | }
|
7 | const EMPTY_STRING_ARRAY = emptyArray();
|
8 | const EMPTY_NUMBER_ARRAY = emptyArray();
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function isEmptyArray(input) {
|
15 | return input === EMPTY_ARRAY;
|
16 | }
|
17 | function* reverse(input) {
|
18 | for (let i = input.length - 1; i >= 0; i--) {
|
19 | yield input[i];
|
20 | }
|
21 | }
|
22 | function* enumerate(input) {
|
23 | let i = 0;
|
24 | for (const item of input) {
|
25 | yield [i++, item];
|
26 | }
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function debugAssert(test, msg) {
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | if (!test) {
|
41 | throw new Error(msg || 'assertion failure');
|
42 | }
|
43 | }
|
44 | function deprecate(desc) {
|
45 | LOCAL_LOGGER.warn(`DEPRECATION: ${desc}`);
|
46 | }
|
47 |
|
48 | function keys(obj) {
|
49 | return Object.keys(obj);
|
50 | }
|
51 | function unwrap(val) {
|
52 | if (val === null || val === undefined) throw new Error(`Expected value to be present`);
|
53 | return val;
|
54 | }
|
55 | function expect(val, message) {
|
56 | if (val === null || val === undefined) throw new Error(message);
|
57 | return val;
|
58 | }
|
59 | function unreachable(message = 'unreachable') {
|
60 | return new Error(message);
|
61 | }
|
62 | function exhausted(value) {
|
63 | throw new Error(`Exhausted ${String(value)}`);
|
64 | }
|
65 | const tuple = (...args) => args;
|
66 |
|
67 | function isPresent(value) {
|
68 | return value !== null && value !== undefined;
|
69 | }
|
70 | function assertPresent(value, message) {
|
71 | if (!isPresent(value)) {
|
72 | throw new Error(`Expected present, got ${typeof value === 'string' ? value : message}`);
|
73 | }
|
74 | }
|
75 | function isPresentArray(list) {
|
76 | return list.length > 0;
|
77 | }
|
78 | function ifPresent(list, ifPresent, otherwise) {
|
79 | if (isPresentArray(list)) {
|
80 | return ifPresent(list);
|
81 | } else {
|
82 | return otherwise();
|
83 | }
|
84 | }
|
85 | function arrayToOption(list) {
|
86 | if (isPresentArray(list)) {
|
87 | return list;
|
88 | } else {
|
89 | return null;
|
90 | }
|
91 | }
|
92 | function assertPresentArray(list, message = `unexpected empty list`) {
|
93 | if (!isPresentArray(list)) {
|
94 | throw new Error(message);
|
95 | }
|
96 | }
|
97 | function asPresentArray(list, message = `unexpected empty list`) {
|
98 | assertPresentArray(list, message);
|
99 | return list;
|
100 | }
|
101 | function getLast(list) {
|
102 | return list.length === 0 ? undefined : list[list.length - 1];
|
103 | }
|
104 | function getFirst(list) {
|
105 | return list.length === 0 ? undefined : list[0];
|
106 | }
|
107 | function mapPresentArray(list, mapper) {
|
108 | if (list === null) {
|
109 | return null;
|
110 | }
|
111 | let out = [];
|
112 | for (let item of list) {
|
113 | out.push(mapper(item));
|
114 | }
|
115 | return out;
|
116 | }
|
117 |
|
118 | function dict() {
|
119 | return Object.create(null);
|
120 | }
|
121 | function isDict(u) {
|
122 | return u !== null && u !== undefined;
|
123 | }
|
124 | function isObject(u) {
|
125 | return typeof u === 'function' || typeof u === 'object' && u !== null;
|
126 | }
|
127 | class StackImpl {
|
128 | stack;
|
129 | current = null;
|
130 | constructor(values = []) {
|
131 | this.stack = values;
|
132 | }
|
133 | get size() {
|
134 | return this.stack.length;
|
135 | }
|
136 | push(item) {
|
137 | this.current = item;
|
138 | this.stack.push(item);
|
139 | }
|
140 | pop() {
|
141 | let item = this.stack.pop();
|
142 | this.current = getLast(this.stack) ?? null;
|
143 | return item === undefined ? null : item;
|
144 | }
|
145 | nth(from) {
|
146 | let len = this.stack.length;
|
147 | return len < from ? null : unwrap(this.stack[len - from]);
|
148 | }
|
149 | isEmpty() {
|
150 | return this.stack.length === 0;
|
151 | }
|
152 | toArray() {
|
153 | return this.stack;
|
154 | }
|
155 | }
|
156 |
|
157 |
|
158 |
|
159 | let beginTestSteps;
|
160 | let endTestSteps;
|
161 | let verifySteps;
|
162 | let logStep;
|
163 |
|
164 | let debugToString;
|
165 | if (DEBUG) {
|
166 | let getFunctionName = fn => {
|
167 | let functionName = fn.name;
|
168 | if (functionName === undefined) {
|
169 | let match = /function (\w+)\s*\(/u.exec(String(fn));
|
170 | functionName = match && match[1] || '';
|
171 | }
|
172 | return functionName.replace(/^bound /u, '');
|
173 | };
|
174 | let getObjectName = obj => {
|
175 | let name;
|
176 | let className;
|
177 | if (obj.constructor && typeof obj.constructor === 'function') {
|
178 | className = getFunctionName(obj.constructor);
|
179 | }
|
180 | if ('toString' in obj && obj.toString !== Object.prototype.toString && obj.toString !== Function.prototype.toString) {
|
181 | name = obj.toString();
|
182 | }
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | if (name && /<.*:ember\d+>/u.test(name) && className && className[0] !== '_' && className.length > 2 && className !== 'Class') {
|
189 | return name.replace(/<.*:/u, `<${className}:`);
|
190 | }
|
191 | return name || className;
|
192 | };
|
193 | let getPrimitiveName = value => {
|
194 | return String(value);
|
195 | };
|
196 | debugToString = value => {
|
197 | if (typeof value === 'function') {
|
198 | return getFunctionName(value) || `(unknown function)`;
|
199 | } else if (typeof value === 'object' && value !== null) {
|
200 | return getObjectName(value) || `(unknown object)`;
|
201 | } else {
|
202 | return getPrimitiveName(value);
|
203 | }
|
204 | };
|
205 | }
|
206 | var debugToString$1 = debugToString;
|
207 |
|
208 | function clearElement(parent) {
|
209 | let current = parent.firstChild;
|
210 | while (current) {
|
211 | let next = current.nextSibling;
|
212 | parent.removeChild(current);
|
213 | current = next;
|
214 | }
|
215 | }
|
216 |
|
217 | const RAW_NODE = -1;
|
218 | const ELEMENT_NODE = 1;
|
219 | const TEXT_NODE = 3;
|
220 | const COMMENT_NODE = 8;
|
221 | const DOCUMENT_NODE = 9;
|
222 | const DOCUMENT_TYPE_NODE = 10;
|
223 | const DOCUMENT_FRAGMENT_NODE = 11;
|
224 | const NS_HTML = 'http://www.w3.org/1999/xhtml';
|
225 | const NS_MATHML = 'http://www.w3.org/1998/Math/MathML';
|
226 | const NS_SVG = 'http://www.w3.org/2000/svg';
|
227 | const NS_XLINK = 'http://www.w3.org/1999/xlink';
|
228 | const NS_XML = 'http://www.w3.org/XML/1998/namespace';
|
229 | const NS_XMLNS = 'http://www.w3.org/2000/xmlns/';
|
230 | const INSERT_BEFORE_BEGIN = 'beforebegin';
|
231 | const INSERT_AFTER_BEGIN = 'afterbegin';
|
232 | const INSERT_BEFORE_END = 'beforeend';
|
233 | const INSERT_AFTER_END = 'afterend';
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 | let ImmediateConstants = function (ImmediateConstants) {
|
272 | ImmediateConstants[ImmediateConstants["MAX_SMI"] = 1073741823] = "MAX_SMI";
|
273 | ImmediateConstants[ImmediateConstants["MIN_SMI"] = -1073741824] = "MIN_SMI";
|
274 | ImmediateConstants[ImmediateConstants["SIGN_BIT"] = -536870913] = "SIGN_BIT";
|
275 | ImmediateConstants[ImmediateConstants["MAX_INT"] = 536870911] = "MAX_INT";
|
276 | ImmediateConstants[ImmediateConstants["MIN_INT"] = -536870912] = "MIN_INT";
|
277 | ImmediateConstants[ImmediateConstants["FALSE_HANDLE"] = 0] = "FALSE_HANDLE";
|
278 | ImmediateConstants[ImmediateConstants["TRUE_HANDLE"] = 1] = "TRUE_HANDLE";
|
279 | ImmediateConstants[ImmediateConstants["NULL_HANDLE"] = 2] = "NULL_HANDLE";
|
280 | ImmediateConstants[ImmediateConstants["UNDEFINED_HANDLE"] = 3] = "UNDEFINED_HANDLE";
|
281 | ImmediateConstants[ImmediateConstants["ENCODED_FALSE_HANDLE"] = 0] = "ENCODED_FALSE_HANDLE";
|
282 | ImmediateConstants[ImmediateConstants["ENCODED_TRUE_HANDLE"] = 1] = "ENCODED_TRUE_HANDLE";
|
283 | ImmediateConstants[ImmediateConstants["ENCODED_NULL_HANDLE"] = 2] = "ENCODED_NULL_HANDLE";
|
284 | ImmediateConstants[ImmediateConstants["ENCODED_UNDEFINED_HANDLE"] = 3] = "ENCODED_UNDEFINED_HANDLE";
|
285 | return ImmediateConstants;
|
286 | }({});
|
287 | function isHandle(value) {
|
288 | return value >= 0;
|
289 | }
|
290 | function isNonPrimitiveHandle(value) {
|
291 | return value > ImmediateConstants.ENCODED_UNDEFINED_HANDLE;
|
292 | }
|
293 | function constants(...values) {
|
294 | return [false, true, null, undefined, ...values];
|
295 | }
|
296 | function isSmallInt(value) {
|
297 | return value % 1 === 0 && value <= ImmediateConstants.MAX_INT && value >= ImmediateConstants.MIN_INT;
|
298 | }
|
299 | function encodeNegative(num) {
|
300 | return num & ImmediateConstants.SIGN_BIT;
|
301 | }
|
302 | function decodeNegative(num) {
|
303 | return num | ~ImmediateConstants.SIGN_BIT;
|
304 | }
|
305 | function encodePositive(num) {
|
306 | return ~num;
|
307 | }
|
308 | function decodePositive(num) {
|
309 | return ~num;
|
310 | }
|
311 | function encodeHandle(num) {
|
312 | return num;
|
313 | }
|
314 | function decodeHandle(num) {
|
315 | return num;
|
316 | }
|
317 | function encodeImmediate(num) {
|
318 | num |= 0;
|
319 | return num < 0 ? encodeNegative(num) : encodePositive(num);
|
320 | }
|
321 | function decodeImmediate(num) {
|
322 | num |= 0;
|
323 | return num > ImmediateConstants.SIGN_BIT ? decodePositive(num) : decodeNegative(num);
|
324 | }
|
325 | [1, -1].forEach(x => decodeImmediate(encodeImmediate(x)));
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 | function intern(str) {
|
367 | let obj = {};
|
368 | obj[str] = 1;
|
369 | for (let key in obj) {
|
370 | if (key === str) {
|
371 | return key;
|
372 | }
|
373 | }
|
374 | return str;
|
375 | }
|
376 |
|
377 | const SERIALIZATION_FIRST_NODE_STRING = '%+b:0%';
|
378 | function isSerializationFirstNode(node) {
|
379 | return node.nodeValue === SERIALIZATION_FIRST_NODE_STRING;
|
380 | }
|
381 |
|
382 | let assign = Object.assign;
|
383 | function values(obj) {
|
384 | return Object.values(obj);
|
385 | }
|
386 | function entries(dict) {
|
387 | return Object.entries(dict);
|
388 | }
|
389 |
|
390 | function castToSimple(node) {
|
391 | if (isDocument(node)) {
|
392 | return node;
|
393 | } else if (isSimpleElement(node)) {
|
394 | return node;
|
395 | } else {
|
396 | return node;
|
397 | }
|
398 | }
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 | function castToBrowser(node, sugaryCheck) {
|
409 | if (node === null || node === undefined) {
|
410 | return null;
|
411 | }
|
412 | if (typeof document === undefined) {
|
413 | throw new Error('Attempted to cast to a browser node in a non-browser context');
|
414 | }
|
415 | if (isDocument(node)) {
|
416 | return node;
|
417 | }
|
418 | if (node.ownerDocument !== document) {
|
419 | throw new Error('Attempted to cast to a browser node with a node that was not created from this document');
|
420 | }
|
421 | return checkBrowserNode(node, sugaryCheck);
|
422 | }
|
423 | function checkError(from, check) {
|
424 | return new Error(`cannot cast a ${from} into ${String(check)}`);
|
425 | }
|
426 | function isDocument(node) {
|
427 | return node.nodeType === DOCUMENT_NODE;
|
428 | }
|
429 | function isSimpleElement(node) {
|
430 | return node?.nodeType === ELEMENT_NODE;
|
431 | }
|
432 | function isElement(node) {
|
433 | return node?.nodeType === ELEMENT_NODE && node instanceof Element;
|
434 | }
|
435 | function checkBrowserNode(node, check) {
|
436 | let isMatch = false;
|
437 | if (node !== null) {
|
438 | if (typeof check === 'string') {
|
439 | isMatch = stringCheckNode(node, check);
|
440 | } else if (Array.isArray(check)) {
|
441 | isMatch = check.some(c => stringCheckNode(node, c));
|
442 | } else {
|
443 | throw unreachable();
|
444 | }
|
445 | }
|
446 | if (isMatch && node instanceof Node) {
|
447 | return node;
|
448 | } else {
|
449 | throw checkError(`SimpleElement(${node?.constructor?.name ?? 'null'})`, check);
|
450 | }
|
451 | }
|
452 | function stringCheckNode(node, check) {
|
453 | switch (check) {
|
454 | case 'NODE':
|
455 | return true;
|
456 | case 'HTML':
|
457 | return node instanceof HTMLElement;
|
458 | case 'SVG':
|
459 | return node instanceof SVGElement;
|
460 | case 'ELEMENT':
|
461 | return node instanceof Element;
|
462 | default:
|
463 | if (check.toUpperCase() === check) {
|
464 | throw new Error(`BUG: this code is missing handling for a generic node type`);
|
465 | }
|
466 | return node instanceof Element && node.tagName.toLowerCase() === check;
|
467 | }
|
468 | }
|
469 |
|
470 | function strip(strings, ...args) {
|
471 | let out = '';
|
472 | for (const [i, string] of enumerate(strings)) {
|
473 | let dynamic = args[i] !== undefined ? String(args[i]) : '';
|
474 | out += `${string}${dynamic}`;
|
475 | }
|
476 | let lines = out.split('\n');
|
477 | while (isPresentArray(lines) && /^\s*$/u.test(getFirst(lines))) {
|
478 | lines.shift();
|
479 | }
|
480 | while (isPresentArray(lines) && /^\s*$/u.test(getLast(lines))) {
|
481 | lines.pop();
|
482 | }
|
483 | let min = Infinity;
|
484 | for (let line of lines) {
|
485 | let leading = /^\s*/u.exec(line)[0].length;
|
486 | min = Math.min(min, leading);
|
487 | }
|
488 | let stripped = [];
|
489 | for (let line of lines) {
|
490 | stripped.push(line.slice(min));
|
491 | }
|
492 | return stripped.join('\n');
|
493 | }
|
494 |
|
495 | function unwrapHandle(handle) {
|
496 | if (typeof handle === 'number') {
|
497 | return handle;
|
498 | } else {
|
499 | let error = handle.errors[0];
|
500 | throw new Error(`Compile Error: ${error.problem} @ ${error.span.start}..${error.span.end}`);
|
501 | }
|
502 | }
|
503 | function unwrapTemplate(template) {
|
504 | if (template.result === 'error') {
|
505 | throw new Error(`Compile Error: ${template.problem} @ ${template.span.start}..${template.span.end}`);
|
506 | }
|
507 | return template;
|
508 | }
|
509 | function extractHandle(handle) {
|
510 | if (typeof handle === 'number') {
|
511 | return handle;
|
512 | } else {
|
513 | return handle.handle;
|
514 | }
|
515 | }
|
516 | function isOkHandle(handle) {
|
517 | return typeof handle === 'number';
|
518 | }
|
519 | function isErrHandle(handle) {
|
520 | return typeof handle === 'number';
|
521 | }
|
522 |
|
523 | function buildUntouchableThis(source) {
|
524 | let context = null;
|
525 | if (DEBUG) {
|
526 | let assertOnProperty = property => {
|
527 | let access = typeof property === 'symbol' || typeof property === 'number' ? `[${String(property)}]` : `.${property}`;
|
528 | throw new Error(`You accessed \`this${access}\` from a function passed to the ${source}, but the function itself was not bound to a valid \`this\` context. Consider updating to use a bound function (for instance, use an arrow function, \`() => {}\`).`);
|
529 | };
|
530 | context = new Proxy({}, {
|
531 | get(_target, property) {
|
532 | assertOnProperty(property);
|
533 | },
|
534 | set(_target, property) {
|
535 | assertOnProperty(property);
|
536 | return false;
|
537 | },
|
538 | has(_target, property) {
|
539 | assertOnProperty(property);
|
540 | return false;
|
541 | }
|
542 | });
|
543 | }
|
544 | return context;
|
545 | }
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 | const LOCAL_LOGGER = console;
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 | const LOGGER = console;
|
564 | function assertNever(value, desc = 'unexpected unreachable branch') {
|
565 | LOGGER.log('unreachable', value);
|
566 | LOGGER.log(`${desc} :: ${JSON.stringify(value)} (${value})`);
|
567 | throw new Error(`code reached unreachable`);
|
568 | }
|
569 |
|
570 | export { COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, EMPTY_ARRAY, EMPTY_NUMBER_ARRAY, EMPTY_STRING_ARRAY, INSERT_AFTER_BEGIN, INSERT_AFTER_END, INSERT_BEFORE_BEGIN, INSERT_BEFORE_END, ImmediateConstants, LOCAL_LOGGER, LOGGER, NS_HTML, NS_MATHML, NS_SVG, NS_XLINK, NS_XML, NS_XMLNS, RAW_NODE, SERIALIZATION_FIRST_NODE_STRING, StackImpl as Stack, TEXT_NODE, arrayToOption, asPresentArray, debugAssert as assert, assertNever, assertPresent, assertPresentArray, assign, beginTestSteps, buildUntouchableThis, castToBrowser, castToSimple, checkBrowserNode as checkNode, clearElement, constants, debugToString$1 as debugToString, decodeHandle, decodeImmediate, decodeNegative, decodePositive, deprecate, dict, emptyArray, encodeHandle, encodeImmediate, encodeNegative, encodePositive, endTestSteps, entries, enumerate, exhausted, expect, extractHandle, getFirst, getLast, ifPresent, intern, isDict, isElement, isEmptyArray, isErrHandle, isHandle, isNonPrimitiveHandle, isObject, isOkHandle, isPresent, isPresentArray, isSerializationFirstNode, isSimpleElement, isSmallInt, keys, logStep, mapPresentArray, reverse, strip, tuple, unreachable, unwrap, unwrapHandle, unwrapTemplate, values, verifySteps };
|
571 |
|