ember-source 5.12.0-beta.2 → 5.12.0

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.
@@ -3,14 +3,11 @@ import { expect, isDict, EMPTY_ARRAY, isObject } from '../util/index.js';
3
3
  import { CONSTANT_TAG, validateTag, track, valueForTag, consumeTag, dirtyTag as DIRTY_TAG, createTag, INITIAL } from '../validator/index.js';
4
4
  import { isDevelopingApp } from '@embroider/macros';
5
5
 
6
- const REFERENCE = Symbol('REFERENCE');
7
- const CONSTANT = 0;
8
- const COMPUTE = 1;
9
- const UNBOUND = 2;
10
- const INVOKABLE = 3;
6
+ const REFERENCE = Symbol("REFERENCE"),
7
+ COMPUTE = 1,
8
+ UNBOUND = 2;
11
9
 
12
10
  //////////
13
-
14
11
  class ReferenceImpl {
15
12
  [REFERENCE];
16
13
  tag = null;
@@ -26,229 +23,113 @@ class ReferenceImpl {
26
23
  }
27
24
  function createPrimitiveRef(value) {
28
25
  const ref = new ReferenceImpl(UNBOUND);
29
- ref.tag = CONSTANT_TAG;
30
- ref.lastValue = value;
31
- if (isDevelopingApp()) {
32
- ref.debugLabel = String(value);
33
- }
34
- return ref;
26
+ return ref.tag = CONSTANT_TAG, ref.lastValue = value, isDevelopingApp() && (ref.debugLabel = String(value)), ref;
35
27
  }
36
- const UNDEFINED_REFERENCE = createPrimitiveRef(undefined);
37
- const NULL_REFERENCE = createPrimitiveRef(null);
38
- const TRUE_REFERENCE = createPrimitiveRef(true);
39
- const FALSE_REFERENCE = createPrimitiveRef(false);
28
+ const UNDEFINED_REFERENCE = createPrimitiveRef(void 0),
29
+ NULL_REFERENCE = createPrimitiveRef(null),
30
+ TRUE_REFERENCE = createPrimitiveRef(!0),
31
+ FALSE_REFERENCE = createPrimitiveRef(!1);
40
32
  function createConstRef(value, debugLabel) {
41
- const ref = new ReferenceImpl(CONSTANT);
42
- ref.lastValue = value;
43
- ref.tag = CONSTANT_TAG;
44
- if (isDevelopingApp()) {
45
- ref.debugLabel = debugLabel;
46
- }
47
- return ref;
33
+ const ref = new ReferenceImpl(0);
34
+ return ref.lastValue = value, ref.tag = CONSTANT_TAG, isDevelopingApp() && (ref.debugLabel = debugLabel), ref;
48
35
  }
49
36
  function createUnboundRef(value, debugLabel) {
50
37
  const ref = new ReferenceImpl(UNBOUND);
51
- ref.lastValue = value;
52
- ref.tag = CONSTANT_TAG;
53
- if (isDevelopingApp()) {
54
- ref.debugLabel = debugLabel;
55
- }
56
- return ref;
38
+ return ref.lastValue = value, ref.tag = CONSTANT_TAG, isDevelopingApp() && (ref.debugLabel = debugLabel), ref;
57
39
  }
58
- function createComputeRef(compute, update = null, debugLabel = 'unknown') {
40
+ function createComputeRef(compute, update = null, debugLabel = "unknown") {
59
41
  const ref = new ReferenceImpl(COMPUTE);
60
- ref.compute = compute;
61
- ref.update = update;
62
- if (isDevelopingApp()) {
63
- ref.debugLabel = `(result of a \`${debugLabel}\` helper)`;
64
- }
65
- return ref;
42
+ return ref.compute = compute, ref.update = update, isDevelopingApp() && (ref.debugLabel = `(result of a \`${debugLabel}\` helper)`), ref;
66
43
  }
67
44
  function createReadOnlyRef(ref) {
68
- if (!isUpdatableRef(ref)) return ref;
69
- return createComputeRef(() => valueForRef(ref), null, ref.debugLabel);
45
+ return isUpdatableRef(ref) ? createComputeRef(() => valueForRef(ref), null, ref.debugLabel) : ref;
70
46
  }
71
47
  function isInvokableRef(ref) {
72
- return ref[REFERENCE] === INVOKABLE;
48
+ return 3 === ref[REFERENCE];
73
49
  }
74
50
  function createInvokableRef(inner) {
75
51
  const ref = createComputeRef(() => valueForRef(inner), value => updateRef(inner, value));
76
- ref.debugLabel = inner.debugLabel;
77
- ref[REFERENCE] = INVOKABLE;
78
- return ref;
52
+ return ref.debugLabel = inner.debugLabel, ref[REFERENCE] = 3, ref;
79
53
  }
80
54
  function isConstRef(_ref) {
81
- const ref = _ref;
82
- return ref.tag === CONSTANT_TAG;
55
+ return _ref.tag === CONSTANT_TAG;
83
56
  }
84
57
  function isUpdatableRef(_ref) {
85
- const ref = _ref;
86
- return ref.update !== null;
58
+ return null !== _ref.update;
87
59
  }
88
60
  function valueForRef(_ref) {
89
61
  const ref = _ref;
90
62
  let {
91
- tag
63
+ tag: tag
92
64
  } = ref;
93
- if (tag === CONSTANT_TAG) {
94
- return ref.lastValue;
95
- }
65
+ if (tag === CONSTANT_TAG) return ref.lastValue;
96
66
  const {
97
- lastRevision
67
+ lastRevision: lastRevision
98
68
  } = ref;
99
69
  let lastValue;
100
- if (tag === null || !validateTag(tag, lastRevision)) {
70
+ if (null !== tag && validateTag(tag, lastRevision)) lastValue = ref.lastValue;else {
101
71
  const {
102
- compute
103
- } = ref;
104
- const newTag = track(() => {
105
- lastValue = ref.lastValue = compute();
106
- }, isDevelopingApp() && ref.debugLabel);
107
- tag = ref.tag = newTag;
108
- ref.lastRevision = valueForTag(newTag);
109
- } else {
110
- lastValue = ref.lastValue;
72
+ compute: compute
73
+ } = ref,
74
+ newTag = track(() => {
75
+ lastValue = ref.lastValue = compute();
76
+ }, isDevelopingApp() && ref.debugLabel);
77
+ tag = ref.tag = newTag, ref.lastRevision = valueForTag(newTag);
111
78
  }
112
- consumeTag(tag);
113
- return lastValue;
79
+ return consumeTag(tag), lastValue;
114
80
  }
115
81
  function updateRef(_ref, value) {
116
- const ref = _ref;
117
- const update = expect(ref.update, 'called update on a non-updatable reference');
118
- update(value);
82
+ expect(_ref.update, "called update on a non-updatable reference")(value);
119
83
  }
120
84
  function childRefFor(_parentRef, path) {
121
- const parentRef = _parentRef;
122
- const type = parentRef[REFERENCE];
123
- let children = parentRef.children;
124
- let child;
125
- if (children === null) {
126
- children = parentRef.children = new Map();
127
- } else {
128
- child = children.get(path);
129
- if (child !== undefined) {
130
- return child;
131
- }
132
- }
85
+ const parentRef = _parentRef,
86
+ type = parentRef[REFERENCE];
87
+ let child,
88
+ children = parentRef.children;
89
+ if (null === children) children = parentRef.children = new Map();else if (child = children.get(path), void 0 !== child) return child;
133
90
  if (type === UNBOUND) {
134
91
  const parent = valueForRef(parentRef);
135
- if (isDict(parent)) {
136
- child = createUnboundRef(parent[path], isDevelopingApp() && `${parentRef.debugLabel}.${path}`);
137
- } else {
138
- child = UNDEFINED_REFERENCE;
139
- }
140
- } else {
141
- child = createComputeRef(() => {
142
- const parent = valueForRef(parentRef);
143
- if (isDict(parent)) {
144
- return getProp(parent, path);
145
- }
146
- }, val => {
147
- const parent = valueForRef(parentRef);
148
- if (isDict(parent)) {
149
- return setProp(parent, path, val);
150
- }
151
- });
152
- if (isDevelopingApp()) {
153
- child.debugLabel = `${parentRef.debugLabel}.${path}`;
154
- }
155
- }
156
- children.set(path, child);
157
- return child;
92
+ child = isDict(parent) ? createUnboundRef(parent[path], isDevelopingApp() && `${parentRef.debugLabel}.${path}`) : UNDEFINED_REFERENCE;
93
+ } else child = createComputeRef(() => {
94
+ const parent = valueForRef(parentRef);
95
+ if (isDict(parent)) return getProp(parent, path);
96
+ }, val => {
97
+ const parent = valueForRef(parentRef);
98
+ if (isDict(parent)) return setProp(parent, path, val);
99
+ }), isDevelopingApp() && (child.debugLabel = `${parentRef.debugLabel}.${path}`);
100
+ return children.set(path, child), child;
158
101
  }
159
102
  function childRefFromParts(root, parts) {
160
103
  let reference = root;
161
- for (const part of parts) {
162
- reference = childRefFor(reference, part);
163
- }
104
+ for (const part of parts) reference = childRefFor(reference, part);
164
105
  return reference;
165
106
  }
166
107
  let createDebugAliasRef;
167
- if (isDevelopingApp()) {
168
- createDebugAliasRef = (debugLabel, inner) => {
169
- const update = isUpdatableRef(inner) ? value => updateRef(inner, value) : null;
170
- const ref = createComputeRef(() => valueForRef(inner), update);
171
- ref[REFERENCE] = inner[REFERENCE];
172
- ref.debugLabel = debugLabel;
173
- return ref;
174
- };
175
- }
176
- const NULL_IDENTITY = {};
177
- const KEY = (_, index) => index;
178
- const INDEX = (_, index) => String(index);
179
- const IDENTITY = item => {
180
- if (item === null) {
181
- // Returning null as an identity will cause failures since the iterator
182
- // can't tell that it's actually supposed to be null
183
- return NULL_IDENTITY;
184
- }
185
- return item;
186
- };
187
- function keyForPath(path) {
188
- if (isDevelopingApp() && path[0] === '@') {
189
- throw new Error(`invalid keypath: '${path}', valid keys: @index, @identity, or a path`);
190
- }
191
- return uniqueKeyFor(item => getPath(item, path));
192
- }
193
- function makeKeyFor(key) {
194
- switch (key) {
195
- case '@key':
196
- return uniqueKeyFor(KEY);
197
- case '@index':
198
- return uniqueKeyFor(INDEX);
199
- case '@identity':
200
- return uniqueKeyFor(IDENTITY);
201
- default:
202
- return keyForPath(key);
203
- }
204
- }
108
+ isDevelopingApp() && (createDebugAliasRef = (debugLabel, inner) => {
109
+ const ref = createComputeRef(() => valueForRef(inner), isUpdatableRef(inner) ? value => updateRef(inner, value) : null);
110
+ return ref[REFERENCE] = inner[REFERENCE], ref.debugLabel = debugLabel, ref;
111
+ });
112
+ const NULL_IDENTITY = {},
113
+ KEY = (_, index) => index,
114
+ INDEX = (_, index) => String(index),
115
+ IDENTITY = item => null === item ? NULL_IDENTITY : item;
205
116
  class WeakMapWithPrimitives {
206
117
  _weakMap;
207
118
  _primitiveMap;
208
119
  get weakMap() {
209
- if (this._weakMap === undefined) {
210
- this._weakMap = new WeakMap();
211
- }
212
- return this._weakMap;
120
+ return void 0 === this._weakMap && (this._weakMap = new WeakMap()), this._weakMap;
213
121
  }
214
122
  get primitiveMap() {
215
- if (this._primitiveMap === undefined) {
216
- this._primitiveMap = new Map();
217
- }
218
- return this._primitiveMap;
123
+ return void 0 === this._primitiveMap && (this._primitiveMap = new Map()), this._primitiveMap;
219
124
  }
220
125
  set(key, value) {
221
- if (isObject(key)) {
222
- this.weakMap.set(key, value);
223
- } else {
224
- this.primitiveMap.set(key, value);
225
- }
126
+ isObject(key) ? this.weakMap.set(key, value) : this.primitiveMap.set(key, value);
226
127
  }
227
128
  get(key) {
228
- if (isObject(key)) {
229
- return this.weakMap.get(key);
230
- } else {
231
- return this.primitiveMap.get(key);
232
- }
129
+ return isObject(key) ? this.weakMap.get(key) : this.primitiveMap.get(key);
233
130
  }
234
131
  }
235
132
  const IDENTITIES = new WeakMapWithPrimitives();
236
- function identityForNthOccurence(value, count) {
237
- let identities = IDENTITIES.get(value);
238
- if (identities === undefined) {
239
- identities = [];
240
- IDENTITIES.set(value, identities);
241
- }
242
- let identity = identities[count];
243
- if (identity === undefined) {
244
- identity = {
245
- value,
246
- count
247
- };
248
- identities[count] = identity;
249
- }
250
- return identity;
251
- }
252
133
 
253
134
  /**
254
135
  * When iterating over a list, it's possible that an item with the same unique
@@ -268,100 +149,91 @@ function identityForNthOccurence(value, count) {
268
149
  function uniqueKeyFor(keyFor) {
269
150
  let seen = new WeakMapWithPrimitives();
270
151
  return (value, memo) => {
271
- let key = keyFor(value, memo);
272
- let count = seen.get(key) || 0;
273
- seen.set(key, count + 1);
274
- if (count === 0) {
275
- return key;
276
- }
277
- return identityForNthOccurence(key, count);
152
+ let key = keyFor(value, memo),
153
+ count = seen.get(key) || 0;
154
+ return seen.set(key, count + 1), 0 === count ? key : function (value, count) {
155
+ let identities = IDENTITIES.get(value);
156
+ void 0 === identities && (identities = [], IDENTITIES.set(value, identities));
157
+ let identity = identities[count];
158
+ return void 0 === identity && (identity = {
159
+ value: value,
160
+ count: count
161
+ }, identities[count] = identity), identity;
162
+ }(key, count);
278
163
  };
279
164
  }
280
165
  function createIteratorRef(listRef, key) {
281
166
  return createComputeRef(() => {
282
- let iterable = valueForRef(listRef);
283
- let keyFor = makeKeyFor(key);
284
- if (Array.isArray(iterable)) {
285
- return new ArrayIterator(iterable, keyFor);
286
- }
167
+ let iterable = valueForRef(listRef),
168
+ keyFor = function (key) {
169
+ switch (key) {
170
+ case "@key":
171
+ return uniqueKeyFor(KEY);
172
+ case "@index":
173
+ return uniqueKeyFor(INDEX);
174
+ case "@identity":
175
+ return uniqueKeyFor(IDENTITY);
176
+ default:
177
+ return function (path) {
178
+ if (isDevelopingApp() && "@" === path[0]) throw new Error(`invalid keypath: '${path}', valid keys: @index, @identity, or a path`);
179
+ return uniqueKeyFor(item => getPath(item, path));
180
+ }(key);
181
+ }
182
+ }(key);
183
+ if (Array.isArray(iterable)) return new ArrayIterator(iterable, keyFor);
287
184
  let maybeIterator = toIterator(iterable);
288
- if (maybeIterator === null) {
289
- return new ArrayIterator(EMPTY_ARRAY, () => null);
290
- }
291
- return new IteratorWrapper(maybeIterator, keyFor);
185
+ return null === maybeIterator ? new ArrayIterator(EMPTY_ARRAY, () => null) : new IteratorWrapper(maybeIterator, keyFor);
292
186
  });
293
187
  }
294
188
  function createIteratorItemRef(_value) {
295
- let value = _value;
296
- let tag = createTag();
297
- return createComputeRef(() => {
298
- consumeTag(tag);
299
- return value;
300
- }, newValue => {
301
- if (value !== newValue) {
302
- value = newValue;
303
- DIRTY_TAG(tag);
304
- }
189
+ let value = _value,
190
+ tag = createTag();
191
+ return createComputeRef(() => (consumeTag(tag), value), newValue => {
192
+ value !== newValue && (value = newValue, DIRTY_TAG(tag));
305
193
  });
306
194
  }
307
195
  class IteratorWrapper {
308
196
  constructor(inner, keyFor) {
309
- this.inner = inner;
310
- this.keyFor = keyFor;
197
+ this.inner = inner, this.keyFor = keyFor;
311
198
  }
312
199
  isEmpty() {
313
200
  return this.inner.isEmpty();
314
201
  }
315
202
  next() {
316
203
  let nextValue = this.inner.next();
317
- if (nextValue !== null) {
318
- nextValue.key = this.keyFor(nextValue.value, nextValue.memo);
319
- }
320
- return nextValue;
204
+ return null !== nextValue && (nextValue.key = this.keyFor(nextValue.value, nextValue.memo)), nextValue;
321
205
  }
322
206
  }
323
207
  class ArrayIterator {
324
208
  current;
325
209
  pos = 0;
326
210
  constructor(iterator, keyFor) {
327
- this.iterator = iterator;
328
- this.keyFor = keyFor;
329
- if (iterator.length === 0) {
330
- this.current = {
331
- kind: 'empty'
332
- };
333
- } else {
334
- this.current = {
335
- kind: 'first',
336
- value: iterator[this.pos]
337
- };
338
- }
211
+ this.iterator = iterator, this.keyFor = keyFor, 0 === iterator.length ? this.current = {
212
+ kind: "empty"
213
+ } : this.current = {
214
+ kind: "first",
215
+ value: iterator[this.pos]
216
+ };
339
217
  }
340
218
  isEmpty() {
341
- return this.current.kind === 'empty';
219
+ return "empty" === this.current.kind;
342
220
  }
343
221
  next() {
344
- let value;
345
- let current = this.current;
346
- if (current.kind === 'first') {
347
- this.current = {
348
- kind: 'progress'
349
- };
350
- value = current.value;
351
- } else if (this.pos >= this.iterator.length - 1) {
352
- return null;
353
- } else {
222
+ let value,
223
+ current = this.current;
224
+ if ("first" === current.kind) this.current = {
225
+ kind: "progress"
226
+ }, value = current.value;else {
227
+ if (this.pos >= this.iterator.length - 1) return null;
354
228
  value = this.iterator[++this.pos];
355
229
  }
356
230
  let {
357
- keyFor
231
+ keyFor: keyFor
358
232
  } = this;
359
- let key = keyFor(value, this.pos);
360
- let memo = this.pos;
361
233
  return {
362
- key,
363
- value,
364
- memo
234
+ key: keyFor(value, this.pos),
235
+ value: value,
236
+ memo: this.pos
365
237
  };
366
238
  }
367
239
  }