Commit Graph

14 Commits

Author SHA1 Message Date
George Kalpakas 89b44d1900 fix(elements): do not break when the constructor of an Angular Element is not called (#36114)
Previously, the correct behavior of Angular custom elements relied on
the constructor being called (and thus the `injector` property being
initialized). However, some polyfills (e.g. `document-register-element`)
do not call the constructor of custom elements, which resulted in the
`injector` property being undefined and the `NgElementStrategy` failing
to be instantiated.

This commit fixes it by being tolerant to the `injector` property being
undefined and falling back to the injector passed to the
`createCustomElement()` config.

NOTE:
We don't have proper tests exercising the situation where the
constructor is not called. For now this is tested using a Google
internal test suite (which is how this issue was caught).
This commit also adds a rudimentary unit test to emulate this situation.

PR Close #36114
2020-05-20 09:43:36 -07:00
George Kalpakas 2fc5ae561b fix(elements): capture input properties set before upgrading the element (#36114)
Previously, if an element started out as a regular `HTMLElement` (not a
Custom Element) and was later upgraded to a Custom Element, any
properties corresponding to component inputs that were set on the
element before upgrading it would not be captured correctly and thus not
reflected on the instantiated component.

This commit fixes it by ensuring that such properties are captured
correctly.

Jira issue: [FW-2006](https://angular-team.atlassian.net/browse/FW-2006)

Fixes #30848
Closes #31416

PR Close #36114
2020-05-20 09:43:36 -07:00
George Kalpakas cb719ee16e test(elements): clean up `TestStrategy` between tests (#36114)
Previously, the `TestStrategy` `NgElementStrategy` used in
`createCustomElement()` tests was created once and re-used in each test
(due to complications related to how `customElements.register()` works).
As a result, the `TestStrategy` instance's state (e.g. inputs) could be
polluted from previous tests and affect subsequent ones.

This commit ensures the strategy instance is reset before each test.

PR Close #36114
2020-05-20 09:43:36 -07:00
George Kalpakas ed46d9ebd7 test(elements): only declare helpers if needed (#36114)
Previously, helper modules/components classes were declared even if the
tests were not run (because the environment did not support Custom
Elements for example).

This commit moves the declaration of the helpers inside the `describe()`
block, so they are not declared unnecessarily. This is in preparation of
adding more helpers that need to access variables declared inside the
`describe()` block.

PR Close #36114
2020-05-20 09:43:36 -07:00
George Kalpakas 327980bf49 fix(elements): correctly handle getting/setting properties before connecting the element (#36114)
`createCustomElements()` creates some getters/setters for properties
corresponding to component inputs that delegate to the
`NgElementStrategy`. However, it is not guaranteed that the element's
`NgElementStrategy` will have been created when these getters/setters
are called, because some polyfills (e.g. `document-register-element`) do
not call the constructor.

Previously, trying to get/set input properties before connecting the
element to the DOM (via `connectedCallback()`) would fail due to
`NgElementStrategy` not being created.

This commit ensures that the `NgElementStrategy` is always created
before used inside the input property getters/setters (similar to how it
is done for other methods of `NgElement`).

Mentioned in https://github.com/angular/angular/pull/31416/files#r300326698.

PR Close #36114
2020-05-20 09:43:35 -07:00
Joey Perrott 698b0288be build: reformat repo to new clang@1.4.0 (#36613)
PR Close #36613
2020-04-14 12:08:36 -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
Rob Wormald d76a7d6f7c test(core): update Web Platform feature detection (#24861)
PR Close #24861
2018-08-30 21:33:14 -07:00
Roope Hakulinen 732026c3f5 feat(core): add DoBootstrap interface. (#24558)
Closes #24557.

PR Close #24558
2018-08-07 13:17:06 -07:00
Rado Kirov c95437f15d build(bazel): Turning on strictPropertyInitialization for Angular. (#24572)
All errors for existing fields have been detected and suppressed with a
`!` assertion.

Issue/24571 is tracking proper clean up of those instances.

One-line change required in ivy/compilation.ts, because it appears that
the new syntax causes tsickle emitted node to no longer track their
original sourceFiles.

PR Close #24572
2018-06-25 07:57:13 -07:00
Igor Minar b43f8bc7d3 feat(core): upgrade rxjs to 6.0.0-alpha.4 (#22573)
PR Close #22573
2018-03-19 21:51:51 -07:00
Andrew Seguin 688096b7a3 feat(elements): remove attribute/input from config (#22413)
PR Close #22413
2018-03-16 12:39:07 -07:00
Andrew Seguin 0b45dfac29 feat(elements): fix lint (#22413)
PR Close #22413
2018-03-16 12:39:07 -07:00
Andrew Seguin 167fdf745c feat(elements): rename API to createCustomElement (#22413)
PR Close #22413
2018-03-16 12:39:07 -07:00