249 Commits

Author SHA1 Message Date
Andrew Kushnir
0fecea1427 fix(ivy): reset style property value defined using [style.prop.px] ()
Prior to this change, setting style prop value to undefined or empty string would not result in resetting prop value in case the style prop is defined using [style.prop.px] syntax. The problem is that the check for empty value (and thus reseting the value) considered successful only in case of `null` value. This commit updates the check to use `isStylingValueDefined` function that also checks for undefined and empty string.

PR Close 
2019-11-13 13:32:33 -08:00
Andrew Kushnir
cf10b336e7 fix(ivy): ComponentFactory.create should clear host element content ()
Prior to this change, ComponentFactory.create function invocation in Ivy retained the content of the host element (in case host element reference or CSS seelctor is provided as an argument). This behavior is different in View Engine, where the content of the host element was cleared, except for the case when ShadowDom encapsulation is used (to make sure native slot projection works). This commit aligns Ivy and View Engine and makes sure the host element is cleared before component content insertion.

PR Close 
2019-11-12 21:34:06 -08:00
Pawel Kozlowski
84a0105625 test(ivy): view insertion before ng-container with a ViewContainerRef ()
Closes 

PR Close 
2019-11-12 14:07:31 -08:00
Misko Hevery
b62b11bd6b fix(ivy): Run ChangeDetection on transplanted views ()
https://hackmd.io/@mhevery/rJUJsvv9H

Closes 

PR Close 
2019-11-12 13:53:54 -08:00
Pawel Kozlowski
39712bcdb2 test(ivy): get ViewRef.rootNodes should get all root nodes from projectable nodes ()
PR Close 
2019-11-11 09:37:38 -08:00
Pawel Kozlowski
05d7c575e4 fix(ivy): properly insert views in front of empty views ()
PR Close 
2019-11-11 09:37:38 -08:00
Pawel Kozlowski
056236cafd fix(ivy): properly insert views in front of views with an empty element container ()
PR Close 
2019-11-11 09:37:38 -08:00
Pawel Kozlowski
f63e5d9319 fix(ivy): properly determine the first native node of a view ()
PR Close 
2019-11-07 16:50:29 -08:00
Pawel Kozlowski
c57759f191 test(ivy): tests for view insertion before another view ()
PR Close 
2019-11-07 16:50:29 -08:00
JoostK
bca437617f fix(ivy): match directives on namespaced elements ()
Prior to this change, namespaced elements such as SVG elements would not
participate correctly in directive matching as their namespace was not
ignored, which was the case with the View Engine compiler. This led to
incorrect behavior at runtime and template type checking.

This commit resolved the issue by ignoring the namespace of elements and
attributes like they were in View Engine.

Fixes 

PR Close 
2019-11-07 15:40:50 +00:00
Miško Hevery
c25503b142 test(ivy): Have more descriptive names for LView ()
When debugging `LView`s it is easy to get lost since all of them have
the same name. This change does three things:

1. It makes `TView` have an explicit type:
  - `Host`: for the top level `TView` for bootstrap
  - `Component`: for the `TView` which represents components template
  - `Embedded`: for the `TView` which represents an embedded template
2. It changes the name of `LView` to `LHostView`, `LComponentView`, and
  `LEmbeddedView` depending on the `TView` type.
3. For `LComponentView` and `LEmbeddedView` we also append the name of
  of the `context` constructor. The result is that we have `LView`s which
  are name as: `LComponentView_MyComponent` and `LEmbeddedView_NgIfContext`.

The above changes will make it easier to understand the structure of the
application when debugging.

NOTE: All of these are behind `ngDevMode` and will get removed in
production application.

PR Close 
2019-11-07 15:33:50 +00:00
Andrew Kushnir
39550746f8 fix(ivy): better support for i18n attributes on <ng-container>s ()
Prior to this commit, i18n runtime logic used `elementAttributeInternal` function (that uses `setAttribute` function under the hood) for all elements where i18n attributes are present. However the `<ng-container>` elements in a template may also have i18n attributes and calling `setAttribute` fails, since they are represented as comment nodes in DOM. This commit ensures that we call `setAttribute` on nodes with TNodeType.Element type (that support that operation) only.

PR Close 
2019-11-07 01:51:42 +00:00
JiaLiPassion
8c6fb17d29 build: reference zone.js from source directly instead of npm. ()
Close 

