Go to file
JoostK 4aa4e6fd03 fix(compiler): handle type references to namespaced symbols correctly (#36106)
When the compiler needs to convert a type reference to a value
expression, it may encounter a type that refers to a namespaced symbol.
Such namespaces need to be handled specially as there's various forms
available. Consider a namespace named "ns":

1. One can refer to a namespace by itself: `ns`. A namespace is only
   allowed to be used in a type position if it has been merged with a
   class, but even if this is the case it may not be possible to convert
   that type into a value expression depending on the import form. More
   on this later (case a below)
2. One can refer to a type within the namespace: `ns.Foo`. An import
   needs to be generated to `ns`, from which the `Foo` property can then
   be read.
3. One can refer to a type in a nested namespace within `ns`:
   `ns.Foo.Bar` and possibly even deeper nested. The value
   representation is similar to case 2, but includes additional property
   accesses.

The exact strategy of how to deal with these cases depends on the type
of import used. There's two flavors available:

a. A namespaced import like `import * as ns from 'ns';` that creates
   a local namespace that is irrelevant to the import that needs to be
   generated (as said import would be used instead of the original
   import).

   If the local namespace "ns" itself is referred to in a type position,
   it is invalid to convert it into a value expression. Some JavaScript
   libraries publish a value as default export using `export = MyClass;`
   syntax, however it is illegal to refer to that value using "ns".
   Consequently, such usage in a type position *must* be accompanied by
   an `@Inject` decorator to provide an explicit token.

b. An explicit namespace declaration within a module, that can be
   imported using a named import like `import {ns} from 'ns';` where the
   "ns" module declares a namespace using `declare namespace ns {}`.
   In this case, it's the namespace itself that needs to be imported,
   after which any qualified references into the namespace are converted
   into property accesses.

Before this change, support for namespaces in the type-to-value
conversion was limited and only worked  correctly for a single qualified
name using a namespace import (case 2a). All other cases were either
producing incorrect code or would crash the compiler (case 1a).

Crashing the compiler is not desirable as it does not indicate where
the issue is. Moreover, the result of a type-to-value conversion is
irrelevant when an explicit injection token is provided using `@Inject`,
so referring to a namespace in a type position (case 1) could still be
valid.

This commit introduces logic to the type-to-value conversion to be able
to properly deal with all type references to namespaced symbols.

Fixes #36006
Resolves FW-1995

PR Close #36106
2020-04-09 11:32:21 -07:00
.circleci ci: manually set available resources for bazel on windows CI (#36458) 2020-04-07 10:12:29 -07:00
.devcontainer build: update the recommended `Dockerfile` for VSCode remote development (#34697) 2020-01-09 13:31:14 -08:00
.github fix(dev-infra): do not run the `lock-closed` GitHub action on forks (#36000) 2020-03-11 14:45:47 -04:00
.vscode build: fix @bazel/bazel to bazelisk leftovers (#36132) 2020-03-19 08:58:47 -07:00
.yarn build: vendor yarn using the .yarnrc yarn-path value (#34902) 2020-01-23 11:41:23 -08:00
aio docs: update the Support policy and schedule (#35390) 2020-04-08 12:12:32 -07:00
dev-infra fix(dev-infra): fix commit message validation in git worktrees (#36507) 2020-04-09 09:46:18 -07:00
docs build: depend on bazelisk rather than directly on Bazel (#36078) 2020-03-16 10:58:06 -07:00
goldens fix(language-service): remove circular dependency instance (#36463) 2020-04-08 15:29:09 -07:00
integration fix(core): ngOnDestroy on multi providers called with incorrect context (#35840) 2020-04-07 10:31:41 -07:00
modules feat(benchpress): create component_benchmark macro (#35692) 2020-03-20 10:19:25 -07:00
packages fix(compiler): handle type references to namespaced symbols correctly (#36106) 2020-04-09 11:32:21 -07:00
scripts fix(dev-infra): use commit message validation from @angular/dev-infra-private (#36172) 2020-04-06 09:28:52 -07: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 fix(common): `locales/global/*.js` are not ES5 compliant (#36342) 2020-04-09 11:30:32 -07:00
.bazelignore build: add npm package manifest to npm_integration_test (#35669) 2020-02-26 12:58:35 -08:00
.bazelrc build: remove CI_CHROMEDIRVER_VERSION_ARG from integration/bazel-schematics (#33927) 2020-02-24 08:59:18 -08:00
.bazelversion build: depend on bazelisk rather than directly on Bazel (#36078) 2020-03-16 10:58:06 -07:00
.clang-format feat(tooling): Add a .clang-format for automated JavaScript formatting. 2015-04-02 08:44:34 -07:00
.dev-infra.json feat(dev-infra): create commit-message validation script/tooling (#36117) 2020-03-20 10:20:12 -07:00
.editorconfig build: use https link to editorconfig.org in .editorconfig (#27664) 2018-12-18 09:30:09 -08:00
.gitattributes test: fix ts api guardian and public guard tests on windows (#30105) 2019-04-26 16:32:22 -07:00
.gitignore ci: do not run benchmark measurements in circleci (#34753) 2020-01-29 09:22:27 -08:00
.mailmap build: add a Git .mailmap with my new name (#19550) 2017-10-09 14:35:30 -07:00
.nvmrc build: migrate to node@12.14.1 (#34955) 2020-01-27 09:31:22 -08:00
.pullapprove.yml ci: exclude ngcc directory from fw-compiler pull-approve rule (#35933) 2020-04-06 13:16:37 -07:00
.yarnrc build: vendor yarn using the .yarnrc yarn-path value (#34902) 2020-01-23 11:41:23 -08:00
BUILD.bazel build: remove rollup packaging from dev-infra (#35647) 2020-03-17 12:27:07 -07:00
CHANGELOG.md release: cut the v10.0.0-next.1 release 2020-04-08 12:28:12 -07:00
CODE_OF_CONDUCT.md docs: fix community tab in GitHub by copying CoC 2018-02-27 19:02:30 -08:00
CONTRIBUTING.md docs(dev-infra): update triage and contributing docs for dev-infra (#35995) 2020-03-10 21:02:17 -04:00
LICENSE build: bump year (#34651) 2020-01-13 07:21:43 -08:00
README.md docs: remove browserstack badge from readme (#35684) 2020-03-17 09:29:43 -07:00
WORKSPACE build: update to rules_nodejs 1.5.0 (#36307) 2020-03-30 11:25:16 -07: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 fix(dev-infra): use commit message validation from @angular/dev-infra-private (#36172) 2020-04-06 09:28:52 -07: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 fix(dev-infra): fix commit message validation in git worktrees (#36507) 2020-04-09 09:46:18 -07: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 Revert "refactor: add license header to JS files & format files (#12035)" 2016-10-04 14:06:41 -07:00
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 build: no longer run tslint from within gulp task (#35800) 2020-03-03 09:20:49 -08:00
yarn.lock build: update jasmine to 3.5 (#34625) 2020-04-08 12:10:34 -07:00
yarn.lock.readme.md build: remove travisci leftovers (#27979) 2019-01-09 10:41:16 -08:00

README.md

CircleCI 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.