angular-cn/packages
George Kalpakas bd6a39c364 fix(ngcc): correctly detect emitted TS helpers in ES5 (#35191)
In ES5 code, TypeScript requires certain helpers (such as
`__spreadArrays()`) to be able to support ES2015+ features. These
helpers can be either imported from `tslib` (by setting the
`importHelpers` TS compiler option to `true`) or emitted inline (by
setting the `importHelpers` and `noEmitHelpers` TS compiler options to
`false`, which is the default value for both).

Ngtsc's `StaticInterpreter` (which is also used during ngcc processing)
is able to statically evaluate some of these helpers (currently
`__assign()`, `__spread()` and `__spreadArrays()`), as long as
`ReflectionHost#getDefinitionOfFunction()` correctly detects the
declaration of the helper. For this to happen, the left-hand side of the
corresponding call expression (i.e. `__spread(...)` or
`tslib.__spread(...)`) must be evaluated as a function declaration for
`getDefinitionOfFunction()` to be called with.

In the case of imported helpers, the `tslib.__someHelper` expression was
resolved to a function declaration of the form
`export declare function __someHelper(...args: any[][]): any[];`, which
allows `getDefinitionOfFunction()` to correctly map it to a TS helper.

In contrast, in the case of emitted helpers (and regardless of the
module format: `CommonJS`, `ESNext`, `UMD`, etc.)), the `__someHelper`
identifier was resolved to a variable declaration of the form
`var __someHelper = (this && this.__someHelper) || function () { ... }`,
which upon further evaluation was categorized as a `DynamicValue`
(prohibiting further evaluation by the `getDefinitionOfFunction()`).

As a result of the above, emitted TypeScript helpers were not evaluated
in ES5 code.

---
This commit changes the detection of TS helpers to leverage the existing
`KnownFn` feature (previously only used for built-in functions).
`Esm5ReflectionHost` is changed to always return `KnownDeclaration`s for
TS helpers, both imported (`getExportsOfModule()`) as well as emitted
(`getDeclarationOfIdentifier()`).

Similar changes are made to `CommonJsReflectionHost` and
`UmdReflectionHost`.

The `KnownDeclaration`s are then mapped to `KnownFn`s in
`StaticInterpreter`, allowing it to statically evaluate call expressions
involving any kind of TS helpers.

Jira issue: https://angular-team.atlassian.net/browse/FW-1689

PR Close #35191
2020-02-21 09:06:46 -08:00
..
animations fix(animations): false positive when detecting Node in Webpack builds (#35134) 2020-02-20 10:51:15 -08:00
bazel build: update to bazel_toolchains 2.1.0 (#35430) 2020-02-13 16:29:33 -08:00
benchpress build: derive ts_library dep from jasmine_node_test boostrap label if it ends in `_es5` (#34736) 2020-01-15 14:58:07 -05:00
common test(common): unit test for http/testing expectOne with several requests (#27005) 2020-01-31 13:13:38 -08:00
compiler fix(ivy): incorrectly generating shared pure function between null and object literal (#35481) 2020-02-20 15:23:58 -08:00
compiler-cli fix(ngcc): correctly detect emitted TS helpers in ES5 (#35191) 2020-02-21 09:06:46 -08:00
core fix(ivy): incorrectly generating shared pure function between null and object literal (#35481) 2020-02-20 15:23:58 -08:00
docs
elements fix(elements): schematics fails with schema.json not found error (#35211) 2020-02-11 11:42:52 -08:00
examples docs: changes AoT to AOT for consistency (#35112) 2020-02-04 10:43:33 -08:00
forms docs(forms): remove outdated ngForm selector deprecation notice (#35435) 2020-02-14 15:34:00 -08:00
http refactor(http): fix a strictBindCallApply issue. (#34817) 2020-01-21 16:44:40 -05:00
language-service fix(language-service): provide completions for the structural directive that only injects the 'ViewContainerRef' (#35466) 2020-02-20 15:12:50 -08:00
localize fix(localize): support minified ES5 `$localize` calls (#35562) 2020-02-20 10:55:53 -08:00
platform-browser fix(ivy): set namespace for host elements of dynamically created components (#35136) 2020-02-07 17:22:53 -08:00
platform-browser-dynamic refactor(core): order private exports alphabetically (#35003) 2020-01-28 15:57:57 -08:00
platform-server fix(ivy): set namespace for host elements of dynamically created components (#35136) 2020-02-07 17:22:53 -08:00
platform-webworker build: derive ts_library dep from jasmine_node_test boostrap label if it ends in `_es5` (#34736) 2020-01-15 14:58:07 -05:00
platform-webworker-dynamic build: set up all packages to publish via wombot proxy (#33747) 2019-11-13 11:34:33 -08:00
private/testing
router test: setup circular dependency tests for all entry points (#34774) 2020-01-23 11:36:40 -08:00
service-worker test: setup circular dependency tests for all entry points (#34774) 2020-01-23 11:36:40 -08:00
upgrade docs: changes AoT to AOT for consistency (#35112) 2020-02-04 10:43:33 -08:00
zone.js feat: support passive event options by defining global variables in zone.js config file (#34503) 2020-02-21 09:06:26 -08:00
BUILD.bazel
README.md
empty.ts
goog.d.ts
license-banner.txt build: bump year (#34651) 2020-01-13 07:21:43 -08:00
system.d.ts
tsconfig-build-no-strict.json
tsconfig-build.json
tsconfig-test.json
tsconfig.json
types.d.ts

README.md

Angular

The sources for this package are in the main Angular repo. Please file issues and pull requests against that repo.

Usage information and reference details can be found in Angular documentation.

License: MIT