Commit Graph

5618 Commits

Author SHA1 Message Date
Greg Magolan f13ee3e692 build: update to rules_nodejs 1.4.0 (#35813)
This brings in the 'silent' attribute in rollup_bundle to allow the suppression of verbose output in the zone.js package build.

PR Close #35813
2020-03-03 08:58:26 -08:00
crisbeto 0653db14e7 perf(core): add micro benchmark for destroy hook invocation (#35784)
Adds a micro benchmark which excercises the logic that invokes `ngOnDestroy` hooks.

PR Close #35784
2020-03-03 08:57:58 -08:00
Doug Parker c195d22f68 fix(core): remove side effects from `ɵɵgetInheritedFactory()` (#35769)
`ɵɵgetInheritedFactory()` is called from generated code for a component which extends another class. This function is detected by Closure to have a side effect and is not able to tree shake the component as a result. Marking it with `noSideEffects()` tells Closure it can remove this function under the relevant tree shaking conditions.

PR Close #35769
2020-03-03 08:50:03 -08:00
Doug Parker 9cf85d2177 fix(core): remove side effects from `ɵɵNgOnChangesFeature()` (#35769)
`ɵɵNgOnChangesFeature()` would set `ngInherit`, which is a side effect and also not necessary. This was pulled out to module scope so the function itself can be pure. Since it only curries another function, the call is entirely unnecessary. Updated the compiler to only generate a reference to this function, rather than a call to it, and removed the extra curry indirection.

PR Close #35769
2020-03-03 08:50:03 -08:00
Doug Parker ba3612774f fix(core): add `noSideEffects()` to `ɵɵdefineComponent()` (#35769)
This marks the function are "pure" and eligible to be tree shaken by Closure. Without this, initializing `ngDevMode` is considered a side effect which prevents this function from being tree shaken and also any component which calls it.

PR Close #35769
2020-03-03 08:50:03 -08:00
Doug Parker dc6a7918e3 fix(core): add `noSideEffects()` to `make*Decorator()` functions (#35769)
This causes all the `make*Decorator()` functions to be considered pure and to be eligible for associated tree shaking by Closure.

PR Close #35769
2020-03-03 08:50:03 -08:00
Doug Parker 4052dd8188 refactor(core): update `noSideEffects()` to return the result of the inner function (#35769)
This is useful for propagating return values without them being converted to a string. It still provides the same guarantees to Closure, which will assume that the function invoked is pure and can be tree-shaken accordingly.

PR Close #35769
2020-03-03 08:50:03 -08:00
ayazhafiz 47a1811e0b feat(language-service): modularize error messages (#35678)
This commit performs a modularization of the Language Service's existing
diagnostic messages. Such a modularization has two primary advantages:

- Centralization and decoupling of error messages from the code that
  generates them makes it easy to add/delete/edit diagnostic messages,
  and allows for independent iteration of diagnostic messages and
  diagnostic generation.
- Prepares for additional features like annotating the locations where a
  diagnostic is generated and enabling the configuration of which
  diagnostics should be reported by the language service.

Although it would be preferable to place the diagnostics registry in an
independent JSON file, for ease of typing diagnostic types as an enum
variant of 'ts.DiagnosticCategory', the registry is stored as an object.

Part of #32663.

PR Close #35678
2020-03-03 08:49:34 -08:00
Pawel Kozlowski 5652fb1018 fix(core): allow null / undefined values in query results (#35796)
Before this change ngIvy implementation of queries would throw upon
encountering null / undefined query result collected from an embedded
view. It turns out that we might have a provider that explicitly provides
a null / undefined value in a place of a token queried for.

This commit removes a check from the ngIvy query implementation that was
asserting on a query result to be defined.

Fixes #35673

PR Close #35796
2020-03-02 11:16:22 -08:00
Miško Hevery a153b61098 fix(core): treat `[class]` and `[className]` as unrelated bindings (#35668)
Before this change `[class]` and `[className]` were both converted into `ɵɵclassMap`. The implication of this is that at runtime we could not differentiate between the two and as a result we treated `@Input('class')` and `@Input('className)` as equivalent.

This change makes `[class]` and `[className]` distinct. The implication of this is that `[class]` becomes `ɵɵclassMap` instruction but  `[className]` becomes `ɵɵproperty' instruction. This means that `[className]` will no longer participate in styling and will overwrite the DOM `class` value.

Fix #35577

PR Close #35668
2020-03-02 08:18:59 -08:00
Miško Hevery a4e956a7cf style: Reformat test comment for line breaks (#35668)
PR Close #35668
2020-03-02 08:18:59 -08:00
Andrew Kushnir 40da51f641 fix(compiler): support i18n attributes on `<ng-template>` tags (#35681)
Prior to this commit, i18n attributes defined on `<ng-template>` tags were not processed by the compiler. This commit adds the necessary logic to handle i18n attributes in the same way how these attrs are processed for regular elements.

PR Close #35681
2020-03-02 08:18:06 -08:00
Matias Niemelä 35c9f0dc2f fix(animations): process shorthand `margin` and `padding` styles correctly (#35701)
Prior to this patch, the `margin` and `padding` properties were not
detected properly by Firefox due to them being shorthand properties.
This patch ensures that both `margin` and `padding` are converted
read as `top right bottom left` in the event that the shorthand
property detection fails for auto-styling in Angular animations.

Fix #35463 (FW-1886)

PR Close #35701
2020-03-02 08:17:38 -08:00
Alan Agius d7efc45c04 perf(ngcc): only create tasks for non-processed formats (#35719)
Change the behaviour in `analyzeEntryPoints` to only create tasks for non-processed formats.

PR Close #35719
2020-03-02 08:17:02 -08:00
Alan Agius dc40a93317 perf(ngcc): spawn workers lazily (#35719)
With this change we spawn workers lazily based on the amount of work that needs to be done.

Before this change we spawned the maximum of workers possible. However, in some cases there are less tasks than the max number of workers which resulted in created unnecessary workers

Reference: #35717

PR Close #35719
2020-03-02 08:17:02 -08:00
Paul Gschwendtner 5c2a90814b fix(bazel): ng_package rule creates incorrect UMD module exports (#35792)
The `ng_package` rule currently creates incorrect UMD module exports
if an entry-point has a module name with numbers included.

For example, consider an entry-point called `@angular/cdk/a11y`. The UMD
module name should be `ng.cdk.a11y`. Instead, `ng_package` currently generates
an UMD module export called `ng.cdk.a11Y`.

This is because the logic for converting dash-case to camel case is
invalid as it uses Starlark's `title()` method. The title method
converts text to title case while we actually just want to capitalize
the first letter of a dash-case segment.

Fixes angular/components#18652.

PR Close #35792
2020-03-02 08:15:01 -08:00
Paul Gschwendtner d4fa9744e4 test: add entry-point with numbers in name to ng_package test (#35792)
Adds a new entry-point to the `@angular/bazel` `ng_package` test that
contains numbers in the name. e.g. `example/a11y`. This test is added
to replicate a bug where the UMD module export for such entry-points
is incorrectly generated. i.e. `example.a11Y` is generated instead of
`example.a11y`.

PR Close #35792
2020-03-02 08:15:01 -08:00
Andrew Kushnir 5bc39f8c8d perf(core): use multiple directives in host bindings micro benchmark (#35736)
This commit updates the host bindings micro benchmark to run tests with mutliple directives (where each directive contains host bindings). The number of directives is configurable as a constant in the micro benchmark file. This change is needed to have an ability to measure/compare perf in different scenarios.

PR Close #35736
2020-02-28 12:26:43 -08:00
Andrew Kushnir ef75875ca3 fix(core): handle `<ng-template>` with local refs in i18n blocks (#35758)
This commit extends the range of tNode types that may have local refs to include `TNodeType.Container` to account for `<ng-template>`s. Original changes in https://github.com/angular/angular/pull/33415 didn't include that type and as a result, an error is thrown at runtime in case an i18n block contains an `<ng-template>` with local refs.

PR Close #35758
2020-02-28 12:25:11 -08:00
Misko Hevery 40035380e7 fix(core): Remove `debugger` statement when assert is thrown (#35763)
Fix #35470
Fix FW-1925

PR Close #35763
2020-02-28 12:23:50 -08:00
Miško Hevery 8f38eb7acb fix(core): Remove `debugger` statement (#35763)
Fix #35470

PR Close #35763
2020-02-28 12:23:50 -08:00
JoostK 40039d8068 fix(ivy): narrow `NgIf` context variables in template type checker (#35125)
When the `NgIf` directive is used in a template, its context variables
can be used to capture the bound value. This is typically used together
with a pipe or function call, where the resulting value is captured in a
context variable. There's two syntax forms available:

1. Binding to `NgIfContext.ngIf` using the `as` syntax:
```html
<span *ngIf="(user$ | async) as user">{{user.name}}</span>
```

2. Binding to `NgIfContext.$implicit` using the `let` syntax:
```html
<span *ngIf="user$ | async; let user">{{user.name}}</span>
```

Because of the semantics of `ngIf`, it is known that the captured
context variable is non-nullable, however the template type checker
would not consider them as such and still report errors when
`strictNullTypes` is enabled.

This commit updates `NgIf`'s context guard to make the types of the
context variables non-nullable, avoiding the issue.

Fixes #34572

PR Close #35125
2020-02-28 07:39:57 -08:00
Keen Yee Liau 208ef7bd62 refactor(compiler): Remove NullAstVisitor and visitAstChildren (#35619)
This commit removes the `NullAstVisitor` and `visitAstChildren` exported
from `packages/compiler/src/expression_parser/ast.ts` because they
contain duplicate and buggy implementation, and their use cases could be
sufficiently covered by `RecursiveAstVisitor` if the latter implements the
`visit` method. This use case is only needed in the language service.

With this change, any visitor that extends `RecursiveAstVisitor` could
just define their own `visit` function and the parent class will behave
correctly.

A bit of historical context:
In language service, we need a way to tranverse the expression AST in a
selective manner based on where the user's cursor is. This means we need a
"filtering" function to decide which node to visit and which node to not
visit. Instead of refactoring `RecursiveAstVisitor` to support this,
`visitAstChildren` was created. `visitAstChildren` duplicates the
implementation of `RecursiveAstVisitor`, but introduced some bugs along
the way. For example, in `visitKeyedWrite`, it visits
```
obj -> key -> obj
```
instead of
```
obj -> key -> value
```

Moreover, because of the following line
```
visitor.visit && visitor.visit(ast, context) || ast.visit(visitor, context);
```
`visitAstChildren` visits every node *twice*.

PR Close #35619
2020-02-28 07:13:17 -08:00
ayazhafiz 73ee57a6e3 test(language-service): differentiate feature and internal infra tests (#35688)
This commit differentiates language service feature and language service
infrastructure tests. This is primarily to make testing of different
components at the development level easier. This commit continues a
small effort to expand our test coverage and normalize testing
structure.

Also adds test coverage to language service tests. We have quite a bit
to go on that front 🙂.

PR Close #35688
2020-02-28 07:10:46 -08:00
Pete Bacon Darwin a55f7aeff0 build: enable IDE type checking of $localize code (#35711)
The `packages/localize/src/tools` folder was excluded
from the top level `tsconfig.json` which meant that in IDEs
these source files were not being given the correct configuration.
It was originally excluded because it required the native `node` typings
but this is no longer a requirement.

Removing this folder from the exclusion list exposed a new issue
where there was a typings mismatch between `@babel/...` sources
and the associated `@types/babel__...` typings packages.

A clean up of the package.json and yarn.lock appears to fix this.

PR Close #35711
2020-02-28 07:09:50 -08:00
JoostK 3e3a1ef30d fix(ivy): support dynamic query tokens in AOT mode (#35307)
For view and content queries, the Ivy compiler attempts to statically
evaluate the predicate token so that string predicates containing
comma-separated reference names can be split into an array of strings
during compilation. When the predicate is a dynamic value that cannot be
statically interpreted at compile time, the compiler would previously
produce an error. This behavior breaks a use-case where an `InjectionToken`
is being used as query predicate, as the usage of the `new` keyword
prevents such predicates from being statically evaluated.

This commit changes the behavior to no longer produce an error for
dynamic values. Instead, the expression is emitted as is into the
generated code, postponing the evaluation to happen at runtime.

Fixes #34267
Resolves FW-1828

PR Close #35307
2020-02-27 16:05:21 -08:00
JiaLiPassion 03d88c7965 feat: define all zone.js configurations to typescript interfaces (#35329)
PR Close #35329
2020-02-27 14:08:01 -08:00
Andrew Kushnir 7b13977c3a fix(core): use proper configuration to compile Injectable in JIT (#35706)
Prior to this change, the logic that compiles Injectable in JIT mode used incorrect configuration that triggers a problem when `ChangeDetectorRef` is used as a dependency. This commit updates the logic to generate correct inject instruction to add the `ChangeDetectorRef` dependency in case it's requested in @Injectable class.

PR Close #35706
2020-02-27 14:01:15 -08:00
Andrew Kushnir 8fed1fe792 perf(core): adding micro benchmark for host bindings (#35705)
This commit adds micro benchmark for host bindings, so that we can assess the impact of changes related to host bindings (for example PR #35568).

PR Close #35705
2020-02-27 13:59:56 -08:00
Pete Bacon Darwin 5d8f7da3aa refactor(ngcc): guard against a crash if source-map flattening fails (#35718)
Source-maps in the wild could be badly formatted,
causing the source-map flattening processing to fail
unexpectedly. Rather than causing the whole of ngcc
to crash, we gracefully fallback to just returning the
generated source-map instead.

PR Close #35718
2020-02-27 16:09:37 -05:00
Pete Bacon Darwin 73cf7d5cb4 fix(ngcc): handle mappings outside the content when flattening source-maps (#35718)
Previously when rendering flattened source-maps, it was assumed that no
mapping would come from a line that is outside the lines of the actual
source content. It turns out this is not a valid assumption.

Now the code that renders flattened source-maps will handle such
mappings, with the additional benefit that the rendered source-map
will only contain mapping lines up to the last mapping, rather than a
mapping line for every content line.

Fixes #35709

PR Close #35718
2020-02-27 16:09:36 -05:00
Pete Bacon Darwin 72c4fda613 fix(ngcc): handle missing sources when flattening source-maps (#35718)
If a package has a source-map but it does not provide
the actual content of the sources, then the source-map
flattening was crashing.

Now we ignore such mappings that have no source
since we are not able to compute the merged
mapping if there is no source file.

Fixes #35709

PR Close #35718
2020-02-27 16:09:36 -05:00
Pete Bacon Darwin 20b0c80b0b fix(ngcc): allow deep-import warnings to be ignored (#35683)
This commit adds a new ngcc configuration, `ignorableDeepImportMatchers`
for packages. This is a list of regular expressions matching deep imports
that can be safely ignored from that package. Deep imports that are not
ignored cause a warning to be logged.

// FW-1892

Fixes #35615

PR Close #35683
2020-02-27 10:48:48 -08:00
crisbeto 0bc35a71e2 fix(ivy): injecting incorrect provider when re-providing injectable with useClass (#34574)
If an injectable has a `useClass`, Ivy injects the token in `useClass`, rather than the original injectable, if the injectable is re-provided under a different token. The correct behavior is that it should inject the re-provided token, no matter whether it has `useClass`.

Fixes #34110.

PR Close #34574
2020-02-26 13:00:21 -08:00
Joey Perrott ec789b0198 fix(animations): Remove ɵAnimationDriver from private exports (#35690)
ɵAnimationDriver can be safely removed from private exports as AnimationDriver
is already a public export.  Since its already available, we can safely remove
its declaration and migrate its only usage in our repo to rely on the public
AnimationDriver symbol.

PR Close #35690
2020-02-26 12:59:30 -08:00
Alan Agius 59c0689ade refactor(ngcc): remove redundant await (#35686)
Inside an async function, return await is not needed. Since the return value of an async function is always wrapped in Promise.resolve,
PR Close #35686
2020-02-26 12:59:13 -08:00
Alex Rickabaugh 8f5b7f367c feat(bazel): enable ivy template type-checking in g3 (#35672)
Template type-checking within the Ivy compiler has been disabled internally
in g3 until compatibility with the whole codebase could be verified. As that
verification is now complete and template type-checking is known to be
compatible with g3, this commit enables it.

PR Close #35672
2020-02-26 12:58:55 -08:00
Ayaz Hafiz 500e49f0ac refactor(language-service): normalize hover tests (#35656)
This commit normalizes hover and util tests in the language service.
This is part of a small effort to simplify and normalize the language
service testing structure, which currently contains specs that are
largely created and left without relation to other tests.

PR Close #35656
2020-02-26 12:57:49 -08:00
Alex Rickabaugh 173a1ac8e4 fix(ivy): better inference for circularly referenced directive types (#35622)
It's possible to pass a directive as an input to itself. Consider:

```html
<some-cmp #ref [value]="ref">
```

Since the template type-checker attempts to infer a type for `<some-cmp>`
using the values of its inputs, this creates a circular reference where the
type of the `value` input is used in its own inference:

```typescript
var _t0 = SomeCmp.ngTypeCtor({value: _t0});
```

Obviously, this doesn't work. To resolve this, the template type-checker
used to generate a `null!` expression when a reference would otherwise be
circular:

```typescript
var _t0 = SomeCmp.ngTypeCtor({value: null!});
```

This effectively asks TypeScript to infer a value for this context, and
works well to resolve this simple cycle. However, if the template
instead tries to use the circular value in a larger expression:

```html
<some-cmp #ref [value]="ref.prop">
```

The checker would generate:

```typescript
var _t0 = SomeCmp.ngTypeCtor({value: (null!).prop});
```

In this case, TypeScript can't figure out any way `null!` could have a
`prop` key, and so it infers `never` as the type. `(never).prop` is thus a
type error.

This commit implements a better fallback pattern for circular references to
directive types like this. Instead of generating a `null!` in place for the
reference, a type is inferred by calling the type constructor again with
`null!` as its input. This infers the widest possible type for the directive
which is then used to break the cycle:

```typescript
var _t0 = SomeCmp.ngTypeCtor(null!);
var _t1 = SomeCmp.ngTypeCtor({value: _t0.prop});
```

This has the desired effect of validating that `.prop` is legal for the
directive type (the type of `#ref`) while also avoiding a cycle.

Fixes #35372
Fixes #35603
Fixes #35522

PR Close #35622
2020-02-26 12:57:08 -08:00
Alex Rickabaugh 2d89b5d13d fix(ivy): provide a more detailed error message for NG6002/NG6003 (#35620)
NG6002/NG6003 are errors produced when an NgModule being compiled has an
imported or exported type which does not have the proper metadata (that is,
it doesn't appear to be an @NgModule, or @Directive, etc. depending on
context).

Previously this error message was a bit sparse. However, Github issues show
that this is the most common error users receive when for whatever reason
ngcc wasn't able to handle one of their libraries, or they just didn't run
it. So this commit changes the error message to offer a bit more useful
context, instructing users differently depending on whether the class in
question is from their own project, from NPM, or from a monorepo-style local
dependency.

PR Close #35620
2020-02-26 12:56:47 -08:00
Misko Hevery 3af103aa61 fix(core): support sanitizer value in the [style] bindings (#35564)
When binding to `[style]` we correctly sanitized/unwrapped properties but we did not do it for the object itself.

```
@HostBinding("style")
style: SafeStyle = this.sanitizer.bypassSecurityTrustStyle(
    "background: red; color: white; display: block;"
  );
```

Above code would fail since the `[style]` would not unwrap the `SafeValue` and would treat it as object resulting in incorrect behavior.

Fix #35476 (FW-1875)

PR Close #35564
2020-02-26 12:56:09 -08:00
JiaLiPassion 4acb676f2e feat: add interface definitions which zone extends EventTarget (#35304)
Close #35173

PR Close #35304
2020-02-26 12:52:08 -08:00
Pete Bacon Darwin df816c9c80 feat(ngcc): implement source-map flattening (#35132)
The library used by ngcc to update the source files (MagicString) is able
to generate a source-map but it is not able to account for any previous
source-map that the input text is already associated with.

There have been various attempts to fix this but none have been very
successful, since it is not a trivial problem to solve.

This commit contains a novel approach that is able to load up a tree of
source-files connected by source-maps and flatten them down into a single
source-map that maps directly from the final generated file to the original
sources referenced by the intermediate source-maps.

PR Close #35132
2020-02-26 12:51:35 -08:00
KostyaTretyak 2a8dd4758c test(core): check dependency in extended child (#34767)
Related to https://github.com/angular/angular/issues/31337

PR Close #34767
2020-02-26 12:50:52 -08:00
Lars Gyrup Brink Nielsen d41988437e docs(common): update ngForTrackBy error URL (#34761)
Old URL is redirected to
`https://angular.io/api/common/NgForOf#!#change-propagation`
which is not exactly
`https://angular.io/api/common/NgForOf#change-propagation`

PR Close #34761
2020-02-26 12:47:48 -08:00
Zac a7ed74f573 docs(core): correct insertBefore's description (#34547)
Update the description of `refChild`
Based on https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
PR Close #34547
2020-02-26 12:46:10 -08:00
Zac 8fbb966ca7 docs(core): describe your change... (#34513)
According to https://angular.io/guide/lifecycle-hooks#ondestroy
"Put cleanup logic in ngOnDestroy(), the logic that must run before Angular destroys the directive."
PR Close #34513
2020-02-26 12:45:41 -08:00
crisbeto 835618c678 fix(ivy): error when accessing NgModuleRef.componentFactoryResolver in constructor (#35637)
Currently we resolve the `NgModuleRef.componentFactoryResolver` by going through the injector, but the problem is that `ComponentFactoryResolver` has a dependency on `NgModuleRef`, which means that if the module that's attached to the ref tries to inject  `ComponentFactoryResolver` in its constructor, we'll create a circular dependency which throws at runtime.

These changes resolve the issue by creating the `ComponentFactoryResolver` manually ahead of time without going through the injector. We can do this safely, because the only dependency for the resolver is the current module ref which is providing it.

Aside from fixing the issue, another advantage to this approach is that it should reduce the amount of generated JS, because it removes a getter and a provider definitio.

Fixes #35580.

PR Close #35637
2020-02-25 13:19:13 -08:00
Felix Becker 1e20b2ca36 build(packaging): add repository.directory field to package.jsons (#27544)
PR Close #27544
2020-02-25 13:12:45 -08:00
Rado Kirov 294e56d529 refactor(platform-browser): Hoist functions to workaround optimization bug. (#32230)
Technically, function definitions can live anywhere because they are
hoisted. However, in this case Closure optimizations break when exported
function definitions are referred in another static object that is
exported.

The bad pattern is:
```
exports const obj = {f};
export function f() {...}
```

which turns to the following in Closure's module system:
```
goog.module('m');

exports.obj = {f};

function f() {...}
exports.f = f;
```

which badly optimizes to (note module objects are collapsed)
```
var b = a; var a = function() {...};  // now b is undefined.
```

This is an optimizer bug and should be fixed in Closure, but in the
meantime this change is a noop and will unblock other changes we want to
make.

PR Close #32230
2020-02-25 13:12:27 -08:00