ember-source 5.6.0-alpha.2 → 5.6.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.
Files changed (54) hide show
  1. package/build-metadata.json +3 -3
  2. package/dist/dependencies/@glimmer/debug.js +1533 -0
  3. package/dist/dependencies/@glimmer/destroyable.js +30 -59
  4. package/dist/dependencies/@glimmer/encoder.js +13 -24
  5. package/dist/dependencies/@glimmer/global-context.js +38 -41
  6. package/dist/dependencies/@glimmer/manager.js +144 -326
  7. package/dist/dependencies/@glimmer/node.js +14 -46
  8. package/dist/dependencies/@glimmer/opcode-compiler.js +1673 -2478
  9. package/dist/dependencies/@glimmer/owner.js +2 -5
  10. package/dist/dependencies/@glimmer/program.js +102 -185
  11. package/dist/dependencies/@glimmer/reference.js +58 -126
  12. package/dist/dependencies/@glimmer/runtime.js +4674 -5639
  13. package/dist/dependencies/@glimmer/util.js +340 -326
  14. package/dist/dependencies/@glimmer/validator.js +160 -217
  15. package/dist/dependencies/@glimmer/vm.js +174 -23
  16. package/dist/dependencies/@glimmer/wire-format.js +91 -34
  17. package/dist/dependencies/@simple-dom/document.js +1 -1
  18. package/dist/dependencies/router_js.js +15 -16
  19. package/dist/dependencies/rsvp.js +89 -88
  20. package/dist/ember-template-compiler.js +8574 -8350
  21. package/dist/ember-template-compiler.map +1 -1
  22. package/dist/ember-testing.js +107 -107
  23. package/dist/ember-testing.map +1 -1
  24. package/dist/ember.debug.js +11199 -9636
  25. package/dist/ember.debug.map +1 -1
  26. package/dist/header/license.js +1 -1
  27. package/dist/packages/@ember/-internals/glimmer/index.js +93 -83
  28. package/dist/packages/@ember/-internals/metal/index.js +5 -4
  29. package/dist/packages/@ember/-internals/utils/index.js +3 -4
  30. package/dist/packages/@ember/array/-internals.js +1 -2
  31. package/dist/packages/@ember/debug/lib/inspect.js +0 -1
  32. package/dist/packages/@ember/object/core.js +0 -1
  33. package/dist/packages/@ember/object/mixin.js +1 -2
  34. package/dist/packages/@ember/routing/route.js +23 -101
  35. package/dist/packages/@ember/routing/router.js +25 -84
  36. package/dist/packages/ember/version.js +1 -1
  37. package/dist/packages/ember-babel.js +13 -0
  38. package/docs/data.json +218 -243
  39. package/lib/index.js +1 -5
  40. package/package.json +24 -19
  41. package/types/stable/@ember/-internals/glimmer/index.d.ts +1 -1
  42. package/types/stable/@ember/-internals/glimmer/lib/component-managers/curly.d.ts +4 -4
  43. package/types/stable/@ember/-internals/glimmer/lib/component-managers/mount.d.ts +3 -3
  44. package/types/stable/@ember/-internals/glimmer/lib/component-managers/outlet.d.ts +5 -8
  45. package/types/stable/@ember/-internals/glimmer/lib/component-managers/root.d.ts +3 -3
  46. package/types/stable/@ember/-internals/glimmer/lib/renderer.d.ts +3 -3
  47. package/types/stable/@ember/-internals/glimmer/lib/resolver.d.ts +3 -3
  48. package/types/stable/@ember/-internals/glimmer/lib/syntax/utils.d.ts +3 -2
  49. package/types/stable/@ember/-internals/glimmer/lib/utils/iterator.d.ts +2 -2
  50. package/types/stable/@ember/-internals/glimmer/lib/utils/outlet.d.ts +39 -18
  51. package/types/stable/@ember/-internals/utility-types/index.d.ts +1 -0
  52. package/types/stable/@ember/-internals/views/lib/system/utils.d.ts +4 -3
  53. package/types/stable/@ember/routing/route.d.ts +6 -28
  54. package/dist/dependencies/@glimmer/low-level.js +0 -77
@@ -1,33 +1,36 @@
1
1
  import { DEBUG } from '@glimmer/env';