PR Close 
2019-11-06 00:48:34 +00:00
Matias Niemelä
91147ade2e refactor(ivy): introduce a firstUpdatePass flag for TView instances ()
This patch introduces a `firstUpdatePass` flag which can be used inside
of instruction code to determine if this is the first time each
instruction is running inside of the update block of a template or
a hostBindings function.

PR Close 
2019-11-04 21:39:22 +00:00
crisbeto
c83f5013bf feat(ivy): implement unknown element detection in jit mode ()
In ViewEngine we used to throw an error if we encountered an unknown element while rendering. We have this already for Ivy in AoT, but we didn't in JiT. These changes implement the error for JiT mode.

PR Close 
2019-11-04 15:59:10 +00:00
Pawel Kozlowski
300d7ca6da test(ivy): remove code duplication from the EmbeddedView.rootNodes tests ()
PR Close 
2019-10-30 11:46:09 -07:00
Pawel Kozlowski
563a507315 fix(ivy): descend into ICU containers when collecting rootNodes ()
PR Close 
2019-10-30 11:46:09 -07:00
Pawel Kozlowski
a5167bd53c fix(ivy): descend into view containers on ng-container when collecting rootNodes ()
PR Close 
2019-10-30 11:46:09 -07:00
Pawel Kozlowski
87743f1aa1 fix(ivy): descend into view containers on elements when collecting rootNodes ()
PR Close 
2019-10-30 11:46:09 -07:00
Pawel Kozlowski
502fb7e307 fix(ivy): descend into view containers on ng-template when collecting rootNodes ()
PR Close 
2019-10-30 11:46:09 -07:00
Andrew Kushnir
bd40c89688 fix(ivy): handle elements with local refs in i18n blocks ()
Prior to this commit, i18n logic which ensures that elements removed in a translation are also removed in DOM, didn't take into account the fact that elements may have local refs. As a result, remove operation failed, since there is no corresponding tNode found. This commit updates the logic to skip all local refs while going though the list of nodes to ensure that DOM matches elements present in translation.

PR Close 
2019-10-29 11:47:28 -07:00
Miško Hevery
e16f75db56 refactor(ivy): move bindingIndex from LView to LFrame ()
`bindingIndex` stores the current location of the bindings in the
template function. Because it used to be stored in `LView` that `LView`
was not reentrant. This could happen if a binding was a getter and had
a side-effect of calling `detectChanges()`.

By moving the `bindingIndex` to `LFrame` where all of the global state
is kept in reentrant way we correct the issue.

PR Close 
2019-10-28 10:59:29 -07:00
crisbeto
14c4b1b205 refactor(ivy): remove ngBaseDef ()
Removes `ngBaseDef` from the compiler and any runtime code that was still referring to it. In the cases where we'd previously generate a base def we now generate a definition for an abstract directive.

PR Close 
2019-10-25 13:11:34 -07:00
Alex Rickabaugh
818c514968 feat(ivy): add a runtime feature to copy cmp/dir definitions ()
This commit adds CopyDefinitionFeature, which supports the case where an
entire decorator (@Component or @Directive) is inherited from parent to
child.

The existing inheritance feature, InheritDefinitionFeature, supports merging
of parent and child definitions when both were originally present. This
merges things like inputs, outputs, host bindings, etc.

CopyDefinitionFeature, on the other hand, compensates for a definition that
was missing entirely on the child class, by copying fields that aren't
ordinarily inherited (like the template function itself).

This feature is intended to only be used as part of ngcc code generation.

PR Close 
2019-10-25 09:16:50 -07:00
Matias Niemelä
dcdb433b7d perf(ivy): apply [style]/[class] bindings directly to style/className ()
This patch ensures that the `[style]` and `[class]` based bindings
are directly applied to an element's style and className attributes.

This patch optimizes the algorithm so that it...
- Doesn't construct an update an instance of `StylingMapArray` for
  `[style]` and `[class]` bindings
- Doesn't apply `[style]` and `[class]` based entries using
  `classList` and `style` (direct attributes are used instead)
- Doesn't split or iterate over all string-based tokens in a
  string value obtained from a `[class]` binding.

This patch speeds up the following cases:
- `<div [class]>` and `<div class="..." [class]>`
- `<div [style]>` and `<div style="..." [style]>`

The overall speec increase is by over 5x.

