Go to file
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
.circleci ci: get rid of the `CI_CHROMEDRIVER_VERSION_ARG` env var (#35381) 2020-02-18 12:42:48 -08:00
.devcontainer build: update the recommended `Dockerfile` for VSCode remote development (#34697) 2020-01-09 13:31:14 -08:00
.github ci: Migrate from CODEOWNERS to PullApprove for PR review management (#34814) 2020-01-28 09:19:34 -08:00
.vscode build: migrate references and scripts that set to build with ivy via compile=aot to use config=ivy (#33983) 2019-11-26 16:38:40 -05:00
.yarn build: vendor yarn using the .yarnrc yarn-path value (#34902) 2020-01-23 11:41:23 -08:00
aio feat: support passive event options by defining global variables in zone.js config file (#34503) 2020-02-21 09:06:26 -08:00
docs docs: minor typo fix (#35423) 2020-02-13 10:08:23 -08:00
integration feat: support passive event options by defining global variables in zone.js config file (#34503) 2020-02-21 09:06:26 -08:00
modules refactor(benchpress): delete outdated/unused folder (#35147) 2020-02-07 16:14:27 -08:00
packages fix(ngcc): correctly detect emitted TS helpers in ES5 (#35191) 2020-02-21 09:06:46 -08:00
scripts build: several minor fixes related to using `puppeteer` (#35381) 2020-02-18 12:42:47 -08:00
third_party ci: Remove old vendoring solution in favor of relying on yarn-path (#35083) 2020-02-06 15:30:51 -08:00
tools build: refactor zone bazel settings (#34532) 2020-02-20 15:20:14 -08:00
.bazelignore build: add integration/platform-server/node_modules to .bazelignore (#33765) 2019-11-22 16:52:08 -05:00
.bazelrc refactor: simplify bazel saucelabs targets using karma pre-test wrapper and shared saucelabs connection between tests (#34769) 2020-01-28 13:47:00 -08:00
.clang-format
.editorconfig
.gitattributes
.gitignore ci: do not run benchmark measurements in circleci (#34753) 2020-01-29 09:22:27 -08:00
.mailmap
.nvmrc build: migrate to node@12.14.1 (#34955) 2020-01-27 09:31:22 -08:00
.pullapprove.yml ci: update pullapprove config to ensure complete coverage of files (#35060) 2020-02-12 16:39:13 -08:00
.yarnrc build: vendor yarn using the .yarnrc yarn-path value (#34902) 2020-01-23 11:41:23 -08:00
BUILD.bazel refactor: simplify bazel saucelabs targets using karma pre-test wrapper and shared saucelabs connection between tests (#34769) 2020-01-28 13:47:00 -08:00
CHANGELOG.md release: cut the v9.1.0-next.1 release 2020-02-19 12:15:43 -08:00
CODE_OF_CONDUCT.md
CONTRIBUTING.md docs: document golden file requirement (#33900) 2020-01-07 10:58:53 -08:00
LICENSE build: bump year (#34651) 2020-01-13 07:21:43 -08:00
README.md docs: fix typo of Typescript to TypeScript (#32153) 2019-08-15 12:44:41 -07:00
WORKSPACE build: update to @bazel/bazel 2.1.0 (#35430) 2020-02-13 16:29:32 -08:00
browser-providers.conf.js ci: update the browser test matrix to match supported browsers (#35202) 2020-02-14 11:14:05 -08:00
gulpfile.js build: create bazel marco to test for circular dependencies (#34774) 2020-01-23 11:36:40 -08:00
karma-js.conf.js ci: ensure saucelabs browsers can load karma test page (#35171) 2020-02-06 15:36:27 -08:00
package.json build: update cli packages to latest versions (#35608) 2020-02-21 08:31:18 -08:00
protractor-perf.conf.js test: ensure global options for benchmark tests can be set in bazel (#34753) 2020-01-29 09:22:27 -08:00
shims_for_IE.js
test-events.js refactor: rename unpatched event flag in Zone from `BLACK_LISTED_EVENTS` to `UNPATCHED_EVENTS` (#29617) 2019-10-04 08:44:58 -07:00
test-main.js feat(ivy): i18n - implement compile-time inlining (#32881) 2019-10-09 13:19:38 -07:00
tslint.json style: enforce disallowance of object constructor (#33211) 2019-12-03 10:08:25 -08:00
yarn.lock build: update cli packages to latest versions (#35608) 2020-02-21 08:31:18 -08:00
yarn.lock.readme.md

README.md

CircleCI BrowserStack Status Join the chat at https://gitter.im/angular/angular npm version

Angular

Angular is a development platform for building mobile and desktop web applications using TypeScript/JavaScript and other languages.

Quickstart

Get started in 5 minutes.

Changelog

Learn about the latest improvements.

Want to help?

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues in the hotlist: community-help.