2
- import { setProp, getProp, toIterator, getPath } from '@glimmer/global-context';
3
- import { symbol, isDict, EMPTY_ARRAY, isObject } from '@glimmer/util';
4
- import { CONSTANT_TAG, validateTag, track, valueForTag, consumeTag, INITIAL, createTag, dirtyTag } from '@glimmer/validator';
2
+ import { getProp, toIterator, setProp, getPath } from '@glimmer/global-context';
3
+ import { expect, isDict, EMPTY_ARRAY, isObject } from '@glimmer/util';
4
+ import { CONSTANT_TAG, validateTag, track, valueForTag, consumeTag, createTag, dirtyTag, INITIAL } from '@glimmer/validator';
5
5
 
6
- const REFERENCE = symbol('REFERENCE');
6
+ const REFERENCE = Symbol('REFERENCE');
7
+ const CONSTANT = 0;
8
+ const COMPUTE = 1;
9
+ const UNBOUND = 2;
10
+ const INVOKABLE = 3;
11
+
12
+ //////////
7
13
 
8
14
  class ReferenceImpl {
15
+ [REFERENCE];
16
+ tag = null;
17
+ lastRevision = INITIAL;
18
+ lastValue;
19
+ children = null;
20
+ compute = null;
21
+ update = null;
22
+ debugLabel;
9
23
  constructor(type) {
10
- this.tag = null;
11
- this.lastRevision = INITIAL;
12
- this.children = null;
13
- this.compute = null;
14
- this.update = null;
15
24
  this[REFERENCE] = type;
16
25
  }
17
-
18
26
  }
19
-
20
27
  function createPrimitiveRef(value) {
21
- let ref = new ReferenceImpl(2
22
- /* Unbound */
23
- );
28
+ const ref = new ReferenceImpl(UNBOUND);
24
29
  ref.tag = CONSTANT_TAG;
25
30
  ref.lastValue = value;
26
-
27
31
  if (DEBUG) {
28
32
  ref.debugLabel = String(value);
29
33
  }
30
-
31
34
  return ref;
32
35
  }
33
36
  const UNDEFINED_REFERENCE = createPrimitiveRef(undefined);
@@ -35,42 +38,32 @@ const NULL_REFERENCE = createPrimitiveRef(null);
35
38
  const TRUE_REFERENCE = createPrimitiveRef(true);
36
39
  const FALSE_REFERENCE = createPrimitiveRef(false);
37
40
  function createConstRef(value, debugLabel) {
38
- let ref = new ReferenceImpl(0
39
- /* Constant */
40
- );
41
+ const ref = new ReferenceImpl(CONSTANT);
41
42
  ref.lastValue = value;
42
43
  ref.tag = CONSTANT_TAG;
43
-
44
44
  if (DEBUG) {
45
45
  ref.debugLabel = debugLabel;
46
46
  }
47
-
48
47
  return ref;
49
48
  }
50
49
  function createUnboundRef(value, debugLabel) {
51
- let ref = new ReferenceImpl(2
52
- /* Unbound */
53
- );
50
+ const ref = new ReferenceImpl(UNBOUND);
54
51
  ref.lastValue = value;
55
52
  ref.tag = CONSTANT_TAG;
56
-
57
53
  if (DEBUG) {
58
54
  ref.debugLabel = debugLabel;
59
55
  }
60
-
61
56
  return ref;
62
57
  }
