@angular/upgrade 21.0.0-next.0 → 21.0.0-next.2

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.
@@ -1,1106 +0,0 @@
1
- /**
2
- * @license Angular v21.0.0-next.0
3
- * (c) 2010-2025 Google LLC. https://angular.io/
4
- * License: MIT
5
- */
6
-
7
- import { Version, ɵNG_MOD_DEF as _NG_MOD_DEF, Injector, ChangeDetectorRef, Testability, TestabilityRegistry, ApplicationRef, SimpleChange, ɵSIGNAL as _SIGNAL, NgZone, ComponentFactoryResolver } from '@angular/core';
8
- import { element, $ROOT_ELEMENT, $ROOT_SCOPE, DOWNGRADED_MODULE_COUNT_KEY, UPGRADE_APP_TYPE_KEY, $SCOPE, $COMPILE, $INJECTOR, $PARSE, REQUIRE_INJECTOR, REQUIRE_NG_MODEL, LAZY_MODULE_REF, INJECTOR_KEY, $CONTROLLER, $TEMPLATE_CACHE, $HTTP_BACKEND } from './constants.mjs';
9
-
10
- /**
11
- * @module
12
- * @description
13
- * Entry point for all public APIs of the upgrade package.
14
- */
15
- /**
16
- * @publicApi
17
- */
18
- const VERSION = new Version('21.0.0-next.0');
19
-
20
- /**
21
- * A `PropertyBinding` represents a mapping between a property name
22
- * and an attribute name. It is parsed from a string of the form
23
- * `"prop: attr"`; or simply `"propAndAttr" where the property
24
- * and attribute have the same identifier.
25
- */
26
- class PropertyBinding {
27
- prop;
28
- attr;
29
- bracketAttr;
30
- bracketParenAttr;
31
- parenAttr;
32
- onAttr;
33
- bindAttr;
34
- bindonAttr;
35
- constructor(prop, attr) {
36
- this.prop = prop;
37
- this.attr = attr;
38
- this.bracketAttr = `[${this.attr}]`;
39
- this.parenAttr = `(${this.attr})`;
40
- this.bracketParenAttr = `[(${this.attr})]`;
41
- const capitalAttr = this.attr.charAt(0).toUpperCase() + this.attr.slice(1);
42
- this.onAttr = `on${capitalAttr}`;
43
- this.bindAttr = `bind${capitalAttr}`;
44
- this.bindonAttr = `bindon${capitalAttr}`;
45
- }
46
- }
47
-
48
- const DIRECTIVE_PREFIX_REGEXP = /^(?:x|data)[:\-_]/i;
49
- const DIRECTIVE_SPECIAL_CHARS_REGEXP = /[:\-_]+(.)/g;
50
- function onError(e) {
51
- // TODO: (misko): We seem to not have a stack trace here!
52
- console.error(e, e.stack);
53
- throw e;
54
- }
55
- /**
56
- * Clean the jqLite/jQuery data on the element and all its descendants.
57
- * Equivalent to how jqLite/jQuery invoke `cleanData()` on an Element when removed:
58
- * https://github.com/angular/angular.js/blob/2e72ea13fa98bebf6ed4b5e3c45eaf5f990ed16f/src/jqLite.js#L349-L355
59
- * https://github.com/jquery/jquery/blob/6984d1747623dbc5e87fd6c261a5b6b1628c107c/src/manipulation.js#L182
60
- *
61
- * NOTE:
62
- * `cleanData()` will also invoke the AngularJS `$destroy` DOM event on the element:
63
- * https://github.com/angular/angular.js/blob/2e72ea13fa98bebf6ed4b5e3c45eaf5f990ed16f/src/Angular.js#L1932-L1945
64
- *
65
- * @param node The DOM node whose data needs to be cleaned.
66
- */
67
- function cleanData(node) {
68
- element.cleanData([node]);
69
- if (isParentNode(node)) {
70
- element.cleanData(node.querySelectorAll('*'));
71
- }
72
- }
73
- function controllerKey(name) {
74
- return '$' + name + 'Controller';
75
- }
76
- /**
77
- * Destroy an AngularJS app given the app `$injector`.
78
- *
79
- * NOTE: Destroying an app is not officially supported by AngularJS, but try to do our best by
80
- * destroying `$rootScope` and clean the jqLite/jQuery data on `$rootElement` and all
81
- * descendants.
82
- *
83
- * @param $injector The `$injector` of the AngularJS app to destroy.
84
- */
85
- function destroyApp($injector) {
86
- const $rootElement = $injector.get($ROOT_ELEMENT);
87
- const $rootScope = $injector.get($ROOT_SCOPE);
88
- $rootScope.$destroy();
89
- cleanData($rootElement[0]);
90
- }
91
- function directiveNormalize(name) {
92
- return name
93
- .replace(DIRECTIVE_PREFIX_REGEXP, '')
94
- .replace(DIRECTIVE_SPECIAL_CHARS_REGEXP, (_, letter) => letter.toUpperCase());
95
- }
96
- function getTypeName(type) {
97
- // Return the name of the type or the first line of its stringified version.
98
- return type.overriddenName || type.name || type.toString().split('\n')[0];
99
- }
100
- function getDowngradedModuleCount($injector) {
101
- return $injector.has(DOWNGRADED_MODULE_COUNT_KEY)
102
- ? $injector.get(DOWNGRADED_MODULE_COUNT_KEY)
103
- : 0;
104
- }
105
- function getUpgradeAppType($injector) {
106
- return $injector.has(UPGRADE_APP_TYPE_KEY)
107
- ? $injector.get(UPGRADE_APP_TYPE_KEY)
108
- : 0 /* UpgradeAppType.None */;
109
- }
110
- function isFunction(value) {
111
- return typeof value === 'function';
112
- }
113
- function isNgModuleType(value) {
114
- // NgModule class should have the `ɵmod` static property attached by AOT or JIT compiler.
115
- return isFunction(value) && !!value[_NG_MOD_DEF];
116
- }
117
- function isParentNode(node) {
118
- return isFunction(node.querySelectorAll);
119
- }
120
- function validateInjectionKey($injector, downgradedModule, injectionKey, attemptedAction) {
121
- const upgradeAppType = getUpgradeAppType($injector);
122
- const downgradedModuleCount = getDowngradedModuleCount($injector);
123
- // Check for common errors.
124
- switch (upgradeAppType) {
125
- case 1 /* UpgradeAppType.Dynamic */:
126
- case 2 /* UpgradeAppType.Static */:
127
- if (downgradedModule) {
128
- throw new Error(`Error while ${attemptedAction}: 'downgradedModule' unexpectedly specified.\n` +
129
- "You should not specify a value for 'downgradedModule', unless you are downgrading " +
130
- "more than one Angular module (via 'downgradeModule()').");
131
- }
132
- break;
133
- case 3 /* UpgradeAppType.Lite */:
134
- if (!downgradedModule && downgradedModuleCount >= 2) {
135
- throw new Error(`Error while ${attemptedAction}: 'downgradedModule' not specified.\n` +
136
- 'This application contains more than one downgraded Angular module, thus you need to ' +
137
- "always specify 'downgradedModule' when downgrading components and injectables.");
138
- }
139
- if (!$injector.has(injectionKey)) {
140
- throw new Error(`Error while ${attemptedAction}: Unable to find the specified downgraded module.\n` +
141
- 'Did you forget to downgrade an Angular module or include it in the AngularJS ' +
142
- 'application?');
143
- }
144
- break;
145
- default:
146
- throw new Error(`Error while ${attemptedAction}: Not a valid '@angular/upgrade' application.\n` +
147
- 'Did you forget to downgrade an Angular module or include it in the AngularJS ' +
148
- 'application?');
149
- }
150
- }
151
- class Deferred {
152
- promise;
153
- resolve;
154
- reject;
155
- constructor() {
156
- this.promise = new Promise((res, rej) => {
157
- this.resolve = res;
158
- this.reject = rej;
159
- });
160
- }
161
- }
162
- /**
163
- * @return Whether the passed-in component implements the subset of the
164
- * `ControlValueAccessor` interface needed for AngularJS `ng-model`
165
- * compatibility.
166
- */
167
- function supportsNgModel(component) {
168
- return (typeof component.writeValue === 'function' && typeof component.registerOnChange === 'function');
169
- }
170
- /**
171
- * Glue the AngularJS `NgModelController` (if it exists) to the component
172
- * (if it implements the needed subset of the `ControlValueAccessor` interface).
173
- */
174
- function hookupNgModel(ngModel, component) {
175
- if (ngModel && supportsNgModel(component)) {
176
- ngModel.$render = () => {
177
- component.writeValue(ngModel.$viewValue);
178
- };
179
- component.registerOnChange(ngModel.$setViewValue.bind(ngModel));
180
- if (typeof component.registerOnTouched === 'function') {
181
- component.registerOnTouched(ngModel.$setTouched.bind(ngModel));
182
- }
183
- }
184
- }
185
- /**
186
- * Test two values for strict equality, accounting for the fact that `NaN !== NaN`.
187
- */
188
- function strictEquals(val1, val2) {
189
- return val1 === val2 || (val1 !== val1 && val2 !== val2);
190
- }
191
-
192
- var util = /*#__PURE__*/Object.freeze({
193
- __proto__: null,
194
- Deferred: Deferred,
195
- cleanData: cleanData,
196
- controllerKey: controllerKey,
197
- destroyApp: destroyApp,
198
- directiveNormalize: directiveNormalize,
199
- getDowngradedModuleCount: getDowngradedModuleCount,
200
- getTypeName: getTypeName,
201
- getUpgradeAppType: getUpgradeAppType,
202
- hookupNgModel: hookupNgModel,
203
- isFunction: isFunction,
204
- isNgModuleType: isNgModuleType,
205
- onError: onError,
206
- strictEquals: strictEquals,
207
- validateInjectionKey: validateInjectionKey
208
- });
209
-
210
- const INITIAL_VALUE = {
211
- __UNINITIALIZED__: true,
212
- };
213
- class DowngradeComponentAdapter {
214
- element;
215
- attrs;
216
- scope;
217
- ngModel;
218
- parentInjector;
219
- $compile;
220
- $parse;
221
- componentFactory;
222
- wrapCallback;
223
- unsafelyOverwriteSignalInputs;
224
- implementsOnChanges = false;
225
- inputChangeCount = 0;
226
- inputChanges = {};
227
- componentScope;
228
- constructor(element, attrs, scope, ngModel, parentInjector, $compile, $parse, componentFactory, wrapCallback, unsafelyOverwriteSignalInputs) {
229
- this.element = element;
230
- this.attrs = attrs;
231
- this.scope = scope;
232
- this.ngModel = ngModel;
233
- this.parentInjector = parentInjector;
234
- this.$compile = $compile;
235
- this.$parse = $parse;
236
- this.componentFactory = componentFactory;
237
- this.wrapCallback = wrapCallback;
238
- this.unsafelyOverwriteSignalInputs = unsafelyOverwriteSignalInputs;
239
- this.componentScope = scope.$new();
240
- }
241
- compileContents() {
242
- const compiledProjectableNodes = [];
243
- const projectableNodes = this.groupProjectableNodes();
244
- const linkFns = projectableNodes.map((nodes) => this.$compile(nodes));
245
- this.element.empty();
246
- linkFns.forEach((linkFn) => {
247
- linkFn(this.scope, (clone) => {
248
- compiledProjectableNodes.push(clone);
249
- this.element.append(clone);
250
- });
251
- });
252
- return compiledProjectableNodes;
253
- }
254
- createComponentAndSetup(projectableNodes, manuallyAttachView = false, propagateDigest = true) {
255
- const component = this.createComponent(projectableNodes);
256
- this.setupInputs(manuallyAttachView, propagateDigest, component);
257
- this.setupOutputs(component.componentRef);
258
- this.registerCleanup(component.componentRef);
259
- return component.componentRef;
260
- }
261
- createComponent(projectableNodes) {
262
- const providers = [{ provide: $SCOPE, useValue: this.componentScope }];
263
- const childInjector = Injector.create({
264
- providers: providers,
265
- parent: this.parentInjector,
266
- name: 'DowngradeComponentAdapter',
267
- });
268
- const componentRef = this.componentFactory.create(childInjector, projectableNodes, this.element[0]);
269
- const viewChangeDetector = componentRef.injector.get(ChangeDetectorRef);
270
- const changeDetector = componentRef.changeDetectorRef;
271
- // testability hook is commonly added during component bootstrap in
272
- // packages/core/src/application_ref.bootstrap()
273
- // in downgraded application, component creation will take place here as well as adding the
274
- // testability hook.
275
- const testability = componentRef.injector.get(Testability, null);
276
- if (testability) {
277
- componentRef.injector
278
- .get(TestabilityRegistry)
279
- .registerApplication(componentRef.location.nativeElement, testability);
280
- }
281
- hookupNgModel(this.ngModel, componentRef.instance);
282
- return { viewChangeDetector, componentRef, changeDetector };
283
- }
284
- setupInputs(manuallyAttachView, propagateDigest = true, { componentRef, changeDetector, viewChangeDetector }) {
285
- const attrs = this.attrs;
286
- const inputs = this.componentFactory.inputs || [];
287
- for (const input of inputs) {
288
- const inputBinding = new PropertyBinding(input.propName, input.templateName);
289
- let expr = null;
290
- if (attrs.hasOwnProperty(inputBinding.attr)) {
291
- const observeFn = ((prop, isSignal) => {
292
- let prevValue = INITIAL_VALUE;
293
- return (currValue) => {
294
- // Initially, both `$observe()` and `$watch()` will call this function.
295
- if (!strictEquals(prevValue, currValue)) {
296
- if (prevValue === INITIAL_VALUE) {
297
- prevValue = currValue;
298
- }
299
- this.updateInput(componentRef, prop, prevValue, currValue, isSignal);
300
- prevValue = currValue;
301
- }
302
- };
303
- })(inputBinding.prop, input.isSignal);
304
- attrs.$observe(inputBinding.attr, observeFn);
305
- // Use `$watch()` (in addition to `$observe()`) in order to initialize the input in time
306
- // for `ngOnChanges()`. This is necessary if we are already in a `$digest`, which means that
307
- // `ngOnChanges()` (which is called by a watcher) will run before the `$observe()` callback.
308
- let unwatch = this.componentScope.$watch(() => {
309
- unwatch();
310
- unwatch = null;
311
- observeFn(attrs[inputBinding.attr]);
312
- });
313
- }
314
- else if (attrs.hasOwnProperty(inputBinding.bindAttr)) {
315
- expr = attrs[inputBinding.bindAttr];
316
- }
317
- else if (attrs.hasOwnProperty(inputBinding.bracketAttr)) {
318
- expr = attrs[inputBinding.bracketAttr];
319
- }
320
- else if (attrs.hasOwnProperty(inputBinding.bindonAttr)) {
321
- expr = attrs[inputBinding.bindonAttr];
322
- }
323
- else if (attrs.hasOwnProperty(inputBinding.bracketParenAttr)) {
324
- expr = attrs[inputBinding.bracketParenAttr];
325
- }
326
- if (expr != null) {
327
- const watchFn = ((prop, isSignal) => (currValue, prevValue) => this.updateInput(componentRef, prop, prevValue, currValue, isSignal))(inputBinding.prop, input.isSignal);
328
- this.componentScope.$watch(expr, watchFn);
329
- }
330
- }
331
- // Invoke `ngOnChanges()` and Change Detection (when necessary)
332
- const detectChanges = () => changeDetector.detectChanges();
333
- const prototype = this.componentFactory.componentType.prototype;
334
- this.implementsOnChanges = !!(prototype && prototype.ngOnChanges);
335
- this.componentScope.$watch(() => this.inputChangeCount, this.wrapCallback(() => {
336
- // Invoke `ngOnChanges()`
337
- if (this.implementsOnChanges) {
338
- const inputChanges = this.inputChanges;
339
- this.inputChanges = {};
340
- componentRef.instance.ngOnChanges(inputChanges);
341
- }
342
- viewChangeDetector.markForCheck();
343
- // If opted out of propagating digests, invoke change detection when inputs change.
344
- if (!propagateDigest) {
345
- detectChanges();
346
- }
347
- }));
348
- // If not opted out of propagating digests, invoke change detection on every digest
349
- if (propagateDigest) {
350
- this.componentScope.$watch(this.wrapCallback(detectChanges));
351
- }
352
- // If necessary, attach the view so that it will be dirty-checked.
353
- // (Allow time for the initial input values to be set and `ngOnChanges()` to be called.)
354
- if (manuallyAttachView || !propagateDigest) {
355
- let unwatch = this.componentScope.$watch(() => {
356
- unwatch();
357
- unwatch = null;
358
- const appRef = this.parentInjector.get(ApplicationRef);
359
- appRef.attachView(componentRef.hostView);
360
- });
361
- }
362
- }
363
- setupOutputs(componentRef) {
364
- const attrs = this.attrs;
365
- const outputs = this.componentFactory.outputs || [];
366
- for (const output of outputs) {
367
- const outputBindings = new PropertyBinding(output.propName, output.templateName);
368
- const bindonAttr = outputBindings.bindonAttr.substring(0, outputBindings.bindonAttr.length - 6);
369
- const bracketParenAttr = `[(${outputBindings.bracketParenAttr.substring(2, outputBindings.bracketParenAttr.length - 8)})]`;
370
- // order below is important - first update bindings then evaluate expressions
371
- if (attrs.hasOwnProperty(bindonAttr)) {
372
- this.subscribeToOutput(componentRef, outputBindings, attrs[bindonAttr], true);
373
- }
374
- if (attrs.hasOwnProperty(bracketParenAttr)) {
375
- this.subscribeToOutput(componentRef, outputBindings, attrs[bracketParenAttr], true);
376
- }
377
- if (attrs.hasOwnProperty(outputBindings.onAttr)) {
378
- this.subscribeToOutput(componentRef, outputBindings, attrs[outputBindings.onAttr]);
379
- }
380
- if (attrs.hasOwnProperty(outputBindings.parenAttr)) {
381
- this.subscribeToOutput(componentRef, outputBindings, attrs[outputBindings.parenAttr]);
382
- }
383
- }
384
- }
385
- subscribeToOutput(componentRef, output, expr, isAssignment = false) {
386
- const getter = this.$parse(expr);
387
- const setter = getter.assign;
388
- if (isAssignment && !setter) {
389
- throw new Error(`Expression '${expr}' is not assignable!`);
390
- }
391
- const emitter = componentRef.instance[output.prop];
392
- if (emitter) {
393
- const subscription = emitter.subscribe(isAssignment
394
- ? (v) => setter(this.scope, v)
395
- : (v) => getter(this.scope, { '$event': v }));
396
- componentRef.onDestroy(() => subscription.unsubscribe());
397
- }
398
- else {
399
- throw new Error(`Missing emitter '${output.prop}' on component '${getTypeName(this.componentFactory.componentType)}'!`);
400
- }
401
- }
402
- registerCleanup(componentRef) {
403
- const testabilityRegistry = componentRef.injector.get(TestabilityRegistry);
404
- const destroyComponentRef = this.wrapCallback(() => componentRef.destroy());
405
- let destroyed = false;
406
- this.element.on('$destroy', () => {
407
- // The `$destroy` event may have been triggered by the `cleanData()` call in the
408
- // `componentScope` `$destroy` handler below. In that case, we don't want to call
409
- // `componentScope.$destroy()` again.
410
- if (!destroyed)
411
- this.componentScope.$destroy();
412
- });
413
- this.componentScope.$on('$destroy', () => {
414
- if (!destroyed) {
415
- destroyed = true;
416
- testabilityRegistry.unregisterApplication(componentRef.location.nativeElement);
417
- // The `componentScope` might be getting destroyed, because an ancestor element is being
418
- // removed/destroyed. If that is the case, jqLite/jQuery would normally invoke `cleanData()`
419
- // on the removed element and all descendants.
420
- // https://github.com/angular/angular.js/blob/2e72ea13fa98bebf6ed4b5e3c45eaf5f990ed16f/src/jqLite.js#L349-L355
421
- // https://github.com/jquery/jquery/blob/6984d1747623dbc5e87fd6c261a5b6b1628c107c/src/manipulation.js#L182
422
- //
423
- // Here, however, `destroyComponentRef()` may under some circumstances remove the element
424
- // from the DOM and therefore it will no longer be a descendant of the removed element when
425
- // `cleanData()` is called. This would result in a memory leak, because the element's data
426
- // and event handlers (and all objects directly or indirectly referenced by them) would be
427
- // retained.
428
- //
429
- // To ensure the element is always properly cleaned up, we manually call `cleanData()` on
430
- // this element and its descendants before destroying the `ComponentRef`.
431
- cleanData(this.element[0]);
432
- destroyComponentRef();
433
- }
434
- });
435
- }
436
- updateInput(componentRef, prop, prevValue, currValue, isSignal) {
437
- if (this.implementsOnChanges) {
438
- this.inputChanges[prop] = new SimpleChange(prevValue, currValue, prevValue === currValue);
439
- }
440
- this.inputChangeCount++;
441
- if (isSignal && !this.unsafelyOverwriteSignalInputs) {
442
- const node = componentRef.instance[prop][_SIGNAL];
443
- node.applyValueToInputSignal(node, currValue);
444
- }
445
- else {
446
- componentRef.instance[prop] = currValue;
447
- }
448
- }
449
- groupProjectableNodes() {
450
- let ngContentSelectors = this.componentFactory.ngContentSelectors;
451
- return groupNodesBySelector(ngContentSelectors, this.element.contents());
452
- }
453
- }
454
- /**
455
- * Group a set of DOM nodes into `ngContent` groups, based on the given content selectors.
456
- */
457
- function groupNodesBySelector(ngContentSelectors, nodes) {
458
- const projectableNodes = [];
459
- for (let i = 0, ii = ngContentSelectors.length; i < ii; ++i) {
460
- projectableNodes[i] = [];
461
- }
462
- for (let j = 0, jj = nodes.length; j < jj; ++j) {
463
- const node = nodes[j];
464
- const ngContentIndex = findMatchingNgContentIndex(node, ngContentSelectors);
465
- if (ngContentIndex != null) {
466
- projectableNodes[ngContentIndex].push(node);
467
- }
468
- }
469
- return projectableNodes;
470
- }
471
- function findMatchingNgContentIndex(element, ngContentSelectors) {
472
- const ngContentIndices = [];
473
- let wildcardNgContentIndex = -1;
474
- for (let i = 0; i < ngContentSelectors.length; i++) {
475
- const selector = ngContentSelectors[i];
476
- if (selector === '*') {
477
- wildcardNgContentIndex = i;
478
- }
479
- else {
480
- if (matchesSelector(element, selector)) {
481
- ngContentIndices.push(i);
482
- }
483
- }
484
- }
485
- ngContentIndices.sort();
486
- if (wildcardNgContentIndex !== -1) {
487
- ngContentIndices.push(wildcardNgContentIndex);
488
- }
489
- return ngContentIndices.length ? ngContentIndices[0] : null;
490
- }
491
- function matchesSelector(el, selector) {
492
- const elProto = Element.prototype;
493
- return el.nodeType === Node.ELEMENT_NODE
494
- ? // matches is supported by all browsers from 2014 onwards except non-chromium edge
495
- (elProto.matches ?? elProto.msMatchesSelector).call(el, selector)
496
- : false;
497
- }
498
-
499
- function isThenable(obj) {
500
- return !!obj && isFunction(obj.then);
501
- }
502
- /**
503
- * Synchronous, promise-like object.
504
- */
505
- class SyncPromise {
506
- value;
507
- resolved = false;
508
- callbacks = [];
509
- static all(valuesOrPromises) {
510
- const aggrPromise = new SyncPromise();
511
- let resolvedCount = 0;
512
- const results = [];
513
- const resolve = (idx, value) => {
514
- results[idx] = value;
515
- if (++resolvedCount === valuesOrPromises.length)
516
- aggrPromise.resolve(results);
517
- };
518
- valuesOrPromises.forEach((p, idx) => {
519
- if (isThenable(p)) {
520
- p.then((v) => resolve(idx, v));
521
- }
522
- else {
523
- resolve(idx, p);
524
- }
525
- });
526
- return aggrPromise;
527
- }
528
- resolve(value) {
529
- // Do nothing, if already resolved.
530
- if (this.resolved)
531
- return;
532
- this.value = value;
533
- this.resolved = true;
534
- // Run the queued callbacks.
535
- this.callbacks.forEach((callback) => callback(value));
536
- this.callbacks.length = 0;
537
- }
538
- then(callback) {
539
- if (this.resolved) {
540
- callback(this.value);
541
- }
542
- else {
543
- this.callbacks.push(callback);
544
- }
545
- }
546
- }
547
-
548
- /**
549
- * @description
550
- *
551
- * A helper function that allows an Angular component to be used from AngularJS.
552
- *
553
- * *Part of the [upgrade/static](api?query=upgrade%2Fstatic)
554
- * library for hybrid upgrade apps that support AOT compilation*
555
- *
556
- * This helper function returns a factory function to be used for registering
557
- * an AngularJS wrapper directive for "downgrading" an Angular component.
558
- *
559
- * @usageNotes
560
- * ### Examples
561
- *
562
- * Let's assume that you have an Angular component called `ng2Heroes` that needs
563
- * to be made available in AngularJS templates.
564
- *
565
- * {@example upgrade/static/ts/full/module.ts region="ng2-heroes"}
566
- *
567
- * We must create an AngularJS [directive](https://docs.angularjs.org/guide/directive)
568
- * that will make this Angular component available inside AngularJS templates.
569
- * The `downgradeComponent()` function returns a factory function that we
570
- * can use to define the AngularJS directive that wraps the "downgraded" component.
571
- *
572
- * {@example upgrade/static/ts/full/module.ts region="ng2-heroes-wrapper"}
573
- *
574
- * For more details and examples on downgrading Angular components to AngularJS components please
575
- * visit the [Upgrade guide](https://angular.io/guide/upgrade#using-angular-components-from-angularjs-code).
576
- *
577
- * @param info contains information about the Component that is being downgraded:
578
- *
579
- * - `component: Type<any>`: The type of the Component that will be downgraded
580
- * - `downgradedModule?: string`: The name of the downgraded module (if any) that the component
581
- * "belongs to", as returned by a call to `downgradeModule()`. It is the module, whose
582
- * corresponding Angular module will be bootstrapped, when the component needs to be instantiated.
583
- * <br />
584
- * (This option is only necessary when using `downgradeModule()` to downgrade more than one
585
- * Angular module.)
586
- * - `propagateDigest?: boolean`: Whether to perform {@link /api/core/ChangeDetectorRef#detectChanges detectChanges} on the
587
- * component on every {@link https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest $digest}.
588
- * If set to `false`, change detection will still be performed when any of the component's inputs changes.
589
- * (Default: true)
590
- *
591
- * @returns a factory function that can be used to register the component in an
592
- * AngularJS module.
593
- *
594
- * @publicApi
595
- */
596
- function downgradeComponent(info) {
597
- const directiveFactory = function ($compile, $injector, $parse) {
598
- const unsafelyOverwriteSignalInputs = info.unsafelyOverwriteSignalInputs ?? false;
599
- // When using `downgradeModule()`, we need to handle certain things specially. For example:
600
- // - We always need to attach the component view to the `ApplicationRef` for it to be
601
- // dirty-checked.
602
- // - We need to ensure callbacks to Angular APIs (e.g. change detection) are run inside the
603
- // Angular zone.
604
- // NOTE: This is not needed, when using `UpgradeModule`, because `$digest()` will be run
605
- // inside the Angular zone (except if explicitly escaped, in which case we shouldn't
606
- // force it back in).
607
- const isNgUpgradeLite = getUpgradeAppType($injector) === 3 /* UpgradeAppType.Lite */;
608
- const wrapCallback = !isNgUpgradeLite
609
- ? (cb) => cb
610
- : (cb) => () => (NgZone.isInAngularZone() ? cb() : ngZone.run(cb));
611
- let ngZone;
612
- // When downgrading multiple modules, special handling is needed wrt injectors.
613
- const hasMultipleDowngradedModules = isNgUpgradeLite && getDowngradedModuleCount($injector) > 1;
614
- return {
615
- restrict: 'E',
616
- terminal: true,
617
- require: [REQUIRE_INJECTOR, REQUIRE_NG_MODEL],
618
- // Controller needs to be set so that `angular-component-router.js` (from beta Angular 2)
619
- // configuration properties can be made available. See:
620
- // See G3: javascript/angular2/angular1_router_lib.js
621
- // https://github.com/angular/angular.js/blob/47bf11ee94664367a26ed8c91b9b586d3dd420f5/src/ng/compile.js#L1670-L1691.
622
- controller: function () { },
623
- link: (scope, element, attrs, required) => {
624
- // We might have to compile the contents asynchronously, because this might have been
625
- // triggered by `UpgradeNg1ComponentAdapterBuilder`, before the Angular templates have
626
- // been compiled.
627
- const ngModel = required[1];
628
- const parentInjector = required[0];
629
- let moduleInjector = undefined;
630
- let ranAsync = false;
631
- if (!parentInjector || hasMultipleDowngradedModules) {
632
- const downgradedModule = info.downgradedModule || '';
633
- const lazyModuleRefKey = `${LAZY_MODULE_REF}${downgradedModule}`;
634
- const attemptedAction = `instantiating component '${getTypeName(info.component)}'`;
635
- validateInjectionKey($injector, downgradedModule, lazyModuleRefKey, attemptedAction);
636
- const lazyModuleRef = $injector.get(lazyModuleRefKey);
637
- moduleInjector = lazyModuleRef.injector ?? lazyModuleRef.promise;
638
- }
639
- // Notes:
640
- //
641
- // There are two injectors: `finalModuleInjector` and `finalParentInjector` (they might be
642
- // the same instance, but that is irrelevant):
643
- // - `finalModuleInjector` is used to retrieve `ComponentFactoryResolver`, thus it must be
644
- // on the same tree as the `NgModule` that declares this downgraded component.
645
- // - `finalParentInjector` is used for all other injection purposes.
646
- // (Note that Angular knows to only traverse the component-tree part of that injector,
647
- // when looking for an injectable and then switch to the module injector.)
648
- //
649
- // There are basically three cases:
650
- // - If there is no parent component (thus no `parentInjector`), we bootstrap the downgraded
651
- // `NgModule` and use its injector as both `finalModuleInjector` and
652
- // `finalParentInjector`.
653
- // - If there is a parent component (and thus a `parentInjector`) and we are sure that it
654
- // belongs to the same `NgModule` as this downgraded component (e.g. because there is only
655
- // one downgraded module, we use that `parentInjector` as both `finalModuleInjector` and
656
- // `finalParentInjector`.
657
- // - If there is a parent component, but it may belong to a different `NgModule`, then we
658
- // use the `parentInjector` as `finalParentInjector` and this downgraded component's
659
- // declaring `NgModule`'s injector as `finalModuleInjector`.
660
- // Note 1: If the `NgModule` is already bootstrapped, we just get its injector (we don't
661
- // bootstrap again).
662
- // Note 2: It is possible that (while there are multiple downgraded modules) this
663
- // downgraded component and its parent component both belong to the same NgModule.
664
- // In that case, we could have used the `parentInjector` as both
665
- // `finalModuleInjector` and `finalParentInjector`, but (for simplicity) we are
666
- // treating this case as if they belong to different `NgModule`s. That doesn't
667
- // really affect anything, since `parentInjector` has `moduleInjector` as ancestor
668
- // and trying to resolve `ComponentFactoryResolver` from either one will return
669
- // the same instance.
670
- // If there is a parent component, use its injector as parent injector.
671
- // If this is a "top-level" Angular component, use the module injector.
672
- const finalParentInjector = parentInjector || moduleInjector;
673
- // If this is a "top-level" Angular component or the parent component may belong to a
674
- // different `NgModule`, use the module injector for module-specific dependencies.
675
- // If there is a parent component that belongs to the same `NgModule`, use its injector.
676
- const finalModuleInjector = moduleInjector || parentInjector;
677
- const doDowngrade = (injector, moduleInjector) => {
678
- // Retrieve `ComponentFactoryResolver` from the injector tied to the `NgModule` this
679
- // component belongs to.
680
- const componentFactoryResolver = moduleInjector.get(ComponentFactoryResolver);
681
- const componentFactory = componentFactoryResolver.resolveComponentFactory(info.component);
682
- if (!componentFactory) {
683
- throw new Error(`Expecting ComponentFactory for: ${getTypeName(info.component)}`);
684
- }
685
- const injectorPromise = new ParentInjectorPromise(element);
686
- const facade = new DowngradeComponentAdapter(element, attrs, scope, ngModel, injector, $compile, $parse, componentFactory, wrapCallback, unsafelyOverwriteSignalInputs);
687
- const projectableNodes = facade.compileContents();
688
- const componentRef = facade.createComponentAndSetup(projectableNodes, isNgUpgradeLite, info.propagateDigest);
689
- injectorPromise.resolve(componentRef.injector);
690
- if (ranAsync) {
691
- // If this is run async, it is possible that it is not run inside a
692
- // digest and initial input values will not be detected.
693
- scope.$evalAsync(() => { });
694
- }
695
- };
696
- const downgradeFn = !isNgUpgradeLite
697
- ? doDowngrade
698
- : (pInjector, mInjector) => {
699
- if (!ngZone) {
700
- ngZone = pInjector.get(NgZone);
701
- }
702
- wrapCallback(() => doDowngrade(pInjector, mInjector))();
703
- };
704
- // NOTE:
705
- // Not using `ParentInjectorPromise.all()` (which is inherited from `SyncPromise`), because
706
- // Closure Compiler (or some related tool) complains:
707
- // `TypeError: ...$src$downgrade_component_ParentInjectorPromise.all is not a function`
708
- SyncPromise.all([finalParentInjector, finalModuleInjector]).then(([pInjector, mInjector]) => downgradeFn(pInjector, mInjector));
709
- ranAsync = true;
710
- },
711
- };
712
- };
713
- // bracket-notation because of closure - see #14441
714
- directiveFactory['$inject'] = [$COMPILE, $INJECTOR, $PARSE];
715
- return directiveFactory;
716
- }
717
- /**
718
- * Synchronous promise-like object to wrap parent injectors,
719
- * to preserve the synchronous nature of AngularJS's `$compile`.
720
- */
721
- class ParentInjectorPromise extends SyncPromise {
722
- element;
723
- injectorKey = controllerKey(INJECTOR_KEY);
724
- constructor(element) {
725
- super();
726
- this.element = element;
727
- // Store the promise on the element.
728
- element.data(this.injectorKey, this);
729
- }
730
- resolve(injector) {
731
- // Store the real injector on the element.
732
- this.element.data(this.injectorKey, injector);
733
- // Release the element to prevent memory leaks.
734
- this.element = null;
735
- // Resolve the promise.
736
- super.resolve(injector);
737
- }
738
- }
739
-
740
- /**
741
- * @description
742
- *
743
- * A helper function to allow an Angular service to be accessible from AngularJS.
744
- *
745
- * *Part of the [upgrade/static](api?query=upgrade%2Fstatic)
746
- * library for hybrid upgrade apps that support AOT compilation*
747
- *
748
- * This helper function returns a factory function that provides access to the Angular
749
- * service identified by the `token` parameter.
750
- *
751
- * @usageNotes
752
- * ### Examples
753
- *
754
- * First ensure that the service to be downgraded is provided in an `NgModule`
755
- * that will be part of the upgrade application. For example, let's assume we have
756
- * defined `HeroesService`
757
- *
758
- * {@example upgrade/static/ts/full/module.ts region="ng2-heroes-service"}
759
- *
760
- * and that we have included this in our upgrade app `NgModule`
761
- *
762
- * {@example upgrade/static/ts/full/module.ts region="ng2-module"}
763
- *
764
- * Now we can register the `downgradeInjectable` factory function for the service
765
- * on an AngularJS module.
766
- *
767
- * {@example upgrade/static/ts/full/module.ts region="downgrade-ng2-heroes-service"}
768
- *
769
- * Inside an AngularJS component's controller we can get hold of the
770
- * downgraded service via the name we gave when downgrading.
771
- *
772
- * {@example upgrade/static/ts/full/module.ts region="example-app"}
773
- *
774
- * <div class="docs-alert docs-alert-important">
775
- *
776
- * When using `downgradeModule()`, downgraded injectables will not be available until the Angular
777
- * module that provides them is instantiated. In order to be safe, you need to ensure that the
778
- * downgraded injectables are not used anywhere _outside_ the part of the app where it is
779
- * guaranteed that their module has been instantiated.
780
- *
781
- * For example, it is _OK_ to use a downgraded service in an upgraded component that is only used
782
- * from a downgraded Angular component provided by the same Angular module as the injectable, but
783
- * it is _not OK_ to use it in an AngularJS component that may be used independently of Angular or
784
- * use it in a downgraded Angular component from a different module.
785
- *
786
- * </div>
787
- *
788
- * @param token an `InjectionToken` that identifies a service provided from Angular.
789
- * @param downgradedModule the name of the downgraded module (if any) that the injectable
790
- * "belongs to", as returned by a call to `downgradeModule()`. It is the module, whose injector will
791
- * be used for instantiating the injectable.<br />
792
- * (This option is only necessary when using `downgradeModule()` to downgrade more than one Angular
793
- * module.)
794
- *
795
- * @returns a [factory function](https://docs.angularjs.org/guide/di) that can be
796
- * used to register the service on an AngularJS module.
797
- *
798
- * @publicApi
799
- */
800
- function downgradeInjectable(token, downgradedModule = '') {
801
- const factory = function ($injector) {
802
- const injectorKey = `${INJECTOR_KEY}${downgradedModule}`;
803
- const injectableName = isFunction(token) ? getTypeName(token) : String(token);
804
- const attemptedAction = `instantiating injectable '${injectableName}'`;
805
- validateInjectionKey($injector, downgradedModule, injectorKey, attemptedAction);
806
- try {
807
- const injector = $injector.get(injectorKey);
808
- return injector.get(token);
809
- }
810
- catch (err) {
811
- throw new Error(`Error while ${attemptedAction}: ${err.message || err}`);
812
- }
813
- };
814
- factory['$inject'] = [$INJECTOR];
815
- return factory;
816
- }
817
-
818
- /**
819
- * The Trusted Types policy, or null if Trusted Types are not
820
- * enabled/supported, or undefined if the policy has not been created yet.
821
- */
822
- let policy;
823
- /**
824
- * Returns the Trusted Types policy, or null if Trusted Types are not
825
- * enabled/supported. The first call to this function will create the policy.
826
- */
827
- function getPolicy() {
828
- if (policy === undefined) {
829
- policy = null;
830
- const windowWithTrustedTypes = window;
831
- if (windowWithTrustedTypes.trustedTypes) {
832
- try {
833
- policy = windowWithTrustedTypes.trustedTypes.createPolicy('angular#unsafe-upgrade', {
834
- createHTML: (s) => s,
835
- });
836
- }
837
- catch {
838
- // trustedTypes.createPolicy throws if called with a name that is
839
- // already registered, even in report-only mode. Until the API changes,
840
- // catch the error not to break the applications functionally. In such
841
- // cases, the code will fall back to using strings.
842
- }
843
- }
844
- }
845
- return policy;
846
- }
847
- /**
848
- * Unsafely promote a legacy AngularJS template to a TrustedHTML, falling back
849
- * to strings when Trusted Types are not available.
850
- * @security This is a security-sensitive function; any use of this function
851
- * must go through security review. In particular, the template string should
852
- * always be under full control of the application author, as untrusted input
853
- * can cause an XSS vulnerability.
854
- */
855
- function trustedHTMLFromLegacyTemplate(html) {
856
- return getPolicy()?.createHTML(html) || html;
857
- }
858
-
859
- // Constants
860
- const REQUIRE_PREFIX_RE = /^(\^\^?)?(\?)?(\^\^?)?/;
861
- // Classes
862
- class UpgradeHelper {
863
- name;
864
- $injector;
865
- element;
866
- $element;
867
- directive;
868
- $compile;
869
- $controller;
870
- constructor(injector, name, elementRef, directive) {
871
- this.name = name;
872
- this.$injector = injector.get($INJECTOR);
873
- this.$compile = this.$injector.get($COMPILE);
874
- this.$controller = this.$injector.get($CONTROLLER);
875
- this.element = elementRef.nativeElement;
876
- this.$element = element(this.element);
877
- this.directive = directive ?? UpgradeHelper.getDirective(this.$injector, name);
878
- }
879
- static getDirective($injector, name) {
880
- const directives = $injector.get(name + 'Directive');
881
- if (directives.length > 1) {
882
- throw new Error(`Only support single directive definition for: ${name}`);
883
- }
884
- const directive = directives[0];
885
- // AngularJS will transform `link: xyz` to `compile: () => xyz`. So we can only tell there was a
886
- // user-defined `compile` if there is no `link`. In other cases, we will just ignore `compile`.
887
- if (directive.compile && !directive.link)
888
- notSupported(name, 'compile');
889
- if (directive.replace)
890
- notSupported(name, 'replace');
891
- if (directive.terminal)
892
- notSupported(name, 'terminal');
893
- return directive;
894
- }
895
- static getTemplate($injector, directive, fetchRemoteTemplate = false, $element) {
896
- if (directive.template !== undefined) {
897
- return trustedHTMLFromLegacyTemplate(getOrCall(directive.template, $element));
898
- }
899
- else if (directive.templateUrl) {
900
- const $templateCache = $injector.get($TEMPLATE_CACHE);
901
- const url = getOrCall(directive.templateUrl, $element);
902
- const template = $templateCache.get(url);
903
- if (template !== undefined) {
904
- return trustedHTMLFromLegacyTemplate(template);
905
- }
906
- else if (!fetchRemoteTemplate) {
907
- throw new Error('loading directive templates asynchronously is not supported');
908
- }
909
- return new Promise((resolve, reject) => {
910
- const $httpBackend = $injector.get($HTTP_BACKEND);
911
- $httpBackend('GET', url, null, (status, response) => {
912
- if (status === 200) {
913
- resolve(trustedHTMLFromLegacyTemplate($templateCache.put(url, response)));
914
- }
915
- else {
916
- reject(`GET component template from '${url}' returned '${status}: ${response}'`);
917
- }
918
- });
919
- });
920
- }
921
- else {
922
- throw new Error(`Directive '${directive.name}' is not a component, it is missing template.`);
923
- }
924
- }
925
- buildController(controllerType, $scope) {
926
- // TODO: Document that we do not pre-assign bindings on the controller instance.
927
- // Quoted properties below so that this code can be optimized with Closure Compiler.
928
- const locals = { '$scope': $scope, '$element': this.$element };
929
- const controller = this.$controller(controllerType, locals, null, this.directive.controllerAs);
930
- this.$element.data?.(controllerKey(this.directive.name), controller);
931
- return controller;
932
- }
933
- compileTemplate(template) {
934
- if (template === undefined) {
935
- template = UpgradeHelper.getTemplate(this.$injector, this.directive, false, this.$element);
936
- }
937
- return this.compileHtml(template);
938
- }
939
- onDestroy($scope, controllerInstance) {
940
- if (controllerInstance && isFunction(controllerInstance.$onDestroy)) {
941
- controllerInstance.$onDestroy();
942
- }
943
- $scope.$destroy();
944
- cleanData(this.element);
945
- }
946
- prepareTransclusion() {
947
- const transclude = this.directive.transclude;
948
- const contentChildNodes = this.extractChildNodes();
949
- const attachChildrenFn = (scope, cloneAttachFn) => {
950
- // Since AngularJS v1.5.8, `cloneAttachFn` will try to destroy the transclusion scope if
951
- // `$template` is empty. Since the transcluded content comes from Angular, not AngularJS,
952
- // there will be no transclusion scope here.
953
- // Provide a dummy `scope.$destroy()` method to prevent `cloneAttachFn` from throwing.
954
- scope = scope || { $destroy: () => undefined };
955
- return cloneAttachFn($template, scope);
956
- };
957
- let $template = contentChildNodes;
958
- if (transclude) {
959
- const slots = Object.create(null);
960
- if (typeof transclude === 'object') {
961
- $template = [];
962
- const slotMap = Object.create(null);
963
- const filledSlots = Object.create(null);
964
- // Parse the element selectors.
965
- Object.keys(transclude).forEach((slotName) => {
966
- let selector = transclude[slotName];
967
- const optional = selector.charAt(0) === '?';
968
- selector = optional ? selector.substring(1) : selector;
969
- slotMap[selector] = slotName;
970
- slots[slotName] = null; // `null`: Defined but not yet filled.
971
- filledSlots[slotName] = optional; // Consider optional slots as filled.
972
- });
973
- // Add the matching elements into their slot.
974
- contentChildNodes.forEach((node) => {
975
- const slotName = slotMap[directiveNormalize(node.nodeName.toLowerCase())];
976
- if (slotName) {
977
- filledSlots[slotName] = true;
978
- slots[slotName] = slots[slotName] || [];
979
- slots[slotName].push(node);
980
- }
981
- else {
982
- $template.push(node);
983
- }
984
- });
985
- // Check for required slots that were not filled.
986
- Object.keys(filledSlots).forEach((slotName) => {
987
- if (!filledSlots[slotName]) {
988
- throw new Error(`Required transclusion slot '${slotName}' on directive: ${this.name}`);
989
- }
990
- });
991
- Object.keys(slots)
992
- .filter((slotName) => slots[slotName])
993
- .forEach((slotName) => {
994
- const nodes = slots[slotName];
995
- slots[slotName] = (scope, cloneAttach) => {
996
- return cloneAttach(nodes, scope);
997
- };
998
- });
999
- }
1000
- // Attach `$$slots` to default slot transclude fn.
1001
- attachChildrenFn.$$slots = slots;
1002
- // AngularJS v1.6+ ignores empty or whitespace-only transcluded text nodes. But Angular
1003
- // removes all text content after the first interpolation and updates it later, after
1004
- // evaluating the expressions. This would result in AngularJS failing to recognize text
1005
- // nodes that start with an interpolation as transcluded content and use the fallback
1006
- // content instead.
1007
- // To avoid this issue, we add a
1008
- // [zero-width non-joiner character](https://en.wikipedia.org/wiki/Zero-width_non-joiner)
1009
- // to empty text nodes (which can only be a result of Angular removing their initial content).
1010
- // NOTE: Transcluded text content that starts with whitespace followed by an interpolation
1011
- // will still fail to be detected by AngularJS v1.6+
1012
- $template.forEach((node) => {
1013
- if (node.nodeType === Node.TEXT_NODE && !node.nodeValue) {
1014
- node.nodeValue = '\u200C';
1015
- }
1016
- });
1017
- }
1018
- return attachChildrenFn;
1019
- }
1020
- resolveAndBindRequiredControllers(controllerInstance) {
1021
- const directiveRequire = this.getDirectiveRequire();
1022
- const requiredControllers = this.resolveRequire(directiveRequire);
1023
- if (controllerInstance && this.directive.bindToController && isMap(directiveRequire)) {
1024
- const requiredControllersMap = requiredControllers;
1025
- Object.keys(requiredControllersMap).forEach((key) => {
1026
- controllerInstance[key] = requiredControllersMap[key];
1027
- });
1028
- }
1029
- return requiredControllers;
1030
- }
1031
- compileHtml(html) {
1032
- this.element.innerHTML = html;
1033
- return this.$compile(this.element.childNodes);
1034
- }
1035
- extractChildNodes() {
1036
- const childNodes = [];
1037
- let childNode;
1038
- while ((childNode = this.element.firstChild)) {
1039
- childNode.remove();
1040
- childNodes.push(childNode);
1041
- }
1042
- return childNodes;
1043
- }
1044
- getDirectiveRequire() {
1045
- const require = this.directive.require || (this.directive.controller && this.directive.name);
1046
- if (isMap(require)) {
1047
- Object.entries(require).forEach(([key, value]) => {
1048
- const match = value.match(REQUIRE_PREFIX_RE);
1049
- const name = value.substring(match[0].length);
1050
- if (!name) {
1051
- require[key] = match[0] + key;
1052
- }
1053
- });
1054
- }
1055
- return require;
1056
- }
1057
- resolveRequire(require) {
1058
- if (!require) {
1059
- return null;
1060
- }
1061
- else if (Array.isArray(require)) {
1062
- return require.map((req) => this.resolveRequire(req));
1063
- }
1064
- else if (typeof require === 'object') {
1065
- const value = {};
1066
- Object.keys(require).forEach((key) => (value[key] = this.resolveRequire(require[key])));
1067
- return value;
1068
- }
1069
- else if (typeof require === 'string') {
1070
- const match = require.match(REQUIRE_PREFIX_RE);
1071
- const inheritType = match[1] || match[3];
1072
- const name = require.substring(match[0].length);
1073
- const isOptional = !!match[2];
1074
- const searchParents = !!inheritType;
1075
- const startOnParent = inheritType === '^^';
1076
- const ctrlKey = controllerKey(name);
1077
- const elem = startOnParent ? this.$element.parent() : this.$element;
1078
- const value = searchParents ? elem.inheritedData(ctrlKey) : elem.data(ctrlKey);
1079
- if (!value && !isOptional) {
1080
- throw new Error(`Unable to find required '${require}' in upgraded directive '${this.name}'.`);
1081
- }
1082
- return value;
1083
- }
1084
- else {
1085
- throw new Error(`Unrecognized 'require' syntax on upgraded directive '${this.name}': ${require}`);
1086
- }
1087
- }
1088
- }
1089
- function getOrCall(property, ...args) {
1090
- return isFunction(property) ? property(...args) : property;
1091
- }
1092
- // NOTE: Only works for `typeof T !== 'object'`.
1093
- function isMap(value) {
1094
- return value && !Array.isArray(value) && typeof value === 'object';
1095
- }
1096
- function notSupported(name, feature) {
1097
- throw new Error(`Upgraded directive '${name}' contains unsupported feature: '${feature}'.`);
1098
- }
1099
-
1100
- var upgrade_helper = /*#__PURE__*/Object.freeze({
1101
- __proto__: null,
1102
- UpgradeHelper: UpgradeHelper
1103
- });
1104
-
1105
- export { Deferred, UpgradeHelper, VERSION, controllerKey, destroyApp, downgradeComponent, downgradeInjectable, getDowngradedModuleCount, isFunction, isNgModuleType, onError, strictEquals, trustedHTMLFromLegacyTemplate, upgrade_helper, util };
1106
- //# sourceMappingURL=upgrade_helper.mjs.map