Compare commits
292 Commits
Author | SHA1 | Date | |
---|---|---|---|
c2dbc55f11 | |||
9ee2703824 | |||
b78ada198a | |||
6790e02a13 | |||
7cabaa0ae7 | |||
da3563ce19 | |||
9bbec42a6c | |||
be994496cd | |||
77ef527993 | |||
f092a7c824 | |||
5e25d3986d | |||
35977e3830 | |||
f7328c69b3 | |||
25f2211726 | |||
18793c896b | |||
e7cdb9f660 | |||
6911a250ef | |||
7e7ff2e0aa | |||
d34f0bf573 | |||
1f5fa25583 | |||
d507057476 | |||
f582620d5b | |||
3fbcde9048 | |||
f841fbe60f | |||
b9a91a5e74 | |||
65f4fad801 | |||
60a30818ef | |||
b967cbfc66 | |||
8826a8235b | |||
47addd169d | |||
ba6af2a6dd | |||
b9e4d62d5a | |||
71e5de646b | |||
3def2cc552 | |||
4ec4a99f16 | |||
3203069d6c | |||
54bfe14313 | |||
ba850b36de | |||
f3c5481181 | |||
48300067fb | |||
b841e0d530 | |||
65a2cb8307 | |||
0bef021321 | |||
aafa75da84 | |||
503be69af6 | |||
eb01ad583f | |||
15a54df7d3 | |||
eaaae2edf4 | |||
c2b3792a3b | |||
b2a586cee1 | |||
8bb42df47e | |||
add5953aa1 | |||
6b4c24020d | |||
24bf3e2a25 | |||
8ecda94899 | |||
1366762d12 | |||
dd6237ecd9 | |||
6e83204238 | |||
a53a040071 | |||
5bef070e16 | |||
89de98b25e | |||
de78307928 | |||
6293ca23c3 | |||
330bb2a360 | |||
59455ea8d1 | |||
e9e4ffd6e1 | |||
0444e13efb | |||
ffb6dbeefe | |||
0e012c9669 | |||
a0819d3af1 | |||
ffd8c361eb | |||
1594f8c09e | |||
d7a727cc07 | |||
437a0446e2 | |||
ac93f1235e | |||
e2b76bb386 | |||
ae0275e2dd | |||
ecce90718b | |||
c2cb475a2c | |||
7cf5e95ac9 | |||
a740e4f00a | |||
2a9d2bacd5 | |||
4ed04392d3 | |||
23ab83b504 | |||
9332161e01 | |||
816d5ba3fd | |||
69c53c3e03 | |||
365712e2f0 | |||
997336b790 | |||
1861e416a1 | |||
7c44637fbf | |||
68b53c07fd | |||
368cb5ad4e | |||
949836d003 | |||
697fb76960 | |||
0fedb57cb0 | |||
717ac5ac4d | |||
4064cbe945 | |||
a88306d671 | |||
c702ffc471 | |||
dcfffbf828 | |||
336041aac9 | |||
7e38f4fd1f | |||
c28b52187a | |||
5ec1717c58 | |||
c2a24b4241 | |||
a9f3e2bd95 | |||
f8658cdc38 | |||
043e408805 | |||
c004d483ab | |||
2586846ee2 | |||
d47b2a6f70 | |||
1adbcda12e | |||
12af6d356e | |||
20aafff092 | |||
a622e19df6 | |||
1db7c0d139 | |||
b9bd3204f2 | |||
bf651a504f | |||
e5c4371d72 | |||
3caae94261 | |||
e7a2b31472 | |||
c03186013c | |||
5a2531ee45 | |||
6ca780178c | |||
9608b0636d | |||
89187d9b6b | |||
335b72f301 | |||
74071210eb | |||
fde966832b | |||
75d474e1d3 | |||
24cf8b3269 | |||
743651f5e8 | |||
161f88fe6f | |||
c33a57666b | |||
cf618c564c | |||
401ead07b8 | |||
b55c2ba342 | |||
d8db0f12a2 | |||
eb8013e853 | |||
fb4b90a564 | |||
7830d74615 | |||
8e24c0fff4 | |||
cf0444b731 | |||
a7bbe9a1ff | |||
ffe323036e | |||
b4a39f9c30 | |||
3257fcdcee | |||
9bcd7097d0 | |||
c32f5fd393 | |||
78ba39bfe2 | |||
119034c642 | |||
6e8e3bd248 | |||
a460066972 | |||
05d96dc507 | |||
b489259a34 | |||
6b748835be | |||
d30ea61f0d | |||
0c47ea704e | |||
049c89645b | |||
bf22f2df88 | |||
880201681f | |||
63d26a1777 | |||
8b50ed083c | |||
3997d97806 | |||
200d92d030 | |||
dbec3ca716 | |||
f7c9b941cb | |||
f0764016f9 | |||
a99eb16320 | |||
e36bac9e90 | |||
196ce6d475 | |||
faa621218e | |||
169cedd43b | |||
567cc26b8e | |||
1d19d61970 | |||
03f080b7da | |||
26f82995f6 | |||
f1da1419fa | |||
5079d2d37c | |||
c7fd172ba7 | |||
dcf8840831 | |||
60c0b178af | |||
0899f4f8fc | |||
aed4a11d01 | |||
75cf70ae04 | |||
6b30fbf94e | |||
24f17f913a | |||
ebfa204af0 | |||
a28d616e10 | |||
613a9e3672 | |||
65d57a07e0 | |||
22946cfd40 | |||
9975486954 | |||
068348e9b1 | |||
1beab0da6a | |||
3a03ff6b2d | |||
feae55b264 | |||
0355142737 | |||
5b16ce9302 | |||
17ed14faea | |||
d156e72ad7 | |||
7186c9c839 | |||
a41558eb30 | |||
a91252a90c | |||
132c0719dc | |||
3db7112b89 | |||
2ea76cce31 | |||
b8bb2dd0f5 | |||
27ae0f9475 | |||
171dceb010 | |||
1ebc0d1e33 | |||
1d8e0758fa | |||
cd55643f85 | |||
486b8e6f69 | |||
215d373ebd | |||
4038b42396 | |||
9ab1f4a9c9 | |||
e9afc59a81 | |||
83c826c3f9 | |||
abfc41d661 | |||
11fd7eaf63 | |||
54eba606cb | |||
3337865913 | |||
f24397c5d0 | |||
9d52bf27de | |||
19fbfbc371 | |||
6578b30b77 | |||
10c1c2ba5a | |||
e18bfd1f3d | |||
3c2ddbe9ab | |||
a149605c9f | |||
b396029d39 | |||
040b376052 | |||
175c872514 | |||
71291aa2c0 | |||
415e75716a | |||
3216abee2e | |||
327ad02a28 | |||
1df0c9e1b0 | |||
280dadaaad | |||
c30eff898a | |||
ca129ba549 | |||
171ae154c2 | |||
4426c0f14e | |||
901436e46f | |||
6fbc2b3be0 | |||
93d23ddcc8 | |||
548a809a05 | |||
a161b4ab6d | |||
60b91656cd | |||
1858d99559 | |||
3a8665409d | |||
005a78bd83 | |||
7553ce9dfe | |||
42bfe4477f | |||
3bdbb18c8b | |||
13f8648a00 | |||
b6abcb2500 | |||
f1a9e1e361 | |||
54480f7dfc | |||
951bd33b09 | |||
bf57df3e04 | |||
420852e2f5 | |||
04eb80cc2b | |||
308fc8e328 | |||
9bb2939d68 | |||
2f63899be2 | |||
22c66f0e02 | |||
00bc80bb37 | |||
394d951883 | |||
98b26381f6 | |||
31797d3b50 | |||
957be960d2 | |||
18e9d86a3b | |||
a869aeecd2 | |||
eca822b756 | |||
17142a778a | |||
5adb7c9669 | |||
703fcda590 | |||
f16a7cd7e3 | |||
fde5f2fa14 | |||
d56724659f | |||
56b18ff063 | |||
7bfeac746e | |||
c92efc15fb | |||
b51d57deb8 | |||
c357b40dca | |||
a0ae120093 | |||
d3211a2468 | |||
adab4f3e49 | |||
82fed62af2 |
18
.bazelrc
18
.bazelrc
@ -1,18 +0,0 @@
|
||||
# Make compilation fast, by keeping a few copies of the compilers
|
||||
# running as daemons, and cache SourceFile AST's to reduce parse time.
|
||||
build --strategy=TypeScriptCompile=worker
|
||||
build --strategy=AngularTemplateCompile=worker
|
||||
|
||||
# Don't create bazel-* symlinks in the WORKSPACE directory.
|
||||
# These require .gitignore and may scare users.
|
||||
# Also, it's a workaround for https://github.com/bazelbuild/rules_typescript/issues/12
|
||||
# which affects the common case of having `tsconfig.json` in the WORKSPACE directory.
|
||||
#
|
||||
# Instead, you should run `bazel info bazel-bin` to find out where the outputs went.
|
||||
build --symlink_prefix=/
|
||||
|
||||
# Performance: avoid stat'ing input files
|
||||
build --watchfs
|
||||
|
||||
# Don't print all the .d.ts output locations after builds
|
||||
build --show_result=0
|
@ -11,7 +11,7 @@
|
||||
anchor_1: &job_defaults
|
||||
working_directory: ~/ng
|
||||
docker:
|
||||
- image: angular/ngcontainer:0.0.2
|
||||
- image: angular/ngcontainer:0.0.6
|
||||
|
||||
# After checkout, rebase on top of master.
|
||||
# Similar to travis behavior, but not quite the same.
|
||||
@ -39,7 +39,7 @@ jobs:
|
||||
<<: *post_checkout
|
||||
- restore_cache:
|
||||
key: angular-{{ .Branch }}-{{ checksum "yarn.lock" }}
|
||||
|
||||
- run: bazel info release
|
||||
- run: bazel run @yarn//:yarn
|
||||
- run: bazel build packages/...
|
||||
- run: bazel test @angular//...
|
||||
|
@ -279,7 +279,7 @@ groups:
|
||||
files:
|
||||
- "packages/benchpress/*"
|
||||
users:
|
||||
- alxhub #primary
|
||||
# needs primary
|
||||
# needs secondary
|
||||
- IgorMinar #fallback
|
||||
- mhevery #fallback
|
||||
|
@ -2,7 +2,7 @@ language: node_js
|
||||
sudo: false
|
||||
dist: trusty
|
||||
node_js:
|
||||
- '6.9.5'
|
||||
- '8.9.1'
|
||||
|
||||
addons:
|
||||
# firefox: "38.0"
|
||||
|
132
CHANGELOG.md
132
CHANGELOG.md
@ -1,3 +1,73 @@
|
||||
<a name="5.1.0"></a>
|
||||
# [5.1.0](https://github.com/angular/angular/compare/5.1.0-rc.1...5.1.0) (2017-12-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **animations:** ensure DOM is cleaned up after multiple [@trigger](https://github.com/trigger) leave animations finish ([#20740](https://github.com/angular/angular/issues/20740)) ([b78ada1](https://github.com/angular/angular/commit/b78ada1)), closes [#20541](https://github.com/angular/angular/issues/20541)
|
||||
* **service-worker:** initialize in browser only ([#20782](https://github.com/angular/angular/issues/20782)) ([7cabaa0](https://github.com/angular/angular/commit/7cabaa0)), closes [#20360](https://github.com/angular/angular/issues/20360)
|
||||
* **service-worker:** esm2015 points to wrong path ([#20800](https://github.com/angular/angular/issues/20800)) ([da3563c](https://github.com/angular/angular/commit/da3563c))
|
||||
|
||||
|
||||
|
||||
<a name="5.1.0-rc.1"></a>
|
||||
# [5.1.0-rc.1](https://github.com/angular/angular/compare/5.1.0-rc.0...5.1.0-rc.1) (2017-12-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **compiler-cli:** propagate ts.SourceFile moduleName into metadata ([f841fbe](https://github.com/angular/angular/commit/f841fbe))
|
||||
* **service-worker:** allow disabling SW while still using services ([65f4fad](https://github.com/angular/angular/commit/65f4fad))
|
||||
* **service-worker:** don't crash if SW not supported ([b9a91a5](https://github.com/angular/angular/commit/b9a91a5))
|
||||
* **service-worker:** send initialization signal from the application ([3fbcde9](https://github.com/angular/angular/commit/3fbcde9))
|
||||
* **service-worker:** use relative path for ngsw.json ([f582620](https://github.com/angular/angular/commit/f582620))
|
||||
|
||||
|
||||
|
||||
<a name="5.0.5"></a>
|
||||
## [5.0.5](https://github.com/angular/angular/compare/5.0.4...5.0.5) (2017-12-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **compiler-cli:** propagate ts.SourceFile moduleName into metadata ([a2ff4ab](https://github.com/angular/angular/commit/a2ff4ab))
|
||||
* **service-worker:** allow disabling SW while still using services ([f99335b](https://github.com/angular/angular/commit/f99335b))
|
||||
* **service-worker:** don't crash if SW not supported ([ee37d4b](https://github.com/angular/angular/commit/ee37d4b))
|
||||
* **service-worker:** send initialization signal from the application ([6bf07b4](https://github.com/angular/angular/commit/6bf07b4))
|
||||
* **service-worker:** use relative path for ngsw.json ([56c98f7](https://github.com/angular/angular/commit/56c98f7))
|
||||
|
||||
|
||||
|
||||
<a name="5.1.0-rc.0"></a>
|
||||
# [5.1.0-rc.0](https://github.com/angular/angular/compare/5.1.0-beta.2...5.1.0-rc.0) (2017-12-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **animations:** ensure multi-level enter animations work ([#19455](https://github.com/angular/angular/issues/19455)) ([dd6237e](https://github.com/angular/angular/commit/dd6237e))
|
||||
* **animations:** ensure multi-level enter animations work ([#19455](https://github.com/angular/angular/issues/19455)) ([b2a586c](https://github.com/angular/angular/commit/b2a586c))
|
||||
* **animations:** ensure multi-level leave animations work ([#19455](https://github.com/angular/angular/issues/19455)) ([1366762](https://github.com/angular/angular/commit/1366762))
|
||||
* **animations:** ensure multi-level leave animations work ([#19455](https://github.com/angular/angular/issues/19455)) ([c2b3792](https://github.com/angular/angular/commit/c2b3792))
|
||||
* **bazel:** produce named AMD modules for codegen ([#20547](https://github.com/angular/angular/issues/20547)) ([6e83204](https://github.com/angular/angular/commit/6e83204)), closes [#19422](https://github.com/angular/angular/issues/19422)
|
||||
* **common:** accept falsy values as HTTP bodies ([#19958](https://github.com/angular/angular/issues/19958)) ([15a54df](https://github.com/angular/angular/commit/15a54df)), closes [#19825](https://github.com/angular/angular/issues/19825) [#19195](https://github.com/angular/angular/issues/19195)
|
||||
* **common:** don't strip XSSI prefix for if error isn't JSON ([#19958](https://github.com/angular/angular/issues/19958)) ([aafa75d](https://github.com/angular/angular/commit/aafa75d))
|
||||
* **common:** remove useless guard in HttpClient ([#19958](https://github.com/angular/angular/issues/19958)) ([eb01ad5](https://github.com/angular/angular/commit/eb01ad5)), closes [#19223](https://github.com/angular/angular/issues/19223)
|
||||
* **common:** treat an empty body as null when parsing JSON in HttpClient ([#19958](https://github.com/angular/angular/issues/19958)) ([503be69](https://github.com/angular/angular/commit/503be69)), closes [#18680](https://github.com/angular/angular/issues/18680) [#19413](https://github.com/angular/angular/issues/19413) [#19502](https://github.com/angular/angular/issues/19502) [#19555](https://github.com/angular/angular/issues/19555)
|
||||
* **compiler:** correctly detect when to serialze summary metadata ([#20668](https://github.com/angular/angular/issues/20668)) ([8bb42df](https://github.com/angular/angular/commit/8bb42df))
|
||||
* **compiler-cli:** fix memory leak in program creation ([#20692](https://github.com/angular/angular/issues/20692)) ([71e5de6](https://github.com/angular/angular/commit/71e5de6)), closes [#20691](https://github.com/angular/angular/issues/20691)
|
||||
* **compiler-cli:** normalize sourcepaths for i18n extracted files ([#20417](https://github.com/angular/angular/issues/20417)) ([de78307](https://github.com/angular/angular/commit/de78307)), closes [#20416](https://github.com/angular/angular/issues/20416)
|
||||
* **core:** should use native addEventListener in ngZone ([#20672](https://github.com/angular/angular/issues/20672)) ([65a2cb8](https://github.com/angular/angular/commit/65a2cb8))
|
||||
* **language-service:** Allow empty templates ([#20651](https://github.com/angular/angular/issues/20651)) ([3203069](https://github.com/angular/angular/commit/3203069)), closes [#19406](https://github.com/angular/angular/issues/19406)
|
||||
* **language-service:** Fix crash when no script files are found ([#20550](https://github.com/angular/angular/issues/20550)) ([54bfe14](https://github.com/angular/angular/commit/54bfe14)), closes [#19325](https://github.com/angular/angular/issues/19325)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **common:** add locale id parameter to `registerLocaleData` ([#20623](https://github.com/angular/angular/issues/20623)) ([24bf3e2](https://github.com/angular/angular/commit/24bf3e2))
|
||||
* **compiler-cli:** improve error messages produced during structural errors ([#20459](https://github.com/angular/angular/issues/20459)) ([8ecda94](https://github.com/angular/angular/commit/8ecda94))
|
||||
|
||||
|
||||
|
||||
<a name="5.0.4"></a>
|
||||
## [5.0.4](https://github.com/angular/angular/compare/5.0.3...5.0.4) (2017-12-01)
|
||||
|
||||
@ -15,6 +85,30 @@
|
||||
|
||||
|
||||
|
||||
<a name="5.1.0-beta.2"></a>
|
||||
# [5.1.0-beta.2](https://github.com/angular/angular/compare/5.1.0-beta.1...5.1.0-beta.2) (2017-11-22)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **animations:** always fire inner trigger callbacks even if blocked by parent animations ([#19753](https://github.com/angular/angular/issues/19753)) ([0e012c9](https://github.com/angular/angular/commit/0e012c9)), closes [#19100](https://github.com/angular/angular/issues/19100)
|
||||
* **animations:** always fire start and done callbacks in order for noop animations ([#20570](https://github.com/angular/angular/issues/20570)) ([ffb6dbe](https://github.com/angular/angular/commit/ffb6dbe))
|
||||
* **animations:** validate against trigger() names that use @ symbols ([#20326](https://github.com/angular/angular/issues/20326)) ([1861e41](https://github.com/angular/angular/commit/1861e41))
|
||||
* **benchpress:** Allow ignoring navigationStart events in perflog metric. ([#20312](https://github.com/angular/angular/issues/20312)) ([717ac5a](https://github.com/angular/angular/commit/717ac5a))
|
||||
* **common:** return ISubscription from Location.subscribe() ([#20429](https://github.com/angular/angular/issues/20429)) ([437a044](https://github.com/angular/angular/commit/437a044)), closes [#20406](https://github.com/angular/angular/issues/20406)
|
||||
* **compiler:** emit correct type-check-blocks with TemplateRef's ([#20463](https://github.com/angular/angular/issues/20463)) ([68b53c0](https://github.com/angular/angular/commit/68b53c0))
|
||||
* **compiler:** support event bindings in `fullTemplateTypeCheck` ([#20490](https://github.com/angular/angular/issues/20490)) ([4ed0439](https://github.com/angular/angular/commit/4ed0439))
|
||||
* **core:** fix [#20532](https://github.com/angular/angular/issues/20532), should be able to cancel listener from mixed zone ([#20538](https://github.com/angular/angular/issues/20538)) ([a740e4f](https://github.com/angular/angular/commit/a740e4f))
|
||||
* **core:** should support event.stopImmediatePropagation ([#20469](https://github.com/angular/angular/issues/20469)) ([997336b](https://github.com/angular/angular/commit/997336b))
|
||||
* **forms:** updateOn should check if change occurred ([#20358](https://github.com/angular/angular/issues/20358)) ([69c53c3](https://github.com/angular/angular/commit/69c53c3)), closes [#20259](https://github.com/angular/angular/issues/20259)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **platform-browser-dynamic:** export `JitCompilerFactory` ([#20478](https://github.com/angular/angular/issues/20478)) ([d7a727c](https://github.com/angular/angular/commit/d7a727c)), closes [#20125](https://github.com/angular/angular/issues/20125)
|
||||
|
||||
|
||||
|
||||
<a name="5.0.3"></a>
|
||||
## [5.0.3](https://github.com/angular/angular/compare/5.0.2...5.0.3) (2017-11-22)
|
||||
|
||||
@ -32,6 +126,28 @@
|
||||
* **forms:** updateOn should check if change occurred ([#20358](https://github.com/angular/angular/issues/20358)) ([f9f2c20](https://github.com/angular/angular/commit/f9f2c20)), closes [#20259](https://github.com/angular/angular/issues/20259)
|
||||
|
||||
|
||||
<a name="5.1.0-beta.1"></a>
|
||||
# [5.1.0-beta.1](https://github.com/angular/angular/compare/5.1.0-beta.0...5.1.0-beta.1) (2017-11-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **animations:** always fire inner trigger callbacks even if blocked by parent animations ([#19753](https://github.com/angular/angular/issues/19753)) ([d47b2a6](https://github.com/angular/angular/commit/d47b2a6)), closes [#19100](https://github.com/angular/angular/issues/19100)
|
||||
* **animations:** ensure final state() styles are applied within @.disabled animations ([#20267](https://github.com/angular/angular/issues/20267)) ([20aafff](https://github.com/angular/angular/commit/20aafff)), closes [#20266](https://github.com/angular/angular/issues/20266)
|
||||
* **bazel:** adjust mock of tsconfig for ng_module rule unit test ([#20175](https://github.com/angular/angular/issues/20175)) ([c2a24b4](https://github.com/angular/angular/commit/c2a24b4))
|
||||
* **compiler:** fix corner cases in shadow CSS ([c32f5fd](https://github.com/angular/angular/commit/c32f5fd))
|
||||
* **compiler:** recognize @NgModule with a redundant @Injectable ([#20320](https://github.com/angular/angular/issues/20320)) ([c33a576](https://github.com/angular/angular/commit/c33a576))
|
||||
* **compiler:** show explanatory text in template errors ([#20313](https://github.com/angular/angular/issues/20313)) ([3257fcd](https://github.com/angular/angular/commit/3257fcd))
|
||||
* **core:** ensure init lifecycle events are called ([#20258](https://github.com/angular/angular/issues/20258)) ([24cf8b3](https://github.com/angular/angular/commit/24cf8b3))
|
||||
* **language-service:** pass compilerOptions.paths to ReflectorHost ([#20222](https://github.com/angular/angular/issues/20222)) ([eb8013e](https://github.com/angular/angular/commit/eb8013e))
|
||||
* **router:** 'merge' queryParamHandling strategy should be able to remove query params ([#19733](https://github.com/angular/angular/issues/19733)) ([a622e19](https://github.com/angular/angular/commit/a622e19)), closes [#18463](https://github.com/angular/angular/issues/18463) [#17202](https://github.com/angular/angular/issues/17202)
|
||||
* Update test code to type-check under TS 2.5 ([#20175](https://github.com/angular/angular/issues/20175)) ([5ec1717](https://github.com/angular/angular/commit/5ec1717))
|
||||
|
||||
### Features
|
||||
|
||||
* **typescript:** support TypeScript 2.5 ([a9f3e2b](https://github.com/angular/angular/commit/a9f3e2b)), closes [#20175](https://github.com/angular/angular/issues/20175)
|
||||
|
||||
> Note, if you do `Injector.get(Token)` where `Token` has static members, you'll run into https://github.com/Microsoft/TypeScript/issues/20102 where the returned type is `{}` rather than `Token`. Use `Injector.get<Token>(Token)` to work around.
|
||||
|
||||
<a name="5.0.2"></a>
|
||||
## [5.0.2](https://github.com/angular/angular/compare/5.0.1...5.0.2) (2017-11-16)
|
||||
@ -46,6 +162,22 @@
|
||||
* **router:** 'merge' queryParamHandling strategy should be able to remove query params ([#19733](https://github.com/angular/angular/issues/19733)) ([b732fb9](https://github.com/angular/angular/commit/b732fb9)), closes [#18463](https://github.com/angular/angular/issues/18463) [#17202](https://github.com/angular/angular/issues/17202)
|
||||
|
||||
|
||||
<a name="5.1.0-beta.0"></a>
|
||||
# [5.1.0-beta.0](https://github.com/angular/angular/compare/5.0.0-rc.4...5.1.0-beta.0) (2017-11-08)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **compiler:** don't overwrite missingTranslation's value in JIT ([#19952](https://github.com/angular/angular/issues/19952)) ([799cbb9](https://github.com/angular/angular/commit/799cbb9))
|
||||
* **compiler:** report a reasonable error with invalid metadata ([#20062](https://github.com/angular/angular/issues/20062)) ([da22c48](https://github.com/angular/angular/commit/da22c48))
|
||||
* **compiler-cli:** don't report emit diagnostics when `--noEmitOnError` is off ([#20063](https://github.com/angular/angular/issues/20063)) ([8639995](https://github.com/angular/angular/commit/8639995))
|
||||
* **core:** `__symbol__` should return `__zone_symbol__` without zone.js loaded ([#19541](https://github.com/angular/angular/issues/19541)) ([678d1cf](https://github.com/angular/angular/commit/678d1cf))
|
||||
* **core:** should support event.stopImmediatePropagation ([#19222](https://github.com/angular/angular/issues/19222)) ([7083791](https://github.com/angular/angular/commit/7083791))
|
||||
* **platform-browser:** support Symbols in custom `jasmineToString()` method ([#19794](https://github.com/angular/angular/issues/19794)) ([5a6efa7](https://github.com/angular/angular/commit/5a6efa7))
|
||||
|
||||
### Features
|
||||
|
||||
* **compiler:** introduce `TestBed.overrideTemplateUsingTestingModule` ([a460066](https://github.com/angular/angular/commit/a460066)), closes [#19815](https://github.com/angular/angular/issues/19815)
|
||||
|
||||
|
||||
<a name="5.0.1"></a>
|
||||
## [5.0.1](https://github.com/angular/angular/compare/5.0.0...5.0.1) (2017-11-08)
|
||||
|
@ -69,21 +69,22 @@ You can file new issues by filling out our [new issue form](https://github.com/a
|
||||
### <a name="submit-pr"></a> Submitting a Pull Request (PR)
|
||||
Before you submit your Pull Request (PR) consider the following guidelines:
|
||||
|
||||
* Search [GitHub](https://github.com/angular/angular/pulls) for an open or closed PR
|
||||
1. Search [GitHub](https://github.com/angular/angular/pulls) for an open or closed PR
|
||||
that relates to your submission. You don't want to duplicate effort.
|
||||
* Please sign our [Contributor License Agreement (CLA)](#cla) before sending PRs.
|
||||
1. Please sign our [Contributor License Agreement (CLA)](#cla) before sending PRs.
|
||||
We cannot accept code without this.
|
||||
* Make your changes in a new git branch:
|
||||
1. Fork the angular/angular repo.
|
||||
1. Make your changes in a new git branch:
|
||||
|
||||
```shell
|
||||
git checkout -b my-fix-branch master
|
||||
```
|
||||
|
||||
* Create your patch, **including appropriate test cases**.
|
||||
* Follow our [Coding Rules](#rules).
|
||||
* Run the full Angular test suite, as described in the [developer documentation][dev-doc],
|
||||
1. Create your patch, **including appropriate test cases**.
|
||||
1. Follow our [Coding Rules](#rules).
|
||||
1. Run the full Angular test suite, as described in the [developer documentation][dev-doc],
|
||||
and ensure that all tests pass.
|
||||
* Commit your changes using a descriptive commit message that follows our
|
||||
1. Commit your changes using a descriptive commit message that follows our
|
||||
[commit message conventions](#commit). Adherence to these conventions
|
||||
is necessary because release notes are automatically generated from these messages.
|
||||
|
||||
@ -92,13 +93,13 @@ Before you submit your Pull Request (PR) consider the following guidelines:
|
||||
```
|
||||
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
|
||||
|
||||
* Push your branch to GitHub:
|
||||
1. Push your branch to GitHub:
|
||||
|
||||
```shell
|
||||
git push origin my-fix-branch
|
||||
```
|
||||
|
||||
* In GitHub, send a pull request to `angular:master`.
|
||||
1. In GitHub, send a pull request to `angular:master`.
|
||||
* If we suggest changes then:
|
||||
* Make the required updates.
|
||||
* Re-run the Angular test suites to ensure tests are still passing.
|
||||
|
@ -5,8 +5,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
|
||||
git_repository(
|
||||
name = "build_bazel_rules_nodejs",
|
||||
remote = "https://github.com/bazelbuild/rules_nodejs.git",
|
||||
# TODO(alexeagle): use the correct tag here.
|
||||
commit = "2c6243df53fd33fdab283ebdd01582e4eb815db8",
|
||||
commit = "0.2.1",
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
|
||||
|
@ -1,9 +1,10 @@
|
||||
<hr>
|
||||
<h4>{{hero.name}} Detail</h4>
|
||||
<div>Id: {{hero.id}}</div>
|
||||
<div>Name:
|
||||
<label>Name:
|
||||
<!-- #docregion ngModel -->
|
||||
<input [(ngModel)]="hero.name">
|
||||
<!-- #enddocregion ngModel -->
|
||||
</div>
|
||||
<div>Power:<input [(ngModel)]="hero.power"></div>
|
||||
</label>
|
||||
<br />
|
||||
<label>Power: <input [(ngModel)]="hero.power"></label>
|
||||
|
@ -7,7 +7,7 @@ import { TaxRateService } from './tax-rate.service';
|
||||
selector: 'app-sales-tax',
|
||||
template: `
|
||||
<h2>Sales Tax Calculator</h2>
|
||||
Amount: <input #amountBox (change)="0">
|
||||
<label>Amount: <input #amountBox (change)="0"></label>
|
||||
|
||||
<div *ngIf="amountBox.value">
|
||||
The sales tax is
|
||||
|
@ -2,5 +2,6 @@
|
||||
import { registerLocaleData } from '@angular/common';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
|
||||
registerLocaleData(localeFr);
|
||||
// the second parameter 'fr' is optional
|
||||
registerLocaleData(localeFr, 'fr');
|
||||
// #enddocregion import-locale
|
||||
|
@ -1,7 +1,7 @@
|
||||
// #docregion import-locale-extra
|
||||
import { registerLocaleData } from '@angular/common';
|
||||
import localeFrCa from '@angular/common/locales/fr-CA';
|
||||
import localeFrCaExtra from '@angular/common/locales/extra/fr-CA';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import localeFrExtra from '@angular/common/locales/extra/fr';
|
||||
|
||||
registerLocaleData(localeFrCa, localeFrCaExtra);
|
||||
registerLocaleData(localeFr, 'fr-FR', localeFrExtra);
|
||||
// #enddocregion import-locale-extra
|
||||
|
37
aio/content/examples/service-worker-getstart/e2e/app.e2e-spec.ts
Executable file
37
aio/content/examples/service-worker-getstart/e2e/app.e2e-spec.ts
Executable file
@ -0,0 +1,37 @@
|
||||
import { AppPage } from './app.po';
|
||||
import { browser, element, by } from 'protractor';
|
||||
|
||||
describe('sw-example App', () => {
|
||||
let page: AppPage;
|
||||
let logo = element(by.css('img'));
|
||||
|
||||
beforeEach(() => {
|
||||
page = new AppPage();
|
||||
});
|
||||
|
||||
it('should display welcome message', () => {
|
||||
page.navigateTo();
|
||||
expect(page.getParagraphText()).toEqual('Welcome to Service Workers!');
|
||||
});
|
||||
|
||||
it('should display the Angular logo', () => {
|
||||
page.navigateTo();
|
||||
expect(logo.isPresent()).toBe(true);
|
||||
});
|
||||
|
||||
it('should show a header for the list of links', function () {
|
||||
const listHeader = element(by.css('app-root > h2'));
|
||||
expect(listHeader.getText()).toEqual('Here are some links to help you start:');
|
||||
});
|
||||
|
||||
it('should show a list of links', function () {
|
||||
element.all(by.css('ul > li > h2 > a')).then(function(items) {
|
||||
expect(items.length).toBe(4);
|
||||
expect(items[0].getText()).toBe('Angular Service Worker Intro');
|
||||
expect(items[1].getText()).toBe('Tour of Heroes');
|
||||
expect(items[2].getText()).toBe('CLI Documentation');
|
||||
expect(items[3].getText()).toBe('Angular blog');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
23
aio/content/examples/service-worker-getstart/src/app/app.component.html
Executable file
23
aio/content/examples/service-worker-getstart/src/app/app.component.html
Executable file
@ -0,0 +1,23 @@
|
||||
<!--The content below is only a placeholder and can be replaced.-->
|
||||
<div style="text-align:center">
|
||||
<h1>
|
||||
Welcome to {{title}}!
|
||||
</h1>
|
||||
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
|
||||
</div>
|
||||
<h2>Here are some links to help you start: </h2>
|
||||
<ul>
|
||||
<li>
|
||||
<h2><a target="_blank" rel="noopener" href="https://angular.io/service-worker-intro">Angular Service Worker Intro</a></h2>
|
||||
</li>
|
||||
<li>
|
||||
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
|
||||
</li>
|
||||
<li>
|
||||
<h2><a target="_blank" rel="noopener" href="https://github.com/angular/angular-cli/wiki">CLI Documentation</a></h2>
|
||||
</li>
|
||||
<li>
|
||||
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
|
||||
</li>
|
||||
</ul>
|
||||
|
27
aio/content/examples/service-worker-getstart/src/app/app.component.spec.ts
Executable file
27
aio/content/examples/service-worker-getstart/src/app/app.component.spec.ts
Executable file
@ -0,0 +1,27 @@
|
||||
import { TestBed, async } from '@angular/core/testing';
|
||||
import { AppComponent } from './app.component';
|
||||
describe('AppComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [
|
||||
AppComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
it('should create the app', async(() => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
}));
|
||||
it(`should have as title 'app'`, async(() => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app.title).toEqual('app');
|
||||
}));
|
||||
it('should render title in a h1 tag', async(() => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.debugElement.nativeElement;
|
||||
expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
|
||||
}));
|
||||
});
|
10
aio/content/examples/service-worker-getstart/src/app/app.component.ts
Executable file
10
aio/content/examples/service-worker-getstart/src/app/app.component.ts
Executable file
@ -0,0 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
templateUrl: './app.component.html',
|
||||
styleUrls: ['./app.component.css']
|
||||
})
|
||||
export class AppComponent {
|
||||
title = 'Service Workers';
|
||||
}
|
31
aio/content/examples/service-worker-getstart/src/app/app.module.ts
Executable file
31
aio/content/examples/service-worker-getstart/src/app/app.module.ts
Executable file
@ -0,0 +1,31 @@
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
// #docregion sw-import
|
||||
import { ServiceWorkerModule } from '@angular/service-worker';
|
||||
import { environment } from '../environments/environment';
|
||||
// #enddocregion sw-import
|
||||
|
||||
import { CheckForUpdateService } from './check-for-update.service';
|
||||
import { LogUpdateService } from './log-update.service';
|
||||
import { PromptUpdateService } from './prompt-update.service';
|
||||
|
||||
// #docregion sw-module
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AppComponent
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
ServiceWorkerModule.register('/ngsw-worker.js', {enabled: environment.production})
|
||||
],
|
||||
providers: [
|
||||
CheckForUpdateService,
|
||||
LogUpdateService,
|
||||
PromptUpdateService,
|
||||
],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule { }
|
||||
// #enddocregion sw-module
|
@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SwUpdate } from '@angular/service-worker';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/observable/interval';
|
||||
|
||||
function promptUser(event): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
// #docregion sw-check-update
|
||||
@Injectable()
|
||||
export class CheckForUpdateService {
|
||||
|
||||
constructor(updates: SwUpdate) {
|
||||
Observable.interval(6 * 60 * 60).subscribe(() => updates.checkForUpdate());
|
||||
}
|
||||
}
|
||||
// #enddocregion sw-check-update
|
19
aio/content/examples/service-worker-getstart/src/app/log-update.service.ts
Executable file
19
aio/content/examples/service-worker-getstart/src/app/log-update.service.ts
Executable file
@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SwUpdate } from '@angular/service-worker';
|
||||
|
||||
// #docregion sw-update
|
||||
@Injectable()
|
||||
export class LogUpdateService {
|
||||
|
||||
constructor(updates: SwUpdate) {
|
||||
updates.available.subscribe(event => {
|
||||
console.log('current version is', event.current);
|
||||
console.log('available version is', event.available);
|
||||
});
|
||||
updates.activated.subscribe(event => {
|
||||
console.log('old version was', event.previous);
|
||||
console.log('new version is', event.current);
|
||||
});
|
||||
}
|
||||
}
|
||||
// #enddocregion sw-update
|
@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SwUpdate } from '@angular/service-worker';
|
||||
|
||||
function promptUser(event): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
// #docregion sw-activate
|
||||
@Injectable()
|
||||
export class PromptUpdateService {
|
||||
|
||||
constructor(updates: SwUpdate) {
|
||||
updates.available.subscribe(event => {
|
||||
if (promptUser(event)) {
|
||||
updates.activateUpdate().then(() => document.location.reload());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// #enddocregion sw-activate
|
14
aio/content/examples/service-worker-getstart/src/index.html
Executable file
14
aio/content/examples/service-worker-getstart/src/index.html
Executable file
@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>SwExample</title>
|
||||
<base href="/">
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
12
aio/content/examples/service-worker-getstart/src/main.ts
Executable file
12
aio/content/examples/service-worker-getstart/src/main.ts
Executable file
@ -0,0 +1,12 @@
|
||||
import { enableProdMode } from '@angular/core';
|
||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||
|
||||
import { AppModule } from './app/app.module';
|
||||
import { environment } from './environments/environment';
|
||||
|
||||
if (environment.production) {
|
||||
enableProdMode();
|
||||
}
|
||||
|
||||
platformBrowserDynamic().bootstrapModule(AppModule)
|
||||
.catch(err => console.log(err));
|
28
aio/content/examples/service-worker-getstart/src/ngsw-config.json
Executable file
28
aio/content/examples/service-worker-getstart/src/ngsw-config.json
Executable file
@ -0,0 +1,28 @@
|
||||
|
||||
{
|
||||
"index": "/index.html",
|
||||
"assetGroups": [{
|
||||
"name": "app",
|
||||
"installMode": "prefetch",
|
||||
"resources": {
|
||||
"files": [
|
||||
"/favicon.ico",
|
||||
"/index.html"
|
||||
],
|
||||
"versionedFiles": [
|
||||
"/*.bundle.css",
|
||||
"/*.bundle.js",
|
||||
"/*.chunk.js"
|
||||
]
|
||||
}
|
||||
}, {
|
||||
"name": "assets",
|
||||
"installMode": "lazy",
|
||||
"updateMode": "prefetch",
|
||||
"resources": {
|
||||
"files": [
|
||||
"/assets/**"
|
||||
]
|
||||
}
|
||||
}]
|
||||
}
|
@ -37,7 +37,7 @@ describe('Structural Directives', function () {
|
||||
expect(paragraph.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it('myUnless should show 3 paragraph (A)s and (B)s at the start', function () {
|
||||
it('appUnless should show 3 paragraph (A)s and (B)s at the start', function () {
|
||||
const paragraph = element.all(by.css('p.unless'));
|
||||
expect(paragraph.count()).toEqual(3);
|
||||
for (let i = 0; i < 3; i++) {
|
||||
@ -45,7 +45,7 @@ describe('Structural Directives', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('myUnless should show 1 paragraph (B) after toggling condition', function () {
|
||||
it('appUnless should show 1 paragraph (B) after toggling condition', function () {
|
||||
const toggleConditionButton = element.all(by.cssContainingText('button', 'Toggle condition')).get(0);
|
||||
const paragraph = element.all(by.css('p.unless'));
|
||||
|
||||
|
@ -188,7 +188,7 @@
|
||||
|
||||
<hr>
|
||||
|
||||
<h2 id="myUnless">UnlessDirective</h2>
|
||||
<h2 id="appUnless">UnlessDirective</h2>
|
||||
<p>
|
||||
The condition is currently
|
||||
<span [ngClass]="{ 'a': !condition, 'b': condition, 'unless': true }">{{condition}}</span>.
|
||||
@ -198,31 +198,31 @@
|
||||
Toggle condition to {{condition ? 'false' : 'true'}}
|
||||
</button>
|
||||
</p>
|
||||
<!-- #docregion myUnless-->
|
||||
<!-- #docregion appUnless-->
|
||||
<p *appUnless="condition" class="unless a">
|
||||
(A) This paragraph is displayed because the condition is false.
|
||||
</p>
|
||||
|
||||
<p *appUnless="!condition" class="unless b">
|
||||
(B) Although the condition is true,
|
||||
this paragraph is displayed because myUnless is set to false.
|
||||
this paragraph is displayed because appUnless is set to false.
|
||||
</p>
|
||||
<!-- #enddocregion myUnless-->
|
||||
<!-- #enddocregion appUnless-->
|
||||
|
||||
|
||||
<h4>UnlessDirective with template</h4>
|
||||
|
||||
<!-- #docregion myUnless-1 -->
|
||||
<!-- #docregion appUnless-1 -->
|
||||
<p *appUnless="condition">Show this sentence unless the condition is true.</p>
|
||||
<!-- #enddocregion myUnless-1 -->
|
||||
<!-- #enddocregion appUnless-1 -->
|
||||
|
||||
<p *appUnless="condition" class="code unless">
|
||||
(A) <p *myUnless="condition" class="code unless">
|
||||
(A) <p *appUnless="condition" class="code unless">
|
||||
</p>
|
||||
|
||||
<ng-template [appUnless]="condition">
|
||||
<p class="code unless">
|
||||
(A) <ng-template [myUnless]="condition">
|
||||
(A) <ng-template [appUnless]="condition">
|
||||
</p>
|
||||
</ng-template>
|
||||
|
||||
|
@ -8,7 +8,7 @@ import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core';
|
||||
* Add the template content to the DOM unless the condition is true.
|
||||
// #enddocregion no-docs
|
||||
*
|
||||
* If the expression assigned to `myUnless` evaluates to a truthy value
|
||||
* If the expression assigned to `appUnless` evaluates to a truthy value
|
||||
* then the templated elements are removed removed from the DOM,
|
||||
* the templated elements are (re)inserted into the DOM.
|
||||
*
|
||||
@ -18,8 +18,8 @@ import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core';
|
||||
*
|
||||
* ### Syntax
|
||||
*
|
||||
* - `<div *myUnless="condition">...</div>`
|
||||
* - `<ng-template [myUnless]="condition"><div>...</div></ng-template>`
|
||||
* - `<div *appUnless="condition">...</div>`
|
||||
* - `<ng-template [appUnless]="condition"><div>...</div></ng-template>`
|
||||
*
|
||||
// #docregion no-docs
|
||||
*/
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase _before_ the browser downloads and runs that code.
|
||||
|
||||
This guide explains how to to build with the AOT compiler and how to write Angular metadata that AOT can compile.
|
||||
This guide explains how to build with the AOT compiler and how to write Angular metadata that AOT can compile.
|
||||
|
||||
<div class="l-sub-section">
|
||||
|
||||
|
@ -245,7 +245,8 @@ See the [CLI documentation](https://github.com/angular/angular-cli/wiki/stories-
|
||||
|
||||
### Non-CSS style files
|
||||
|
||||
You can write style files in [sass](http://sass-lang.com/), [less](http://lesscss.org/), or [stylus](http://stylus-lang.com/) and specify those files in the `styleUrls` metadata, e.g.,
|
||||
If you're building with the CLI,
|
||||
you can write style files in [sass](http://sass-lang.com/), [less](http://lesscss.org/), or [stylus](http://stylus-lang.com/) and specify those files in the `@Component.styleUrls` metadata with the appropriate extensions (`.scss`, `.less`, `.styl`) as in the following example:
|
||||
|
||||
<code-example>
|
||||
@Component({
|
||||
@ -256,10 +257,18 @@ You can write style files in [sass](http://sass-lang.com/), [less](http://lesscs
|
||||
...
|
||||
</code-example>
|
||||
|
||||
The CLI build process runs the corresponding CSS pre-processors.
|
||||
The CLI build process runs the pertinent CSS preprocessor.
|
||||
|
||||
You can also configure the CLI to default to your preferred CSS pre-processer
|
||||
as explained in the [CLI documentation](https://github.com/angular/angular-cli/wiki/stories-css-preprocessors).
|
||||
When generating a component file with `ng generate component`, the CLI emits an empty CSS styles file (`.css`) by default.
|
||||
You can configure the CLI to default to your preferred CSS preprocessor
|
||||
as explained in the [CLI documentation](https://github.com/angular/angular-cli/wiki/stories-css-preprocessors
|
||||
"CSS Preprocessor integration").
|
||||
|
||||
<div class="alert is-important">
|
||||
|
||||
Style strings added to the `@Component.styles` array _must be written in CSS_ because the CLI cannot apply a preprocessor to inline styles.
|
||||
|
||||
</div>
|
||||
|
||||
{@a view-encapsulation}
|
||||
|
||||
|
@ -8,7 +8,6 @@ See the <live-example downloadOnly name="i18n">i18n Example</live-example> for a
|
||||
an AOT-compiled app, translated into French.
|
||||
|
||||
{@a angular-i18n}
|
||||
|
||||
## Angular and i18n
|
||||
|
||||
Angular simplifies the following aspects of internationalization:
|
||||
@ -62,6 +61,23 @@ For more information about Unicode locale identifiers, see the
|
||||
For a complete list of locales supported by Angular, see
|
||||
[the Angular repository](https://github.com/angular/angular/tree/master/packages/common/locales).
|
||||
|
||||
The locale identifiers used by CLDR and Angular are based on [BCP47](http://www.rfc-editor.org/rfc/bcp/bcp47.txt).
|
||||
These specifications change over time; the following table maps previous identifiers to current ones at
|
||||
time of writing:
|
||||
|
||||
| Locale name | Old locale id | New locale id |
|
||||
|-------------------------------|-------------------|---------------|
|
||||
| Indonesian | in | id |
|
||||
| Hebrew | iw | he |
|
||||
| Romanian Moldova | mo | ro-MD |
|
||||
| Norwegian Bokmål | no, no-NO | nb |
|
||||
| Serbian Latin | sh | sr-Latn |
|
||||
| Filipino | tl | fil |
|
||||
| Portuguese Brazil | pt-BR | pt |
|
||||
| Chinese Simplified | zh-cn, zh-Hans-CN | zh-Hans |
|
||||
| Chinese Traditional | zh-tw, zh-Hant-TW | zh-Hant |
|
||||
| Chinese Traditional Hong Kong | zh-hk | zh-Hant-HK |
|
||||
|
||||
|
||||
## i18n pipes
|
||||
|
||||
@ -78,6 +94,14 @@ If you want to import locale data for other languages, you can do it manually:
|
||||
<code-example path="i18n/doc-files/app.locale_data.ts" region="import-locale" title="src/app/app.module.ts" linenums="false">
|
||||
</code-example>
|
||||
|
||||
The first parameter is an object containing the locale data imported from `@angular/common/locales`.
|
||||
By default, the imported locale data is registered with the locale id that is defined in the Angular
|
||||
locale data itself.
|
||||
If you want to register the imported locale data with another locale id, use the second parameter to
|
||||
specify a custom locale id. For example, Angular's locale data defines the locale id for French as
|
||||
"fr". You can use the second parameter to associate the imported French locale data with the custom
|
||||
locale id "fr-FR instead of "fr".
|
||||
|
||||
The files in `@angular/common/locales` contain most of the locale data that you
|
||||
need, but some advanced formatting options might only be available in the extra dataset that you can
|
||||
import from `@angular/common/locales/extra`. An error message informs you when this is the case.
|
||||
@ -118,7 +142,6 @@ in the target language.
|
||||
You need to build and deploy a separate version of the app for each supported language.
|
||||
|
||||
{@a i18n-attribute}
|
||||
|
||||
### Mark text with the i18n attribute
|
||||
|
||||
The Angular `i18n` attribute marks translatable content. Place it on every element tag whose fixed
|
||||
@ -144,7 +167,6 @@ To mark the greeting for translation, add the `i18n` attribute to the `<h1>` tag
|
||||
|
||||
|
||||
{@a help-translator}
|
||||
|
||||
### Help the translator with a description and meaning
|
||||
|
||||
To translate a text message accurately, the translator may need additional information or context.
|
||||
@ -175,7 +197,6 @@ text messages with different descriptions (not different meanings), then they ar
|
||||
|
||||
|
||||
{@a custom-id}
|
||||
|
||||
### Set a custom id for persistence and maintenance
|
||||
|
||||
The angular i18n extractor tool generates a file with a translation unit entry for each `i18n`
|
||||
@ -250,7 +271,6 @@ the same text, `Bonjour`:
|
||||
|
||||
|
||||
{@a no-element}
|
||||
|
||||
### Translate text without creating an element
|
||||
|
||||
If there is a section of text that you would like to translate, you can wrap it in a `<span>` tag.
|
||||
@ -262,7 +282,6 @@ The `<ng-container>` is transformed into an html comment:
|
||||
</code-example>
|
||||
|
||||
{@a translate-attributes}
|
||||
|
||||
## Add i18n translation attributes
|
||||
|
||||
You also can translate attributes.
|
||||
@ -286,7 +305,6 @@ You also can assign a meaning, description, and id with the `i18n-x="<meaning>|<
|
||||
syntax.
|
||||
|
||||
{@a plural-ICU}
|
||||
|
||||
## Translate singular and plural
|
||||
|
||||
Different languages have different pluralization rules.
|
||||
@ -342,7 +360,6 @@ for two, three, or any other number if the pluralization rules were different. F
|
||||
</div>
|
||||
|
||||
{@a select-ICU}
|
||||
|
||||
## Select among alternative text messages
|
||||
|
||||
If your template needs to display different text messages depending on the value of a variable, you
|
||||
@ -360,7 +377,6 @@ The message maps those values to the appropriate translations:
|
||||
</code-example>
|
||||
|
||||
{@a nesting-ICUS}
|
||||
|
||||
## Nesting plural and select ICU expressions
|
||||
|
||||
You can also nest different ICU expressions together, as shown in this example:
|
||||
@ -369,7 +385,6 @@ You can also nest different ICU expressions together, as shown in this example:
|
||||
</code-example>
|
||||
|
||||
{@a ng-xi18n}
|
||||
|
||||
## Create a translation source file with _ng xi18n_
|
||||
|
||||
Use the `ng xi18n` command provided by the CLI to extract the text messages marked with `i18n` into
|
||||
@ -394,7 +409,6 @@ package, or you can manually use the CLI Webpack plugin `ExtractI18nPlugin` from
|
||||
</div>
|
||||
|
||||
{@a other-formats}
|
||||
|
||||
### Other translation formats
|
||||
|
||||
Angular i18n tooling supports three translation formats:
|
||||
@ -422,7 +436,6 @@ The sample in this guide uses the default XLIFF 1.2 format.
|
||||
</div>
|
||||
|
||||
{@a ng-xi18n-options}
|
||||
|
||||
### Other options
|
||||
|
||||
You can specify the output path used by the CLI to extract your translation source file with
|
||||
@ -456,7 +469,6 @@ file. This information is not used by Angular, but external translation tools ma
|
||||
|
||||
|
||||
{@a translate}
|
||||
|
||||
## Translate text messages
|
||||
|
||||
The `ng xi18n` command generates a translation source file named `messages.xlf` in the project `src`
|
||||
@ -466,7 +478,6 @@ The next step is to translate this source file into the specific language
|
||||
translation files. The example in this guide creates a French translation file.
|
||||
|
||||
{@a localization-folder}
|
||||
|
||||
### Create a localization folder
|
||||
|
||||
Most apps are translated into more than one other language. For this reason, it is standard practice
|
||||
@ -500,7 +511,6 @@ For this example:
|
||||
If you were translating to other languages, you would repeat these steps for each target language.
|
||||
|
||||
{@a translate-text-nodes}
|
||||
|
||||
### Translate text nodes
|
||||
|
||||
In a large translation project, you would send the `messages.fr.xlf` file to a French translator who
|
||||
@ -544,7 +554,6 @@ This sample file is easy to translate without a special editor or knowledge of F
|
||||
</div>
|
||||
|
||||
{@a translate-plural-select}
|
||||
|
||||
## Translate plural and select expressions
|
||||
|
||||
_Plural_ and _select_ ICU expressions are extracted separately, so they require special attention
|
||||
@ -555,7 +564,6 @@ elsewhere in the source template. In this example, you know the translation unit
|
||||
must be just below the translation unit for the logo.
|
||||
|
||||
{@a translate-plural}
|
||||
|
||||
### Translate _plural_
|
||||
|
||||
To translate a `plural`, translate its ICU format match values:
|
||||
@ -567,7 +575,6 @@ You can add or remove plural cases, with each language having its own cardinalit
|
||||
[CLDR plural rules](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html).)
|
||||
|
||||
{@a translate-select}
|
||||
|
||||
### Translate _select_
|
||||
|
||||
Below is the content of our example `select` ICU expression in the component template:
|
||||
@ -598,7 +605,6 @@ Here they are together, after translation:
|
||||
</code-example>
|
||||
|
||||
{@a translate-nested}
|
||||
|
||||
### Translate a nested expression
|
||||
|
||||
A nested expression is similar to the previous examples. As in the previous example, there are
|
||||
@ -621,7 +627,6 @@ The entire template translation is complete. The next section describes how to l
|
||||
into the app.
|
||||
|
||||
{@a app-pre-translation}
|
||||
|
||||
### The app and its translation file
|
||||
|
||||
The sample app and its translation file are now as follows:
|
||||
@ -640,7 +645,6 @@ The sample app and its translation file are now as follows:
|
||||
</code-tabs>
|
||||
|
||||
{@a merge}
|
||||
|
||||
## Merge the completed translation file into the app
|
||||
|
||||
To merge the translated text into component templates, compile the app with the completed
|
||||
@ -656,12 +660,11 @@ format that Angular understands, such as `.xtb`.
|
||||
How you provide this information depends upon whether you compile with
|
||||
the JIT compiler or the AOT compiler.
|
||||
|
||||
* With [AOT](guide/i18n#aot), you pass the information as a CLI parameter.
|
||||
* With [JIT](guide/i18n#jit), you provide the information at bootstrap time.
|
||||
* With [AOT](guide/i18n#merge-aot), you pass the information as a CLI parameter.
|
||||
* With [JIT](guide/i18n#merge-jit), you provide the information at bootstrap time.
|
||||
|
||||
|
||||
{@a aot}
|
||||
|
||||
{@a merge-aot}
|
||||
### Merge with the AOT compiler
|
||||
|
||||
The AOT (_Ahead-of-Time_) compiler is part of a build process that produces a small, fast,
|
||||
@ -685,8 +688,7 @@ guide:
|
||||
ng serve --aot --i18nFile=src/locale/messages.fr.xlf --i18nFormat=xlf --locale=fr
|
||||
</code-example>
|
||||
|
||||
{@a jit}
|
||||
|
||||
{@a merge-jit}
|
||||
### Merge with the JIT compiler
|
||||
|
||||
The JIT compiler compiles the app in the browser as the app loads.
|
||||
@ -713,3 +715,29 @@ Then provide the `LOCALE_ID` in the main module:
|
||||
|
||||
<code-example path="i18n/doc-files/app.module.ts" title="src/app/app.module.ts" linenums="false">
|
||||
</code-example>
|
||||
|
||||
|
||||
{@a missing-translation}
|
||||
### Report missing translations
|
||||
By default, when a translation is missing, the build succeeds but generates a warning such as
|
||||
`Missing translation for message "foo"`. You can configure the level of warning that is generated by
|
||||
the Angular compiler:
|
||||
|
||||
* Error: throw an error. If you are using AOT compilation, the build will fail. If you are using JIT
|
||||
compilation, the app will fail to load.
|
||||
* Warning (default): show a 'Missing translation' warning in the console or shell.
|
||||
* Ignore: do nothing.
|
||||
|
||||
If you use the AOT compiler, specify the warning level by using the CLI parameter
|
||||
`--missingTranslation`. The example below shows how to set the warning level to error:
|
||||
|
||||
<code-example language="sh" class="code-shell">
|
||||
ng serve --aot --missingTranslation=error
|
||||
</code-example>
|
||||
|
||||
If you use the JIT compiler, specify the warning level in the compiler config at bootstrap by adding
|
||||
the 'MissingTranslationStrategy' property. The example below shows how to set the warning level to
|
||||
error:
|
||||
|
||||
<code-example path="i18n/doc-files/main.3.ts" title="src/main.ts">
|
||||
</code-example>
|
||||
|
41
aio/content/guide/service-worker-comm.md
Normal file
41
aio/content/guide/service-worker-comm.md
Normal file
@ -0,0 +1,41 @@
|
||||
# Communicating with service workers
|
||||
|
||||
Importing `ServiceWorkerModule` into your `AppModule` doesn't just register the service worker, it also provides a few services you can use to interact with the service worker and control the caching of your app.
|
||||
|
||||
## `SwUpdate` service
|
||||
|
||||
The `SwUpdate` service gives you access to events that indicate when the service worker has discovered an available update for your app or when it has activated such an update—meaning it is now serving content from that update to your app.
|
||||
|
||||
The `SwUpdate` service supports four separate operations:
|
||||
* Getting notified of *available* updates. These are new versions of the app to be loaded if the page is refreshed.
|
||||
* Getting notified of update *activation*. This is when the service worker starts serving a new version of the app immediately.
|
||||
* Asking the service worker to check the server for new updates.
|
||||
* Asking the service worker to activate the latest version of the app for the current tab.
|
||||
|
||||
### Available and activated updates
|
||||
|
||||
The two update events, `available` and `activated`, are `Observable` properties of `SwUpdate`:
|
||||
|
||||
<code-example path="service-worker-getstart/src/app/log-update.service.ts" linenums="false" title="log-update.service.ts" region="sw-update"> </code-example>
|
||||
|
||||
|
||||
You can use these events to notify the user of a pending update or to refresh their pages when the code they are running is out of date.
|
||||
|
||||
### Checking for updates
|
||||
|
||||
It's possible to ask the service worker to check if any updates have been deployed to the server. You might choose to do this if you have a site that changes frequently or want updates to happen on a schedule.
|
||||
|
||||
Do this with the `checkForUpdate()` method:
|
||||
|
||||
<code-example path="service-worker-getstart/src/app/check-for-update.service.ts" linenums="false" title="check-for-update.service.ts" region="sw-check-update"> </code-example>
|
||||
|
||||
|
||||
This method returns a `Promise` which indicates that the update check has completed successfully, though it does not indicate whether an update was discovered as a result of the check. Even if one is found, the service worker must still successfully download the changed files, which can fail. If successful, the `available` event will indicate availability of a new version of the app.
|
||||
|
||||
### Forcing update activation
|
||||
|
||||
If the current tab needs to be updated to the latest app version immediately, it can ask to do so with the `activateUpdate()` method:
|
||||
|
||||
<code-example path="service-worker-getstart/src/app/prompt-update.service.ts" linenums="false" title="prompt-update.service.ts" region="sw-activate"> </code-example>
|
||||
|
||||
Doing this could break lazy-loading into currently running apps, especially if the lazy-loaded chunks use filenames with hashes, which change every version.
|
161
aio/content/guide/service-worker-configref.md
Normal file
161
aio/content/guide/service-worker-configref.md
Normal file
@ -0,0 +1,161 @@
|
||||
{@a glob}
|
||||
|
||||
# Reference: Configuration file
|
||||
|
||||
The `src/ngsw-config.json` configuration file specifies which files and data URLs the Angular
|
||||
service worker should cache and how it should update the cached files and data. The
|
||||
CLI processes the configuration file during `ng build --prod`. Manually, you can process
|
||||
it with the `ngsw-config` tool:
|
||||
|
||||
```sh
|
||||
ngsw-config dist src/ngswn-config.json /base/href
|
||||
```
|
||||
|
||||
The configuration file uses the JSON format. All file paths must begin with `/`, which is the deployment directory—usually `dist` in CLI projects.
|
||||
|
||||
Patterns use a limited glob format:
|
||||
|
||||
* `**` matches 0 or more path segments.
|
||||
* `*` matches exactly one path segment or filename segment.
|
||||
* The `!` prefix marks the pattern as being negative, meaning that only files that don't match the pattern will be included.
|
||||
|
||||
Example patterns:
|
||||
|
||||
* `/**/*.html` specifies all HTML files.
|
||||
* `/*.html` specifies only HTML files in the root.
|
||||
* `!/**/*.map` exclude all sourcemaps.
|
||||
|
||||
Each section of the configuration file is described below.
|
||||
|
||||
## `appData`
|
||||
|
||||
This section enables you to pass any data you want that describes this particular version of the app.
|
||||
The `SwUpdate` service includes that data in the update notifications. Many apps use this section to provide additional information for the display of UI popups, notifying users of the available update.
|
||||
|
||||
## `index`
|
||||
|
||||
Specifies the file that serves as the index page to satisfy navigation requests. Usually this is `/index.html`.
|
||||
|
||||
## `assetGroups`
|
||||
|
||||
*Assets* are resources that are part of the app version that update along with the app. They can include resources loaded from the page's origin as well as third-party resources loaded from CDNs and other external URLs. As not all such external URLs may be known at build time, URL patterns can be matched.
|
||||
|
||||
This field contains an array of asset groups, each of which defines a set of asset resources and the policy by which they are cached.
|
||||
|
||||
```json
|
||||
{
|
||||
"assetGroups": [{
|
||||
...
|
||||
}, {
|
||||
...
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
Each asset group specifies both a group of resources and a policy that governs them. This policy determines when the resources are fetched and what happens when changes are detected.
|
||||
|
||||
Asset groups follow the Typescript interface shown here:
|
||||
|
||||
```typescript
|
||||
interface AssetGroup {
|
||||
name: string;
|
||||
installMode?: 'prefetch' | 'lazy';
|
||||
updateMode?: 'prefetch' | 'lazy';
|
||||
resources: {
|
||||
files?: string[];
|
||||
versionedFiles?: string[];
|
||||
urls?: string[];
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### `name`
|
||||
|
||||
A `name` is mandatory. It identifies this particular group of assets between versions of the configuration.
|
||||
|
||||
### `installMode`
|
||||
|
||||
The `installMode` determines how these resources are initially cached. The `installMode` can be either of two values:
|
||||
|
||||
* `prefetch` tells the Angular service worker to fetch every single listed resource while it's caching the current version of the app. This is bandwidth-intensive but ensures resources are available whenever they're requested, even if the browser is currently offline.
|
||||
|
||||
* `lazy` does not cache any of the resources up front. Instead, the Angular service worker only caches resources for which it receives requests. This is an on-demand caching mode. Resources that are never requested will not be cached. This is useful for things like images at different resolutions, so the service worker only caches the correct assets for the particular screen and orientation.
|
||||
|
||||
### `updateMode`
|
||||
|
||||
For resources already in the cache, the `updateMode` determines the caching behavior when a new version of the app is discovered. Any resources in the group that have changed since the previous version are updated in accordance with `updateMode`.
|
||||
|
||||
* `prefetch` tells the service worker to download and cache the changed resources immediately.
|
||||
|
||||
* `lazy` tells the service worker to not cache those resources. Instead, it treats them as unrequested and waits until they're requested again before updating them. An `updateMode` of `lazy` is only valid if the `installMode` is also `lazy`.
|
||||
|
||||
### `resources`
|
||||
|
||||
This section describes the resources to cache, broken up into three groups.
|
||||
|
||||
* `files` lists patterns that match files in the distribution directory. These can be single files or glob-like patterns that match a number of files.
|
||||
|
||||
* `versionedFiles` is like `files` but should be used for build artifacts that already include a hash in the filename, which is used for cache busting. The Angular service worker can optimize some aspects of its operation if it can assume file contents are immutable.
|
||||
|
||||
* `urls` includes both URLs and URL patterns that will be matched at runtime. These resources are not fetched directly and do not have content hashes, but they will be cached according to their HTTP headers. This is most useful for CDNs such as the Google Fonts service.
|
||||
|
||||
## `dataGroups`
|
||||
|
||||
Unlike asset resources, data requests are not versioned along with the app. They're cached according to manually-configured policies that are more useful for situations such as API requests and other data dependencies.
|
||||
|
||||
Data groups follow this Typescript interface:
|
||||
|
||||
```typescript
|
||||
export interface DataGroup {
|
||||
name: string;
|
||||
urls: string[];
|
||||
version?: number;
|
||||
cacheConfig: {
|
||||
maxSize: number;
|
||||
maxAge: string;
|
||||
timeout?: string;
|
||||
strategy?: 'freshness' | 'performance';
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### `name`
|
||||
Similar to `assetGroups`, every data group has a `name` which uniquely identifies it.
|
||||
|
||||
### `urls`
|
||||
A list of URL patterns. URLs that match these patterns will be cached according to this data group's policy.
|
||||
|
||||
### `version`
|
||||
Occasionally APIs change formats in a way that is not backward-compatible. A new version of the app may not be compatible with the old API format and thus may not be compatible with existing cached resources from that API.
|
||||
|
||||
`version` provides a mechanism to indicate that the resources being cached have been updated in a backwards-incompatible way, and that the old cache entries—those from previous versions—should be discarded.
|
||||
|
||||
`version` is an integer field and defaults to `0`.
|
||||
|
||||
### `cacheConfig`
|
||||
This section defines the policy by which matching requests will be cached.
|
||||
|
||||
#### `maxSize`
|
||||
(required) The maximum number of entries, or responses, in the cache. Open-ended caches can grow in unbounded ways and eventually exceed storage quotas, calling for eviction.
|
||||
|
||||
#### `maxAge`
|
||||
(required) The `maxAge` parameter indicates how long responses are allowed to remain in the cache before being considered invalid and evicted. `maxAge` is a duration string, using the following unit suffixes:
|
||||
|
||||
* `d`: days
|
||||
* `h`: hours
|
||||
* `m`: minutes
|
||||
* `s`: seconds
|
||||
* `u`: milliseconds
|
||||
|
||||
For example, the string `3d12h` will cache content for up to three and a half days.
|
||||
|
||||
#### `timeout`
|
||||
This duration string specifies the network timeout. The network timeout is how long the Angular service worker will wait for the network to respond before using a cached response, if configured to do so.
|
||||
|
||||
#### `strategy`
|
||||
|
||||
The Angular service worker can use either of two caching strategies for data resources.
|
||||
|
||||
* `performance`, the default, optimizes for responses that are as fast as possible. If a resource exists in the cache, the cached version is used. This allows for some staleness, depending on the `maxAge`, in exchange for better performance. This is suitable for resources that don't change often; for example, user avatar images.
|
||||
|
||||
* `freshness` optimizes for currency of data, preferentially fetching requested data from the network. Only if the network times out, according to `timeout`, does the request fall back to the cache. This is useful for resources that change frequently; for example, account balances.
|
302
aio/content/guide/service-worker-devops.md
Normal file
302
aio/content/guide/service-worker-devops.md
Normal file
@ -0,0 +1,302 @@
|
||||
# DevOps: Angular service worker in production
|
||||
|
||||
This page is a reference for deploying and supporting production apps that use the Angular service worker. It explains how the Angular service worker fits into the larger production environment, the service worker's behavior under various conditions, and available recourses and fail-safes.
|
||||
|
||||
## Service worker and caching of app resources
|
||||
|
||||
Conceptually, you can imagine the Angular service worker as a forward cache or a CDN edge that is installed in the end user's web browser. The service worker's job is to satisfy requests made by the Angular app for resources or data from a local cache, without needing to wait for the network. Like any cache, it has rules for how content is expired and updated.
|
||||
|
||||
{@a versions}
|
||||
|
||||
### App versions
|
||||
|
||||
In the context of an Angular service worker, a "version" is a collection of resources that represent a specific build of the Angular app. Whenever a new build of the app is deployed, the service worker treats that build as a new version of the app. This is true even if only a single file is updated. At any given time, the service worker may have multiple versions of the app in its cache and it may be serving them simultaneously. For more information, see the [App tabs](guide/service-worker-devops#tabs) section below.
|
||||
|
||||
To preserve app integrity, the Angular service worker groups all files into a version together. The files grouped into a version usually include HTML, JS, and CSS files. Grouping of these files is essential for integrity because HTML, JS, and CSS files frequently refer to each other and depend on specific content. For example, an `index.html` file might have a `<script>` tag that references `bundle.js` and it might attempt to call a function `startApp()` from within that script. Any time this version of `index.html` is served, the corresponding `bundle.js` must be served with it. For example, assume that the `startApp()` function is renamed to `runApp()` in both files. In this scenario, it is not valid to serve the old `index.html`, which calls `startApp()`, along with the new bundle, which defines `runApp()`.
|
||||
|
||||
This file integrity is especially important when lazy loading modules.
|
||||
A JS bundle may reference many lazy chunks, and the filenames of the
|
||||
lazy chunks are unique to the particular build of the app. If a running
|
||||
app at version `X` attempts to load a lazy chunk, but the server has
|
||||
updated to version `X + 1` already, the lazy loading operation will fail.
|
||||
|
||||
The version identifier of the app is determined by the contents of all
|
||||
resources, and it changes if any of them change. In practice, the version
|
||||
is determined by the contents of the `ngsw.json` file, which includes
|
||||
hashes for all known content. If any of the cached files change, the file's
|
||||
hash will change in `ngsw.json`, causing the Angular service worker to
|
||||
treat the active set of files as a new version.
|
||||
|
||||
With the versioning behavior of the Angular service worker, an application
|
||||
server can ensure that the Angular app always has a consistent set of files.
|
||||
|
||||
#### Update checks
|
||||
|
||||
Every time the Angular service worker starts, it checks for updates to the
|
||||
app by looking for updates to the `ngsw.json` manifest.
|
||||
|
||||
Note that the service worker starts periodically throughout the usage of
|
||||
the app because the web browser terminates the service worker if the page
|
||||
is idle beyond a given timeout.
|
||||
|
||||
### Resource integrity
|
||||
|
||||
One of the potential side effects of long caching is inadvertently
|
||||
caching an invalid resource. In a normal HTTP cache, a hard refresh
|
||||
or cache expiration limits the negative effects of caching an invalid
|
||||
file. A service worker ignores such constraints and effectively long
|
||||
caches the entire app. Consequently, it is essential that the service worker
|
||||
get the correct content.
|
||||
|
||||
To ensure resource integrity, the Angular service worker validates
|
||||
the hashes of all resources for which it has a hash. Typically for
|
||||
a CLI app, this is everything in the `dist` directory covered by
|
||||
the user's `src/ngsw-config.json` configuration.
|
||||
|
||||
If a particular file fails validation, the Angular service worker
|
||||
attempts to re-fetch the content using a "cache-busting" URL
|
||||
parameter to eliminate the effects of browser or intermediate
|
||||
caching. If that content also fails validation, the service worker
|
||||
considers the entire version of the app to be invalid and it stops
|
||||
serving the app. If necessary, the service worker enters a safe mode
|
||||
where requests fall back on the network, opting not to use its cache
|
||||
if the risk of serving invalid, broken, or outdated content is high.
|
||||
|
||||
Hash mismatches can occur for a variety of reasons:
|
||||
|
||||
* Caching layers in between the origin server and the end user could serve stale content.
|
||||
* A non-atomic deployment could result in the Angular service worker having visibility of partially updated content.
|
||||
* Errors during the build process could result in updated resources without `ngsw.json` being updated. The reverse could also happen resulting in an updated `ngsw.json` without updated resources.
|
||||
|
||||
#### Unhashed content
|
||||
|
||||
The only resources that have hashes in the `ngsw.json`
|
||||
manifest are resources that were present in the `dist`
|
||||
directory at the time the manifest was built. Other
|
||||
resources, especially those loaded from CDNs, have
|
||||
content that is unknown at build time or are updated
|
||||
more frequently than the app is deployed.
|
||||
|
||||
If the Angular service worker does not have a hash to validate
|
||||
a given resource, it still caches its contents but it honors
|
||||
the HTTP caching headers by using a policy of "stale while
|
||||
revalidate." That is, when HTTP caching headers for a cached
|
||||
resource indicate that the resource has expired, the Angular
|
||||
service worker continues to serve the content and it attempts
|
||||
to refresh the resource in the background. This way, broken
|
||||
unhashed resources do not remain in the cache beyond their
|
||||
configured lifetimes.
|
||||
|
||||
{@a tabs}
|
||||
|
||||
### App tabs
|
||||
|
||||
It can be problematic for an app if the version of resources
|
||||
it's receiving changes suddenly or without warning. See the
|
||||
[Versions](guide/service-worker-devops#versions) section above
|
||||
for a description of such issues.
|
||||
|
||||
The Angular service worker provides a guarantee: a running app
|
||||
will continue to run the same version of the app. If another
|
||||
instance of the app is opened in a new web browser tab, then
|
||||
the most current version of the app is served. As a result,
|
||||
that new tab can be running a different version of the app
|
||||
than the original tab.
|
||||
|
||||
It's important to note that this guarantee is **stronger**
|
||||
than that provided by the normal web deployment model. Without
|
||||
a service worker, there is no guarantee that code lazily loaded
|
||||
later in a running app is from the same version as the initial
|
||||
code for the app.
|
||||
|
||||
There are a few limited reasons why the Angular service worker
|
||||
might change the version of a running app. Some of them are
|
||||
error conditions:
|
||||
|
||||
* The current version becomes invalid due to a failed hash.
|
||||
* An unrelated error causes the service worker to enter safe mode; that is, temporary deactivation.
|
||||
|
||||
The Angular service worker is aware of which versions are in
|
||||
use at any given moment and it cleans up versions when
|
||||
no tab is using them.
|
||||
|
||||
Other reasons the Angular service worker might change the version
|
||||
of a running app are normal events:
|
||||
|
||||
* The page is reloaded/refreshed.
|
||||
* The page requests an update be immediately activated via the `SwUpdate` service.
|
||||
|
||||
### Service worker updates
|
||||
|
||||
The Angular service worker is a small script that runs in web browsers.
|
||||
From time to time, the service worker will be updated with bug
|
||||
fixes and feature improvements.
|
||||
|
||||
The Angular service worker is downloaded when the app is first opened
|
||||
and when the app is accessed after a period of inactivity. If the
|
||||
service worker has changed, the service worker will be updated in the background.
|
||||
|
||||
Most updates to the Angular service worker are transparent to the
|
||||
app—the old caches are still valid and content is still served
|
||||
normally. However, occasionally a bugfix or feature in the Angular
|
||||
service worker requires the invalidation of old caches. In this case,
|
||||
the app will be refreshed transparently from the network.
|
||||
|
||||
|
||||
## Debugging the Angular service worker
|
||||
|
||||
Occasionally, it may be necessary to examine the Angular service
|
||||
worker in a running state to investigate issues or to ensure that
|
||||
it is operating as designed. Browsers provide built-in tools for
|
||||
debugging service workers and the Angular service worker itself
|
||||
includes useful debugging features.
|
||||
|
||||
### Locating and analyzing debugging information
|
||||
|
||||
The Angular service worker exposes debugging information under
|
||||
the `ngsw/` virtual directory. Currently, the single exposed URL
|
||||
is `ngsw/state`. Here is an example of this debug page's contents:
|
||||
|
||||
```
|
||||
NGSW Debug Info:
|
||||
|
||||
Driver state: NORMAL ((nominal))
|
||||
Latest manifest hash: eea7f5f464f90789b621170af5a569d6be077e5c
|
||||
Last update check: never
|
||||
|
||||
=== Version eea7f5f464f90789b621170af5a569d6be077e5c ===
|
||||
|
||||
Clients: 7b79a015-69af-4d3d-9ae6-95ba90c79486, 5bc08295-aaf2-42f3-a4cc-9e4ef9100f65
|
||||
|
||||
=== Idle Task Queue ===
|
||||
Last update tick: 1s496u
|
||||
Last update run: never
|
||||
Task queue:
|
||||
* init post-load (update, cleanup)
|
||||
|
||||
Debug log:
|
||||
```
|
||||
|
||||
#### Driver state
|
||||
|
||||
The first line indicates the driver state:
|
||||
|
||||
```
|
||||
Driver state: NORMAL ((nominal))
|
||||
```
|
||||
|
||||
`NORMAL` indicates that the service worker is operating normally and is not in a degraded state.
|
||||
|
||||
There are two possible degraded states:
|
||||
|
||||
* `EXISTING_CLIENTS_ONLY`: the service worker does not have a
|
||||
clean copy of the latest known version of the app. Older cached
|
||||
versions are safe to use, so existing tabs continue to run from
|
||||
cache, but new loads of the app will be served from the network.
|
||||
|
||||
* `SAFE_MODE`: the service worker cannot guarantee the safety of
|
||||
using cached data. Either an unexpected error occurred or all c
|
||||
ached versions are invalid. All traffic will be served from the
|
||||
network, running as little service worker code as possible.
|
||||
|
||||
In both cases, the parenthetical annotation provides the
|
||||
error that caused the service worker to enter the degraded state.
|
||||
|
||||
|
||||
#### Latest manifest hash
|
||||
|
||||
```
|
||||
Latest manifest hash: eea7f5f464f90789b621170af5a569d6be077e5c
|
||||
```
|
||||
|
||||
This is the SHA1 hash of the most up-to-date version of the app that the service worker knows about.
|
||||
|
||||
|
||||
#### Last update check
|
||||
|
||||
```
|
||||
Last update check: never
|
||||
```
|
||||
|
||||
This indicates the last time the service worker checked for a new version, or update, of the app. `never` indicates that the service worker has never checked for an update.
|
||||
|
||||
In this example debug file, the update check is currently scheduled, as explained the next section.
|
||||
|
||||
#### Version
|
||||
|
||||
```
|
||||
=== Version eea7f5f464f90789b621170af5a569d6be077e5c ===
|
||||
|
||||
Clients: 7b79a015-69af-4d3d-9ae6-95ba90c79486, 5bc08295-aaf2-42f3-a4cc-9e4ef9100f65
|
||||
```
|
||||
|
||||
In this example, the service worker has one version of the app cached and
|
||||
being used to serve two different tabs. Note that this version hash
|
||||
is the "latest manifest hash" listed above. Both clients are on the
|
||||
latest version. Each client is listed by its ID from the `Clients`
|
||||
API in the browser.
|
||||
|
||||
|
||||
#### Idle task queue
|
||||
|
||||
```
|
||||
=== Idle Task Queue ===
|
||||
Last update tick: 1s496u
|
||||
Last update run: never
|
||||
Task queue:
|
||||
* init post-load (update, cleanup)
|
||||
```
|
||||
|
||||
The Idle Task Queue is the queue of all pending tasks that happen
|
||||
in the background in the service worker. If there are any tasks
|
||||
in the queue, they are listed with a description. In this example,
|
||||
the service worker has one such task scheduled, a post-initialization
|
||||
operation involving an update check and cleanup of stale caches.
|
||||
|
||||
The last update tick/run counters give the time since specific
|
||||
events happened related to the idle queue. The "Last update run"
|
||||
counter shows the last time idle tasks were actually executed.
|
||||
"Last update tick" shows the time since the last event after
|
||||
which the queue might be processed.
|
||||
|
||||
|
||||
#### Debug log
|
||||
|
||||
```
|
||||
Debug log:
|
||||
```
|
||||
|
||||
Errors that occur within the service worker will be logged here.
|
||||
|
||||
|
||||
### Developer Tools
|
||||
|
||||
Browsers such as Chrome provide developer tools for interacting
|
||||
with service workers. Such tools can be powerful when used properly,
|
||||
but there are a few things to keep in mind.
|
||||
|
||||
* When using developer tools, the service worker is kept running
|
||||
in the background and never restarts. For the Angular service
|
||||
worker, this means that update checks to the app will generally not happen.
|
||||
|
||||
* If you look in the Cache Storage viewer, the cache is frequently
|
||||
out of date. Right click the Cache Storage title and refresh the caches.
|
||||
|
||||
Stopping and starting the service worker in the Service Worker
|
||||
pane triggers a check for updates.
|
||||
|
||||
## Fail-safe
|
||||
|
||||
Like any complex system, bugs or broken configurations can cause
|
||||
the Angular service worker to act in unforeseen ways. While its
|
||||
design attempts to minimize the impact of such problems, the
|
||||
Angular service worker contains a failsafe mechanism in case
|
||||
an administrator ever needs to deactivate the service worker quickly.
|
||||
|
||||
To deactivate the service worker, remove or rename the
|
||||
`ngsw-config.json` file. When the service worker's request
|
||||
for `ngsw.json` returns a `404`, then the service worker
|
||||
removes all of its caches and de-registers itself,
|
||||
essentially self-destructing.
|
||||
|
||||
|
191
aio/content/guide/service-worker-getstart.md
Normal file
191
aio/content/guide/service-worker-getstart.md
Normal file
@ -0,0 +1,191 @@
|
||||
# Getting started
|
||||
|
||||
Beginning in Angular 5.0.0, you can easily enable Angular service worker support in any CLI project. This document explains how to enable Angular service worker support in new and existing projects. It then uses a simple example to show you a service worker in action, demonstrating loading and basic caching.
|
||||
|
||||
See the <live-example></live-example>.
|
||||
|
||||
|
||||
## Adding a service worker to a new application
|
||||
|
||||
If you're generating a new CLI project, you can use the CLI to set up the Angular service worker as part of creating the project. To do so, add the `--service-worker` flag to the `ng new` command:
|
||||
|
||||
```sh
|
||||
ng new my-project --service-worker
|
||||
```
|
||||
|
||||
The `--service-worker` flag takes care of configuring your app to
|
||||
use service workers by adding the `service-worker` package along
|
||||
with setting up the necessary files to support service workers.
|
||||
For information on the details, see the following section
|
||||
which covers the process in detail as it shows you how to add a
|
||||
service worker manually to an existing app.
|
||||
|
||||
|
||||
|
||||
## Adding a service worker to an existing app
|
||||
|
||||
To add a service worker to an existing app:
|
||||
|
||||
1. Add the service worker package.
|
||||
2. Enable service worker build support in the CLI.
|
||||
3. Import and register the service worker.
|
||||
4. Create the service worker configuration file, which specifies the caching behaviors and other settings.
|
||||
5. Build the project.
|
||||
|
||||
### Step 1: Add the service worker package
|
||||
|
||||
Add the package `@angular/service-worker`, using the yarn utility as shown here:
|
||||
|
||||
```sh
|
||||
yarn add @angular/service-worker
|
||||
```
|
||||
|
||||
### Step 2: Enable service worker build support in the CLI
|
||||
|
||||
To enable the Angular service worker, the CLI must generate an Angular service worker manifest at build time. To cause the CLI to generate the manifest for an existing project, set the `serviceWorker` flag to `true` in the project's `.angular-cli.json` file as shown here:
|
||||
|
||||
```sh
|
||||
ng set apps.0.serviceWorker=true
|
||||
```
|
||||
|
||||
### Step 3: Import and register the service worker
|
||||
|
||||
To import and register the Angular service worker:
|
||||
|
||||
At the top of the root module, `src/app/app.module.ts`, import `ServiceWorkerModule` and `environment`.
|
||||
|
||||
<code-example path="service-worker-getstart/src/app/app.module.ts" linenums="false" title="src/app/app.module.ts" region="sw-import"> </code-example>
|
||||
|
||||
|
||||
Add `ServiceWorkerModule` to the `@NgModule` `imports` array. Use the `register()` helper to take care of registering the service worker, taking care to disable the service worker when not running in production mode.
|
||||
|
||||
<code-example path="service-worker-getstart/src/app/app.module.ts" linenums="false" title="src/app/app.module.ts" region="sw-module"> </code-example>
|
||||
|
||||
The file `ngsw-worker.js` is the name of the prebuilt service worker script, which the CLI copies into `dist/` to deploy along with your server.
|
||||
|
||||
### Step 4: Create the configuration file, `ngsw-config.json`
|
||||
|
||||
The Angular CLI needs a service worker configuration file, called `ngsw-config.json`. The configuration file controls how the service worker caches files and data
|
||||
resources.
|
||||
|
||||
You can begin with the boilerplate version from the CLI, which configures sensible defaults for most applications.
|
||||
|
||||
Alternately, save the following as `src/ngsw-config.json`:
|
||||
|
||||
<code-example path="service-worker-getstart/src/ngsw-config.json" linenums="false" title="src/ngsw-config.json"> </code-example>
|
||||
|
||||
### Step 5: Build the project
|
||||
|
||||
Finally, build the project:
|
||||
|
||||
```sh
|
||||
ng build --prod
|
||||
```
|
||||
|
||||
The CLI project is now set up to use the Angular service worker.
|
||||
|
||||
|
||||
## Service worker in action: a tour
|
||||
|
||||
This section demonstrates a service worker in action,
|
||||
using an example application.
|
||||
|
||||
### Serving with `http-server`
|
||||
|
||||
As `ng serve` does not work with service workers, you must use a real HTTP server to test your project locally. It's a good idea to test on a dedicated port.
|
||||
|
||||
```sh
|
||||
cd dist
|
||||
http-server -p 8080
|
||||
```
|
||||
|
||||
### Initial load
|
||||
|
||||
With the server running, you can point your browser at http://localhost:8080/. Your application should load normally.
|
||||
|
||||
**Tip:** When testing Angular service workers, it's a good idea to use an incognito or private window in your browser to ensure the service worker doesn't end up reading from a previous leftover state, which can cause unexpected behavior.
|
||||
|
||||
### Simulating a network issue
|
||||
|
||||
To simulate a network issue, disable network interaction for your application. In Chrome:
|
||||
|
||||
1. Select **Tools** > **Developer Tools** (from the Chrome menu located at the top right corner).
|
||||
2. Go to the **Network tab**.
|
||||
3. Check the **Offline box**.
|
||||
|
||||
<figure>
|
||||
<img src="generated/images/guide/service-worker/offline-checkbox.png" alt="The offline checkbox in the Network tab is checked">
|
||||
</figure>
|
||||
|
||||
Now the app has no access to network interaction.
|
||||
|
||||
For applications that do not use the Angular service worker, refreshing now would display Chrome's Internet disconnected page that says "There is no Internet connection".
|
||||
|
||||
With the addition of an Angular service worker, the application behavior changes. On a refresh, the page loads normally.
|
||||
|
||||
If you look at the Network tab, you can verify that the service worker is active.
|
||||
|
||||
<figure>
|
||||
<img src="generated/images/guide/service-worker/sw-active.png" alt="Requests are marked as from ServiceWorker">
|
||||
</figure>
|
||||
|
||||
Notice that under the "Size" column, the requests state is `(from ServiceWorker)`. This means that the resources are not being loaded from the network. Instead, they are being loaded from the service worker's cache.
|
||||
|
||||
|
||||
### What's being cached?
|
||||
|
||||
Notice that all of the files the browser needs to render this application are cached. The `ngsw-config.json` boilerplate configuration is set up to cache the specific resources used by the CLI:
|
||||
|
||||
* `index.html`.
|
||||
* `favicon.ico`.
|
||||
* Build artifacts (JS and CSS bundles).
|
||||
* Anything under `assets`.
|
||||
|
||||
### Making changes to your application
|
||||
|
||||
Now that you've seen how service workers cache your application, the
|
||||
next step is understanding how updates work.
|
||||
|
||||
1. If you're testing in an incognito window, open a second blank tab. This will keep the incognito and the cache state alive during your test.
|
||||
|
||||
2. Close the application tab, but not the window. This should also close the Developer Tools.
|
||||
|
||||
3. Shut down `http-server`.
|
||||
|
||||
4. Next, make a change to the application, and watch the service worker install the update.
|
||||
|
||||
5. Open `src/app/app.component.html` for editing.
|
||||
|
||||
6. Change the text `Welcome to {{title}}!` to `Bienvenue à {{title}}!`.
|
||||
|
||||
7. Build and run the server again:
|
||||
|
||||
```sh
|
||||
ng build --prod
|
||||
cd dist
|
||||
http-server -p 8080
|
||||
```
|
||||
|
||||
### Updating your application in the browser
|
||||
|
||||
Now look at how the browser and service worker handle the updated application.
|
||||
|
||||
1. Open http://localhost:8080 again in the same window. What happens?
|
||||
|
||||
<figure>
|
||||
<img src="generated/images/guide/service-worker/welcome-msg-en.png" alt="It still says Welcome to Service Workers!">
|
||||
</figure>
|
||||
|
||||
What went wrong? Nothing, actually. The Angular service worker is doing its job and serving the version of the application that it has **installed**, even though there is an update available. In the interest of speed, the service worker doesn't wait to check for updates before it serves the application that it has cached.
|
||||
|
||||
If you look at the `http-server` logs, you can see the service worker requesting `/ngsw.json`. This is how the service worker checks for updates.
|
||||
|
||||
2. Refresh the page.
|
||||

|
||||
|
||||
<figure>
|
||||
<img src="generated/images/guide/service-worker/welcome-msg-fr.png" alt="The text has changed to say Bienvenue à app!">
|
||||
</figure>
|
||||
|
||||
The service worker installed the updated version of your app *in the background*, and the next time the page is loaded or reloaded, the service worker switches to the latest version.
|
||||
|
48
aio/content/guide/service-worker-intro.md
Normal file
48
aio/content/guide/service-worker-intro.md
Normal file
@ -0,0 +1,48 @@
|
||||
# Introduction to Angular service workers
|
||||
|
||||
Service workers augment the traditional web deployment model and empower applications to deliver a user experience with the reliability and performance on par with natively-installed code.
|
||||
|
||||
At its simplest, a service worker is a script that runs in the web browser and manages caching for an application.
|
||||
|
||||
Service workers function as a network proxy. They intercept all outgoing HTTP requests made by the application and can choose how to respond to them. For example, they can query a local cache and deliver a cached response if one is available. Proxying isn't limited to requests made through programmatic APIs, such as `fetch`; it also includes resources referenced in HTML and even the initial request to `index.html`. Service worker-based caching is thus completely programmable and doesn't rely on server-specified caching headers.
|
||||
|
||||
Unlike the other scripts that make up an application, such as the Angular app bundle, the service worker is preserved after the user closes the tab. The next time that browser loads the application, the service worker loads first, and can intercept every request for resources to load the application. If the service worker is designed to do so, it can *completely satisfy the loading of the application, without the need for the network*.
|
||||
|
||||
Even across a fast reliable network, round-trip delays can introduce significant latency when loading the application. Using a service worker to reduce dependency on the network can significantly improve the user experience.
|
||||
|
||||
|
||||
## Service workers in Angular
|
||||
|
||||
Angular applications, as single-page applications, are in a prime position to benefit from the advantages of service workers. Starting with version 5.0.0, Angular ships with a service worker implementation. Angular developers can take advantage of this service worker and benefit from the increased reliability and performance it provides, without needing to code against low-level APIs.
|
||||
|
||||
Angular's service worker is designed to optimize the end user experience of using an application over a slow or unreliable network connection, while also minimizing the risks of serving outdated content.
|
||||
|
||||
The Angular service worker's behavior follows that design goal:
|
||||
|
||||
* Caching an application is like installing a native application. The application is cached as one unit, and all files update together.
|
||||
* A running application continues to run with the same version of all files. It does not suddenly start receiving cached files from a newer version, which are likely incompatible.
|
||||
* When users refresh the application, they see the latest fully cached version. New tabs load the latest cached code.
|
||||
* Updates happen in the background, relatively quickly after changes are published. The previous version of the application is served until an update is installed and ready.
|
||||
* The service worker conserves bandwidth when possible. Resources are only downloaded if they've changed.
|
||||
|
||||
To support these behaviors, the Angular service worker loads a *manifest* file from the server. The manifest describes the resources to cache and includes hashes of every file's contents. When an update to the application is deployed, the contents of the manifest change, informing the service worker that a new version of the application should be downloaded and cached. This manifest is generated from a user-provided configuration file called `ngsw-config.json`, by using a build tool such as the Angular CLI.
|
||||
|
||||
Installing the Angular service worker is as simple as including an `NgModule`. In addition to registering the Angular service worker with the browser, this also makes a few services available for injection which interact with the service worker and can be used to control it. For example, an application can ask to be notified when a new update becomes available, or an application can ask the service worker to check the server for available updates.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
To use Angular service workers, you must have the following Angular and CLI versions:
|
||||
|
||||
* Angular 5.0.0 or later.
|
||||
* Angular CLI 1.6.0 or later.
|
||||
|
||||
Your application must run in a web browser that supports service workers. Currently, the latest versions of Chrome and Firefox are supported. To learn about other browsers that are service worker ready, see the [Can I Use](http://caniuse.com/#feat=serviceworkers) page.
|
||||
|
||||
## Related resources
|
||||
|
||||
For more information about service workers in general, see [Service Workers: an Introduction](https://developers.google.com/web/fundamentals/primers/service-workers/).
|
||||
|
||||
For more information about browser support, see the [browser support](https://developers.google.com/web/fundamentals/primers/service-workers/#browser_support) section of [Service Workers: an Introduction](https://developers.google.com/web/fundamentals/primers/service-workers/), Jake Archibald's [Is Serviceworker ready?](https://jakearchibald.github.io/isserviceworkerready/), and
|
||||
[Can I Use](http://caniuse.com/#feat=serviceworkers).
|
||||
|
||||
The remainder of this Angular documentation specifically addresses the Angular implementation of service workers.
|
@ -625,7 +625,7 @@ that does the opposite of `NgIf`.
|
||||
`UnlessDirective` displays the content when the condition is ***false***.
|
||||
|
||||
|
||||
<code-example path="structural-directives/src/app/app.component.html" linenums="false" title="src/app/app.component.html (myUnless-1)" region="myUnless-1">
|
||||
<code-example path="structural-directives/src/app/app.component.html" linenums="false" title="src/app/app.component.html (appUnless-1)" region="appUnless-1">
|
||||
|
||||
</code-example>
|
||||
|
||||
@ -650,14 +650,14 @@ Here's how you might begin:
|
||||
|
||||
|
||||
|
||||
The directive's _selector_ is typically the directive's **attribute name** in square brackets, `[myUnless]`.
|
||||
The directive's _selector_ is typically the directive's **attribute name** in square brackets, `[appUnless]`.
|
||||
The brackets define a CSS
|
||||
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors" title="MDN: Attribute selectors">attribute selector</a>.
|
||||
|
||||
The directive _attribute name_ should be spelled in _lowerCamelCase_ and begin with a prefix.
|
||||
Don't use `ng`. That prefix belongs to Angular.
|
||||
Pick something short that fits you or your company.
|
||||
In this example, the prefix is `my`.
|
||||
In this example, the prefix is `app`.
|
||||
|
||||
|
||||
The directive _class_ name ends in `Directive` per the [style guide](guide/styleguide#02-03 "Angular Style Guide").
|
||||
@ -685,10 +685,10 @@ You inject both in the directive constructor as private variables of the class.
|
||||
|
||||
|
||||
|
||||
### The _myUnless_ property
|
||||
### The _appUnless_ property
|
||||
|
||||
The directive consumer expects to bind a true/false condition to `[myUnless]`.
|
||||
That means the directive needs a `myUnless` property, decorated with `@Input`
|
||||
The directive consumer expects to bind a true/false condition to `[appUnless]`.
|
||||
That means the directive needs an `appUnless` property, decorated with `@Input`
|
||||
|
||||
|
||||
<div class="l-sub-section">
|
||||
@ -708,8 +708,8 @@ Read about `@Input` in the [_Template Syntax_](guide/template-syntax#inputs-outp
|
||||
|
||||
|
||||
|
||||
Angular sets the `myUnless` property whenever the value of the condition changes.
|
||||
Because the `myUnless` property does work, it needs a setter.
|
||||
Angular sets the `appUnless` property whenever the value of the condition changes.
|
||||
Because the `appUnless` property does work, it needs a setter.
|
||||
|
||||
* If the condition is falsy and the view hasn't been created previously,
|
||||
tell the _view container_ to create the _embedded view_ from the template.
|
||||
@ -717,7 +717,7 @@ tell the _view container_ to create the _embedded view_ from the template.
|
||||
* If the condition is truthy and the view is currently displayed,
|
||||
clear the container which also destroys the view.
|
||||
|
||||
Nobody reads the `myUnless` property so it doesn't need a getter.
|
||||
Nobody reads the `appUnless` property so it doesn't need a getter.
|
||||
|
||||
The completed directive code looks like this:
|
||||
|
||||
@ -733,7 +733,7 @@ Add this directive to the `declarations` array of the AppModule.
|
||||
Then create some HTML to try it.
|
||||
|
||||
|
||||
<code-example path="structural-directives/src/app/app.component.html" linenums="false" title="src/app/app.component.html (myUnless)" region="myUnless">
|
||||
<code-example path="structural-directives/src/app/app.component.html" linenums="false" title="src/app/app.component.html (appUnless)" region="appUnless">
|
||||
|
||||
</code-example>
|
||||
|
||||
|
BIN
aio/content/images/guide/service-worker/offline-checkbox.png
Normal file
BIN
aio/content/images/guide/service-worker/offline-checkbox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
BIN
aio/content/images/guide/service-worker/sw-active.png
Normal file
BIN
aio/content/images/guide/service-worker/sw-active.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
BIN
aio/content/images/guide/service-worker/welcome-msg-en.png
Normal file
BIN
aio/content/images/guide/service-worker/welcome-msg-en.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
BIN
aio/content/images/guide/service-worker/welcome-msg-fr.png
Normal file
BIN
aio/content/images/guide/service-worker/welcome-msg-fr.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
@ -639,6 +639,13 @@
|
||||
"rev": true,
|
||||
"title": "Formation JavaScript (French)",
|
||||
"url": "https://formationjavascript.com/formation-angular/"
|
||||
},
|
||||
"wao": {
|
||||
"desc": "Onsite Angular Training delivered by We Are One Sàrl in Switzerland",
|
||||
"logo": "https://weareone.ch/wordpress/wao-content/uploads/2014/12/logo_200_2x.png",
|
||||
"rev": true,
|
||||
"title": "We Are One Sàrl",
|
||||
"url": "https://weareone.ch/courses/angular/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -276,6 +276,38 @@
|
||||
"title": "Routing & Navigation",
|
||||
"tooltip": "Discover the basics of screen navigation with the Angular Router."
|
||||
},
|
||||
{
|
||||
"title": "Service Workers",
|
||||
"tooltip": "Angular service workers: Controlling caching of application resources.",
|
||||
"children": [
|
||||
{
|
||||
"url": "guide/service-worker-intro",
|
||||
"title": "Introduction",
|
||||
"tooltip": "Angular's implementation of service workers improves user experience with slow or unreliable network connectivity."
|
||||
},
|
||||
{
|
||||
"url": "guide/service-worker-getstart",
|
||||
"title": "Getting Started",
|
||||
"tooltip": "Enabling the service worker in a CLI project and observing behavior in the browser."
|
||||
},
|
||||
{
|
||||
"url": "guide/service-worker-comm",
|
||||
"title": "Communication",
|
||||
"tooltip": "Services that enable you to interact with an Angular service worker."
|
||||
},
|
||||
{
|
||||
"url": "guide/service-worker-devops",
|
||||
"title": "Service Workers in Production",
|
||||
"tooltip": "Information about running applications with service workers, including application update management, debugging, and killing applications."
|
||||
},
|
||||
{
|
||||
"url": "guide/service-worker-configref",
|
||||
"title": "Reference: Configuration File",
|
||||
"tooltip": "The ngsw-config.json configuration file controls service worker caching behavior."
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"url": "guide/testing",
|
||||
"title": "Testing",
|
||||
|
@ -275,6 +275,7 @@ The `HeroDetailsComponent` displays details of a selected hero.
|
||||
At the moment the `HeroDetailsComponent` is only visible at the bottom of the `HeroesComponent`
|
||||
|
||||
The user should be able to get to these details in three ways.
|
||||
|
||||
1. By clicking a hero in the dashboard.
|
||||
1. By clicking a hero in the heroes list.
|
||||
1. By pasting a "deep link" URL into the browser address bar that identifies the hero to display.
|
||||
|
@ -59,7 +59,7 @@
|
||||
"~~update-webdriver": "webdriver-manager update --standalone false --gecko false"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.5 <7.0.0",
|
||||
"node": ">=8.9.1 <9.0.0",
|
||||
"yarn": ">=1.0.2 <2.0.0"
|
||||
},
|
||||
"private": true,
|
||||
|
@ -1,3 +1,21 @@
|
||||
{
|
||||
"aio":{"master":{"change":"application","gzip7":{"inline":925,"main":119519,"polyfills":11863},"gzip9":{"inline":925,"main":119301,"polyfills":11861},"uncompressed":{"inline":1533,"main":486493,"polyfills":37068}}}
|
||||
"aio": {
|
||||
"master": {
|
||||
"gzip7": {
|
||||
"inline": 925,
|
||||
"main": 119519,
|
||||
"polyfills": 11863
|
||||
},
|
||||
"gzip9": {
|
||||
"inline": 925,
|
||||
"main": 119301,
|
||||
"polyfills": 11861
|
||||
},
|
||||
"uncompressed": {
|
||||
"inline": 1533,
|
||||
"main": 486493,
|
||||
"polyfills": 37068
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eu -o pipefail
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
"@angular/platform-browser-dynamic": "~5.0.0",
|
||||
"@angular/platform-server": "~5.0.0",
|
||||
"@angular/router": "~5.0.0",
|
||||
"@angular/service-worker": "~5.0.0",
|
||||
"@angular/upgrade": "~5.0.0",
|
||||
"@nguniversal/express-engine": "^1.0.0-beta.3",
|
||||
"@nguniversal/module-map-ngfactory-loader": "^1.0.0-beta.3",
|
||||
|
@ -160,6 +160,12 @@
|
||||
dependencies:
|
||||
tslib "^1.7.1"
|
||||
|
||||
"@angular/service-worker@~5.0.0":
|
||||
version "5.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@angular/service-worker/-/service-worker-5.0.5.tgz#221d6ae41309c6660609c29aea3de12f1fce474a"
|
||||
dependencies:
|
||||
tslib "^1.7.1"
|
||||
|
||||
"@angular/upgrade@~5.0.0":
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@angular/upgrade/-/upgrade-5.0.0.tgz#d2c4bc83e7dcbe4ad3b1b7e845c6cba7379d779f"
|
||||
|
@ -3,7 +3,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
|
||||
git_repository(
|
||||
name = "build_bazel_rules_nodejs",
|
||||
remote = "https://github.com/bazelbuild/rules_nodejs.git",
|
||||
tag = "0.0.2",
|
||||
tag = "0.2.1",
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
|
||||
@ -22,7 +22,7 @@ local_repository(
|
||||
git_repository(
|
||||
name = "io_bazel_rules_sass",
|
||||
remote = "https://github.com/bazelbuild/rules_sass.git",
|
||||
tag = "0.0.2",
|
||||
tag = "0.0.3",
|
||||
)
|
||||
|
||||
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_repositories")
|
||||
|
@ -20,6 +20,6 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "ngc -p angular.tsconfig.json",
|
||||
"test": "bazel build ..."
|
||||
"test": "bazel build ... --noshow_progress"
|
||||
}
|
||||
}
|
19
integration/dynamic-compiler/e2e/app.e2e-spec.ts
Normal file
19
integration/dynamic-compiler/e2e/app.e2e-spec.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { AppPage } from './app.po';
|
||||
|
||||
describe('dynamic-compiler App', () => {
|
||||
let page: AppPage;
|
||||
|
||||
beforeEach(() => {
|
||||
page = new AppPage();
|
||||
});
|
||||
|
||||
it('should display welcome message', () => {
|
||||
page.navigateTo();
|
||||
expect(page.getParagraphText()).toEqual('Hello world!');
|
||||
});
|
||||
|
||||
it('should display lazy-loaded component', () => {
|
||||
page.navigateTo();
|
||||
expect(page.getLazyLoadedText()).toEqual('Lazy-loaded component!');
|
||||
});
|
||||
});
|
16
integration/dynamic-compiler/e2e/app.po.ts
Normal file
16
integration/dynamic-compiler/e2e/app.po.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import {browser, by, element, protractor} from 'protractor';
|
||||
|
||||
export class AppPage {
|
||||
navigateTo() {
|
||||
return browser.get('/');
|
||||
}
|
||||
|
||||
getParagraphText() {
|
||||
return element(by.css('app-root h1')).getText();
|
||||
}
|
||||
|
||||
getLazyLoadedText() {
|
||||
const el = element(by.css('app-root lazy-component'));
|
||||
return browser.wait(protractor.ExpectedConditions.presenceOf(el)).then(() => el.getText(), err => el.getText());
|
||||
}
|
||||
}
|
15
integration/dynamic-compiler/e2e/browser.config.json
Normal file
15
integration/dynamic-compiler/e2e/browser.config.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"open": false,
|
||||
"logLevel": "silent",
|
||||
"port": 8080,
|
||||
"server": {
|
||||
"baseDir": ".",
|
||||
"routes": {
|
||||
"/dist": "dist",
|
||||
"/node_modules": "node_modules"
|
||||
},
|
||||
"middleware": {
|
||||
"0": null
|
||||
}
|
||||
}
|
||||
}
|
16
integration/dynamic-compiler/e2e/protractor.config.js
Normal file
16
integration/dynamic-compiler/e2e/protractor.config.js
Normal file
@ -0,0 +1,16 @@
|
||||
exports.config = {
|
||||
specs: [
|
||||
'../dist/e2e/*.e2e-spec.js'
|
||||
],
|
||||
capabilities: {
|
||||
browserName: 'chrome',
|
||||
chromeOptions: {
|
||||
args: ['--no-sandbox'],
|
||||
binary: process.env.CHROME_BIN,
|
||||
}
|
||||
},
|
||||
directConnect: true,
|
||||
baseUrl: 'http://localhost:8080/',
|
||||
framework: 'jasmine',
|
||||
useAllAngular2AppRoots: true
|
||||
};
|
7
integration/dynamic-compiler/e2e/tsconfig.json
Normal file
7
integration/dynamic-compiler/e2e/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "../dist/e2e",
|
||||
"types": ["jasmine"],
|
||||
"skipLibCheck": true
|
||||
}
|
||||
}
|
14
integration/dynamic-compiler/index.html
Normal file
14
integration/dynamic-compiler/index.html
Normal file
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
<script src="/node_modules/zone.js/dist/zone.js"></script>
|
||||
<script src="/node_modules/reflect-metadata/Reflect.js"></script>
|
||||
<script src="/node_modules/systemjs/dist/system.js"></script>
|
||||
<script src="/dist/bundle.js"></script>
|
||||
</body>
|
||||
</html>
|
44
integration/dynamic-compiler/package.json
Normal file
44
integration/dynamic-compiler/package.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "dynamic-compiler",
|
||||
"version": "0.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "npm run clean && npm run ngc && npm run rollup && npm run rollup:lazy && npm run es5 && npm run es5:lazy",
|
||||
"clean": "rm -rf dist",
|
||||
"es5": "tsc --target es5 --skipLibCheck --allowJs dist/bundle.es2015.js --out dist/bundle.js",
|
||||
"es5:lazy": "tsc --target es5 --skipLibCheck --allowJs dist/lazy.bundle.es2015.js --out dist/lazy.bundle.js",
|
||||
"ngc": "ngc -p tsconfig.json",
|
||||
"rollup": "rollup -f iife -c rollup.config.js -o dist/bundle.es2015.js",
|
||||
"rollup:lazy": "rollup -f cjs -c rollup.lazy.config.js -o dist/lazy.bundle.es2015.js",
|
||||
"postinstall": "webdriver-manager update --gecko false",
|
||||
"preprotractor": "tsc -p e2e",
|
||||
"protractor": "protractor e2e/protractor.config.js",
|
||||
"serve": "lite-server -c e2e/browser.config.json",
|
||||
"test": "npm run build && concurrently \"yarn run serve\" \"yarn run protractor\" --kill-others --success first"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/jasmine": "file:../../node_modules/@types/jasmine",
|
||||
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
|
||||
"concurrently": "3.4.0",
|
||||
"lite-server": "2.2.2",
|
||||
"protractor": "file:../../node_modules/protractor",
|
||||
"rollup": "file:../../node_modules/rollup",
|
||||
"rollup-plugin-commonjs": "file:../../node_modules/rollup-plugin-commonjs",
|
||||
"rollup-plugin-node-resolve": "file:../../node_modules/rollup-plugin-node-resolve",
|
||||
"typescript": "file:../../node_modules/typescript"
|
||||
},
|
||||
"dependencies": {
|
||||
"@angular/animations": "file:../../dist/packages-dist/animations",
|
||||
"@angular/common": "file:../../dist/packages-dist/common",
|
||||
"@angular/compiler": "file:../../dist/packages-dist/compiler",
|
||||
"@angular/core": "file:../../dist/packages-dist/core",
|
||||
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
|
||||
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
|
||||
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
|
||||
"core-js": "file:../../node_modules/core-js",
|
||||
"rxjs": "file:../../node_modules/rxjs",
|
||||
"systemjs": "file:../../node_modules/systemjs",
|
||||
"zone.js": "file:../../node_modules/zone.js"
|
||||
}
|
||||
}
|
17
integration/dynamic-compiler/rollup.config.js
Normal file
17
integration/dynamic-compiler/rollup.config.js
Normal file
@ -0,0 +1,17 @@
|
||||
import nodeResolve from 'rollup-plugin-node-resolve';
|
||||
import commonjs from 'rollup-plugin-commonjs';
|
||||
|
||||
export default {
|
||||
entry: 'dist/src/main.js',
|
||||
sourceMap: true,
|
||||
treeshake: true,
|
||||
moduleName: 'main',
|
||||
plugins: [
|
||||
commonjs({
|
||||
include: 'node_modules/**'
|
||||
}),
|
||||
nodeResolve({
|
||||
jsnext: true, main: true, module: true
|
||||
})
|
||||
]
|
||||
};
|
19
integration/dynamic-compiler/rollup.lazy.config.js
Normal file
19
integration/dynamic-compiler/rollup.lazy.config.js
Normal file
@ -0,0 +1,19 @@
|
||||
import nodeResolve from 'rollup-plugin-node-resolve';
|
||||
import commonjs from 'rollup-plugin-commonjs';
|
||||
|
||||
// a real app should make a common bundle for libraries instead of bundling them
|
||||
// in both the main module & the lazy module, but we don't care about size here
|
||||
export default {
|
||||
entry: 'dist/src/lazy.module.js',
|
||||
sourceMap: true,
|
||||
treeshake: true,
|
||||
moduleName: 'lazy',
|
||||
plugins: [
|
||||
commonjs({
|
||||
include: 'node_modules/**'
|
||||
}),
|
||||
nodeResolve({
|
||||
jsnext: true, main: true, module: true
|
||||
})
|
||||
]
|
||||
};
|
27
integration/dynamic-compiler/src/app.component.ts
Normal file
27
integration/dynamic-compiler/src/app.component.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import {AfterViewInit, Compiler, Component, ViewChild, ViewContainerRef} from '@angular/core';
|
||||
|
||||
declare var System: any;
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
template: `
|
||||
<h1>Hello world!</h1>
|
||||
<div #vc></div>
|
||||
`,
|
||||
})
|
||||
export class AppComponent implements AfterViewInit {
|
||||
@ViewChild('vc', {read: ViewContainerRef}) container: ViewContainerRef;
|
||||
|
||||
constructor(private compiler: Compiler) {
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
System.import('./dist/lazy.bundle.js').then((module: any) => {
|
||||
this.compiler.compileModuleAndAllComponentsAsync(module.LazyModule)
|
||||
.then((compiled) => {
|
||||
const factory = compiled.componentFactories[0];
|
||||
this.container.createComponent(factory);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
22
integration/dynamic-compiler/src/app.module.ts
Normal file
22
integration/dynamic-compiler/src/app.module.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import {Compiler, COMPILER_OPTIONS, CompilerFactory, NgModule} from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import {JitCompilerFactory} from '@angular/platform-browser-dynamic';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
export function createCompiler(compilerFactory: CompilerFactory) {
|
||||
return compilerFactory.createCompiler();
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
imports: [BrowserModule],
|
||||
bootstrap: [AppComponent],
|
||||
declarations: [AppComponent],
|
||||
providers: [
|
||||
{provide: COMPILER_OPTIONS, useValue: {}, multi: true},
|
||||
{provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS]},
|
||||
{provide: Compiler, useFactory: createCompiler, deps: [CompilerFactory]}
|
||||
]
|
||||
})
|
||||
export class AppModule {}
|
||||
|
17
integration/dynamic-compiler/src/lazy.module.ts
Normal file
17
integration/dynamic-compiler/src/lazy.module.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import {NgModule} from "@angular/core";
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'lazy-component',
|
||||
template: 'Lazy-loaded component!'
|
||||
})
|
||||
export class LazyComponent {
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [LazyComponent]
|
||||
})
|
||||
export class LazyModule {
|
||||
}
|
8
integration/dynamic-compiler/src/main.ts
Normal file
8
integration/dynamic-compiler/src/main.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { enableProdMode } from '@angular/core';
|
||||
import { platformBrowser } from '@angular/platform-browser';
|
||||
|
||||
import { AppModuleNgFactory } from './app.module.ngfactory';
|
||||
|
||||
enableProdMode();
|
||||
|
||||
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
|
28
integration/dynamic-compiler/tsconfig.json
Normal file
28
integration/dynamic-compiler/tsconfig.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2015",
|
||||
"module": "es2015",
|
||||
"moduleResolution": "node",
|
||||
"declaration": false,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"lib": ["es6", "es2015", "dom"],
|
||||
"sourceMap": true,
|
||||
"pretty": true,
|
||||
"allowUnreachableCode": false,
|
||||
"allowUnusedLabels": false,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitUseStrict": false,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"outDir": "./dist",
|
||||
"types": [
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"src/main.ts",
|
||||
"src/lazy.module.ts"
|
||||
]
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "angular-integration",
|
||||
"description": "Assert that users with TypeScript 2.2 can type-check an Angular application",
|
||||
"description": "Assert that users with TypeScript 2.4 can type-check an Angular application",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@ -18,7 +18,7 @@
|
||||
"@angular/upgrade": "file:../../dist/packages-dist/upgrade",
|
||||
"@types/jasmine": "2.5.41",
|
||||
"rxjs": "file:../../node_modules/rxjs",
|
||||
"typescript": "file:../../node_modules/typescript",
|
||||
"typescript": "2.4.x",
|
||||
"zone.js": "file:../../node_modules/zone.js"
|
||||
},
|
||||
"scripts": {
|
||||
|
41
integration/typings_test_ts25/include-all.ts
Normal file
41
integration/typings_test_ts25/include-all.ts
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import * as compiler from '@angular/compiler';
|
||||
import * as compilerTesting from '@angular/compiler/testing';
|
||||
import * as core from '@angular/core';
|
||||
import * as coreTesting from '@angular/core/testing';
|
||||
import * as forms from '@angular/forms';
|
||||
import * as http from '@angular/http';
|
||||
import * as httpTesting from '@angular/http/testing';
|
||||
import * as platformBrowserDynamic from '@angular/platform-browser-dynamic';
|
||||
import * as platformBrowser from '@angular/platform-browser';
|
||||
import * as platformBrowserTesting from '@angular/platform-browser/testing';
|
||||
import * as platformServer from '@angular/platform-server';
|
||||
import * as platformServerTesting from '@angular/platform-server/testing';
|
||||
import * as router from '@angular/router';
|
||||
import * as routerTesting from '@angular/router/testing';
|
||||
import * as upgrade from '@angular/upgrade';
|
||||
|
||||
export default {
|
||||
compiler,
|
||||
compilerTesting,
|
||||
core,
|
||||
coreTesting,
|
||||
forms,
|
||||
http,
|
||||
httpTesting,
|
||||
platformBrowser,
|
||||
platformBrowserTesting,
|
||||
platformBrowserDynamic,
|
||||
platformServer,
|
||||
platformServerTesting,
|
||||
router,
|
||||
routerTesting,
|
||||
upgrade
|
||||
};
|
27
integration/typings_test_ts25/package.json
Normal file
27
integration/typings_test_ts25/package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "angular-integration",
|
||||
"description": "Assert that users with TypeScript 2.5 can type-check an Angular application",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@angular/animations": "file:../../dist/packages-dist/animations",
|
||||
"@angular/common": "file:../../dist/packages-dist/common",
|
||||
"@angular/compiler": "file:../../dist/packages-dist/compiler",
|
||||
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
|
||||
"@angular/core": "file:../../dist/packages-dist/core",
|
||||
"@angular/forms": "file:../../dist/packages-dist/forms",
|
||||
"@angular/http": "file:../../dist/packages-dist/http",
|
||||
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
|
||||
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
|
||||
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
|
||||
"@angular/router": "file:../../dist/packages-dist/router",
|
||||
"@angular/upgrade": "file:../../dist/packages-dist/upgrade",
|
||||
"@types/jasmine": "2.5.41",
|
||||
"rxjs": "file:../../node_modules/rxjs",
|
||||
"typescript": "2.5.x",
|
||||
"zone.js": "file:../../node_modules/zone.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tsc"
|
||||
}
|
||||
}
|
24
integration/typings_test_ts25/tsconfig.json
Normal file
24
integration/typings_test_ts25/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../../dist/typings_test_ts25/",
|
||||
"rootDir": ".",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection",
|
||||
"es2015.iterable",
|
||||
"es2015.promise"
|
||||
],
|
||||
"types": [],
|
||||
"strictNullChecks": true
|
||||
},
|
||||
"files": [
|
||||
"include-all.ts",
|
||||
"node_modules/@types/jasmine/index.d.ts"
|
||||
]
|
||||
}
|
11
package.json
11
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "angular-srcs",
|
||||
"version": "5.0.4",
|
||||
"version": "5.1.0",
|
||||
"private": true,
|
||||
"branchPattern": "2.0.*",
|
||||
"description": "Angular - a web framework for modern web apps",
|
||||
@ -8,8 +8,7 @@
|
||||
"bugs": "https://github.com/angular/angular/issues",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6.9.5 <7.0.0",
|
||||
"npm": ">=3.10.7 <4.0.0",
|
||||
"node": ">=8.9.1 <9.0.0",
|
||||
"yarn": ">=1.0.2 <2.0.0"
|
||||
},
|
||||
"repository": {
|
||||
@ -32,7 +31,7 @@
|
||||
"fsevents": "1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@bazel/typescript": "0.2.x",
|
||||
"@bazel/typescript": "0.3.2",
|
||||
"@types/angularjs": "1.5.14-alpha",
|
||||
"@types/base64-js": "1.2.5",
|
||||
"@types/chokidar": "1.7.3",
|
||||
@ -95,10 +94,10 @@
|
||||
"source-map-support": "0.4.18",
|
||||
"systemjs": "0.18.10",
|
||||
"ts-api-guardian": "0.2.2",
|
||||
"tsickle": "0.24.x",
|
||||
"tsickle": "0.25.5",
|
||||
"tslint": "5.7.0",
|
||||
"tslint-eslint-rules": "4.1.1",
|
||||
"typescript": "2.4.2",
|
||||
"typescript": "2.5.x",
|
||||
"uglify-js": "2.8.29",
|
||||
"universal-analytics": "0.4.15",
|
||||
"vlq": "0.2.2",
|
||||
|
@ -32,7 +32,6 @@ export class AnimationGroupPlayer implements AnimationPlayer {
|
||||
scheduleMicroTask(() => this._onFinish());
|
||||
} else {
|
||||
this.players.forEach(player => {
|
||||
player.parentPlayer = this;
|
||||
player.onDone(() => {
|
||||
if (++doneCount >= total) {
|
||||
this._onFinish();
|
||||
|
@ -62,8 +62,8 @@ export class NoopAnimationPlayer implements AnimationPlayer {
|
||||
init(): void {}
|
||||
play(): void {
|
||||
if (!this.hasStarted()) {
|
||||
this.triggerMicrotask();
|
||||
this._onStart();
|
||||
this.triggerMicrotask();
|
||||
}
|
||||
this._started = true;
|
||||
}
|
||||
|
@ -6,9 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {fakeAsync} from '@angular/core/testing';
|
||||
|
||||
import {flushMicrotasks} from '../../core/testing/src/fake_async';
|
||||
import {NoopAnimationPlayer} from '../src/players/animation_player';
|
||||
import {scheduleMicroTask} from '../src/util';
|
||||
|
||||
export function main() {
|
||||
describe('NoopAnimationPlayer', function() {
|
||||
@ -61,6 +61,21 @@ export function main() {
|
||||
player.finish();
|
||||
expect(log).toEqual(['started', 'done']);
|
||||
|
||||
flushMicrotasks();
|
||||
expect(log).toEqual(['started', 'done']);
|
||||
}));
|
||||
|
||||
it('should fire off start callbacks before triggering the finish callback', fakeAsync(() => {
|
||||
const log: string[] = [];
|
||||
|
||||
const player = new NoopAnimationPlayer();
|
||||
player.onStart(() => { scheduleMicroTask(() => log.push('started')); });
|
||||
player.onDone(() => log.push('done'));
|
||||
expect(log).toEqual([]);
|
||||
|
||||
player.play();
|
||||
expect(log).toEqual([]);
|
||||
|
||||
flushMicrotasks();
|
||||
expect(log).toEqual(['started', 'done']);
|
||||
}));
|
||||
|
@ -6,10 +6,10 @@
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"@angular/compiler-cli": "0.0.0-PLACEHOLDER",
|
||||
"typescript": ">=2.4.2 <2.5"
|
||||
"typescript": ">=2.4.2 <2.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bazel/typescript": "0.2.x",
|
||||
"@bazel/typescript": "0.3.2",
|
||||
"@types/node": "6.0.84"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -73,7 +73,8 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs):
|
||||
"allowEmptyCodegenFiles": True,
|
||||
"enableSummariesForJit": True,
|
||||
# FIXME: wrong place to de-dupe
|
||||
"expectedOut": depset([o.path for o in expected_outs]).to_list()
|
||||
"expectedOut": depset([o.path for o in expected_outs]).to_list(),
|
||||
"preserveWhitespaces": False,
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -5,8 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// TODO(tbosch): figure out why we need this as it breaks node code within ngc-wrapped
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as ng from '@angular/compiler-cli';
|
||||
import {BazelOptions, CachedFileLoader, CompilerHost, FileCache, FileLoader, UncachedFileLoader, constructManifest, debug, fixUmdModuleDeclarations, parseTsconfig, runAsWorker, runWorkerLoop} from '@bazel/typescript';
|
||||
import * as fs from 'fs';
|
||||
@ -165,11 +164,19 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
|
||||
}
|
||||
return origBazelHostFileExist.call(bazelHost, fileName);
|
||||
};
|
||||
const origBazelHostShouldNameModule = bazelHost.shouldNameModule.bind(bazelHost);
|
||||
bazelHost.shouldNameModule = (fileName: string) =>
|
||||
origBazelHostShouldNameModule(fileName) || NGC_GEN_FILES.test(fileName);
|
||||
|
||||
const ngHost = ng.createCompilerHost({options: compilerOpts, tsHost: bazelHost});
|
||||
|
||||
ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) =>
|
||||
relativeToRootDirs(importedFilePath, compilerOpts.rootDirs).replace(EXT, '');
|
||||
ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) => {
|
||||
if ((compilerOpts.module === ts.ModuleKind.UMD || compilerOpts.module === ts.ModuleKind.AMD) &&
|
||||
ngHost.amdModuleName) {
|
||||
return ngHost.amdModuleName({ fileName: importedFilePath } as ts.SourceFile);
|
||||
}
|
||||
return relativeToRootDirs(importedFilePath, compilerOpts.rootDirs).replace(EXT, '');
|
||||
};
|
||||
ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) =>
|
||||
ngHost.fileNameToModuleName(fileName, referringSrcFileName);
|
||||
if (allDepsCompiledWithBazel) {
|
||||
|
@ -64,6 +64,10 @@ export function createTsConfig(options: TsConfigOptions) {
|
||||
'es5Mode': true,
|
||||
'manifest': createManifestPath(options),
|
||||
'compilationTargetSrc': options.compilationTargetSrc,
|
||||
// Override this property from the real tsconfig we read
|
||||
// Because we ask for :empty_tsconfig.json, we get the ES6 version which
|
||||
// expects to write externs, yet that doesn't work under this fixture.
|
||||
'tsickleExternsPath': '',
|
||||
},
|
||||
'files': options.files,
|
||||
'angularCompilerOptions': {
|
||||
|
@ -81,7 +81,9 @@ export class Runner {
|
||||
{provide: WebDriverAdapter, useValue: adapter}
|
||||
]);
|
||||
|
||||
const sampler = injector.get(Sampler);
|
||||
// TODO: With TypeScript 2.5 injector.get does not infer correctly the
|
||||
// return type. Remove 'any' and investigate the issue.
|
||||
const sampler = injector.get(Sampler) as any;
|
||||
return sampler.sample();
|
||||
});
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ export function main() {
|
||||
ids.map(id => ({provide: id, useValue: new MockMetric(id)})),
|
||||
MultiMetric.provideWith(ids)
|
||||
])
|
||||
.get(MultiMetric);
|
||||
.get<MultiMetric>(MultiMetric);
|
||||
return Promise.resolve(m);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ export function main() {
|
||||
}
|
||||
}
|
||||
];
|
||||
return Injector.create(providers).get(JsonFileReporter);
|
||||
return Injector.create(providers).get<JsonFileReporter>(JsonFileReporter);
|
||||
}
|
||||
|
||||
it('should write all data into a file',
|
||||
|
@ -17,7 +17,7 @@ export function main() {
|
||||
ids.map(id => ({provide: id, useValue: new MockReporter(id)})),
|
||||
MultiReporter.provideWith(ids)
|
||||
])
|
||||
.get(MultiReporter);
|
||||
.get<MultiReporter>(MultiReporter);
|
||||
return Promise.resolve(r);
|
||||
}
|
||||
|
||||
|
@ -4895,6 +4895,5 @@ switch (goog.LOCALE) {
|
||||
}
|
||||
|
||||
if (l) {
|
||||
l[0] = goog.LOCALE;
|
||||
registerLocaleData(l);
|
||||
registerLocaleData(l, goog.LOCALE);
|
||||
}
|
||||
|
@ -17,9 +17,17 @@ export const LOCALE_DATA: {[localeId: string]: any} = {};
|
||||
*
|
||||
* @experimental i18n support is experimental.
|
||||
*/
|
||||
export function registerLocaleData(data: any, extraData?: any) {
|
||||
const localeId = data[LocaleDataIndex.LocaleId].toLowerCase().replace(/_/g, '-');
|
||||
// The signature registerLocaleData(data: any, extraData?: any) is deprecated since v5.1
|
||||
export function registerLocaleData(data: any, localeId?: string | any, extraData?: any): void {
|
||||
if (typeof localeId !== 'string') {
|
||||
extraData = localeId;
|
||||
localeId = data[LocaleDataIndex.LocaleId];
|
||||
}
|
||||
|
||||
localeId = localeId.toLowerCase().replace(/_/g, '-');
|
||||
|
||||
LOCALE_DATA[localeId] = data;
|
||||
|
||||
if (extraData) {
|
||||
LOCALE_DATA[localeId][LocaleDataIndex.ExtraData] = extraData;
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import localeCaESVALENCIA from '../../locales/ca-ES-VALENCIA';
|
||||
import localeEn from '../../locales/en';
|
||||
import localeFr from '../../locales/fr';
|
||||
import localeFrCA from '../../locales/fr-CA';
|
||||
import {findLocaleData} from '../../src/i18n/locale_data_api';
|
||||
import {registerLocaleData} from '../../src/i18n/locale_data';
|
||||
import {findLocaleData} from '../../src/i18n/locale_data_api';
|
||||
|
||||
export function main() {
|
||||
describe('locale data api', () => {
|
||||
@ -20,6 +20,8 @@ export function main() {
|
||||
registerLocaleData(localeEn);
|
||||
registerLocaleData(localeFr);
|
||||
registerLocaleData(localeFrCA);
|
||||
registerLocaleData(localeFr, 'fake-id');
|
||||
registerLocaleData(localeFrCA, 'fake_Id2');
|
||||
});
|
||||
|
||||
describe('findLocaleData', () => {
|
||||
@ -42,6 +44,12 @@ export function main() {
|
||||
expect(findLocaleData('ca-ES-VALENCIA')).toEqual(localeCaESVALENCIA);
|
||||
expect(findLocaleData('CA_es_Valencia')).toEqual(localeCaESVALENCIA);
|
||||
});
|
||||
|
||||
it(`should find the LOCALE_DATA if the locale id was registered`, () => {
|
||||
expect(findLocaleData('fake-id')).toEqual(localeFr);
|
||||
expect(findLocaleData('fake_iD')).toEqual(localeFr);
|
||||
expect(findLocaleData('fake-id2')).toEqual(localeFrCA);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -42,7 +42,9 @@ export class SpyLocation implements Location {
|
||||
return currPath == givenPath + (query.length > 0 ? ('?' + query) : '');
|
||||
}
|
||||
|
||||
simulateUrlPop(pathname: string) { this._subject.emit({'url': pathname, 'pop': true}); }
|
||||
simulateUrlPop(pathname: string) {
|
||||
this._subject.emit({'url': pathname, 'pop': true, 'type': 'popstate'});
|
||||
}
|
||||
|
||||
simulateHashChange(pathname: string) {
|
||||
// Because we don't prevent the native event, the browser will independently update the path
|
||||
|
@ -11,11 +11,11 @@
|
||||
"dependencies": {
|
||||
"reflect-metadata": "^0.1.2",
|
||||
"minimist": "^1.2.0",
|
||||
"tsickle": "^0.24.0",
|
||||
"tsickle": "^0.25.5",
|
||||
"chokidar": "^1.4.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=2.4.2 <2.5",
|
||||
"typescript": ">=2.4.2 <2.6",
|
||||
"@angular/compiler": "0.0.0-PLACEHOLDER"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -20,7 +20,6 @@ import {GENERATED_FILES} from './transformers/util';
|
||||
|
||||
import {exitCodeFromResult, performCompilation, readConfiguration, formatDiagnostics, Diagnostics, ParsedConfiguration, PerformCompilationResult, filterErrorsAndWarnings} from './perform_compile';
|
||||
import {performWatchCompilation, createPerformWatchHost} from './perform_watch';
|
||||
import {isSyntaxError} from '@angular/compiler';
|
||||
|
||||
export function main(
|
||||
args: string[], consoleError: (s: string) => void = console.error,
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {Evaluator, errorSymbol} from './evaluator';
|
||||
import {ClassMetadata, ConstructorMetadata, FunctionMetadata, InterfaceMetadata, METADATA_VERSION, MemberMetadata, MetadataEntry, MetadataError, MetadataMap, MetadataSymbolicBinaryExpression, MetadataSymbolicCallExpression, MetadataSymbolicExpression, MetadataSymbolicIfExpression, MetadataSymbolicIndexExpression, MetadataSymbolicPrefixExpression, MetadataSymbolicReferenceExpression, MetadataSymbolicSelectExpression, MetadataSymbolicSpreadExpression, MetadataValue, MethodMetadata, ModuleExportMetadata, ModuleMetadata, isClassMetadata, isConstructorMetadata, isFunctionMetadata, isMetadataError, isMetadataGlobalReferenceExpression, isMetadataSymbolicExpression, isMetadataSymbolicReferenceExpression, isMetadataSymbolicSelectExpression, isMethodMetadata} from './schema';
|
||||
import {Evaluator, errorSymbol, recordMapEntry} from './evaluator';
|
||||
import {ClassMetadata, ConstructorMetadata, FunctionMetadata, InterfaceMetadata, METADATA_VERSION, MemberMetadata, MetadataEntry, MetadataError, MetadataMap, MetadataSymbolicBinaryExpression, MetadataSymbolicCallExpression, MetadataSymbolicExpression, MetadataSymbolicIfExpression, MetadataSymbolicIndexExpression, MetadataSymbolicPrefixExpression, MetadataSymbolicReferenceExpression, MetadataSymbolicSelectExpression, MetadataSymbolicSpreadExpression, MetadataValue, MethodMetadata, ModuleExportMetadata, ModuleMetadata, isClassMetadata, isConstructorMetadata, isFunctionMetadata, isMetadataError, isMetadataGlobalReferenceExpression, isMetadataImportDefaultReference, isMetadataImportedSymbolReferenceExpression, isMetadataSymbolicExpression, isMetadataSymbolicReferenceExpression, isMetadataSymbolicSelectExpression, isMethodMetadata} from './schema';
|
||||
import {Symbols} from './symbols';
|
||||
|
||||
const isStatic = (node: ts.Node) => ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Static;
|
||||
@ -76,8 +76,7 @@ export class MetadataCollector {
|
||||
}
|
||||
|
||||
function recordEntry<T extends MetadataEntry>(entry: T, node: ts.Node): T {
|
||||
nodeMap.set(entry, node);
|
||||
return entry;
|
||||
return recordMapEntry(entry, node, nodeMap, sourceFile);
|
||||
}
|
||||
|
||||
function errorSym(
|
||||
@ -116,8 +115,8 @@ export class MetadataCollector {
|
||||
function classMetadataOf(classDeclaration: ts.ClassDeclaration): ClassMetadata {
|
||||
const result: ClassMetadata = {__symbolic: 'class'};
|
||||
|
||||
function getDecorators(decorators: ts.Decorator[] | undefined): MetadataSymbolicExpression[]|
|
||||
undefined {
|
||||
function getDecorators(decorators: ReadonlyArray<ts.Decorator>| undefined):
|
||||
MetadataSymbolicExpression[]|undefined {
|
||||
if (decorators && decorators.length)
|
||||
return decorators.map(decorator => objFromDecorator(decorator));
|
||||
return undefined;
|
||||
@ -551,6 +550,7 @@ export class MetadataCollector {
|
||||
__symbolic: 'module',
|
||||
version: this.options.version || METADATA_VERSION, metadata
|
||||
};
|
||||
if (sourceFile.moduleName) result.importAs = sourceFile.moduleName;
|
||||
if (exports) result.exports = exports;
|
||||
return result;
|
||||
}
|
||||
|
@ -9,10 +9,11 @@
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {CollectorOptions} from './collector';
|
||||
import {MetadataEntry, MetadataError, MetadataImportedSymbolReferenceExpression, MetadataSymbolicCallExpression, MetadataValue, isMetadataError, isMetadataGlobalReferenceExpression, isMetadataModuleReferenceExpression, isMetadataSymbolicReferenceExpression, isMetadataSymbolicSpreadExpression} from './schema';
|
||||
import {ClassMetadata, FunctionMetadata, InterfaceMetadata, MetadataEntry, MetadataError, MetadataImportedSymbolReferenceExpression, MetadataSourceLocationInfo, MetadataSymbolicCallExpression, MetadataValue, isMetadataError, isMetadataGlobalReferenceExpression, isMetadataImportDefaultReference, isMetadataImportedSymbolReferenceExpression, isMetadataModuleReferenceExpression, isMetadataSymbolicReferenceExpression, isMetadataSymbolicSpreadExpression} from './schema';
|
||||
import {Symbols} from './symbols';
|
||||
|
||||
|
||||
|
||||
// In TypeScript 2.1 the spread element kind was renamed.
|
||||
const spreadElementSyntaxKind: ts.SyntaxKind =
|
||||
(ts.SyntaxKind as any).SpreadElement || (ts.SyntaxKind as any).SpreadElementExpression;
|
||||
@ -38,6 +39,24 @@ function isCallOf(callExpression: ts.CallExpression, ident: string): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function recordMapEntry<T extends MetadataEntry>(
|
||||
entry: T, node: ts.Node,
|
||||
nodeMap: Map<MetadataValue|ClassMetadata|InterfaceMetadata|FunctionMetadata, ts.Node>,
|
||||
sourceFile?: ts.SourceFile) {
|
||||
if (!nodeMap.has(entry)) {
|
||||
nodeMap.set(entry, node);
|
||||
if (node && (isMetadataImportedSymbolReferenceExpression(entry) ||
|
||||
isMetadataImportDefaultReference(entry)) &&
|
||||
entry.line == null) {
|
||||
const info = sourceInfo(node, sourceFile);
|
||||
if (info.line != null) entry.line = info.line;
|
||||
if (info.character != null) entry.character = info.character;
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* ts.forEachChild stops iterating children when the callback return a truthy value.
|
||||
* This method inverts this to implement an `every` style iterator. It will return
|
||||
@ -77,21 +96,22 @@ function getSourceFileOfNode(node: ts.Node | undefined): ts.SourceFile {
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function errorSymbol(
|
||||
message: string, node?: ts.Node, context?: {[name: string]: string},
|
||||
sourceFile?: ts.SourceFile): MetadataError {
|
||||
let result: MetadataError|undefined = undefined;
|
||||
export function sourceInfo(
|
||||
node: ts.Node | undefined, sourceFile: ts.SourceFile | undefined): MetadataSourceLocationInfo {
|
||||
if (node) {
|
||||
sourceFile = sourceFile || getSourceFileOfNode(node);
|
||||
if (sourceFile) {
|
||||
const {line, character} =
|
||||
ts.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));
|
||||
result = {__symbolic: 'error', message, line, character};
|
||||
return ts.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
result = {__symbolic: 'error', message};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function errorSymbol(
|
||||
message: string, node?: ts.Node, context?: {[name: string]: string},
|
||||
sourceFile?: ts.SourceFile): MetadataError {
|
||||
const result: MetadataError = {__symbolic: 'error', message, ...sourceInfo(node, sourceFile)};
|
||||
if (context) {
|
||||
result.context = context;
|
||||
}
|
||||
@ -242,8 +262,7 @@ export class Evaluator {
|
||||
}
|
||||
entry = newEntry;
|
||||
}
|
||||
t.nodeMap.set(entry, node);
|
||||
return entry;
|
||||
return recordMapEntry(entry, node, t.nodeMap);
|
||||
}
|
||||
|
||||
function isFoldableError(value: any): value is MetadataError {
|
||||
@ -256,6 +275,9 @@ export class Evaluator {
|
||||
// Encode as a global reference. StaticReflector will check the reference.
|
||||
return recordEntry({__symbolic: 'reference', name}, node);
|
||||
}
|
||||
if (reference && isMetadataSymbolicReferenceExpression(reference)) {
|
||||
return recordEntry({...reference}, node);
|
||||
}
|
||||
return reference;
|
||||
};
|
||||
|
||||
@ -628,7 +650,7 @@ export class Evaluator {
|
||||
return recordEntry({__symbolic: 'if', condition, thenExpression, elseExpression}, node);
|
||||
case ts.SyntaxKind.FunctionExpression:
|
||||
case ts.SyntaxKind.ArrowFunction:
|
||||
return recordEntry(errorSymbol('Function call not supported', node), node);
|
||||
return recordEntry(errorSymbol('Lambda not supported', node), node);
|
||||
case ts.SyntaxKind.TaggedTemplateExpression:
|
||||
return recordEntry(
|
||||
errorSymbol('Tagged template expressions are not supported in metadata', node), node);
|
||||
|
@ -178,7 +178,20 @@ export function isMetadataSymbolicIfExpression(value: any): value is MetadataSym
|
||||
return value && value.__symbolic === 'if';
|
||||
}
|
||||
|
||||
export interface MetadataGlobalReferenceExpression extends MetadataSymbolicExpression {
|
||||
export interface MetadataSourceLocationInfo {
|
||||
/**
|
||||
* The line number of the error in the .ts file the metadata was created for.
|
||||
*/
|
||||
line?: number;
|
||||
|
||||
/**
|
||||
* The number of utf8 code-units from the beginning of the file of the error.
|
||||
*/
|
||||
character?: number;
|
||||
}
|
||||
|
||||
export interface MetadataGlobalReferenceExpression extends MetadataSymbolicExpression,
|
||||
MetadataSourceLocationInfo {
|
||||
__symbolic: 'reference';
|
||||
name: string;
|
||||
arguments?: MetadataValue[];
|
||||
@ -188,7 +201,8 @@ export function isMetadataGlobalReferenceExpression(value: any):
|
||||
return value && value.name && !value.module && isMetadataSymbolicReferenceExpression(value);
|
||||
}
|
||||
|
||||
export interface MetadataModuleReferenceExpression extends MetadataSymbolicExpression {
|
||||
export interface MetadataModuleReferenceExpression extends MetadataSymbolicExpression,
|
||||
MetadataSourceLocationInfo {
|
||||
__symbolic: 'reference';
|
||||
module: string;
|
||||
}
|
||||
@ -198,7 +212,8 @@ export function isMetadataModuleReferenceExpression(value: any):
|
||||
isMetadataSymbolicReferenceExpression(value);
|
||||
}
|
||||
|
||||
export interface MetadataImportedSymbolReferenceExpression extends MetadataSymbolicExpression {
|
||||
export interface MetadataImportedSymbolReferenceExpression extends MetadataSymbolicExpression,
|
||||
MetadataSourceLocationInfo {
|
||||
__symbolic: 'reference';
|
||||
module: string;
|
||||
name: string;
|
||||
@ -209,7 +224,8 @@ export function isMetadataImportedSymbolReferenceExpression(value: any):
|
||||
return value && value.module && !!value.name && isMetadataSymbolicReferenceExpression(value);
|
||||
}
|
||||
|
||||
export interface MetadataImportedDefaultReferenceExpression extends MetadataSymbolicExpression {
|
||||
export interface MetadataImportedDefaultReferenceExpression extends MetadataSymbolicExpression,
|
||||
MetadataSourceLocationInfo {
|
||||
__symbolic: 'reference';
|
||||
module: string;
|
||||
default:
|
||||
@ -218,7 +234,7 @@ export interface MetadataImportedDefaultReferenceExpression extends MetadataSymb
|
||||
}
|
||||
export function isMetadataImportDefaultReference(value: any):
|
||||
value is MetadataImportedDefaultReferenceExpression {
|
||||
return value.module && value.default && isMetadataSymbolicReferenceExpression(value);
|
||||
return value && value.module && value.default && isMetadataSymbolicReferenceExpression(value);
|
||||
}
|
||||
|
||||
export type MetadataSymbolicReferenceExpression = MetadataGlobalReferenceExpression |
|
||||
@ -248,7 +264,7 @@ export function isMetadataSymbolicSpreadExpression(value: any):
|
||||
return value && value.__symbolic === 'spread';
|
||||
}
|
||||
|
||||
export interface MetadataError {
|
||||
export interface MetadataError extends MetadataSourceLocationInfo {
|
||||
__symbolic: 'error';
|
||||
|
||||
/**
|
||||
@ -259,16 +275,6 @@ export interface MetadataError {
|
||||
*/
|
||||
message: string;
|
||||
|
||||
/**
|
||||
* The line number of the error in the .ts file the metadata was created for.
|
||||
*/
|
||||
line?: number;
|
||||
|
||||
/**
|
||||
* The number of utf8 code-units from the beginning of the file of the error.
|
||||
*/
|
||||
character?: number;
|
||||
|
||||
/**
|
||||
* The module of the error (only used in bundled metadata)
|
||||
*/
|
||||
@ -280,6 +286,7 @@ export interface MetadataError {
|
||||
*/
|
||||
context?: {[name: string]: string};
|
||||
}
|
||||
|
||||
export function isMetadataError(value: any): value is MetadataError {
|
||||
return value && value.__symbolic === 'error';
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {isSyntaxError, syntaxError} from '@angular/compiler';
|
||||
import {Position, isSyntaxError, syntaxError} from '@angular/compiler';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
@ -29,30 +29,76 @@ const defaultFormatHost: ts.FormatDiagnosticsHost = {
|
||||
getNewLine: () => ts.sys.newLine
|
||||
};
|
||||
|
||||
function displayFileName(fileName: string, host: ts.FormatDiagnosticsHost): string {
|
||||
return path.relative(host.getCurrentDirectory(), host.getCanonicalFileName(fileName));
|
||||
}
|
||||
|
||||
export function formatDiagnosticPosition(
|
||||
position: Position, host: ts.FormatDiagnosticsHost = defaultFormatHost): string {
|
||||
return `${displayFileName(position.fileName, host)}(${position.line + 1},${position.column+1})`;
|
||||
}
|
||||
|
||||
export function flattenDiagnosticMessageChain(
|
||||
chain: api.DiagnosticMessageChain, host: ts.FormatDiagnosticsHost = defaultFormatHost): string {
|
||||
let result = chain.messageText;
|
||||
let indent = 1;
|
||||
let current = chain.next;
|
||||
const newLine = host.getNewLine();
|
||||
while (current) {
|
||||
result += newLine;
|
||||
for (let i = 0; i < indent; i++) {
|
||||
result += ' ';
|
||||
}
|
||||
result += current.messageText;
|
||||
const position = current.position;
|
||||
if (position) {
|
||||
result += ` at ${formatDiagnosticPosition(position, host)}`;
|
||||
}
|
||||
current = current.next;
|
||||
indent++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function formatDiagnostic(
|
||||
diagnostic: api.Diagnostic, host: ts.FormatDiagnosticsHost = defaultFormatHost) {
|
||||
let result = '';
|
||||
const newLine = host.getNewLine();
|
||||
const span = diagnostic.span;
|
||||
if (span) {
|
||||
result += `${formatDiagnosticPosition({
|
||||
fileName: span.start.file.url,
|
||||
line: span.start.line,
|
||||
column: span.start.col
|
||||
}, host)}: `;
|
||||
} else if (diagnostic.position) {
|
||||
result += `${formatDiagnosticPosition(diagnostic.position, host)}: `;
|
||||
}
|
||||
if (diagnostic.span && diagnostic.span.details) {
|
||||
result += `: ${diagnostic.span.details}, ${diagnostic.messageText}${newLine}`;
|
||||
} else if (diagnostic.chain) {
|
||||
result += `${flattenDiagnosticMessageChain(diagnostic.chain, host)}.${newLine}`;
|
||||
} else {
|
||||
result += `: ${diagnostic.messageText}${newLine}`;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function formatDiagnostics(
|
||||
diags: Diagnostics, tsFormatHost: ts.FormatDiagnosticsHost = defaultFormatHost): string {
|
||||
diags: Diagnostics, host: ts.FormatDiagnosticsHost = defaultFormatHost): string {
|
||||
if (diags && diags.length) {
|
||||
return diags
|
||||
.map(d => {
|
||||
if (api.isTsDiagnostic(d)) {
|
||||
return ts.formatDiagnostics([d], tsFormatHost);
|
||||
.map(diagnostic => {
|
||||
if (api.isTsDiagnostic(diagnostic)) {
|
||||
return ts.formatDiagnostics([diagnostic], host);
|
||||
} else {
|
||||
let res = ts.DiagnosticCategory[d.category];
|
||||
if (d.span) {
|
||||
res +=
|
||||
` at ${d.span.start.file.url}(${d.span.start.line + 1},${d.span.start.col + 1})`;
|
||||
}
|
||||
if (d.span && d.span.details) {
|
||||
res += `: ${d.span.details}, ${d.messageText}\n`;
|
||||
} else {
|
||||
res += `: ${d.messageText}\n`;
|
||||
}
|
||||
return res;
|
||||
return formatDiagnostic(diagnostic, host);
|
||||
}
|
||||
})
|
||||
.join('');
|
||||
} else
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export interface ParsedConfiguration {
|
||||
|
@ -6,16 +6,24 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {GeneratedFile, ParseSourceSpan} from '@angular/compiler';
|
||||
import {GeneratedFile, ParseSourceSpan, Position} from '@angular/compiler';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
export const DEFAULT_ERROR_CODE = 100;
|
||||
export const UNKNOWN_ERROR_CODE = 500;
|
||||
export const SOURCE = 'angular' as 'angular';
|
||||
|
||||
export interface DiagnosticMessageChain {
|
||||
messageText: string;
|
||||
position?: Position;
|
||||
next?: DiagnosticMessageChain;
|
||||
}
|
||||
|
||||
export interface Diagnostic {
|
||||
messageText: string;
|
||||
span?: ParseSourceSpan;
|
||||
position?: Position;
|
||||
chain?: DiagnosticMessageChain;
|
||||
category: ts.DiagnosticCategory;
|
||||
code: number;
|
||||
source: 'angular';
|
||||
@ -192,6 +200,13 @@ export interface CompilerHost extends ts.CompilerHost {
|
||||
* cause a diagnostics diagnostic error or an exception to be thrown.
|
||||
*/
|
||||
readResource?(fileName: string): Promise<string>|string;
|
||||
/**
|
||||
* Produce an AMD module name for the source file. Used in Bazel.
|
||||
*
|
||||
* An AMD module can have an arbitrary name, so that it is require'd by name
|
||||
* rather than by path. See http://requirejs.org/docs/whyamd.html#namedmodules
|
||||
*/
|
||||
amdModuleName?(sf: ts.SourceFile): string|undefined;
|
||||
}
|
||||
|
||||
export enum EmitFlags {
|
||||
|
@ -41,6 +41,13 @@ export interface CodeGenerator {
|
||||
findGeneratedFileNames(fileName: string): string[];
|
||||
}
|
||||
|
||||
function assert<T>(condition: T | null | undefined) {
|
||||
if (!condition) {
|
||||
// TODO(chuckjaz): do the right thing
|
||||
}
|
||||
return condition !;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the following hosts based on an api.CompilerHost:
|
||||
* - ts.CompilerHost to be consumed by a ts.Program
|
||||
@ -113,7 +120,7 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
|
||||
return sf ? this.metadataProvider.getMetadata(sf) : undefined;
|
||||
},
|
||||
fileExists: (filePath) => this.originalFileExists(filePath),
|
||||
readFile: (filePath) => this.context.readFile(filePath),
|
||||
readFile: (filePath) => assert(this.context.readFile(filePath)),
|
||||
};
|
||||
}
|
||||
|
||||
@ -296,6 +303,11 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
|
||||
/* emitSourceMaps */ false);
|
||||
const sf = ts.createSourceFile(
|
||||
genFile.genFileUrl, sourceText, this.options.target || ts.ScriptTarget.Latest);
|
||||
if ((this.options.module === ts.ModuleKind.AMD || this.options.module === ts.ModuleKind.UMD) &&
|
||||
this.context.amdModuleName) {
|
||||
const moduleName = this.context.amdModuleName(sf);
|
||||
if (moduleName) sf.moduleName = moduleName;
|
||||
}
|
||||
this.generatedSourceFiles.set(genFile.genFileUrl, {
|
||||
sourceFile: sf,
|
||||
emitCtx: context, externalReferences,
|
||||
@ -421,7 +433,7 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
|
||||
return summary.text;
|
||||
}
|
||||
if (this.originalFileExists(filePath)) {
|
||||
return this.context.readFile(filePath);
|
||||
return assert(this.context.readFile(filePath));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -472,7 +484,7 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
|
||||
if (!this.originalFileExists(filePath)) {
|
||||
throw syntaxError(`Error: Resource file not found: ${filePath}`);
|
||||
}
|
||||
return this.context.readFile(filePath);
|
||||
return assert(this.context.readFile(filePath));
|
||||
}
|
||||
|
||||
private hasBundleIndex(filePath: string): boolean {
|
||||
@ -490,13 +502,13 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
|
||||
if (this.originalFileExists(packageFile)) {
|
||||
// Once we see a package.json file, assume false until it we find the bundle index.
|
||||
result = false;
|
||||
const packageContent: any = JSON.parse(this.context.readFile(packageFile));
|
||||
const packageContent: any = JSON.parse(assert(this.context.readFile(packageFile)));
|
||||
if (packageContent.typings) {
|
||||
const typings = path.normalize(path.join(directory, packageContent.typings));
|
||||
if (DTS.test(typings)) {
|
||||
const metadataFile = typings.replace(DTS, '.metadata.json');
|
||||
if (this.originalFileExists(metadataFile)) {
|
||||
const metadata = JSON.parse(this.context.readFile(metadataFile));
|
||||
const metadata = JSON.parse(assert(this.context.readFile(metadataFile)));
|
||||
if (metadata.flatModuleIndexRedirect) {
|
||||
this.flatModuleIndexRedirectNames.add(typings);
|
||||
// Note: don't set result = true,
|
||||
|
@ -112,6 +112,7 @@ function upgradeMetadataWithDtsData(
|
||||
newMetadata.metadata[prop] = dtsMetadata.metadata[prop];
|
||||
}
|
||||
}
|
||||
if (dtsMetadata['importAs']) newMetadata['importAs'] = dtsMetadata['importAs'];
|
||||
|
||||
// Only copy exports from exports from metadata prior to version 3.
|
||||
// Starting with version 3 the collector began collecting exports and
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AotCompiler, AotCompilerHost, AotCompilerOptions, EmitterVisitorContext, GeneratedFile, MessageBundle, NgAnalyzedFile, NgAnalyzedModules, ParseSourceSpan, Serializer, TypeScriptEmitter, Xliff, Xliff2, Xmb, core, createAotCompiler, getParseErrors, isSyntaxError} from '@angular/compiler';
|
||||
import {AotCompiler, AotCompilerHost, AotCompilerOptions, EmitterVisitorContext, FormattedMessageChain, GeneratedFile, MessageBundle, NgAnalyzedFile, NgAnalyzedModules, ParseSourceSpan, Position, Serializer, TypeScriptEmitter, Xliff, Xliff2, Xmb, core, createAotCompiler, getParseErrors, isFormattedError, isSyntaxError} from '@angular/compiler';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
@ -14,14 +14,13 @@ import * as ts from 'typescript';
|
||||
import {TypeCheckHost, translateDiagnostics} from '../diagnostics/translate_diagnostics';
|
||||
import {ModuleMetadata, createBundleIndexHost} from '../metadata/index';
|
||||
|
||||
import {CompilerHost, CompilerOptions, CustomTransformers, DEFAULT_ERROR_CODE, Diagnostic, EmitFlags, LazyRoute, LibrarySummary, Program, SOURCE, TsEmitArguments, TsEmitCallback} from './api';
|
||||
import {CompilerHost, CompilerOptions, CustomTransformers, DEFAULT_ERROR_CODE, Diagnostic, DiagnosticMessageChain, EmitFlags, LazyRoute, LibrarySummary, Program, SOURCE, TsEmitArguments, TsEmitCallback} from './api';
|
||||
import {CodeGenerator, TsCompilerAotCompilerTypeCheckHostAdapter, getOriginalReferences} from './compiler_host';
|
||||
import {LowerMetadataCache, getExpressionLoweringTransformFactory} from './lower_expressions';
|
||||
import {getAngularEmitterTransformFactory} from './node_emitter_transform';
|
||||
import {GENERATED_FILES, StructureIsReused, createMessageDiagnostic, isInRootDir, ngToTsDiagnostic, tsStructureIsReused} from './util';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Maximum number of files that are emitable via calling ts.Program.emit
|
||||
* passing individual targetSourceFiles.
|
||||
@ -378,10 +377,12 @@ class AngularCompilerProgram implements Program {
|
||||
}
|
||||
|
||||
private get structuralDiagnostics(): Diagnostic[] {
|
||||
if (!this._structuralDiagnostics) {
|
||||
let diagnostics = this._structuralDiagnostics;
|
||||
if (!diagnostics) {
|
||||
this.initSync();
|
||||
diagnostics = (this._structuralDiagnostics = this._structuralDiagnostics || []);
|
||||
}
|
||||
return this._structuralDiagnostics !;
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
private get tsProgram(): ts.Program {
|
||||
@ -430,16 +431,9 @@ class AngularCompilerProgram implements Program {
|
||||
this.rootNames, this.options, this.host, this.metadataCache, codegen,
|
||||
this.oldProgramLibrarySummaries);
|
||||
const aotOptions = getAotCompilerOptions(this.options);
|
||||
this._structuralDiagnostics = [];
|
||||
const errorCollector =
|
||||
(this.options.collectAllErrors || this.options.fullTemplateTypeCheck) ? (err: any) => {
|
||||
this._structuralDiagnostics !.push({
|
||||
messageText: err.toString(),
|
||||
category: ts.DiagnosticCategory.Error,
|
||||
source: SOURCE,
|
||||
code: DEFAULT_ERROR_CODE
|
||||
});
|
||||
} : undefined;
|
||||
const errorCollector = (this.options.collectAllErrors || this.options.fullTemplateTypeCheck) ?
|
||||
(err: any) => this._addStructuralDiagnostics(err) :
|
||||
undefined;
|
||||
this._compiler = createAotCompiler(this._hostAdapter, aotOptions, errorCollector).compiler;
|
||||
}
|
||||
|
||||
@ -522,33 +516,26 @@ class AngularCompilerProgram implements Program {
|
||||
this._hostAdapter.isSourceFile = () => false;
|
||||
this._tsProgram = ts.createProgram(this.rootNames, this.options, this.hostAdapter);
|
||||
if (isSyntaxError(e)) {
|
||||
const parserErrors = getParseErrors(e);
|
||||
if (parserErrors && parserErrors.length) {
|
||||
this._structuralDiagnostics = [
|
||||
...(this._structuralDiagnostics || []),
|
||||
...parserErrors.map<Diagnostic>(e => ({
|
||||
messageText: e.contextualMessage(),
|
||||
category: ts.DiagnosticCategory.Error,
|
||||
span: e.span,
|
||||
source: SOURCE,
|
||||
code: DEFAULT_ERROR_CODE
|
||||
}))
|
||||
];
|
||||
} else {
|
||||
this._structuralDiagnostics = [
|
||||
...(this._structuralDiagnostics || []), {
|
||||
messageText: e.message,
|
||||
category: ts.DiagnosticCategory.Error,
|
||||
source: SOURCE,
|
||||
code: DEFAULT_ERROR_CODE
|
||||
}
|
||||
];
|
||||
}
|
||||
this._addStructuralDiagnostics(e);
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
private _addStructuralDiagnostics(error: Error) {
|
||||
const diagnostics = this._structuralDiagnostics || (this._structuralDiagnostics = []);
|
||||
if (isSyntaxError(error)) {
|
||||
diagnostics.push(...syntaxErrorToDiagnostics(error));
|
||||
} else {
|
||||
diagnostics.push({
|
||||
messageText: error.toString(),
|
||||
category: ts.DiagnosticCategory.Error,
|
||||
source: SOURCE,
|
||||
code: DEFAULT_ERROR_CODE
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Note: this returns a ts.Diagnostic so that we
|
||||
// can return errors in a ts.EmitResult
|
||||
private generateFilesForEmit(emitFlags: EmitFlags):
|
||||
@ -606,7 +593,8 @@ class AngularCompilerProgram implements Program {
|
||||
|
||||
private writeFile(
|
||||
outFileName: string, outData: string, writeByteOrderMark: boolean,
|
||||
onError?: (message: string) => void, genFile?: GeneratedFile, sourceFiles?: ts.SourceFile[]) {
|
||||
onError?: (message: string) => void, genFile?: GeneratedFile,
|
||||
sourceFiles?: ReadonlyArray<ts.SourceFile>) {
|
||||
// collect emittedLibrarySummaries
|
||||
let baseFile: ts.SourceFile|undefined;
|
||||
if (genFile) {
|
||||
@ -653,7 +641,8 @@ class AngularCompilerProgram implements Program {
|
||||
if (baseFile) {
|
||||
sourceFiles = sourceFiles ? [...sourceFiles, baseFile] : [baseFile];
|
||||
}
|
||||
this.host.writeFile(outFileName, outData, writeByteOrderMark, onError, sourceFiles);
|
||||
// TODO: remove any when TS 2.4 support is removed.
|
||||
this.host.writeFile(outFileName, outData, writeByteOrderMark, onError, sourceFiles as any);
|
||||
}
|
||||
}
|
||||
|
||||
@ -841,3 +830,56 @@ function mergeEmitResults(emitResults: ts.EmitResult[]): ts.EmitResult {
|
||||
}
|
||||
return {diagnostics, emitSkipped, emittedFiles};
|
||||
}
|
||||
|
||||
function diagnosticSourceOfSpan(span: ParseSourceSpan): ts.SourceFile {
|
||||
// For diagnostics, TypeScript only uses the fileName and text properties.
|
||||
// The redundant '()' are here is to avoid having clang-format breaking the line incorrectly.
|
||||
return ({ fileName: span.start.file.url, text: span.start.file.content } as any);
|
||||
}
|
||||
|
||||
function diagnosticSourceOfFileName(fileName: string, program: ts.Program): ts.SourceFile {
|
||||
const sourceFile = program.getSourceFile(fileName);
|
||||
if (sourceFile) return sourceFile;
|
||||
|
||||
// If we are reporting diagnostics for a source file that is not in the project then we need
|
||||
// to fake a source file so the diagnostic formatting routines can emit the file name.
|
||||
// The redundant '()' are here is to avoid having clang-format breaking the line incorrectly.
|
||||
return ({ fileName, text: '' } as any);
|
||||
}
|
||||
|
||||
|
||||
function diagnosticChainFromFormattedDiagnosticChain(chain: FormattedMessageChain):
|
||||
DiagnosticMessageChain {
|
||||
return {
|
||||
messageText: chain.message,
|
||||
next: chain.next && diagnosticChainFromFormattedDiagnosticChain(chain.next),
|
||||
position: chain.position
|
||||
};
|
||||
}
|
||||
|
||||
function syntaxErrorToDiagnostics(error: Error): Diagnostic[] {
|
||||
const parserErrors = getParseErrors(error);
|
||||
if (parserErrors && parserErrors.length) {
|
||||
return parserErrors.map<Diagnostic>(e => ({
|
||||
messageText: e.contextualMessage(),
|
||||
file: diagnosticSourceOfSpan(e.span),
|
||||
start: e.span.start.offset,
|
||||
length: e.span.end.offset - e.span.start.offset,
|
||||
category: ts.DiagnosticCategory.Error,
|
||||
source: SOURCE,
|
||||
code: DEFAULT_ERROR_CODE
|
||||
}));
|
||||
} else {
|
||||
if (isFormattedError(error)) {
|
||||
return [{
|
||||
messageText: error.message,
|
||||
chain: error.chain && diagnosticChainFromFormattedDiagnosticChain(error.chain),
|
||||
category: ts.DiagnosticCategory.Error,
|
||||
source: SOURCE,
|
||||
code: DEFAULT_ERROR_CODE,
|
||||
position: error.position
|
||||
}];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
@ -27,7 +27,7 @@ describe('metadata bundler', () => {
|
||||
|
||||
const originalOne = './src/one';
|
||||
const originalTwo = './src/two/index';
|
||||
expect(Object.keys(result.metadata.origins)
|
||||
expect(Object.keys(result.metadata.origins !)
|
||||
.sort()
|
||||
.map(name => ({name, value: result.metadata.origins ![name]})))
|
||||
.toEqual([
|
||||
|
@ -45,6 +45,7 @@ describe('Collector', () => {
|
||||
're-exports.ts',
|
||||
're-exports-2.ts',
|
||||
'export-as.d.ts',
|
||||
'named-module.d.ts',
|
||||
'static-field-reference.ts',
|
||||
'static-method.ts',
|
||||
'static-method-call.ts',
|
||||
@ -101,6 +102,12 @@ describe('Collector', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should preserve module names from TypeScript sources', () => {
|
||||
const sourceFile = program.getSourceFile('named-module.d.ts');
|
||||
const metadata = collector.getMetadata(sourceFile);
|
||||
expect(metadata !['importAs']).toEqual('some-named-module');
|
||||
});
|
||||
|
||||
it('should be able to collect a simple component\'s metadata', () => {
|
||||
const sourceFile = program.getSourceFile('app/hero-detail.component.ts');
|
||||
const metadata = collector.getMetadata(sourceFile);
|
||||
@ -112,7 +119,13 @@ describe('Collector', () => {
|
||||
__symbolic: 'class',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Component'},
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/core',
|
||||
name: 'Component',
|
||||
line: 4,
|
||||
character: 7
|
||||
},
|
||||
arguments: [{
|
||||
selector: 'my-hero-detail',
|
||||
template: `
|
||||
@ -132,8 +145,13 @@ describe('Collector', () => {
|
||||
__symbolic: 'property',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression:
|
||||
{__symbolic: 'reference', module: 'angular2/core', name: 'Input'}
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/core',
|
||||
name: 'Input',
|
||||
line: 18,
|
||||
character: 9
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}
|
||||
@ -153,7 +171,13 @@ describe('Collector', () => {
|
||||
__symbolic: 'class',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Component'},
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/core',
|
||||
name: 'Component',
|
||||
line: 9,
|
||||
character: 7
|
||||
},
|
||||
arguments: [{
|
||||
selector: 'my-app',
|
||||
template: `
|
||||
@ -172,20 +196,52 @@ describe('Collector', () => {
|
||||
__symbolic: 'reference',
|
||||
module: './hero-detail.component',
|
||||
name: 'HeroDetailComponent',
|
||||
line: 22,
|
||||
character: 21
|
||||
},
|
||||
{__symbolic: 'reference', module: 'angular2/common', name: 'NgFor'}
|
||||
{
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/common',
|
||||
name: 'NgFor',
|
||||
line: 22,
|
||||
character: 42
|
||||
}
|
||||
],
|
||||
providers: [{__symbolic: 'reference', module: './hero.service', default: true}],
|
||||
providers: [{
|
||||
__symbolic: 'reference',
|
||||
module: './hero.service',
|
||||
default: true,
|
||||
line: 23,
|
||||
character: 20
|
||||
}],
|
||||
pipes: [
|
||||
{__symbolic: 'reference', module: 'angular2/common', name: 'LowerCasePipe'},
|
||||
{__symbolic: 'reference', module: 'angular2/common', name: 'UpperCasePipe'}
|
||||
{
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/common',
|
||||
name: 'LowerCasePipe',
|
||||
line: 24,
|
||||
character: 16
|
||||
},
|
||||
{
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/common',
|
||||
name: 'UpperCasePipe',
|
||||
line: 24,
|
||||
character: 38
|
||||
}
|
||||
]
|
||||
}]
|
||||
}],
|
||||
members: {
|
||||
__ctor__: [{
|
||||
__symbolic: 'constructor',
|
||||
parameters: [{__symbolic: 'reference', module: './hero.service', default: true}]
|
||||
parameters: [{
|
||||
__symbolic: 'reference',
|
||||
module: './hero.service',
|
||||
default: true,
|
||||
line: 31,
|
||||
character: 42
|
||||
}]
|
||||
}],
|
||||
onSelect: [{__symbolic: 'method'}],
|
||||
ngOnInit: [{__symbolic: 'method'}],
|
||||
@ -236,22 +292,23 @@ describe('Collector', () => {
|
||||
});
|
||||
|
||||
it('should record annotations on set and get declarations', () => {
|
||||
const propertyData = {
|
||||
const propertyData = (line: number) => ({
|
||||
name: [{
|
||||
__symbolic: 'property',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Input'},
|
||||
expression:
|
||||
{__symbolic: 'reference', module: 'angular2/core', name: 'Input', line, character: 9},
|
||||
arguments: ['firstName']
|
||||
}]
|
||||
}]
|
||||
};
|
||||
});
|
||||
const caseGetProp = <ClassMetadata>casesMetadata.metadata['GetProp'];
|
||||
expect(caseGetProp.members).toEqual(propertyData);
|
||||
expect(caseGetProp.members).toEqual(propertyData(11));
|
||||
const caseSetProp = <ClassMetadata>casesMetadata.metadata['SetProp'];
|
||||
expect(caseSetProp.members).toEqual(propertyData);
|
||||
expect(caseSetProp.members).toEqual(propertyData(19));
|
||||
const caseFullProp = <ClassMetadata>casesMetadata.metadata['FullProp'];
|
||||
expect(caseFullProp.members).toEqual(propertyData);
|
||||
expect(caseFullProp.members).toEqual(propertyData(27));
|
||||
});
|
||||
|
||||
it('should record references to parameterized types', () => {
|
||||
@ -260,7 +317,13 @@ describe('Collector', () => {
|
||||
__symbolic: 'class',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Injectable'}
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/core',
|
||||
name: 'Injectable',
|
||||
line: 40,
|
||||
character: 7
|
||||
}
|
||||
}],
|
||||
members: {
|
||||
__ctor__: [{
|
||||
@ -313,7 +376,7 @@ describe('Collector', () => {
|
||||
const ctor = <ConstructorMetadata>someClass.members !['__ctor__'][0];
|
||||
const parameters = ctor.parameters;
|
||||
expect(parameters).toEqual([
|
||||
{__symbolic: 'reference', module: 'angular2/common', name: 'NgFor'}
|
||||
{__symbolic: 'reference', module: 'angular2/common', name: 'NgFor', line: 6, character: 29}
|
||||
]);
|
||||
});
|
||||
|
||||
@ -398,7 +461,7 @@ describe('Collector', () => {
|
||||
const ctor = <ConstructorMetadata>someClass.members !['__ctor__'][0];
|
||||
const parameters = ctor.parameters;
|
||||
expect(parameters).toEqual([
|
||||
{__symbolic: 'reference', module: 'angular2/common', name: 'NgFor'}
|
||||
{__symbolic: 'reference', module: 'angular2/common', name: 'NgFor', line: 6, character: 29}
|
||||
]);
|
||||
});
|
||||
|
||||
@ -427,7 +490,13 @@ describe('Collector', () => {
|
||||
B: 1,
|
||||
C: 30,
|
||||
D: 40,
|
||||
E: {__symbolic: 'reference', module: './exported-consts', name: 'constValue'}
|
||||
E: {
|
||||
__symbolic: 'reference',
|
||||
module: './exported-consts',
|
||||
name: 'constValue',
|
||||
line: 5,
|
||||
character: 75
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -457,13 +526,25 @@ describe('Collector', () => {
|
||||
expect(classData).toBeDefined();
|
||||
expect(classData.decorators).toEqual([{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Component'},
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/core',
|
||||
name: 'Component',
|
||||
line: 4,
|
||||
character: 5
|
||||
},
|
||||
arguments: [{
|
||||
providers: {
|
||||
__symbolic: 'call',
|
||||
expression: {
|
||||
__symbolic: 'select',
|
||||
expression: {__symbolic: 'reference', module: './static-method', name: 'MyModule'},
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: './static-method',
|
||||
name: 'MyModule',
|
||||
line: 5,
|
||||
character: 17
|
||||
},
|
||||
member: 'with'
|
||||
},
|
||||
arguments: ['a']
|
||||
@ -489,13 +570,25 @@ describe('Collector', () => {
|
||||
expect(classData).toBeDefined();
|
||||
expect(classData.decorators).toEqual([{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Component'},
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/core',
|
||||
name: 'Component',
|
||||
line: 4,
|
||||
character: 5
|
||||
},
|
||||
arguments: [{
|
||||
providers: [{
|
||||
provide: 'a',
|
||||
useValue: {
|
||||
__symbolic: 'select',
|
||||
expression: {__symbolic: 'reference', module: './static-field', name: 'MyModule'},
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: './static-field',
|
||||
name: 'MyModule',
|
||||
line: 5,
|
||||
character: 45
|
||||
},
|
||||
member: 'VALUE'
|
||||
}
|
||||
}]
|
||||
@ -578,8 +671,20 @@ describe('Collector', () => {
|
||||
const metadata = collector.getMetadata(source) !;
|
||||
expect(metadata.metadata).toEqual({
|
||||
MyClass: Object({__symbolic: 'class'}),
|
||||
OtherModule: {__symbolic: 'reference', module: './static-field-reference', name: 'Foo'},
|
||||
MyOtherModule: {__symbolic: 'reference', module: './static-field', name: 'MyModule'}
|
||||
OtherModule: {
|
||||
__symbolic: 'reference',
|
||||
module: './static-field-reference',
|
||||
name: 'Foo',
|
||||
line: 4,
|
||||
character: 12
|
||||
},
|
||||
MyOtherModule: {
|
||||
__symbolic: 'reference',
|
||||
module: './static-field',
|
||||
name: 'MyModule',
|
||||
line: 4,
|
||||
character: 25
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -598,7 +703,13 @@ describe('Collector', () => {
|
||||
__symbolic: 'class',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Component'},
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/core',
|
||||
name: 'Component',
|
||||
line: 11,
|
||||
character: 5
|
||||
},
|
||||
arguments: [{providers: [{__symbolic: 'reference', name: 'REQUIRED_VALIDATOR'}]}]
|
||||
}]
|
||||
}
|
||||
@ -620,7 +731,13 @@ describe('Collector', () => {
|
||||
__symbolic: 'class',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Component'},
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/core',
|
||||
name: 'Component',
|
||||
line: 11,
|
||||
character: 5
|
||||
},
|
||||
arguments: [{providers: [{__symbolic: 'reference', name: 'REQUIRED_VALIDATOR'}]}]
|
||||
}]
|
||||
}
|
||||
@ -653,7 +770,13 @@ describe('Collector', () => {
|
||||
__symbolic: 'constructor',
|
||||
parameterDecorators: [[{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Inject'},
|
||||
expression: {
|
||||
__symbolic: 'reference',
|
||||
module: 'angular2/core',
|
||||
name: 'Inject',
|
||||
line: 6,
|
||||
character: 19
|
||||
},
|
||||
arguments: ['a']
|
||||
}]],
|
||||
parameters: [{__symbolic: 'reference', name: 'any'}]
|
||||
@ -687,13 +810,20 @@ describe('Collector', () => {
|
||||
__symbolic: 'reference',
|
||||
module: './external',
|
||||
name: 'external',
|
||||
line: 0,
|
||||
character: 68,
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should simplify a redundant template', () => {
|
||||
e('`${external}`', 'import {external} from "./external";')
|
||||
.toEqual({__symbolic: 'reference', module: './external', name: 'external'});
|
||||
e('`${external}`', 'import {external} from "./external";').toEqual({
|
||||
__symbolic: 'reference',
|
||||
module: './external',
|
||||
name: 'external',
|
||||
line: 0,
|
||||
character: 59
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to collect complex template with imported references', () => {
|
||||
@ -710,11 +840,18 @@ describe('Collector', () => {
|
||||
__symbolic: 'binop',
|
||||
operator: '+',
|
||||
left: 'foo:',
|
||||
right: {__symbolic: 'reference', module: './external', name: 'foo'}
|
||||
right: {
|
||||
__symbolic: 'reference',
|
||||
module: './external',
|
||||
name: 'foo',
|
||||
line: 0,
|
||||
character: 63
|
||||
}
|
||||
},
|
||||
right: ', bar:'
|
||||
},
|
||||
right: {__symbolic: 'reference', module: './external', name: 'bar'}
|
||||
right:
|
||||
{__symbolic: 'reference', module: './external', name: 'bar', line: 0, character: 75}
|
||||
},
|
||||
right: ', end'
|
||||
});
|
||||
@ -741,11 +878,11 @@ describe('Collector', () => {
|
||||
__ctor__: [{
|
||||
__symbolic: 'constructor',
|
||||
parameters: [
|
||||
{__symbolic: 'reference', module: './foo', name: 'Foo'},
|
||||
{__symbolic: 'reference', module: './foo', name: 'Foo'},
|
||||
{__symbolic: 'reference', module: './foo', name: 'Foo'},
|
||||
{__symbolic: 'reference', module: './foo', name: 'Foo'},
|
||||
{__symbolic: 'reference', module: './foo', name: 'Foo'}
|
||||
{__symbolic: 'reference', module: './foo', name: 'Foo', line: 3, character: 24},
|
||||
{__symbolic: 'reference', module: './foo', name: 'Foo', line: 3, character: 24},
|
||||
{__symbolic: 'reference', module: './foo', name: 'Foo', line: 3, character: 24},
|
||||
{__symbolic: 'reference', module: './foo', name: 'Foo', line: 3, character: 24},
|
||||
{__symbolic: 'reference', module: './foo', name: 'Foo', line: 3, character: 24}
|
||||
]
|
||||
}]
|
||||
});
|
||||
@ -825,7 +962,9 @@ describe('Collector', () => {
|
||||
extends: {
|
||||
__symbolic: 'reference',
|
||||
module: './class-inheritance-parent',
|
||||
name: 'ParentClassFromOtherFile'
|
||||
name: 'ParentClassFromOtherFile',
|
||||
line: 9,
|
||||
character: 45,
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1383,6 +1522,10 @@ const FILES: Directory = {
|
||||
'export-as.d.ts': `
|
||||
declare function someFunction(): void;
|
||||
export { someFunction as SomeFunction };
|
||||
`,
|
||||
'named-module.d.ts': `
|
||||
/// <amd-module name="some-named-module" />
|
||||
export type SomeType = 'a';
|
||||
`,
|
||||
'local-symbol-ref.ts': `
|
||||
import {Component, Validators} from 'angular2/core';
|
||||
|
@ -149,12 +149,14 @@ describe('Evaluator', () => {
|
||||
const newExpression = program.getSourceFile('newExpression.ts');
|
||||
expect(evaluator.evaluateNode(findVarInitializer(newExpression, 'someValue'))).toEqual({
|
||||
__symbolic: 'new',
|
||||
expression: {__symbolic: 'reference', name: 'Value', module: './classes'},
|
||||
expression:
|
||||
{__symbolic: 'reference', name: 'Value', module: './classes', line: 4, character: 33},
|
||||
arguments: ['name', 12]
|
||||
});
|
||||
expect(evaluator.evaluateNode(findVarInitializer(newExpression, 'complex'))).toEqual({
|
||||
__symbolic: 'new',
|
||||
expression: {__symbolic: 'reference', name: 'Value', module: './classes'},
|
||||
expression:
|
||||
{__symbolic: 'reference', name: 'Value', module: './classes', line: 5, character: 42},
|
||||
arguments: ['name', 12]
|
||||
});
|
||||
});
|
||||
@ -173,8 +175,7 @@ describe('Evaluator', () => {
|
||||
const errors = program.getSourceFile('errors.ts');
|
||||
const fDecl = findVar(errors, 'f') !;
|
||||
expect(evaluator.evaluateNode(fDecl.initializer !))
|
||||
.toEqual(
|
||||
{__symbolic: 'error', message: 'Function call not supported', line: 1, character: 12});
|
||||
.toEqual({__symbolic: 'error', message: 'Lambda not supported', line: 1, character: 12});
|
||||
const eDecl = findVar(errors, 'e') !;
|
||||
expect(evaluator.evaluateNode(eDecl.type !)).toEqual({
|
||||
__symbolic: 'error',
|
||||
|
@ -102,6 +102,7 @@ export class MockNode implements ts.Node {
|
||||
|
||||
export class MockIdentifier extends MockNode implements ts.Identifier {
|
||||
public text: string;
|
||||
public escapedText: ts.__String;
|
||||
// tslint:disable
|
||||
public _primaryExpressionBrand: any;
|
||||
public _memberExpressionBrand: any;
|
||||
@ -137,12 +138,14 @@ export class MockVariableDeclaration extends MockNode implements ts.VariableDecl
|
||||
}
|
||||
|
||||
export class MockSymbol implements ts.Symbol {
|
||||
public escapedName: ts.__String;
|
||||
constructor(
|
||||
public name: string, private node: ts.Declaration = MockVariableDeclaration.of(name),
|
||||
public flags: ts.SymbolFlags = 0) {}
|
||||
|
||||
getFlags(): ts.SymbolFlags { return this.flags; }
|
||||
getName(): string { return this.name; }
|
||||
getEscapedName(): ts.__String { return this.escapedName; }
|
||||
getDeclarations(): ts.Declaration[] { return [this.node]; }
|
||||
getDocumentationComment(): ts.SymbolDisplayPart[] { return []; }
|
||||
// TODO(vicb): removed in TS 2.2
|
||||
|
@ -163,7 +163,7 @@ describe('ngc transformer command-line', () => {
|
||||
const exitCode = main(['-p', 'not-exist'], errorSpy);
|
||||
expect(errorSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errorSpy.calls.mostRecent().args[0]).toContain('no such file or directory');
|
||||
expect(errorSpy.calls.mostRecent().args[0]).toContain('at Error (native)');
|
||||
expect(errorSpy.calls.mostRecent().args[0]).toContain('at Object.fs.lstatSync');
|
||||
expect(exitCode).toEqual(2);
|
||||
});
|
||||
|
||||
@ -184,8 +184,7 @@ describe('ngc transformer command-line', () => {
|
||||
|
||||
const exitCode = main(['-p', basePath], errorSpy);
|
||||
expect(errorSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errorSpy.calls.mostRecent().args[0])
|
||||
.toContain('Error at ' + path.join(basePath, 'mymodule.ts.MyComp.html'));
|
||||
expect(errorSpy.calls.mostRecent().args[0]).toContain('mymodule.ts.MyComp.html');
|
||||
expect(errorSpy.calls.mostRecent().args[0])
|
||||
.toContain(`Property 'unknownProp' does not exist on type 'MyComp'`);
|
||||
|
||||
@ -215,8 +214,7 @@ describe('ngc transformer command-line', () => {
|
||||
|
||||
const exitCode = main(['-p', basePath], errorSpy);
|
||||
expect(errorSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errorSpy.calls.mostRecent().args[0])
|
||||
.toContain('Error at ' + path.join(basePath, 'my.component.html(1,5):'));
|
||||
expect(errorSpy.calls.mostRecent().args[0]).toContain('my.component.html(1,5):');
|
||||
expect(errorSpy.calls.mostRecent().args[0])
|
||||
.toContain(`Property 'unknownProp' does not exist on type 'MyComp'`);
|
||||
|
||||
@ -1566,4 +1564,49 @@ describe('ngc transformer command-line', () => {
|
||||
expect(main(['-p', path.join(basePath, 'src/tsconfig.json')])).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatted messages', () => {
|
||||
it('should emit a formatted error message for a structural error', () => {
|
||||
write('src/tsconfig.json', `{
|
||||
"extends": "../tsconfig-base.json",
|
||||
"files": ["test-module.ts"]
|
||||
}`);
|
||||
write('src/lib/indirect2.ts', `
|
||||
declare var f: any;
|
||||
|
||||
export const t2 = f\`<p>hello</p>\`;
|
||||
`);
|
||||
write('src/lib/indirect1.ts', `
|
||||
import {t2} from './indirect2';
|
||||
export const t1 = t2 + ' ';
|
||||
`);
|
||||
write('src/lib/test.component.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
import {t1} from './indirect1';
|
||||
|
||||
@Component({
|
||||
template: t1,
|
||||
styleUrls: ['./test.component.css']
|
||||
})
|
||||
export class TestComponent {}
|
||||
`);
|
||||
write('src/test-module.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
import {TestComponent} from './lib/test.component';
|
||||
|
||||
@NgModule({declarations: [TestComponent]})
|
||||
export class TestModule {}
|
||||
`);
|
||||
const messages: string[] = [];
|
||||
const exitCode =
|
||||
main(['-p', path.join(basePath, 'src/tsconfig.json')], message => messages.push(message));
|
||||
expect(exitCode).toBe(1, 'Compile was expected to fail');
|
||||
expect(messages[0])
|
||||
.toEqual(`lib/test.component.ts(6,21): Error during template compile of 'TestComponent'
|
||||
Tagged template expressions are not supported in metadata in 't1'
|
||||
't1' references 't2' at lib/indirect1.ts(3,27)
|
||||
't2' contains the error at lib/indirect2.ts(4,27).
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -119,7 +119,7 @@ describe('perform watch', () => {
|
||||
const errorFileContent = `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
@NgModule(() => (1===1 ? null as any : null as any))
|
||||
@NgModule((() => (1===1 ? null as any : null as any)) as any)
|
||||
export class MyModule {}
|
||||
`;
|
||||
const indexTsPath = path.resolve(testSupport.basePath, 'src', 'index.ts');
|
||||
@ -143,7 +143,7 @@ describe('perform watch', () => {
|
||||
|
||||
const errDiags = host.diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error);
|
||||
expect(errDiags.length).toBe(1);
|
||||
expect(errDiags[0].messageText).toContain('Function calls are not supported.');
|
||||
expect(errDiags[0].messageText).toContain('Function expressions are not supported');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user