Commit Graph

16473 Commits

Author SHA1 Message Date
crisbeto 0100a39e21 fix(ivy): i18n instructions thrown off by sanitizer in IE11 (#34305)
While sanitizing on browsers that don't support the `template` element (pretty much only IE), we create an inert document and we insert content into it via `document.body.innerHTML = unsafeHTML`. The problem is that IE appears to parse the HTML passed to `innerHTML` differently, depending on whether the element has been inserted into a document or not. In particular, it seems to split some strings into multiple text nodes, which would've otherwise been a single node. This ended up throwing off some of the i18n code down the line and causing a handful of failures. I've worked around it by creating a new inert `body` element into which the HTML would be inserted.

PR Close #34305
2019-12-13 14:19:56 -08:00
Kara Erickson 17f7f06ca5 Revert "build: update to yarn@1.21.1" (#34402)
This reverts commit f029af50820765019413fa319330830306b80d6a while we investigate
some failures on master on Circle CI. Currently the Windows tests and the
"test-ivy-aot" jobs are red because of incompatible yarn versions.

PR Close #34402
2019-12-13 13:43:25 -08:00
Pawel Kozlowski ea57587b7c docs(ivy): document breaking changes for DebugElement classes and attributes (#34328)
PR Close #34328
2019-12-13 10:53:41 -08:00
Pawel Kozlowski a781800276 refactor(ivy): remove usage of Proxy for IE10/11 compatibility (#34328)
PR Close #34328
2019-12-13 10:53:41 -08:00
Igor Minar b405942b0c build: update to yarn@1.21.1 (#34384)
This updates yarn throughout the monorepo for both build and CI.

PR Close #34384
2019-12-13 10:51:12 -08:00
Pawel Kozlowski 0fba79cda2 refactor(ivy): don't include removed classes in the styling debug (#34375)
This is mostly done to allign behaviour with DebugElement.classes and remove
Proxy usage (not supported in IE10/11).

PR Close #34375
2019-12-12 15:58:41 -08:00
Kapunahele Wong a9e3cbd534 docs: add docs about inputs and strictNullChecks to template typecheck (#34194)
PR Close #34194
2019-12-12 15:58:13 -08:00
Alex Rickabaugh af95dddd7e perf(ivy): eagerly parse the template twice during analysis (#34334)
A quirk of the Angular template parser is that when parsing templates in the
"default" mode, with options specified by the user, the source mapping
information in the template AST may be inaccurate. As a result, the compiler
parses the template twice: once for "emit" and once to produce an AST with
accurate sourcemaps for diagnostic production.

Previously, only the first parse was performed during analysis. The second
parse occurred during the template type-checking phase, just in time to
produce the template type-checking file.

However, with the reuse of analysis results during incremental builds, it
makes more sense to do the diagnostic parse eagerly during analysis so that
the work isn't unnecessarily repeated in subsequent builds. This commit
refactors the `ComponentDecoratorHandler` to do both parses eagerly, which
actually cleans up some complexity around template parsing as well.

PR Close #34334
2019-12-12 14:13:16 -08:00
JoostK ff0a91422a perf(compiler): speed up i18n digest computations (#34332)
Avoids the usage of array destructuring, as it introduces calls to
a `__values` helper function in ES5 that has a relatively high
performance impact. This shaves off roughly 130ms of CPU time for a
large compilation with big templates that uses i18n.

PR Close #34332
2019-12-12 14:06:37 -08:00
JoostK 014a7137f4 perf(compiler): use a shared interpolation regex (#34332)
The template parser has a certain interpolation config associated with
it and builds a regular expression each time it needs to extract the
interpolations from an input string. Since the interpolation config is
typically the default of `{{` and `}}`, the regular expression doesn't
have to be recreated each time. Therefore, this commit creates only a
single regular expression instance that is used for the default
configuration.

In a large compilation unit with big templates, computing the regular
expression took circa 275ms. This change reduces this to effectively
zero.

PR Close #34332
2019-12-12 14:06:37 -08:00
JoostK 4945274080 perf(compiler): optimize cloning cursors state (#34332)
On a large compilation unit with big templates, the total time spent in
the `PlainCharacterCursor` constructor was 470ms. This commit applies
two optimizations to reduce this time:

1. Avoid the object spread operator within the constructor, as the
generated `__assign` helper in the emitted UMD bundle (ES5) does not
optimize well compared to a hardcoded object literal. This results in a
significant performance improvement. Because of the straight-forward
object literal, the VM is now much better able to optimize the memory
allocations which makes a significant difference as the
`PlainCharacterCursor` constructor is called in tight loops.

2. Reduce the number of `CharacterCursor` clones. Although cloning
itself is now much faster because of the optimization above, several
clone operations were not necessary.

Combined, these changes reduce the total time spent in the
`PlainCharacterCursor` constructor to just 10ms.

PR Close #34332
2019-12-12 14:06:37 -08:00
JoostK 8c2cbdd385 perf(ivy): use module resolution cache (#34332)
During TypeScript module resolution, a lot of filesystem requests are
done. This is quite an expensive operation, so a module resolution cache
can be used to speed up the process significantly.

This commit lets the Ivy compiler perform all module resolution with a
module resolution cache. Note that the module resolution behavior can be
changed with a custom compiler host, in which case that custom host
implementation is responsible for caching. In the case of the Angular
CLI a custom compiler host with proper module resolution caching is
already in place, so the CLI already has this optimization.

PR Close #34332
2019-12-12 14:06:37 -08:00
JoostK 2f5ddd9c96 perf(ivy): cache export scopes extracted from declaration files (#34332)
The export scope of NgModules from external compilations units, as
present in .d.ts declarations, does not change during a compilation so
can be easily shared. There was already a cache but the computed export
scope was not actually stored there. This commit fixes that.

PR Close #34332
2019-12-12 14:06:36 -08:00
JoostK 6e5f076330 perf(ivy): share instances of `DomElementSchemaRegistry` (#34332)
To create a binding parser, an instance of `ElementSchemaRegistry` is
required. Prior to this change, each time a new binding parser was
created a new instance of `DomElementSchemaRegistry` would be
instantiated. This is an expensive operation that takes roughly 1ms per
instantiation, so it is key that multiple allocations are avoided.

By sharing a single `DomElementSchemaRegistry`, we avoid two such
allocations, i.e. save ~2ms, per component template.

PR Close #34332
2019-12-12 14:06:36 -08:00
Adam Plumer 3255d2b197 test(core): fix schematics calls to run synchronously (#34364)
Previously the calls to run the schematics were not being properly
or consistently awaited in the tests. While this currently does not
affect the tests' performance, this fix corrects the syntax and
adds stability for future changes.

PR Close #34364
2019-12-12 13:14:29 -08:00
Igor Minar 6e7ca05efc build: remove unused webpack npm dependency (#34366)
We no longer need it.

PR Close #34366
2019-12-12 13:14:01 -08:00
Alex Rickabaugh 6ba5fdc208 fix(ivy): generate a better error for template var writes (#34339)
In Ivy it's illegal for a template to write to a template variable. So the
template:

```html
<ng-template let-somevar>
  <button (click)="somevar = 3">Set var to 3</button>
</ng-template>
```

is erroneous and previously would fail to compile with an assertion error
from the `TemplateDefinitionBuilder`. This error wasn't particularly user-
friendly, though, as it lacked the context of which template or where the
error occurred.

In this commit, a new check in template type-checking is added which detects
such erroneous writes and produces a true diagnostic with the appropriate
context information.

Closes #33674

PR Close #34339
2019-12-12 13:13:32 -08:00
Alex Rickabaugh 74edde0a94 perf(ivy): reuse prior analysis work during incremental builds (#34288)
Previously, the compiler performed an incremental build by analyzing and
resolving all classes in the program (even unchanged ones) and then using
the dependency graph information to determine which .js files were stale and
needed to be re-emitted. This algorithm produced "correct" rebuilds, but the
cost of re-analyzing the entire program turned out to be higher than
anticipated, especially for component-heavy compilations.

To achieve performant rebuilds, it is necessary to reuse previous analysis
results if possible. Doing this safely requires knowing when prior work is
viable and when it is stale and needs to be re-done.

The new algorithm implemented by this commit is such:

1) Each incremental build starts with knowledge of the last known good
   dependency graph and analysis results from the last successful build,
   plus of course information about the set of files changed.

2) The previous dependency graph's information is used to determine the
   set of source files which have "logically" changed. A source file is
   considered logically changed if it or any of its dependencies have
   physically changed (on disk) since the last successful compilation. Any
   logically unchanged dependencies have their dependency information copied
   over to the new dependency graph.

3) During the `TraitCompiler`'s loop to consider all source files in the
   program, if a source file is logically unchanged then its previous
   analyses are "adopted" (and their 'register' steps are run). If the file
   is logically changed, then it is re-analyzed as usual.

4) Then, incremental build proceeds as before, with the new dependency graph
   being used to determine the set of files which require re-emitting.

This analysis reuse avoids template parsing operations in many circumstances
and significantly reduces the time it takes ngtsc to rebuild a large
application.

Future work will increase performance even more, by tackling a variety of
other opportunities to reuse or avoid work.

PR Close #34288
2019-12-12 13:11:45 -08:00
Alex Rickabaugh 50cdc0ac1b refactor(ivy): move analysis side effects into a register phase (#34288)
Previously 'analyze' in the various `DecoratorHandler`s not only extracts
information from the decorators on the classes being analyzed, but also has
several side effects within the compiler:

* it can register metadata about the types involved in global metadata
  trackers.
* it can register information about which .ngfactory symbols are actually
  needed.

In this commit, these side-effects are moved into a new 'register' phase,
which runs after the 'analyze' step. Currently this is a no-op refactoring
as 'register' is always called directly after 'analyze'. In the future this
opens the door for re-use of prior analysis work (with only 'register' being
called, to apply the above side effects).

Also as part of this refactoring, the reification of NgModule scope
information into the incremental dependency graph is moved to the
`NgtscProgram` instead of the `TraitCompiler` (which now only manages trait
compilation and does not have other side effects).

PR Close #34288
2019-12-12 13:11:45 -08:00
Alex Rickabaugh 252e3e9487 refactor(ivy): formalize the compilation process for matched handlers (#34288)
Prior to this commit, the `IvyCompilation` tracked the state of each matched
`DecoratorHandler` on each class in the `ts.Program`, and how they
progressed through the compilation process. This tracking was originally
simple, but had grown more complicated as the compiler evolved. The state of
each specific "target" of compilation was determined by the nullability of
a number of fields on the object which tracked it.

This commit formalizes the process of compilation of each matched handler
into a new "trait" concept. A trait is some aspect of a class which gets
created when a `DecoratorHandler` matches the class. It represents an Ivy
aspect that needs to go through the compilation process.

Traits begin in a "pending" state and undergo transitions as various steps
of compilation take place. The `IvyCompilation` class is renamed to the
`TraitCompiler`, which manages the state of all of the traits in the active
program.

Making the trait concept explicit will support future work to incrementalize
the expensive analysis process of compilation.

PR Close #34288
2019-12-12 13:11:45 -08:00
Pete Bacon Darwin c13a4b8c03 style(common): remove unnecessary jsdoc type (#34369)
These types cause the compiler to give warnings,
which add noise to compilation logs.

PR Close #34369
2019-12-12 11:05:41 -08:00
Pete Bacon Darwin 05c1398b4d fix(ngcc): render UMD imports even if no prior imports (#34353)
Previously the UMD rendering formatter assumed that
there would already be import (and an export) arguments
to the UMD factory function.

This commit adds support for this corner case.

Fixes #34138

PR Close #34353
2019-12-12 09:09:41 -08:00
owenmecham 1583293694 docs: ng-conf 2020 the musical (#34342)
Added event and announcement info for ng-conf 2020

PR Close #34342
2019-12-12 09:06:11 -08:00
Kara Erickson ad987021ce Revert "build: update integration/bazel to rules_nodejs 0.42.1" (#34360)
This reverts commit ec7ea77aa8d90d2ba32089e140ed716cb6aadb89 because it's part
of a PR that was red on CircleCI once it was merged into master (Windows tests
are only run on master, not on PRs).

PR Close #34360
2019-12-11 15:58:46 -08:00
Kara Erickson 9a800e8fa2 Revert "build: update @angular/bazel schematics to rules_nodejs 0.42.1" (#34360)
This reverts commit 73fd10ddd5548ce899b897ba2779ff041914c2dc because it's part
of a PR that was red on CircleCI once it was merged into master (Windows tests
are only run on master, not on PRs).

PR Close #34360
2019-12-11 15:58:46 -08:00
Kara Erickson 0bf9263297 Revert "build: update @angular/bazel schematics to use html_insert_assets & pkg_web" (#34360)
This reverts commit 6b905347bd2294bba703f6d38c983356af58946b because it's part
of a PR that was red on CircleCI once it was merged into master (Windows tests
are only run on master, not on PRs).

PR Close #34360
2019-12-11 15:58:46 -08:00
Kara Erickson ef179e6a00 Revert "build: remove html_insert_assets complication from integration/bazel" (#34360)
This reverts commit 810b7072d0a9ba0b07162f7a600a75347b06d379 because it's part
of a PR that was red on CircleCI once it was merged into master (Windows tests
are only run on master, not on PRs).

PR Close #34360
2019-12-11 15:58:46 -08:00
Kara Erickson caaeb21e59 Revert "build: update integration/bazel & @angular/bazel schematics to rules_nodejs 0.42.1" (#34360)
This reverts commit 4e38a973b158ba397903199abe1e008b0627d81c because it's part of a PR
that was red on CircleCI once it was merged into master (Windows tests are only run
on master, not on PRs).

PR Close #34360
2019-12-11 15:58:46 -08:00
Pete Bacon Darwin c77656e2dd fix(ngcc): handle imports in dts files when processing UMD (#34356)
When statically evalulating UMD code it is possible to find
that we are looking for the declaration of an identifier that
actually came from a typings file (rather than a UMD file).

Previously, the UMD reflection host would always try to use
a UMD specific algorithm for finding identifier declarations,
but when the id is actually in a typings file this resulted in the
returned declaration being the containing file of the declaration
rather than the declaration itself.

Now the UMD reflection host will check to see if the file containing
the identifier is a typings file and use the appropriate stategy.

PR Close #34356
2019-12-11 13:20:49 -08:00
Sonu Kapoor 5f2897be0b docs(forms): Update catchError to return an `observable` (#34357)
Closes #34323

PR Close #34357
2019-12-11 13:19:57 -08:00
Pete Bacon Darwin 6ce940315b fix(ivy): i18n - remove `translate` function when clearing translations (#34346)
The `loadTranslations()` function will attach the `translate()` function
to `$localize.translate` to cause runtime translation to occur.

We should cleanup after ourselves by unattaching this function when
we call `clearTranslations()`.

Fixes #32781

PR Close #34346
2019-12-11 13:19:22 -08:00
Greg Magolan 656607b640 build: update integration/bazel & @angular/bazel schematics to rules_nodejs 0.42.1 (#34112)
This release brings a bug fix that https://github.com/angular/angular/pull/34243 is waiting on in order to remove rules_nodejs patches: fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazelbuild/rules_nodejs#1402)

PR Close #34112
2019-12-11 13:18:51 -08:00
Greg Magolan b0534177e0 build: remove html_insert_assets complication from integration/bazel (#34112)
For the purposes of the integration test the zone.js script & bundle script tags could just go into the source index.html itself. The purpose of the integration test is is to test @angular/bazel & ng_module & ng_package so there is no need to exercise html_insert_assets.

PR Close #34112
2019-12-11 13:18:51 -08:00
Greg Magolan 7df2b4aeff build: update @angular/bazel schematics to use html_insert_assets & pkg_web (#34112)
PR Close #34112
2019-12-11 13:18:51 -08:00
Greg Magolan bfeaa7d564 build: update @angular/bazel schematics to rules_nodejs 0.42.1 (#34112)
PR Close #34112
2019-12-11 13:18:51 -08:00
Greg Magolan dd3b27e971 build: update integration/bazel to rules_nodejs 0.42.1 (#34112)
PR Close #34112
2019-12-11 13:18:51 -08:00
Andrew Kushnir db4f508737 docs: release notes for the v9.0.0-rc.6 release 2019-12-11 11:07:04 -08:00
Keen Yee Liau 08ea38f197 fix(bazel): improve performance of tsHost.writeFile() (#34331)
Removing from an array incurs O(n^2) cost, and could be mitigated with the use of a Set instead.

PR Close #34331
2019-12-11 09:51:14 -08:00
Andrew Kushnir 8572911e94 test(ivy): `class_binding` benchmark fixes (#34242)
This commit fixes a couple issues that prevent `class_binding` benchmark from running: moving constants requires by the `benchmark` function before function declaration and referencing correct consts in template instructions.

PR Close #34242
2019-12-11 09:50:23 -08:00
ajitsinghkaler f503832abe docs: fix headers in "Getting Started" code-snippets (#34321)
The headers of two of the code-snippets in the [Input section](https://angular.io/start#input)
of the "Getting Started" guide incorrectly referenced an non-existent
file path (`src/app/product-list/product-alerts.component.ts`).

This commit fixes the headers to show the correct file path
(`src/app/product-alerts/product-alerts.component.ts`).

Fixes #34320

PR Close #34321
2019-12-11 09:49:49 -08:00
JoostK b72c7a89a9 refactor(ivy): include generic type for `ModuleWithProviders` in .d.ts files (#34235)
The `ModuleWithProviders` type has an optional type parameter that
should be specified to indicate what NgModule class will be provided.
This enables the Ivy compiler to statically determine the NgModule type
from the declaration files. This type parameter will become required in
the future, however to aid in the migration the compiler will detect
code patterns where using `ModuleWithProviders` as return type is
appropriate, in which case it transforms the emitted .d.ts files to
include the generic type argument.

This should reduce the number of occurrences where `ModuleWithProviders`
is referenced without its generic type argument.

Resolves FW-389

PR Close #34235
2019-12-10 16:34:47 -08:00
Alex Rickabaugh a8fced8846 refactor(ivy): abstract .d.ts file transformations (#34235)
This commit refactors the way the compiler transforms .d.ts files during
ngtsc builds. Previously the `IvyCompilation` kept track of a
`DtsFileTransformer` for each input file. Now, any number of
`DtsTransform` operations that need to be applied to a .d.ts file are
collected in the `DtsTransformRegistry`. These are then ran using a
single `DtsTransformer` so that multiple transforms can be applied
efficiently.

PR Close #34235
2019-12-10 16:34:46 -08:00
JoostK 0984fbc748 fix(compiler-cli): allow declaration-only template type check members (#34296)
The metadata collector for View Engine compilations emits error symbols
for static class members that have not been initialized, which prevents
a library from building successfully when `strictMetadataEmit` is
enabled, which is recommended for libraries to avoid issues in library
consumers. This is troublesome for libraries that are adopting static
members for the Ivy template type checker: these members don't need a
value assignment as only their type is of importance, however this
causes metadata errors. As such, a library used to be required to
initialize the special static members to workaround this error,
undesirably introducing a code-size overhead in terms of emitted
JavaScript code.

This commit modifies the collector logic to specifically ignore
the special static members for Ivy's template type checker, preventing
any errors from being recorded during the metadata collection.

PR Close #34296
2019-12-10 16:31:23 -08:00
JoostK 22ad701134 fix(ivy): inherit static coercion members from base classes (#34296)
For Ivy's template type checker it is possible to let a directive
specify static members to allow a wider type for some input:

```typescript
export class MatSelect {
  @Input() disabled: boolean;

  static ngAcceptInputType_disabled: boolean | string;
}
```

This allows a binding to the `MatSelect.disabled` input to be of type
boolean or string, whereas the `disabled` property itself is only of
type boolean.

Up until now, any static `ngAcceptInputType_*` property was not
inherited for subclasses of a directive class. This is cumbersome, as
the directive's inputs are inherited, so any acceptance member should as
well. To resolve this limitation, this commit extends the flattening of
directive metadata to include the acceptance members.

Fixes #33830
Resolves FW-1759

PR Close #34296
2019-12-10 16:31:23 -08:00
Judy Bogart c9df9afddd docs: add change detection to glossary (#34316)
PR Close #34316
2019-12-10 16:30:35 -08:00
Andrew Kushnir c8b5b81516 refactor(ivy): avoid type coercion in `saveNameToExportMap` function (#34335)
TypeScript 3.7 flags `if` conditions that implicitly coerce a function/method definition. While checking for the `template` presence on a def (actually checking whether we work with Component) in `saveNameToExportMap`, the `if` condition had implicit type coercion. This commit updates the condition to use the `isComponentDef` function (that checks `def.template` against `null` internally) to avoid compilation errors with TypeScript 3.7.

PR Close #34335
2019-12-10 14:06:25 -08:00
Misko Hevery c8447d21bd refactor(ivy): pull property read into a constant (#34290)
PR Close #34290
2019-12-10 10:33:19 -08:00
Misko Hevery 4ef6f1ab2e refactor(ivy): prevent `-0` from being generated (#34290)
PR Close #34290
2019-12-10 10:33:19 -08:00
Andrew Kushnir bb52fb798c fix(ivy): handle SafeStyles in [style.prop] correctly (#34286)
Prior to this commit, values wrapped into SafeStyle were not handled correctly in [style.prop] bindings in case style sanitizer is present (when template contains some style props that require sanitization). Style sanitizer was not unwrapping values in case a given prop doesn't require sanitization.As a result, wrapped values were used as final styling values (see https://github.com/angular/angular/blob/master/packages/core/src/render3/styling/bindings.ts#L620). This commit updates the logic to unwrap safe values in sanitizer in case no sanitization is required.

PR Close #34286
2019-12-10 10:32:27 -08:00
George Kalpakas 2ecf9f3f2a refactor(docs-infra): give more descriptive variable name (#34284)
Discussion:
https://github.com/angular/angular/pull/34213#discussion_r353249119

PR Close #34284
2019-12-10 09:18:35 -08:00