@angular/core 14.1.0-rc.0 → 14.2.0-next.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.
Files changed (34) hide show
  1. package/esm2020/src/application_ref.mjs +25 -20
  2. package/esm2020/src/core.mjs +2 -1
  3. package/esm2020/src/core_private_export.mjs +2 -2
  4. package/esm2020/src/di/injector_compatibility.mjs +2 -2
  5. package/esm2020/src/di/r3_injector.mjs +7 -1
  6. package/esm2020/src/errors.mjs +1 -1
  7. package/esm2020/src/linker/component_factory_resolver.mjs +1 -1
  8. package/esm2020/src/render3/component.mjs +120 -127
  9. package/esm2020/src/render3/component_ref.mjs +144 -9
  10. package/esm2020/src/render3/errors.mjs +9 -5
  11. package/esm2020/src/render3/index.mjs +2 -2
  12. package/esm2020/src/render3/instructions/element_validation.mjs +9 -5
  13. package/esm2020/src/render3/ng_module_ref.mjs +4 -14
  14. package/esm2020/src/version.mjs +1 -1
  15. package/esm2020/testing/src/logger.mjs +3 -3
  16. package/esm2020/testing/src/ng_zone_mock.mjs +3 -3
  17. package/esm2020/testing/src/test_bed.mjs +442 -15
  18. package/esm2020/testing/src/test_bed_common.mjs +1 -1
  19. package/esm2020/testing/src/test_bed_compiler.mjs +823 -0
  20. package/esm2020/testing/src/test_hooks.mjs +5 -5
  21. package/esm2020/testing/src/testing.mjs +1 -1
  22. package/fesm2015/core.mjs +13088 -12945
  23. package/fesm2015/core.mjs.map +1 -1
  24. package/fesm2015/testing.mjs +13215 -13220
  25. package/fesm2015/testing.mjs.map +1 -1
  26. package/fesm2020/core.mjs +13088 -12945
  27. package/fesm2020/core.mjs.map +1 -1
  28. package/fesm2020/testing.mjs +13215 -13221
  29. package/fesm2020/testing.mjs.map +1 -1
  30. package/index.d.ts +155 -8
  31. package/package.json +1 -1
  32. package/testing/index.d.ts +19 -95
  33. package/esm2020/testing/src/r3_test_bed.mjs +0 -433
  34. package/esm2020/testing/src/r3_test_bed_compiler.mjs +0 -823
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v14.1.0-rc.0
2
+ * @license Angular v14.2.0-next.0
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -1318,6 +1318,46 @@ declare class ComponentFactoryResolver_2 extends ComponentFactoryResolver {
1318
1318
 
1319
1319
  declare type ComponentInstance = {};
1320
1320
 
1321
+ /**
1322
+ * An interface that describes the subset of component metadata
1323
+ * that can be retrieved using the `reflectComponentType` function.
1324
+ *
1325
+ * @publicApi
1326
+ */
1327
+ export declare interface ComponentMirror<C> {
1328
+ /**
1329
+ * The component's HTML selector.
1330
+ */
1331
+ get selector(): string;
1332
+ /**
1333
+ * The type of component the factory will create.
1334
+ */
1335
+ get type(): Type<C>;
1336
+ /**
1337
+ * The inputs of the component.
1338
+ */
1339
+ get inputs(): ReadonlyArray<{
1340
+ readonly propName: string;
1341
+ readonly templateName: string;
1342
+ }>;
1343
+ /**
1344
+ * The outputs of the component.
1345
+ */
1346
+ get outputs(): ReadonlyArray<{
1347
+ readonly propName: string;
1348
+ readonly templateName: string;
1349
+ }>;
1350
+ /**
1351
+ * Selector for all <ng-content> elements in the component.
1352
+ */
1353
+ get ngContentSelectors(): ReadonlyArray<string>;
1354
+ /**
1355
+ * Whether this component is marked as standalone.
1356
+ * Note: an extra flag, not present in `ComponentFactory`.
1357
+ */
1358
+ get isStandalone(): boolean;
1359
+ }
1360
+
1321
1361
  /**
1322
1362
  * Represents a component created by a `ComponentFactory`.
1323
1363
  * Provides access to the component instance and related objects,
@@ -1618,6 +1658,72 @@ declare type ContentQueriesFunction<T> = <U extends T>(rf: ɵRenderFlags, ctx: U
1618
1658
 
1619
1659
  declare const CONTEXT = 8;
1620
1660
 
1661
+ /**
1662
+ * Creates a `ComponentRef` instance based on provided component type and a set of options.
1663
+ *
1664
+ * @usageNotes
1665
+ *
1666
+ * The example below demonstrates how the `createComponent` function can be used
1667
+ * to create an instance of a ComponentRef dynamically and attach it to an ApplicationRef,
1668
+ * so that it gets included into change detection cycles.
1669
+ *
1670
+ * Note: the example uses standalone components, but the function can also be used for
1671
+ * non-standalone components (declared in an NgModule) as well.
1672
+ *
1673
+ * ```typescript
1674
+ * @Component({
1675
+ * standalone: true,
1676
+ * template: `Hello {{ name }}!`
1677
+ * })
1678
+ * class HelloComponent {
1679
+ * name = 'Angular';
1680
+ * }
1681
+ *
1682
+ * @Component({
1683
+ * standalone: true,
1684
+ * template: `<div id="hello-component-host"></div>`
1685
+ * })
1686
+ * class RootComponent {}
1687
+ *
1688
+ * // Bootstrap an application.
1689
+ * const applicationRef = await bootstrapApplication(RootComponent);
1690
+ *
1691
+ * // Locate a DOM node that would be used as a host.
1692
+ * const host = document.getElementById('hello-component-host');
1693
+ *
1694
+ * // Get an `EnvironmentInjector` instance from the `ApplicationRef`.
1695
+ * const environmentInjector = applicationRef.injector;
1696
+ *
1697
+ * // We can now create a `ComponentRef` instance.
1698
+ * const componentRef = createComponent(HelloComponent, {host, environmentInjector});
1699
+ *
1700
+ * // Last step is to register the newly created ref using the `ApplicationRef` instance
1701
+ * // to include the component view into change detection cycles.
1702
+ * applicationRef.attachView(componentRef.hostView);
1703
+ * ```
1704
+ *
1705
+ * @param component Component class reference.
1706
+ * @param options Set of options to use:
1707
+ * * `environmentInjector`: An `EnvironmentInjector` instance to be used for the component, see
1708
+ * additional info about it at https://angular.io/guide/standalone-components#environment-injectors.
1709
+ * * `hostElement` (optional): A DOM node that should act as a host node for the component. If not
1710
+ * provided, Angular creates one based on the tag name used in the component selector (and falls
1711
+ * back to using `div` if selector doesn't have tag name info).
1712
+ * * `elementInjector` (optional): An `ElementInjector` instance, see additional info about it at
1713
+ * https://angular.io/guide/hierarchical-dependency-injection#elementinjector.
1714
+ * * `projectableNodes` (optional): A list of DOM nodes that should be projected through
1715
+ * [`<ng-content>`](api/core/ng-content) of the new component instance.
1716
+ * @returns ComponentRef instance that represents a given Component.
1717
+ *
1718
+ * @publicApi
1719
+ */
1720
+ export declare function createComponent<C>(component: Type<C>, options: {
1721
+ environmentInjector: EnvironmentInjector;
1722
+ hostElement?: Element;
1723
+ elementInjector?: Injector;
1724
+ projectableNodes?: Node[][];
1725
+ }): ComponentRef<C>;
1726
+
1621
1727
  /**
1622
1728
  * Create a new environment injector.
1623
1729
  *
@@ -6342,6 +6448,47 @@ declare interface RDomTokenList {
6342
6448
  remove(token: string): void;
6343
6449
  }
6344
6450
 
6451
+ /**
6452
+ * Creates an object that allows to retrieve component metadata.
6453
+ *
6454
+ * @usageNotes
6455
+ *
6456
+ * The example below demonstrates how to use the function and how the fields
6457
+ * of the returned object map to the component metadata.
6458
+ *
6459
+ * ```typescript
6460
+ * @Component({
6461
+ * standalone: true,
6462
+ * selector: 'foo-component',
6463
+ * template: `
6464
+ * <ng-content></ng-content>
6465
+ * <ng-content select="content-selector-a"></ng-content>
6466
+ * `,
6467
+ * })
6468
+ * class FooComponent {
6469
+ * @Input('inputName') inputPropName: string;
6470
+ * @Output('outputName') outputPropName = new EventEmitter<void>();
6471
+ * }
6472
+ *
6473
+ * const mirror = reflectComponentType(FooComponent);
6474
+ * expect(mirror.type).toBe(FooComponent);
6475
+ * expect(mirror.selector).toBe('foo-component');
6476
+ * expect(mirror.isStandalone).toBe(true);
6477
+ * expect(mirror.inputs).toEqual([{propName: 'inputName', templateName: 'inputPropName'}]);
6478
+ * expect(mirror.outputs).toEqual([{propName: 'outputName', templateName: 'outputPropName'}]);
6479
+ * expect(mirror.ngContentSelectors).toEqual([
6480
+ * '*', // first `<ng-content>` in a template, the selector defaults to `*`
6481
+ * 'content-selector-a' // second `<ng-content>` in a template
6482
+ * ]);
6483
+ * ```
6484
+ *
6485
+ * @param component Component class reference.
6486
+ * @returns An object that allows to retrieve component metadata.
6487
+ *
6488
+ * @publicApi
6489
+ */
6490
+ export declare function reflectComponentType<C>(component: Type<C>): ComponentMirror<C> | null;
6491
+
6345
6492
  /**
6346
6493
  * `Dependency` is used by the framework to extend DI.
6347
6494
  * This is internal to Angular and should not be used directly.
@@ -7083,6 +7230,7 @@ declare const enum RuntimeErrorCode {
7083
7230
  INJECTOR_ALREADY_DESTROYED = 205,
7084
7231
  PROVIDER_IN_WRONG_CONTEXT = 207,
7085
7232
  MISSING_INJECTION_TOKEN = 208,
7233
+ INVALID_MULTI_PROVIDER = 209,
7086
7234
  MULTIPLE_COMPONENTS_MATCH = -300,
7087
7235
  EXPORT_NOT_FOUND = -301,
7088
7236
  PIPE_NOT_FOUND = -302,
@@ -10169,7 +10317,8 @@ export declare function ɵinjectChangeDetectorRef(flags: InjectFlags): ChangeDet
10169
10317
  export declare const ɵINJECTOR_SCOPE: InjectionToken<InjectorScope | null>;
10170
10318
 
10171
10319
  /**
10172
- * Internal bootstrap application API that implements the core bootstrap logic.
10320
+ * Internal create application API that implements the core application creation logic and optional
10321
+ * bootstrap logic.
10173
10322
  *
10174
10323
  * Platforms (such as `platform-browser`) may require different set of application and platform
10175
10324
  * providers for an application to function correctly. As a result, platforms may use this function
@@ -10178,8 +10327,8 @@ export declare const ɵINJECTOR_SCOPE: InjectionToken<InjectorScope | null>;
10178
10327
  *
10179
10328
  * @returns A promise that returns an `ApplicationRef` instance once resolved.
10180
10329
  */
10181
- export declare function ɵinternalBootstrapApplication(config: {
10182
- rootComponent: Type<unknown>;
10330
+ export declare function ɵinternalCreateApplication(config: {
10331
+ rootComponent?: Type<unknown>;
10183
10332
  appProviders?: Array<Provider | ImportedNgModuleProviders>;
10184
10333
  platformProviders?: Provider[];
10185
10334
  }): Promise<ApplicationRef>;
@@ -10722,17 +10871,15 @@ export declare class ɵRender3ComponentRef<T> extends ComponentRef<T> {
10722
10871
  onDestroy(callback: () => void): void;
10723
10872
  }
10724
10873
 
10725
- export declare class ɵRender3NgModuleRef<T> extends NgModuleRef<T> implements InternalNgModuleRef<T>, EnvironmentInjector {
10874
+ export declare class ɵRender3NgModuleRef<T> extends NgModuleRef<T> implements InternalNgModuleRef<T> {
10726
10875
  _parent: Injector | null;
10727
10876
  _bootstrapComponents: Type<any>[];
10728
10877
  _r3Injector: R3Injector;
10729
- injector: EnvironmentInjector;
10730
10878
  instance: T;
10731
10879
  destroyCbs: (() => void)[] | null;
10732
10880
  readonly componentFactoryResolver: ComponentFactoryResolver_2;
10733
10881
  constructor(ngModuleType: Type<T>, _parent: Injector | null);
10734
- get(token: any, notFoundValue?: any, injectFlags?: InjectFlags): any;
10735
- runInContext<ReturnT>(fn: () => ReturnT): ReturnT;
10882
+ get injector(): EnvironmentInjector;
10736
10883
  destroy(): void;
10737
10884
  onDestroy(callback: () => void): void;
10738
10885
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular/core",
3
- "version": "14.1.0-rc.0",
3
+ "version": "14.2.0-next.0",
4
4
  "description": "Angular - the core framework",
5
5
  "author": "angular",
6
6
  "license": "MIT",
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v14.1.0-rc.0
2
+ * @license Angular v14.2.0-next.0
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -178,13 +178,11 @@ export declare function flush(maxTurns?: number): number;
178
178
  export declare function flushMicrotasks(): void;
179
179
 
180
180
  /**
181
- * Returns a singleton of the applicable `TestBed`.
182
- *
183
- * It will be either an instance of `TestBedViewEngine` or `TestBedRender3`.
181
+ * Returns a singleton of the `TestBed` class.
184
182
  *
185
183
  * @publicApi
186
184
  */
187
- export declare const getTestBed: () => TestBed;
185
+ export declare function getTestBed(): TestBed;
188
186
 
189
187
  /**
190
188
  * Allows injecting dependencies in `beforeEach()` and `it()`. Note: this function
@@ -237,7 +235,7 @@ export declare type MetadataOverride<T> = {
237
235
  * @publicApi
238
236
  */
239
237
  export declare interface ModuleTeardownOptions {
240
- /** Whether the test module should be destroyed after every test. */
238
+ /** Whether the test module should be destroyed after every test. Defaults to `true`. */
241
239
  destroyAfterEach: boolean;
242
240
  /** Whether errors during test module destruction should be re-thrown. Defaults to `true`. */
243
241
  rethrowErrors?: boolean;
@@ -255,8 +253,8 @@ export declare function resetFakeAsyncZone(): void;
255
253
  * @publicApi
256
254
  */
257
255
  export declare interface TestBed {
258
- platform: PlatformRef;
259
- ngModule: Type<any> | Type<any>[];
256
+ get platform(): PlatformRef;
257
+ get ngModule(): Type<any> | Type<any>[];
260
258
  /**
261
259
  * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
262
260
  * angular module. These are common to every test in the suite.
@@ -273,12 +271,12 @@ export declare interface TestBed {
273
271
  * Reset the providers for the test injector.
274
272
  */
275
273
  resetTestEnvironment(): void;
276
- resetTestingModule(): void;
274
+ resetTestingModule(): TestBed;
277
275
  configureCompiler(config: {
278
276
  providers?: any[];
279
277
  useJit?: boolean;
280
278
  }): void;
281
- configureTestingModule(moduleDef: TestModuleMetadata): void;
279
+ configureTestingModule(moduleDef: TestModuleMetadata): TestBed;
282
280
  compileComponents(): Promise<any>;
283
281
  inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
284
282
  inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
@@ -287,26 +285,27 @@ export declare interface TestBed {
287
285
  /** @deprecated from v9.0.0 use TestBed.inject */
288
286
  get(token: any, notFoundValue?: any): any;
289
287
  execute(tokens: any[], fn: Function, context?: any): any;
290
- overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
291
- overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
292
- overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
293
- overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void;
288
+ overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBed;
289
+ overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBed;
290
+ overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBed;
291
+ overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBed;
292
+ overrideTemplate(component: Type<any>, template: string): TestBed;
294
293
  /**
295
294
  * Overwrites all providers for the given token with the given provider definition.
296
295
  */
297
296
  overrideProvider(token: any, provider: {
298
297
  useFactory: Function;
299
298
  deps: any[];
300
- }): void;
299
+ }): TestBed;
301
300
  overrideProvider(token: any, provider: {
302
301
  useValue: any;
303
- }): void;
302
+ }): TestBed;
304
303
  overrideProvider(token: any, provider: {
305
304
  useFactory?: Function;
306
305
  useValue?: any;
307
306
  deps?: any[];
308
- }): void;
309
- overrideTemplateUsingTestingModule(component: Type<any>, template: string): void;
307
+ }): TestBed;
308
+ overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBed;
310
309
  createComponent<T>(component: Type<T>): ComponentFixture<T>;
311
310
  }
312
311
 
@@ -317,92 +316,17 @@ export declare interface TestBed {
317
316
  *
318
317
  * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
319
318
  *
320
- * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
321
- * according to the compiler used.
322
- *
323
319
  * @publicApi
324
320
  */
325
321
  export declare const TestBed: TestBedStatic;
326
322
 
327
323
  /**
328
- * Static methods implemented by the `TestBedViewEngine` and `TestBedRender3`
324
+ * Static methods implemented by the `TestBed`.
329
325
  *
330
326
  * @publicApi
331
327
  */
332
- export declare interface TestBedStatic {
328
+ export declare interface TestBedStatic extends TestBed {
333
329
  new (...args: any[]): TestBed;
334
- /**
335
- * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
336
- * angular module. These are common to every test in the suite.
337
- *
338
- * This may only be called once, to set up the common providers for the current test
339
- * suite on the current platform. If you absolutely need to change the providers,
340
- * first use `resetTestEnvironment`.
341
- *
342
- * Test modules and platforms for individual platforms are available from
343
- * '@angular/<platform_name>/testing'.
344
- */
345
- initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, options?: TestEnvironmentOptions): TestBed;
346
- /**
347
- * Reset the providers for the test injector.
348
- */
349
- resetTestEnvironment(): void;
350
- resetTestingModule(): TestBedStatic;
351
- /**
352
- * Allows overriding default compiler providers and settings
353
- * which are defined in test_injector.js
354
- */
355
- configureCompiler(config: {
356
- providers?: any[];
357
- useJit?: boolean;
358
- }): TestBedStatic;
359
- /**
360
- * Allows overriding default providers, directives, pipes, modules of the test injector,
361
- * which are defined in test_injector.js
362
- */
363
- configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic;
364
- /**
365
- * Compile components with a `templateUrl` for the test's NgModule.
366
- * It is necessary to call this function
367
- * as fetching urls is asynchronous.
368
- */
369
- compileComponents(): Promise<any>;
370
- overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic;
371
- overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic;
372
- overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic;
373
- overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBedStatic;
374
- overrideTemplate(component: Type<any>, template: string): TestBedStatic;
375
- /**
376
- * Overrides the template of the given component, compiling the template
377
- * in the context of the TestingModule.
378
- *
379
- * Note: This works for JIT and AOTed components as well.
380
- */
381
- overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic;
382
- /**
383
- * Overwrites all providers for the given token with the given provider definition.
384
- *
385
- * Note: This works for JIT and AOTed components as well.
386
- */
387
- overrideProvider(token: any, provider: {
388
- useFactory: Function;
389
- deps: any[];
390
- }): TestBedStatic;
391
- overrideProvider(token: any, provider: {
392
- useValue: any;
393
- }): TestBedStatic;
394
- overrideProvider(token: any, provider: {
395
- useFactory?: Function;
396
- useValue?: any;
397
- deps?: any[];
398
- }): TestBedStatic;
399
- inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
400
- inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
401
- /** @deprecated from v9.0.0 use TestBed.inject */
402
- get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
403
- /** @deprecated from v9.0.0 use TestBed.inject */
404
- get(token: any, notFoundValue?: any): any;
405
- createComponent<T>(component: Type<T>): ComponentFixture<T>;
406
330
  }
407
331
 
408
332
  /**