ember-source 6.4.0-alpha.2 → 6.4.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-metadata.json +3 -3
- package/dist/ember-template-compiler.js +907 -1527
- package/dist/ember-testing.js +1 -1
- package/dist/ember.debug.js +3574 -4029
- package/dist/ember.prod.js +3408 -3984
- package/dist/packages/@ember/-internals/glimmer/index.js +2 -2
- package/dist/packages/@ember/-internals/owner/index.js +1 -0
- package/dist/packages/@ember/application/index.js +2 -2
- package/dist/packages/@ember/application/instance.js +1 -1
- package/dist/packages/@ember/component/helper.js +1 -1
- package/dist/packages/@ember/component/index.js +1 -1
- package/dist/packages/@ember/debug/lib/capture-render-tree.js +5 -3
- package/dist/packages/@ember/engine/index.js +2 -2
- package/dist/packages/@ember/helper/index.js +1 -1
- package/dist/packages/@ember/modifier/index.js +1 -1
- package/dist/packages/@ember/renderer/index.js +1 -1
- package/dist/packages/@ember/routing/index.js +1 -1
- package/dist/packages/@ember/template/index.js +1 -1
- package/dist/packages/@ember/template-compiler/lib/plugins/index.js +1 -1
- package/dist/packages/@ember/template-compiler/lib/plugins/transform-resolutions.js +1 -1
- package/dist/packages/@ember/template-compiler/lib/template.js +73 -89
- package/dist/packages/@glimmer/destroyable/index.js +45 -16
- package/dist/packages/@glimmer/encoder/index.js +1 -2
- package/dist/packages/@glimmer/global-context/index.js +15 -27
- package/dist/packages/@glimmer/manager/index.js +137 -84
- package/dist/packages/@glimmer/node/index.js +7 -4
- package/dist/packages/@glimmer/opcode-compiler/index.js +564 -534
- package/dist/packages/@glimmer/owner/index.js +1 -0
- package/dist/packages/@glimmer/program/index.js +42 -109
- package/dist/packages/@glimmer/reference/index.js +18 -29
- package/dist/packages/@glimmer/runtime/index.js +3435 -3263
- package/dist/packages/@glimmer/util/index.js +32 -273
- package/dist/packages/@glimmer/validator/index.js +36 -43
- package/dist/packages/@glimmer/vm/index.js +2 -140
- package/dist/packages/@glimmer/wire-format/index.js +1 -2
- package/dist/packages/ember/barrel.js +1 -1
- package/dist/packages/ember/version.js +1 -1
- package/dist/packages/ember-testing/lib/initializers.js +1 -1
- package/dist/packages/shared-chunks/{index-CQygUgr9.js → index-y5ClupI2.js} +50 -45
- package/dist/packages/shared-chunks/{setup-registry-DXuvS1Rj.js → setup-registry-8yPevDL_.js} +1 -1
- package/dist/packages/shared-chunks/{transform-resolutions-O6uYv8DS.js → transform-resolutions-Dpc2ClA0.js} +298 -441
- package/docs/data.json +40 -22
- package/package.json +21 -22
- package/types/stable/@ember/-internals/glimmer/lib/component-managers/outlet.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/component-managers/unwrap-template.d.ts +7 -0
- package/types/stable/@ember/-internals/glimmer/lib/renderer.d.ts +7 -9
- package/types/stable/@ember/-internals/glimmer/lib/resolver.d.ts +2 -5
- package/types/stable/index.d.ts +1 -0
- package/dist/packages/@glimmer/debug/index.js +0 -168
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { isDevelopingApp } from '@embroider/macros';
|
|
2
|
-
|
|
3
1
|
const EMPTY_ARRAY = Object.freeze([]);
|
|
4
2
|
function emptyArray() {
|
|
5
3
|
return EMPTY_ARRAY;
|
|
@@ -15,90 +13,46 @@ function isEmptyArray(input) {
|
|
|
15
13
|
return input === EMPTY_ARRAY;
|
|
16
14
|
}
|
|
17
15
|
function* reverse(input) {
|
|
18
|
-
for (let i = input.length - 1; i >= 0; i--)
|
|
16
|
+
for (let i = input.length - 1; i >= 0; i--)
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme
|
|
18
|
+
yield input[i];
|
|
19
19
|
}
|
|
20
20
|
function* enumerate(input) {
|
|
21
21
|
let i = 0;
|
|
22
22
|
for (const item of input) yield [i++, item];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// Logger.warn("Don't leave debug assertions on in public builds");
|
|
31
|
-
// }
|
|
32
|
-
if (!test) throw new Error(msg || "assertion failure");
|
|
33
|
-
}
|
|
34
|
-
function deprecate(desc) {
|
|
35
|
-
LOCAL_LOGGER.warn(`DEPRECATION: ${desc}`);
|
|
36
|
-
}
|
|
37
|
-
function keys(obj) {
|
|
38
|
-
return Object.keys(obj);
|
|
39
|
-
}
|
|
40
|
-
function unwrap(val) {
|
|
41
|
-
if (null == val) throw new Error("Expected value to be present");
|
|
42
|
-
return val;
|
|
43
|
-
}
|
|
44
|
-
function expect(val, message) {
|
|
45
|
-
if (null == val) throw new Error(message);
|
|
46
|
-
return val;
|
|
47
|
-
}
|
|
48
|
-
function unreachable(message = "unreachable") {
|
|
49
|
-
return new Error(message);
|
|
50
|
-
}
|
|
51
|
-
function exhausted(value) {
|
|
52
|
-
throw new Error(`Exhausted ${String(value)}`);
|
|
53
|
-
}
|
|
54
|
-
const tuple = (...args) => args;
|
|
55
|
-
function isPresent(value) {
|
|
56
|
-
return null != value;
|
|
25
|
+
/**
|
|
26
|
+
* Zip two tuples with the same type and number of elements.
|
|
27
|
+
*/
|
|
28
|
+
function* zipTuples(left, right) {
|
|
29
|
+
for (let i = 0; i < left.length; i++) yield [i, left[i], right[i]];
|
|
57
30
|
}
|
|
58
|
-
function
|
|
59
|
-
|
|
31
|
+
function* zipArrays(left, right) {
|
|
32
|
+
for (let i = 0; i < left.length; i++) {
|
|
33
|
+
const perform = i < right.length ? "retain" : "pop";
|
|
34
|
+
yield [perform, i, left[i], right[i]];
|
|
35
|
+
}
|
|
36
|
+
for (let i = left.length; i < right.length; i++) yield ["push", i, void 0, right[i]];
|
|
60
37
|
}
|
|
61
38
|
function isPresentArray(list) {
|
|
62
|
-
return list.length > 0;
|
|
63
|
-
}
|
|
64
|
-
function ifPresent(list, ifPresent, otherwise) {
|
|
65
|
-
return isPresentArray(list) ? ifPresent(list) : otherwise();
|
|
66
|
-
}
|
|
67
|
-
function arrayToOption(list) {
|
|
68
|
-
return isPresentArray(list) ? list : null;
|
|
69
|
-
}
|
|
70
|
-
function assertPresentArray(list, message = "unexpected empty list") {
|
|
71
|
-
if (!isPresentArray(list)) throw new Error(message);
|
|
72
|
-
}
|
|
73
|
-
function asPresentArray(list, message = "unexpected empty list") {
|
|
74
|
-
return assertPresentArray(list, message), list;
|
|
39
|
+
return !!list && list.length > 0;
|
|
75
40
|
}
|
|
76
41
|
function getLast(list) {
|
|
77
42
|
return 0 === list.length ? void 0 : list[list.length - 1];
|
|
78
43
|
}
|
|
79
|
-
function getFirst(list) {
|
|
80
|
-
return 0 === list.length ? void 0 : list[0];
|
|
81
|
-
}
|
|
82
|
-
function mapPresentArray(list, mapper) {
|
|
83
|
-
if (null === list) return null;
|
|
84
|
-
let out = [];
|
|
85
|
-
for (let item of list) out.push(mapper(item));
|
|
86
|
-
return out;
|
|
87
|
-
}
|
|
88
44
|
function dict() {
|
|
89
45
|
return Object.create(null);
|
|
90
46
|
}
|
|
91
47
|
function isDict(u) {
|
|
92
48
|
return null != u;
|
|
93
49
|
}
|
|
94
|
-
function
|
|
50
|
+
function isIndexable(u) {
|
|
95
51
|
return "function" == typeof u || "object" == typeof u && null !== u;
|
|
96
52
|
}
|
|
97
53
|
class StackImpl {
|
|
98
|
-
stack;
|
|
99
|
-
current = null;
|
|
100
54
|
constructor(values = []) {
|
|
101
|
-
this.stack = values;
|
|
55
|
+
this.current = null, this.stack = values;
|
|
102
56
|
}
|
|
103
57
|
get size() {
|
|
104
58
|
return this.stack.length;
|
|
@@ -112,39 +66,21 @@ class StackImpl {
|
|
|
112
66
|
}
|
|
113
67
|
nth(from) {
|
|
114
68
|
let len = this.stack.length;
|
|
115
|
-
return len < from ? null :
|
|
69
|
+
return len < from ? null : this.stack[len - from];
|
|
116
70
|
}
|
|
117
71
|
isEmpty() {
|
|
118
72
|
return 0 === this.stack.length;
|
|
119
73
|
}
|
|
74
|
+
snapshot() {
|
|
75
|
+
return [...this.stack];
|
|
76
|
+
}
|
|
120
77
|
toArray() {
|
|
121
78
|
return this.stack;
|
|
122
79
|
}
|
|
123
80
|
}
|
|
124
81
|
|
|
125
82
|
/// <reference types="qunit" />
|
|
126
|
-
let beginTestSteps, endTestSteps, verifySteps, logStep
|
|
127
|
-
if (isDevelopingApp()) {
|
|
128
|
-
let getFunctionName = fn => {
|
|
129
|
-
let functionName = fn.name;
|
|
130
|
-
if (void 0 === functionName) {
|
|
131
|
-
let match = /function (\w+)\s*\(/u.exec(String(fn));
|
|
132
|
-
functionName = match && match[1] || "";
|
|
133
|
-
}
|
|
134
|
-
return functionName.replace(/^bound /u, "");
|
|
135
|
-
},
|
|
136
|
-
getObjectName = obj => {
|
|
137
|
-
let name, className;
|
|
138
|
-
// If the class has a decent looking name, and the `toString` is one of the
|
|
139
|
-
// default Ember toStrings, replace the constructor portion of the toString
|
|
140
|
-
// with the class name. We check the length of the class name to prevent doing
|
|
141
|
-
// this when the value is minified.
|
|
142
|
-
return obj.constructor && "function" == typeof obj.constructor && (className = getFunctionName(obj.constructor)), "toString" in obj && obj.toString !== Object.prototype.toString && obj.toString !== Function.prototype.toString && (name = obj.toString()), name && /<.*:ember\d+>/u.test(name) && className && "_" !== className[0] && className.length > 2 && "Class" !== className ? name.replace(/<.*:/u, `<${className}:`) : name || className;
|
|
143
|
-
},
|
|
144
|
-
getPrimitiveName = value => String(value);
|
|
145
|
-
debugToString = value => "function" == typeof value ? getFunctionName(value) || "(unknown function)" : "object" == typeof value && null !== value ? getObjectName(value) || "(unknown object)" : getPrimitiveName(value);
|
|
146
|
-
}
|
|
147
|
-
var debugToString$1 = debugToString;
|
|
83
|
+
let beginTestSteps, endTestSteps, verifySteps, logStep;
|
|
148
84
|
function clearElement(parent) {
|
|
149
85
|
let current = parent.firstChild;
|
|
150
86
|
for (; current;) {
|
|
@@ -152,98 +88,6 @@ function clearElement(parent) {
|
|
|
152
88
|
parent.removeChild(current), current = next;
|
|
153
89
|
}
|
|
154
90
|
}
|
|
155
|
-
const RAW_NODE = -1,
|
|
156
|
-
ELEMENT_NODE = 1,
|
|
157
|
-
TEXT_NODE = 3,
|
|
158
|
-
COMMENT_NODE = 8,
|
|
159
|
-
DOCUMENT_NODE = 9,
|
|
160
|
-
DOCUMENT_TYPE_NODE = 10,
|
|
161
|
-
DOCUMENT_FRAGMENT_NODE = 11,
|
|
162
|
-
NS_HTML = "http://www.w3.org/1999/xhtml",
|
|
163
|
-
NS_MATHML = "http://www.w3.org/1998/Math/MathML",
|
|
164
|
-
NS_SVG = "http://www.w3.org/2000/svg",
|
|
165
|
-
NS_XLINK = "http://www.w3.org/1999/xlink",
|
|
166
|
-
NS_XML = "http://www.w3.org/XML/1998/namespace",
|
|
167
|
-
NS_XMLNS = "http://www.w3.org/2000/xmlns/",
|
|
168
|
-
INSERT_BEFORE_BEGIN = "beforebegin",
|
|
169
|
-
INSERT_AFTER_BEGIN = "afterbegin",
|
|
170
|
-
INSERT_BEFORE_END = "beforeend",
|
|
171
|
-
INSERT_AFTER_END = "afterend";
|
|
172
|
-
|
|
173
|
-
/*
|
|
174
|
-
Encoding notes
|
|
175
|
-
|
|
176
|
-
We use 30 bit integers for encoding, so that we don't ever encode a non-SMI
|
|
177
|
-
integer to push on the stack.
|
|
178
|
-
|
|
179
|
-
Handles are >= 0
|
|
180
|
-
Immediates are < 0
|
|
181
|
-
|
|
182
|
-
True, False, Undefined and Null are pushed as handles into the symbol table,
|
|
183
|
-
with well known handles (0, 1, 2, 3)
|
|
184
|
-
|
|
185
|
-
The negative space is divided into positives and negatives. Positives are
|
|
186
|
-
higher numbers (-1, -2, -3, etc), negatives are lower.
|
|
187
|
-
|
|
188
|
-
We only encode immediates for two reasons:
|
|
189
|
-
|
|
190
|
-
1. To transfer over the wire, so they're smaller in general
|
|
191
|
-
2. When pushing values onto the stack from the low level/inner VM, which may
|
|
192
|
-
be converted into WASM one day.
|
|
193
|
-
|
|
194
|
-
This allows the low-level VM to always use SMIs, and to minimize using JS
|
|
195
|
-
values via handles for things like the stack pointer and frame pointer.
|
|
196
|
-
Externally, most code pushes values as JS values, except when being pulled
|
|
197
|
-
from the append byte code where it was already encoded.
|
|
198
|
-
|
|
199
|
-
Logically, this is because the low level VM doesn't really care about these
|
|
200
|
-
higher level values. For instance, the result of a userland helper may be a
|
|
201
|
-
number, or a boolean, or undefined/null, but it's extra work to figure that
|
|
202
|
-
out and push it correctly, vs. just pushing the value as a JS value with a
|
|
203
|
-
handle.
|
|
204
|
-
|
|
205
|
-
Note: The details could change here in the future, this is just the current
|
|
206
|
-
strategy.
|
|
207
|
-
*/
|
|
208
|
-
let ImmediateConstants = function (ImmediateConstants) {
|
|
209
|
-
return ImmediateConstants[ImmediateConstants.MAX_SMI = 1073741823] = "MAX_SMI", ImmediateConstants[ImmediateConstants.MIN_SMI = -1073741824] = "MIN_SMI", ImmediateConstants[ImmediateConstants.SIGN_BIT = -536870913] = "SIGN_BIT", ImmediateConstants[ImmediateConstants.MAX_INT = 536870911] = "MAX_INT", ImmediateConstants[ImmediateConstants.MIN_INT = -536870912] = "MIN_INT", ImmediateConstants[ImmediateConstants.FALSE_HANDLE = 0] = "FALSE_HANDLE", ImmediateConstants[ImmediateConstants.TRUE_HANDLE = 1] = "TRUE_HANDLE", ImmediateConstants[ImmediateConstants.NULL_HANDLE = 2] = "NULL_HANDLE", ImmediateConstants[ImmediateConstants.UNDEFINED_HANDLE = 3] = "UNDEFINED_HANDLE", ImmediateConstants[ImmediateConstants.ENCODED_FALSE_HANDLE = 0] = "ENCODED_FALSE_HANDLE", ImmediateConstants[ImmediateConstants.ENCODED_TRUE_HANDLE = 1] = "ENCODED_TRUE_HANDLE", ImmediateConstants[ImmediateConstants.ENCODED_NULL_HANDLE = 2] = "ENCODED_NULL_HANDLE", ImmediateConstants[ImmediateConstants.ENCODED_UNDEFINED_HANDLE = 3] = "ENCODED_UNDEFINED_HANDLE", ImmediateConstants;
|
|
210
|
-
}({});
|
|
211
|
-
function isHandle(value) {
|
|
212
|
-
return value >= 0;
|
|
213
|
-
}
|
|
214
|
-
function isNonPrimitiveHandle(value) {
|
|
215
|
-
return value > ImmediateConstants.ENCODED_UNDEFINED_HANDLE;
|
|
216
|
-
}
|
|
217
|
-
function constants(...values) {
|
|
218
|
-
return [!1, !0, null, void 0, ...values];
|
|
219
|
-
}
|
|
220
|
-
function isSmallInt(value) {
|
|
221
|
-
return value % 1 == 0 && value <= ImmediateConstants.MAX_INT && value >= ImmediateConstants.MIN_INT;
|
|
222
|
-
}
|
|
223
|
-
function encodeNegative(num) {
|
|
224
|
-
return num & ImmediateConstants.SIGN_BIT;
|
|
225
|
-
}
|
|
226
|
-
function decodeNegative(num) {
|
|
227
|
-
return num | ~ImmediateConstants.SIGN_BIT;
|
|
228
|
-
}
|
|
229
|
-
function encodePositive(num) {
|
|
230
|
-
return ~num;
|
|
231
|
-
}
|
|
232
|
-
function decodePositive(num) {
|
|
233
|
-
return ~num;
|
|
234
|
-
}
|
|
235
|
-
function encodeHandle(num) {
|
|
236
|
-
return num;
|
|
237
|
-
}
|
|
238
|
-
function decodeHandle(num) {
|
|
239
|
-
return num;
|
|
240
|
-
}
|
|
241
|
-
function encodeImmediate(num) {
|
|
242
|
-
return (num |= 0) < 0 ? encodeNegative(num) : encodePositive(num);
|
|
243
|
-
}
|
|
244
|
-
function decodeImmediate(num) {
|
|
245
|
-
return (num |= 0) > ImmediateConstants.SIGN_BIT ? decodePositive(num) : decodeNegative(num);
|
|
246
|
-
}
|
|
247
91
|
|
|
248
92
|
/**
|
|
249
93
|
Strongly hint runtimes to intern the provided string.
|
|
@@ -290,77 +134,29 @@ function intern(str) {
|
|
|
290
134
|
for (let key in obj) if (key === str) return key;
|
|
291
135
|
return str;
|
|
292
136
|
}
|
|
293
|
-
[1, -1].forEach(x => decodeImmediate(encodeImmediate(x)));
|
|
294
137
|
const SERIALIZATION_FIRST_NODE_STRING = "%+b:0%";
|
|
295
138
|
function isSerializationFirstNode(node) {
|
|
296
139
|
return "%+b:0%" === node.nodeValue;
|
|
297
140
|
}
|
|
298
|
-
|
|
141
|
+
const assign = Object.assign;
|
|
299
142
|
function values(obj) {
|
|
300
143
|
return Object.values(obj);
|
|
301
144
|
}
|
|
302
145
|
function entries(dict) {
|
|
303
146
|
return Object.entries(dict);
|
|
304
147
|
}
|
|
305
|
-
function
|
|
306
|
-
return
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// If passed a document, verify we're in the browser and return it as a Document
|
|
310
|
-
// If we don't know what this is, but the check requires it to be an element,
|
|
311
|
-
// the cast will mandate that it's a browser element
|
|
312
|
-
// Finally, if it's a more generic check, the cast will mandate that it's a
|
|
313
|
-
// browser node and return a BrowserNodeUtils corresponding to the check
|
|
314
|
-
function castToBrowser(node, sugaryCheck) {
|
|
315
|
-
if (null == node) return null;
|
|
316
|
-
if (void 0 === typeof document) throw new Error("Attempted to cast to a browser node in a non-browser context");
|
|
317
|
-
if (isDocument(node)) return node;
|
|
318
|
-
if (node.ownerDocument !== document) throw new Error("Attempted to cast to a browser node with a node that was not created from this document");
|
|
319
|
-
return checkBrowserNode(node, sugaryCheck);
|
|
320
|
-
}
|
|
321
|
-
function isDocument(node) {
|
|
322
|
-
return node.nodeType === DOCUMENT_NODE;
|
|
323
|
-
}
|
|
324
|
-
function isSimpleElement(node) {
|
|
325
|
-
return node?.nodeType === ELEMENT_NODE;
|
|
326
|
-
}
|
|
327
|
-
function isElement(node) {
|
|
328
|
-
return node?.nodeType === ELEMENT_NODE && node instanceof Element;
|
|
329
|
-
}
|
|
330
|
-
function checkBrowserNode(node, check) {
|
|
331
|
-
let isMatch = !1;
|
|
332
|
-
if (null !== node) if ("string" == typeof check) isMatch = stringCheckNode(node, check);else {
|
|
333
|
-
if (!Array.isArray(check)) throw unreachable();
|
|
334
|
-
isMatch = check.some(c => stringCheckNode(node, c));
|
|
335
|
-
}
|
|
336
|
-
if (isMatch && node instanceof Node) return node;
|
|
337
|
-
throw function (from, check) {
|
|
338
|
-
return new Error(`cannot cast a ${from} into ${String(check)}`);
|
|
339
|
-
}(`SimpleElement(${node?.constructor?.name ?? "null"})`, check);
|
|
340
|
-
}
|
|
341
|
-
function stringCheckNode(node, check) {
|
|
342
|
-
switch (check) {
|
|
343
|
-
case "NODE":
|
|
344
|
-
return !0;
|
|
345
|
-
case "HTML":
|
|
346
|
-
return node instanceof HTMLElement;
|
|
347
|
-
case "SVG":
|
|
348
|
-
return node instanceof SVGElement;
|
|
349
|
-
case "ELEMENT":
|
|
350
|
-
return node instanceof Element;
|
|
351
|
-
default:
|
|
352
|
-
if (check.toUpperCase() === check) throw new Error("BUG: this code is missing handling for a generic node type");
|
|
353
|
-
return node instanceof Element && node.tagName.toLowerCase() === check;
|
|
354
|
-
}
|
|
148
|
+
function keys(obj) {
|
|
149
|
+
return Object.keys(obj);
|
|
355
150
|
}
|
|
356
151
|
function strip(strings, ...args) {
|
|
357
152
|
let out = "";
|
|
358
153
|
for (const [i, string] of enumerate(strings)) out += `${string}${void 0 !== args[i] ? String(args[i]) : ""}`;
|
|
359
154
|
let lines = out.split("\n");
|
|
360
|
-
for (; isPresentArray(lines) && /^\s*$/u.test(
|
|
361
|
-
for (; isPresentArray(lines) && /^\s*$/u.test(getLast(lines));) lines.pop();
|
|
155
|
+
for (; isPresentArray(lines) && /^\s*$/u.test(0 === (list = lines).length ? void 0 : list[0]);) lines.shift();
|
|
156
|
+
for (var list; isPresentArray(lines) && /^\s*$/u.test(getLast(lines));) lines.pop();
|
|
362
157
|
let min = 1 / 0;
|
|
363
158
|
for (let line of lines) {
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme
|
|
364
160
|
let leading = /^\s*/u.exec(line)[0].length;
|
|
365
161
|
min = Math.min(min, leading);
|
|
366
162
|
}
|
|
@@ -368,50 +164,13 @@ function strip(strings, ...args) {
|
|
|
368
164
|
for (let line of lines) stripped.push(line.slice(min));
|
|
369
165
|
return stripped.join("\n");
|
|
370
166
|
}
|
|
371
|
-
function unwrapHandle(handle) {
|
|
372
|
-
if ("number" == typeof handle) return handle;
|
|
373
|
-
{
|
|
374
|
-
let error = handle.errors[0];
|
|
375
|
-
throw new Error(`Compile Error: ${error.problem} @ ${error.span.start}..${error.span.end}`);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
function unwrapTemplate(template) {
|
|
379
|
-
if ("error" === template.result) throw new Error(`Compile Error: ${template.problem} @ ${template.span.start}..${template.span.end}`);
|
|
380
|
-
return template;
|
|
381
|
-
}
|
|
382
|
-
function extractHandle(handle) {
|
|
383
|
-
return "number" == typeof handle ? handle : handle.handle;
|
|
384
|
-
}
|
|
385
|
-
function isOkHandle(handle) {
|
|
386
|
-
return "number" == typeof handle;
|
|
387
|
-
}
|
|
388
|
-
function isErrHandle(handle) {
|
|
389
|
-
return "number" == typeof handle;
|
|
390
|
-
}
|
|
391
|
-
function buildUntouchableThis(source) {
|
|
392
|
-
let context = null;
|
|
393
|
-
if (isDevelopingApp()) {
|
|
394
|
-
let assertOnProperty = property => {
|
|
395
|
-
let access = "symbol" == typeof property || "number" == typeof property ? `[${String(property)}]` : `.${property}`;
|
|
396
|
-
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, \`() => {}\`).`);
|
|
397
|
-
};
|
|
398
|
-
context = new Proxy({}, {
|
|
399
|
-
get(_target, property) {
|
|
400
|
-
assertOnProperty(property);
|
|
401
|
-
},
|
|
402
|
-
set: (_target, property) => (assertOnProperty(property), !1),
|
|
403
|
-
has: (_target, property) => (assertOnProperty(property), !1)
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
return context;
|
|
407
|
-
}
|
|
408
167
|
|
|
409
168
|
/**
|
|
410
169
|
* This constant exists to make it easier to differentiate normal logs from
|
|
411
170
|
* errant console.logs. LOCAL_LOGGER should only be used inside a
|
|
412
|
-
*
|
|
171
|
+
* LOCAL_TRACE_LOGGING check.
|
|
413
172
|
*
|
|
414
|
-
* It does not alleviate the need to check
|
|
173
|
+
* It does not alleviate the need to check LOCAL_TRACE_LOGGING, which is used
|
|
415
174
|
* for stripping.
|
|
416
175
|
*/
|
|
417
176
|
const LOCAL_LOGGER = console,
|
|
@@ -419,7 +178,7 @@ const LOCAL_LOGGER = console,
|
|
|
419
178
|
|
|
420
179
|
/**
|
|
421
180
|
* This constant exists to make it easier to differentiate normal logs from
|
|
422
|
-
* errant console.logs. LOGGER can be used outside of
|
|
181
|
+
* errant console.logs. LOGGER can be used outside of LOCAL_TRACE_LOGGING checks,
|
|
423
182
|
* and is meant to be used in the rare situation where a console.* call is
|
|
424
183
|
* actually appropriate.
|
|
425
184
|
*/
|
|
@@ -427,4 +186,4 @@ function assertNever(value, desc = "unexpected unreachable branch") {
|
|
|
427
186
|
throw LOGGER.log("unreachable", value), LOGGER.log(`${desc} :: ${JSON.stringify(value)} (${value})`), new Error("code reached unreachable");
|
|
428
187
|
}
|
|
429
188
|
|
|
430
|
-
export {
|
|
189
|
+
export { EMPTY_ARRAY, EMPTY_NUMBER_ARRAY, EMPTY_STRING_ARRAY, LOCAL_LOGGER, LOGGER, SERIALIZATION_FIRST_NODE_STRING, StackImpl as Stack, assertNever, assign, beginTestSteps, clearElement, dict, emptyArray, endTestSteps, entries, enumerate, intern, isDict, isEmptyArray, isIndexable, isSerializationFirstNode, keys, logStep, reverse, strip, values, verifySteps, zipArrays, zipTuples };
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { assert, scheduleRevalidate } from '../global-context/index.js';
|
|
2
|
-
import { getLast, asPresentArray } from '../util/index.js';
|
|
3
2
|
import { isDevelopingApp } from '@embroider/macros';
|
|
4
3
|
|
|
5
|
-
function unwrap(val) {
|
|
6
|
-
if (null == val) throw new Error("Expected value to be present");
|
|
7
|
-
return val;
|
|
8
|
-
}
|
|
9
4
|
const debug = {};
|
|
10
5
|
if (isDevelopingApp()) {
|
|
11
6
|
let CONSUMED_TAGS = null;
|
|
@@ -13,7 +8,7 @@ if (isDevelopingApp()) {
|
|
|
13
8
|
TRANSACTION_ENV = {
|
|
14
9
|
debugMessage(obj, keyName) {
|
|
15
10
|
let objName;
|
|
16
|
-
return objName = "function" == typeof obj ? obj.name : "object" == typeof obj && null !== obj ? `(an instance of ${obj.constructor
|
|
11
|
+
return objName = "function" == typeof obj ? obj.name : "object" == typeof obj && null !== obj ? `(an instance of ${obj.constructor.name || "(unknown class)"})` : void 0 === obj ? "(an unknown tag)" : String(obj), `You attempted to update ${keyName ? `\`${keyName}\` on \`${objName}\`` : `\`${objName}\``}, but it had already been used previously in the same computation. Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.`;
|
|
17
12
|
}
|
|
18
13
|
};
|
|
19
14
|
/////////
|
|
@@ -49,7 +44,7 @@ if (isDevelopingApp()) {
|
|
|
49
44
|
let value = fn();
|
|
50
45
|
return didError = !1, value;
|
|
51
46
|
} finally {
|
|
52
|
-
|
|
47
|
+
didError || debug.endTrackingTransaction();
|
|
53
48
|
// if (id !== TRANSACTION_STACK.length) {
|
|
54
49
|
// throw new Error(
|
|
55
50
|
// `attempted to close a tracking transaction (${id}), but it was not the last transaction (${TRANSACTION_STACK.length})`
|
|
@@ -74,7 +69,8 @@ if (isDevelopingApp()) {
|
|
|
74
69
|
return trackingStack.map((label, index) => " ".repeat(2 * index) + label).join("\n");
|
|
75
70
|
}, debug.markTagAsConsumed = _tag => {
|
|
76
71
|
if (!CONSUMED_TAGS || CONSUMED_TAGS.has(_tag)) return;
|
|
77
|
-
|
|
72
|
+
var list;
|
|
73
|
+
CONSUMED_TAGS.set(_tag, 0 === (list = TRANSACTION_STACK).length ? void 0 : list[list.length - 1]);
|
|
78
74
|
// We need to mark the tag and all of its subtags as consumed, so we need to
|
|
79
75
|
// cast it and access its internals. In the future this shouldn't be necessary,
|
|
80
76
|
// this is only for computed properties.
|
|
@@ -84,7 +80,6 @@ if (isDevelopingApp()) {
|
|
|
84
80
|
if (null === CONSUMED_TAGS) return;
|
|
85
81
|
let transaction = CONSUMED_TAGS.get(tag);
|
|
86
82
|
var error;
|
|
87
|
-
//////////
|
|
88
83
|
if (transaction)
|
|
89
84
|
// This hack makes the assertion message nicer, we can cut off the first
|
|
90
85
|
// few lines of the stack trace and let users know where the actual error
|
|
@@ -97,6 +92,7 @@ if (isDevelopingApp()) {
|
|
|
97
92
|
if (-1 !== updateStackBegin) {
|
|
98
93
|
let start = nthIndex(e.stack, "\n", 1, updateStackBegin),
|
|
99
94
|
end = nthIndex(e.stack, "\n", 4, updateStackBegin);
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- @fixme
|
|
100
96
|
e.stack = e.stack.substr(0, start) + e.stack.substr(end);
|
|
101
97
|
}
|
|
102
98
|
}
|
|
@@ -104,6 +100,10 @@ if (isDevelopingApp()) {
|
|
|
104
100
|
}
|
|
105
101
|
};
|
|
106
102
|
}
|
|
103
|
+
function unwrap(val) {
|
|
104
|
+
if (null == val) throw new Error("Expected value to be present");
|
|
105
|
+
return val;
|
|
106
|
+
}
|
|
107
107
|
const CONSTANT = 0,
|
|
108
108
|
INITIAL = 1,
|
|
109
109
|
VOLATILE = NaN;
|
|
@@ -113,8 +113,7 @@ function bump() {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
//////////
|
|
116
|
-
const
|
|
117
|
-
COMPUTE = Symbol("TAG_COMPUTE");
|
|
116
|
+
const COMPUTE = Symbol("TAG_COMPUTE");
|
|
118
117
|
|
|
119
118
|
//////////
|
|
120
119
|
/**
|
|
@@ -144,6 +143,7 @@ function validateTag(tag, snapshot) {
|
|
|
144
143
|
}
|
|
145
144
|
|
|
146
145
|
//////////
|
|
146
|
+
Reflect.set(globalThis, "COMPUTE_SYMBOL", COMPUTE);
|
|
147
147
|
const TYPE = Symbol("TAG_TYPE");
|
|
148
148
|
|
|
149
149
|
// this is basically a const
|
|
@@ -163,21 +163,14 @@ class MonomorphicTagImpl {
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
revision = 1;
|
|
167
|
-
lastChecked = 1;
|
|
168
|
-
lastValue = 1;
|
|
169
|
-
isUpdating = !1;
|
|
170
|
-
subtag = null;
|
|
171
|
-
subtagBufferCache = null;
|
|
172
|
-
[TYPE];
|
|
173
166
|
constructor(type) {
|
|
174
|
-
this[TYPE] = type;
|
|
167
|
+
this.revision = 1, this.lastChecked = 1, this.lastValue = 1, this.isUpdating = !1, this.subtag = null, this.subtagBufferCache = null, this[TYPE] = type;
|
|
175
168
|
}
|
|
176
169
|
[COMPUTE]() {
|
|
177
170
|
let {
|
|
178
171
|
lastChecked: lastChecked
|
|
179
172
|
} = this;
|
|
180
|
-
if (
|
|
173
|
+
if (this.isUpdating) {
|
|
181
174
|
if (isDevelopingApp() && void 0 !== ALLOW_CYCLES && !ALLOW_CYCLES.has(this)) throw new Error("Cycles in tags are not allowed");
|
|
182
175
|
this.lastChecked = ++$REVISION;
|
|
183
176
|
} else if (lastChecked !== $REVISION) {
|
|
@@ -204,7 +197,9 @@ class MonomorphicTagImpl {
|
|
|
204
197
|
return this.lastValue;
|
|
205
198
|
}
|
|
206
199
|
static updateTag(_tag, _subtag) {
|
|
207
|
-
|
|
200
|
+
// catch bug by non-TS users
|
|
201
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
202
|
+
if (isDevelopingApp() && 1 !== _tag[TYPE]) throw new Error("Attempted to update a tag that was not updatable");
|
|
208
203
|
// TODO: TS 3.7 should allow us to do this via assertion
|
|
209
204
|
let tag = _tag,
|
|
210
205
|
subtag = _subtag;
|
|
@@ -227,7 +222,7 @@ class MonomorphicTagImpl {
|
|
|
227
222
|
tag.subtagBufferCache = subtag[COMPUTE](), tag.subtag = subtag);
|
|
228
223
|
}
|
|
229
224
|
static dirtyTag(tag, disableConsumptionAssertion) {
|
|
230
|
-
if (isDevelopingApp() && tag[TYPE]
|
|
225
|
+
if (isDevelopingApp() && 1 !== tag[TYPE] && 0 !== tag[TYPE]) throw new Error("Attempted to dirty a tag that was not dirtyable");
|
|
231
226
|
isDevelopingApp() && !0 !== disableConsumptionAssertion &&
|
|
232
227
|
// Usually by this point, we've already asserted with better error information,
|
|
233
228
|
// but this is our last line of defense.
|
|
@@ -242,7 +237,7 @@ function createTag() {
|
|
|
242
237
|
return new MonomorphicTagImpl(0);
|
|
243
238
|
}
|
|
244
239
|
function createUpdatableTag() {
|
|
245
|
-
return new MonomorphicTagImpl(
|
|
240
|
+
return new MonomorphicTagImpl(1);
|
|
246
241
|
}
|
|
247
242
|
|
|
248
243
|
//////////
|
|
@@ -253,19 +248,23 @@ function isConstTag(tag) {
|
|
|
253
248
|
|
|
254
249
|
//////////
|
|
255
250
|
class VolatileTag {
|
|
256
|
-
[TYPE] = 100;
|
|
257
251
|
[COMPUTE]() {
|
|
258
252
|
return NaN;
|
|
259
253
|
}
|
|
254
|
+
constructor() {
|
|
255
|
+
this[TYPE] = 100;
|
|
256
|
+
}
|
|
260
257
|
}
|
|
261
258
|
const VOLATILE_TAG = new VolatileTag();
|
|
262
259
|
|
|
263
260
|
//////////
|
|
264
261
|
class CurrentTag {
|
|
265
|
-
[TYPE] = 101;
|
|
266
262
|
[COMPUTE]() {
|
|
267
263
|
return $REVISION;
|
|
268
264
|
}
|
|
265
|
+
constructor() {
|
|
266
|
+
this[TYPE] = 101;
|
|
267
|
+
}
|
|
269
268
|
}
|
|
270
269
|
const CURRENT_TAG = new CurrentTag(),
|
|
271
270
|
combine = MonomorphicTagImpl.combine;
|
|
@@ -276,8 +275,6 @@ let tag1 = createUpdatableTag(),
|
|
|
276
275
|
tag2 = createUpdatableTag(),
|
|
277
276
|
tag3 = createUpdatableTag();
|
|
278
277
|
valueForTag(tag1), DIRTY_TAG(tag1), valueForTag(tag1), UPDATE_TAG(tag1, combine([tag2, tag3])), valueForTag(tag1), DIRTY_TAG(tag2), valueForTag(tag1), DIRTY_TAG(tag3), valueForTag(tag1), UPDATE_TAG(tag1, tag3), valueForTag(tag1), DIRTY_TAG(tag3), valueForTag(tag1);
|
|
279
|
-
|
|
280
|
-
///////////
|
|
281
278
|
const TRACKED_TAGS = new WeakMap();
|
|
282
279
|
function dirtyTagFor(obj, key, meta) {
|
|
283
280
|
if (isDevelopingApp() && ("object" != typeof (u = obj) || null === u) && "function" != typeof u) throw new Error("BUG: Can't update a tag for a primitive");
|
|
@@ -303,8 +300,6 @@ function tagFor(obj, key, meta) {
|
|
|
303
300
|
* An object that that tracks @tracked properties that were consumed.
|
|
304
301
|
*/
|
|
305
302
|
class Tracker {
|
|
306
|
-
tags = new Set();
|
|
307
|
-
last = null;
|
|
308
303
|
add(tag) {
|
|
309
304
|
tag !== CONSTANT_TAG && (this.tags.add(tag), isDevelopingApp() && unwrap(debug.markTagAsConsumed)(tag), this.last = tag);
|
|
310
305
|
}
|
|
@@ -314,6 +309,9 @@ class Tracker {
|
|
|
314
309
|
} = this;
|
|
315
310
|
return 0 === tags.size ? CONSTANT_TAG : 1 === tags.size ? this.last : combine(Array.from(this.tags));
|
|
316
311
|
}
|
|
312
|
+
constructor() {
|
|
313
|
+
this.tags = new Set(), this.last = null;
|
|
314
|
+
}
|
|
317
315
|
}
|
|
318
316
|
|
|
319
317
|
/**
|
|
@@ -361,8 +359,6 @@ function isTracking() {
|
|
|
361
359
|
function consumeTag(tag) {
|
|
362
360
|
null !== CURRENT_TRACKER && CURRENT_TRACKER.add(tag);
|
|
363
361
|
}
|
|
364
|
-
|
|
365
|
-
// public interface
|
|
366
362
|
const FN = Symbol("FN"),
|
|
367
363
|
LAST_VALUE = Symbol("LAST_VALUE"),
|
|
368
364
|
TAG = Symbol("TAG"),
|
|
@@ -409,7 +405,9 @@ function isConst(cache) {
|
|
|
409
405
|
(tag, cache), isConstTag(tag);
|
|
410
406
|
}
|
|
411
407
|
function assertCache(value, fnName) {
|
|
412
|
-
if (isDevelopingApp() && ("object" != typeof value ||
|
|
408
|
+
if (isDevelopingApp() && ("object" != typeof value || !(FN in value))) throw new Error(`${fnName}() can only be used on an instance of a cache created with createCache(). Called with: ${String(
|
|
409
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string -- @fixme
|
|
410
|
+
value)}`);
|
|
413
411
|
}
|
|
414
412
|
function track(block, debugLabel) {
|
|
415
413
|
let tag;
|
|
@@ -441,22 +439,17 @@ function trackedData(key, initializer) {
|
|
|
441
439
|
getter: function (self) {
|
|
442
440
|
let value;
|
|
443
441
|
// If the field has never been initialized, we should initialize it
|
|
444
|
-
return consumeTag(tagFor(self, key)), hasInitializer && !values.has(self) ? (
|
|
442
|
+
return consumeTag(tagFor(self, key)), hasInitializer && !values.has(self) ? (
|
|
443
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme
|
|
444
|
+
value = initializer.call(self), values.set(self, value)) : value = values.get(self), value;
|
|
445
445
|
},
|
|
446
446
|
setter: function (self, value) {
|
|
447
447
|
dirtyTagFor(self, key), values.set(self, value);
|
|
448
448
|
}
|
|
449
449
|
};
|
|
450
450
|
}
|
|
451
|
-
const GLIMMER_VALIDATOR_REGISTRATION = Symbol("GLIMMER_VALIDATOR_REGISTRATION")
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
if ("undefined" != typeof self) return self;
|
|
455
|
-
if ("undefined" != typeof window) return window;
|
|
456
|
-
if ("undefined" != typeof global) return global;
|
|
457
|
-
throw new Error("unable to locate global object");
|
|
458
|
-
}();
|
|
459
|
-
if (!0 === globalObj[GLIMMER_VALIDATOR_REGISTRATION]) throw new Error("The `@glimmer/validator` library has been included twice in this application. It could be different versions of the package, or the same version included twice by mistake. `@glimmer/validator` depends on having a single copy of the package in use at any time in an application, even if they are the same version. You must dedupe your build to remove the duplicate packages in order to prevent this error.");
|
|
460
|
-
globalObj[GLIMMER_VALIDATOR_REGISTRATION] = !0;
|
|
451
|
+
const GLIMMER_VALIDATOR_REGISTRATION = Symbol("GLIMMER_VALIDATOR_REGISTRATION");
|
|
452
|
+
if (Reflect.has(globalThis, GLIMMER_VALIDATOR_REGISTRATION)) throw new Error("The `@glimmer/validator` library has been included twice in this application. It could be different versions of the package, or the same version included twice by mistake. `@glimmer/validator` depends on having a single copy of the package in use at any time in an application, even if they are the same version. You must dedupe your build to remove the duplicate packages in order to prevent this error.");
|
|
453
|
+
Reflect.set(globalThis, GLIMMER_VALIDATOR_REGISTRATION, !0);
|
|
461
454
|
|
|
462
455
|
export { ALLOW_CYCLES, COMPUTE, CONSTANT, CONSTANT_TAG, CURRENT_TAG, CurrentTag, INITIAL, VOLATILE, VOLATILE_TAG, VolatileTag, beginTrackFrame, beginUntrackFrame, bump, combine, consumeTag, createCache, createTag, createUpdatableTag, debug, DIRTY_TAG as dirtyTag, dirtyTagFor, endTrackFrame, endUntrackFrame, getValue, isConst, isConstTag, isTracking, resetTracking, tagFor, tagMetaFor, track, trackedData, untrack, UPDATE_TAG as updateTag, validateTag, valueForTag };
|