Commit Graph

4688 Commits

Author SHA1 Message Date
Matias Niemelä b2decf0266 perf(ivy): speed up bindings when no directives are present (#32919)
Prior to this fix, whenever a style or class binding is present, the
binding application process would require an instance of `TStylingContext`
to be built regardless of whether or not any binding resolution is needed
(just so that it knows whether or not there are any collisions).
This check is, however, unnecessary because if (and only if) there
are directives present on the element then are collisions possible.

This patch removes the need for style/class bindings to register
themselves on to a `TStylingContext` if there are no directives and
present on an element. This means that all map and prop-based
style/class bindings are applied as soon as bindings are updated on
an element.

PR Close #32919
2019-10-10 13:57:24 -07:00
Pawel Kozlowski 8d111da7f6 perf(ivy): use instanceof operator to check for NodeInjectorFactory instances (#33082)
We used to have a custom version of the NodeInjectorFactory check that was
supposed to be faster to the direct usage of the `instanceof` operator. This
might have been the case in the past but the recent benchmark shows that using
`instanceof` speeds up the `directive_instantiate` by ~10%
(from time getting from ~340ms down to ~305ms).

PR Close #33082
2019-10-10 13:56:52 -07:00
Pawel Kozlowski 22d4efbed1 perf(ivy): introduce micro-benchmark for directive instantiation (#33082)
PR Close #33082
2019-10-10 13:56:52 -07:00
FaustmannChr be54c580bf docs(common): Fixes typo (#33003)
PR Close #33003
2019-10-10 13:55:40 -07:00
crisbeto 305f3686c3 build: fix compilation error in benchmark (#33067)
A PR that updates one of the benchmarks and another one that changes the signature for `elementStart` got in around the same time which is causing a compilation error. These changes fix the error.

PR Close #33067
2019-10-09 13:40:10 -07:00
Pete Bacon Darwin 90855f331f refactor(ivy): i18n - rename `I18nError` to `TranslationParserError` (#32881)
This closer reflects what caused the error.

PR Close #32881
2019-10-09 13:19:38 -07:00
Pete Bacon Darwin 2cdb3a079d feat(ivy): i18n - implement compile-time inlining (#32881)
This commit implements a tool that will inline translations and generate
a translated copy of a set of application files from a set of translation
files.

PR Close #32881
2019-10-09 13:19:38 -07:00
crisbeto d5b87d32b0 perf(ivy): move attributes array into component def (#32798)
Currently Ivy stores the element attributes into an array above the component def and passes it into the relevant instructions, however the problem is that upon minification the array will get a unique name which won't compress very well. These changes move the attributes array into the component def and pass in the index into the instructions instead.

Before:
```
const _c0 = ['foo', 'bar'];

SomeComp.ngComponentDef = defineComponent({
  template: function() {
    element(0, 'div', _c0);
  }
});
```

After:
```
SomeComp.ngComponentDef = defineComponent({
  consts: [['foo', 'bar']],
  template: function() {
    element(0, 'div', 0);
  }
});
```

A couple of cases that this PR doesn't handle:
* Template references are still in a separate array.
* i18n attributes are still in a separate array.

PR Close #32798
2019-10-09 13:16:55 -07:00
Pete Bacon Darwin b2b917d2d8 feat(ngcc): expose `--create-ivy-entry-points` option on ivy-ngcc (#33049)
This allows a postinstall hook to generate the same
output as the CLI integration does.

See https://github.com/angular/angular/pull/32999#issuecomment-539937368

PR Close #33049
2019-10-09 13:16:16 -07:00
Pawel Kozlowski 9f0c549bc8 perf(ivy): avoid memory allocation in the isAnimationProp check (#32997)
Accessing a string's character at index allocates a new, single character string.
A better (faster) check is to use `charCodeAt` that doesn't trigger allocation.

This simple change speeds up the element_text_create benchmark by ~7%.

PR Close #32997
2019-10-08 13:02:11 -07:00
Pawel Kozlowski affae99b22 perf(ivy): add static attributes to the element_text_create benchmark (#32997)
PR Close #32997
2019-10-08 13:02:11 -07:00
Alex Rickabaugh ed711418f1 style(bazel): fix 2 unformatted .bzl files 2019-10-08 10:45:48 -07:00
Alex Eagle c653a16b57 build: load build_bazel_rules_nodejs through external (#33041)
PR Close #33041
2019-10-08 10:24:41 -07:00
Greg Magolan 64823f561c build: add history-server to @angular/bazel schematics (#32889)
The history_server rule is not longer shipped with rules_nodejs as it has been replaced by auto-generated rule `load("@npm//history-server:index.bzl", "history_server")` which requires the user to add history-server to their package.json.

PR Close #32889
2019-10-08 09:27:11 -07:00
Greg Magolan e1d07b2fd2 build: add JSEcmaScripModuleInfo provider to ng_module (#32889)
PR Close #32889
2019-10-08 09:27:11 -07:00
Alex Eagle cdfbda3d3b build: add missing http-server dep to bazel example (#32889)
Also update rules_nodejs 0.38.0->0.38.1

PR Close #32889
2019-10-08 09:27:11 -07:00
Alex Eagle f783244ad1 build: update to rules_nodejs 0.38 (#32889)
PR Close #32889
2019-10-08 09:27:11 -07:00
crisbeto 2265cb5938 refactor(core): remove deprecated Renderer (#33019)
Removes the `Renderer` and related symbols which have been deprecated since version 4.

BREAKING CHANGES:
* `Renderer` has been removed. Use `Renderer2` instead.
* `RenderComponentType` has been removed. Use `RendererType2` instead.
* `RootRenderer` has been removed. Use `RendererFactory2` instead.

PR Close #33019
2019-10-08 09:23:00 -07:00
Paul Gschwendtner c1bb88603e fix(common): expand type for "ngForOf" input to work with strict null checks (#31371)
Currently the `ngForOf` input accepts `null` or `undefined` as valid
values. Although when using strict template input type checking
(which will be supported by `ngtsc`), passing `null` or `undefined`
with strict null checks enabled causes a type check failure because
the type for the `ngForOf` input becomes too strict if strict null checks
are enabled. The type of the input needs to be expanded to also accept
`null` or `undefined` to behave consistently regardless of the
`strictNullChecks` flag.

This is necessary because whenever strict input type checking is enabled
by default, most of the Angular projects that use `*ngFor` with the async pipe
will either need to disable template type checking or strict null checks
because the `async` pipe returns `null` if the observable hasn't been
emitted yet.

See for example how this affects the `angular/components` repository and
how much bloat the workaround involves: https://github.com/angular/components/pull/16373/files#r296942696.

PR Close #31371
2019-10-07 11:01:22 -07:00
LASLEDJ fee28e20bb feat(forms): formGroupName and formArrayName also accepts a number (#32607)
For consistency, `FormGroupName` and `FormaArrayName` also accepts a
number as input's type like `FormControlName`

Closes https://github.com/angular/angular/issues/32436

PR Close #32607
2019-10-07 11:00:49 -07:00
Kristiyan Kostadinov 3efb060127 fix(ivy): unable to bind style zero (#32994)
Fixes not being able to bind zero as a value in style bindings.

Fixes #32984.

PR Close #32994
2019-10-07 11:00:19 -07:00
JoostK c61e4d7841 fix(ivy): process nested animation metadata (#32818)
In View Engine, animation metadata could occur in nested arrays which
would be flattened in the compiler. When compiling a component for Ivy
however, the compiler no longer statically evaluates a component's
animation metadata and is therefore unable to flatten it statically.
This resulted in an issue to find animations at runtime, as the metadata
was incorrectly registered with the animation engine.

Although it would be possible to statically evaluate the animation
metadata in ngtsc, doing so would prevent reusable animations exported
from libraries from being usable as ngtsc's partial evaluator is unable
to read values inside libraries. This is unlike ngc's usage of static
symbols represented in a library's `.metadata.json`, which explains how
the View Engine compiler is able to flatten the animation metadata
statically.

As an alternative solution, the metadata flattening is now done in the
runtime during the registration of the animation metadata with the
animation engine.

Fixes #32794

PR Close #32818
2019-10-07 10:51:37 -07:00
George Kalpakas e007918e35 refactor(forms): refactor `Validators.email()` regexp for easier comparison with WHATWG version (#32961)
As mentioned in the previous commit, the regexp used by
`Validators.email()` is a slightly enhanced version of the
[WHATWG one](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address).

This commit refactors the regexp (without changing its behavior) to make
it more closely match the format of WHATWG version, so that it is easier
for people to compare it against the WHATWG one and understand the
differences.

The main changes were:
- Changing the order of characters/character classes inside `[...]`;
  e.g. `[A-Za-z]` --> `[a-zA-Z]`
- Mark all groups as non-capturing (since we do not use the captured
  values); e.g. `(foo)` --> `(?:foo)`
  (This could theoretically also have a positive performance impact, but
  I suspect JavaScript engines are already optimizing away capturing
  groups when they are not used.)

PR Close #32961
2019-10-07 10:51:00 -07:00
George Kalpakas 3c2770bfc7 docs(forms): expand e-mail validation description (#32961)
Previously, there was no documentation of what `Validators.email()`
expects as a valid e-mail address, making it difficult for people to
determine whether it covers their requirements or not. Even more so that
the used pattern slightly deviates from the
[WHATWG version](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address).
One's only option was to look at the source code and try to decipher the
regexp pattern.

This commit adds a high-level description of the validator and mentions
its similarity to and differences from the WHATWG version. It also adds
a brief explanation of the regexp's behavior and references for more
information in the source code to provide more context to
maintainers/users trying to understand the implementation in the future.

Fixes #18985
Fixes #25186
Closes #32747

PR Close #32961
2019-10-07 10:51:00 -07:00
Andrew Kushnir 90fb5d9f7a fix(ivy): generate ng-reflect properties for i18n attributes (#32989)
Prior to this change, ng-reflect properties were not created in case an attribute was marked as translatable (for ex. `i18n-title`). This commit adds the logic to generate ng-reflect for such cases.

PR Close #32989
2019-10-07 10:50:44 -07:00
cexbrayat d18289fa9c fix(ivy): missing schematics field in localize package (#33025)
The schematics added in #32791 is currently failing as the package.json does not reference it.

```
> ng add @angular/localize@9.0.0-next.9
+ @angular/localize@9.0.0-next.9
added 1 package from 1 contributor in 6.745s
Installed packages for tooling via npm.
The package that you are trying to add does not support schematics. You can try using a different version of the package or contact the package author to add ng-add support.
```

PR Close #33025
2019-10-07 10:21:29 -07:00
Andrew Kushnir bad3434337 fix(ivy): avoid exposing `ng` with Closure Compiler enhanced optimizations (#33010)
Prior to this commit, the `ng` was exposed in global namespace, which turned out to be problematic when minifying code with Closure, since it sometimes clobber our `ng` global. This commit aligns Ivy debugging tools behavior with existing logic in "platform-browser" package (packages/platform-browser/src/dom/util.ts#L31) by avoiding `ng` in global namespace when Closure Compiler is used.

PR Close #33010
2019-10-07 10:19:54 -07:00
Charles Lyding 0119f46daf fix(core): set migration schematic versions to valid semver versions (#32991)
PR Close #32991
2019-10-04 13:54:39 -07:00
Charles Lyding f8eca840ee fix(core): update migration descriptions with links to AIO documentation (#32991)
PR Close #32991
2019-10-04 13:54:39 -07:00
Kristiyan Kostadinov 7f6429d802 refactor: re-enable dynamic queries migration (#32992)
Re-enables the dynamic queries migration, now that we have all of the necessary framework changes in place.

Also moves the logic that identifies static queries out of the compiler and into the static queries migration, because that's the only place left that's using it.

PR Close #32992
2019-10-04 13:54:09 -07:00
cexbrayat 94b9b7e154 docs(core): update static flag documentation (#32993)
Followup to #32720 that removed the logic that statically determines whether a query is dynamic.
This updates the docs to reflect that, and mentions that the flag now defaults to false.

PR Close #32993
2019-10-04 13:53:55 -07:00
JiaLiPassion 3a53e2c960 fix(core): ngNoopZone should have the same signature with ngZone (#32068)
Close #32063

PR Close #32068
2019-10-04 11:48:12 -07:00
Alan 01677b21b6 refactor(core): add `createMigrationCompilerHost` (#32827)
Current we need to create and override certain compiler host methods in every schematic because schematics use a virtual fs. We this change we extract this logic to a common util.

PR Close #32827
2019-10-04 11:45:35 -07:00
Pawel Kozlowski 60047037a3 perf(ivy): attempt rendering initial styling only if present (#32979)
PR Close #32979
2019-10-04 11:44:57 -07:00
Pawel Kozlowski e6881b5b42 perf(ivy): limit TNode.inputs reads on first template pass (#32979)
PR Close #32979
2019-10-04 11:44:57 -07:00
Pawel Kozlowski 8593d0d52e perf(ivy): increase number of created views in the element_text_create benchmark (#32979)
PR Close #32979
2019-10-04 11:44:57 -07:00
JiaLiPassion 53d13c3fc6 refactor: rename unpatched event flag in Zone from `BLACK_LISTED_EVENTS` to `UNPATCHED_EVENTS` (#29617)
Closes #28529

PR Close #29617
2019-10-04 08:44:58 -07:00
George Kalpakas 75fd407bbd build: avoid error in `build-packages-dist.sh` (#32923)
Not sure why it works on other people's environments, but after
217db9b21 I started getting the following error when running
`scripts/build-packages-dist.sh` (on Windows):

```
ERROR: C:/.../angular/packages/bazel/docs/BUILD.bazel:3:1: Generating Skylark documentation dir for docs (3 files) failed (Exit 1)
Traceback (most recent call last):
  File "c:\...\temp\Bazel.runfiles_u_l5te\runfiles\io_bazel_skydoc\skydoc\main.py", line 335, in <module>
    main(sys.argv)
  File "c:\...\temp\Bazel.runfiles_u_l5te\runfiles\io_bazel_skydoc\skydoc\main.py", line 303, in main
    load_symbols = load_sym_extractor.extract(bzl_file)
  File "c:\...\temp\Bazel.runfiles_u_l5te\runfiles\io_bazel_skydoc\skydoc\load_extractor.py", line 110, in extract
    load_symbols = self._extract_loads(bzl_file)
  File "c:\...\temp\Bazel.runfiles_u_l5te\runfiles\io_bazel_skydoc\skydoc\load_extractor.py", line 38, in _extract_loads
    tree = ast.parse(f.read(), bzl_file)
  File "C:\...\.windows-build-tools\python27\lib\ast.py", line 37, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "packages/bazel/src/ng_package/ng_package.bzl", line 39
    print("[ng_package.bzl]", *args)
                              ^
SyntaxError: invalid syntax
```

It seems expected, because `print` is not a function, so
`print(foo, *args)` is interpreted as printing a tuple (where `*args` is
invalid syntax). Not sure why it doesn't break on other people's
machines :/

This change makes the verbose logs a little less pretty, but that
shouldn't be a big issue (given that it is an opt-in feature and it can
always be overwritten locally, if necessary).

PR Close #32923
2019-10-04 08:27:21 -07:00
Keen Yee Liau adb562bca6 fix(language-service): create StaticReflector once only (#32543)
The creation of StaticReflector in createMetadataResolver() is a very expensive operation because it involves numerous module resolutions.
To make matter worse, since the API of the Reflector does not provide the ability to invalidate its internal caches, it has to be destroyed and recreated on *every* program change.
This has a HUGE impact on performance.
This PR fixes this problem by carefully invalidating all StaticSymbols in a file that has changed, thereby reducing the overhead of recomputation on program change.

PR Close #32543
2019-10-03 15:02:03 -07:00
crisbeto 900d0055e0 feat(core): make static query flag optional (#32986)
This is a re-submit of #32686.

Switches back to having the static flag be optional on ViewChild and ContentChild queries, in preparation for changing its default value.

PR Close #32986
2019-10-03 14:02:47 -07:00
crisbeto 7806596fba feat(core): default to dynamic queries (#32720)
These changes switch to defaulting the `static` flag on `ViewChild` and `ContentChild` queries to `false`, in addition to removing the logic that statically determines whether a query is dynamic.

PR Close #32720
2019-10-03 12:26:21 -07:00
Andrius 65297cde19 perf(language-service): improve Language service performance (#32098)
PR Close #32098
2019-10-03 12:16:15 -07:00
Pete Bacon Darwin bcbf3e4123 feat(ivy): i18n - render legacy message ids in `$localize` if requested (#32937)
The `$localize` library uses a new message digest function for
computing message ids. This means that translations in legacy
translation files will no longer match the message ids in the code
and so will not be translated.

This commit adds the ability to specify the format of your legacy
translation files, so that the appropriate message id can be rendered
in the `$localize` tagged strings. This results in larger code size
and requires that all translations are in the legacy format.

Going forward the developer should migrate their translation files
to use the new message id format.

PR Close #32937
2019-10-03 12:12:55 -07:00
Pete Bacon Darwin fc28b266cd refactor(compiler): clean up I18nMetaVisitor constructor (#32937)
The initialization of the `_createI18nMessage` property
can be done where it is declared to avoid needing to
type it as `any`.

PR Close #32937
2019-10-03 12:12:55 -07:00
Pete Bacon Darwin 447fa2fccd refactor(compiler): move test helper to test file (#32937)
The `processI18nMeta()` function is only called from
a single test, so let's move it there to keep the main
source simpler.

PR Close #32937
2019-10-03 12:12:55 -07:00
George Kalpakas 0f21ae9a74 docs(core): mark `EventEmitter#__isAsync` as internal to hide from API docs (#31378)
The `__isAsync` property is not part of the public API and should not
appear in the API docs.

PR Close #31378
2019-10-03 10:24:34 -07:00
Alison Gale efbce7501b test(upgrade): add unit tests for AngularJSUrlCodec's parse method (#32976)
Add unit test coverage for new logic added in #32874 and for existing
logic that was untested.

test(upgrade): add unit tests for AngularJSUrlCodec's parse method

Add additional coverage and fix spacing

test(upgrade): add unit tests for AngularJSUrlCodec's parse method

Add unit test coverage for new logic added in #32874 and for existing
logic that was untested.

test(upgrade): add unit tests for AngularJSUrlCodec's parse method

Add additional coverage and fix spacing

test(upgrade): add unit tests for AngularJSUrlCodec's parse method

Add unit test coverage for new logic added in #32874 and for existing
logic that was untested.

test(upgrade): add unit tests for AngularJSUrlCodec's parse method

Add unit test coverage for new logic added in #32874 and for existing
logic that was untested.

test(upgrade): add unit tests for AngularJSUrlCodec's parse method

Add additional coverage and fix spacing

test(upgrade): add unit tests for AngularJSUrlCodec's parse method

Add unit test coverage for new logic added in #32874 and for existing
logic that was untested.

PR Close #32976
2019-10-03 09:55:26 -07:00
Martin Probst 5332b04f35 build: TypeScript 3.6 compatibility. (#32908)
This PR updates Angular to compile with TypeScript 3.6 while retaining
compatibility with TS3.5. We achieve this by inserting several `as any`
casts for compatiblity around `ts.CompilerHost` APIs.

PR Close #32908
2019-10-03 09:09:11 -07:00
Paul Gschwendtner 6f5f481fda refactor(core): undecorated-classes-with-di migration should ignore referenced resources (#32953)
Currently the undecorated-classes-with-di migration leverages NGC in order
to work with metadata resolution. Since NGC by default tries to resolve referenced
resources on initialization of the underlying TS program, it can result in unexpected
migration failures due to missing resource files.

This is especially an issue since the CLI wraps the `AngularCompilerProgram` with
special logic (i.e. to support SCSS preprocessing etc.). We don't have all of this since
we instantiate a vanilla NGC program.

The solution to the problem is to simply treat resource requests as valid, and returning
a fake content. The migration is not dependent on templates or stylesheets.. so it's the
simplest and most robust solution.

Fixes #32826

PR Close #32953
2019-10-02 14:54:33 -07:00
Paul Gschwendtner 90dda5873a test(core): remove "enableIvy" compiler option from migration tests (#32954)
ec4381d explicitly set `enableIvy: false` for all migrations inside
the core package. This actually hides migration issues because the
migration itself should ensure that it instantiates the right
compiler program if it relies on `@angular/compiler-cli`.

We should remove these options from all migration tests to
ensure that we catch issues with migrations running in version
9 where Ivy is enabled by default.

e.g. e5636a322c
was accidentally hidden due to the `enableIvy: false` option.

PR Close #32954
2019-10-02 14:53:41 -07:00