PR Close 
2019-10-24 17:42:46 -07:00
Miško Hevery
09a2bb839f refactor(ivy): Intruduce LFrame to store global instruction information ()
`LFrame` stores information specifice to the current `LView` As the code
enters and leaves `LView`s we use `enterView()` and `leaveView()`
respectively to build a a stack of `LFrame`s. This allows us to easily
restore the previous `LView` instruction state.

PR Close 
2019-10-24 14:42:15 -07:00
Miško Hevery
5632424d04 refactor(ivy): ViewRef needs embededViewRef declaration ()
PR Close 
2019-10-22 12:00:21 -07:00
Matias Niemelä
7b64680670 fix(ivy): ensure map-based interpolation works with other map-based sources ()
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 
2019-10-17 18:24:10 -04:00
Matias Niemelä
f45c43188f fix(ivy): ensure errors are thrown during checkNoChanges for style/class bindings ()
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 
2019-10-17 16:46:49 -04:00
crisbeto
9d54679e66 test: clean up explicit dynamic query usages ()
Cleans up all the places where we explicitly set `static: false` on queries.

PR Close 
2019-10-17 16:10:10 -04:00
Andrew Kushnir
7e64bbe5a8 fix(ivy): use container i18n meta if a message is a single ICU ()
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 

PR Close 
2019-10-17 16:07:07 -04:00
Andrew Kushnir
6f203c9575 fix(ivy): handling className as an input properly ()
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 
2019-10-17 14:16:02 -04:00
Andrew Kushnir
11e04b1892 fix(ivy): avoid DOM element assertions if procedural renderer is used ()
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 
2019-10-15 21:03:29 +00:00
Matias Niemelä
1cda80eb3a fix(ivy): ensure sanitizer is not used when direct class application occurs ()
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 
2019-10-15 16:50:43 +00:00
Matias Niemelä
35a95a8a7e refactor(ivy): ensure StylingDebug instances provide context debug info ()
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 
2019-10-10 13:59:32 -07:00
Kristiyan Kostadinov
3efb060127 fix(ivy): unable to bind style zero ()
Fixes not being able to bind zero as a value in style bindings.

Fixes .

PR Close 
2019-10-07 11:00:19 -07:00
Andrew Kushnir
90fb5d9f7a fix(ivy): generate ng-reflect properties for i18n attributes ()
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 
2019-10-07 10:50:44 -07:00
Pawel Kozlowski
60047037a3 perf(ivy): attempt rendering initial styling only if present ()
PR Close 
2019-10-04 11:44:57 -07:00
Pete Bacon Darwin
9188751adc fix(ivy): i18n - do not render message ids unnecessarily ()
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 
2019-10-02 14:52:00 -07:00
crisbeto
4e35e348af refactor(ivy): generate ngFactoryDef for injectables ()
With  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 
2019-10-02 13:04:26 -07:00
Andrew Scott
72f3747d7b fix(ivy): refresh child components before executing ViewQuery function ()
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 
2019-10-01 14:47:15 -07:00
Matias Niemelä
c32b2ae0a8 fix(ivy): ensure class/style values are debuggable through DebugElement ()
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 
2019-09-30 14:14:00 -07:00
Andrew Kushnir
966c2a326a fix(ivy): include ngProjectAs into attributes array ()
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 
2019-09-27 10:12:18 -07:00
Matias Niemelä
a54adcaff0 test(ivy): remove extra implementation of getDebugNode ()
PR Close 
2019-09-25 11:27:33 -07:00
Matias Niemelä
948714c17c revert: refactor(ivy): ensure StylingDebug instances provide context debug info () ()
This reverts commit f8f7c1540a3b667a85887b881a456070b285cb6e.

PR Close 
2019-09-24 16:57:58 -07:00
Matias Niemelä
86fd5719b5 fix(ivy): ensure multiple map-based bindings do not skip intermediate values ()
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 
2019-09-24 11:58:52 -07:00
Matias Niemelä
f8f7c1540a refactor(ivy): ensure StylingDebug instances provide context debug info ()
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 
2019-09-24 10:37:42 -07:00
Matias Niemelä
5651fa3a95 fix(ivy): ensure window.ng.getDebugNode returns debug info for component elements ()
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 
2019-09-23 14:32:42 -07:00
Matias Niemelä
0618bed83e refactor(ivy): combine styling testing files into one ()
PR Close 
2019-09-18 15:06:38 -07:00
Matias Niemelä
4726ac2481 feat(ivy): expose window.ng.getDebugNode helper ()
PR Close 
2019-09-17 15:46:07 -07:00