Commit Graph

1467 Commits

Author SHA1 Message Date
Ben Lesh b71cd7b4ee refactor(ivy): fix formatting issue with `select` comment (#29576)
PR Close #29576
2019-04-10 16:32:22 -07:00
Ben Lesh 147a15a419 refactor(ivy): move property instruction (#29576)
- moves the property instruction to its own file
- moves shared functions that should not be public to the existing `shared.ts` file.
- adds the export of `property.ts` to `all.ts`

PR Close #29576
2019-04-10 16:32:22 -07:00
Matias Niemelä 675f3909d7 perf(ivy): do not use spread operations in styling (#29795)
While investigating styling performance regressions, it was discovered
that a single `fn(...args)` operation was causing a performance hit
because the generated es5 `__spread` operation uses `[].concat` and
reads from the `arguments` values (which are not very efficient). This
patch changes that around to use `fn.apply` instead.

PR Close #29795
2019-04-10 12:17:18 -07:00
Paul Gschwendtner 39bfd1a11f refactor(core): run migration schematics for v8 beta and rc releases (#29735)
Currently the `static-query` and `template-var-assignment` schematic only runs
for `8.0.0` which does not include any betas or release candidates. We want to
run the schematic in the beta's and RC in order to get early feedback about the
schematics. Enabling it promptly with V8 stable release can result in accidental
breakages that we would like to fix/identify before.

PR Close #29735
2019-04-10 12:15:25 -07:00
Paul Gschwendtner 4e8c2c3422 refactor(core): static-query schematic should handle abstract classes (#29688)
Queries can not only be accessed within derived classes, but also in
the super class through abstract methods. e.g.

```
abstract class BaseClass {

  abstract getEmbeddedForm(): NgForm {}

  ngOnInit() {
     this.getEmbeddedForm().doSomething();
  }
}

class Subclass extends BaseClass {
  @ViewChild(NgForm) form: NgForm;

  getEmbeddedForm() { return this.form; }

}
```

Same applies for abstract properties which are implemented in the base class
through accessors. This case is also now handled by the schematic.

Resolves FW-1213

PR Close #29688
2019-04-10 12:15:05 -07:00
Ben Lesh 138ca5a246 refactor(ivy): prefix all generated instructions (#29692)
- Updates all instructions to be prefixed with the Greek delta symbol

PR Close #29692
2019-04-10 12:11:40 -07:00
Paul Gschwendtner 1102b02406 refactor(core): static-query schematic should handle function callbacks (#29663)
Currently the static-query schematic is not able to properly handle
call expressions that pass function declarations that access a given
query. e.g.

```ts
ngOnInit() {
  this._callFunction(() => this.myQuery.doSomething());
}

_callFunction(cb: any) { cb(); }
```

In that case the passed function is executed synchronously in
the "ngOnInit" lifecycle and therefore the query needs to be
detected as "static".

We can fix this by keeping track of the current function context
and using it to resolve identifiers to the passed arguments.

PR Close #29663
2019-04-08 17:21:24 -07:00
Paul Gschwendtner 00bf636afa refactor(core): static-query schematic should handle binary expressions (#29663)
Currently we only check getters for property access expressions. This is wrong
because property access expressions do not always cause the "getter" to be
triggered. e.g.

```ts
set a() {...}
get a() {...}

ngOnInit() {
  this.a = true;
}
```

In that case the schematic currently incorrectly checks the "getter", while this is a binary
expression and the property access is used as left-side of the binary expression. In that
case we need to check the setter declaration of the property and not the "getter". In order
to fix this, we need to also check `ts.BinaryExpression` nodes and check getters/setters
based on the used operator token. There are three types of binary expressions:

1) Value assignment (using `=`). In that case only the setter is triggered.
2) Compound assignment (e.g. using `+=`). In that case `getter` and `setter` are triggered.
3) Comparison (e.g. using `===`). In that case only the getter is triggered.

PR Close #29663
2019-04-08 17:21:24 -07:00
Brandon 82c77ce232 docs(core): update API doc examples to use static injector (#29729)
PR Close #29729
2019-04-08 17:20:34 -07:00
Matias Niemelä 84be7c52dc refactor(ivy): rename `styling_instructions` to `styling` (#29770)
PR Close #29770
2019-04-08 12:04:25 -07:00
Kristiyan Kostadinov 98cf3e8fcd fix(ivy): creation mode not run on view detached from change detection (#29741)
Fixes the creation mode block not being run on components which have been detached from change detection.

This PR resolves FW-1217.
Fixes #29645.

PR Close #29741
2019-04-08 12:04:09 -07:00
Kristiyan Kostadinov d144a3bd91 fix(ivy): not throwing error for unknown properties on container nodes (#29691)
Fixes Ivy not throwing an error if it runs into an invalid property binding on a container node (e.g. `<div *ngFor="let row of rows">` instead of `<div *ngFor="let row if rows">`).

This PR resolves FW-1219.

PR Close #29691
2019-04-08 12:03:34 -07:00
Matias Niemelä 66b87cef33 fix(ivy): add dev mode counter information to styling (#29579)
In order to optimize performance for styling-related operations in
Angular, debug counters need to be introduced. This patch adds various
counters to ngDevMode which are fired each time a styling-related
binding is updated.

PR Close #29579
2019-04-08 12:03:21 -07:00
Pawel Kozlowski 38a3a5a1f1 refactor(ivy): remove unused code related to listeners clanup (#29725)
PR Close #29725
2019-04-08 09:47:55 -07:00
Paul Gschwendtner 6d35c5094a test(core): add test for template variable object property assignment (#29708)
The `template-var-assignment` schematic currently complains if someone
assigns a value to a template variable. This will no longer work with Ivy, but
it should be totally fine to update a property of the template variable if it refers
to an object. This commit adds a test that ensures that we don't incorrectly report
any failure for such property writes in bound events.

PR Close #29708
2019-04-08 09:46:57 -07:00
Paul Gschwendtner 4a2fb86b1e refactor(core): polish failure messages for template-var-assignment schematic (#29708)
Improves the failure messages for the `template-var-assignment` schematic. After manual
testing of the schematic it's not quite clear for developers what the failure message means
without any context. The schematic now also references a short markdown file mentioning
what needs to be changed, but eventually this document needs to be expanded with more
information and context of the reasoning behind this change within Ivy.

PR Close #29708
2019-04-08 09:46:57 -07:00
Matias Niemelä ec56354306 fix(ivy): ensure parent/sub-class components evaluate styling correctly (#29602)
The new styling algorithm in angular is designed to evaluate host
bindings stylinh priority in order of directive evaluation order. This,
however, does not work with respect to parent/sub-class directives
because sub-class host bindings are run after the parent host bindings
but still have priority. This patch ensures that the host styling bindings
for parent and sub-class components/directives are executed with respect
to the styling algorithm prioritization.

Jira Issue: FW-1132

PR Close #29602
2019-04-05 16:49:52 -07:00
JoostK 5c13feebfd test(ivy): verify ngOnDestroy is called for tree-shakeable providers (#28943)
This test verifies that Ivy's module injector does not suffer from
#28927 to prevent regressing on this behavior going forward.

PR Close #28943
2019-04-05 09:40:00 -07:00
JoostK 30b04424a3 fix(core): call ngOnDestroy for tree-shakeable providers (#28943)
Prior to this change, any provider that was independently resolved using
its InjectableDef would not be considered when destroying the module it
was requested from. This commit provides a fix for this issue by storing
the resolved provider in the module's list of provider definitions.

Fixes #28927

PR Close #28943
2019-04-05 09:40:00 -07:00
Carlos Ortiz García 609024f93d fix(core): Deprecate TestBed.get(...):any (#29290)
Adds an overload to TestBed.get making parameters strongly typed and
deprecated previous signature that accepted types `any`. The function
still returns `any` to prevent build breakages, but eventually stronger
type checks will be added so a future Angular version will break builds
due to additional type checks.
See previous breaking change - #13785

Issue #26491

PR Close #29290
2019-04-04 15:32:23 -07:00
Filipe Silva 96b76dc3f1 fix(core): add missing migration to npm package (#29705)
While running `ng update @angular/core --next`, the following error would be displayed:

```
Cannot find module '....\node_modules\@angular\core\schematics\migrations\template-var-assignment\index'
```

This happened because the Schematics migration was referenced, but not included.

This commit fixes that bug by including the migration in the Bazel npm package dependencies.

PR Close #29705
2019-04-04 10:51:19 -07:00
Ben Lesh 699ecac2c2 refactor(ivy): Add i18n create op codes debug info (#29348)
Simply adds a `debug` property to the array of create opcodes while inside
`readCreateOpCodes` in i18n. This `debug` property has a property called `operations`
that is a human-readable list of operations that will be performed, as derived
from the op codes themselves, and the view it's acting upon.

PR Close #29348
2019-04-03 15:54:42 -07:00
Carlos Ortiz García afd4a4ed4d feat(core): Add "AbstractType<T>" interface (#29295)
This new interface will match classes whether they are abstract or
concrete. Casting as `AbstractType<MyConcrete>` will return a type that
isn't newable. This type will be used to match abstract classes in the
`get()` functions of `Injector` and `TestBed`.
Type isn't used yet so this isn't a breaking change.

Issue #26491

PR Close #29295
2019-04-02 16:07:22 -07:00
JoostK 45c6360e5a feat(ivy): emit module scope metadata using pure function call (#29598)
Prior to this change, all module metadata would be included in the
`defineNgModule` call that is set as the `ngModuleDef` field of module
types. Part of the metadata is scope information like declarations,
imports and exports that is used for computing the transitive module
scope in JIT environments, preventing those references from being
tree-shaken for production builds.

This change moves the metadata for scope computations to a pure function
call that patches the scope references onto the module type. Because the
function is marked pure, it may be tree-shaken out during production builds
such that references to declarations and exports are dropped, which in turn
allows for tree-shaken any declaration that is not otherwise referenced.

Fixes #28077, FW-1035

PR Close #29598
2019-04-02 16:03:54 -07:00
Paul Gschwendtner 7c8f4e3202 feat(core): template-var-assignment update schematic (#29608)
Introduces a new update schematic called "template-var-assignment"
that is responsible for analyzing template files in order to warn
developers if template variables are assigned to values.

The schematic also comes with a driver for `tslint` so that the
check can be used wtihin Google.

PR Close #29608
2019-04-02 15:47:32 -07:00
Paul Gschwendtner 15eb1e0ce1 refactor(core): stronger type for resolved angular decorators (#29608)
PR Close #29608
2019-04-02 15:47:32 -07:00
Paul Gschwendtner 780081def0 refactor(core): move schematic typescript logic to utility package (#29608)
PR Close #29608
2019-04-02 15:47:32 -07:00
Ben Lesh 5a724b34bd refactor(ivy): move instructions (#29646)
- moves all publicly exported instructions to their own files
- refactors namespace instructions to set state in `state.ts`
- no longer exports * from `instructions.ts`.
- `instructions.ts` renamed to `shared.ts` (old `shared.ts` contents folded in to `instructions.ts`)
- updates `all.ts` to re-export from public instruction files.

PR Close #29646
2019-04-02 15:47:02 -07:00
Ben Lesh 1293da1cf7 refactor(core): update docs (#29600)
PR Close #29600
2019-04-02 10:28:23 -07:00
Paul Gschwendtner 33016b8929 fix(core): static-query schematic should detect static queries in getters. (#29609)
Queries can also be statically accessed within getters. e.g.

```ts
ngOnInit() {
  this.myQueryGetter.doSomething();
}
```

In that case we need to check if the `myQueryGetter` definition accesses
a query statically. As we need to use the type checker for every property acess
within lifecylce hooks, the schematic might become slower than before, but considering
that this is a one-time execution, it is totally fine using the type-checker extensively.

PR Close #29609
2019-04-01 10:58:51 -07:00
Jon Grunewald c67f6a7e60 docs: fix typo in renderer description (#29581)
PR Close #29581
2019-03-29 10:50:35 -07:00
Marc Laval d4c4a89431 fix(ivy): host attributes and @COmponentChild should be supported on the same component (#29565)
PR Close #29565
2019-03-29 10:49:35 -07:00
Marc Laval 303eae918d fix(ivy): querying should be possible on any debug element (#29534)
PR Close #29534
2019-03-29 10:32:57 -07:00
Marc Laval 50f7ab2a06 fix(ivy): debug element should support components with ViewContainerRef (#29534)
PR Close #29534
2019-03-29 10:32:57 -07:00
Judy Bogart 333bfa0ffb docs: api doc for i18n (#29289)
PR Close #29289
2019-03-29 10:27:42 -07:00
Kara 632669f069 refactor: update tsickle comment to be more precise (#29513)
Co-Authored-By: benlesh <ben@benlesh.com>
PR Close #29513
2019-03-28 15:22:37 -07:00
Ben Lesh 33963ca0d3 feat(ivy): add property instruction (#29513)
- Adds `property` instruction
- Does _NOT_ add compiler changes to accommodate `property` instruction, that will be a follow up PR.
- Updates `select` instruction to set the selected index in state.
- Adds dev mode assertions around the selected index state.

Related #29527

PR Close #29513
2019-03-28 15:22:37 -07:00
Alex Rickabaugh 7b27009e20 fix(ivy): fix proliferation of provider overrides for modules (#29571)
When an @NgModule is imported more than once in the testing module (for
example it appears in the imports of more than one module, or if it's
literally listed multiple times), then TestBed had a bug where the
providers for the module would be overridden many times.

This alone was problematic but would not break tests. However, the original
value of the providers field of the ngInjectorDef was saved each time, and
restored in the same order. Thus, if the provider array was [X], and
overrides were applied twice, then the override array would become
[X, X'] and then [X, X', X, X']. However, on the second override the state
[X, X'] would be stored as original. The array would then be restored to
[X] and then [X, X'].

Each test, therefore, would continue to double the size of the providers
array for the module, eventually exhausting the browser's memory.

This commit adds a Set to track when overrides have been applied to a module
and refrain from applying them more than once.

PR Close #29571
2019-03-28 13:59:25 -07:00
Andrew Kushnir 71ec99856a fix(ivy): allow TestBed to recompile AOT-compiled components in case of template overrides (#29555)
Prior to this change, recompilation of AOT-compiled components in TestBed may fail when template override is requested. That was happening due to the `styleUrls` field defined for a Component, thus switching its state to "requires resolution" (i.e. having external resources) at compile time. This change avoids this issue by storing styles and resetting `styleUrls` field before recompilation. Once compilation is done, saved styles are patched back onto Component def.

PR Close #29555
2019-03-28 10:11:41 -07:00
Miško Hevery 931d356a10 Revert "feat(ivy): add property instruction (#29513)"
This reverts commit e4c1c88cbc.
2019-03-27 16:11:04 -07:00
Ben Lesh e4c1c88cbc feat(ivy): add property instruction (#29513)
- Adds `property` instruction
- Does _NOT_ add compiler changes to accommodate `property` instruction, that will be a follow up PR.
- Updates `select` instruction to set the selected index in state.
- Adds dev mode assertions around the selected index state.

Related #29527

PR Close #29513
2019-03-27 13:49:01 -07:00
Pawel Kozlowski 1727fe24fb refactor(ivy): name anonymous wrapper function (#29543)
This simple change helps with debugging / perf investigations
as we can see function names on a call stack.

PR Close #29543
2019-03-27 12:37:33 -07:00
Pawel Kozlowski 4eb6b02f08 refactor(ivy): remove forEach usage in ApplicationRef.tick (#29543)
forEach is slower as compared to a regular loop but more importantly
this change removes an anonymous function and thus makes stack traces
shorter and easier to read (important for perf analysis).

PR Close #29543
2019-03-27 12:37:33 -07:00
Pawel Kozlowski dd69e4e780 refactor(ivy): remove duplicated flatten util (#29547)
This commit removes code duplication where we had 2 versions of a
`flatten` utility. Moreover this change results in queries using
a non-recursive version of `flatten` which should result in a better
performance of query refresh operations.

PR Close #29547
2019-03-27 12:36:23 -07:00
Andrew Kushnir 309ffe7e16 fix(ivy): TestBed rewrite to avoid unnecessary recompilations (#29483)
Prior to this change, Ivy version of TestBed was not designed to support the logic to avoid recompilations - most of the Components/Directives/Pipes were recompiled for each test, even if there were no overrides defined for a given Type. Additional checks to avoid recompilation were introduced in one of the previous commits (0244a2433e), but there were still some corner cases that required attention. In order to support the necessary logic better, Ivy TestBed was rewritten/refactored. Main results of this rewrite are:

* no recompilation for Components/Directives/Pipes without overrides
* the logic to restore state between tests (isolate tests) was improved
* transitive scopes calculation no longer performs recompilation (it works with compiled defs)

As a result of these changes we see reduction in memory consumption (3.5-4x improvement) and pefromance increase (4-4.5x improvement).

PR Close #29483
2019-03-27 09:41:58 -07:00
Ben Lesh a2f8f5595f refactor(ivy): rename flushHooksUpTo to select (#29527)
PR Close #29527
2019-03-27 09:35:55 -07:00
JiaLiPassion 17f7bdbd60 build: update zone.js to 0.9.0 (#28219)
The API changes are due to enabling strict checks in TypeScript (via `strict: true`).
The payload size changes in `polyfills.js` are due to more browser APIs being patched in recent versions (e.g. `fetch`, `customElement v1`).

PR Close #28219
2019-03-26 12:50:38 -07:00
Marc Laval c412374854 fix(ivy): DebugNode.query should query nodes in the logical tree (#29480)
PR Close #29480
2019-03-26 12:48:37 -07:00
Kara Erickson 9724247ad8 fix(ivy): generate empty QueryList for root component content queries (#29514)
In View Engine, we used to generate empty QueryLists for content queries on root
components (though we did not actually support populating these lists). We need
to keep this behavior in Ivy for backwards compatibility. Otherwise, components
that are sometimes used as root will fail if they are relying on content query
results to always be defined.

PR Close #29514
2019-03-26 12:45:21 -07:00
Kristiyan Kostadinov 568140fb03 fix(ivy): include className in DebugNode.properties (#29488)
Fixes the node's class bindings not being included under `DebugNode.properties.className` like in ViewEngine.

This PR resolves FW-1196.

PR Close #29488
2019-03-26 12:44:51 -07:00