Fixes#25018.
Instantiating a NgModuleRef from NgModuleFactory reuses the NgModuleDefinition if it is already present. However the NgModuleDefinition has a providers array which modified when tree shakable providers are instantiated. This corrupts the provider definitions the next time the same factory is used to create a new NgModuleRef - Two provider definitions can end up with the same index anf the injector could potentially return a completely wrong object for a provider token.
This scenario is more likely on the server where the same NgModuleFactory is reused across requests.
The fix clones the cached NgModuleDefinition so that any tree shakable providers added later do not affect the cached copy.
PR Close#25022
Previously ngtsc would use a tuple of class types for listing metadata
in .d.ts files. For example, an @NgModule's declarations might be
represented with the type:
[NgIf, NgForOf, NgClass]
If the module had no declarations, an empty tuple [] would be produced.
This has two problems.
1. If the class type has generic type parameters, TypeScript will
complain that they're not provided.
2. The empty tuple type is not actually legal.
This commit addresses both problems.
1. Class types are now represented using the `typeof` operator, so the
above declarations would be represented as:
[typeof NgIf, typeof NgForOf, typeof NgClass].
Since typeof operates on a value, it doesn't require generic type
arguments.
2. Instead of an empty tuple, `never` is used to indicate no metadata.
PR Close#24862
Previously, some of the *Def symbols were not exported or were exported
as public API. This commit ensures every definition type is in the
private export namespace.
PR Close#24862
ngInjectorDef.imports is generated from @NgModule.imports plus
@NgModule.exports. A problem arises as a result, because @NgModule
exports contain not only other modules (which will have ngInjectorDef
fields), but components, directives, and pipes as well. Because of
locality, it's difficult for the compiler to filter these out at
build time.
It's not impossible, but for now filtering them out at runtime will
allow testing of the compiler against complex applications.
PR Close#24862
On accident a few of the definition types were emitted as public API
symbols. Much of the Ivy API surface is still prefixed with ɵ,
indicating it's a private API. The definition types should be private
for now.
PR Close#24738
Tree shakable providers use the APP_ROOT token to determine where to attach themselves. APP_ROOT gets set on NgModule with BrowserModule irrespective of whether it is actually the root(Ex. in case of SSR app where the shell app is first bootstrapped without BrowserModule being the root module).
This change allows a NgModule with BrowserModule to explicitly mark itself as not the root by setting APP_ROOT token to false. This allows tree shakable providers to be attached to the right rott module.
PR Close#24814
With these changes, the types are a little stricter now and also not
compatible with Protractor's jasmine-like syntax. So, we have to also
use `@types/jasminewd2` for e2e tests (but not for non-e2e tests).
I also had to "augment" `@types/jasminewd2`, because the latest
typings from [DefinitelyTyped][1] do not reflect the fact that the
`jasminewd2` version (v2.1.0) currently used by Protractor supports
passing a `done` callback to a spec.
[1]: 566e039485/types/jasminewd2/index.d.ts (L9-L15)Fixes#23952Closes#24733
PR Close#19904
This updates the r3_pipe_compiler to not depend on global analysis,
and to produce ngPipeDef instructions in the same way that the other
compilers do. It's a precursor to JIT and AOT implementations of
@Pipe compilation.
PR Close#24703
This propagates other custom equality testers added by users. Additionally, if
an Angular project is using jasmine 2.6+, it will allow Jasmine's custom object
differ to print out pretty test error messages.
fixes#22939
PR Close#22983
- Adds InheritanceDefinitionFeature to ivy
- Ensures that lifecycle hooks are inherited from super classes whether they are defined as directives or not
- Directives cannot inherit from Components
- Components can inherit from Directives or Components
- Ensures that Inputs, Outputs, and Host Bindings are inherited
- Ensures that super class Features are run
PR Close#24570
Used to resolve resource URLs on `@Component` when used with JIT compilation.
```
@Component({
selector: 'my-comp',
templateUrl: 'my-comp.html', // This requires asynchronous resolution
})
class MyComponnent{
}
// Calling `renderComponent` will fail because `MyComponent`'s `@Compenent.templateUrl`
// needs to be resolved because `renderComponent` is synchronous process.
// renderComponent(MyComponent);
// Calling `resolveComponentResources` will resolve `@Compenent.templateUrl` into
// `@Compenent.template`, which would allow `renderComponent` to proceed in synchronous manner.
// Use browser's `fetch` function as the default resource resolution strategy.
resolveComponentResources(fetch).then(() => {
// After resolution all URLs have been converted into strings.
renderComponent(MyComponent);
});
```
PR Close#24637
Previously the todo app imported reflect-metadata, since it is a dependency
of JIT and the todo app tests run in both JIT and AOT modes. However, the
code doesn't get tree-shaken away in AOT mode.
This change adds a target //packages/core/test/bundling/util:reflect_metadata
which, depending on whether the compile flag is in JIT or AOT mode, either
includes reflect-metadata or is a no-op.
Not including reflect-metadata gets the compressed todo bundle down to 12.5 kB.
PR Close#24677
ngtsc is sufficiently capable now that it can compile hello_world
and todo and achieve equivalent results to ngc in ivy (global) mode.
Bundle sizes:
hello_world - 3.0 kB
todo - 14.7 kB
PR Close#24677
This change makes @angular/compiler more tree-shakeable by changing
an enum to a const enum and by getting rid of a top-level map that
the tree-shaker was seeing as a reference which caused r3_identifiers
to be retained.
This drops a few hundred bytes of JS from tree-shaken ngtsc compiled
apps.
PR Close#24677
Previously the repo was depending on an old version of build optimizer.
This change updates to the latest (an RC release in the CLI package).
Additionally, this changes the behavior of ng_rollup_bundle to apply
the optimizer to ngtsc compiled code, and configures it to treat the
@angular/compiler package as side-effect-free.
This results in a substantial size reduction of ngtsc compiled code.
PR Close#24677
This commit takes advantage of the @angular/compiler work for ngInjectorDef
in AOT mode in order to generate the same definition in JIT mode.
PR Close#24632
All errors for existing fields have been detected and suppressed with a
`!` assertion.
Issue/24571 is tracking proper clean up of those instances.
One-line change required in ivy/compilation.ts, because it appears that
the new syntax causes tsickle emitted node to no longer track their
original sourceFiles.
PR Close#24572
This change supports compilation of components, directives, and modules
within ngtsc. Support is not complete, but is enough to compile and test
//packages/core/test/bundling/todo in full AOT mode. Code size benefits
are not yet achieved as //packages/core itself does not get compiled, and
some decorators (e.g. @Input) are not stripped, leading to unwanted code
being retained by the tree-shaker. This will be improved in future commits.
PR Close#24427
clang-format (on mac) has taken a disliking to this particular line, and
rewrites one of the ɵ characters to an invalid Unicode sequence.
PR Close#24479
At runtime in JIT mode, when the compiler writes a reference to a symbol that symbol
is resolved through a symbol table named angularCoreEnv in render3/jit/environment.
Previously, this symbol table was not kept up-to-date with the Ivy instruction set
and the names of symbols the compiler could reference.
This change brings the symbol table in sync, and also adds a test that verifies every
symbol the compiler can reference is available at runtime in the symbol table.
PR Close#24479
When creating content queries from a directive on an element we need to take into account
existing view queries. The same element can be reported to both content and view queries
so freshly created content queries must be combined with pre-existing view queries.
PR Close#24507
NOTE: This does NOT add parsing of namespaced attributes
- Adds AttributeMarker for namespaced attributes
- Adds test for namespaced attributes
- Updates AttributeMarker enum to use CamelCase, and not UPPER_CASE names
PR Close#24386