63
- function createComputeRef(compute, update = null, debugLabel = 'unknown') {
64
- let ref = new ReferenceImpl(1
65
- /* Compute */
66
- );
58
+ function createComputeRef(compute) {
59
+ let update = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
60
+ let debugLabel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'unknown';
61
+ const ref = new ReferenceImpl(COMPUTE);
67
62
  ref.compute = compute;
68
63
  ref.update = update;
69
-
70
64
  if (DEBUG) {
71
65
  ref.debugLabel = `(result of a \`${debugLabel}\` helper)`;
72
66
  }
73
-
74
67
  return ref;
75
68
  }
76
69
  function createReadOnlyRef(ref) {
@@ -78,125 +71,105 @@ function createReadOnlyRef(ref) {
78
71
  return createComputeRef(() => valueForRef(ref), null, ref.debugLabel);
79
72
  }
80
73
  function isInvokableRef(ref) {
81
- return ref[REFERENCE] === 3
82
- /* Invokable */
83
- ;
74
+ return ref[REFERENCE] === INVOKABLE;
84
75
  }
85
76
  function createInvokableRef(inner) {
86
- let ref = createComputeRef(() => valueForRef(inner), value => updateRef(inner, value));
77
+ const ref = createComputeRef(() => valueForRef(inner), value => updateRef(inner, value));
87
78
  ref.debugLabel = inner.debugLabel;
88
- ref[REFERENCE] = 3
89
- /* Invokable */
90
- ;
79
+ ref[REFERENCE] = INVOKABLE;
91
80
  return ref;
92
81
  }
93
82
  function isConstRef(_ref) {
94
- let ref = _ref;
83
+ const ref = _ref;
95
84
  return ref.tag === CONSTANT_TAG;
96
85
  }
97
86
  function isUpdatableRef(_ref) {
98
- let ref = _ref;
87
+ const ref = _ref;
99
88
  return ref.update !== null;
100
89
  }
101
90
  function valueForRef(_ref) {
102
- let ref = _ref;
91
+ const ref = _ref;
103
92
  let {
104
93
  tag
105
94
  } = ref;
106
-
107
95
  if (tag === CONSTANT_TAG) {
108
96
  return ref.lastValue;
109
97
  }
110
-
111
- let {
98
+ const {
112
99
  lastRevision
113
100
  } = ref;
114
101
  let lastValue;
115
-
116
102
  if (tag === null || !validateTag(tag, lastRevision)) {
117
- let {
103
+ const {
118
104
  compute
119
105
  } = ref;
120
- tag = ref.tag = track(() => {
106
+ const newTag = track(() => {
121
107
  lastValue = ref.lastValue = compute();
122
108
  }, DEBUG && ref.debugLabel);
123
- ref.lastRevision = valueForTag(tag);
109
+ tag = ref.tag = newTag;
110
+ ref.lastRevision = valueForTag(newTag);
124
111
  } else {
125
112
  lastValue = ref.lastValue;
126
113
  }
127
-
128
114
  consumeTag(tag);
129
115
  return lastValue;
130
116
  }
131
117
  function updateRef(_ref, value) {
132
- let ref = _ref;
133
- let update = ref.update;
118
+ const ref = _ref;
119
+ const update = expect(ref.update, 'called update on a non-updatable reference');
134
120
  update(value);
135
121
  }
136
122
  function childRefFor(_parentRef, path) {
137
- let parentRef = _parentRef;
138
- let type = parentRef[REFERENCE];
123
+ const parentRef = _parentRef;
124
+ const type = parentRef[REFERENCE];
139
125
  let children = parentRef.children;
140
126
  let child;
141
-
142
127
  if (children === null) {
143
128
  children = parentRef.children = new Map();
144
129
  } else {
145
130
  child = children.get(path);
146
-
147
131
  if (child !== undefined) {
148
132
  return child;
149
133
  }
150
134
  }
151
-
152
- if (type === 2
153
- /* Unbound */
154
- ) {
155
- let parent = valueForRef(parentRef);
156
-
157
- if (isDict(parent)) {
158
- child = createUnboundRef(parent[path], DEBUG && `${parentRef.debugLabel}.${path}`);
159
- } else {
160
- child = UNDEFINED_REFERENCE;
161
- }
135
+ if (type === UNBOUND) {
136
+ const parent = valueForRef(parentRef);
137
+ if (isDict(parent)) {
138
+ child = createUnboundRef(parent[path], DEBUG && `${parentRef.debugLabel}.${path}`);
162
139
  } else {
140
+ child = UNDEFINED_REFERENCE;
141
+ }
142
+ } else {
163
143
  child = createComputeRef(() => {
164
- let parent = valueForRef(parentRef);
165
-
144
+ const parent = valueForRef(parentRef);
166
145
  if (isDict(parent)) {
167
146
  return getProp(parent, path);
168
147
  }
169
148
  }, val => {
170
- let parent = valueForRef(parentRef);
171
-
149
+ const parent = valueForRef(parentRef);
172
150
  if (isDict(parent)) {
173
151
  return setProp(parent, path, val);
174
152
  }
175
153
  });
176
-
177
154
  if (DEBUG) {
178
155
  child.debugLabel = `${parentRef.debugLabel}.${path}`;
179
156
  }
180
157
  }
181
-
182
158
  children.set(path, child);
183
159
  return child;
184
160
  }
185
161
  function childRefFromParts(root, parts) {
186
162
  let reference = root;
187
-
188
- for (let i = 0; i < parts.length; i++) {
189
- reference = childRefFor(reference, parts[i]);
163
+ for (const part of parts) {
164
+ reference = childRefFor(reference, part);
190
165
  }
191
-
192
166
  return reference;
193
167
  }
194
168
  let createDebugAliasRef;
195
-
196
169
  if (DEBUG) {
197
170
  createDebugAliasRef = (debugLabel, inner) => {
198
- let update = isUpdatableRef(inner) ? value => updateRef(inner, value) : null;
199
- let ref = createComputeRef(() => valueForRef(inner), update);
171
+ const update = isUpdatableRef(inner) ? value => updateRef(inner, value) : null;
172
+ const ref = createComputeRef(() => valueForRef(inner), update);
200
173
  ref[REFERENCE] = inner[REFERENCE];
201
174
  ref.debugLabel = debugLabel;
202
175
  return ref;
@@ -204,62 +177,49 @@ if (DEBUG) {
204
177
  }
205
178
 
206
179
  const NULL_IDENTITY = {};
207
-
208
180
  const KEY = (_, index) => index;
209
-
210
181
  const INDEX = (_, index) => String(index);
211
-
212
182
  const IDENTITY = item => {
213
183
  if (item === null) {
214
184
  // Returning null as an identity will cause failures since the iterator
215
185
  // can't tell that it's actually supposed to be null
216
186
  return NULL_IDENTITY;
217
187
  }
218
-
219
188
  return item;
220
189
  };
221
-
222
190
  function keyForPath(path) {
223
191
  if (DEBUG && path[0] === '@') {
224
192
  throw new Error(`invalid keypath: '${path}', valid keys: @index, @identity, or a path`);
225
193
  }
226
-
227
194
  return uniqueKeyFor(item => getPath(item, path));
228
195
  }
229
-
230
196
  function makeKeyFor(key) {
231
197
  switch (key) {
232
198
  case '@key':
233
199
  return uniqueKeyFor(KEY);
234
-
235
200
  case '@index':
236
201
  return uniqueKeyFor(INDEX);
237
-
238
202
  case '@identity':
239
203
  return uniqueKeyFor(IDENTITY);
240
-
241
204
  default:
242
205
  return keyForPath(key);
243
206
  }
244
207
  }
245
-
246
208
  class WeakMapWithPrimitives {
209
+ _weakMap;
210
+ _primitiveMap;
247
211
  get weakMap() {
248
212
  if (this._weakMap === undefined) {
249
213
  this._weakMap = new WeakMap();
250
214
  }
251
-
252
215
  return this._weakMap;
253
216
  }
254
-
255
217
  get primitiveMap() {
256
218
  if (this._primitiveMap === undefined) {
257
219
  this._primitiveMap = new Map();
258
220
  }
259
-
260
221
  return this._primitiveMap;
261
222
  }
262
-
263
223
  set(key, value) {
264
224
  if (isObject(key)) {
265
225
  this.weakMap.set(key, value);
@@ -267,7 +227,6 @@ class WeakMapWithPrimitives {
267
227
  this.primitiveMap.set(key, value);
268
228
  }
269
229
  }
270
-
271
230
  get(key) {
272
231
  if (isObject(key)) {
273
232
  return this.weakMap.get(key);
@@ -275,21 +234,15 @@ class WeakMapWithPrimitives {
275
234
  return this.primitiveMap.get(key);
276
235
  }
277
236
  }
278
-
279
237
  }
280
-
281
238
  const IDENTITIES = new WeakMapWithPrimitives();
282
-
283
239
  function identityForNthOccurence(value, count) {
284
240
  let identities = IDENTITIES.get(value);
285
-
286
241
  if (identities === undefined) {
287
242
  identities = [];
288
243
  IDENTITIES.set(value, identities);
289
244
  }
290
-
291
245
  let identity = identities[count];
292
-
293
246
  if (identity === undefined) {
294
247
  identity = {
295
248
  value,
@@ -297,9 +250,9 @@ function identityForNthOccurence(value, count) {
297
250
  };
298
251
  identities[count] = identity;
299
252
  }
300
-
301
253
  return identity;
302
254
  }
255
+
303
256
  /**
304
257
  * When iterating over a list, it's possible that an item with the same unique
305
258
  * key could be encountered twice:
@@ -315,38 +268,29 @@ function identityForNthOccurence(value, count) {
315
268
  * and encounter an item for the nth time, we can get the _same_ key, and let
316
269
  * Glimmer know that it should reuse the DOM for the previous nth occurence.
317
270
  */
318
-
319
-
320
271
  function uniqueKeyFor(keyFor) {
321
272
  let seen = new WeakMapWithPrimitives();
322
273
  return (value, memo) => {
323
274
  let key = keyFor(value, memo);
324
275
  let count = seen.get(key) || 0;
325
276
  seen.set(key, count + 1);
326
-
327
277
  if (count === 0) {
328
278
  return key;
329
279
  }
330
-
331
280
  return identityForNthOccurence(key, count);
332
281
  };
333
282
  }
334
-
335
283
  function createIteratorRef(listRef, key) {
336
284
  return createComputeRef(() => {
337
285
  let iterable = valueForRef(listRef);
338
286
  let keyFor = makeKeyFor(key);
339
-
340
287
  if (Array.isArray(iterable)) {
341
288
  return new ArrayIterator(iterable, keyFor);
342
289
  }
343
-
344
290
  let maybeIterator = toIterator(iterable);
345
-
346
291
  if (maybeIterator === null) {
347
292
  return new ArrayIterator(EMPTY_ARRAY, () => null);
348
293
  }
349
-
350
294
  return new IteratorWrapper(maybeIterator, keyFor);
351
295
  });
352
296
  }
@@ -363,35 +307,28 @@ function createIteratorItemRef(_value) {
363
307
  }
364
308
  });
365
309
  }
366
-
367
310
  class IteratorWrapper {
368
311
  constructor(inner, keyFor) {
369
312
  this.inner = inner;
370
313
  this.keyFor = keyFor;
371
314
  }
372
-
373
315
  isEmpty() {
374
316
  return this.inner.isEmpty();
375
317
  }
376
-
377
318
  next() {
378
319
  let nextValue = this.inner.next();
379
-
380
320
  if (nextValue !== null) {
381
321
  nextValue.key = this.keyFor(nextValue.value, nextValue.memo);
382
322
  }
383
-
384
323
  return nextValue;
385
324
  }
386
-
387
325
  }
388
-
389
326
  class ArrayIterator {
327
+ current;
328
+ pos = 0;
390
329
  constructor(iterator, keyFor) {
391
330
  this.iterator = iterator;
392
331
  this.keyFor = keyFor;
393
- this.pos = 0;
394
-
395
332
  if (iterator.length === 0) {
396
333
  this.current = {
397
334
  kind: 'empty'
@@ -403,15 +340,12 @@ class ArrayIterator {
403
340
  };
404
341
  }
405
342
  }
406
-
407
343
  isEmpty() {
408
344
  return this.current.kind === 'empty';
409
345
  }
410
-
411
346
  next() {
412
347
  let value;
413
348
  let current = this.current;
414
-
415
349
  if (current.kind === 'first') {
416
350
  this.current = {
417
351
  kind: 'progress'
@@ -422,7 +356,6 @@ class ArrayIterator {
422
356
  } else {
423
357
  value = this.iterator[++this.pos];
424
358
  }
425
-
426
359
  let {
427
360
  keyFor
428
361
  } = this;
@@ -434,7 +367,6 @@ class ArrayIterator {
434
367
  memo
435
368
  };
436
369
  }
437
-
438
370
  }
439
371
 
440
372
  export { FALSE_REFERENCE, NULL_REFERENCE, REFERENCE, TRUE_REFERENCE, UNDEFINED_REFERENCE, childRefFor, childRefFromParts, createComputeRef, createConstRef, createDebugAliasRef, createInvokableRef, createIteratorItemRef, createIteratorRef, createPrimitiveRef, createReadOnlyRef, createUnboundRef, isConstRef, isInvokableRef, isUpdatableRef, updateRef, valueForRef };