Commit Graph

1592 Commits

Author SHA1 Message Date
Misko Hevery a1d7b6bb86 test(ivy): fined tune micro benchmark parameters (#33341)
Decrease `MIN_SAMPLE_DURATION` to make it more likely that we cane fit into single time slice.
Increase `MIN_SAMPLE_COUNT_NO_IMPROVEMENT` to make it more likely to find the best

PR Close #33341
2019-10-23 16:40:51 -07:00
Misko Hevery d40ee6a259 perf(ivy): improve styling performance (#33326)
change the existing implementation from using

```
string.split(/\s+/);
```

to a char scan which performers the same thing.

The reason why `split(/\s+/)` is slow is that:
- `/\s+/` allocates new `RegExp` every time this code executes.
- `RegExp` scans are a lot more expensive because they are more powerful.

PR Close #33326
2019-10-23 16:40:12 -07:00
Miško Hevery bd89626e2e test(ivy): add instructions for deoptigate (#33357)
PR Close #33357
2019-10-23 09:56:42 -07:00
Miško Hevery 5632424d04 refactor(ivy): ViewRef needs embededViewRef declaration (#33074)
PR Close #33074
2019-10-22 12:00:21 -07:00
JoostK 6958d11d95 feat(ivy): type checking of event bindings (#33125)
Until now, the template type checker has not checked any of the event
bindings that could be present on an element, for example

```
<my-cmp
  (changed)="handleChange($event)"
  (click)="handleClick($event)"></my-cmp>
```

has two event bindings: the `change` event corresponding with an
`@Output()` on the `my-cmp` component and the `click` DOM event.

This commit adds functionality to the template type checker in order to
type check both kind of event bindings. This means that the correctness
of the bindings expressions, as well as the type of the `$event`
variable will now be taken into account during template type checking.

Resolves FW-1598

PR Close #33125
2019-10-18 14:41:53 -04:00
Igor Minar 86e1e6c082 feat: typescript 3.6 support (#32946)
BREAKING CHANGE: typescript 3.4 and 3.5 are no longer supported, please update to typescript 3.6

Fixes #32380

PR Close #32946
2019-10-18 13:15:16 -04:00
Matias Niemelä 7b64680670 fix(ivy): ensure map-based interpolation works with other map-based sources (#33236)
Prior to this fix if a map-based class or style binding wrote
its values onto an elemenent, the internal styling context would
not register the binding if the initial value as a `NO_CHANGE`
value. This situation occurs if a directive takes control of the
`class` or `style` input values and then returns a `NO_CHANGE` value
if the initial value is empty.

This patch ensures that all bindings are always registered with the
`TStylingContext` data-structure even if their initial value is
an instance of `NO_CHANGE`.

PR Close #33236
2019-10-17 18:24:10 -04:00
Matias Niemelä f45c43188f fix(ivy): ensure errors are thrown during checkNoChanges for style/class bindings (#33103)
Prior to this fix, all style/class bindings (e.g. `[style]` and
`[class.foo]`) would quietly update a binding value if and when the
current binding value changes during checkNoChanges.

With this patch, all styling instructions will properly check to see
if the value has changed during the second pass of detectChanges()
if checkNoChanges is active.

PR Close #33103
2019-10-17 16:46:49 -04:00
crisbeto 9d54679e66 test: clean up explicit dynamic query usages (#33015)
Cleans up all the places where we explicitly set `static: false` on queries.

PR Close #33015
2019-10-17 16:10:10 -04:00
Andrew Kushnir 7e64bbe5a8 fix(ivy): use container i18n meta if a message is a single ICU (#33191)
Prior to this commit, metadata defined on ICU container element was not inherited by the ICU if the whole message is a single ICU (for example: `<ng-container i18n="meaning|description@@id">{count, select, ...}</ng-container>). This commit updates the logic to use parent container i18n meta information for the cases when a message consists of a single ICU.

Fixes #33171

PR Close #33191
2019-10-17 16:07:07 -04:00
Miško Hevery bb53b6549c refactor(ivy): move all of the instruction state into a singe object (#33093)
Turns out that writing to global state is more expensive than writing to
a property on an object.

Slower:
````
let count = 0;

function increment() {
  count++;
}
```

Faster:
````
const state = {
  count: 0
};

function increment() {
  state.count++;
}
```

This change moves all of the instruction state into a single state object.

`noop_change_detection` benchmark
Pre refactoring: 16.7 us
Post refactoring: 14.523 us (-13.3%)

PR Close #33093
2019-10-17 16:00:55 -04:00
Andrew Kushnir 6f203c9575 fix(ivy): handling className as an input properly (#33188)
Prior to this commit, all `className` inputs were not set because the runtime code assumed that the `classMap` instruction is only generated for `[class]` bindings. However the `[className]` binding also produces the same `classMap`, thus the code needs to distinguish between `class` and `className`. This commit adds extra logic to select the right input name and also throws an error in case `[class]` and `[className]` bindings are used on the same element simultaneously.

PR Close #33188
2019-10-17 14:16:02 -04:00
Miško Hevery 4800fa1c08 refactor(core): tweek micro-benchmarks to make them more consistent (#33207)
```
┌────────────────────────────────────┬─────────┬──────┬───────────┬───────────┬───────┐
│              (index)               │  time   │ unit │ base_time │ base_unit │   %   │
├────────────────────────────────────┼─────────┼──────┼───────────┼───────────┼───────┤
│       directive_instantiate        │  2.474  │ 'us' │   2.507   │   'us'    │ -1.32 │
│        element_text_create         │  1.313  │ 'us' │   1.319   │   'us'    │ -0.45 │
│           interpolation            │ 220.17  │ 'us' │  224.217  │   'us'    │ -1.8  │
│             listeners              │  1.988  │ 'us' │   2.021   │   'us'    │ -1.63 │
│ map_based_style_and_class_bindings │ 17.908  │ 'ms' │  18.523   │   'ms'    │ -3.32 │
│       noop_change_detection        │ 24.851  │ 'us' │  24.874   │   'us'    │ -0.09 │
│          property_binding          │ 218.76  │ 'us' │  216.736  │   'us'    │ 0.93  │
│      property_binding_update       │ 443.175 │ 'us' │  447.686  │   'us'    │ -1.01 │
│      style_and_class_bindings      │  1.053  │ 'ms' │   1.069   │   'ms'    │ -1.5  │
│           style_binding            │ 488.154 │ 'us' │  484.092  │   'us'    │ 0.84  │
└────────────────────────────────────┴─────────┴──────┴───────────┴───────────┴───────┘
```

PR Close #33207
2019-10-17 14:13:16 -04:00
Matias Niemelä 082aed6e46 revert: feat: add a flag in bootstrap to enable coalesce event change detection to improve performance (#30533) (#33230)
This reverts commit 21c1e14385.

PR Close #33230
2019-10-17 12:50:04 -04:00
Matias Niemelä 724707c6e4 feat(ivy): improve debugging experience for styles/classes (#33179)
This patch introduces the `printTable()` and `printSources()`
methods to `DebugStylingContext` which can be used via the
`window.ng.getDebugNode` helpers when debugging an application.

PR Close #33179
2019-10-17 00:35:17 -04:00
Kara Erickson 86104b82b8 refactor(core): rename ngInjectableDef to ɵprov (#33151)
Injectable defs are not considered public API, so the property
that contains them should be prefixed with Angular's marker
for "private" ('ɵ') to discourage apps from relying on def
APIs directly.

This commit adds the prefix and shortens the name from
ngInjectableDef to "prov" (for "provider", since injector defs
are known as "inj"). This is because property names cannot
be minified by Uglify without turning on property mangling
(which most apps have turned off) and are thus size-sensitive.

PR Close #33151
2019-10-16 16:36:19 -04:00
Kara Erickson cda9248b33 refactor(core): rename ngInjectorDef to ɵinj (#33151)
Injector defs are not considered public API, so the property
that contains them should be prefixed with Angular's marker
for "private" ('ɵ') to discourage apps from relying on def
APIs directly.

This commit adds the prefix and shortens the name from
ngInjectorDef to inj. This is because property names
cannot be minified by Uglify without turning on property
mangling (which most apps have turned off) and are thus
size-sensitive.

PR Close #33151
2019-10-16 16:36:19 -04:00
JiaLiPassion 21c1e14385 feat: add a flag in bootstrap to enable coalesce event change detection to improve performance (#30533)
PR Close #30533
2019-10-16 14:38:36 -04:00
Miško Hevery d3f3d9b4cb test: Add script which allows running all of the profiling tests and compare results (#33186)
PR Close #33186
2019-10-16 10:22:30 -04:00
Andrew Kushnir 11e04b1892 fix(ivy): avoid DOM element assertions if procedural renderer is used (#33156)
Prior to this commit, Ivy runtime asserted that a given element is an instance of a DOM node. These asserts may not be correct in case custom renderer is used, which operates objects with a shape different than DOM nodes. This commit updates the code to avoid the mentioned checks in case procedural renderer is used.

PR Close #33156
2019-10-15 21:03:29 +00:00
Matias Niemelä 1cda80eb3a fix(ivy): ensure sanitizer is not used when direct class application occurs (#33154)
Prior to this patch, if a map-class binding is applied directly then
that value will be incorrectly provided a sanitizer even if there is no
sanitization present for an element.

PR Close #33154
2019-10-15 16:50:43 +00:00
Nikita Potapenko 72494c4411 refactor(core): replace instanceof Array (#33077)
PR Close #33077
2019-10-14 23:44:57 +00:00
Kara Erickson fc93dafab1 refactor(core): rename ngModuleDef to ɵmod (#33142)
Module defs are not considered public API, so the property
that contains them should be prefixed with Angular's marker
for "private" ('ɵ') to discourage apps from relying on def
APIs directly.

This commit adds the prefix and shortens the name from
ngModuleDef to mod. This is because property names
cannot be minified by Uglify without turning on property
mangling (which most apps have turned off) and are thus
size-sensitive.

PR Close #33142
2019-10-14 23:08:10 +00:00
Kara Erickson d62eff7316 refactor(core): rename ngPipeDef to ɵpipe (#33142)
Pipe defs are not considered public API, so the property
that contains them should be prefixed with Angular's marker
for "private" ('ɵ') to discourage apps from relying on def
APIs directly.

This commit adds the prefix and shortens the name from
ngPipeDef to pipe. This is because property names
cannot be minified by Uglify without turning on property
mangling (which most apps have turned off) and are thus
size-sensitive.

PR Close #33142
2019-10-14 23:08:10 +00:00
Kara Erickson 0de2a5e408 refactor(core): rename ngFactoryDef to ɵfac (#33116)
Factory defs are not considered public API, so the property
that contains them should be prefixed with Angular's marker
for "private" ('ɵ') to discourage apps from relying on def
APIs directly.

This commit adds the prefix and shortens the name from
ngFactoryDef to fac. This is because property names
cannot be minified by Uglify without turning on property
mangling (which most apps have turned off) and are thus
size-sensitive.

Note that the other "defs" (ngPipeDef, etc) will be
prefixed and shortened in follow-up PRs, in an attempt to
limit how large and conflict-y this change is.

PR Close #33116
2019-10-14 20:27:25 +00:00
Greg Magolan c3aaa5211e test: fix //packages/core/test/bundling/todo_i18n:test test deps (#33073)
PR Close #33073
2019-10-14 20:25:57 +00:00
Kara Erickson 1a67d70bf8 refactor(core): rename ngDirectiveDef to ɵdir (#33110)
Directive defs are not considered public API, so the property
that contains them should be prefixed with Angular's marker
for "private" ('ɵ') to discourage apps from relying on def
APIs directly.

This commit adds the prefix and shortens the name from
ngDirectiveDef to dir. This is because property names
cannot be minified by Uglify without turning on property
mangling (which most apps have turned off) and are thus
size-sensitive.

Note that the other "defs" (ngFactoryDef, etc) will be
prefixed and shortened in follow-up PRs, in an attempt to
limit how large and conflict-y this change is.

PR Close #33110
2019-10-14 16:20:11 +00:00
Kara Erickson 64fd0d6db9 refactor(core): rename ngComponentDef to ɵcmp (#33088)
Component defs are not considered public API, so the property
that contains them should be prefixed with Angular's marker
for "private" ('ɵ') to discourage apps from relying on def
APIs directly.

This commit adds the prefix and shortens the name from
`ngComponentDef` to `cmp`. This is because property names
cannot be minified by Uglify without turning on property
mangling (which most apps have turned off) and are thus
size-sensitive.

Note that the other "defs" (ngDirectiveDef, etc) will be
prefixed and shortened in follow-up PRs, in an attempt to
limit how large and conflict-y this change is.

PR Close #33088
2019-10-11 15:45:22 -07:00
Matias Niemelä 35a95a8a7e refactor(ivy): ensure `StylingDebug` instances provide context debug info (#32856)
This patch enables a styling debug instance (which is apart of the
`debugNode.styles` or `debugNode.classes` data structures) to expose
its context value so that it can be easily debugged.

PR Close #32856
2019-10-10 13:59:32 -07:00
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 22d4efbed1 perf(ivy): introduce micro-benchmark for directive instantiation (#33082)
PR Close #33082
2019-10-10 13:56:52 -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
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
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 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
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
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
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
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 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
Pete Bacon Darwin 9188751adc fix(ivy): i18n - do not render message ids unnecessarily (#32867)
In an attempt to be compatible with previous translation files
the Angular compiler was generating instructions that always
included the message id. This was because it was not possible
to accurately re-generate the id from the calls to `$localize()` alone.

In line with https://hackmd.io/EQF4_-atSXK4XWg8eAha2g this
commit changes the compiler so that it only renders ids if they are
"custom" ones provided by the template author.

NOTE:

When translating messages generated by the Angular compiler
from i18n tags in templates, the `$localize.translate()` function
will compute message ids, if no custom id is provided, using a
common digest function that only relies upon the information
available in the `$localize()` calls.

This computed message id will not be the same as the message
ids stored in legacy translation files. Such files will need to be
migrated to use the new common digest function.

This only affects developers who have been trialling `$localize`, have
been calling `loadTranslations()`, and are not exclusively using custom
ids in their templates.

PR Close #32867
2019-10-02 14:52:00 -07:00
Kara Erickson 41ed694d01 ci: update size benchmarks for core with 9.0.0-next.8 (#32947)
PR Close #32947
2019-10-02 13:22:36 -07:00
crisbeto 4e35e348af refactor(ivy): generate ngFactoryDef for injectables (#32433)
With #31953 we moved the factories for components, directives and pipes into a new field called `ngFactoryDef`, however I decided not to do it for injectables, because they needed some extra logic. These changes set up the `ngFactoryDef` for injectables as well.

For reference, the extra logic mentioned above is that for injectables we have two code paths:

1. For injectables that don't configure how they should be instantiated, we create a `factory` that proxies to `ngFactoryDef`:

```
// Source
@Injectable()
class Service {}

// Output
class Service {
  static ngInjectableDef = defineInjectable({
    factory: () => Service.ngFactoryFn(),
  });

  static ngFactoryFn: (t) => new (t || Service)();
}
```

2. For injectables that do configure how they're created, we keep the `ngFactoryDef` and generate the factory based on the metadata:

```
// Source
@Injectable({
  useValue: DEFAULT_IMPL,
})
class Service {}

// Output
export class Service {
  static ngInjectableDef = defineInjectable({
    factory: () => DEFAULT_IMPL,
  });

  static ngFactoryFn: (t) => new (t || Service)();
}
```

PR Close #32433
2019-10-02 13:04:26 -07:00
Andrew Scott 63256b511a fix(ivy): Only restore registered modules if user compiles modules with TestBed (#32944)
There are a couple scenarios that are problematic and need special
handling:

1. A user has a custom implementation of lazy-loaded modules, sets some
provider overrides, then compiles the module so it can be loaded. In a
follow-up test, the user sets different overrides for the module and
then compiles. This is problematic because we need to be sure the module
registered in the first test is not used, so we need to clear it out of
the modules list in `ng_module_factory_registration`.
2. A user has a similar lazy-loaded module factory implementation but
relies on the module being registered automatically. This can happen,
for example, as a side effect of importing the ngfactory file.

PR Close #32944
2019-10-01 17:17:47 -07:00
Alan Agius 668f57abaa build: update rxjs to 6.5.3 (#32812)
PR Close #32812
2019-10-01 14:56:45 -07:00
Andrew Scott 72f3747d7b fix(ivy): refresh child components before executing ViewQuery function (#32922)
Child component refresh must happen before executing the ViewQueryFn because
child components could insert a template from the host that contains the result
of the ViewQuery function (see related test added in this PR).

PR Close #32922
2019-10-01 14:47:15 -07:00
Andrew Scott 475e36abb5 fix(ivy): R3TestBed should clean up registered modules after each test (#32872)
PR Close #32872
2019-09-30 15:01:08 -07:00
Matias Niemelä c32b2ae0a8 fix(ivy): ensure class/style values are debuggable through `DebugElement` (#32842)
This patch changes the Ivy `DebugElement` code to always read style and
class values directly from the native element instead of reading them
through the styling contexts. The reason for this change is because Ivy
does not make use of a debug renderer and will therefore not have access
to any classes/styles applied directly through the renderer (unless it
reads the values directly from the element).

PR Close #32842
2019-09-30 14:14:00 -07:00
Andrew Kushnir 966c2a326a fix(ivy): include `ngProjectAs` into attributes array (#32784)
Prior to this commit, the `ngProjectAs` attribute was only included with a special flag and in a parsed format. As a result, projected node was missing `ngProjectAs` attribute as well as other attributes added after `ngProjectAs` one. This is problematic since app code might rely on the presence of `ngProjectAs` attribute (for example in CSS). This commit fixes the problem by including `ngProjectAs` into attributes array as a regular attribute and also makes sure that the parsed version of the `ngProjectAs` attribute with a special marker is added after regular attributes (thus we set them correctly at runtime). This change also aligns View Engine and Ivy behavior.

PR Close #32784
2019-09-27 10:12:18 -07:00
Greg Magolan c1346462db build: update to nodejs rules 0.37.1 (#32151)
This release includes a ts_config runfiles fix so also cleaning up the one line work-around from #31943.

This also updates to upstream rules_webtesting browser repositories load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories") to fix a breaking change in the chromedriver distro. This bumps up the version of chromium to the version here: https://github.com/bazelbuild/rules_webtesting/blob/master/web/versioned/browsers-0.3.2.bzl

PR Close #32151
2019-09-25 11:29:12 -07:00
Andrew Scott c8be987b40 fix(ivy): ensure TestBed restores fields to the most original value (#32823)
PR Close #32823
2019-09-25 11:28:09 -07:00
Matias Niemelä a54adcaff0 test(ivy): remove extra implementation of `getDebugNode` (#32843)
PR Close #32843
2019-09-25 11:27:33 -07:00
Matias Niemelä 948714c17c revert: refactor(ivy): ensure `StylingDebug` instances provide context debug info (#32753) (#32841)
This reverts commit f8f7c1540a.

PR Close #32841
2019-09-24 16:57:58 -07:00
Matias Niemelä e668d7971d revert: feat(ivy): improve debugging experience for styles/classes (#32753) (#32841)
This reverts commit 32f4544f34.

PR Close #32841
2019-09-24 16:57:58 -07:00
Matias Niemelä 86fd5719b5 fix(ivy): ensure multiple map-based bindings do not skip intermediate values (#32774)
This patch fixes a bug where the map-based cursor moves too far and
skips intermediate values when the correct combination of single-prop
bindings and map-based bindings are used together.

PR Close #32774
2019-09-24 11:58:52 -07:00
Matias Niemelä 32f4544f34 feat(ivy): improve debugging experience for styles/classes (#32753)
This patch introduces the `printTable()` and `printSources()`
methods to `DebugStylingContext` which can be used via the
`window.ng.getDebugNode` helpers when debugging an application.

PR Close #32753
2019-09-24 10:37:42 -07:00
Matias Niemelä f8f7c1540a refactor(ivy): ensure `StylingDebug` instances provide context debug info (#32753)
This patch enables a styling debug instance (which is apart of the
`debugNode.styles` or `debugNode.classes` data structures) to expose
its context value so that it can be easily debugged.

PR Close #32753
2019-09-24 10:37:42 -07:00
Matias Niemelä 5651fa3a95 fix(ivy): ensure `window.ng.getDebugNode` returns debug info for component elements (#32780)
Prior to this patch the `window.ng.getDebugNode` method would fail to
return the debug information for an element that is a host element to
a component.

PR Close #32780
2019-09-23 14:32:42 -07:00
Matias Niemelä 7a00c676ec build(ivy): make sure animation_world prodserver and devserver work as expected (#32778)
PR Close #32778
2019-09-23 14:18:22 -07:00
Matias Niemelä 0450f39625 refactor(ivy): move all styling util code into `utils/styling_utils.ts` (#32731)
PR Close #32731
2019-09-18 15:06:39 -07:00
Matias Niemelä ec0aa88f4e refactor(ivy): move `styling/instructions.ts` to `instructions/styling.ts` (#32731)
PR Close #32731
2019-09-18 15:06:39 -07:00
Matias Niemelä f88f717094 refactor(ivy): remame `styling_next` directory to `styling` (#32731)
PR Close #32731
2019-09-18 15:06:39 -07:00
Matias Niemelä 0618bed83e refactor(ivy): combine styling testing files into one (#32731)
PR Close #32731
2019-09-18 15:06:38 -07:00
Matias Niemelä 4726ac2481 feat(ivy): expose `window.ng.getDebugNode` helper (#32727)
PR Close #32727
2019-09-17 15:46:07 -07:00
Matias Niemelä a0d04c628c fix(ivy): ensure that `window.ng` utilities are published when NgModules are used (#32725)
Prior to this patch if any backwards-compatible Angular code was using
Ivy then the built-in `window.ng` debug utilies would not be exposed.

PR Close #32725
2019-09-17 13:32:06 -07:00
Pete Bacon Darwin b741a1c3e7 fix(ivy): i18n - update the compiler to output `MessageId`s (#32594)
Now that the `$localize` translations are `MessageId` based the
compiler must render `MessageId`s in its generated `$localize` code.
This is because the `MessageId` used by the compiler is computed
from information that does not get passed through to the `$localize`
tagged string.

For example, the generated code for the following template

```html
<div id="static" i18n-title="m|d" title="introduction"></div>
```

will contain these localization statements

```ts
if (ngI18nClosureMode) {
  /**
    * @desc d
    * @meaning m
    */
  const MSG_EXTERNAL_8809028065680254561$$APP_SPEC_TS_1 = goog.getMsg("introduction");
  I18N_1 = MSG_EXTERNAL_8809028065680254561$$APP_SPEC_TS_1;
}
else {
  I18N_1 = $localize \`:m|d@@8809028065680254561:introduction\`;
}
```

Since `$localize` is not able to accurately regenerate the source-message
(and so the `MessageId`) from the generated code, it must rely upon the
`MessageId` being provided explicitly in the generated code.

The compiler now prepends all localized messages with a "metadata block"
containing the id (and the meaning and description if defined).

Note that this metadata block will also allow translation file extraction
from the compiled code - rather than relying on the legacy ViewEngine
extraction code. (This will be implemented post-v9).

Although these metadata blocks add to the initial code size, compile-time
inlining will completely remove these strings and so will not impact on
production bundle size.

PR Close #32594
2019-09-17 09:17:45 -07:00
Matias Niemelä a2e890e4f7 refactor(ivy): get rid of styling cleanup functions outside of styling code (#32591)
Prior to this patch, each time `advance()` would run (or when a
templateFn or hostBindings code exits) then the core change detection
code would check to see whether the styling data needs to be reset. This
patch removes that functionality and places everything inside of the
scheduled styling exit function. This means that each time one or more
styling bindings run (even if the value hasn't changed) then an exit
function will be scheduled and that will do all the cleanup.

PR Close #32591
2019-09-16 14:12:48 -07:00
Matias Niemelä 4f41473048 refactor(ivy): remove styling state storage and introduce direct style writing (#32591)
This patch is a final major refactor in styling Angular.

This PR includes three main fixes:

All temporary state taht is persisted between template style/class application
and style/class application in host bindings is now removed.
Removes the styling() and stylingApply() instructions.
Introduces a "direct apply" mode that is used apply prop-based
style/class in the event that there are no map-based bindings as
well as property collisions.

PR Close #32259

PR Close #32591
2019-09-16 14:12:48 -07:00
Pawel Kozlowski 1748aeb9c8 perf(ivy): convert all node-based benchmark to use a testing harness (#32699)
PR Close #32699
2019-09-16 09:31:15 -07:00
Paul Gschwendtner 8415460b12 test: add size-tracking test for core_all with view engine (#32676)
* adds a size-tracking bazel target for testing and tracking
of `@angular/core` with view engine.

PR Close #32676
2019-09-13 13:27:04 -07:00
Andrew Scott bfb3995869 fix(ivy): DebugNode throws exceptions when querying some properties (#32622)
PR Close #32622
2019-09-13 10:13:08 -07:00
Andrew Kushnir 5328bb223a fix(ivy): avoid unnecessary i18n instructions generation for <ng-template> with structural directives (#32623)
If an <ng-template> contains a structural directive (for example *ngIf), Ngtsc generates extra template function with 1 template instruction call. When <ng-template> tag also contains i18n attribute on it, we generate i18nStart and i18nEnd instructions around it, which is unnecessary and breaking runtime. This commit adds a logic to make sure we do not generate i18n instructions in case only `template` is present.

PR Close #32623
2019-09-13 10:01:55 -07:00
thekiba 0477bfc8ed fix(core): make injector.get() return default value with InjectFlags.Self flag on (#27739)
Fixes #27729

PR Close #27739
2019-09-13 09:19:56 -07:00
Pete Bacon Darwin 2bf5606bbe feat(ivy): i18n - reorganize entry-points for better reuse (#32488)
This is a refactoring that moves the source code around to provide a better
platform for adding the compile-time inlining.

1. Move the global side-effect import from the primary entry-point to a
   secondary entry-point @angular/localize/init.

   This has two benefits: first it allows the top level entry-point to
   contain tree-shakable shareable code; second it gives the side-effect
   import more of an "action" oriented name, which indicates that importing
   it does something tangible

2. Move all the source code into the top src folder, and import the localize
   related functions into the localize/init/index.ts entry-point.

   This allows the different parts of the package to share code without
   a proliferation of secondary entry-points (i.e. localize/utils).

3. Avoid publicly exporting any utilities at this time - the only public
   API at this point are the global `$localize` function and the two runtime
   helpers `loadTranslations()` and `clearTranslations()`.
   This does not mean that we will not expose additional helpers for 3rd
   party tooling in the future, but it avoid us preemptively exposing
   something that we might want to change in the near future.

Notes:

It is not possible to have the `$localize` code in the same Bazel package
as the rest of the code. If we did this, then the bundled `@angular/localize/init`
entry-point code contains all of the helper code, even though most of it is not used.

Equally it is not possible to have the `$localize` types (i.e. `LocalizeFn`
and `TranslateFn`) defined in the `@angular/localize/init` entry-point because
these types are needed for the runtime code, which is inside the primary
entry-point. Importing them from `@angular/localize/init` would run the
side-effect.

The solution is to have a Bazel sub-package at `//packages/localize/src/localize`
which contains these types and the `$localize` function implementation.
The primary `//packages/localize` entry-point imports the types without
any side-effect.
The secondary `//packages/localize/init` entry-point imports the `$localize`
function and attaches it to the global scope as a side-effect, without
bringing with it all the other utility functions.

BREAKING CHANGES:

The entry-points have changed:

* To attach the `$localize` function to the global scope import from
`@angular/localize/init`. Previously it was `@angular/localize`.

* To access the `loadTranslations()` and `clearTranslations()` functions,
import from `@angular/localize`. Previously it was `@angular/localize/run_time`.

PR Close #32488
2019-09-12 15:35:34 -07:00
Misko Hevery 5a830c49cf refactor(ivy): improve micro-benchmark profiling (#32647)
PR Close #32647
2019-09-12 13:06:38 -07:00
Pawel Kozlowski ad178c55fd perf(ivy): initialise TNode inputs / outputs on the first creation pass (#32608)
This perf-focused refactoring moves the TNode's input / output initialization
logic to the first template pass - close to the place where directives are
matched and resolved.

This code change makes it possible to update-mode checks for both property
bindings and listeners registration.

PR Close #32608
2019-09-12 12:11:32 -07:00
cexbrayat 88c28ce208 refactor(ivy): migrate debug spec from render3 (#32621)
Migrate the remaining `render3/debug_spec.ts` to `acceptance`

PR Close #32621
2019-09-12 11:35:49 -07:00
cexbrayat e013aee636 refactor(ivy): migrate export spec from render3 (#32624)
The remaining test was using JS blocks and was already tested with `ngIf` in the existing acceptance test.

PR Close #32624
2019-09-12 11:33:03 -07:00
Pawel Kozlowski 6674746e86 refactor(ivy): remove duplicated TNode utility (#32495)
Before this refactoring we had 2 utility functions to check if a given
TNode has matching directives. This PR leaves just one such function
(one that does less memory read).

PR Close #32495
2019-09-12 10:27:44 -07:00
Pawel Kozlowski 024765b86a perf(ivy): introduce benchmark for listeners registration (#32495)
PR Close #32495
2019-09-12 10:27:44 -07:00
Pawel Kozlowski fcdd06896e perf(ivy): avoid megamorphic reads during property binding (#32574)
While determining a property name to bind to we were checking a mapping object
resulting in the megamorphic read. Replacing such read with a series of if checks
speeds up rproprty update benchmark ~30% (~1400ms down to ~1000ms).

PR Close #32574
2019-09-12 06:30:08 -04:00
Pawel Kozlowski ea378a993a perf(ivy): binding update benchmark (#32574)
PR Close #32574
2019-09-12 06:30:08 -04:00
Paul Gschwendtner 97dae900fb build: enforce proper compile mode for size-tracking test (#32613)
Ensures that the "core_all:size_test" target runs with "--define=compile=aot".
This is necessary because we don't run this test on CI currently, but if we run
it manually, we need to ensure that it runs with Ivy for proper size comparisons.

PR Close #32613
2019-09-11 20:22:28 -04:00
Kara Erickson f0a969579d ci: update size benchmarks for core with 9.0.0-next.5 (#32595)
PR Close #32595
2019-09-11 19:29:13 -04:00
Matias Niemelä 53dbff66d7 revert: refactor(ivy): remove styling state storage and introduce direct style writing (#32259)
This reverts commit 15aeab1620.
2019-09-11 15:24:10 -07:00
Matias Niemelä 15aeab1620 refactor(ivy): remove styling state storage and introduce direct style writing (#32259) (#32596)
This patch is a final major refactor in styling Angular.

This PR includes three main fixes:

All temporary state taht is persisted between template style/class application
and style/class application in host bindings is now removed.
Removes the styling() and stylingApply() instructions.
Introduces a "direct apply" mode that is used apply prop-based
style/class in the event that there are no map-based bindings as
well as property collisions.

PR Close #32259

PR Close #32596
2019-09-11 16:27:10 -04:00
Matias Niemelä c84c27f7f4 revert: refactor(ivy): remove styling state storage and introduce direct style writing (#32259) 2019-09-10 18:08:05 -04:00
Matias Niemelä 3b37469735 refactor(ivy): remove styling state storage and introduce direct style writing (#32259)
This patch is a final major refactor in styling Angular.

This PR includes three main fixes:

All temporary state taht is persisted between template style/class application
and style/class application in host bindings is now removed.
Removes the styling() and stylingApply() instructions.
Introduces a "direct apply" mode that is used apply prop-based
style/class in the event that there are no map-based bindings as
well as property collisions.

PR Close #32259
2019-09-10 15:54:58 -04:00
cexbrayat f00bb85b58 refactor(ivy): migrate content spec from render3 (#32474)
Migrate the remaining `render3/content_spec.ts` to `acceptance` (some JS block ones were already migrated with `ngIf`).

PR Close #32474
2019-09-10 13:03:16 -04:00
cexbrayat ded57245e1 fix(ivy): match class and attribute value without case-sensitivity (#32548)
Prior to this commit, a directive with a selector `selector=".Titledir"` would not match an element like `div class="titleDir"` in Ivy whereas it would in VE. The same issue was present for `selector="[title=Titledir]` and `title="titleDir"`.  This fixes the Ivy behavior by changing the matching algorithm to use lowercased values.

Note that some `render3` tests needed to be changed to reflect that the compiler generates lowercase selectors. These tests are in the process to be migrated to `acceptance` to use `TestBed` in another PR anyway.

PR Close #32548
2019-09-10 06:31:22 -04:00
cexbrayat 8a6e54a06d test(ivy): test case-insensitive selectors (#32548)
Adds two acceptance tests to show a current difference in behavior between Ivy and VE.
A directive with a selector `.Titledir` matches an element with `class="titleDir"` in VE but not in Ivy.
Same thing for an attribute value.

PR Close #32548
2019-09-10 06:31:22 -04:00
Andrew Kushnir a1beba4b6e fix(ivy): restore global state after running refreshView (#32521)
Prior to this commit, the `previousOrParentTNode` was set to null after performing all operations within `refreshView` function. It's causing problems in more complex scenarios, for example when change detection is triggered during DI (see test added as a part of this commit). As a result, global state might be corrupted. This commit captures current value of `previousOrParentTNode` and restores it after `refreshView` call.

PR Close #32521
2019-09-10 06:30:49 -04:00
crisbeto 664e0015d4 perf(ivy): replace select instruction with advance (#32516)
Replaces the `select` instruction with a new one called `advance`. Instead of the jumping to a specific index, the new instruction goes forward X amount of elements. The advantage of doing this is that it should generate code the compresses better.

PR Close #32516
2019-09-10 06:30:28 -04:00
Pete Bacon Darwin ea6a2e9f25 fix(ivy): template compiler should render correct $localize placeholder names (#32509)
The `goog.getMsg()` function requires placeholder names to be camelCased.

This is not the case for `$localize`. Here placeholder names need
match what is serialized to translation files.

Specifically such placeholder names keep their casing but have all characters
that are not in `a-z`, `A-Z`, `0-9` and `_` converted to `_`.

PR Close #32509
2019-09-09 19:11:36 -04:00
Carlos Ortiz García 9166baf709 refactor(core): Migrate TestBed.get to TestBed.inject (#32382)
This is cleanup/followup for PR #32200

PR Close #32382
2019-09-09 19:10:54 -04:00
Pawel Kozlowski 2895edc9c6 perf(ivy): introduce a node-based micro-benchmarks harness (#32510)
PR Close #32510
2019-09-09 15:56:41 -04:00
Greg Magolan df5924abd0 test: fix ivy ts_devserver tests under /packages/core/test/bunding/ (#32520)
PR Close #32520
2019-09-06 20:03:40 -04:00
crisbeto bc061b78be fix(ivy): warn instead of throwing for unknown properties (#32463)
Logs a warning instead of throwing when running into a binding to an unknown property in JIT mode. Since we aren't using a schema for the runtime validation anymore, this allows us to support browsers where properties are unsupported.

PR Close #32463
2019-09-06 13:15:03 -04:00
crisbeto 62d92f8091 fix(ivy): unable to bind to properties that start with class or style (#32421)
Fixes Ivy picking up property bindings that start with `class` or `style` as if they're style bindings.

Fixes #32310

PR Close #32421
2019-09-05 18:10:08 -04:00
Andrew Kushnir 098feec4a0 fix(ivy): maintain coalesced listeners order (#32484)
Prior to this commit, listeners order was not preserved in case we coalesce them to avoid triggering unnecessary change detection cycles. For performance reasons we were attaching listeners to existing events at head (always using first listener as an anchor), to avoid going through the list, thus breaking the order in which listeners are registered. In some scenarios this order might be important (for example with `ngModelChange` and `input` listeners), so this commit updates the logic to put new listeners at the end of the list. In order to avoid performance implications, we keep a pointer to the last listener in the list, so adding a new listener takes constant amount of time.

PR Close #32484
2019-09-05 18:09:47 -04:00
crisbeto da42a7648a fix(ivy): node placed in incorrect order inside ngFor with ng-container (#32324)
Fixes an issue where Ivy incorrectly inserts items in the beginning of an `ngFor`, if the `ngFor` is set on an `ng-container`. The issue comes from the fact that we choose the `ng-container` comment node as the anchor point before which to insert the content, however the node might be after any of the nodes inside the container. These changes switch to picking out the first node inside of the container instead.

PR Close #32324
2019-09-05 18:08:48 -04:00
Andrew Kushnir f00d03356f fix(ivy): handle expressions in i18n attributes properly (#32309)
Prior to this commit, complex expressions (that require additional statements to be generated) were handled incorrectly in case they were used in attributes annotated with i18n flags. The problem was caused by the fact that extra statements were not appended to the temporary vars block, so they were missing in generated code. This commit updated the logic to use the `convertPropertyBinding`, which contains the necessary code to append extra statements. The `convertExpressionBinding` function was removed as it duplicates the `convertPropertyBinding` one (for the most part) and is no longer used.

PR Close #32309
2019-09-05 13:35:16 -04:00
Matias Niemelä 7cc4225eb9 fix(ivy): ensure binding ordering doesn't mess up when a `NO_CHANGE` value is encountered (#32143)
Prior to this fix if a `NO_CHANGE` value was assigned to a binding, or
an interpolation value rendererd a `NO_CHANGE` value, then the presence
of that value would cause the internal counter index values to not
increment properly. This patch ensures that this doesn't happen and
that the counter/bitmask values update accordingly.

PR Close #32143
2019-09-04 11:54:19 -07:00
cexbrayat bdbf0c94b1 style(core): typos in docs and tests (#32410)
PR #32154 introduced `platform` and `any` for `providedIn` and the doc has a minor typo.
Also a test name was not changed accordingly to the refactoring done.

PR Close #32410
2019-09-04 11:52:30 -07:00
Pawel Kozlowski 641c5c1c1e perf(ivy): guard directive-related operations with a TNode flag (#32445)
PR Close #32445
2019-09-04 11:39:57 -07:00
Pawel Kozlowski a383a5a165 refactor(ivy): simplify property binding metadata storage (#32457)
Since property binding metadata storage is guarded with the ngDevMode now
and several instructions were merged together, we can simplify the way we
store and read property binding metadata.

PR Close #32457
2019-09-04 11:37:35 -07:00
Kara Erickson 89434e09c2 refactor(core): move Meta methods that only have one version from DomAdapter (#32408)
PR Close #32408
2019-09-03 11:59:39 -07:00
Kara Erickson 1a7c79746d refactor(core): move misc methods that only have one version from DomAdapter (#32408)
PR Close #32408
2019-09-03 11:59:39 -07:00
Kara Erickson c207ad80fd refactor(core): move DomAdapter style methods to ServerRenderer (#32408)
PR Close #32408
2019-09-03 11:59:39 -07:00
Kara Erickson 970b58b13f refactor(core): move server-only DomAdapter methods into ServerRenderer (#32408)
PR Close #32408
2019-09-03 11:59:39 -07:00
Pete Bacon Darwin a7f61e63fa refactor(ivy): remove `i18nConfigureLocalize` instruction (#31609)
This has been replaced by the `loadTranslations()` function in
`@angular/localize/run_time`.

PR Close #31609
2019-08-30 12:53:26 -07:00
Pete Bacon Darwin fa79f51645 refactor(ivy): update the compiler to emit `$localize` tags (#31609)
This commit changes the Angular compiler (ivy-only) to generate `$localize`
tagged strings for component templates that use `i18n` attributes.

BREAKING CHANGE

Since `$localize` is a global function, it must be included in any applications
that use i18n. This is achieved by importing the `@angular/localize` package
into an appropriate bundle, where it will be executed before the renderer
needs to call `$localize`. For CLI based projects, this is best done in
the `polyfills.ts` file.

```ts
import '@angular/localize';
```

For non-CLI applications this could be added as a script to the index.html
file or another suitable script file.

PR Close #31609
2019-08-30 12:53:26 -07:00
Andrew Scott 260217a800 fix(ivy): Prevent errors when querying for elements outside Angular context (#32361)
DebugElement.query also searches elements that may have been created
outside of Angular (ex: with `document.appendChild`). The current
behavior attempts to get the LContext of these nodes but throws an error
because the LContext does not exist.

PR Close #32361
2019-08-30 12:51:34 -07:00
cexbrayat c8b065524e refactor(ivy): cleanup di tests from render3 (#32165)
The tests were already migrated to acceptance with `ngFor`/`ngIf`, but were leftover in case JS blocks ended up supported in Ivy.

PR Close #32165
2019-08-30 12:49:04 -07:00
Pawel Kozlowski 8dc3f3647c perf(ivy): properly initialise global state in the element_text_create benchmark (#32397)
PR Close #32397
2019-08-30 12:42:28 -07:00
Matias Niemelä ba5e07efc7 perf(ivy): add a micro benchmark for map-based style and class bindings (#32401)
This patch introduces a new micro benchmark that performance tests
against map-based style and class bindings in Ivy running together
on the same element.

PR Close #32401
2019-08-30 13:52:35 -04:00
Matias Niemelä df8e6750a1 perf(ivy): add a micro benchmark for style and class bindings (#32401)
This patch introduces a new micro benchmark that performance tests
against style and class bindings in Ivy running together on the same
element.

PR Close #32401
2019-08-30 13:52:35 -04:00
Misko Hevery 77c382ccba feat(core): Adds DI support for `providedIn: 'platform'|'any'` (#32154)
Extend the vocabulary of the `providedIn` to also include  `'platform'` and `'any'`` scope.
```
@Injectable({
  providedId: 'platform', // tree shakable injector for platform injector
})
class MyService {...}
```

PR Close #32154
2019-08-29 21:51:56 -07:00
Misko Hevery 8a47b48912 refactor: Move `dom_adapter.ts` to `@angular/common` (#32154)
This work is needed in preparation for turning tokens into tree-shakable injectables.

PR Close #32154
2019-08-29 21:51:56 -07:00
Kara Erickson 7742a99cee ci: update size benchmarks for core with 9.0.0-next.4 (#32255)
PR Close #32255
2019-08-28 21:39:24 -07:00
Pawel Kozlowski 5635505f2e refactor(ivy): remove unused ɵɵtextBinding instruction (#32345)
PR Close #32345
2019-08-28 21:37:15 -07:00
Carlos Ortiz García 3aba7ebe6a feat(core): Introduce TestBed.inject to replace TestBed.get (#32200)
TestBed.get is not type safe, fixing it would be a massive breaking
change. The Angular team has proposed replacing it with TestBed.inject
and deprecate TestBed.get.

Deprecation from TestBed.get will come as a separate commit.

Issue #26491
Fixes #29905

BREAKING CHANGE: Injector.get now accepts abstract classes to return
type-safe values. Previous implementation returned `any` through the
deprecated implementation.

PR Close #32200
2019-08-28 21:26:46 -07:00
Pawel Kozlowski 85864ed9f7 perf(ivy): add element and text creation benchmark (#32342)
PR Close #32342
2019-08-28 17:12:38 -07:00
Kara Erickson f3e4cb491e refactor(core): remove testing-only event utilities from DomAdapters (#32291)
PR Close #32291
2019-08-28 17:10:30 -07:00
Kara Erickson cb5701f8d9 refactor(core): remove testing-only node getters and invoke() from DomAdapters (#32291)
PR Close #32291
2019-08-28 17:10:30 -07:00
Kara Erickson c0680602f9 refactor(core): remove testing-only childNodes() and firstChild() fns from DomAdapters (#32291)
PR Close #32291
2019-08-28 17:10:30 -07:00
Kara Erickson 30dabdf8fc refactor(core): remove testing-only DOM manipulation utils from DomAdapters (#32291)
PR Close #32291
2019-08-28 17:10:30 -07:00
Kara Erickson ede5786d1e refactor(core): remove testing-only style utils from DomAdapters (#32291)
PR Close #32291
2019-08-28 17:10:29 -07:00
Kristiyan Kostadinov c885178d5f refactor(ivy): move directive, component and pipe factories to ngFactoryFn (#31953)
Reworks the compiler to output the factories for directives, components and pipes under a new static field called `ngFactoryFn`, instead of the usual `factory` property in their respective defs. This should eventually allow us to inject any kind of decorated class (e.g. a pipe).

**Note:** these changes are the first part of the refactor and they don't include injectables. I decided to leave injectables for a follow-up PR, because there's some more cases we need to handle when it comes to their factories. Furthermore, directives, components and pipes make up most of the compiler output tests that need to be refactored and it'll make follow-up PRs easier to review if the tests are cleaned up now.

This is part of the larger refactor for FW-1468.

PR Close #31953
2019-08-27 13:57:00 -07:00
Andrew Scott 14feb56139 fix(ivy): debug node names should match user declaration (#32328)
PR Close #32328
2019-08-27 13:55:59 -07:00
Pawel Kozlowski 0874bf42b6 perf(ivy): store binding metadata in the ngDevMode only (#32317)
Binding metadata are only needed:
- for property bindings;
- when TestBed tests are being run.

This commit guards binding metadata storage with the ngDevMode flag
which saves ~6% of a proerty binding processing time in the production
mode (and reduces bundle size).

PR Close #32317
2019-08-26 16:19:02 -07:00
Pawel Kozlowski e63a7b0532 refactor(ivy): replace enter / leave view with selectView (#32263)
After a series of recent refactorings `enterView` and `leaveView` became
identical. This PR merges both into one concept of view selectio (similar
to a node selection). This reduces number of concepts and code size.

PR Close #32263
2019-08-26 13:18:28 -07:00
Kara Erickson cf4b944865 refactor(core): remove misc dom utils from DomAdapters (#32278)
PR Close #32278
2019-08-26 10:39:09 -07:00
Kara Erickson 28c8b03797 refactor(core): remove shadow dom utility from DomAdapters (#32278)
PR Close #32278
2019-08-26 10:39:09 -07:00
Kara Erickson bceeeba405 refactor(core): remove animation utilities from DomAdapters (#32278)
PR Close #32278
2019-08-26 10:39:09 -07:00
Kara Erickson 7bcd42e7be refactor(core): remove cookie and comment testing utilities from DomAdapters (#32278)
PR Close #32278
2019-08-26 10:39:09 -07:00
Kara Erickson 4908a5cffc refactor(core): remove unused attribute utilities from DomAdapters (#32278)
PR Close #32278
2019-08-26 10:39:09 -07:00
Kara Erickson c3f9893d81 refactor(core): remove innerHTML and outerHTML testing utilities from DomAdapters (#32278)
PR Close #32278
2019-08-26 10:39:09 -07:00
Andrew Kushnir 6b245a39ee fix(ivy): reset binding index before executing a template in `refreshView` call (#32201)
Prior to this change, the `BINDING_INDEX` of a given lView was reset after processing a template. However change detection can be triggered as a result of View queries processing, thus leading to subsequent `refreshView` call (and executing a template), which in turn operates with the binding index that is not reset after the previous `refreshView` call. This commit updates the logic to reset binding index before we execute a template, so binding index is correct for instructions inside template function.

PR Close #32201
2019-08-22 10:16:24 -07:00
Pawel Kozlowski 53bfa7c6d6 perf(ivy): improve NaN checks in change detection (#32212)
This commit drops our custom, change-detection specific, equality comparison util
in favour of the standard Object.is which has desired semantics.

There are multiple advantages of this approach:
- less code to maintain on our end;
- avoid NaN checks if both values are equal;
- re-write NaN checks so we don't trigger V8 deoptimizations.

PR Close #32212
2019-08-21 11:45:51 -07:00
Pawel Kozlowski 10629600c5 perf(ivy): split hooks processing into init and check phases (#32131)
Angular hooks come after 2 flavours:
- init hooks (OnInit, AfterContentInit, AfterViewInit);
- check hooks (OnChanges, DoChanges, AfterContentChecked, AfterViewChecked).

We need to do more processing for init hooks to ensure that those hooks
are run once and only once for a given directive (even in case of errors).
As soon as all init hooks execute to completion we are only left with the
checks to execute.

It turns out that keeping track of the remaining init hooks to execute is
rather expensive (multiple LView flags reads, writes and checks). But we can
observe that non of this tracking is needed as soon as all init hooks are
completed.

This PR takes advantage of the above observations and splits hooks processing
functions into:
- init-specific (slower but less common);
- check-specific (faster and more common).

NOTE: there is code duplication in this PR and it is left like this intentinally:
hand-inlining this perf-critical code makes the view refresh process substentially
faster.

PR Close #32131
2019-08-21 11:44:27 -07:00
Miško Hevery 64770571b2 perf: don't create holey arrays (#32155)
Don't use `Array` constructor with the size value (ex. `new Array(5)`) - this will create a `HOLEY_ELEMENTS` array (even if this array is filled in later on!);

https://v8.dev/blog/elements-kinds
https://stackoverflow.com/questions/32054170/how-to-resize-an-array

PR Close #32155
2019-08-21 08:27:43 -07:00
Andrew Scott 3dbc4ab572 fix(ivy): get name directly from nativeNode (#32198)
nativeElement can return null so an error can occur when accessing
nodeName from nativeElement.

PR Close #32198
2019-08-20 09:57:17 -07:00
atscott cfed0c0cf1 fix(ivy): Support selector-less directive as base classes (#32125)
Following #31379, this adds support for directives without a selector to
Ivy.

PR Close #32125
2019-08-20 09:56:54 -07:00
Misko Hevery 994264c0ba refactor(ivy): simplify `walkTNodeTree` method for readability (#31065)
PR Close #31065
2019-08-19 10:12:38 -07:00
Pawel Kozlowski 172bb76964 docs(ivy): update micro-benchmark instructions (#32190)
PR Close #32190
2019-08-19 10:10:39 -07:00
Pawel Kozlowski 4c3b791ff3 perf(ivy): avoid first template pass checks during view creation (#32120)
PR Close #32120
2019-08-15 14:46:26 -07:00
Miško Hevery 2e4d17f3a9 perf(core): make sanitization tree-shakable in Ivy mode (#31934)
In VE the `Sanitizer` is always available in `BrowserModule` because the VE retrieves it using injection.

In Ivy the injection is optional and we have instructions instead of component definition arrays. The implication of this is that in Ivy the instructions can pull in the sanitizer only when they are working with a property which is known to be unsafe. Because the Injection is optional this works even if no Sanitizer is present. So in Ivy we first use the sanitizer which is pulled in by the instruction, unless one is available through the `Injector` then we use that one instead.

This PR does few things:
1) It makes `Sanitizer` optional in Ivy.
2) It makes `DomSanitizer` tree shakable.
3) It aligns the semantics of Ivy `Sanitizer` with that of the Ivy sanitization rules.
4) It refactors `DomSanitizer` to use same functions as Ivy sanitization for consistency.

PR Close #31934
2019-08-15 10:30:12 -07:00
Pawel Kozlowski 253a1125bf test(ivy): add style binding node-based micro benchmark (#32104)
PR Close #32104
2019-08-15 09:55:03 -07:00
Pawel Kozlowski f41c41fd50 test(ivy): add property binding node-based micro benchmark (#32104)
PR Close #32104
2019-08-15 09:55:03 -07:00
Pawel Kozlowski 33fab26930 test(ivy): remove code duplication from node perf benchmarks (#32104)
PR Close #32104
2019-08-15 09:55:03 -07:00
Pawel Kozlowski be665d8de1 perf(ivy): interpolation micro-benchmark (#32104)
PR Close #32104
2019-08-15 09:55:03 -07:00
Pawel Kozlowski c422c7210f perf(ivy): noop change detection micro-benchmark (#32104)
PR Close #32104
2019-08-15 09:55:03 -07:00
Pete Bacon Darwin 7a75f7805c build(core): add missing tsconfig-build.json dependency (#31943)
For some reason (on OS/X) this transitive dependency is not being passed
through to the final TS builds that rely on this rule, so the build fails
with a missing file error:

```
The specified path does not exist:
'/.../sandbox/darwin-sandbox/451/execroot/angular/packages/tsconfig-build.json'.
```

PR Close #31943
2019-08-14 11:56:13 -07:00
Pawel Kozlowski b9dfe66028 perf(ivy): split view processing into render (create) and refresh (update) pass (#32020)
PR Close #32020
2019-08-13 15:22:42 -07:00
Kristiyan Kostadinov 914900a561 refactor(ivy): remove load instruction (#32067)
These changes remove the `ɵɵload` instruction which isn't being generated anymore.

PR Close #32067
2019-08-12 12:55:18 -07:00
Kristiyan Kostadinov 4ea3e7e000 refactor(ivy): combine query load instructions (#32100)
Combines the `loadViewQuery` and `loadContentQuery` instructions since they have the exact same internal logic. Based on a discussion here: https://github.com/angular/angular/pull/32067#pullrequestreview-273001730

PR Close #32100
2019-08-12 10:32:08 -07:00
Pete Bacon Darwin 0ddf0c4895 fix(compiler): do not remove whitespace wrapping i18n expansions (#31962)
Similar to interpolation, we do not want to completely remove whitespace
nodes that are siblings of an expansion.

For example, the following template

```html
<div>
  <strong>items left<strong> {count, plural, =1 {item} other {items}}
</div>
```

was being collapsed to

```html
<div><strong>items left<strong>{count, plural, =1 {item} other {items}}</div>
```

which results in the text looking like

```
items left4
```

instead it should be collapsed to

```html
<div><strong>items left<strong> {count, plural, =1 {item} other {items}}</div>
```

which results in the text looking like

```
items left 4
```

---

**Analysis of the code and manual testing has shown that this does not cause
the generated ids to change, so there is no breaking change here.**

PR Close #31962
2019-08-09 12:03:50 -07:00
Pawel Kozlowski 9d1f43f3ba perf(ivy): remove unnecessary view type checks (#31959)
PR Close #31959
2019-08-08 12:13:00 -07:00
Kristiyan Kostadinov a2183ddb7a fix(ivy): directive matching not working in some cases when preceded by styling attributes (#31942)
Fixes Ivy's directive matching not capturing attribute selectors when there is one class binding, one style binding and a regular binding that precede  the attribute that would match the directive. The issue appears to come from the fact that we weren't skipping over style bindings correctly which was throwing the loop off not to go into `bindingsMode` and to skip some of the bindings when matching.

PR Close #31942
2019-08-01 17:42:42 -07:00
Pawel Kozlowski a7c71d1a57 perf(ivy): remove firstTemplatePass check for component view creation (#31946)
PR Close #31946
2019-08-01 17:42:23 -07:00
Kristiyan Kostadinov 184d270725 fix(ivy): DebugElement.triggerEventHandler not picking up events registered via Renderer2 (#31845)
Fixes Ivy's `DebugElement.triggerEventHandler` to picking up events that have been registered through a `Renderer2`, unlike ViewEngine.

This PR resolves FW-1480.

PR Close #31845
2019-08-01 10:13:07 -07:00
Andrew Kushnir d0d875a3fe fix(ivy): pass `schemas` field to nested views (#31913)
Prior to this commit, the `schemas` configuration was applied to top-level view only. That leads to problems when using unknown props with elements inside nested views (for example generated as a result of *ngIf). This commit passes `schemas` information down to nested views to make sure that all the checks are consistent.

PR Close #31913
2019-08-01 10:11:01 -07:00
Kristiyan Kostadinov 14dba72aee fix(core): DebugElement.listeners not cleared on destroy (#31820)
Currently the `DebugElement.listeners` array are retained after the node is destroyed. This means that they'll continue to fire through `triggerEventHandler` and can cause memory leaks. This has already been fixed in Ivy, but these changes fix it in ViewEngine for consistency.

PR Close #31820
2019-07-29 10:05:19 -07:00
Greg Magolan 5f0d5e9ccf build: update to nodejs rules 0.34.0 and bazel 0.28.1 (#31824)
nodejs rules 0.34.0 now includes protractor_web_test_suite rule (via new @bazel/protractor rule) so we switch to that location for that rule in this PR so that /packages/bazel/src/protractor can be removed in a future PR

this PR also brings in node toolchain support which was released in nodejs rules 0.33.0. this is a prerequisite for RBE for mac & windows users

bazel schematics also updated with the same. @bazel/bazel 0.28.1 npm package includes transitive dep on hide-bazel-files so we're able to remove an explicit dep on that as well.

PR Close #31824
2019-07-26 15:01:25 -07:00
Olivier Combe 5296c04f61 fix(ivy): set LOCALE_ID when using the injector (#31566)
In `BrowserModule` the value of `LOCALE_ID` is defined in the `APPLICATION_MODULE_PROVIDERS` after `APP_INITIALIZER` has run.
This PR ensures that `LOCALE_ID` is also set for ivy at the same moment which allows the application to fetch the locale from a backend (for example).

Fixes #31465

FW-1436 #resolve

PR Close #31566
2019-07-26 14:04:47 -07:00
Kristiyan Kostadinov 40a0666651 fix(ivy): error when using forwardRef in Injectable's useClass (#30532)
Fixes Ivy throwing an error when something is passed in as a `forwardRef` into `@Injectable`'s `useClass` option. The error was being thrown, because we were trying to get the provider factory off of the wrapper function, rather than the value itself.

This PR resolves FW-1335.

PR Close #30532
2019-07-26 14:02:49 -07:00
Kara Erickson 2172368eae build: update ivy file sizes (#31828)
PR Close #31828
2019-07-24 14:43:31 -07:00
crisbeto 3d7303efc0 perf(ivy): avoid extra parameter in query instructions (#31667)
Currently we always generate the `read` parameter for the view and content query instructions, however since most of the time the `read` parameter won't be set, we'll end up generating `null` which adds 5 bytes for each query when minified. These changes make it so that the `read` parameter only gets generated if it has a value.

PR Close #31667
2019-07-24 14:37:51 -07:00
Kara Erickson b696413a79 fix(ivy): support attribute selectors in dynamic component creation (#31812)
This commit fixes a bug where we assumed all dynamically created
components would have tag-name selectors, so we passed through the
"tag name" to the renderer as the first index of the selector. For
components with attribute selectors, the tag name would be "", so
the renderer would try to create an element with tag name "" and
throw. Now we default to a "div" element the same way that View
Engine did.

Closes #31785

PR Close #31812
2019-07-23 21:16:05 -07:00
crisbeto 9eefe25e2f fix(ivy): components created with wrong context when passing root node to component factory (#31661)
The way the `ComponentFactory.create` is set up at the moment is that if a `rootSelectorOrNode` is passed in, the root context will be injected instead of creating dedicated one for the component. As far as I can tell, there doesn't seem to be a reason to do this and nothing seems to break because of it. These changes switch to always create the root context.

PR Close #31661
2019-07-23 15:51:50 -07:00
crisbeto 221782a8a1 fix(ivy): DebugNode.query not picking up nodes inserted through Renderer2 (#31716)
In ViewEngine nodes that were inserted through `Renderer2` would also be picked up by `DebugNode.query` and `DebugNode.queryAll`. This worked because everything in ViewEngine went through `Renderer2` and `DebugRenderer2` in dev mode which was able to keep track of the child nodes as they're being inserted. This no longer works in Ivy, because we don't use `DebugRenderer2` and debug nodes work a little differently. These changes work around the issue by walking the DOM as the logical tree is being walked and looking for matches. Note that this is __not__ optimal, because we're walking similar trees multiple times. ViewEngine could do it more efficiently, because all the insertions go through Renderer2, however that's not the case in Ivy. This approach is being used because:
1. Matching the ViewEngine behavior would mean potentially introducing a depedency from `Renderer2` to Ivy which could bring Ivy code into ViewEngine.
2. We would have to make `Renderer3` "know" about debug nodes.
3. It allows us to capture nodes that were inserted directly via the DOM.

PR Close #31716
2019-07-23 15:51:00 -07:00
Paul Gschwendtner b31a292955 test: update size-tracking golden for "core_all" bundling test (#31779)
Updates the size-tracking golden for the core_all test of the
@angular/core package.

PR Close #31779
2019-07-23 15:48:06 -07:00
crisbeto 0aff4a6919 fix(ivy): incorrect ChangeDetectorRef injected into pipes used in component inputs (#31438)
When injecting a `ChangeDetectorRef` into a pipe, the expected result is that the ref will be tied to the component in which the pipe is being used. This works for most cases, however when a pipe is used inside a property binding of a component (see test case as an example), the current `TNode` is pointing to component's host so we end up injecting the inner component's view. These changes fix the issue by only looking up the component view of the `TNode` if the `TNode` is a parent.

This PR resolves FW-1419.

PR Close #31438
2019-07-23 15:46:23 -07:00
Matias Niemelä f50dede8f7 refactor(ivy): remove all old styling code prior to refactor (#31193)
In the previous patch () all the existing styling code was turned
off in favor of using the new refactored ivy styling code. This
patch is a follow up patch to that and removes all old, unused
styling code from the render3 directory.

PR Close #31193
2019-07-23 15:45:32 -07:00
Kara Erickson 0e68c7edf9 fix(ivy): support projecting containers created by query reads (#31790)
PR Close #31790
2019-07-22 23:07:01 -07:00
Kara Erickson 54ef63b0f4 fix(ivy): support ICU expressions inserted in ngTemplateOutlets inside ngFors (#31789)
This commit fixes a bug where ICU expressions inserted into ngTemplateOutlets
that are inside ngFor blocks would throw an error. We were assuming in view
insertion code that text nodes would always exist by the time a view\`s
creation block had executed. This is not true for text nodes created dynamically
by ICUs because this happens in the update block (in `i18nApply`).

This change ensures such dynamically created nodes are skipped when encountered
too early (as they will be attached later by i18n code anyway).

PR Close #31789
2019-07-22 23:06:42 -07:00
Kara Erickson 215ef3c5f4 fix(ivy): ensure NgClass does not overwrite other dir data (#31788)
We currently have a handwritten version of the Ivy directive def for NgClass so
we can switch between Ivy and View Engine behavior. This generated code needs to
be kept up-to-date with what the Ivy compiler generates.

PR 30742 recently changed `classMap` such that it now requires allocation of
host binding slots. This means that the `allocHostVars()` function must be
called in the NgClass directive def to match compiler output, but the
handwritten directive def was not updated. This caused a bug where NgClass
was inappropriately overwriting data for other directives because space was
not allocated for its values.

PR Close #31788
2019-07-22 16:56:27 -07:00
Pawel Kozlowski 8b26447c4f perf(ivy): avoid using array splice (#31656)
PR Close #31656
2019-07-22 09:53:18 -07:00
Pawel Kozlowski d52ae7cbab perf(ivy): match query results on the TView level (#31489)
PR Close #31489
2019-07-19 20:38:08 -07:00
Matias Niemelä 9c954ebc62 refactor(ivy): make styling instructions use the new styling algorithm (#30742)
This commit is the final patch of the ivy styling algorithm refactor.
This patch swaps functionality from the old styling mechanism to the
new refactored code by changing the instruction code the compiler
generates and by pointing the runtime instruction code to the new
styling algorithm.

PR Close #30742
2019-07-19 16:40:40 -07:00
Miško Hevery f14693b9a4 refactor(ivy): correct circular dependency which causes g3 failures (#31665)
PR Close #31665
2019-07-19 15:06:46 -07:00
Misko Hevery 4495a46b99 refactor(ivy): clean up RNode retrieval; add better debug support for TNode (#31040)
PR Close #31040
2019-07-18 16:46:54 -07:00
Paul Gschwendtner 647d7bdd88 refactor: fix typescript strict flag failures in all tests (#30993)
Fixes all TypeScript failures caused by enabling the `--strict`
flag for test source files. We also want to enable the strict
options for tests as the strictness enforcement improves the
overall codehealth, unveiled common issues and additionally it
allows us to enable `strict` in the `tsconfig.json` that is picked
up by IDE's.

PR Close #30993
2019-07-18 14:21:26 -07:00
Paul Gschwendtner e061e638cb fix(ivy): semantic module check incorrectly handles nested arrays (#30993)
In View Engine, developers can pass bootstrap and entry components
as nested arrays. e.g.

```ts
export const MyOtherEntryComponents = [A, B, C]

@NgModule({
  entryComponents: [MyComp, MyOtherEntryComponents]
})
```

Currently using nested arrays for these properties causes
unexpected errors to be reported in Ivy since the semantic
NgModule checks aren't properly recursing into the nested
entry/bootstrap components. This issue has been unveiled by
enabling the strict function parameter checks.

PR Close #30993
2019-07-18 14:21:26 -07:00
Paul Gschwendtner 2200884e55 refactor(core): ensure compatibility with typescript strict flag (#30993)
As part of FW-1265, the `@angular/core` package is made compatible
with the TypeScript `--strict` flag. This already unveiled a few bugs,
so the strictness flag seems to help with increasing the overall code health.

Read more about the strict flag [here](https://www.typescriptlang.org/docs/handbook/compiler-options.html)

PR Close #30993
2019-07-18 14:21:25 -07:00
crisbeto 12fd06916b fix(ivy): don't match directives against attribute bindings (#31541)
Fixes Ivy matching directives against attribute bindings (e.g. `[attr.some-directive]="foo"`). Works by excluding attribute bindings from the attributes array during compilation. This has the added benefit of generating less code.

**Note:** My initial approach to implementing this was to have a different marker for attribute bindings so that they can be ignored when matching directives, however as I was implementing it I realized that the attributes in that array were only used for directive matching (as far as I could tell). I decided to drop the attribute bindings completely, because it results in less generated code.

PR Close #31541
2019-07-16 23:59:13 -04:00
crisbeto 9e83822679 fix(ivy): a couple of typos in error messages (#31571)
Fixes a couple of typos that were noticed after the initial PR (#31543) got merged in.

PR Close #31571
2019-07-16 23:58:52 -04:00
crisbeto 40d785f0a0 perf(ivy): avoid generating extra parameters for host property bindings (#31550)
Currently we reuse the same instruction both for regular property bindings and property bindings on the `host`. The only difference between the two is that when it's on the host we shouldn't support inputs. We have an optional parameter called `nativeOnly` which is used to differentiate the two, however since `nativeOnly` is preceeded by another optional parameter (`sanitizer`), we have to generate two extra parameters for each host property bindings every time (e.g. `property('someProp', 'someValue', null, true)`).

These changes add a new instruction called `hostProperty` which avoids the need for the two parameters by removing `nativeOnly` which is always set and it allows us to omit `sanitizer` when it isn't being used.

These changes also remove the `nativeOnly` parameter from the `updateSyntheticHostBinding` instruction, because it's only generated for host elements which means that we can assume that its value will always be `true`.

PR Close #31550
2019-07-16 13:01:42 -04:00
crisbeto 31ea254a07 fix(ivy): align NgModule assertions with ViewEngine (#31543)
Aligns Ivy's `NgModule` assertion messages with the ones from `ViewEngine` and adds a few that hadn't been implemented.

PR Close #31543
2019-07-15 13:58:19 -04:00
Joey Perrott 32aa18be78 build: add tsconfig-test to dependency for tsconfig in core/test/strict_types (#31471)
PR Close #31471
2019-07-12 11:38:16 -04:00
Andrew Kushnir 63e458dd3a fix(ivy): handle ICUs with placeholders in case other nested ICUs are present (#31516)
Prior to this fix, the logic to set the right placeholder format for ICUs was a bit incorrect: if there was a nested ICU in one of the root ICU cases, that led to a problem where placeholders in subsequent branches used the wrong ({$placeholder}) format instead of {PLACEHOLDER} one. This commit updates the logic to make sure we properly transform all placeholders even if nested ICUs are present.

PR Close #31516
2019-07-12 11:37:16 -04:00
Andrew Kushnir d545bbeee4 fix(ivy): handle ModuleWithProviders in R3TestBed correctly (#31415)
Prior to this commit, it was impossible to override providers defined via ModuleWithProviders using TestBed.overrideProvider API. The problem was caused by the fact that we were not taking into account these providers while calculating accumulated set of provider overrides. This commit updates the logic to extract providers from ModuleWithProviders and calculate the final set of overrides taking them into account.

PR Close #31415
2019-07-11 18:27:13 -04:00
crisbeto ef44f51d58 refactor(ivy): remove instruction usage from other instructions (#31456)
Removes direct calls from one instruction into another, moves the shared logic into a separate function and removes the state getters from the shared function.

This PR resolves FW-1340.

PR Close #31456
2019-07-11 15:10:20 -04:00
Andrew Kushnir dee16a4355 fix(ivy): update ICU placeholders format to match Closure compiler (#31459)
Since `goog.getMsg` does not process ICUs (post-processing is required via goog.i18n.MessageFormat, https://google.github.io/closure-library/api/goog.i18n.MessageFormat.html) and placeholder format used for ICUs and regular messages inside `goog.getMsg` are different, the current implementation (that assumed the same placeholder format) needs to be updated. This commit updates placeholder format used inside ICUs from `{$placeholder}` to `{PLACEHOLDER}` to better align with Closure. ICU placeholders (that were left as is prior to this commit) are now replaced with actual values in post-processing step (inside `i18nPostprocess`).

PR Close #31459
2019-07-10 18:31:33 -04:00
Andrew Kushnir 6da1446afc fix(ivy): handle &ngsp; in i18n translations correctly (#31479)
Prior to this commit, the `` unicode symbol that represents `&ngsp` in translations was not handled correctly, i.e. was not replaced with a whitespace, thus appearing on a screen. This commit adds post-processing and replaces the mentioned symbol with a whitespace.

PR Close #31479
2019-07-10 18:29:32 -04:00
Olivier Combe 2b44be984e fix(ivy): i18n should not alloc expando slots when there is no new var (#31451)
`i18nStart` was calling `allocExpando` even if there was 0 new variable created.
This created a new expando instruction with the value 0 which was later interpreted as the start of a new expando block instead of just skipping 0 instructions.

FW-1417 #resolve

PR Close #31451
2019-07-09 14:31:10 -07:00
crisbeto 989ebcbb62 fix(ivy): inconsistent value returned by DebugNode.context (#31442)
Fixes Ivy's return value for `DebugNode.context` not being consistent for the case where there is both a structural directive and a component on a node. In `ViewEngine` the instance of the component would be returned, whereas in Ivy the context of the directive is returned.

Also adds a couple of extra test cases for how `DebugNode.context` deals with directives.

This PR resolves FW-1343.

PR Close #31442
2019-07-09 13:50:51 -07:00
crisbeto 23e0d65471 perf(ivy): add self-closing elementContainer instruction (#31444)
Adds a new `elementContainer` instruction that can be used to avoid two instruction (`elementContainerStart` and `elementContainerEnd`) for `ng-container` that has text-only content. This is particularly useful when we have `ng-container` inside i18n sections.

This PR resolves FW-1105.

PR Close #31444
2019-07-09 13:50:28 -07:00
crisbeto e30f494a39 refactor(ivy): remove interpolation instructions (#31395)
Makes the `interpolateX` instructions internal-only and removes their use of global state.

This PR resolves FW-1387.

PR Close #31395
2019-07-08 09:34:13 -07:00
crisbeto 02491a6ce8 refactor(ivy): move classMap interpolation logic internally (#31211)
Adds the new `classMapInterpolate1` through `classMapInterpolate8` instructions which handle interpolations inside the `class` attribute and moves the interpolation logic internally. This allows us to remove the `interpolationX` instructions in a follow-up PR.

These changes also add an error if an interpolation is encountered inside a `style` tag (e.g. `style="width: {{value}}"`). Up until now this would actually generate valid instructions, because `styleMap` goes through the same code path as `classMap` which does support interpolation. At runtime, however, `styleMap` would set invalid styles that look like `<div style="0:w;1:i;2:d;3:t;4:h;5::;7:1;">`. In `ViewEngine` interpolations inside `style` weren't supported either, however there we'd output invalid styles like `<div style="unsafe">`, even if the content was trusted.

PR Close #31211
2019-07-02 11:07:14 -07:00
Greg Magolan 361109d80f build: update to rules_nodejs 0.32.2 (#31325)
Brings in ts_library fixes required to get angular/angular building after 0.32.0:
typescript: exclude typescript lib declarations in node_module_library transitive_declarations
typescript: remove override of @bazel/tsetse (+1 squashed commit)

@npm//node_modules/foobar:foobar.js labels changed to @npm//:node_modules/foobar/foobar.js with fix for bazelbuild/rules_nodejs#802

also updates to rules_rass commit compatible with rules_nodejs 0.32.0

PR Close #31325
2019-07-01 14:16:42 -07:00
Alan f83dfd6f5a fix(core): handle `undefined` meta in `injectArgs` (#31333)
In the recent versions of the CLI we introduced a ctor downleveler tranformer for VE JIT builds based on the one found in tsickle, to fix the TDZ issue of `forwardRef`.

However this caused a regression as the injector is not handling that a position `paramType` can be undefined. Which is bubbled down to c6b29f4c6d/packages/core/src/di/injector_compatibility.ts (L162) and will crash c6b29f4c6d/packages/core/src/di/injector_compatibility.ts (L174-L186)

Fixes https://github.com/angular/angular-cli/issues/14888

PR Close #31333
2019-07-01 10:11:08 -07:00
Pawel Kozlowski 7ca611cd12 fix(ivy): properly handle re-projection with an empty set of nodes to re-project (#31306)
PR Close #31306
2019-06-28 12:21:37 -07:00
Andrew Kushnir c12b6fa028 fix(ivy): attach host element for views created via TestBed.createComponent (#31318)
Prior to this commit, host element of a view created via TestBed.createComponent was not attached to the component's host, making it problematic to use TestBed.createComponent API in component factories, which might be used for testing purposes only. This behavior is observed in google3 app tests and was supported by VE, so this commit aligns Ivy and VE.

PR Close #31318
2019-06-28 12:20:53 -07:00
Olivier Combe 4f38419e33 fix(ivy): handle ICU expressions in `executeActionOnNode` (#31313)
When `walkTNodeTree` was refactored, the case of ICU expressions was forgotten (because it was handled in the `else` previously).
This PR fixes that to handle it like `ElementContainer`.

FW-1411 #resolve
PR Close #31313
2019-06-27 15:53:10 -07:00
Kristiyan Kostadinov f2360aab9d fix(ivy): incorrect namespace for root node created through ViewContainerRef (#31232)
Currently in Ivy whenever we encounter a new namespace, we set it in the global state so that all subsequent nodes are created under the same namespace. Next time a template is run the namespace will be reset back to HTML.

This breaks down if the last node that was rendered was under the SVG or MathML namespace and we create a component through `ViewContainerRef.create`, because the next template function hasn't run yet and it hasn't had the chance to update the namespace. The result is that the root node of the new component will retain the wrong namespace and may not end up rendering at all (e.g. if we're trying to show a `div` inside the SVG namespace). This issue has the potential to affect a lot of apps, because all components inserted through the router also go through `ViewContainerRef.create`.

PR Close #31232
2019-06-27 09:50:52 -07:00
Alex Rickabaugh 32c760f5e7 fix(ivy): don't mask errors by calling lifecycle hooks after a crash (#31244)
The Angular runtime frequently calls into user code (for example, when
writing to a property binding). Since user code can throw errors, calls to
it are frequently wrapped in a try-finally block. In Ivy, the following
pattern is common:

```typescript
enterView();
try {
  callUserCode();
} finally {
  leaveView();
}
```

This has a significant problem, however: `leaveView` has a side effect: it
calls any pending lifecycle hooks that might've been scheduled during the
current round of change detection. Generally it's a bad idea to run
lifecycle hooks after the application has crashed. The application is in an
inconsistent state - directives may not be instantiated fully, queries may
not be resolved, bindings may not have been applied, etc. Invariants that
the app code relies upon may not hold. Further crashes or broken behavior
are likely.

Frequently, lifecycle hooks are used to make assertions about these
invariants. When these assertions fail, they will throw and "swallow" the
original error, making debugging of the problem much more difficult.

This commit modifies `leaveView` to understand whether the application is
currently crashing, via a parameter `safeToRunHooks`. This parameter is set
by modifying the above pattern:

```typescript
enterView();
let safeToRunHooks = false;
try {
  callUserCode();
  safeToRunHooks = true;
} finally {
  leaveView(..., safeToRunHooks);
}
```

If `callUserCode` crashes, then `safeToRunHooks` will never be set to `true`
and `leaveView` won't call any further user code. The original error will
then propagate back up the stack and be reported correctly. A test is added
to verify this behavior.

PR Close #31244
2019-06-26 08:01:14 -07:00
Pawel Kozlowski 4fe0e75365 refactor(ivy): rename applyXYZ to executeActionOnXYZ for clarity (#31182)
PR Close #31182
2019-06-25 17:03:52 -07:00
Misko Hevery 29a9909232 refactor(ivy): simplify `walkTNodeTree` method for readability (#31182)
PR Close #31182
2019-06-25 17:03:51 -07:00
Alex Rickabaugh 660800ca4e Revert "build: update to rules_nodejs 0.32.2 (#31019)" (#31267)
This reverts commit a38433f36b.

Reason: this causes failures in g3 with i18n extraction. See #31267.

PR Close #31267
2019-06-25 14:36:00 -07:00
Greg Magolan a38433f36b build: update to rules_nodejs 0.32.2 (#31019)
Brings in ts_library fixes required to get angular/angular building after 0.32.0:
typescript: exclude typescript lib declarations in node_module_library transitive_declarations
typescript: remove override of @bazel/tsetse (+1 squashed commit)

@npm//node_modules/foobar:foobar.js labels changed to @npm//:node_modules/foobar/foobar.js with fix for bazelbuild/rules_nodejs#802

also updates to rules_rass commit compatible with rules_nodejs 0.32.0

PR Close #31019
2019-06-25 10:21:07 -07:00
crisbeto 23c017121e perf(ivy): chain multiple attribute instructions (#31152)
Similarly to what we did in #31078, these changes implement chaining for the `attribute` instruction.

This PR resolves FW-1390.

PR Close #31152
2019-06-24 12:33:49 -07:00
crisbeto fcb03abc72 fix(ivy): injecting incorrect Renderer2 into child components (#31063)
In ViewEngine injecting a Renderer2 returns a renderer that is specific to the particular component, however in Ivy we inject the renderer for the parent view instead. This causes it to set incorrect `ngcontent` attributes when creating elements through the renderer.

The issue comes from the fact that the `Renderer2` is created according to the current `LView`, but because DI happens before we've entered the `LView` of the component that's injecting the renderer, we end up with one that's one level up. We work around the issue by finding the `LView` that corresponds to the `previousOrParentTNode` inside of the parent view and associating the `Renderer2` with it.

This PR resolves FW-1382.

PR Close #31063
2019-06-24 11:33:31 -07:00
Alex Rickabaugh bd3b0564e6 fix(ivy): sync ViewRefs between multiple ViewContainerRefs (#30985)
Previously, multiple ViewContainerRef instances (obtained by injecting
ViewContainerRef multiple times) each had private state that could be out of
sync with actual LContainer, if views were inserted/removed/queried across
the different instances. In particular each instance had its own array which
tracked ViewRefs inserted via that instance.

This commit moves the ViewRefs array onto the LContainer itself, so that it
can be shared across multiple ViewContainerRef instances. A test is added
that verifies ViewContainerRefs now provide a consistent view of the
container.

FW-1377 #resolve

PR Close #30985
2019-06-21 10:18:06 -07:00
Olivier Combe 7ff628f8d5 refactor(ivy): make `bind` an internal-only function (#31131)
The function `bind` has been internalized wherever it was needed, this PR makes sure that it is no longer publicly exported.

FW-1385 #resolve
PR Close #31131
2019-06-20 17:20:56 -07:00
Alex Eagle db08fd2607 build: enable shard_count for some jasmine tests that have many specs (#31009)
This partitions the spects across multiple processes so they run in parallel.

PR Close #31009
2019-06-18 12:11:30 -07:00
Olivier Combe 65544ac742 fix(ivy): reprojected ICU expression nodes when creating embedded views (#30979)
When using `createEmbeddedView` after the creation of an ICU expression, the nodes for the current selected case were not reprojected (only the anchor comment node was moved to the new location).
Now we reproject correctly all the child nodes of an ICU expression when an anchor comment node is projected.

FW-1372 #resolve

PR Close #30979
2019-06-18 09:48:46 -07:00
Ben Lesh 16aa6ceff8 refactor(ivy): update ɵɵtextBinding to not take index (#30792)
- Splits core functionality off into a shared internal function
- ɵɵtextBinding will no longer require an index
- Alters the compiler to stop generating an index argument for the instruction
- Updates tests
- Updates some usage of ɵɵtextBinding in i18n to use the helper function instead

PR Close #30792
2019-06-14 12:22:11 -07:00
crisbeto 8f5c396a7c fix(ivy): don't throw when attempting to destroy a destroyed ComponentRef (#31022)
Currently in Ivy we throw when attempting to destroy a `ComponentRef` that has been destroyed, however in ViewEngine we didn't which can cause some tests to break. These changes remove the error to match ViewEngine.

These changes resolve FW-1379.

PR Close #31022
2019-06-14 10:44:30 -07:00
Paul Gschwendtner 58be2ff884 fix(ivy): unable to bind to implicit receiver in embedded views (#30897)
To provide some context: The implicit receiver is part of the
parsed Angular template AST. Any property reads in bindings,
interpolations etc. read from a given object (usually the component
instance). In that case there is an _implicit_ receiver which can also
be specified explicitly by just using `this`.

e.g.

```html
<ng-template>{{this.myProperty}}</ng-template>
```

This works as expected in Ivy and View Engine, but breaks in case the
implicit receiver is not used for property reads. For example:

```html
<my-dir [myFn]="greetFn.bind(this)"></my-dir>
```

In that case the `this` will not be properly translated into the generated
template function code because the Ivy compiler currently always treats
the `ctx` variable as the implicit receiver. This is **not correct** and breaks
compatibility with View Engine. Rather we need to ensure that we retrieve
the root context for the standalone implicit receiver similar to how it works
for property reads (as seen in the example above with `this.myProperty`)

Note that this requires some small changes to the `expression_converter`
because we only want to generate the `eenextContent()` instruction if the
implicit receiver is _actually_ used/needed. View Engine determines if that is the case by recursively walking through the converted output AST and
checking for usages of the `o.variable('_co')` variable ([see here][ve_check]). This would work too for Ivy, but involves most likely more code duplication
since templates are isolated in different functions and it another pass
through the output AST for every template expression.

[ve_check]: 0d6c9d36a1/packages/compiler/src/view_compiler/view_compiler.ts (L206-L208)

Resolves FW-1366.

PR Close #30897
2019-06-11 14:29:42 -07:00
Alex Rickabaugh 7912db3829 fix(ivy): call factory functions with correct type for derived classes (#30855)
In a derived service class with no decorator (and therefore no factory) of
its own, the factory function of the base class will be used instead.
Previously this logic had a bug where the factory function would be called
with no arguments, which would incorrectly create an instance of the base
class.

This commit adds logic to call the base class' factory and pass the type of
the derived class, which will correctly construct an instance of the
derived class using the base class' factory. A test is also added to verify
correctness of this behavior.

PR Close #30855
2019-06-11 14:27:17 -07:00
Alex Rickabaugh 0ee09cdd7e refactor(ivy): fix type of factory functions to allow explicit types (#30855)
Factory functions written by the compiler optionally allow an explicit type
to be passed. If called with this type, an instance of the given type will
be created instead of the type for which the factory was generated. This is
used to power inheritance of Angular types, as if the constructor of a class
is inherited from its superclass, then the factory function of the
superclass must be used (it has all the DI info) to construct an instance of
the derived class.

This commit adjusts typings in a few places to allow factory functions to be
called with this extra type parameter.

PR Close #30855
2019-06-11 14:27:17 -07:00
Alex Rickabaugh a4b4f35533 feat(ivy): require 'token' for ngInjectableDef (#30855)
The compiler generates a 'token' field when it emits an ngInjectableDef,
but this field was not required by defineInjectable or the InjectableDef
interface, nor was it added by InjectionToken.

This commit makes 'token' required and adds it where missing.

PR Close #30855
2019-06-11 14:27:16 -07:00
Paul Gschwendtner 8c4bd61b2f test(core): add missing static flag to view_insertion test view queries (#30967)
17d87d4e10 has been created before the changes
to the `@ViewChild` and `@ContentChild` decorators. Meaning that it still uses the queries
without the `static` flag. This results in failures in `master` because #30625 has been merged.

PR Close #30967
2019-06-11 09:37:19 -07:00
Olivier Combe 4155ed439a fix(ivy): correctly set `TView.firstChild` with runtime i18n (#30920)
`TView.firstChild` was defined as the first node with index 0, but when we use runtime i18n then the instruction `i18nStart` can be the one with index 0 and the first node will be index 1 or more.
With this fix we set `TView.firstChild` when we see the first node with index 0 or later if `TView.firstChild` is still null.

FW-1367 #resolve
PR Close #30920
2019-06-11 00:09:32 +00:00
Alex Eagle ef0b2cc74d build: convert entry_point to label (#30627)
PR Close #30627
2019-06-11 00:03:11 +00:00
Ben Lesh 17d87d4e10 test(ivy): Add acceptance tests for view insertion (#30625)
This work is being done ahead of changes to how view insertion is done in Ivy in accordance with [this design document](https://hackmd.io/Ae3W_2pOQlKouu9YNy1t6A?view).

The idea is to make sure we have acceptance tests ahead of that change.

PR Close #30625
2019-06-10 23:53:34 +00:00
Ben Lesh c0386757b1 refactor(ivy): inherently call ɵɵselect(0) (#30830)
- Refactors compiler to stop generating `ɵɵselect(0)` instructions
- Alters template execution to always call the equivalent of `ɵɵselect(0)` before running a template in update mode
- Updates tests to not check for or call `ɵɵselect(0)`.

The goal here is to reduce the size of generated templates

PR Close #30830
2019-06-07 08:48:31 -07:00
Pawel Kozlowski 11a4454ab3 perf(ivy): remove check for function type in renderStringify (#30838)
The `renderStringify` function shows up pretty high in the CPU profiling.
Turns out that this function contained unnecessary `typeof` check for
function types - the check only makes sense / is used in error messages.

The PR also alligns how ivy and view engine stringify functions used in
interpolations.

PR Close #30838
2019-06-06 13:47:41 -07:00
crisbeto 04587a33c5 fix(ivy): DebugNode.attributes not preserving attribute name casing (#30864)
In Ivy the `DebugNode.attributes` is populated directly from the DOM, but the problem is that the browser will lowercase all attribute names. These changes preserve the case by first going through the `TNode.attrs`, populating the map with the case-sensitive names and saving a reference to the lower case name. Afterwards when we're going through the attributes from the DOM, we can check whether we've mapped the attribute by its case-sensitive name already.

This PR resolves FW-1358.

PR Close #30864
2019-06-06 13:47:16 -07:00
Olivier Combe b4b7af86c2 fix(ivy): trigger directive inputs for each template creation (#30870)
A directive input that doesn't use a binding is triggered during the creation phase. But this was only executed at the first template pass, and not on subsequent ones.
Now only the creation of the update instruction is executed on the first template pass, anything else is executed every time a template is created.

FW-1361 #resolve
PR Close #30870
2019-06-06 13:46:40 -07:00
Ben Lesh 3859bcc70c refactor(ivy): remove ɵɵelementAttribute instruction (#30640)
PR Close #30640
2019-06-05 21:29:38 -07:00
Olivier Combe 30efb6b8ea fix(ivy): don't project removed placeholders with runtime i18n (#30783)
When translated content was projected, all of the content was reappended, even the placeholders that had been removed in the translation.
To avoid that we added a new flag on `TNode` that specifies that a node is detached, in which case it should be ignored by the projection.

FW-1319 #resolve
PR Close #30783
2019-06-05 21:28:39 -07:00
Ben Lesh d1df0a94d4 refactor(ivy): remove ɵɵelementProperty instruction (#30645)
- Removes ɵɵelementProperty instruction
- Updates tests that were using it
- NOTE: There is one test under `render3/integration_spec.ts` that is commented out, and needs to be reviewed. Basically, I could not find a good why to test what it was doing, because it was doing things that I am not sure we could generate in an acceptance test.

PR Close #30645
2019-06-05 09:04:43 -07:00
Olivier Combe 00cc905b98 feat(ivy): support `ng-content` in runtime i18n translations (#30782)
Added a new syntax for projections (`¤` will represent `ng-content` nodes) so that we can treat them specifically.
When we enter an i18n block with the instruction `i18nStart`, a new `delayProjection` variable is set to true to prevent the instruction `projection` from projecting the nodes. Once we reach the `i18nEnd` instruction and encounter a projection in the translation we will project its nodes.
If a projection was removed from a translation, then its nodes won't be projected at all.
The variable `delayProjection` is restored to `false` at the end of `i18nEnd` so that it doesn't stop projections outside of i18n blocks.

FW-1261 #resolve
PR Close #30782
2019-06-05 09:04:13 -07:00
Olivier Combe 0d4f8c7dd9 fix(ivy): allow empty cases for ICU expressions (#30846)
We used to ignore empty strings for optimization purposes, but it turns out that empty strings are also valid values for ICU cases and we shouldn't ignore those.

FW-1290 #resolve
PR Close #30846
2019-06-04 13:36:28 -07:00
Miško Hevery 55a14e4866 feat(ivy): in `ngDevMode` use named object literals and arrays for easier debugging/profiling (#30542)
PR Close #30542
2019-06-04 12:01:46 -07:00
Miško Hevery c7850fff3b refactor(ivy): rename debug.ts to lview_debug.ts (#30542)
PR Close #30542
2019-06-04 12:01:46 -07:00
Misko Hevery fcdd784667 refactor(core): cleanup code with side-effects which was preventing tree-shaking (#30580)
PR Close #30580
2019-06-03 09:01:51 -07:00
Olivier Combe 680d38513b fix(ivy): correctly project bare ICU expressions (#30696)
Projecting bare ICU expressions failed because we would assume that component's content nodes would be projected later and doing so at that point would be wasteful. But ICU nodes are handled independently and should be inserted immediately because they will be ignored by projections.

FW-1348 #resolve

PR Close #30696
2019-06-03 08:59:14 -07:00
crisbeto f936590573 fix(ivy): DebugNode.queryAll matching sibling nodes (#30788)
Inside of `DebugNode.queryAll` we walk through all of the descendants of the node that we're querying against, however the logic that walks sideways through a node siblings also applies to the root node. This means that eventually we'll match against its nodes as well which will give us invalid results. These changes add an extra check to ensure that we aren't matching against the siblings of the root node.

This PR resolves FW-1353.

PR Close #30788
2019-05-31 15:19:18 -07:00
Paul Gschwendtner aca339e864 fix(ivy): unable to project into multiple slots with default selector (#30561)
With View engine it was possible to declare multiple projection
definitions and to programmatically project nodes into the slots.

e.g.

```html
<ng-content></ng-content>
<ng-content></ng-content>
```

Using `ViewContainerRef#createComponent` allowed projecting
nodes into one of the projection defs (through index)

This no longer works with Ivy as the `projectionDef` instruction only
retrieves a list of selectors instead of also retrieving entries for
reserved projection slots which appear when using the default
selector multiple times (as seen above).

In order to fix this issue, the Ivy compiler now passes all
projection slots to the `projectionDef` instruction. Meaning that
there can be multiple projection slots with the same wildcard
selector. This allows multi-slot projection as seen in the
example above, and it also allows us to match the multi-slot node
projection order from View Engine (to avoid breaking changes).

It basically ensures that Ivy fully matches the View Engine behavior
except of a very small edge case that has already been discussed
in FW-886 (with the conclusion of working as intended).

Read more here: https://hackmd.io/s/Sy2kQlgTE

PR Close #30561
2019-05-31 09:52:32 -07:00
Paul Gschwendtner 6d861f240b fix(ivy): module with providers are processed too early (#30688)
Currently with Ivy, `ModuleWithProvider` providers are processed in order
of declaration in the `NgModule` imports. This technically makes makes
sense but is a potential breaking change as `ModuleWithProvider` providers
are processed after all imported modules in View Engine.

In order to keep the behavior of View Engine, the `r3_injector` is updated
to no longer process `ModuleWithProvider` providers egarly.

Resolves FW-1349

PR Close #30688
2019-05-31 09:48:39 -07:00
Alex Rickabaugh d82adbe8c4 fix(ivy): align DebugNode/DebugElement behavior with View Engine (#30756)
Two issues with DebugNode/DebugElement in Ivy were causing problems in user
tests.

1. The DebugNodes returned by Ivy were not actually instances of DebugNode.

This was due to an issue with the Ivy switch logic in debug_node.ts.
The declaration of the exported DebugNode reference was set to
`DebugNode__PRE_R3__ as any`. The cast prevented the Ivy switch transform
from detecting this as a switchable declaration. The transform cannot handle
arbitrary syntax, and exports *must* be of the form "const x = y__PRE_R3__;"
or they will not work. The cast to any in this case was not needed, so this
commit removes it.

2. DebugNodes returned by Ivy multiple times for the same element were not
reference-identical. This was previously considered a minor breaking change
in Ivy, but testing has shown that users depend on referential equality of
DebugNodes. This commit caches a DebugNode on a DOM node when first creating
it, to allow returning the same instance in subsequent operations.

PR Close #30756
2019-05-30 20:45:31 -07:00
Matias Niemelä 19bbf4bc8e test(ivy): fix sanitization state leaking issue
Due to sanitization being stored as a temp/global value between
instructions, unit tests randomly failed because one test failed
to clean up its temporary value. This patch fixes this issue.
2019-05-30 13:53:06 -07:00
Olivier Combe 91699259b2 fix(ivy): trigger directive inputs with i18n translations (#30402)
Changed runtime i18n to define attributes with bindings, or matching directive inputs/outputs as element properties as we are supposed to do in Angular.
This PR fixes the issue where directive inputs wouldn't be trigged.

FW-1315 #resolve
PR Close #30402
2019-05-30 16:39:24 -04:00