Compare commits
169 Commits
Author | SHA1 | Date | |
---|---|---|---|
7a1f964201 | |||
3dffbb6cf1 | |||
79f1798b68 | |||
dd08d421a1 | |||
a2d4299f2c | |||
2598b59de7 | |||
20b4617289 | |||
958bb0da04 | |||
4ba8f1989b | |||
c04b4d795a | |||
f1b5ba9231 | |||
50b524ba1e | |||
680ceb7d65 | |||
ea186d5ccd | |||
10455044f1 | |||
31150fe6e8 | |||
9223066123 | |||
cca4a5c519 | |||
6e5f8b59b3 | |||
8409b65153 | |||
38e2203b24 | |||
bd1dcb5f11 | |||
3993279527 | |||
bf1e2613b2 | |||
f7db0668d1 | |||
27d76776b8 | |||
8603d9c269 | |||
d55f747858 | |||
52de0fa558 | |||
d61ecf0663 | |||
5a9c5f28b8 | |||
15fc5dd7ee | |||
a5419608e0 | |||
5f95bf1dd2 | |||
33c8948fd3 | |||
606e51881a | |||
fdf4309b50 | |||
af996ef0c4 | |||
68d2dfdd2a | |||
07bd4b0630 | |||
df1718d624 | |||
17e3410d98 | |||
5effc330ed | |||
3df00828d7 | |||
8c477b2f45 | |||
7787771aba | |||
7275e1beb3 | |||
12ba62e5e2 | |||
e6e007e2f1 | |||
91dd138fa5 | |||
d972d82354 | |||
bdcf46f82e | |||
79e1c7b807 | |||
d22eeb70b8 | |||
aa92512ac6 | |||
f782b08f58 | |||
4202936bbf | |||
e1faca6386 | |||
f5b0e22d35 | |||
00693d70a2 | |||
bcef5efffe | |||
13ecc140e8 | |||
709a6dea06 | |||
16cfb88c00 | |||
efee6f5199 | |||
2aa8aae76d | |||
afb4bd9ef6 | |||
d641c36a45 | |||
f4566f8128 | |||
a67c06708d | |||
d9d57d71dd | |||
e06303a987 | |||
40b92ddf21 | |||
1681e4f57f | |||
71b7654660 | |||
eaaec6979c | |||
c587c63591 | |||
f50c1da4e2 | |||
0254ce1f6c | |||
c9b765f5c0 | |||
8c975ed156 | |||
bb35fcb562 | |||
57230b70a9 | |||
43dc60ce4f | |||
230b3b73d8 | |||
0b7dc2f9ff | |||
de1f44f51f | |||
f1cfddf6d6 | |||
ef621a2f00 | |||
df9761951b | |||
f786c560f1 | |||
c5557de3e7 | |||
ec3a5b54de | |||
cf269d9ff4 | |||
5fa5ffb82a | |||
4a57dcfd8d | |||
43923ffcf5 | |||
50c37d45dc | |||
a63359689f | |||
43d3a84df3 | |||
8310c91823 | |||
b64b5ece65 | |||
ed9c2b6281 | |||
1cf5f5fa38 | |||
a32078f85e | |||
decd129a4d | |||
c3c9ecb302 | |||
af520947aa | |||
040bf57966 | |||
65a60b7456 | |||
756ef09d12 | |||
9316f95467 | |||
83d94b7504 | |||
a121136fae | |||
a6bb84e02b | |||
3898dc488e | |||
ca3f9926f9 | |||
1c012a035f | |||
38c5304b7f | |||
9a049be67f | |||
2045c9e8ee | |||
6c4ec05a4a | |||
f7bfda31ff | |||
a92b573309 | |||
4fd13d71c8 | |||
bf7b82b658 | |||
c143fee849 | |||
0286956107 | |||
e884f4854d | |||
df1822fc2a | |||
42b4b6d21b | |||
36bc2ff269 | |||
1564042fe8 | |||
41c8c30973 | |||
61129fa12d | |||
3a5b4882bc | |||
425c1e6042 | |||
58605cf350 | |||
34b31dea7c | |||
a241ab7c07 | |||
745e10e6d2 | |||
33340dbbd1 | |||
52812c08e2 | |||
52f5ae1961 | |||
9be895b6da | |||
9f1c82537e | |||
5ab5cc77bb | |||
f1b6c6efa1 | |||
45ad13560b | |||
2045268cec | |||
fb1076b44a | |||
6fc46526ae | |||
3ef5ede6d6 | |||
136621ebc9 | |||
f23b22a0f4 | |||
0ca971c5bd | |||
3a6fcee0e6 | |||
8972137c29 | |||
cc6481077f | |||
c041b93418 | |||
bc33765913 | |||
31dce72b7b | |||
212f8dbde7 | |||
44da4984f9 | |||
d95344430c | |||
131626fc61 | |||
676bb0fa7d | |||
5a849829c4 | |||
671f73448c |
124
CHANGELOG.md
124
CHANGELOG.md
@ -1,3 +1,93 @@
|
||||
# [2.1.1](https://github.com/angular/angular/compare/2.1.0...2.1.1) (2016-10-20)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **compiler:** generate aot code for animation trigger output events ([#12291](https://github.com/angular/angular/issues/12291)) ([6e5f8b5](https://github.com/angular/angular/commit/6e5f8b5)), closes [#11707](https://github.com/angular/angular/issues/11707)
|
||||
* **compiler:** don't redeclare a var in the same scope ([#12386](https://github.com/angular/angular/issues/12386)) ([cca4a5c](https://github.com/angular/angular/commit/cca4a5c))
|
||||
* **core:** fix decorator defalut values ([bd1dcb5](https://github.com/angular/angular/commit/bd1dcb5))
|
||||
* **core:** fix property decorators ([3993279](https://github.com/angular/angular/commit/3993279)), closes [#12224](https://github.com/angular/angular/issues/12224)
|
||||
* **http:** make normalizeMethodName optimizer-compatible. ([#12370](https://github.com/angular/angular/issues/12370)) ([8409b65](https://github.com/angular/angular/commit/8409b65))
|
||||
* **router:** correctly export filter operator in es5 ([#12286](https://github.com/angular/angular/issues/12286)) ([27d7677](https://github.com/angular/angular/commit/27d7677))
|
||||
* **router:** do not update primary route if only secondary outlet is given ([#11797](https://github.com/angular/angular/issues/11797)) ([da5fc69](https://github.com/angular/angular/commit/da5fc69))
|
||||
* **router:** fix lazy loading triggered by redirects from wildcard routes ([5ae6915](https://github.com/angular/angular/commit/5ae6915)), closes [#12183](https://github.com/angular/angular/issues/12183)
|
||||
* **router:** module loader should start compiling modules when stubbedModules are set ([#11742](https://github.com/angular/angular/issues/11742)) ([b44b6ef](https://github.com/angular/angular/commit/b44b6ef))
|
||||
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* **common:** optimize NgSwitch default case ([fdf4309](https://github.com/angular/angular/commit/fdf4309))
|
||||
|
||||
|
||||
|
||||
<a name="2.2.0-beta.0"></a>
|
||||
# [2.2.0-beta.0](https://github.com/angular/angular/compare/2.1.0...2.2.0-beta.0) (2016-10-20)
|
||||
|
||||
### Features
|
||||
|
||||
* **common:** support narrow forms for month and weekdays in DatePipe ([#12297](https://github.com/angular/angular/issues/12297)) ([f77ab6a](https://github.com/angular/angular/commit/f77ab6a)), closes [#12294](https://github.com/angular/angular/issues/12294)
|
||||
* **forms:** add hasError and getError to AbstractControlDirective ([#11985](https://github.com/angular/angular/issues/11985)) ([592f40a](https://github.com/angular/angular/commit/592f40a)), closes [#7255](https://github.com/angular/angular/issues/7255)
|
||||
* **forms:** add ng-pending CSS class during async validation ([#11243](https://github.com/angular/angular/issues/11243)) ([97bc971](https://github.com/angular/angular/commit/97bc971)), closes [#10336](https://github.com/angular/angular/issues/10336)
|
||||
* **forms:** Added emitEvent to AbstractControl methods ([#11949](https://github.com/angular/angular/issues/11949)) ([b9fc090](https://github.com/angular/angular/commit/b9fc090))
|
||||
* **forms:** make 'parent' a public property of 'AbstractControl' ([#11855](https://github.com/angular/angular/issues/11855)) ([445e592](https://github.com/angular/angular/commit/445e592))
|
||||
* **forms:** Validator.pattern accepts a RegExp ([#12323](https://github.com/angular/angular/issues/12323)) ([bf60418](https://github.com/angular/angular/commit/bf60418))
|
||||
* **upgrade:** add support for AoT compiled upgrade applications ([d6791ff](https://github.com/angular/angular/commit/d6791ff)), closes [#12239](https://github.com/angular/angular/issues/12239)
|
||||
* **router:** add support for ng1/ng2 migration ([#12160](https://github.com/angular/angular/issues/12160)) ([8b9ab44](https://github.com/angular/angular/commit/8b9ab44))
|
||||
|
||||
Note: The 2.2.0-beta.0 release also contains all the changes present in the 2.1.1 release.
|
||||
|
||||
|
||||
|
||||
<a name="2.1.0"></a>
|
||||
# [2.1.0 incremental-metamorphosis](https://github.com/angular/angular/compare/2.1.0-rc.0...2.1.0) (2016-10-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **compiler:** allow whitespace as `<ng-content>` content ([#12225](https://github.com/angular/angular/issues/12225)) ([df1718d](https://github.com/angular/angular/commit/df1718d))
|
||||
* **compiler:** interpolation expressions report the correct offset ([#12125](https://github.com/angular/angular/issues/12125)) ([d641c36](https://github.com/angular/angular/commit/d641c36))
|
||||
* **compiler:** properly shim `:host:before` and `:host(:before)` ([#12171](https://github.com/angular/angular/issues/12171)) ([aa92512](https://github.com/angular/angular/commit/aa92512)), closes [#12165](https://github.com/angular/angular/issues/12165)
|
||||
* **compiler:** validate `@HostBinding` name ([#12139](https://github.com/angular/angular/issues/12139)) ([13ecc14](https://github.com/angular/angular/commit/13ecc14))
|
||||
* **compiler-cli:** don't clone static symbols when simplifying annotation metadata ([#12158](https://github.com/angular/angular/issues/12158)) ([8c477b2](https://github.com/angular/angular/commit/8c477b2))
|
||||
* **compiler-cli:** remove peerDependency on [@angular](https://github.com/angular)/platform-server ([#12122](https://github.com/angular/angular/issues/12122)) ([71b7654](https://github.com/angular/angular/commit/71b7654))
|
||||
* **compiler-cli:** remove unused parse5 dependency from package.json ([eaaec69](https://github.com/angular/angular/commit/eaaec69))
|
||||
* **forms:** allow optional fields with pattern and minlength validators ([#12147](https://github.com/angular/angular/issues/12147)) ([d22eeb7](https://github.com/angular/angular/commit/d22eeb7))
|
||||
* **forms:** properly validate blank strings with minlength ([#12091](https://github.com/angular/angular/issues/12091)) ([f50c1da](https://github.com/angular/angular/commit/f50c1da))
|
||||
* **http:** fix Headers initialization from Headers and Object ([#12106](https://github.com/angular/angular/issues/12106)) ([f4566f8](https://github.com/angular/angular/commit/f4566f8))
|
||||
* **http:** Headers.append should append to the list ([a67c067](https://github.com/angular/angular/commit/a67c067))
|
||||
* **platform-browser-dynamic:** mark platformBrowserDynamic as stable API ([#12154](https://github.com/angular/angular/issues/12154)) ([bcef5ef](https://github.com/angular/angular/commit/bcef5ef))
|
||||
* **router:** improve error message ([#12102](https://github.com/angular/angular/issues/12102)) ([e06303a](https://github.com/angular/angular/commit/e06303a))
|
||||
* **router:** parent resolve should complete before merging resolved data ([1681e4f](https://github.com/angular/angular/commit/1681e4f)), closes [#12032](https://github.com/angular/angular/issues/12032)
|
||||
* **router:** wildcards routes should support lazy loading ([40b92dd](https://github.com/angular/angular/commit/40b92dd)), closes [#12024](https://github.com/angular/angular/issues/12024)
|
||||
* **upgrade:** allow compilerOptions in bootstrap ([#10575](https://github.com/angular/angular/issues/10575)) ([5effc33](https://github.com/angular/angular/commit/5effc33))
|
||||
|
||||
|
||||
|
||||
<a name="2.1.0-rc.0"></a>
|
||||
# [2.1.0-rc.0](https://github.com/angular/angular/compare/2.1.0-beta.0...2.1.0-rc.0) (2016-10-05)
|
||||
|
||||
### Features
|
||||
|
||||
* **animations:** provide aliases for `:enter` and `:leave` transitions ([#11991](https://github.com/angular/angular/issues/11991)) ([e884f48](https://github.com/angular/angular/commit/e884f48))
|
||||
|
||||
Note: 2.1.0-rc.0 release also contains all the changes present in the 2.0.2 release.
|
||||
|
||||
|
||||
|
||||
<a name="2.1.0-beta.0"></a>
|
||||
# [2.1.0-beta.0](https://github.com/angular/angular/compare/2.0.0...2.1.0-beta.0) (2016-09-23)
|
||||
|
||||
### Features
|
||||
|
||||
* **router:** add router preloader to optimistically preload routes ([5a84982](https://github.com/angular/angular/commit/5a84982))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
* **router:** update the router not to reset router state when updating root component ([#11799](https://github.com/angular/angular/issues/11799)) ([31dce72](https://github.com/angular/angular/commit/31dce72))
|
||||
|
||||
Note: 2.1.0-beta.0 release also contains all the changes present in the 2.0.1 release.
|
||||
|
||||
|
||||
|
||||
<a name="2.0.2"></a>
|
||||
## [2.0.2](https://github.com/angular/angular/compare/2.0.1...2.0.2) (2016-10-05)
|
||||
|
||||
@ -7,18 +97,18 @@
|
||||
* **common:** correctly removes styles on IE ([#11953](https://github.com/angular/angular/pull/11953)), closes [#7916](https://github.com/angular/angular/issues/7916)
|
||||
* **compiler:** do not embed templateUrl in view factories in non-debug mode. ([#11818](https://github.com/angular/angular/issues/11818)) ([51e1994](https://github.com/angular/angular/commit/51e1994)), closes [#11117](https://github.com/angular/angular/issues/11117)
|
||||
* **compiler:** move detection of unsafe properties for binding to ElementSchemaRegistry ([#11378](https://github.com/angular/angular/issues/11378)) ([5911c3b](https://github.com/angular/angular/commit/5911c3b))
|
||||
* **forms:** properly validate empty strings with patterns ([#11450](https://github.com/angular/angular/issues/11450)) ([e00de0c](https://github.com/angular/angular/commit/e00de0c))
|
||||
* **http:** preserve case of the first init, `set()` or `append()` ([#12023](https://github.com/angular/angular/issues/12023)) ([adb17fe](https://github.com/angular/angular/commit/adb17fe)), closes [#11624](https://github.com/angular/angular/issues/11624)
|
||||
* **compiler-cli:** allow ReflectorHost passed as argument to CodeGenerator#create ([#11951](https://github.com/angular/angular/issues/11951)) ([826c98e](https://github.com/angular/angular/commit/826c98e))
|
||||
* **router:** do not reset the router state when updating the component ([#11867](https://github.com/angular/angular/issues/11867)) ([cf750e1](https://github.com/angular/angular/commit/cf750e1))
|
||||
* **compiler:** fix `:host(tag)` and `:host-context(tag)` ([a6bb84e0](https://github.com/angular/angular/commit/a6bb84e02b7579f8d957ef6ba5b10d83482ed756)), closes [#11972](https://github.com/angular/angular/issues/11972)
|
||||
* **compiler:** fix attribute selectors in :host and :host-context ([#12056](https://github.com/angular/angular/issues/12056)) ([6f7ed32](https://github.com/angular/angular/commit/6f7ed32)), closes [#11917](https://github.com/angular/angular/issues/11917)
|
||||
* **compiler:** support `[@page](https://github.com/page)` and `[@document](https://github.com/document)` CSS rules ([#11878](https://github.com/angular/angular/issues/11878)) ([c99ef49](https://github.com/angular/angular/commit/c99ef49)), closes [#11860](https://github.com/angular/angular/issues/11860)
|
||||
* **compiler:** support `@page` and `@document` CSS rules ([#11878](https://github.com/angular/angular/issues/11878)) ([c99ef49](https://github.com/angular/angular/commit/c99ef49)), closes [#11860](https://github.com/angular/angular/issues/11860)
|
||||
* **compiler:** support `[attr="value with space"]` ([bd012ef](https://github.com/angular/angular/commit/bd012ef)), closes [#6249](https://github.com/angular/angular/issues/6249)
|
||||
* **compiler:** support quoted attribute values ([7395400](https://github.com/angular/angular/commit/7395400)), closes [#6085](https://github.com/angular/angular/issues/6085)
|
||||
* **upgrade:** bind optional properties when upgrading from ng1 ([#11411](https://github.com/angular/angular/issues/11411)) ([0851238](https://github.com/angular/angular/commit/0851238)), closes [#10181](https://github.com/angular/angular/issues/10181)
|
||||
* **http:** change a behavior when a param value is null or undefined ([#11990](https://github.com/angular/angular/issues/11990)) ([9cc0a4e](https://github.com/angular/angular/commit/9cc0a4e))
|
||||
* **compiler:** fix `<x>` ctype names ([7578d85](https://github.com/angular/angular/commit/7578d85)), closes [#12000](https://github.com/angular/angular/issues/12000)
|
||||
* **compiler-cli:** allow ReflectorHost passed as argument to CodeGenerator#create ([#11951](https://github.com/angular/angular/issues/11951)) ([826c98e](https://github.com/angular/angular/commit/826c98e))
|
||||
* **forms:** properly validate empty strings with patterns ([#11450](https://github.com/angular/angular/issues/11450)) ([e00de0c](https://github.com/angular/angular/commit/e00de0c))
|
||||
* **http:** preserve case of the first init, `set()` or `append()` ([#12023](https://github.com/angular/angular/issues/12023)) ([adb17fe](https://github.com/angular/angular/commit/adb17fe)), closes [#11624](https://github.com/angular/angular/issues/11624)
|
||||
* **http:** remove url params if provided value is null or undefined ([#11990](https://github.com/angular/angular/issues/11990)) ([9cc0a4e](https://github.com/angular/angular/commit/9cc0a4e))
|
||||
* **router:** do not reset the router state when updating the component ([#11867](https://github.com/angular/angular/issues/11867)) ([cf750e1](https://github.com/angular/angular/commit/cf750e1))
|
||||
* **upgrade:** bind optional properties when upgrading from ng1 ([#11411](https://github.com/angular/angular/issues/11411)) ([0851238](https://github.com/angular/angular/commit/0851238)), closes [#10181](https://github.com/angular/angular/issues/10181)
|
||||
|
||||
|
||||
<a name="2.0.1"></a>
|
||||
@ -41,7 +131,7 @@
|
||||
|
||||
|
||||
<a name="2.0.0"></a>
|
||||
# [2.0.0](https://github.com/angular/angular/compare/2.0.0-rc.7...2.0.0) (2016-09-14)
|
||||
# [2.0.0 proprioception-reinforcement](https://github.com/angular/angular/compare/2.0.0-rc.7...2.0.0) (2016-09-14)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
@ -254,7 +344,7 @@
|
||||
use `Type<any>` in place of `Type`.
|
||||
|
||||
We don't expect that any user applications use the `Type` type directly.
|
||||
|
||||
|
||||
* core: Previously inconsistently named APIs SanitizationService and DomSanitizationService were renamed to Sanitizer and DomSanitizer
|
||||
|
||||
* core: previously deprecated @Component.directives and @Component.pipes support was removed.
|
||||
@ -268,11 +358,11 @@ use `Type<any>` in place of `Type`.
|
||||
* core: deprecated ComponentResolver was removed. Please use ComponentFactoryResolver instead.
|
||||
|
||||
* core: animations defined using an at-symbol prefix that are not property bound are now invalid.
|
||||
|
||||
|
||||
```html
|
||||
<!-- this is now invalid -->
|
||||
<div @flip="flipState"></div>
|
||||
|
||||
|
||||
<!-- change that to -->
|
||||
<div [@flip]="flipState"></div>
|
||||
```
|
||||
@ -298,7 +388,7 @@ prefix using `animate-` must now be preixed using `bind-animate-`.
|
||||
```
|
||||
{provide: MyClass, useFactory: ...}
|
||||
```
|
||||
|
||||
|
||||
* core: previously deprecated NgZoneError has been removed
|
||||
|
||||
* core: Exceptions are no longer part of the public API. We don't expect that anyone should be referring to the Exception types.
|
||||
@ -310,7 +400,7 @@ prefix using `animate-` must now be preixed using `bind-animate-`.
|
||||
```
|
||||
ErrorHandler.handleError(error: any): void;
|
||||
```
|
||||
|
||||
|
||||
* core: deprecated DynamicComponentLoader was removed; see deprecation notice for migration instructions.
|
||||
|
||||
* core: deprecated SystemJsComponentResolver and SystemJsCmpFactoryResolver have been removed.
|
||||
@ -344,13 +434,13 @@ prefix using `animate-` must now be preixed using `bind-animate-`.
|
||||
* platform-browser-dynamic: `CACHED_TEMPLATE_PROVIDER` is now renamed to `RESOURCE_CACHE_PROVIDER`
|
||||
|
||||
Before:
|
||||
|
||||
|
||||
```js
|
||||
import {CACHED_TEMPLATE_PROVIDER} from '@angular/platform-browser-dynamic';
|
||||
```
|
||||
|
||||
|
||||
After:
|
||||
|
||||
|
||||
```js
|
||||
import {RESOURCE_CACHE_PROVIDER} from '@angular/platform-browser-dynamic';
|
||||
```
|
||||
@ -368,7 +458,7 @@ prefix using `animate-` must now be preixed using `bind-animate-`.
|
||||
* webworkers: web worker platform is now exported via separate packages.
|
||||
|
||||
Please use @angular/platform-webworker and @angular/platform-webworker-dynamic
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="2.0.0-rc.5"></a>
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Contributing to Angular 2
|
||||
# Contributing to Angular
|
||||
|
||||
We would love for you to contribute to Angular 2 and help make it even better than it is
|
||||
We would love for you to contribute to Angular and help make it even better than it is
|
||||
today! As a contributor, here are the guidelines we would like you to follow:
|
||||
|
||||
- [Code of Conduct](#coc)
|
||||
@ -17,17 +17,26 @@ Help us keep Angular open and inclusive. Please read and follow our [Code of Con
|
||||
|
||||
## <a name="question"></a> Got a Question or Problem?
|
||||
|
||||
If you have questions about how to *use* Angular, please direct them to the [Google Group][angular-group]
|
||||
discussion list or [StackOverflow][stackoverflow]. Please note that the Angular team's capacity to answer usage questions is limited. We are also available on [Gitter][gitter].
|
||||
Please, do not open issues for the general support questions as we want to keep GitHub issues for bug reports and feature requests. You've got much better chances of getting your question answered on [StackOverflow](stackoverflow.com/questions/tagged/angular) where the questions should be tagged with tag `angular`.
|
||||
|
||||
## <a name="issue"></a> Found an Issue?
|
||||
StackOverflow is a much better place to ask questions since:
|
||||
|
||||
- there are thousands of people willing to help on StackOverflow
|
||||
- questions and answers stay available for public viewing so your question / answer might help someone else
|
||||
- StackOverflow's voting system assures that the best answers are prominently visible.
|
||||
|
||||
To save your and our time we will be systematically closing all the issues that are requests for general support and redirecting people to StackOverflow.
|
||||
|
||||
If you would like to chat about the question in real-time, you can reach out via [our gitter channel][gitter].
|
||||
|
||||
## <a name="issue"></a> Found a Bug?
|
||||
If you find a bug in the source code, you can help us by
|
||||
[submitting an issue](#submit-issue) to our [GitHub Repository][github]. Even better, you can
|
||||
[submit a Pull Request](#submit-pr) with a fix.
|
||||
|
||||
## <a name="feature"></a> Want a Feature?
|
||||
You can *request* a new feature by [submitting an issue](#submit-issue) to our [GitHub
|
||||
Repository][github]. If you would like to *implement* a new feature, please submit an issue with
|
||||
## <a name="feature"></a> Missing a Feature?
|
||||
You can *request* a new feature by [submitting an issue](#submit-issue) to our GitHub
|
||||
Repository. If you would like to *implement* a new feature, please submit an issue with
|
||||
a proposal for your work first, to be sure that we can use it.
|
||||
Please consider what kind of change it is:
|
||||
|
||||
@ -39,24 +48,22 @@ and help you to craft the change so that it is successfully accepted into the pr
|
||||
## <a name="submit"></a> Submission Guidelines
|
||||
|
||||
### <a name="submit-issue"></a> Submitting an Issue
|
||||
Before you submit an issue, search the archive, maybe your question was already answered.
|
||||
|
||||
If your issue appears to be a bug, and hasn't been reported, open a new issue.
|
||||
Help us to maximize the effort we can spend fixing issues and adding new
|
||||
features, by not reporting duplicate issues. Providing the following information will increase the
|
||||
chances of your issue being dealt with quickly:
|
||||
Before you submit an issue, please search the issue tracker, maybe an issue for your problem already exists and the discussion might inform you of workarounds readily available.
|
||||
|
||||
* **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
|
||||
* **Angular Version** - what version of Angular is affected (e.g. 2.0.0-alpha.53)
|
||||
* **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
|
||||
* **Browsers and Operating System** - is this a problem with all browsers?
|
||||
* **Reproduce the Error** - provide a live example (using [Plunker][plunker],
|
||||
[JSFiddle][jsfiddle] or [Runnable][runnable]) or a unambiguous set of steps
|
||||
* **Related Issues** - has a similar issue been reported before?
|
||||
* **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
|
||||
causing the problem (line of code or commit)
|
||||
We want to fix all the issues as soon as possible, but before fixing a bug we need to reproduce and confirm it. In order to reproduce bugs we will systematically ask you to provide a minimal reproduction scenario using http://plnkr.co. Having a live, reproducible scenario gives us wealth of important information without going back & forth to you with additional questions like:
|
||||
|
||||
You can file new issues by providing the above information [here](https://github.com/angular/angular/issues/new).
|
||||
- version of Angular used
|
||||
- 3rd-party libraries and their versions
|
||||
- and most importantly - a use-case that fails
|
||||
|
||||
A minimal reproduce scenario using http://plnkr.co/ allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem. If plunker is not a suitable way to demostrate the problem (for example for issues related to our npm packaging), please create a standalone git repository demostrating the problem.
|
||||
|
||||
We will be insisting on a minimal reproduce scenario in order to save maintainers time and ultimately be able to fix more bugs. Interestingly, from our experience users often find coding problems themselves while preparing a minimal plunk. We understand that sometimes it might be hard to extract essentials bits of code from a larger code-base but we really need to isolate the problem before we can fix it.
|
||||
|
||||
Unfortunately we are not able to investigate / fix bugs without a minimal reproduction, so if we don't hear back from you we are going to close an issue that don't have enough info to be reproduced.
|
||||
|
||||
You can file new issues by filling out our [new issue form](https://github.com/angular/angular/issues/new).
|
||||
|
||||
|
||||
### <a name="submit-pr"></a> Submitting a Pull Request (PR)
|
||||
@ -94,7 +101,7 @@ Before you submit your Pull Request (PR) consider the following guidelines:
|
||||
* In GitHub, send a pull request to `angular:master`.
|
||||
* If we suggest changes then:
|
||||
* Make the required updates.
|
||||
* Re-run the Angular 2 test suites to ensure tests are still passing.
|
||||
* Re-run the Angular test suites to ensure tests are still passing.
|
||||
* Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
|
||||
|
||||
```shell
|
||||
|
62
SAVED_REPLIES.md
Normal file
62
SAVED_REPLIES.md
Normal file
@ -0,0 +1,62 @@
|
||||
# Saved Responses for Angular's Issue Tracker
|
||||
|
||||
The following are canned responses that the Angular team should use to close issues on our issue tracker that fall into the listed resolution categories.
|
||||
|
||||
Since GitHub currently doesn't allow us to have a repository-wide or organization-wide list of [saved replies](https://help.github.com/articles/working-with-saved-replies/), these replies need to be maintained by individual team members. Since the responses can be modified in the future, all responses are versioned to simplify the process of keeping the responses up to date.
|
||||
|
||||
|
||||
## Angular: Already Fixed (v1)
|
||||
```
|
||||
Thanks for reporting this issue. Luckily it has already been fixed in one of the recent releases. Please update to the most recent version to resolve the problem.
|
||||
|
||||
If after upgrade the problem still exists in your application please open a new issue and provide a plunker reproducing the problem and describing the difference between the expected and current behavior. You can use this plunker template: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5?p=catalogue
|
||||
```
|
||||
|
||||
## Angular: Don't Understand (v1)
|
||||
```
|
||||
I'm sorry but we don't understand the problem you are reporting.
|
||||
|
||||
If the problem still exists please open a new issue and provide a plunker reproducing the problem and describing the difference between the expected and current behavior. You can use this plunker template: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5?p=catalogue
|
||||
```
|
||||
|
||||
|
||||
## Angular: Duplicate (v1)
|
||||
```
|
||||
Thanks for reporting this issue. However this issue is a duplicate of an existing issue #<ISSUE_NUMBER>. Please subscribe to that issue for future updates.
|
||||
```
|
||||
|
||||
|
||||
## Angular: Insufficient Information Provided (v1)
|
||||
```
|
||||
Thanks for reporting this issue. However, you didn't provide sufficient information for us to understand and reproduce the problem. Please check out [our submission guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-submitting-an-issue) to understand why we can't act on issues that are lacking important information.
|
||||
|
||||
If the problem still persists, please file a new issue and ensure you provide all of the required information when filling out the issue template.
|
||||
```
|
||||
|
||||
## Angular: Issue Outside of Angular (v1)
|
||||
```
|
||||
I'm sorry but this issue is not caused by Angular. Please contact the author(s) of project <PROJECT NAME> or file issue on their issue tracker.
|
||||
```
|
||||
|
||||
|
||||
## Angular: Non-reproducible (v1)
|
||||
```
|
||||
I'm sorry but we can't reproduce the problem following the instructions you provided.
|
||||
|
||||
If the problem still exists please open a new issue following [our submission guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-submitting-an-issue).
|
||||
```
|
||||
|
||||
## Angular: Obsolete (v1)
|
||||
```
|
||||
Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular version.
|
||||
|
||||
If the problem still persists, please file a new issue and ensure you provide the version of Angular affected and include the steps to reproduce the problem when filling out the issue template.
|
||||
```
|
||||
|
||||
|
||||
## Angular: Support Request (v1)
|
||||
```
|
||||
Hello, we reviewed this issue and determined that it doesn't fall into the bug report or feature request category. This issue tracker is not suitable for support requests, please repost your issue on [StackOverflow](http://stackoverflow.com/) using tag `angular`.
|
||||
|
||||
If you are wondering why we don't resolve support issues via the issue tracker, please [check out this explanation](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-got-a-question-or-problem).
|
||||
```
|
@ -1,7 +1,7 @@
|
||||
# Triage Process and Github Labels for Angular 2
|
||||
|
||||
This document describes how the Angular team uses labels and milestones
|
||||
to triage issues on github. The basic idea of the new process is that
|
||||
to triage issues on github. The basic idea of the process is that
|
||||
caretaker only assigns a component and type (bug, feature) label. The
|
||||
owner of the component than is in full control of how the issues should
|
||||
be triaged further.
|
||||
@ -35,7 +35,7 @@ There are few components which are cross-cutting. They don't have
|
||||
a clear location in the source tree. We will treat them as a component
|
||||
even thought no specific source tree is associated with them.
|
||||
|
||||
* `comp: documentation`: `@naomiblack`
|
||||
* `comp: docs`: `@naomiblack`
|
||||
* `comp: packaging`: `@IgorMinar`
|
||||
* `comp: performance`: `@tbosch`
|
||||
* `comp: security`: `@IgorMinar`
|
||||
@ -53,11 +53,11 @@ What kind of problem is this?
|
||||
|
||||
## Caretaker Triage Process
|
||||
|
||||
It is the caretaker's responsibility to assign `comp: *` and `type: *`
|
||||
to each new issue as they come in. The reason why we limit the
|
||||
responsibility of the caretaker to these two labels is that it is
|
||||
unlikely that without domain knowledge the caretaker could add any
|
||||
additional labels of value.
|
||||
It is the caretaker's responsibility to assign `comp: *` to each new
|
||||
issue as they come in. The reason why we limit the responsibility of the
|
||||
caretaker to this one label is that it is likely that without domain
|
||||
knowledge the caretaker could mislabel issues or lack knowledge of
|
||||
duplicate issues.
|
||||
|
||||
|
||||
## Component's owner Triage Process
|
||||
@ -68,11 +68,37 @@ process for their component.
|
||||
It will be up to the component owner to determine the order in which the
|
||||
issues within the component will be resolved.
|
||||
|
||||
Several owners have adopted the issue categorization based on
|
||||
[user pain](http://www.lostgarden.com/2008/05/improving-bug-triage-with-user-pain.html)
|
||||
used by Angular 1. In this system every issue is assigned frequency and
|
||||
severity based on which the total user pain score is calculated.
|
||||
|
||||
Following is the definition of various frequency and severity levels:
|
||||
|
||||
1. `freq(score): *` – How often does this issue come up? How many developers does this affect?
|
||||
* low (1) - obscure issue affecting a handful of developers
|
||||
* moderate (2) - impacts auxiliary usage patterns, only small number of applications are affected
|
||||
* high (3) - impacts primary usage patterns, affecting most Angular apps
|
||||
* critical (4) - impacts all Angular apps
|
||||
1. `severity(score): *` - How bad is the issue?
|
||||
* inconvenience (1) - causes ugly/boilerplate code in apps
|
||||
* confusing (2) - unexpected or inconsistent behavior; hard-to-debug
|
||||
* broken expected use (3) - it's hard or impossible for a developer using Angular to accomplish something that Angular should be able to do
|
||||
* memory leak (4)
|
||||
* regression (5) - functionality that used to work no longer works in a new release due to an unintentional change
|
||||
* security issue (6)
|
||||
|
||||
|
||||
These criteria are then used to calculate a "user pain" score as follows:
|
||||
|
||||
`pain = severity × frequency`
|
||||
|
||||
|
||||
### Assigning Issues to Milestones
|
||||
|
||||
Any issue that is being worked on must have:
|
||||
|
||||
* An `assignee`: The person doing the work.
|
||||
* An `Assignee`: The person doing the work.
|
||||
* A `Milestone`: When we expect to complete this work.
|
||||
|
||||
We aim to only have at most three milestones open at a time:
|
||||
|
40
docs/PUBLIC_API.md
Normal file
40
docs/PUBLIC_API.md
Normal file
@ -0,0 +1,40 @@
|
||||
# Supported Public API Surface of Angular
|
||||
|
||||
Our SemVer, timed-release cycle and deprecation policy currently applies to these npm packages:
|
||||
|
||||
- `@angular/core`
|
||||
- `@angular/common`
|
||||
- `@angular/platform-browser`
|
||||
- `@angular/platform-browser-dynamic`
|
||||
- `@angular/platform-server`
|
||||
- `@angular/platform-webworker`
|
||||
- `@angular/platform-webworker-dynamic`
|
||||
- `@angular/upgrade`
|
||||
- `@angular/router`
|
||||
- `@angular/forms`
|
||||
- `@angular/http`
|
||||
|
||||
|
||||
One intentional omission from this list is `@angular/compiler`, which is currently considered a low level api and is subject to internal changes. These changes will not affect any applications or libraries using the higher-level apis (the command line interface or JIT compilation via `@angular/platform-browser-dynamic`). Only very specific use-cases require direct access to the compiler API (mostly tooling integration for IDEs, linters, etc). If you are working on this kind of integration, please reach out to us first.
|
||||
|
||||
Additionally only the command line usage (not direct use of APIs) of `@angular/compiler-cli` is covered.
|
||||
|
||||
Other projects developed by the Angular team like angular-cli, Angular Material, benchpress, will be covered by these or similar guarantees in the future as they mature.
|
||||
|
||||
Within the supported packages, we provide guarantees for:
|
||||
|
||||
- symbols exported via the main entry point (e.g. `@angular/core`) and testing entry point (e.g. `@angular/core/testing`). This applies to both runtime/JavaScript values and TypeScript types.
|
||||
- symbols exported via global namespace `ng` (e.g. `ng.core`)
|
||||
- bundles located in the `bundles/` directory of our npm packages (e.g. `@angular/core/bundles/core.umd.js`)
|
||||
|
||||
|
||||
We explicitly don't consider the following to be our public API surface:
|
||||
|
||||
- any file/import paths within our package except for the `/`, `/testing` and `/bundles/*`
|
||||
- constructors of injectable classes (services and directives) - please use DI to obtain instances of these classes
|
||||
- any class members or symbols marked as `private` or prefixed with underscore
|
||||
- extending any of our classes unless the support for this is specifically documented in the API docs
|
||||
- the contents and API surface of the code generated by Angular's compiler (with one notable exception: the existence and name of `NgModuleFactory` instances exported from generated code is guaranteed)
|
||||
|
||||
|
||||
Our peer dependencies (e.g. typescript, zone.js, or rxjs) are not considered part of our API surface, but they are included in our SemVer policies. We might update the required version of any of these dependencies in minor releases if the update doesn't cause breaking changes for Angular applications. Peer dependency updates that result in non-trivial breaking changes must be deferred to major Angular releases.
|
@ -5,7 +5,7 @@ See [here for an example project](https://github.com/angular/benchpress-tree).
|
||||
|
||||
The sources for this package are in the main [Angular2](https://github.com/angular/angular) repo. Please file issues and pull requests against that repo.
|
||||
|
||||
License: Apache MIT 2.0
|
||||
License: MIT
|
||||
|
||||
# Why?
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
import {Inject, Injectable} from '@angular/core';
|
||||
|
||||
import {Options} from '../common_options';
|
||||
import {isNumber} from '../facade/lang';
|
||||
import {Metric} from '../metric';
|
||||
import {WebDriverAdapter} from '../web_driver_adapter';
|
||||
|
||||
@ -44,7 +43,7 @@ export class UserMetric extends Metric {
|
||||
function getAndClearValues() {
|
||||
Promise.all(names.map(name => adapter.executeScript(`return window.${name}`)))
|
||||
.then((values: any[]) => {
|
||||
if (values.every(isNumber)) {
|
||||
if (values.every(v => typeof v === 'number')) {
|
||||
Promise.all(names.map(name => adapter.executeScript(`delete window.${name}`)))
|
||||
.then((_: any[]) => {
|
||||
let map: {[k: string]: any} = {};
|
||||
|
@ -9,7 +9,6 @@
|
||||
import {Inject, Injectable, OpaqueToken} from '@angular/core';
|
||||
|
||||
import {Options} from '../common_options';
|
||||
import {Json} from '../facade/lang';
|
||||
import {MeasureValues} from '../measure_values';
|
||||
import {Reporter} from '../reporter';
|
||||
import {SampleDescription} from '../sample_description';
|
||||
@ -39,12 +38,14 @@ export class JsonFileReporter extends Reporter {
|
||||
sortedProps(this._description.metrics).forEach((metricName) => {
|
||||
stats[metricName] = formatStats(validSample, metricName);
|
||||
});
|
||||
var content = Json.stringify({
|
||||
'description': this._description,
|
||||
'stats': stats,
|
||||
'completeSample': completeSample,
|
||||
'validSample': validSample,
|
||||
});
|
||||
var content = JSON.stringify(
|
||||
{
|
||||
'description': this._description,
|
||||
'stats': stats,
|
||||
'completeSample': completeSample,
|
||||
'validSample': validSample,
|
||||
},
|
||||
null, 2);
|
||||
var filePath = `${this._path}/${this._description.id}_${this._now().getTime()}.json`;
|
||||
return this._writeFile(filePath, content);
|
||||
}
|
||||
|
@ -6,20 +6,15 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
|
||||
import {NumberWrapper} from '../facade/lang';
|
||||
import {MeasureValues} from '../measure_values';
|
||||
import {Statistic} from '../statistic';
|
||||
|
||||
export function formatNum(n: number) {
|
||||
return NumberWrapper.toFixed(n, 2);
|
||||
return n.toFixed(2);
|
||||
}
|
||||
|
||||
export function sortedProps(obj: {[key: string]: any}) {
|
||||
var props: string[] = [];
|
||||
props.push(...Object.keys(obj));
|
||||
props.sort();
|
||||
return props;
|
||||
return Object.keys(obj).sort();
|
||||
}
|
||||
|
||||
export function formatStats(validSamples: MeasureValues[], metricName: string): string {
|
||||
@ -29,5 +24,5 @@ export function formatStats(validSamples: MeasureValues[], metricName: string):
|
||||
var formattedMean = formatNum(mean);
|
||||
// Note: Don't use the unicode character for +- as it might cause
|
||||
// hickups for consoles...
|
||||
return NumberWrapper.isNaN(cv) ? formattedMean : `${formattedMean}+-${Math.floor(cv)}%`;
|
||||
return isNaN(cv) ? formattedMean : `${formattedMean}+-${Math.floor(cv)}%`;
|
||||
}
|
||||
|
@ -6,8 +6,6 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Math} from './facade/math';
|
||||
|
||||
export class Statistic {
|
||||
static calculateCoefficientOfVariation(sample: number[], mean: number) {
|
||||
return Statistic.calculateStandardDeviation(sample, mean) / mean * 100;
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
import {StringWrapper, isPresent} from '../facade/lang';
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {WebDriverAdapter} from '../web_driver_adapter';
|
||||
import {PerfLogEvent, PerfLogFeatures, WebDriverExtension} from '../web_driver_extension';
|
||||
|
||||
@ -48,6 +48,6 @@ export class FirefoxDriverExtension extends WebDriverExtension {
|
||||
perfLogFeatures(): PerfLogFeatures { return new PerfLogFeatures({render: true, gc: true}); }
|
||||
|
||||
supports(capabilities: {[key: string]: any}): boolean {
|
||||
return StringWrapper.equals(capabilities['browserName'].toLowerCase(), 'firefox');
|
||||
return capabilities['browserName'].toLowerCase() === 'firefox';
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
import {StringWrapper, isBlank, isPresent} from '../facade/lang';
|
||||
import {isBlank, isPresent} from '../facade/lang';
|
||||
import {WebDriverAdapter} from '../web_driver_adapter';
|
||||
import {PerfLogEvent, PerfLogFeatures, WebDriverExtension} from '../web_driver_extension';
|
||||
|
||||
@ -42,7 +42,7 @@ export class IOsDriverExtension extends WebDriverExtension {
|
||||
var records: any[] = [];
|
||||
entries.forEach(entry => {
|
||||
var message = JSON.parse(entry['message'])['message'];
|
||||
if (StringWrapper.equals(message['method'], 'Timeline.eventRecorded')) {
|
||||
if (message['method'] === 'Timeline.eventRecorded') {
|
||||
records.push(message['params']['record']);
|
||||
}
|
||||
});
|
||||
@ -62,19 +62,16 @@ export class IOsDriverExtension extends WebDriverExtension {
|
||||
var startTime = record['startTime'];
|
||||
var endTime = record['endTime'];
|
||||
|
||||
if (StringWrapper.equals(type, 'FunctionCall') &&
|
||||
(isBlank(data) || !StringWrapper.equals(data['scriptName'], 'InjectedScript'))) {
|
||||
if (type === 'FunctionCall' && (isBlank(data) || data['scriptName'] !== 'InjectedScript')) {
|
||||
events.push(createStartEvent('script', startTime));
|
||||
endEvent = createEndEvent('script', endTime);
|
||||
} else if (StringWrapper.equals(type, 'Time')) {
|
||||
} else if (type === 'Time') {
|
||||
events.push(createMarkStartEvent(data['message'], startTime));
|
||||
} else if (StringWrapper.equals(type, 'TimeEnd')) {
|
||||
} else if (type === 'TimeEnd') {
|
||||
events.push(createMarkEndEvent(data['message'], startTime));
|
||||
} else if (
|
||||
StringWrapper.equals(type, 'RecalculateStyles') || StringWrapper.equals(type, 'Layout') ||
|
||||
StringWrapper.equals(type, 'UpdateLayerTree') || StringWrapper.equals(type, 'Paint') ||
|
||||
StringWrapper.equals(type, 'Rasterize') ||
|
||||
StringWrapper.equals(type, 'CompositeLayers')) {
|
||||
type === 'RecalculateStyles' || type === 'Layout' || type === 'UpdateLayerTree' ||
|
||||
type === 'Paint' || type === 'Rasterize' || type === 'CompositeLayers') {
|
||||
events.push(createStartEvent('render', startTime));
|
||||
endEvent = createEndEvent('render', endTime);
|
||||
}
|
||||
@ -92,7 +89,7 @@ export class IOsDriverExtension extends WebDriverExtension {
|
||||
perfLogFeatures(): PerfLogFeatures { return new PerfLogFeatures({render: true}); }
|
||||
|
||||
supports(capabilities: {[key: string]: any}): boolean {
|
||||
return StringWrapper.equals(capabilities['browserName'].toLowerCase(), 'safari');
|
||||
return capabilities['browserName'].toLowerCase() === 'safari';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {JsonFileReporter, MeasureValues, Options, ReflectiveInjector, SampleDescription} from '../../index';
|
||||
import {Json, isPresent} from '../../src/facade/lang';
|
||||
import {isPresent} from '../../src/facade/lang';
|
||||
|
||||
export function main() {
|
||||
describe('file reporter', () => {
|
||||
@ -51,7 +51,7 @@ export function main() {
|
||||
[mv(0, 0, {'a': 3, 'b': 6}), mv(1, 1, {'a': 5, 'b': 9})]);
|
||||
var regExp = /somePath\/someId_\d+\.json/;
|
||||
expect(isPresent(loggedFile['filename'].match(regExp))).toBe(true);
|
||||
var parsedContent = Json.parse(loggedFile['content']);
|
||||
var parsedContent = JSON.parse(loggedFile['content']);
|
||||
expect(parsedContent).toEqual({
|
||||
'description': {
|
||||
'id': 'someId',
|
||||
|
@ -212,7 +212,7 @@ function createCountingValidator(
|
||||
return new MockValidator(log, (completeSample: MeasureValues[]) => {
|
||||
count--;
|
||||
if (count === 0) {
|
||||
return isPresent(validSample) ? validSample : completeSample;
|
||||
return validSample || completeSample;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {Options, ReflectiveInjector, WebDriverExtension} from '../index';
|
||||
import {StringWrapper, isPresent} from '../src/facade/lang';
|
||||
import {isPresent} from '../src/facade/lang';
|
||||
|
||||
export function main() {
|
||||
function createExtension(ids: any[], caps: any) {
|
||||
@ -52,6 +52,6 @@ class MockExtension extends WebDriverExtension {
|
||||
constructor(public id: string) { super(); }
|
||||
|
||||
supports(capabilities: {[key: string]: any}): boolean {
|
||||
return StringWrapper.equals(capabilities['browser'], this.id);
|
||||
return capabilities['browser'] === this.id;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {ChromeDriverExtension, Options, ReflectiveInjector, WebDriverAdapter, WebDriverExtension} from '../../index';
|
||||
import {Json, isBlank} from '../../src/facade/lang';
|
||||
import {isBlank} from '../../src/facade/lang';
|
||||
import {TraceEventFactory} from '../trace_event_factory';
|
||||
|
||||
export function main() {
|
||||
@ -398,8 +398,8 @@ class MockDriverAdapter extends WebDriverAdapter {
|
||||
if (type === 'performance') {
|
||||
return Promise.resolve(this._events.map(
|
||||
(event) => ({
|
||||
'message':
|
||||
Json.stringify({'message': {'method': this._messageMethod, 'params': event}})
|
||||
'message': JSON.stringify(
|
||||
{'message': {'method': this._messageMethod, 'params': event}}, null, 2)
|
||||
})));
|
||||
} else {
|
||||
return null;
|
||||
|
@ -9,7 +9,6 @@
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {IOsDriverExtension, ReflectiveInjector, WebDriverAdapter, WebDriverExtension} from '../../index';
|
||||
import {Json} from '../../src/facade/lang';
|
||||
import {TraceEventFactory} from '../trace_event_factory';
|
||||
|
||||
export function main() {
|
||||
@ -184,8 +183,9 @@ class MockDriverAdapter extends WebDriverAdapter {
|
||||
if (type === 'performance') {
|
||||
return Promise.resolve(this._perfRecords.map(function(record) {
|
||||
return {
|
||||
'message': Json.stringify(
|
||||
{'message': {'method': 'Timeline.eventRecorded', 'params': {'record': record}}})
|
||||
'message': JSON.stringify(
|
||||
{'message': {'method': 'Timeline.eventRecorded', 'params': {'record': record}}}, null,
|
||||
2)
|
||||
};
|
||||
}));
|
||||
} else {
|
||||
|
@ -11,14 +11,14 @@ import {Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core';
|
||||
/**
|
||||
* Removes or recreates a portion of the DOM tree based on an {expression}.
|
||||
*
|
||||
* If the expression assigned to `ngIf` evaluates to a false value then the element
|
||||
* If the expression assigned to `ngIf` evaluates to a falsy value then the element
|
||||
* is removed from the DOM, otherwise a clone of the element is reinserted into the DOM.
|
||||
*
|
||||
* ### Example ([live demo](http://plnkr.co/edit/fe0kgemFBtmQOY31b4tw?p=preview)):
|
||||
*
|
||||
* ```
|
||||
* <div *ngIf="errorCount > 0" class="error">
|
||||
* <!-- Error message displayed when the errorCount property on the current context is greater
|
||||
* <!-- Error message displayed when the errorCount property in the current context is greater
|
||||
* than 0. -->
|
||||
* {{errorCount}} errors detected
|
||||
* </div>
|
||||
@ -34,7 +34,7 @@ import {Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core';
|
||||
*/
|
||||
@Directive({selector: '[ngIf]'})
|
||||
export class NgIf {
|
||||
private _hasView: boolean = false;
|
||||
private _hasView = false;
|
||||
|
||||
constructor(private _viewContainer: ViewContainerRef, private _template: TemplateRef<Object>) {}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import {Directive, Host, Input, TemplateRef, ViewContainerRef} from '@angular/co
|
||||
|
||||
import {ListWrapper} from '../facade/collection';
|
||||
|
||||
const _CASE_DEFAULT = new Object();
|
||||
const _CASE_DEFAULT = {};
|
||||
|
||||
export class SwitchView {
|
||||
constructor(
|
||||
@ -38,7 +38,7 @@ export class SwitchView {
|
||||
* <inner-element></inner-element>
|
||||
* <inner-other-element></inner-other-element>
|
||||
* </ng-container>
|
||||
* <some-element *ngSwitchDefault>...</p>
|
||||
* <some-element *ngSwitchDefault>...</some-element>
|
||||
* </container-element>
|
||||
* ```
|
||||
* @description
|
||||
@ -53,8 +53,7 @@ export class SwitchView {
|
||||
* root elements.
|
||||
*
|
||||
* Elements within `NgSwitch` but outside of a `NgSwitchCase` or `NgSwitchDefault` directives will
|
||||
* be
|
||||
* preserved at the location.
|
||||
* be preserved at the location.
|
||||
*
|
||||
* The `ngSwitchCase` directive informs the parent `NgSwitch` of which view to display when the
|
||||
* expression is evaluated.
|
||||
@ -72,18 +71,23 @@ export class NgSwitch {
|
||||
|
||||
@Input()
|
||||
set ngSwitch(value: any) {
|
||||
// Empty the currently active ViewContainers
|
||||
this._emptyAllActiveViews();
|
||||
|
||||
// Add the ViewContainers matching the value (with a fallback to default)
|
||||
this._useDefault = false;
|
||||
// Set of views to display for this value
|
||||
let views = this._valueViews.get(value);
|
||||
if (!views) {
|
||||
this._useDefault = true;
|
||||
views = this._valueViews.get(_CASE_DEFAULT) || null;
|
||||
}
|
||||
this._activateViews(views);
|
||||
|
||||
if (views) {
|
||||
this._useDefault = false;
|
||||
} else {
|
||||
// No view to display for the current value -> default case
|
||||
// Nothing to do if the default case was already active
|
||||
if (this._useDefault) {
|
||||
return;
|
||||
}
|
||||
this._useDefault = true;
|
||||
views = this._valueViews.get(_CASE_DEFAULT);
|
||||
}
|
||||
|
||||
this._emptyAllActiveViews();
|
||||
this._activateViews(views);
|
||||
this._switchValue = value;
|
||||
}
|
||||
|
||||
@ -119,7 +123,7 @@ export class NgSwitch {
|
||||
this._activeViews = [];
|
||||
}
|
||||
|
||||
private _activateViews(views: SwitchView[]): void {
|
||||
private _activateViews(views?: SwitchView[]): void {
|
||||
if (views) {
|
||||
for (var i = 0; i < views.length; i++) {
|
||||
views[i].create();
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {Pipe, PipeTransform} from '@angular/core';
|
||||
import {isBlank, isStringMap} from '../facade/lang';
|
||||
import {isBlank} from '../facade/lang';
|
||||
import {NgLocalization, getPluralCategory} from '../localization';
|
||||
import {InvalidPipeArgumentError} from './invalid_pipe_argument_error';
|
||||
|
||||
@ -37,7 +37,7 @@ export class I18nPluralPipe implements PipeTransform {
|
||||
transform(value: number, pluralMap: {[count: string]: string}): string {
|
||||
if (isBlank(value)) return '';
|
||||
|
||||
if (!isStringMap(pluralMap)) {
|
||||
if (typeof pluralMap !== 'object' || pluralMap === null) {
|
||||
throw new InvalidPipeArgumentError(I18nPluralPipe, pluralMap);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {Pipe, PipeTransform} from '@angular/core';
|
||||
import {isBlank, isStringMap} from '../facade/lang';
|
||||
import {isBlank} from '../facade/lang';
|
||||
import {InvalidPipeArgumentError} from './invalid_pipe_argument_error';
|
||||
|
||||
/**
|
||||
@ -31,10 +31,10 @@ export class I18nSelectPipe implements PipeTransform {
|
||||
transform(value: string, mapping: {[key: string]: string}): string {
|
||||
if (isBlank(value)) return '';
|
||||
|
||||
if (!isStringMap(mapping)) {
|
||||
if (typeof mapping !== 'object' || mapping === null) {
|
||||
throw new InvalidPipeArgumentError(I18nSelectPipe, mapping);
|
||||
}
|
||||
|
||||
return mapping.hasOwnProperty(value) ? mapping[value] : '';
|
||||
return mapping[value] || '';
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,6 @@
|
||||
|
||||
import {Pipe, PipeTransform} from '@angular/core';
|
||||
|
||||
import {Json} from '../facade/lang';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @ngModule CommonModule
|
||||
* @whatItDoes Converts value into JSON string.
|
||||
@ -27,5 +23,5 @@ import {Json} from '../facade/lang';
|
||||
*/
|
||||
@Pipe({name: 'json', pure: false})
|
||||
export class JsonPipe implements PipeTransform {
|
||||
transform(value: any): string { return Json.stringify(value); }
|
||||
transform(value: any): string { return JSON.stringify(value, null, 2); }
|
||||
}
|
||||
|
@ -50,25 +50,6 @@ export function main() {
|
||||
detectChangesAndExpectText('when b');
|
||||
}));
|
||||
|
||||
// TODO(robwormald): deprecate and remove
|
||||
it('should switch amongst when values using switchCase', async(() => {
|
||||
const template = '<div>' +
|
||||
'<ul [ngSwitch]="switchValue">' +
|
||||
'<template ngSwitchCase="a"><li>when a</li></template>' +
|
||||
'<template ngSwitchCase="b"><li>when b</li></template>' +
|
||||
'</ul></div>';
|
||||
|
||||
fixture = createTestComponent(template);
|
||||
|
||||
detectChangesAndExpectText('');
|
||||
|
||||
getComponent().switchValue = 'a';
|
||||
detectChangesAndExpectText('when a');
|
||||
|
||||
getComponent().switchValue = 'b';
|
||||
detectChangesAndExpectText('when b');
|
||||
}));
|
||||
|
||||
it('should switch amongst when values with fallback to default', async(() => {
|
||||
const template = '<div>' +
|
||||
'<ul [ngSwitch]="switchValue">' +
|
||||
@ -84,6 +65,9 @@ export function main() {
|
||||
|
||||
getComponent().switchValue = 'b';
|
||||
detectChangesAndExpectText('when default');
|
||||
|
||||
getComponent().switchValue = 'c';
|
||||
detectChangesAndExpectText('when default');
|
||||
}));
|
||||
|
||||
it('should support multiple whens with the same value', async(() => {
|
||||
|
@ -11,8 +11,6 @@ import {Component} from '@angular/core';
|
||||
import {TestBed, async} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {Json, StringWrapper} from '../../src/facade/lang';
|
||||
|
||||
export function main() {
|
||||
describe('JsonPipe', () => {
|
||||
var regNewLine = '\n';
|
||||
@ -20,7 +18,7 @@ export function main() {
|
||||
var inceptionObjString: string;
|
||||
var pipe: JsonPipe;
|
||||
|
||||
function normalize(obj: string): string { return StringWrapper.replace(obj, regNewLine, ''); }
|
||||
function normalize(obj: string): string { return obj.replace(regNewLine, ''); }
|
||||
|
||||
beforeEach(() => {
|
||||
inceptionObj = {dream: {dream: {dream: 'Limbo'}}};
|
||||
@ -48,7 +46,7 @@ export function main() {
|
||||
|
||||
it('should return JSON-formatted string similar to Json.stringify', () => {
|
||||
var dream1 = normalize(pipe.transform(inceptionObj));
|
||||
var dream2 = normalize(Json.stringify(inceptionObj));
|
||||
var dream2 = normalize(JSON.stringify(inceptionObj, null, 2));
|
||||
expect(dream1).toEqual(dream2);
|
||||
});
|
||||
});
|
||||
@ -74,7 +72,6 @@ export function main() {
|
||||
mutable.push(2);
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('[\n 1,\n 2\n]');
|
||||
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
@ -0,0 +1,6 @@
|
||||
# Overview
|
||||
|
||||
This folder will be filled with the benchmark sources
|
||||
so that we can do offline compilation for them.
|
||||
|
||||
|
@ -15,5 +15,15 @@
|
||||
"declaration": true,
|
||||
"lib": ["es6", "dom"],
|
||||
"baseUrl": "."
|
||||
}
|
||||
},
|
||||
|
||||
"files": [
|
||||
"src/module",
|
||||
"src/bootstrap",
|
||||
"test/all_spec",
|
||||
"benchmarks/src/tree/ng2/index_aot.ts",
|
||||
"benchmarks/src/tree/ng2_switch/index_aot.ts",
|
||||
"benchmarks/src/largetable/ng2/index_aot.ts",
|
||||
"benchmarks/src/largetable/ng2_switch/index_aot.ts"
|
||||
]
|
||||
}
|
||||
|
@ -11,13 +11,11 @@
|
||||
"dependencies": {
|
||||
"@angular/tsc-wrapped": "^0.3.0",
|
||||
"reflect-metadata": "^0.1.2",
|
||||
"parse5": "^2.2.1",
|
||||
"minimist": "^1.2.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^2.0.2",
|
||||
"@angular/compiler": "0.0.0-PLACEHOLDER",
|
||||
"@angular/platform-server": "0.0.0-PLACEHOLDER",
|
||||
"@angular/core": "0.0.0-PLACEHOLDER"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -11,17 +11,16 @@
|
||||
* Intended to be used in a build step.
|
||||
*/
|
||||
import * as compiler from '@angular/compiler';
|
||||
import {Component, NgModule, ViewEncapsulation} from '@angular/core';
|
||||
import {Directive, NgModule, ViewEncapsulation} from '@angular/core';
|
||||
import {AngularCompilerOptions, NgcCliOptions} from '@angular/tsc-wrapped';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {PathMappedReflectorHost} from './path_mapped_reflector_host';
|
||||
import {CompileMetadataResolver, DirectiveNormalizer, DomElementSchemaRegistry, HtmlParser, Lexer, NgModuleCompiler, Parser, StyleCompiler, TemplateParser, TypeScriptEmitter, ViewCompiler} from './private_import_compiler';
|
||||
import {Console} from './private_import_core';
|
||||
import {ReflectorHost, ReflectorHostContext} from './reflector_host';
|
||||
import {StaticAndDynamicReflectionCapabilities} from './static_reflection_capabilities';
|
||||
import {StaticReflector, StaticSymbol} from './static_reflector';
|
||||
import {StaticReflector, StaticReflectorHost, StaticSymbol} from './static_reflector';
|
||||
|
||||
const nodeFs = require('fs');
|
||||
|
||||
@ -36,15 +35,30 @@ const PREAMBLE = `/**
|
||||
|
||||
`;
|
||||
|
||||
export class CodeGenerator {
|
||||
export class CodeGeneratorModuleCollector {
|
||||
constructor(
|
||||
private options: AngularCompilerOptions, private program: ts.Program,
|
||||
public host: ts.CompilerHost, private staticReflector: StaticReflector,
|
||||
private compiler: compiler.OfflineCompiler, private reflectorHost: ReflectorHost) {}
|
||||
private staticReflector: StaticReflector, private reflectorHost: StaticReflectorHost,
|
||||
private program: ts.Program, private options: AngularCompilerOptions) {}
|
||||
|
||||
getModuleSymbols(program: ts.Program): {fileMetas: FileMetadata[], ngModules: StaticSymbol[]} {
|
||||
// Compare with false since the default should be true
|
||||
const skipFileNames = (this.options.generateCodeForLibraries === false) ?
|
||||
GENERATED_OR_DTS_FILES :
|
||||
GENERATED_FILES;
|
||||
let filePaths = this.program.getSourceFiles()
|
||||
.filter(sf => !skipFileNames.test(sf.fileName))
|
||||
.map(sf => this.reflectorHost.getCanonicalFileName(sf.fileName));
|
||||
const fileMetas = filePaths.map((filePath) => this.readFileMetadata(filePath));
|
||||
const ngModules = fileMetas.reduce((ngModules, fileMeta) => {
|
||||
ngModules.push(...fileMeta.ngModules);
|
||||
return ngModules;
|
||||
}, <StaticSymbol[]>[]);
|
||||
return {fileMetas, ngModules};
|
||||
}
|
||||
|
||||
private readFileMetadata(absSourcePath: string): FileMetadata {
|
||||
const moduleMetadata = this.staticReflector.getModuleMetadata(absSourcePath);
|
||||
const result: FileMetadata = {components: [], ngModules: [], fileUrl: absSourcePath};
|
||||
const result: FileMetadata = {directives: [], ngModules: [], fileUrl: absSourcePath};
|
||||
if (!moduleMetadata) {
|
||||
console.log(`WARNING: no metadata found for ${absSourcePath}`);
|
||||
return result;
|
||||
@ -64,13 +78,25 @@ export class CodeGenerator {
|
||||
annotations.forEach((annotation) => {
|
||||
if (annotation instanceof NgModule) {
|
||||
result.ngModules.push(staticType);
|
||||
} else if (annotation instanceof Component) {
|
||||
result.components.push(staticType);
|
||||
} else if (annotation instanceof Directive) {
|
||||
result.directives.push(staticType);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export class CodeGenerator {
|
||||
private moduleCollector: CodeGeneratorModuleCollector;
|
||||
|
||||
constructor(
|
||||
private options: AngularCompilerOptions, private program: ts.Program,
|
||||
public host: ts.CompilerHost, private staticReflector: StaticReflector,
|
||||
private compiler: compiler.OfflineCompiler, private reflectorHost: StaticReflectorHost) {
|
||||
this.moduleCollector =
|
||||
new CodeGeneratorModuleCollector(staticReflector, reflectorHost, program, options);
|
||||
}
|
||||
|
||||
// Write codegen in a directory structure matching the sources.
|
||||
private calculateEmitPath(filePath: string): string {
|
||||
@ -95,24 +121,13 @@ export class CodeGenerator {
|
||||
}
|
||||
|
||||
codegen(): Promise<any> {
|
||||
// Compare with false since the default should be true
|
||||
const skipFileNames = (this.options.generateCodeForLibraries === false) ?
|
||||
GENERATED_OR_DTS_FILES :
|
||||
GENERATED_FILES;
|
||||
let filePaths = this.program.getSourceFiles()
|
||||
.filter(sf => !skipFileNames.test(sf.fileName))
|
||||
.map(sf => this.reflectorHost.getCanonicalFileName(sf.fileName));
|
||||
const fileMetas = filePaths.map((filePath) => this.readFileMetadata(filePath));
|
||||
const ngModules = fileMetas.reduce((ngModules, fileMeta) => {
|
||||
ngModules.push(...fileMeta.ngModules);
|
||||
return ngModules;
|
||||
}, <StaticSymbol[]>[]);
|
||||
const {fileMetas, ngModules} = this.moduleCollector.getModuleSymbols(this.program);
|
||||
const analyzedNgModules = this.compiler.analyzeModules(ngModules);
|
||||
return Promise.all(fileMetas.map(
|
||||
(fileMeta) =>
|
||||
this.compiler
|
||||
.compile(
|
||||
fileMeta.fileUrl, analyzedNgModules, fileMeta.components, fileMeta.ngModules)
|
||||
fileMeta.fileUrl, analyzedNgModules, fileMeta.directives, fileMeta.ngModules)
|
||||
.then((generatedModules) => {
|
||||
generatedModules.forEach((generatedModule) => {
|
||||
const sourceFile = this.program.getSourceFile(fileMeta.fileUrl);
|
||||
@ -157,36 +172,38 @@ export class CodeGenerator {
|
||||
const staticReflector = new StaticReflector(reflectorHost);
|
||||
StaticAndDynamicReflectionCapabilities.install(staticReflector);
|
||||
const htmlParser =
|
||||
new compiler.I18NHtmlParser(new HtmlParser(), transContent, cliOptions.i18nFormat);
|
||||
new compiler.I18NHtmlParser(new compiler.HtmlParser(), transContent, cliOptions.i18nFormat);
|
||||
const config = new compiler.CompilerConfig({
|
||||
genDebugInfo: options.debug === true,
|
||||
defaultEncapsulation: ViewEncapsulation.Emulated,
|
||||
logBindingUpdate: false,
|
||||
useJit: false
|
||||
});
|
||||
const normalizer = new DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config);
|
||||
const expressionParser = new Parser(new Lexer());
|
||||
const elementSchemaRegistry = new DomElementSchemaRegistry();
|
||||
const normalizer =
|
||||
new compiler.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config);
|
||||
const expressionParser = new compiler.Parser(new compiler.Lexer());
|
||||
const elementSchemaRegistry = new compiler.DomElementSchemaRegistry();
|
||||
const console = new Console();
|
||||
const tmplParser =
|
||||
new TemplateParser(expressionParser, elementSchemaRegistry, htmlParser, console, []);
|
||||
const resolver = new CompileMetadataResolver(
|
||||
const tmplParser = new compiler.TemplateParser(
|
||||
expressionParser, elementSchemaRegistry, htmlParser, console, []);
|
||||
const resolver = new compiler.CompileMetadataResolver(
|
||||
new compiler.NgModuleResolver(staticReflector),
|
||||
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
|
||||
elementSchemaRegistry, staticReflector);
|
||||
// TODO(vicb): do not pass cliOptions.i18nFormat here
|
||||
const offlineCompiler = new compiler.OfflineCompiler(
|
||||
resolver, normalizer, tmplParser, new StyleCompiler(urlResolver), new ViewCompiler(config),
|
||||
new NgModuleCompiler(), new TypeScriptEmitter(reflectorHost), cliOptions.locale,
|
||||
cliOptions.i18nFormat);
|
||||
resolver, normalizer, tmplParser, new compiler.StyleCompiler(urlResolver),
|
||||
new compiler.ViewCompiler(config), new compiler.DirectiveWrapperCompiler(config),
|
||||
new compiler.NgModuleCompiler(), new compiler.TypeScriptEmitter(reflectorHost),
|
||||
cliOptions.locale, cliOptions.i18nFormat);
|
||||
|
||||
return new CodeGenerator(
|
||||
options, program, compilerHost, staticReflector, offlineCompiler, reflectorHost);
|
||||
}
|
||||
}
|
||||
|
||||
interface FileMetadata {
|
||||
export interface FileMetadata {
|
||||
fileUrl: string;
|
||||
components: StaticSymbol[];
|
||||
directives: StaticSymbol[];
|
||||
ngModules: StaticSymbol[];
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import {Component, NgModule, ViewEncapsulation} from '@angular/core';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
import * as tsc from '@angular/tsc-wrapped';
|
||||
import {CompileMetadataResolver, DirectiveNormalizer, DomElementSchemaRegistry, HtmlParser, Lexer, NgModuleCompiler, Parser, StyleCompiler, TemplateParser, TypeScriptEmitter, ViewCompiler, ParseError} from './private_import_compiler';
|
||||
import {Console} from './private_import_core';
|
||||
import {ReflectorHost, ReflectorHostContext} from './reflector_host';
|
||||
import {StaticAndDynamicReflectionCapabilities} from './static_reflection_capabilities';
|
||||
@ -30,7 +29,7 @@ import {StaticReflector, StaticSymbol} from './static_reflector';
|
||||
function extract(
|
||||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions,
|
||||
program: ts.Program, host: ts.CompilerHost) {
|
||||
const htmlParser = new compiler.I18NHtmlParser(new HtmlParser());
|
||||
const htmlParser = new compiler.I18NHtmlParser(new compiler.HtmlParser());
|
||||
const extractor = Extractor.create(ngOptions, cliOptions.i18nFormat, program, host, htmlParser);
|
||||
const bundlePromise: Promise<compiler.MessageBundle> = extractor.extract();
|
||||
|
||||
@ -63,9 +62,9 @@ export class Extractor {
|
||||
constructor(
|
||||
private program: ts.Program, public host: ts.CompilerHost,
|
||||
private staticReflector: StaticReflector, private messageBundle: compiler.MessageBundle,
|
||||
private reflectorHost: ReflectorHost, private metadataResolver: CompileMetadataResolver,
|
||||
private directiveNormalizer: DirectiveNormalizer,
|
||||
private compiler: compiler.OfflineCompiler) {}
|
||||
private reflectorHost: ReflectorHost,
|
||||
private metadataResolver: compiler.CompileMetadataResolver,
|
||||
private directiveNormalizer: compiler.DirectiveNormalizer) {}
|
||||
|
||||
private readFileMetadata(absSourcePath: string): FileMetadata {
|
||||
const moduleMetadata = this.staticReflector.getModuleMetadata(absSourcePath);
|
||||
@ -105,8 +104,8 @@ export class Extractor {
|
||||
ngModules.push(...fileMeta.ngModules);
|
||||
return ngModules;
|
||||
}, <StaticSymbol[]>[]);
|
||||
const analyzedNgModules = this.compiler.analyzeModules(ngModules);
|
||||
const errors: ParseError[] = [];
|
||||
const analyzedNgModules = compiler.analyzeModules(ngModules, this.metadataResolver);
|
||||
const errors: compiler.ParseError[] = [];
|
||||
|
||||
let bundlePromise =
|
||||
Promise
|
||||
@ -114,7 +113,7 @@ export class Extractor {
|
||||
const url = fileMeta.fileUrl;
|
||||
return Promise.all(fileMeta.components.map(compType => {
|
||||
const compMeta = this.metadataResolver.getDirectiveMetadata(<any>compType);
|
||||
const ngModule = analyzedNgModules.ngModuleByComponent.get(compType);
|
||||
const ngModule = analyzedNgModules.ngModuleByDirective.get(compType);
|
||||
if (!ngModule) {
|
||||
throw new Error(
|
||||
`Cannot determine the module for component ${compMeta.type.name}!`);
|
||||
@ -168,26 +167,19 @@ export class Extractor {
|
||||
useJit: false
|
||||
});
|
||||
|
||||
const normalizer = new DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config);
|
||||
const expressionParser = new Parser(new Lexer());
|
||||
const elementSchemaRegistry = new DomElementSchemaRegistry();
|
||||
const console = new Console();
|
||||
const tmplParser =
|
||||
new TemplateParser(expressionParser, elementSchemaRegistry, htmlParser, console, []);
|
||||
const resolver = new CompileMetadataResolver(
|
||||
const normalizer =
|
||||
new compiler.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config);
|
||||
const elementSchemaRegistry = new compiler.DomElementSchemaRegistry();
|
||||
const resolver = new compiler.CompileMetadataResolver(
|
||||
new compiler.NgModuleResolver(staticReflector),
|
||||
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
|
||||
elementSchemaRegistry, staticReflector);
|
||||
const offlineCompiler = new compiler.OfflineCompiler(
|
||||
resolver, normalizer, tmplParser, new StyleCompiler(urlResolver), new ViewCompiler(config),
|
||||
new NgModuleCompiler(), new TypeScriptEmitter(reflectorHost), null, null);
|
||||
|
||||
// TODO(vicb): implicit tags & attributes
|
||||
let messageBundle = new compiler.MessageBundle(htmlParser, [], {});
|
||||
|
||||
return new Extractor(
|
||||
program, compilerHost, staticReflector, messageBundle, reflectorHost, resolver, normalizer,
|
||||
offlineCompiler);
|
||||
program, compilerHost, staticReflector, messageBundle, reflectorHost, resolver, normalizer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
* @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 {__compiler_private__ as _} from '@angular/compiler';
|
||||
|
||||
export type AssetUrl = typeof _._AssetUrl;
|
||||
export var AssetUrl: typeof _.AssetUrl = _.AssetUrl;
|
||||
|
||||
export type ImportGenerator = typeof _._ImportGenerator;
|
||||
export var ImportGenerator: typeof _.ImportGenerator = _.ImportGenerator;
|
||||
|
||||
export type CompileMetadataResolver = typeof _._CompileMetadataResolver;
|
||||
export var CompileMetadataResolver: typeof _.CompileMetadataResolver = _.CompileMetadataResolver;
|
||||
|
||||
export type HtmlParser = typeof _._HtmlParser;
|
||||
export var HtmlParser: typeof _.HtmlParser = _.HtmlParser;
|
||||
|
||||
export type ParseError = typeof _._ParseError;
|
||||
export var ParseError: typeof _.ParseError = _.ParseError;
|
||||
|
||||
export type InterpolationConfig = typeof _._InterpolationConfig;
|
||||
export var InterpolationConfig: typeof _.InterpolationConfig = _.InterpolationConfig;
|
||||
|
||||
export type DirectiveNormalizer = typeof _._DirectiveNormalizer;
|
||||
export var DirectiveNormalizer: typeof _.DirectiveNormalizer = _.DirectiveNormalizer;
|
||||
|
||||
export type Lexer = typeof _._Lexer;
|
||||
export var Lexer: typeof _.Lexer = _.Lexer;
|
||||
|
||||
export type Parser = typeof _._Parser;
|
||||
export var Parser: typeof _.Parser = _.Parser;
|
||||
|
||||
export type TemplateParser = typeof _._TemplateParser;
|
||||
export var TemplateParser: typeof _.TemplateParser = _.TemplateParser;
|
||||
|
||||
export type DomElementSchemaRegistry = typeof _._DomElementSchemaRegistry;
|
||||
export var DomElementSchemaRegistry: typeof _.DomElementSchemaRegistry = _.DomElementSchemaRegistry;
|
||||
|
||||
export type StyleCompiler = typeof _._StyleCompiler;
|
||||
export var StyleCompiler: typeof _.StyleCompiler = _.StyleCompiler;
|
||||
|
||||
export type ViewCompiler = typeof _._ViewCompiler;
|
||||
export var ViewCompiler: typeof _.ViewCompiler = _.ViewCompiler;
|
||||
|
||||
export type NgModuleCompiler = typeof _._NgModuleCompiler;
|
||||
export var NgModuleCompiler: typeof _.NgModuleCompiler = _.NgModuleCompiler;
|
||||
|
||||
export type TypeScriptEmitter = typeof _._TypeScriptEmitter;
|
||||
export var TypeScriptEmitter: typeof _.TypeScriptEmitter = _.TypeScriptEmitter;
|
@ -6,12 +6,12 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AssetUrl, ImportGenerator} from '@angular/compiler';
|
||||
import {AngularCompilerOptions, MetadataCollector, ModuleMetadata} from '@angular/tsc-wrapped';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AssetUrl, ImportGenerator} from './private_import_compiler';
|
||||
import {StaticReflectorHost, StaticSymbol} from './static_reflector';
|
||||
|
||||
const EXT = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
|
||||
|
@ -20,11 +20,10 @@ export class StaticAndDynamicReflectionCapabilities {
|
||||
|
||||
isReflectionEnabled(): boolean { return true; }
|
||||
factory(type: any): Function { return this.dynamicDelegate.factory(type); }
|
||||
interfaces(type: any): any[] { return this.dynamicDelegate.interfaces(type); }
|
||||
hasLifecycleHook(type: any, lcInterface: /*Type*/ any, lcProperty: string): boolean {
|
||||
return isStaticType(type) ?
|
||||
this.staticDelegate.hasLifecycleHook(type, lcInterface, lcProperty) :
|
||||
this.dynamicDelegate.hasLifecycleHook(type, lcInterface, lcProperty);
|
||||
|
||||
hasLifecycleHook(type: any, lcProperty: string): boolean {
|
||||
return isStaticType(type) ? this.staticDelegate.hasLifecycleHook(type, lcProperty) :
|
||||
this.dynamicDelegate.hasLifecycleHook(type, lcProperty);
|
||||
}
|
||||
parameters(type: any): any[][] {
|
||||
return isStaticType(type) ? this.staticDelegate.parameters(type) :
|
||||
|
@ -44,6 +44,8 @@ export interface StaticReflectorHost {
|
||||
animationMetadata: string,
|
||||
provider: string
|
||||
};
|
||||
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,14 +159,15 @@ export class StaticReflector implements ReflectorReader {
|
||||
}
|
||||
}
|
||||
|
||||
hasLifecycleHook(type: any, lcInterface: /*Type*/ any, lcProperty: string): boolean {
|
||||
hasLifecycleHook(type: any, lcProperty: string): boolean {
|
||||
if (!(type instanceof StaticSymbol)) {
|
||||
throw new Error(
|
||||
`hasLifecycleHook received ${JSON.stringify(type)} which is not a StaticSymbol`);
|
||||
}
|
||||
let classMetadata = this.getTypeMetadata(type);
|
||||
let members = classMetadata ? classMetadata['members'] : null;
|
||||
let member: any[] = members ? members[lcProperty] : null;
|
||||
const classMetadata = this.getTypeMetadata(type);
|
||||
const members = classMetadata ? classMetadata['members'] : null;
|
||||
const member: any[] =
|
||||
members && members.hasOwnProperty(lcProperty) ? members[lcProperty] : null;
|
||||
return member ? member.some(a => a['__symbolic'] == 'method') : false;
|
||||
}
|
||||
|
||||
@ -366,6 +369,9 @@ export class StaticReflector implements ReflectorReader {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (expression instanceof StaticSymbol) {
|
||||
return expression;
|
||||
}
|
||||
if (expression) {
|
||||
if (expression['__symbolic']) {
|
||||
let staticSymbol: StaticSymbol;
|
||||
|
@ -119,6 +119,11 @@ describe('StaticReflector', () => {
|
||||
expect(simplify(noContext, 'some value')).toBe('some value');
|
||||
});
|
||||
|
||||
it('should simplify a static symbol into itself', () => {
|
||||
const staticSymbol = new StaticSymbol('', '');
|
||||
expect(simplify(noContext, staticSymbol)).toBe(staticSymbol);
|
||||
});
|
||||
|
||||
it('should simplify an array into a copy of the array', () => {
|
||||
expect(simplify(noContext, [1, 2, 3])).toEqual([1, 2, 3]);
|
||||
});
|
||||
@ -450,6 +455,9 @@ class MockReflectorHost implements StaticReflectorHost {
|
||||
provider: 'angular2/src/core/di/provider'
|
||||
};
|
||||
}
|
||||
|
||||
getCanonicalFileName(fileName: string): string { return fileName; }
|
||||
|
||||
getStaticSymbol(declarationFile: string, name: string, members?: string[]): StaticSymbol {
|
||||
var cacheKey = `${declarationFile}:${name}${members?'.'+members.join('.'):''}`;
|
||||
var result = this.staticTypeCache.get(cacheKey);
|
||||
|
@ -21,6 +21,37 @@
|
||||
* </p>
|
||||
* </div>
|
||||
*/
|
||||
export * from './src/index';
|
||||
export * from './src/template_parser/template_ast';
|
||||
export {TEMPLATE_TRANSFORMS} from './src/template_parser/template_parser';
|
||||
export {CompilerConfig, RenderTypes} from './src/config';
|
||||
export * from './src/compile_metadata';
|
||||
export * from './src/offline_compiler';
|
||||
export {RuntimeCompiler} from './src/runtime_compiler';
|
||||
export * from './src/url_resolver';
|
||||
export * from './src/resource_loader';
|
||||
export * from './src/compiler';
|
||||
export {DirectiveResolver} from './src/directive_resolver';
|
||||
export {PipeResolver} from './src/pipe_resolver';
|
||||
export {NgModuleResolver} from './src/ng_module_resolver';
|
||||
export {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from './src/ml_parser/interpolation_config';
|
||||
export {ElementSchemaRegistry} from './src/schema/element_schema_registry';
|
||||
export * from './src/i18n/index';
|
||||
export * from './src/template_parser/template_ast';
|
||||
export * from './src/directive_normalizer';
|
||||
export * from './src/expression_parser/lexer';
|
||||
export * from './src/expression_parser/parser';
|
||||
export * from './src/metadata_resolver';
|
||||
export * from './src/ml_parser/html_parser';
|
||||
export * from './src/ml_parser/interpolation_config';
|
||||
export {NgModuleCompiler} from './src/ng_module_compiler';
|
||||
export {DirectiveWrapperCompiler} from './src/directive_wrapper_compiler';
|
||||
export * from './src/output/path_util';
|
||||
export * from './src/output/ts_emitter';
|
||||
export * from './src/parse_util';
|
||||
export * from './src/schema/dom_element_schema_registry';
|
||||
export * from './src/selector';
|
||||
export * from './src/style_compiler';
|
||||
export * from './src/template_parser/template_parser';
|
||||
export {ViewCompiler} from './src/view_compiler/view_compiler';
|
||||
|
||||
// This file only reexports content of the `src` folder. Keep it that way.
|
||||
|
@ -32,6 +32,7 @@ export class AnimationCompiler {
|
||||
var _ANIMATION_FACTORY_ELEMENT_VAR = o.variable('element');
|
||||
var _ANIMATION_DEFAULT_STATE_VAR = o.variable('defaultStateStyles');
|
||||
var _ANIMATION_FACTORY_VIEW_VAR = o.variable('view');
|
||||
var _ANIMATION_FACTORY_VIEW_CONTEXT = _ANIMATION_FACTORY_VIEW_VAR.prop('animationContext');
|
||||
var _ANIMATION_FACTORY_RENDERER_VAR = _ANIMATION_FACTORY_VIEW_VAR.prop('renderer');
|
||||
var _ANIMATION_CURRENT_STATE_VAR = o.variable('currentState');
|
||||
var _ANIMATION_NEXT_STATE_VAR = o.variable('nextState');
|
||||
@ -61,7 +62,9 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
}
|
||||
|
||||
ast.styles.forEach(entry => {
|
||||
stylesArr.push(o.literalMap(Object.keys(entry).map(key => [key, o.literal(entry[key])])));
|
||||
const entries =
|
||||
Object.keys(entry).map((key): [string, o.Expression] => [key, o.literal(entry[key])]);
|
||||
stylesArr.push(o.literalMap(entries));
|
||||
});
|
||||
|
||||
return o.importExpr(resolveIdentifier(Identifiers.AnimationStyles)).instantiate([
|
||||
@ -184,7 +187,7 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
context.stateMap.registerState(DEFAULT_STATE, {});
|
||||
|
||||
var statements: o.Statement[] = [];
|
||||
statements.push(_ANIMATION_FACTORY_VIEW_VAR
|
||||
statements.push(_ANIMATION_FACTORY_VIEW_CONTEXT
|
||||
.callMethod(
|
||||
'cancelActiveAnimation',
|
||||
[
|
||||
@ -261,16 +264,21 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
.toStmt()])])
|
||||
.toStmt());
|
||||
|
||||
statements.push(_ANIMATION_FACTORY_VIEW_VAR
|
||||
statements.push(_ANIMATION_FACTORY_VIEW_CONTEXT
|
||||
.callMethod(
|
||||
'queueAnimation',
|
||||
[
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR, o.literal(this.animationName),
|
||||
_ANIMATION_PLAYER_VAR, _ANIMATION_TIME_VAR,
|
||||
_ANIMATION_CURRENT_STATE_VAR, _ANIMATION_NEXT_STATE_VAR
|
||||
_ANIMATION_PLAYER_VAR
|
||||
])
|
||||
.toStmt());
|
||||
|
||||
statements.push(new o.ReturnStatement(
|
||||
o.importExpr(resolveIdentifier(Identifiers.AnimationTransition)).instantiate([
|
||||
_ANIMATION_PLAYER_VAR, _ANIMATION_CURRENT_STATE_VAR, _ANIMATION_NEXT_STATE_VAR,
|
||||
_ANIMATION_TIME_VAR
|
||||
])));
|
||||
|
||||
return o.fn(
|
||||
[
|
||||
new o.FnParam(
|
||||
@ -280,7 +288,7 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
new o.FnParam(_ANIMATION_CURRENT_STATE_VAR.name, o.DYNAMIC_TYPE),
|
||||
new o.FnParam(_ANIMATION_NEXT_STATE_VAR.name, o.DYNAMIC_TYPE)
|
||||
],
|
||||
statements);
|
||||
statements, o.importType(resolveIdentifier(Identifiers.AnimationTransition)));
|
||||
}
|
||||
|
||||
build(ast: AnimationAst): AnimationEntryCompileResult {
|
||||
|
@ -8,8 +8,7 @@
|
||||
|
||||
import {CompileAnimationAnimateMetadata, CompileAnimationEntryMetadata, CompileAnimationGroupMetadata, CompileAnimationKeyframesSequenceMetadata, CompileAnimationMetadata, CompileAnimationSequenceMetadata, CompileAnimationStateDeclarationMetadata, CompileAnimationStateTransitionMetadata, CompileAnimationStyleMetadata, CompileAnimationWithStepsMetadata, CompileDirectiveMetadata} from '../compile_metadata';
|
||||
import {ListWrapper, StringMapWrapper} from '../facade/collection';
|
||||
import {isArray, isBlank, isPresent, isString, isStringMap} from '../facade/lang';
|
||||
import {Math} from '../facade/math';
|
||||
import {isBlank, isPresent} from '../facade/lang';
|
||||
import {ParseError} from '../parse_util';
|
||||
import {ANY_STATE, FILL_STYLE_FLAG} from '../private_import_core';
|
||||
|
||||
@ -97,7 +96,7 @@ function _parseAnimationDeclarationStates(
|
||||
var styleValues: Styles[] = [];
|
||||
stateMetadata.styles.styles.forEach(stylesEntry => {
|
||||
// TODO (matsko): change this when we get CSS class integration support
|
||||
if (isStringMap(stylesEntry)) {
|
||||
if (typeof stylesEntry === 'object' && stylesEntry !== null) {
|
||||
styleValues.push(stylesEntry as Styles);
|
||||
} else {
|
||||
errors.push(new AnimationParseError(
|
||||
@ -115,13 +114,10 @@ function _parseAnimationStateTransition(
|
||||
stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): AnimationStateTransitionAst {
|
||||
var styles = new StylesCollection();
|
||||
var transitionExprs: any[] /** TODO #9100 */ = [];
|
||||
var transitionExprs: AnimationStateTransitionExpression[] = [];
|
||||
var transitionStates = transitionStateMetadata.stateChangeExpr.split(/\s*,\s*/);
|
||||
transitionStates.forEach(expr => {
|
||||
_parseAnimationTransitionExpr(expr, errors).forEach(transExpr => {
|
||||
transitionExprs.push(transExpr);
|
||||
});
|
||||
});
|
||||
transitionStates.forEach(
|
||||
expr => { transitionExprs.push(..._parseAnimationTransitionExpr(expr, errors)); });
|
||||
var entry = _normalizeAnimationEntry(transitionStateMetadata.steps);
|
||||
var animation = _normalizeStyleSteps(entry, stateStyles, errors);
|
||||
var animationAst = _parseTransitionAnimation(animation, 0, styles, stateStyles, errors);
|
||||
@ -136,9 +132,25 @@ function _parseAnimationStateTransition(
|
||||
return new AnimationStateTransitionAst(transitionExprs, stepsAst);
|
||||
}
|
||||
|
||||
function _parseAnimationAlias(alias: string, errors: AnimationParseError[]): string {
|
||||
switch (alias) {
|
||||
case ':enter':
|
||||
return 'void => *';
|
||||
case ':leave':
|
||||
return '* => void';
|
||||
default:
|
||||
errors.push(
|
||||
new AnimationParseError(`the transition alias value "${alias}" is not supported`));
|
||||
return '* => *';
|
||||
}
|
||||
}
|
||||
|
||||
function _parseAnimationTransitionExpr(
|
||||
eventStr: string, errors: AnimationParseError[]): AnimationStateTransitionExpression[] {
|
||||
var expressions: any[] /** TODO #9100 */ = [];
|
||||
var expressions: AnimationStateTransitionExpression[] = [];
|
||||
if (eventStr[0] == ':') {
|
||||
eventStr = _parseAnimationAlias(eventStr, errors);
|
||||
}
|
||||
var match = eventStr.match(/^(\*|[-\w]+)\s*(<?[=-]>)\s*(\*|[-\w]+)$/);
|
||||
if (!isPresent(match) || match.length < 4) {
|
||||
errors.push(new AnimationParseError(`the provided ${eventStr} is not of a supported format`));
|
||||
@ -159,16 +171,15 @@ function _parseAnimationTransitionExpr(
|
||||
|
||||
function _normalizeAnimationEntry(entry: CompileAnimationMetadata | CompileAnimationMetadata[]):
|
||||
CompileAnimationMetadata {
|
||||
return isArray(entry) ? new CompileAnimationSequenceMetadata(<CompileAnimationMetadata[]>entry) :
|
||||
<CompileAnimationMetadata>entry;
|
||||
return Array.isArray(entry) ? new CompileAnimationSequenceMetadata(entry) : entry;
|
||||
}
|
||||
|
||||
function _normalizeStyleMetadata(
|
||||
entry: CompileAnimationStyleMetadata, stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): Array<{[key: string]: string | number}> {
|
||||
var normalizedStyles: any[] /** TODO #9100 */ = [];
|
||||
errors: AnimationParseError[]): {[key: string]: string | number}[] {
|
||||
var normalizedStyles: {[key: string]: string | number}[] = [];
|
||||
entry.styles.forEach(styleEntry => {
|
||||
if (isString(styleEntry)) {
|
||||
if (typeof styleEntry === 'string') {
|
||||
ListWrapper.addAll(
|
||||
normalizedStyles, _resolveStylesFromState(<string>styleEntry, stateStyles, errors));
|
||||
} else {
|
||||
@ -189,10 +200,10 @@ function _normalizeStyleSteps(
|
||||
|
||||
function _mergeAnimationStyles(
|
||||
stylesList: any[], newItem: {[key: string]: string | number} | string) {
|
||||
if (isStringMap(newItem) && stylesList.length > 0) {
|
||||
if (typeof newItem === 'object' && newItem !== null && stylesList.length > 0) {
|
||||
var lastIndex = stylesList.length - 1;
|
||||
var lastItem = stylesList[lastIndex];
|
||||
if (isStringMap(lastItem)) {
|
||||
if (typeof lastItem === 'object' && lastItem !== null) {
|
||||
stylesList[lastIndex] = StringMapWrapper.merge(
|
||||
<{[key: string]: string | number}>lastItem, <{[key: string]: string | number}>newItem);
|
||||
return;
|
||||
@ -279,7 +290,7 @@ function _resolveStylesFromState(
|
||||
`Unable to apply styles due to missing a state: "${normalizedStateName}"`));
|
||||
} else {
|
||||
value.styles.forEach(stylesEntry => {
|
||||
if (isStringMap(stylesEntry)) {
|
||||
if (typeof stylesEntry === 'object' && stylesEntry !== null) {
|
||||
styles.push(stylesEntry as Styles);
|
||||
}
|
||||
});
|
||||
@ -338,7 +349,6 @@ function _parseAnimationKeyframes(
|
||||
ListWrapper.sort(rawKeyframes, (a, b) => a[0] <= b[0] ? -1 : 1);
|
||||
}
|
||||
|
||||
var i: any /** TODO #9100 */;
|
||||
var firstKeyframe = rawKeyframes[0];
|
||||
if (firstKeyframe[0] != _INITIAL_KEYFRAME) {
|
||||
ListWrapper.insert(rawKeyframes, 0, firstKeyframe = [_INITIAL_KEYFRAME, {}]);
|
||||
@ -353,7 +363,7 @@ function _parseAnimationKeyframes(
|
||||
}
|
||||
|
||||
var lastKeyframeStyles = lastKeyframe[1];
|
||||
for (i = 1; i <= limit; i++) {
|
||||
for (let i = 1; i <= limit; i++) {
|
||||
let entry = rawKeyframes[i];
|
||||
let styles = entry[1];
|
||||
|
||||
@ -364,7 +374,7 @@ function _parseAnimationKeyframes(
|
||||
});
|
||||
}
|
||||
|
||||
for (i = limit - 1; i >= 0; i--) {
|
||||
for (let i = limit - 1; i >= 0; i--) {
|
||||
let entry = rawKeyframes[i];
|
||||
let styles = entry[1];
|
||||
|
||||
@ -492,7 +502,7 @@ function _parseTimeExpression(
|
||||
var duration: number;
|
||||
var delay: number = 0;
|
||||
var easing: string = null;
|
||||
if (isString(exp)) {
|
||||
if (typeof exp === 'string') {
|
||||
const matches = exp.match(regex);
|
||||
if (matches === null) {
|
||||
errors.push(new AnimationParseError(`The provided timing value "${exp}" is invalid.`));
|
||||
|
@ -8,17 +8,17 @@
|
||||
|
||||
import {isDevMode} from '@angular/core';
|
||||
|
||||
import {isArray, isBlank, isPresent, isString} from '../src/facade/lang';
|
||||
import {isBlank, isPresent} from '../src/facade/lang';
|
||||
|
||||
export function assertArrayOfStrings(identifier: string, value: any) {
|
||||
if (!isDevMode() || isBlank(value)) {
|
||||
return;
|
||||
}
|
||||
if (!isArray(value)) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error(`Expected '${identifier}' to be an array of strings.`);
|
||||
}
|
||||
for (var i = 0; i < value.length; i += 1) {
|
||||
if (!isString(value[i])) {
|
||||
if (typeof value[i] !== 'string') {
|
||||
throw new Error(`Expected '${identifier}' to be an array of strings.`);
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,7 @@ const INTERPOLATION_BLACKLIST_REGEXPS = [
|
||||
];
|
||||
|
||||
export function assertInterpolationSymbols(identifier: string, value: any): void {
|
||||
if (isPresent(value) && !(isArray(value) && value.length == 2)) {
|
||||
if (isPresent(value) && !(Array.isArray(value) && value.length == 2)) {
|
||||
throw new Error(`Expected '${identifier}' to be an array, [start, end].`);
|
||||
} else if (isDevMode() && !isBlank(value)) {
|
||||
const start = value[0] as string;
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {ChangeDetectionStrategy, SchemaMetadata, Type, ViewEncapsulation} from '@angular/core';
|
||||
|
||||
import {ListWrapper, MapWrapper} from './facade/collection';
|
||||
import {isPresent, isStringMap, normalizeBlank, normalizeBool} from './facade/lang';
|
||||
import {isPresent, normalizeBlank, normalizeBool} from './facade/lang';
|
||||
import {LifecycleHooks} from './private_import_core';
|
||||
import {CssSelector} from './selector';
|
||||
import {sanitizeIdentifier, splitAtColon} from './util';
|
||||
@ -304,7 +304,7 @@ export class CompileTemplateMetadata {
|
||||
this.styleUrls = _normalizeArray(styleUrls);
|
||||
this.externalStylesheets = _normalizeArray(externalStylesheets);
|
||||
this.animations = isPresent(animations) ? ListWrapper.flatten(animations) : [];
|
||||
this.ngContentSelectors = isPresent(ngContentSelectors) ? ngContentSelectors : [];
|
||||
this.ngContentSelectors = ngContentSelectors || [];
|
||||
if (isPresent(interpolation) && interpolation.length != 2) {
|
||||
throw new Error(`'interpolation' should have a start and an end symbol.`);
|
||||
}
|
||||
@ -590,11 +590,11 @@ export function removeIdentifierDuplicates<T extends CompileMetadataWithIdentifi
|
||||
}
|
||||
|
||||
function _normalizeArray(obj: any[]): any[] {
|
||||
return isPresent(obj) ? obj : [];
|
||||
return obj || [];
|
||||
}
|
||||
|
||||
export function isStaticSymbol(value: any): value is StaticSymbol {
|
||||
return isStringMap(value) && isPresent(value['name']) && isPresent(value['filePath']);
|
||||
return typeof value === 'object' && value !== null && value['name'] && value['filePath'];
|
||||
}
|
||||
|
||||
export interface StaticSymbol {
|
||||
|
@ -8,39 +8,27 @@
|
||||
|
||||
import {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, Inject, Injectable, Optional, PLATFORM_INITIALIZER, PlatformRef, Provider, ReflectiveInjector, TRANSLATIONS, TRANSLATIONS_FORMAT, Type, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
|
||||
|
||||
export * from './template_parser/template_ast';
|
||||
export {TEMPLATE_TRANSFORMS} from './template_parser/template_parser';
|
||||
export {CompilerConfig, RenderTypes} from './config';
|
||||
export * from './compile_metadata';
|
||||
export * from './offline_compiler';
|
||||
export {RuntimeCompiler} from './runtime_compiler';
|
||||
export * from './url_resolver';
|
||||
export * from './resource_loader';
|
||||
|
||||
export {DirectiveResolver} from './directive_resolver';
|
||||
export {PipeResolver} from './pipe_resolver';
|
||||
export {NgModuleResolver} from './ng_module_resolver';
|
||||
|
||||
import {TemplateParser} from './template_parser/template_parser';
|
||||
import {HtmlParser} from './ml_parser/html_parser';
|
||||
import {DirectiveNormalizer} from './directive_normalizer';
|
||||
import {CompileMetadataResolver} from './metadata_resolver';
|
||||
import {StyleCompiler} from './style_compiler';
|
||||
import {ViewCompiler} from './view_compiler/view_compiler';
|
||||
import {NgModuleCompiler} from './ng_module_compiler';
|
||||
import {CompilerConfig} from './config';
|
||||
import {RuntimeCompiler} from './runtime_compiler';
|
||||
import {ElementSchemaRegistry} from './schema/element_schema_registry';
|
||||
import {DomElementSchemaRegistry} from './schema/dom_element_schema_registry';
|
||||
import {UrlResolver, DEFAULT_PACKAGE_URL_PROVIDER} from './url_resolver';
|
||||
import {Parser} from './expression_parser/parser';
|
||||
import {Lexer} from './expression_parser/lexer';
|
||||
import {DirectiveNormalizer} from './directive_normalizer';
|
||||
import {DirectiveResolver} from './directive_resolver';
|
||||
import {PipeResolver} from './pipe_resolver';
|
||||
import {NgModuleResolver} from './ng_module_resolver';
|
||||
import {Console, Reflector, reflector, ReflectorReader, ReflectionCapabilities} from './private_import_core';
|
||||
import {ResourceLoader} from './resource_loader';
|
||||
import {DirectiveWrapperCompiler} from './directive_wrapper_compiler';
|
||||
import {Lexer} from './expression_parser/lexer';
|
||||
import {Parser} from './expression_parser/parser';
|
||||
import * as i18n from './i18n/index';
|
||||
import {CompileMetadataResolver} from './metadata_resolver';
|
||||
import {HtmlParser} from './ml_parser/html_parser';
|
||||
import {NgModuleCompiler} from './ng_module_compiler';
|
||||
import {NgModuleResolver} from './ng_module_resolver';
|
||||
import {PipeResolver} from './pipe_resolver';
|
||||
import {Console, ReflectionCapabilities, Reflector, ReflectorReader, reflector} from './private_import_core';
|
||||
import {ResourceLoader} from './resource_loader';
|
||||
import {RuntimeCompiler} from './runtime_compiler';
|
||||
import {DomElementSchemaRegistry} from './schema/dom_element_schema_registry';
|
||||
import {ElementSchemaRegistry} from './schema/element_schema_registry';
|
||||
import {StyleCompiler} from './style_compiler';
|
||||
import {TemplateParser} from './template_parser/template_parser';
|
||||
import {DEFAULT_PACKAGE_URL_PROVIDER, UrlResolver} from './url_resolver';
|
||||
import {ViewCompiler} from './view_compiler/view_compiler';
|
||||
|
||||
const _NO_RESOURCE_LOADER: ResourceLoader = {
|
||||
get(url: string): Promise<string>{
|
||||
@ -77,6 +65,7 @@ export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> =
|
||||
StyleCompiler,
|
||||
ViewCompiler,
|
||||
NgModuleCompiler,
|
||||
DirectiveWrapperCompiler,
|
||||
{provide: CompilerConfig, useValue: new CompilerConfig()},
|
||||
RuntimeCompiler,
|
||||
{provide: Compiler, useExisting: RuntimeCompiler},
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
import * as chars from '../chars';
|
||||
import {BaseError} from '../facade/errors';
|
||||
import {StringWrapper, isPresent} from '../facade/lang';
|
||||
import {isPresent} from '../facade/lang';
|
||||
|
||||
export enum CssTokenType {
|
||||
EOF,
|
||||
@ -155,7 +155,7 @@ export class CssScanner {
|
||||
}
|
||||
|
||||
peekAt(index: number): number {
|
||||
return index >= this.length ? chars.$EOF : StringWrapper.charCodeAt(this.input, index);
|
||||
return index >= this.length ? chars.$EOF : this.input.charCodeAt(index);
|
||||
}
|
||||
|
||||
consumeEmptyStatements(): void {
|
||||
@ -310,7 +310,7 @@ export class CssScanner {
|
||||
return this.scanCharacter();
|
||||
}
|
||||
|
||||
return this.error(`Unexpected character [${StringWrapper.fromCharCode(peek)}]`);
|
||||
return this.error(`Unexpected character [${String.fromCharCode(peek)}]`);
|
||||
}
|
||||
|
||||
scanComment(): CssToken {
|
||||
@ -476,8 +476,7 @@ export class CssScanner {
|
||||
var index: number = this.index;
|
||||
var column: number = this.column;
|
||||
var line: number = this.line;
|
||||
errorTokenValue =
|
||||
isPresent(errorTokenValue) ? errorTokenValue : StringWrapper.fromCharCode(this.peek);
|
||||
errorTokenValue = errorTokenValue || String.fromCharCode(this.peek);
|
||||
var invalidToken = new CssToken(index, column, line, CssTokenType.Invalid, errorTokenValue);
|
||||
var errorMessage =
|
||||
generateErrorMessage(this.input, message, errorTokenValue, index, line, column);
|
||||
@ -696,11 +695,11 @@ function isValidCssCharacter(code: number, mode: CssLexerMode): boolean {
|
||||
}
|
||||
|
||||
function charCode(input: string, index: number): number {
|
||||
return index >= input.length ? chars.$EOF : StringWrapper.charCodeAt(input, index);
|
||||
return index >= input.length ? chars.$EOF : input.charCodeAt(index);
|
||||
}
|
||||
|
||||
function charStr(code: number): string {
|
||||
return StringWrapper.fromCharCode(code);
|
||||
return String.fromCharCode(code);
|
||||
}
|
||||
|
||||
export function isNewline(code: number): boolean {
|
||||
|
@ -330,7 +330,7 @@ export class CssParser {
|
||||
var span: ParseSourceSpan;
|
||||
var startSelector = selectors[0];
|
||||
if (isPresent(block)) {
|
||||
var span = this._generateSourceSpan(startSelector, block);
|
||||
span = this._generateSourceSpan(startSelector, block);
|
||||
ruleAst = new CssSelectorRuleAst(span, selectors, block);
|
||||
} else {
|
||||
var name = this._extractSourceContent(start, this._getScannerIndex() - 1);
|
||||
|
@ -71,6 +71,13 @@ export class DirectiveResolver {
|
||||
} else if (a instanceof HostBinding) {
|
||||
const hostBinding: HostBinding = a;
|
||||
if (hostBinding.hostPropertyName) {
|
||||
const startWith = hostBinding.hostPropertyName[0];
|
||||
if (startWith === '(') {
|
||||
throw new Error(`@HostBinding can not bind to events. Use @HostListener instead.`);
|
||||
} else if (startWith === '[') {
|
||||
throw new Error(
|
||||
`@HostBinding parameter should be a property name, 'class.<name>', or 'attr.<name>'.`);
|
||||
}
|
||||
host[`[${hostBinding.hostPropertyName}]`] = propName;
|
||||
} else {
|
||||
host[`[${propName}]`] = propName;
|
||||
|
186
modules/@angular/compiler/src/directive_wrapper_compiler.ts
Normal file
186
modules/@angular/compiler/src/directive_wrapper_compiler.ts
Normal file
@ -0,0 +1,186 @@
|
||||
/**
|
||||
* @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 {Injectable} from '@angular/core';
|
||||
|
||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata} from './compile_metadata';
|
||||
import {CompilerConfig} from './config';
|
||||
import {Identifiers, resolveIdentifier} from './identifiers';
|
||||
import * as o from './output/output_ast';
|
||||
import {LifecycleHooks, isDefaultChangeDetectionStrategy} from './private_import_core';
|
||||
|
||||
export class DirectiveWrapperCompileResult {
|
||||
constructor(public statements: o.Statement[], public dirWrapperClassVar: string) {}
|
||||
}
|
||||
|
||||
const CONTEXT_FIELD_NAME = 'context';
|
||||
const CHANGES_FIELD_NAME = 'changes';
|
||||
const CHANGED_FIELD_NAME = 'changed';
|
||||
|
||||
const CURR_VALUE_VAR = o.variable('currValue');
|
||||
const THROW_ON_CHANGE_VAR = o.variable('throwOnChange');
|
||||
const FORCE_UPDATE_VAR = o.variable('forceUpdate');
|
||||
const VIEW_VAR = o.variable('view');
|
||||
const RENDER_EL_VAR = o.variable('el');
|
||||
|
||||
const RESET_CHANGES_STMT = o.THIS_EXPR.prop(CHANGES_FIELD_NAME).set(o.literalMap([])).toStmt();
|
||||
|
||||
/**
|
||||
* We generate directive wrappers to prevent code bloat when a directive is used.
|
||||
* A directive wrapper encapsulates
|
||||
* the dirty checking for `@Input`, the handling of `@HostListener` / `@HostBinding`
|
||||
* and calling the lifecyclehooks `ngOnInit`, `ngOnChanges`, `ngDoCheck`.
|
||||
*
|
||||
* So far, only `@Input` and the lifecycle hooks have been implemented.
|
||||
*/
|
||||
@Injectable()
|
||||
export class DirectiveWrapperCompiler {
|
||||
static dirWrapperClassName(id: CompileIdentifierMetadata) { return `Wrapper_${id.name}`; }
|
||||
|
||||
constructor(private compilerConfig: CompilerConfig) {}
|
||||
|
||||
compile(dirMeta: CompileDirectiveMetadata): DirectiveWrapperCompileResult {
|
||||
const dirDepParamNames: string[] = [];
|
||||
for (let i = 0; i < dirMeta.type.diDeps.length; i++) {
|
||||
dirDepParamNames.push(`p${i}`);
|
||||
}
|
||||
const dirLifecycleHooks = dirMeta.type.lifecycleHooks;
|
||||
let lifecycleHooks: GenConfig = {
|
||||
genChanges: dirLifecycleHooks.indexOf(LifecycleHooks.OnChanges) !== -1 ||
|
||||
this.compilerConfig.logBindingUpdate,
|
||||
ngOnChanges: dirLifecycleHooks.indexOf(LifecycleHooks.OnChanges) !== -1,
|
||||
ngOnInit: dirLifecycleHooks.indexOf(LifecycleHooks.OnInit) !== -1,
|
||||
ngDoCheck: dirLifecycleHooks.indexOf(LifecycleHooks.DoCheck) !== -1
|
||||
};
|
||||
|
||||
const fields: o.ClassField[] = [
|
||||
new o.ClassField(CONTEXT_FIELD_NAME, o.importType(dirMeta.type)),
|
||||
new o.ClassField(CHANGED_FIELD_NAME, o.BOOL_TYPE),
|
||||
];
|
||||
const ctorStmts: o.Statement[] =
|
||||
[o.THIS_EXPR.prop(CHANGED_FIELD_NAME).set(o.literal(false)).toStmt()];
|
||||
if (lifecycleHooks.genChanges) {
|
||||
fields.push(new o.ClassField(CHANGES_FIELD_NAME, new o.MapType(o.DYNAMIC_TYPE)));
|
||||
ctorStmts.push(RESET_CHANGES_STMT);
|
||||
}
|
||||
|
||||
const methods: o.ClassMethod[] = [];
|
||||
Object.keys(dirMeta.inputs).forEach((inputFieldName, idx) => {
|
||||
const fieldName = `_${inputFieldName}`;
|
||||
// private is fine here as no child view will reference the cached value...
|
||||
fields.push(new o.ClassField(fieldName, null, [o.StmtModifier.Private]));
|
||||
ctorStmts.push(o.THIS_EXPR.prop(fieldName)
|
||||
.set(o.importExpr(resolveIdentifier(Identifiers.UNINITIALIZED)))
|
||||
.toStmt());
|
||||
methods.push(checkInputMethod(inputFieldName, o.THIS_EXPR.prop(fieldName), lifecycleHooks));
|
||||
});
|
||||
methods.push(detectChangesInternalMethod(lifecycleHooks, this.compilerConfig.genDebugInfo));
|
||||
|
||||
ctorStmts.push(
|
||||
o.THIS_EXPR.prop(CONTEXT_FIELD_NAME)
|
||||
.set(o.importExpr(dirMeta.type)
|
||||
.instantiate(dirDepParamNames.map((paramName) => o.variable(paramName))))
|
||||
.toStmt());
|
||||
const ctor = new o.ClassMethod(
|
||||
null, dirDepParamNames.map((paramName) => new o.FnParam(paramName, o.DYNAMIC_TYPE)),
|
||||
ctorStmts);
|
||||
|
||||
const wrapperClassName = DirectiveWrapperCompiler.dirWrapperClassName(dirMeta.type);
|
||||
const classStmt = new o.ClassStmt(wrapperClassName, null, fields, [], ctor, methods);
|
||||
return new DirectiveWrapperCompileResult([classStmt], wrapperClassName);
|
||||
}
|
||||
}
|
||||
|
||||
function detectChangesInternalMethod(
|
||||
lifecycleHooks: GenConfig, logBindingUpdate: boolean): o.ClassMethod {
|
||||
const changedVar = o.variable('changed');
|
||||
const stmts: o.Statement[] = [
|
||||
changedVar.set(o.THIS_EXPR.prop(CHANGED_FIELD_NAME)).toDeclStmt(),
|
||||
o.THIS_EXPR.prop(CHANGED_FIELD_NAME).set(o.literal(false)).toStmt(),
|
||||
];
|
||||
const lifecycleStmts: o.Statement[] = [];
|
||||
|
||||
if (lifecycleHooks.genChanges) {
|
||||
const onChangesStmts: o.Statement[] = [];
|
||||
if (lifecycleHooks.ngOnChanges) {
|
||||
onChangesStmts.push(o.THIS_EXPR.prop(CONTEXT_FIELD_NAME)
|
||||
.callMethod('ngOnChanges', [o.THIS_EXPR.prop(CHANGES_FIELD_NAME)])
|
||||
.toStmt());
|
||||
}
|
||||
if (logBindingUpdate) {
|
||||
onChangesStmts.push(
|
||||
o.importExpr(resolveIdentifier(Identifiers.setBindingDebugInfoForChanges))
|
||||
.callFn(
|
||||
[VIEW_VAR.prop('renderer'), RENDER_EL_VAR, o.THIS_EXPR.prop(CHANGES_FIELD_NAME)])
|
||||
.toStmt());
|
||||
}
|
||||
onChangesStmts.push(RESET_CHANGES_STMT);
|
||||
lifecycleStmts.push(new o.IfStmt(changedVar, onChangesStmts));
|
||||
}
|
||||
|
||||
if (lifecycleHooks.ngOnInit) {
|
||||
lifecycleStmts.push(new o.IfStmt(
|
||||
VIEW_VAR.prop('numberOfChecks').identical(new o.LiteralExpr(0)),
|
||||
[o.THIS_EXPR.prop(CONTEXT_FIELD_NAME).callMethod('ngOnInit', []).toStmt()]));
|
||||
}
|
||||
if (lifecycleHooks.ngDoCheck) {
|
||||
lifecycleStmts.push(o.THIS_EXPR.prop(CONTEXT_FIELD_NAME).callMethod('ngDoCheck', []).toStmt());
|
||||
}
|
||||
if (lifecycleStmts.length > 0) {
|
||||
stmts.push(new o.IfStmt(o.not(THROW_ON_CHANGE_VAR), lifecycleStmts));
|
||||
}
|
||||
stmts.push(new o.ReturnStatement(changedVar));
|
||||
|
||||
return new o.ClassMethod(
|
||||
'detectChangesInternal',
|
||||
[
|
||||
new o.FnParam(
|
||||
VIEW_VAR.name, o.importType(resolveIdentifier(Identifiers.AppView), [o.DYNAMIC_TYPE])),
|
||||
new o.FnParam(RENDER_EL_VAR.name, o.DYNAMIC_TYPE),
|
||||
new o.FnParam(THROW_ON_CHANGE_VAR.name, o.BOOL_TYPE),
|
||||
],
|
||||
stmts, o.BOOL_TYPE);
|
||||
}
|
||||
|
||||
function checkInputMethod(
|
||||
input: string, fieldExpr: o.ReadPropExpr, lifecycleHooks: GenConfig): o.ClassMethod {
|
||||
var onChangeStatements: o.Statement[] = [
|
||||
o.THIS_EXPR.prop(CHANGED_FIELD_NAME).set(o.literal(true)).toStmt(),
|
||||
o.THIS_EXPR.prop(CONTEXT_FIELD_NAME).prop(input).set(CURR_VALUE_VAR).toStmt(),
|
||||
];
|
||||
if (lifecycleHooks.genChanges) {
|
||||
onChangeStatements.push(o.THIS_EXPR.prop(CHANGES_FIELD_NAME)
|
||||
.key(o.literal(input))
|
||||
.set(o.importExpr(resolveIdentifier(Identifiers.SimpleChange))
|
||||
.instantiate([fieldExpr, CURR_VALUE_VAR]))
|
||||
.toStmt());
|
||||
}
|
||||
onChangeStatements.push(fieldExpr.set(CURR_VALUE_VAR).toStmt());
|
||||
|
||||
var methodBody: o.Statement[] = [
|
||||
new o.IfStmt(
|
||||
FORCE_UPDATE_VAR.or(o.importExpr(resolveIdentifier(Identifiers.checkBinding))
|
||||
.callFn([THROW_ON_CHANGE_VAR, fieldExpr, CURR_VALUE_VAR])),
|
||||
onChangeStatements),
|
||||
];
|
||||
return new o.ClassMethod(
|
||||
`check_${input}`,
|
||||
[
|
||||
new o.FnParam(CURR_VALUE_VAR.name, o.DYNAMIC_TYPE),
|
||||
new o.FnParam(THROW_ON_CHANGE_VAR.name, o.BOOL_TYPE),
|
||||
new o.FnParam(FORCE_UPDATE_VAR.name, o.BOOL_TYPE),
|
||||
],
|
||||
methodBody);
|
||||
}
|
||||
|
||||
interface GenConfig {
|
||||
genChanges: boolean;
|
||||
ngOnChanges: boolean;
|
||||
ngOnInit: boolean;
|
||||
ngDoCheck: boolean;
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {Injectable} from '@angular/core';
|
||||
import * as chars from '../chars';
|
||||
import {NumberWrapper, StringJoiner, StringWrapper, isPresent} from '../facade/lang';
|
||||
import {NumberWrapper, isPresent} from '../facade/lang';
|
||||
|
||||
export enum TokenType {
|
||||
Character,
|
||||
@ -93,7 +93,7 @@ export class Token {
|
||||
}
|
||||
|
||||
function newCharacterToken(index: number, code: number): Token {
|
||||
return new Token(index, TokenType.Character, code, StringWrapper.fromCharCode(code));
|
||||
return new Token(index, TokenType.Character, code, String.fromCharCode(code));
|
||||
}
|
||||
|
||||
function newIdentifierToken(index: number, text: string): Token {
|
||||
@ -133,8 +133,7 @@ class _Scanner {
|
||||
}
|
||||
|
||||
advance() {
|
||||
this.peek =
|
||||
++this.index >= this.length ? chars.$EOF : StringWrapper.charCodeAt(this.input, this.index);
|
||||
this.peek = ++this.index >= this.length ? chars.$EOF : this.input.charCodeAt(this.index);
|
||||
}
|
||||
|
||||
scanToken(): Token {
|
||||
@ -146,7 +145,7 @@ class _Scanner {
|
||||
peek = chars.$EOF;
|
||||
break;
|
||||
} else {
|
||||
peek = StringWrapper.charCodeAt(input, index);
|
||||
peek = input.charCodeAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,16 +186,16 @@ class _Scanner {
|
||||
case chars.$SLASH:
|
||||
case chars.$PERCENT:
|
||||
case chars.$CARET:
|
||||
return this.scanOperator(start, StringWrapper.fromCharCode(peek));
|
||||
return this.scanOperator(start, String.fromCharCode(peek));
|
||||
case chars.$QUESTION:
|
||||
return this.scanComplexOperator(start, '?', chars.$PERIOD, '.');
|
||||
case chars.$LT:
|
||||
case chars.$GT:
|
||||
return this.scanComplexOperator(start, StringWrapper.fromCharCode(peek), chars.$EQ, '=');
|
||||
return this.scanComplexOperator(start, String.fromCharCode(peek), chars.$EQ, '=');
|
||||
case chars.$BANG:
|
||||
case chars.$EQ:
|
||||
return this.scanComplexOperator(
|
||||
start, StringWrapper.fromCharCode(peek), chars.$EQ, '=', chars.$EQ, '=');
|
||||
start, String.fromCharCode(peek), chars.$EQ, '=', chars.$EQ, '=');
|
||||
case chars.$AMPERSAND:
|
||||
return this.scanComplexOperator(start, '&', chars.$AMPERSAND, '&');
|
||||
case chars.$BAR:
|
||||
@ -207,7 +206,7 @@ class _Scanner {
|
||||
}
|
||||
|
||||
this.advance();
|
||||
return this.error(`Unexpected character [${StringWrapper.fromCharCode(peek)}]`, 0);
|
||||
return this.error(`Unexpected character [${String.fromCharCode(peek)}]`, 0);
|
||||
}
|
||||
|
||||
scanCharacter(start: number, code: number): Token {
|
||||
@ -275,42 +274,41 @@ class _Scanner {
|
||||
}
|
||||
this.advance();
|
||||
}
|
||||
var str: string = this.input.substring(start, this.index);
|
||||
var value: number = simple ? NumberWrapper.parseIntAutoRadix(str) : parseFloat(str);
|
||||
const str: string = this.input.substring(start, this.index);
|
||||
const value: number = simple ? NumberWrapper.parseIntAutoRadix(str) : parseFloat(str);
|
||||
return newNumberToken(start, value);
|
||||
}
|
||||
|
||||
scanString(): Token {
|
||||
var start: number = this.index;
|
||||
var quote: number = this.peek;
|
||||
const start: number = this.index;
|
||||
const quote: number = this.peek;
|
||||
this.advance(); // Skip initial quote.
|
||||
|
||||
var buffer: StringJoiner;
|
||||
var marker: number = this.index;
|
||||
var input: string = this.input;
|
||||
let buffer: string = '';
|
||||
let marker: number = this.index;
|
||||
let input: string = this.input;
|
||||
|
||||
while (this.peek != quote) {
|
||||
if (this.peek == chars.$BACKSLASH) {
|
||||
if (buffer == null) buffer = new StringJoiner();
|
||||
buffer.add(input.substring(marker, this.index));
|
||||
buffer += input.substring(marker, this.index);
|
||||
this.advance();
|
||||
var unescapedCode: number;
|
||||
let unescapedCode: number;
|
||||
if (this.peek == chars.$u) {
|
||||
// 4 character hex code for unicode character.
|
||||
var hex: string = input.substring(this.index + 1, this.index + 5);
|
||||
const hex: string = input.substring(this.index + 1, this.index + 5);
|
||||
try {
|
||||
unescapedCode = NumberWrapper.parseInt(hex, 16);
|
||||
} catch (e) {
|
||||
return this.error(`Invalid unicode escape [\\u${hex}]`, 0);
|
||||
}
|
||||
for (var i: number = 0; i < 5; i++) {
|
||||
for (let i: number = 0; i < 5; i++) {
|
||||
this.advance();
|
||||
}
|
||||
} else {
|
||||
unescapedCode = unescape(this.peek);
|
||||
this.advance();
|
||||
}
|
||||
buffer.add(StringWrapper.fromCharCode(unescapedCode));
|
||||
buffer += String.fromCharCode(unescapedCode);
|
||||
marker = this.index;
|
||||
} else if (this.peek == chars.$EOF) {
|
||||
return this.error('Unterminated quote', 0);
|
||||
@ -319,16 +317,10 @@ class _Scanner {
|
||||
}
|
||||
}
|
||||
|
||||
var last: string = input.substring(marker, this.index);
|
||||
const last: string = input.substring(marker, this.index);
|
||||
this.advance(); // Skip terminating quote.
|
||||
|
||||
// Compute the unescaped string value.
|
||||
var unescaped: string = last;
|
||||
if (buffer != null) {
|
||||
buffer.add(last);
|
||||
unescaped = buffer.toString();
|
||||
}
|
||||
return newStringToken(start, unescaped);
|
||||
return newStringToken(start, buffer + last);
|
||||
}
|
||||
|
||||
error(message: string, offset: number): Token {
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
import * as chars from '../chars';
|
||||
import {StringWrapper, escapeRegExp, isBlank, isPresent} from '../facade/lang';
|
||||
import {escapeRegExp, isBlank, isPresent} from '../facade/lang';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../ml_parser/interpolation_config';
|
||||
|
||||
import {AST, ASTWithSource, AstVisitor, Binary, BindingPipe, Chain, Conditional, EmptyExpr, FunctionCall, ImplicitReceiver, Interpolation, KeyedRead, KeyedWrite, LiteralArray, LiteralMap, LiteralPrimitive, MethodCall, ParseSpan, ParserError, PrefixNot, PropertyRead, PropertyWrite, Quote, SafeMethodCall, SafePropertyRead, TemplateBinding} from './ast';
|
||||
@ -17,7 +17,7 @@ import {EOF, Lexer, Token, TokenType, isIdentifier, isQuote} from './lexer';
|
||||
|
||||
|
||||
export class SplitInterpolation {
|
||||
constructor(public strings: string[], public expressions: string[]) {}
|
||||
constructor(public strings: string[], public expressions: string[], public offsets: number[]) {}
|
||||
}
|
||||
|
||||
export class TemplateBindingParseResult {
|
||||
@ -41,8 +41,12 @@ export class Parser {
|
||||
input: string, location: any,
|
||||
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG): ASTWithSource {
|
||||
this._checkNoInterpolation(input, location, interpolationConfig);
|
||||
const sourceToLex = this._stripComments(input);
|
||||
const tokens = this._lexer.tokenize(this._stripComments(input));
|
||||
const ast = new _ParseAST(input, location, tokens, true, this.errors).parseChain();
|
||||
const ast = new _ParseAST(
|
||||
input, location, tokens, sourceToLex.length, true, this.errors,
|
||||
input.length - sourceToLex.length)
|
||||
.parseChain();
|
||||
return new ASTWithSource(ast, input, location, this.errors);
|
||||
}
|
||||
|
||||
@ -79,8 +83,12 @@ export class Parser {
|
||||
}
|
||||
|
||||
this._checkNoInterpolation(input, location, interpolationConfig);
|
||||
var tokens = this._lexer.tokenize(this._stripComments(input));
|
||||
return new _ParseAST(input, location, tokens, false, this.errors).parseChain();
|
||||
const sourceToLex = this._stripComments(input);
|
||||
const tokens = this._lexer.tokenize(sourceToLex);
|
||||
return new _ParseAST(
|
||||
input, location, tokens, sourceToLex.length, false, this.errors,
|
||||
input.length - sourceToLex.length)
|
||||
.parseChain();
|
||||
}
|
||||
|
||||
private _parseQuote(input: string, location: any): AST {
|
||||
@ -95,7 +103,8 @@ export class Parser {
|
||||
|
||||
parseTemplateBindings(input: string, location: any): TemplateBindingParseResult {
|
||||
var tokens = this._lexer.tokenize(input);
|
||||
return new _ParseAST(input, location, tokens, false, this.errors).parseTemplateBindings();
|
||||
return new _ParseAST(input, location, tokens, input.length, false, this.errors, 0)
|
||||
.parseTemplateBindings();
|
||||
}
|
||||
|
||||
parseInterpolation(
|
||||
@ -107,8 +116,13 @@ export class Parser {
|
||||
let expressions: AST[] = [];
|
||||
|
||||
for (let i = 0; i < split.expressions.length; ++i) {
|
||||
var tokens = this._lexer.tokenize(this._stripComments(split.expressions[i]));
|
||||
var ast = new _ParseAST(input, location, tokens, false, this.errors).parseChain();
|
||||
const expressionText = split.expressions[i];
|
||||
const sourceToLex = this._stripComments(expressionText);
|
||||
const tokens = this._lexer.tokenize(this._stripComments(split.expressions[i]));
|
||||
const ast = new _ParseAST(
|
||||
input, location, tokens, sourceToLex.length, false, this.errors,
|
||||
split.offsets[i] + (expressionText.length - sourceToLex.length))
|
||||
.parseChain();
|
||||
expressions.push(ast);
|
||||
}
|
||||
|
||||
@ -122,20 +136,25 @@ export class Parser {
|
||||
input: string, location: string,
|
||||
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG): SplitInterpolation {
|
||||
const regexp = _createInterpolateRegExp(interpolationConfig);
|
||||
const parts = StringWrapper.split(input, regexp);
|
||||
const parts = input.split(regexp);
|
||||
if (parts.length <= 1) {
|
||||
return null;
|
||||
}
|
||||
const strings: string[] = [];
|
||||
const expressions: string[] = [];
|
||||
|
||||
const offsets: number[] = [];
|
||||
let offset = 0;
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
var part: string = parts[i];
|
||||
if (i % 2 === 0) {
|
||||
// fixed string
|
||||
strings.push(part);
|
||||
offset += part.length;
|
||||
} else if (part.trim().length > 0) {
|
||||
offset += interpolationConfig.start.length;
|
||||
expressions.push(part);
|
||||
offsets.push(offset);
|
||||
offset += part.length + interpolationConfig.end.length;
|
||||
} else {
|
||||
this._reportError(
|
||||
'Blank expressions are not allowed in interpolated strings', input,
|
||||
@ -143,7 +162,7 @@ export class Parser {
|
||||
location);
|
||||
}
|
||||
}
|
||||
return new SplitInterpolation(strings, expressions);
|
||||
return new SplitInterpolation(strings, expressions, offsets);
|
||||
}
|
||||
|
||||
wrapLiteralPrimitive(input: string, location: any): ASTWithSource {
|
||||
@ -160,8 +179,8 @@ export class Parser {
|
||||
private _commentStart(input: string): number {
|
||||
var outerQuote: number = null;
|
||||
for (let i = 0; i < input.length - 1; i++) {
|
||||
const char = StringWrapper.charCodeAt(input, i);
|
||||
const nextChar = StringWrapper.charCodeAt(input, i + 1);
|
||||
const char = input.charCodeAt(i);
|
||||
const nextChar = input.charCodeAt(i + 1);
|
||||
|
||||
if (char === chars.$SLASH && nextChar == chars.$SLASH && isBlank(outerQuote)) return i;
|
||||
|
||||
@ -177,7 +196,7 @@ export class Parser {
|
||||
private _checkNoInterpolation(
|
||||
input: string, location: any, interpolationConfig: InterpolationConfig): void {
|
||||
var regexp = _createInterpolateRegExp(interpolationConfig);
|
||||
var parts = StringWrapper.split(input, regexp);
|
||||
var parts = input.split(regexp);
|
||||
if (parts.length > 1) {
|
||||
this._reportError(
|
||||
`Got interpolation (${interpolationConfig.start}${interpolationConfig.end}) where expression was expected`,
|
||||
@ -208,8 +227,9 @@ export class _ParseAST {
|
||||
index: number = 0;
|
||||
|
||||
constructor(
|
||||
public input: string, public location: any, public tokens: any[], public parseAction: boolean,
|
||||
private errors: ParserError[]) {}
|
||||
public input: string, public location: any, public tokens: Token[],
|
||||
public inputLength: number, public parseAction: boolean, private errors: ParserError[],
|
||||
private offset: number) {}
|
||||
|
||||
peek(offset: number): Token {
|
||||
var i = this.index + offset;
|
||||
@ -219,7 +239,8 @@ export class _ParseAST {
|
||||
get next(): Token { return this.peek(0); }
|
||||
|
||||
get inputIndex(): number {
|
||||
return (this.index < this.tokens.length) ? this.next.index : this.input.length;
|
||||
return (this.index < this.tokens.length) ? this.next.index + this.offset :
|
||||
this.inputLength + this.offset;
|
||||
}
|
||||
|
||||
span(start: number) { return new ParseSpan(start, this.inputIndex); }
|
||||
@ -239,7 +260,7 @@ export class _ParseAST {
|
||||
|
||||
expectCharacter(code: number) {
|
||||
if (this.optionalCharacter(code)) return;
|
||||
this.error(`Missing expected ${StringWrapper.fromCharCode(code)}`);
|
||||
this.error(`Missing expected ${String.fromCharCode(code)}`);
|
||||
}
|
||||
|
||||
optionalOperator(op: string): boolean {
|
||||
@ -311,7 +332,7 @@ export class _ParseAST {
|
||||
while (this.optionalCharacter(chars.$COLON)) {
|
||||
args.push(this.parseExpression());
|
||||
}
|
||||
result = new BindingPipe(this.span(result.span.start), result, name, args);
|
||||
result = new BindingPipe(this.span(result.span.start - this.offset), result, name, args);
|
||||
} while (this.optionalOperator('|'));
|
||||
}
|
||||
|
||||
|
@ -6,10 +6,10 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ElementRef, Injector, LOCALE_ID as LOCALE_ID_, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TRANSLATIONS_FORMAT as TRANSLATIONS_FORMAT_, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, AnimationTransitionEvent, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ElementRef, Injector, LOCALE_ID, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
|
||||
|
||||
import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata';
|
||||
import {AnimationGroupPlayer, AnimationKeyframe, AnimationSequencePlayer, AnimationStyles, AppElement, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, DebugAppView, DebugContext, EMPTY_ARRAY, EMPTY_MAP, NgModuleInjector, NoOpAnimationPlayer, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewType, ViewUtils, balanceAnimationKeyframes, castByValue, checkBinding, clearStyles, collectAndResolveStyles, devModeEqual, flattenNestedViewRenderNodes, interpolate, prepareFinalAnimationStyles, pureProxy1, pureProxy10, pureProxy2, pureProxy3, pureProxy4, pureProxy5, pureProxy6, pureProxy7, pureProxy8, pureProxy9, reflector, registerModuleFactory, renderStyles} from './private_import_core';
|
||||
import {AnimationGroupPlayer, AnimationKeyframe, AnimationSequencePlayer, AnimationStyles, AnimationTransition, AppElement, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, DebugAppView, DebugContext, NgModuleInjector, NoOpAnimationPlayer, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewType, balanceAnimationKeyframes, clearStyles, collectAndResolveStyles, devModeEqual, prepareFinalAnimationStyles, reflector, registerModuleFactory, renderStyles, view_utils} from './private_import_core';
|
||||
import {assetUrl} from './util';
|
||||
|
||||
var APP_VIEW_MODULE_URL = assetUrl('core', 'linker/view');
|
||||
@ -33,7 +33,7 @@ export class Identifiers {
|
||||
static ViewUtils: IdentifierSpec = {
|
||||
name: 'ViewUtils',
|
||||
moduleUrl: assetUrl('core', 'linker/view_utils'),
|
||||
runtime: ViewUtils
|
||||
runtime: view_utils.ViewUtils
|
||||
};
|
||||
static AppView:
|
||||
IdentifierSpec = {name: 'AppView', moduleUrl: APP_VIEW_MODULE_URL, runtime: AppView};
|
||||
@ -161,45 +161,48 @@ export class Identifiers {
|
||||
static checkBinding: IdentifierSpec = {
|
||||
name: 'checkBinding',
|
||||
moduleUrl: VIEW_UTILS_MODULE_URL,
|
||||
runtime: checkBinding
|
||||
runtime: view_utils.checkBinding
|
||||
};
|
||||
static flattenNestedViewRenderNodes: IdentifierSpec = {
|
||||
name: 'flattenNestedViewRenderNodes',
|
||||
moduleUrl: VIEW_UTILS_MODULE_URL,
|
||||
runtime: flattenNestedViewRenderNodes
|
||||
runtime: view_utils.flattenNestedViewRenderNodes
|
||||
};
|
||||
static devModeEqual:
|
||||
IdentifierSpec = {name: 'devModeEqual', moduleUrl: CD_MODULE_URL, runtime: devModeEqual};
|
||||
static interpolate: IdentifierSpec = {
|
||||
name: 'interpolate',
|
||||
moduleUrl: VIEW_UTILS_MODULE_URL,
|
||||
runtime: interpolate
|
||||
runtime: view_utils.interpolate
|
||||
};
|
||||
static castByValue: IdentifierSpec = {
|
||||
name: 'castByValue',
|
||||
moduleUrl: VIEW_UTILS_MODULE_URL,
|
||||
runtime: castByValue
|
||||
runtime: view_utils.castByValue
|
||||
};
|
||||
static EMPTY_ARRAY: IdentifierSpec = {
|
||||
name: 'EMPTY_ARRAY',
|
||||
moduleUrl: VIEW_UTILS_MODULE_URL,
|
||||
runtime: EMPTY_ARRAY
|
||||
runtime: view_utils.EMPTY_ARRAY
|
||||
};
|
||||
static EMPTY_MAP: IdentifierSpec = {
|
||||
name: 'EMPTY_MAP',
|
||||
moduleUrl: VIEW_UTILS_MODULE_URL,
|
||||
runtime: view_utils.EMPTY_MAP
|
||||
};
|
||||
static EMPTY_MAP:
|
||||
IdentifierSpec = {name: 'EMPTY_MAP', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: EMPTY_MAP};
|
||||
|
||||
static pureProxies = [
|
||||
null,
|
||||
{name: 'pureProxy1', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: pureProxy1},
|
||||
{name: 'pureProxy2', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: pureProxy2},
|
||||
{name: 'pureProxy3', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: pureProxy3},
|
||||
{name: 'pureProxy4', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: pureProxy4},
|
||||
{name: 'pureProxy5', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: pureProxy5},
|
||||
{name: 'pureProxy6', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: pureProxy6},
|
||||
{name: 'pureProxy7', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: pureProxy7},
|
||||
{name: 'pureProxy8', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: pureProxy8},
|
||||
{name: 'pureProxy9', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: pureProxy9},
|
||||
{name: 'pureProxy10', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: pureProxy10},
|
||||
{name: 'pureProxy1', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy1},
|
||||
{name: 'pureProxy2', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy2},
|
||||
{name: 'pureProxy3', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy3},
|
||||
{name: 'pureProxy4', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy4},
|
||||
{name: 'pureProxy5', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy5},
|
||||
{name: 'pureProxy6', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy6},
|
||||
{name: 'pureProxy7', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy7},
|
||||
{name: 'pureProxy8', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy8},
|
||||
{name: 'pureProxy9', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy9},
|
||||
{name: 'pureProxy10', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy10},
|
||||
];
|
||||
static SecurityContext: IdentifierSpec = {
|
||||
name: 'SecurityContext',
|
||||
@ -259,12 +262,27 @@ export class Identifiers {
|
||||
static LOCALE_ID: IdentifierSpec = {
|
||||
name: 'LOCALE_ID',
|
||||
moduleUrl: assetUrl('core', 'i18n/tokens'),
|
||||
runtime: LOCALE_ID_
|
||||
runtime: LOCALE_ID
|
||||
};
|
||||
static TRANSLATIONS_FORMAT: IdentifierSpec = {
|
||||
name: 'TRANSLATIONS_FORMAT',
|
||||
moduleUrl: assetUrl('core', 'i18n/tokens'),
|
||||
runtime: TRANSLATIONS_FORMAT_
|
||||
runtime: TRANSLATIONS_FORMAT
|
||||
};
|
||||
static setBindingDebugInfo: IdentifierSpec = {
|
||||
name: 'setBindingDebugInfo',
|
||||
moduleUrl: VIEW_UTILS_MODULE_URL,
|
||||
runtime: view_utils.setBindingDebugInfo
|
||||
};
|
||||
static setBindingDebugInfoForChanges: IdentifierSpec = {
|
||||
name: 'setBindingDebugInfoForChanges',
|
||||
moduleUrl: VIEW_UTILS_MODULE_URL,
|
||||
runtime: view_utils.setBindingDebugInfoForChanges
|
||||
};
|
||||
static AnimationTransition: IdentifierSpec = {
|
||||
name: 'AnimationTransition',
|
||||
moduleUrl: assetUrl('core', 'animation/animation_transition'),
|
||||
runtime: AnimationTransition
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @module
|
||||
* @description
|
||||
* Starting point to import all compiler APIs.
|
||||
*/
|
||||
|
||||
export {COMPILER_PROVIDERS, CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileFactoryMetadata, CompileIdentifierMetadata, CompileMetadataWithIdentifier, CompilePipeMetadata, CompileProviderMetadata, CompileQueryMetadata, CompileTemplateMetadata, CompileTokenMetadata, CompileTypeMetadata, CompilerConfig, DEFAULT_PACKAGE_URL_PROVIDER, DirectiveResolver, NgModuleResolver, OfflineCompiler, PipeResolver, RenderTypes, ResourceLoader, RuntimeCompiler, SourceModule, TEMPLATE_TRANSFORMS, UrlResolver, createOfflineCompileUrlResolver, platformCoreDynamic} from './compiler';
|
||||
export {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from './ml_parser/interpolation_config';
|
||||
export {ElementSchemaRegistry} from './schema/element_schema_registry';
|
||||
export * from './i18n/index';
|
||||
export * from './template_parser/template_ast';
|
||||
export * from './private_export';
|
@ -6,35 +6,30 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit, Type} from '@angular/core';
|
||||
|
||||
import {MapWrapper} from './facade/collection';
|
||||
import {LifecycleHooks, reflector} from './private_import_core';
|
||||
|
||||
const LIFECYCLE_INTERFACES: Map<any, Type<any>> = MapWrapper.createFromPairs([
|
||||
[LifecycleHooks.OnInit, OnInit],
|
||||
[LifecycleHooks.OnDestroy, OnDestroy],
|
||||
[LifecycleHooks.DoCheck, DoCheck],
|
||||
[LifecycleHooks.OnChanges, OnChanges],
|
||||
[LifecycleHooks.AfterContentInit, AfterContentInit],
|
||||
[LifecycleHooks.AfterContentChecked, AfterContentChecked],
|
||||
[LifecycleHooks.AfterViewInit, AfterViewInit],
|
||||
[LifecycleHooks.AfterViewChecked, AfterViewChecked],
|
||||
]);
|
||||
|
||||
const LIFECYCLE_PROPS: Map<any, string> = MapWrapper.createFromPairs([
|
||||
[LifecycleHooks.OnInit, 'ngOnInit'],
|
||||
[LifecycleHooks.OnDestroy, 'ngOnDestroy'],
|
||||
[LifecycleHooks.DoCheck, 'ngDoCheck'],
|
||||
[LifecycleHooks.OnChanges, 'ngOnChanges'],
|
||||
[LifecycleHooks.AfterContentInit, 'ngAfterContentInit'],
|
||||
[LifecycleHooks.AfterContentChecked, 'ngAfterContentChecked'],
|
||||
[LifecycleHooks.AfterViewInit, 'ngAfterViewInit'],
|
||||
[LifecycleHooks.AfterViewChecked, 'ngAfterViewChecked'],
|
||||
]);
|
||||
|
||||
export function hasLifecycleHook(hook: LifecycleHooks, token: any): boolean {
|
||||
var lcInterface = LIFECYCLE_INTERFACES.get(hook);
|
||||
var lcProp = LIFECYCLE_PROPS.get(hook);
|
||||
return reflector.hasLifecycleHook(token, lcInterface, lcProp);
|
||||
return reflector.hasLifecycleHook(token, getHookName(hook));
|
||||
}
|
||||
|
||||
function getHookName(hook: LifecycleHooks): string {
|
||||
switch (hook) {
|
||||
case LifecycleHooks.OnInit:
|
||||
return 'ngOnInit';
|
||||
case LifecycleHooks.OnDestroy:
|
||||
return 'ngOnDestroy';
|
||||
case LifecycleHooks.DoCheck:
|
||||
return 'ngDoCheck';
|
||||
case LifecycleHooks.OnChanges:
|
||||
return 'ngOnChanges';
|
||||
case LifecycleHooks.AfterContentInit:
|
||||
return 'ngAfterContentInit';
|
||||
case LifecycleHooks.AfterContentChecked:
|
||||
return 'ngAfterContentChecked';
|
||||
case LifecycleHooks.AfterViewInit:
|
||||
return 'ngAfterViewInit';
|
||||
case LifecycleHooks.AfterViewChecked:
|
||||
return 'ngAfterViewChecked';
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import {AnimationAnimateMetadata, AnimationEntryMetadata, AnimationGroupMetadata
|
||||
import {assertArrayOfStrings, assertInterpolationSymbols} from './assertions';
|
||||
import * as cpl from './compile_metadata';
|
||||
import {DirectiveResolver} from './directive_resolver';
|
||||
import {isBlank, isPresent, isString, stringify} from './facade/lang';
|
||||
import {isBlank, isPresent, stringify} from './facade/lang';
|
||||
import {Identifiers, resolveIdentifierToken} from './identifiers';
|
||||
import {hasLifecycleHook} from './lifecycle_reflector';
|
||||
import {NgModuleResolver} from './ng_module_resolver';
|
||||
@ -116,8 +116,7 @@ export class CompileMetadataResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
getDirectiveMetadata(directiveType: Type<any>, throwIfNotFound = true):
|
||||
cpl.CompileDirectiveMetadata {
|
||||
getDirectiveMetadata(directiveType: any, throwIfNotFound = true): cpl.CompileDirectiveMetadata {
|
||||
directiveType = resolveForwardRef(directiveType);
|
||||
let meta = this._directiveCache.get(directiveType);
|
||||
if (!meta) {
|
||||
@ -569,7 +568,7 @@ export class CompileMetadataResolver {
|
||||
getTokenMetadata(token: any): cpl.CompileTokenMetadata {
|
||||
token = resolveForwardRef(token);
|
||||
let compileToken: cpl.CompileTokenMetadata;
|
||||
if (isString(token)) {
|
||||
if (typeof token === 'string') {
|
||||
compileToken = new cpl.CompileTokenMetadata({value: token});
|
||||
} else {
|
||||
compileToken = new cpl.CompileTokenMetadata({
|
||||
|
@ -34,7 +34,9 @@ export class ExpansionCase implements Node {
|
||||
}
|
||||
|
||||
export class Attribute implements Node {
|
||||
constructor(public name: string, public value: string, public sourceSpan: ParseSourceSpan) {}
|
||||
constructor(
|
||||
public name: string, public value: string, public sourceSpan: ParseSourceSpan,
|
||||
public valueSpan?: ParseSourceSpan) {}
|
||||
visit(visitor: Visitor, context: any): any { return visitor.visitAttribute(this, context); }
|
||||
}
|
||||
|
||||
@ -52,6 +54,10 @@ export class Comment implements Node {
|
||||
}
|
||||
|
||||
export interface Visitor {
|
||||
// Returning a truthy value from `visit()` will prevent `visitAll()` from the call to the typed
|
||||
// method and result returned will become the result included in `visitAll()`s result array.
|
||||
visit?(node: Node, context: any): any;
|
||||
|
||||
visitElement(element: Element, context: any): any;
|
||||
visitAttribute(attribute: Attribute, context: any): any;
|
||||
visitText(text: Text, context: any): any;
|
||||
@ -62,8 +68,12 @@ export interface Visitor {
|
||||
|
||||
export function visitAll(visitor: Visitor, nodes: Node[], context: any = null): any[] {
|
||||
let result: any[] = [];
|
||||
|
||||
let visit = visitor.visit ?
|
||||
(ast: Node) => visitor.visit(ast, context) || ast.visit(visitor, context) :
|
||||
(ast: Node) => ast.visit(visitor, context);
|
||||
nodes.forEach(ast => {
|
||||
const astResult = ast.visit(visitor, context);
|
||||
const astResult = visit(ast);
|
||||
if (astResult) {
|
||||
result.push(astResult);
|
||||
}
|
||||
|
@ -331,12 +331,15 @@ class _TreeBuilder {
|
||||
const fullName = mergeNsAndName(attrName.parts[0], attrName.parts[1]);
|
||||
let end = attrName.sourceSpan.end;
|
||||
let value = '';
|
||||
let valueSpan: ParseSourceSpan;
|
||||
if (this._peek.type === lex.TokenType.ATTR_VALUE) {
|
||||
const valueToken = this._advance();
|
||||
value = valueToken.parts[0];
|
||||
end = valueToken.sourceSpan.end;
|
||||
valueSpan = valueToken.sourceSpan;
|
||||
}
|
||||
return new html.Attribute(fullName, value, new ParseSourceSpan(attrName.sourceSpan.start, end));
|
||||
return new html.Attribute(
|
||||
fullName, value, new ParseSourceSpan(attrName.sourceSpan.start, end), valueSpan);
|
||||
}
|
||||
|
||||
private _getParentElement(): html.Element {
|
||||
|
@ -163,11 +163,11 @@ class _InjectorBuilder {
|
||||
if (isPresent(provider.useExisting)) {
|
||||
result = this._getDependency(new CompileDiDependencyMetadata({token: provider.useExisting}));
|
||||
} else if (isPresent(provider.useFactory)) {
|
||||
var deps = isPresent(provider.deps) ? provider.deps : provider.useFactory.diDeps;
|
||||
var deps = provider.deps || provider.useFactory.diDeps;
|
||||
var depsExpr = deps.map((dep) => this._getDependency(dep));
|
||||
result = o.importExpr(provider.useFactory).callFn(depsExpr);
|
||||
} else if (isPresent(provider.useClass)) {
|
||||
var deps = isPresent(provider.deps) ? provider.deps : provider.useClass.diDeps;
|
||||
var deps = provider.deps || provider.useClass.diDeps;
|
||||
var depsExpr = deps.map((dep) => this._getDependency(dep));
|
||||
result =
|
||||
o.importExpr(provider.useClass).instantiate(depsExpr, o.importType(provider.useClass));
|
||||
|
@ -12,6 +12,7 @@ import {AnimationCompiler} from './animation/animation_compiler';
|
||||
import {AnimationParser} from './animation/animation_parser';
|
||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, CompileProviderMetadata, StaticSymbol, createHostComponentMeta} from './compile_metadata';
|
||||
import {DirectiveNormalizer} from './directive_normalizer';
|
||||
import {DirectiveWrapperCompileResult, DirectiveWrapperCompiler} from './directive_wrapper_compiler';
|
||||
import {Identifiers, resolveIdentifier, resolveIdentifierToken} from './identifiers';
|
||||
import {CompileMetadataResolver} from './metadata_resolver';
|
||||
import {NgModuleCompiler} from './ng_module_compiler';
|
||||
@ -19,14 +20,31 @@ import {OutputEmitter} from './output/abstract_emitter';
|
||||
import * as o from './output/output_ast';
|
||||
import {CompiledStylesheet, StyleCompiler} from './style_compiler';
|
||||
import {TemplateParser} from './template_parser/template_parser';
|
||||
import {ComponentFactoryDependency, ViewCompileResult, ViewCompiler, ViewFactoryDependency} from './view_compiler/view_compiler';
|
||||
import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewCompileResult, ViewCompiler, ViewFactoryDependency} from './view_compiler/view_compiler';
|
||||
|
||||
export class SourceModule {
|
||||
constructor(public moduleUrl: string, public source: string) {}
|
||||
}
|
||||
|
||||
export class NgModulesSummary {
|
||||
constructor(public ngModuleByComponent: Map<StaticSymbol, CompileNgModuleMetadata>) {}
|
||||
constructor(
|
||||
public ngModuleByDirective: Map<StaticSymbol, CompileNgModuleMetadata>,
|
||||
public ngModules: CompileNgModuleMetadata[]) {}
|
||||
}
|
||||
|
||||
export function analyzeModules(
|
||||
ngModules: StaticSymbol[], metadataResolver: CompileMetadataResolver) {
|
||||
const ngModuleByDirective = new Map<StaticSymbol, CompileNgModuleMetadata>();
|
||||
const modules: CompileNgModuleMetadata[] = [];
|
||||
|
||||
ngModules.forEach((ngModule) => {
|
||||
const ngModuleMeta = metadataResolver.getNgModuleMetadata(<any>ngModule);
|
||||
modules.push(ngModuleMeta);
|
||||
ngModuleMeta.declaredDirectives.forEach((dirMeta: CompileDirectiveMetadata) => {
|
||||
ngModuleByDirective.set(dirMeta.type.reference, ngModuleMeta);
|
||||
});
|
||||
});
|
||||
return new NgModulesSummary(ngModuleByDirective, modules);
|
||||
}
|
||||
|
||||
export class OfflineCompiler {
|
||||
@ -37,21 +55,12 @@ export class OfflineCompiler {
|
||||
private _metadataResolver: CompileMetadataResolver,
|
||||
private _directiveNormalizer: DirectiveNormalizer, private _templateParser: TemplateParser,
|
||||
private _styleCompiler: StyleCompiler, private _viewCompiler: ViewCompiler,
|
||||
private _dirWrapperCompiler: DirectiveWrapperCompiler,
|
||||
private _ngModuleCompiler: NgModuleCompiler, private _outputEmitter: OutputEmitter,
|
||||
private _localeId: string, private _translationFormat: string) {}
|
||||
|
||||
analyzeModules(ngModules: StaticSymbol[]): NgModulesSummary {
|
||||
const ngModuleByComponent = new Map<StaticSymbol, CompileNgModuleMetadata>();
|
||||
|
||||
ngModules.forEach((ngModule) => {
|
||||
const ngModuleMeta = this._metadataResolver.getNgModuleMetadata(<any>ngModule);
|
||||
ngModuleMeta.declaredDirectives.forEach((dirMeta) => {
|
||||
if (dirMeta.isComponent) {
|
||||
ngModuleByComponent.set(dirMeta.type.reference, ngModuleMeta);
|
||||
}
|
||||
});
|
||||
});
|
||||
return new NgModulesSummary(ngModuleByComponent);
|
||||
return analyzeModules(ngModules, this._metadataResolver);
|
||||
}
|
||||
|
||||
clearCache() {
|
||||
@ -60,7 +69,7 @@ export class OfflineCompiler {
|
||||
}
|
||||
|
||||
compile(
|
||||
moduleUrl: string, ngModulesSummary: NgModulesSummary, components: StaticSymbol[],
|
||||
moduleUrl: string, ngModulesSummary: NgModulesSummary, directives: StaticSymbol[],
|
||||
ngModules: StaticSymbol[]): Promise<SourceModule[]> {
|
||||
const fileSuffix = _splitTypescriptSuffix(moduleUrl)[1];
|
||||
const statements: o.Statement[] = [];
|
||||
@ -71,11 +80,18 @@ export class OfflineCompiler {
|
||||
exportedVars.push(
|
||||
...ngModules.map((ngModuleType) => this._compileModule(ngModuleType, statements)));
|
||||
|
||||
// compile directive wrappers
|
||||
exportedVars.push(...directives.map(
|
||||
(directiveType) => this._compileDirectiveWrapper(directiveType, statements)));
|
||||
|
||||
// compile components
|
||||
return Promise
|
||||
.all(components.map((compType) => {
|
||||
const compMeta = this._metadataResolver.getDirectiveMetadata(<any>compType);
|
||||
const ngModule = ngModulesSummary.ngModuleByComponent.get(compType);
|
||||
.all(directives.map((dirType) => {
|
||||
const compMeta = this._metadataResolver.getDirectiveMetadata(<any>dirType);
|
||||
if (!compMeta.isComponent) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
const ngModule = ngModulesSummary.ngModuleByDirective.get(dirType);
|
||||
if (!ngModule) {
|
||||
throw new Error(`Cannot determine the module for component ${compMeta.type.name}!`);
|
||||
}
|
||||
@ -139,6 +155,15 @@ export class OfflineCompiler {
|
||||
return appCompileResult.ngModuleFactoryVar;
|
||||
}
|
||||
|
||||
private _compileDirectiveWrapper(directiveType: StaticSymbol, targetStatements: o.Statement[]):
|
||||
string {
|
||||
const dirMeta = this._metadataResolver.getDirectiveMetadata(directiveType);
|
||||
const dirCompileResult = this._dirWrapperCompiler.compile(dirMeta);
|
||||
|
||||
targetStatements.push(...dirCompileResult.statements);
|
||||
return dirCompileResult.dirWrapperClassVar;
|
||||
}
|
||||
|
||||
private _compileComponentFactory(
|
||||
compMeta: CompileDirectiveMetadata, fileSuffix: string,
|
||||
targetStatements: o.Statement[]): string {
|
||||
@ -208,6 +233,9 @@ function _resolveViewStatements(compileResult: ViewCompileResult): o.Statement[]
|
||||
const cfd = <ComponentFactoryDependency>dep;
|
||||
cfd.placeholder.name = _componentFactoryName(cfd.comp);
|
||||
cfd.placeholder.moduleUrl = _ngfactoryModuleUrl(cfd.comp.moduleUrl);
|
||||
} else if (dep instanceof DirectiveWrapperDependency) {
|
||||
const dwd = <DirectiveWrapperDependency>dep;
|
||||
dwd.placeholder.moduleUrl = _ngfactoryModuleUrl(dwd.dir.moduleUrl);
|
||||
}
|
||||
});
|
||||
return compileResult.statements;
|
||||
@ -222,8 +250,8 @@ function _resolveStyleStatements(
|
||||
return compileResult.statements;
|
||||
}
|
||||
|
||||
function _ngfactoryModuleUrl(compUrl: string): string {
|
||||
const urlWithSuffix = _splitTypescriptSuffix(compUrl);
|
||||
function _ngfactoryModuleUrl(dirUrl: string): string {
|
||||
const urlWithSuffix = _splitTypescriptSuffix(dirUrl);
|
||||
return `${urlWithSuffix[0]}.ngfactory${urlWithSuffix[1]}`;
|
||||
}
|
||||
|
||||
|
@ -6,14 +6,14 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {StringWrapper, isBlank, isPresent, isString} from '../facade/lang';
|
||||
import {isBlank, isPresent} from '../facade/lang';
|
||||
|
||||
import * as o from './output_ast';
|
||||
|
||||
var _SINGLE_QUOTE_ESCAPE_STRING_RE = /'|\\|\n|\r|\$/g;
|
||||
var _LEGAL_IDENTIFIER_RE = /^[$A-Z_][0-9A-Z_$]*$/i;
|
||||
export var CATCH_ERROR_VAR = o.variable('error');
|
||||
export var CATCH_STACK_VAR = o.variable('stack');
|
||||
const _SINGLE_QUOTE_ESCAPE_STRING_RE = /'|\\|\n|\r|\$/g;
|
||||
const _LEGAL_IDENTIFIER_RE = /^[$A-Z_][0-9A-Z_$]*$/i;
|
||||
export const CATCH_ERROR_VAR = o.variable('error');
|
||||
export const CATCH_STACK_VAR = o.variable('stack');
|
||||
|
||||
export abstract class OutputEmitter {
|
||||
abstract emitStatements(moduleUrl: string, stmts: o.Statement[], exportedVars: string[]): string;
|
||||
@ -253,7 +253,7 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
|
||||
visitLiteralExpr(ast: o.LiteralExpr, ctx: EmitterVisitorContext, absentValue: string = 'null'):
|
||||
any {
|
||||
var value = ast.value;
|
||||
if (isString(value)) {
|
||||
if (typeof value === 'string') {
|
||||
ctx.print(escapeIdentifier(value, this._escapeDollarInStrings));
|
||||
} else if (isBlank(value)) {
|
||||
ctx.print(absentValue);
|
||||
@ -368,7 +368,7 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
|
||||
var useNewLine = ast.entries.length > 1;
|
||||
ctx.print(`{`, useNewLine);
|
||||
ctx.incIndent();
|
||||
this.visitAllObjects((entry: any /** TODO #9100 */) => {
|
||||
this.visitAllObjects(entry => {
|
||||
ctx.print(`${escapeIdentifier(entry[0], this._escapeDollarInStrings, false)}: `);
|
||||
entry[1].visitExpression(this, ctx);
|
||||
}, ast.entries, ctx, ',', useNewLine);
|
||||
@ -381,12 +381,11 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
|
||||
expressions: o.Expression[], ctx: EmitterVisitorContext, separator: string,
|
||||
newLine: boolean = false): void {
|
||||
this.visitAllObjects(
|
||||
(expr: any /** TODO #9100 */) => expr.visitExpression(this, ctx), expressions, ctx,
|
||||
separator, newLine);
|
||||
expr => expr.visitExpression(this, ctx), expressions, ctx, separator, newLine);
|
||||
}
|
||||
|
||||
visitAllObjects(
|
||||
handler: Function, expressions: any, ctx: EmitterVisitorContext, separator: string,
|
||||
visitAllObjects<T>(
|
||||
handler: (t: T) => void, expressions: T[], ctx: EmitterVisitorContext, separator: string,
|
||||
newLine: boolean = false): void {
|
||||
for (var i = 0; i < expressions.length; i++) {
|
||||
if (i > 0) {
|
||||
@ -409,18 +408,17 @@ export function escapeIdentifier(
|
||||
if (isBlank(input)) {
|
||||
return null;
|
||||
}
|
||||
var body = StringWrapper.replaceAllMapped(
|
||||
input, _SINGLE_QUOTE_ESCAPE_STRING_RE, (match: any /** TODO #9100 */) => {
|
||||
if (match[0] == '$') {
|
||||
return escapeDollar ? '\\$' : '$';
|
||||
} else if (match[0] == '\n') {
|
||||
return '\\n';
|
||||
} else if (match[0] == '\r') {
|
||||
return '\\r';
|
||||
} else {
|
||||
return `\\${match[0]}`;
|
||||
}
|
||||
});
|
||||
var body = input.replace(_SINGLE_QUOTE_ESCAPE_STRING_RE, (...match: string[]) => {
|
||||
if (match[0] == '$') {
|
||||
return escapeDollar ? '\\$' : '$';
|
||||
} else if (match[0] == '\n') {
|
||||
return '\\n';
|
||||
} else if (match[0] == '\r') {
|
||||
return '\\r';
|
||||
} else {
|
||||
return `\\${match[0]}`;
|
||||
}
|
||||
});
|
||||
let requiresQuotes = alwaysQuote || !_LEGAL_IDENTIFIER_RE.test(body);
|
||||
return requiresQuotes ? `'${body}'` : body;
|
||||
}
|
||||
|
@ -144,11 +144,11 @@ export abstract class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
|
||||
}
|
||||
|
||||
private _visitParams(params: o.FnParam[], ctx: EmitterVisitorContext): void {
|
||||
this.visitAllObjects((param: any /** TODO #9100 */) => ctx.print(param.name), params, ctx, ',');
|
||||
this.visitAllObjects(param => ctx.print(param.name), params, ctx, ',');
|
||||
}
|
||||
|
||||
getBuiltinMethodName(method: o.BuiltinMethod): string {
|
||||
var name: any /** TODO #9100 */;
|
||||
var name: string;
|
||||
switch (method) {
|
||||
case o.BuiltinMethod.ConcatArray:
|
||||
name = 'concat';
|
||||
|
@ -20,7 +20,7 @@ export class JavaScriptEmitter implements OutputEmitter {
|
||||
var converter = new JsEmitterVisitor(moduleUrl);
|
||||
var ctx = EmitterVisitorContext.createRoot(exportedVars);
|
||||
converter.visitAllStatements(stmts, ctx);
|
||||
var srcParts: any[] /** TODO #9100 */ = [];
|
||||
var srcParts: string[] = [];
|
||||
converter.importsWithPrefixes.forEach((prefix, importedModuleUrl) => {
|
||||
// Note: can't write the real word for import as it screws up system.js auto detection...
|
||||
srcParts.push(
|
||||
|
@ -8,9 +8,7 @@
|
||||
|
||||
|
||||
import {CompileIdentifierMetadata} from '../compile_metadata';
|
||||
import {isPresent, isString} from '../facade/lang';
|
||||
|
||||
|
||||
import {isPresent} from '../facade/lang';
|
||||
|
||||
//// Types
|
||||
export enum TypeModifier {
|
||||
@ -196,7 +194,7 @@ export class ReadVarExpr extends Expression {
|
||||
|
||||
constructor(name: string|BuiltinVar, type: Type = null) {
|
||||
super(type);
|
||||
if (isString(name)) {
|
||||
if (typeof name === 'string') {
|
||||
this.name = name;
|
||||
this.builtin = null;
|
||||
} else {
|
||||
@ -215,7 +213,7 @@ export class ReadVarExpr extends Expression {
|
||||
export class WriteVarExpr extends Expression {
|
||||
public value: Expression;
|
||||
constructor(public name: string, value: Expression, type: Type = null) {
|
||||
super(isPresent(type) ? type : value.type);
|
||||
super(type || value.type);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@ -233,7 +231,7 @@ export class WriteKeyExpr extends Expression {
|
||||
public value: Expression;
|
||||
constructor(
|
||||
public receiver: Expression, public index: Expression, value: Expression, type: Type = null) {
|
||||
super(isPresent(type) ? type : value.type);
|
||||
super(type || value.type);
|
||||
this.value = value;
|
||||
}
|
||||
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
||||
@ -246,7 +244,7 @@ export class WritePropExpr extends Expression {
|
||||
public value: Expression;
|
||||
constructor(
|
||||
public receiver: Expression, public name: string, value: Expression, type: Type = null) {
|
||||
super(isPresent(type) ? type : value.type);
|
||||
super(type || value.type);
|
||||
this.value = value;
|
||||
}
|
||||
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
||||
@ -267,7 +265,7 @@ export class InvokeMethodExpr extends Expression {
|
||||
public receiver: Expression, method: string|BuiltinMethod, public args: Expression[],
|
||||
type: Type = null) {
|
||||
super(type);
|
||||
if (isString(method)) {
|
||||
if (typeof method === 'string') {
|
||||
this.name = method;
|
||||
this.builtin = null;
|
||||
} else {
|
||||
@ -322,7 +320,7 @@ export class ConditionalExpr extends Expression {
|
||||
constructor(
|
||||
public condition: Expression, trueCase: Expression, public falseCase: Expression = null,
|
||||
type: Type = null) {
|
||||
super(isPresent(type) ? type : trueCase.type);
|
||||
super(type || trueCase.type);
|
||||
this.trueCase = trueCase;
|
||||
}
|
||||
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
||||
@ -369,7 +367,7 @@ export class BinaryOperatorExpr extends Expression {
|
||||
public lhs: Expression;
|
||||
constructor(
|
||||
public operator: BinaryOperator, lhs: Expression, public rhs: Expression, type: Type = null) {
|
||||
super(isPresent(type) ? type : lhs.type);
|
||||
super(type || lhs.type);
|
||||
this.lhs = lhs;
|
||||
}
|
||||
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
||||
@ -416,7 +414,7 @@ export class LiteralArrayExpr extends Expression {
|
||||
|
||||
export class LiteralMapExpr extends Expression {
|
||||
public valueType: Type = null;
|
||||
constructor(public entries: Array<Array<string|Expression>>, type: MapType = null) {
|
||||
constructor(public entries: [string, Expression][], type: MapType = null) {
|
||||
super(type);
|
||||
if (isPresent(type)) {
|
||||
this.valueType = type.valueType;
|
||||
@ -479,7 +477,7 @@ export class DeclareVarStmt extends Statement {
|
||||
public name: string, public value: Expression, type: Type = null,
|
||||
modifiers: StmtModifier[] = null) {
|
||||
super(modifiers);
|
||||
this.type = isPresent(type) ? type : value.type;
|
||||
this.type = type || value.type;
|
||||
}
|
||||
|
||||
visitStatement(visitor: StatementVisitor, context: any): any {
|
||||
@ -625,7 +623,7 @@ export class ExpressionTransformer implements StatementVisitor, ExpressionVisito
|
||||
expr.value.visitExpression(this, context));
|
||||
}
|
||||
visitInvokeMethodExpr(ast: InvokeMethodExpr, context: any): any {
|
||||
var method = isPresent(ast.builtin) ? ast.builtin : ast.name;
|
||||
var method = ast.builtin || ast.name;
|
||||
return new InvokeMethodExpr(
|
||||
ast.receiver.visitExpression(this, context), method,
|
||||
this.visitAllExpressions(ast.args, context), ast.type);
|
||||
@ -673,9 +671,11 @@ export class ExpressionTransformer implements StatementVisitor, ExpressionVisito
|
||||
visitLiteralArrayExpr(ast: LiteralArrayExpr, context: any): any {
|
||||
return new LiteralArrayExpr(this.visitAllExpressions(ast.entries, context));
|
||||
}
|
||||
|
||||
visitLiteralMapExpr(ast: LiteralMapExpr, context: any): any {
|
||||
return new LiteralMapExpr(ast.entries.map(
|
||||
(entry) => [entry[0], (<Expression>entry[1]).visitExpression(this, context)]));
|
||||
const entries = ast.entries.map(
|
||||
(entry): [string, Expression] => [entry[0], entry[1].visitExpression(this, context), ]);
|
||||
return new LiteralMapExpr(entries);
|
||||
}
|
||||
visitAllExpressions(exprs: Expression[], context: any): Expression[] {
|
||||
return exprs.map(expr => expr.visitExpression(this, context));
|
||||
@ -881,8 +881,7 @@ export function literalArr(values: Expression[], type: Type = null): LiteralArra
|
||||
return new LiteralArrayExpr(values, type);
|
||||
}
|
||||
|
||||
export function literalMap(
|
||||
values: Array<Array<string|Expression>>, type: MapType = null): LiteralMapExpr {
|
||||
export function literalMap(values: [string, Expression][], type: MapType = null): LiteralMapExpr {
|
||||
return new LiteralMapExpr(values, type);
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ function createDynamicClass(
|
||||
_executeFunctionStatements(
|
||||
ctorParamNames, args, _classStmt.constructorMethod.body, instanceCtx, _visitor);
|
||||
};
|
||||
var superClass = _classStmt.parent.visitExpression(_visitor, _ctx);
|
||||
var superClass = _classStmt.parent ? _classStmt.parent.visitExpression(_visitor, _ctx) : Object;
|
||||
ctor.prototype = Object.create(superClass.prototype, propertyDescriptors);
|
||||
return ctor;
|
||||
}
|
||||
|
@ -6,13 +6,26 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {evalExpression, isPresent} from '../facade/lang';
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {sanitizeIdentifier} from '../util';
|
||||
|
||||
import {EmitterVisitorContext} from './abstract_emitter';
|
||||
import {AbstractJsEmitterVisitor} from './abstract_js_emitter';
|
||||
import * as o from './output_ast';
|
||||
|
||||
function evalExpression(
|
||||
sourceUrl: string, expr: string, declarations: string, vars: {[key: string]: any}): any {
|
||||
const fnBody = `${declarations}\nreturn ${expr}\n//# sourceURL=${sourceUrl}`;
|
||||
const fnArgNames: string[] = [];
|
||||
const fnArgValues: any[] = [];
|
||||
for (const argName in vars) {
|
||||
fnArgNames.push(argName);
|
||||
fnArgValues.push(vars[argName]);
|
||||
}
|
||||
return new Function(...fnArgNames.concat(fnBody))(...fnArgValues);
|
||||
}
|
||||
|
||||
|
||||
export function jitStatements(
|
||||
sourceUrl: string, statements: o.Statement[], resultVar: string): any {
|
||||
var converter = new JitEmitterVisitor();
|
||||
@ -26,9 +39,9 @@ class JitEmitterVisitor extends AbstractJsEmitterVisitor {
|
||||
private _evalArgValues: any[] = [];
|
||||
|
||||
getArgs(): {[key: string]: any} {
|
||||
var result = {};
|
||||
var result: {[key: string]: any} = {};
|
||||
for (var i = 0; i < this._evalArgNames.length; i++) {
|
||||
(result as any /** TODO #9100 */)[this._evalArgNames[i]] = this._evalArgValues[i];
|
||||
result[this._evalArgNames[i]] = this._evalArgValues[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -8,24 +8,20 @@
|
||||
|
||||
|
||||
import {CompileIdentifierMetadata} from '../compile_metadata';
|
||||
import {isArray, isBlank, isPresent} from '../facade/lang';
|
||||
import {isBlank, isPresent} from '../facade/lang';
|
||||
|
||||
import {AbstractEmitterVisitor, CATCH_ERROR_VAR, CATCH_STACK_VAR, EmitterVisitorContext, OutputEmitter} from './abstract_emitter';
|
||||
import * as o from './output_ast';
|
||||
import {ImportGenerator} from './path_util';
|
||||
|
||||
var _debugModuleUrl = 'asset://debug/lib';
|
||||
const _debugModuleUrl = 'asset://debug/lib';
|
||||
|
||||
export function debugOutputAstAsTypeScript(ast: o.Statement | o.Expression | o.Type | any[]):
|
||||
string {
|
||||
var converter = new _TsEmitterVisitor(_debugModuleUrl);
|
||||
var ctx = EmitterVisitorContext.createRoot([]);
|
||||
var asts: any[];
|
||||
if (isArray(ast)) {
|
||||
asts = <any[]>ast;
|
||||
} else {
|
||||
asts = [ast];
|
||||
}
|
||||
const converter = new _TsEmitterVisitor(_debugModuleUrl);
|
||||
const ctx = EmitterVisitorContext.createRoot([]);
|
||||
const asts: any[] = Array.isArray(ast) ? ast : [ast];
|
||||
|
||||
asts.forEach((ast) => {
|
||||
if (ast instanceof o.Statement) {
|
||||
ast.visitStatement(converter, ctx);
|
||||
@ -46,7 +42,7 @@ export class TypeScriptEmitter implements OutputEmitter {
|
||||
var converter = new _TsEmitterVisitor(moduleUrl);
|
||||
var ctx = EmitterVisitorContext.createRoot(exportedVars);
|
||||
converter.visitAllStatements(stmts, ctx);
|
||||
var srcParts: any[] /** TODO #9100 */ = [];
|
||||
var srcParts: string[] = [];
|
||||
converter.importsWithPrefixes.forEach((prefix, importedModuleUrl) => {
|
||||
// Note: can't write the real word for import as it screws up system.js auto detection...
|
||||
srcParts.push(
|
||||
@ -75,6 +71,22 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
||||
super.visitLiteralExpr(ast, ctx, '(null as any)');
|
||||
}
|
||||
|
||||
|
||||
// Temporary workaround to support strictNullCheck enabled consumers of ngc emit.
|
||||
// In SNC mode, [] have the type never[], so we cast here to any[].
|
||||
// TODO: narrow the cast to a more explicit type, or use a pattern that does not
|
||||
// start with [].concat. see https://github.com/angular/angular/pull/11846
|
||||
visitLiteralArrayExpr(ast: o.LiteralArrayExpr, ctx: EmitterVisitorContext): any {
|
||||
if (ast.entries.length === 0) {
|
||||
ctx.print('(');
|
||||
}
|
||||
const result = super.visitLiteralArrayExpr(ast, ctx);
|
||||
if (ast.entries.length === 0) {
|
||||
ctx.print(' as any[])');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
visitExternalExpr(ast: o.ExternalExpr, ctx: EmitterVisitorContext): any {
|
||||
this._visitIdentifier(ast.value, ast.typeParams, ctx);
|
||||
return null;
|
||||
@ -227,7 +239,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
||||
}
|
||||
|
||||
visitBuiltintType(type: o.BuiltinType, ctx: EmitterVisitorContext): any {
|
||||
var typeStr: any /** TODO #9100 */;
|
||||
var typeStr: string;
|
||||
switch (type.name) {
|
||||
case o.BuiltinTypeName.Bool:
|
||||
typeStr = 'boolean';
|
||||
@ -291,7 +303,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
||||
}
|
||||
|
||||
private _visitParams(params: o.FnParam[], ctx: EmitterVisitorContext): void {
|
||||
this.visitAllObjects((param: any /** TODO #9100 */) => {
|
||||
this.visitAllObjects(param => {
|
||||
ctx.print(param.name);
|
||||
ctx.print(':');
|
||||
this.visitType(param.type, ctx);
|
||||
@ -320,8 +332,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
||||
}
|
||||
if (isPresent(typeParams) && typeParams.length > 0) {
|
||||
ctx.print(`<`);
|
||||
this.visitAllObjects(
|
||||
(type: any /** TODO #9100 */) => type.visitType(this, ctx), typeParams, ctx, ',');
|
||||
this.visitAllObjects(type => type.visitType(this, ctx), typeParams, ctx, ',');
|
||||
ctx.print(`>`);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class _ValueOutputAstTransformer implements ValueTransformer {
|
||||
}
|
||||
|
||||
visitStringMap(map: {[key: string]: any}, type: o.MapType): o.Expression {
|
||||
var entries: Array<string|o.Expression>[] = [];
|
||||
const entries: [string, o.Expression][] = [];
|
||||
Object.keys(map).forEach(key => { entries.push([key, visitValue(map[key], this, null)]); });
|
||||
return o.literalMap(entries, type);
|
||||
}
|
||||
|
@ -1,112 +0,0 @@
|
||||
/**
|
||||
* @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 directive_normalizer from './directive_normalizer';
|
||||
import * as lexer from './expression_parser/lexer';
|
||||
import * as parser from './expression_parser/parser';
|
||||
import * as metadata_resolver from './metadata_resolver';
|
||||
import * as html_parser from './ml_parser/html_parser';
|
||||
import * as interpolation_config from './ml_parser/interpolation_config';
|
||||
import * as ng_module_compiler from './ng_module_compiler';
|
||||
import * as path_util from './output/path_util';
|
||||
import * as ts_emitter from './output/ts_emitter';
|
||||
import * as parse_util from './parse_util';
|
||||
import * as dom_element_schema_registry from './schema/dom_element_schema_registry';
|
||||
import * as selector from './selector';
|
||||
import * as style_compiler from './style_compiler';
|
||||
import * as template_parser from './template_parser/template_parser';
|
||||
import * as view_compiler from './view_compiler/view_compiler';
|
||||
|
||||
export const __compiler_private__: {
|
||||
_SelectorMatcher?: selector.SelectorMatcher; SelectorMatcher: typeof selector.SelectorMatcher;
|
||||
|
||||
_CssSelector?: selector.CssSelector;
|
||||
CssSelector: typeof selector.CssSelector;
|
||||
|
||||
_AssetUrl?: path_util.AssetUrl;
|
||||
AssetUrl: typeof path_util.AssetUrl;
|
||||
|
||||
_ImportGenerator?: path_util.ImportGenerator;
|
||||
ImportGenerator: typeof path_util.ImportGenerator;
|
||||
|
||||
_CompileMetadataResolver?: metadata_resolver.CompileMetadataResolver;
|
||||
CompileMetadataResolver: typeof metadata_resolver.CompileMetadataResolver;
|
||||
|
||||
_HtmlParser?: html_parser.HtmlParser;
|
||||
HtmlParser: typeof html_parser.HtmlParser;
|
||||
|
||||
_InterpolationConfig?: interpolation_config.InterpolationConfig;
|
||||
InterpolationConfig: typeof interpolation_config.InterpolationConfig;
|
||||
|
||||
_DirectiveNormalizer?: directive_normalizer.DirectiveNormalizer;
|
||||
DirectiveNormalizer: typeof directive_normalizer.DirectiveNormalizer;
|
||||
|
||||
_Lexer?: lexer.Lexer;
|
||||
Lexer: typeof lexer.Lexer;
|
||||
|
||||
_Parser?: parser.Parser;
|
||||
Parser: typeof parser.Parser;
|
||||
|
||||
_ParseLocation?: parse_util.ParseLocation;
|
||||
ParseLocation: typeof parse_util.ParseLocation;
|
||||
|
||||
_ParseError?: parse_util.ParseError;
|
||||
ParseError: typeof parse_util.ParseError;
|
||||
|
||||
_ParseErrorLevel?: parse_util.ParseErrorLevel;
|
||||
ParseErrorLevel: typeof parse_util.ParseErrorLevel;
|
||||
|
||||
_ParseSourceFile?: parse_util.ParseSourceFile;
|
||||
ParseSourceFile: typeof parse_util.ParseSourceFile;
|
||||
|
||||
_ParseSourceSpan?: parse_util.ParseSourceSpan;
|
||||
ParseSourceSpan: typeof parse_util.ParseSourceSpan;
|
||||
|
||||
_TemplateParser?: template_parser.TemplateParser;
|
||||
TemplateParser: typeof template_parser.TemplateParser;
|
||||
|
||||
_TemplateParseResult?: template_parser.TemplateParseResult;
|
||||
|
||||
_DomElementSchemaRegistry?: dom_element_schema_registry.DomElementSchemaRegistry;
|
||||
DomElementSchemaRegistry: typeof dom_element_schema_registry.DomElementSchemaRegistry;
|
||||
|
||||
_StyleCompiler?: style_compiler.StyleCompiler;
|
||||
StyleCompiler: typeof style_compiler.StyleCompiler;
|
||||
|
||||
_ViewCompiler?: view_compiler.ViewCompiler;
|
||||
ViewCompiler: typeof view_compiler.ViewCompiler;
|
||||
|
||||
_NgModuleCompiler?: ng_module_compiler.NgModuleCompiler;
|
||||
NgModuleCompiler: typeof ng_module_compiler.NgModuleCompiler;
|
||||
|
||||
_TypeScriptEmitter?: ts_emitter.TypeScriptEmitter;
|
||||
TypeScriptEmitter: typeof ts_emitter.TypeScriptEmitter;
|
||||
|
||||
} = {
|
||||
SelectorMatcher: selector.SelectorMatcher,
|
||||
CssSelector: selector.CssSelector,
|
||||
AssetUrl: path_util.AssetUrl,
|
||||
ImportGenerator: path_util.ImportGenerator,
|
||||
CompileMetadataResolver: metadata_resolver.CompileMetadataResolver,
|
||||
HtmlParser: html_parser.HtmlParser,
|
||||
InterpolationConfig: interpolation_config.InterpolationConfig,
|
||||
DirectiveNormalizer: directive_normalizer.DirectiveNormalizer,
|
||||
Lexer: lexer.Lexer,
|
||||
Parser: parser.Parser,
|
||||
ParseLocation: parse_util.ParseLocation,
|
||||
ParseError: parse_util.ParseError,
|
||||
ParseErrorLevel: parse_util.ParseErrorLevel,
|
||||
ParseSourceFile: parse_util.ParseSourceFile,
|
||||
ParseSourceSpan: parse_util.ParseSourceSpan,
|
||||
TemplateParser: template_parser.TemplateParser,
|
||||
DomElementSchemaRegistry: dom_element_schema_registry.DomElementSchemaRegistry,
|
||||
StyleCompiler: style_compiler.StyleCompiler,
|
||||
ViewCompiler: view_compiler.ViewCompiler,
|
||||
NgModuleCompiler: ng_module_compiler.NgModuleCompiler,
|
||||
TypeScriptEmitter: ts_emitter.TypeScriptEmitter
|
||||
};
|
@ -27,13 +27,7 @@ export const NgModuleInjector: typeof r.NgModuleInjector = r.NgModuleInjector;
|
||||
export const registerModuleFactory: typeof r.registerModuleFactory = r.registerModuleFactory;
|
||||
export type ViewType = typeof r._ViewType;
|
||||
export const ViewType: typeof r.ViewType = r.ViewType;
|
||||
export const MAX_INTERPOLATION_VALUES: typeof r.MAX_INTERPOLATION_VALUES =
|
||||
r.MAX_INTERPOLATION_VALUES;
|
||||
export const checkBinding: typeof r.checkBinding = r.checkBinding;
|
||||
export const flattenNestedViewRenderNodes: typeof r.flattenNestedViewRenderNodes =
|
||||
r.flattenNestedViewRenderNodes;
|
||||
export const interpolate: typeof r.interpolate = r.interpolate;
|
||||
export const ViewUtils: typeof r.ViewUtils = r.ViewUtils;
|
||||
export const view_utils: typeof r.view_utils = r.view_utils;
|
||||
export const DebugContext: typeof r.DebugContext = r.DebugContext;
|
||||
export const StaticNodeDebugInfo: typeof r.StaticNodeDebugInfo = r.StaticNodeDebugInfo;
|
||||
export const devModeEqual: typeof r.devModeEqual = r.devModeEqual;
|
||||
@ -42,19 +36,6 @@ export const ValueUnwrapper: typeof r.ValueUnwrapper = r.ValueUnwrapper;
|
||||
export const TemplateRef_: typeof r.TemplateRef_ = r.TemplateRef_;
|
||||
export type RenderDebugInfo = typeof r._RenderDebugInfo;
|
||||
export const RenderDebugInfo: typeof r.RenderDebugInfo = r.RenderDebugInfo;
|
||||
export const EMPTY_ARRAY: typeof r.EMPTY_ARRAY = r.EMPTY_ARRAY;
|
||||
export const EMPTY_MAP: typeof r.EMPTY_MAP = r.EMPTY_MAP;
|
||||
export const pureProxy1: typeof r.pureProxy1 = r.pureProxy1;
|
||||
export const pureProxy2: typeof r.pureProxy2 = r.pureProxy2;
|
||||
export const pureProxy3: typeof r.pureProxy3 = r.pureProxy3;
|
||||
export const pureProxy4: typeof r.pureProxy4 = r.pureProxy4;
|
||||
export const pureProxy5: typeof r.pureProxy5 = r.pureProxy5;
|
||||
export const pureProxy6: typeof r.pureProxy6 = r.pureProxy6;
|
||||
export const pureProxy7: typeof r.pureProxy7 = r.pureProxy7;
|
||||
export const pureProxy8: typeof r.pureProxy8 = r.pureProxy8;
|
||||
export const pureProxy9: typeof r.pureProxy9 = r.pureProxy9;
|
||||
export const pureProxy10: typeof r.pureProxy10 = r.pureProxy10;
|
||||
export const castByValue: typeof r.castByValue = r.castByValue;
|
||||
export type Console = typeof r._Console;
|
||||
export const Console: typeof r.Console = r.Console;
|
||||
export const reflector: typeof r.reflector = r.reflector;
|
||||
@ -90,3 +71,4 @@ export const ViewMetadata: typeof r.ViewMetadata = r.ViewMetadata;
|
||||
export type ComponentStillLoadingError = typeof r._ComponentStillLoadingError;
|
||||
export const ComponentStillLoadingError: typeof r.ComponentStillLoadingError =
|
||||
r.ComponentStillLoadingError;
|
||||
export const AnimationTransition: typeof r.AnimationTransition = r.AnimationTransition;
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
import {CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileNgModuleMetadata, CompileProviderMetadata, CompileQueryMetadata, CompileTokenMetadata, CompileTypeMetadata} from './compile_metadata';
|
||||
import {ListWrapper, MapWrapper} from './facade/collection';
|
||||
import {isArray, isBlank, isPresent, normalizeBlank} from './facade/lang';
|
||||
import {isBlank, isPresent, normalizeBlank} from './facade/lang';
|
||||
import {Identifiers, resolveIdentifierToken} from './identifiers';
|
||||
import {ParseError, ParseSourceSpan} from './parse_util';
|
||||
import {AttrAst, DirectiveAst, ProviderAst, ProviderAstType, ReferenceAst} from './template_parser/template_ast';
|
||||
@ -102,7 +102,7 @@ export class ProviderElementContext {
|
||||
|
||||
private _addQueryReadsTo(token: CompileTokenMetadata, queryReadTokens: Map<any, boolean>) {
|
||||
this._getQueriesFor(token).forEach((query) => {
|
||||
const queryReadToken = isPresent(query.read) ? query.read : token;
|
||||
const queryReadToken = query.read || token;
|
||||
if (isBlank(queryReadTokens.get(queryReadToken.reference))) {
|
||||
queryReadTokens.set(queryReadToken.reference, true);
|
||||
}
|
||||
@ -169,11 +169,11 @@ export class ProviderElementContext {
|
||||
transformedUseValue = existingDiDep.value;
|
||||
}
|
||||
} else if (isPresent(provider.useFactory)) {
|
||||
var deps = isPresent(provider.deps) ? provider.deps : provider.useFactory.diDeps;
|
||||
var deps = provider.deps || provider.useFactory.diDeps;
|
||||
transformedDeps =
|
||||
deps.map((dep) => this._getDependency(resolvedProvider.providerType, dep, eager));
|
||||
} else if (isPresent(provider.useClass)) {
|
||||
var deps = isPresent(provider.deps) ? provider.deps : provider.useClass.diDeps;
|
||||
var deps = provider.deps || provider.useClass.diDeps;
|
||||
transformedDeps =
|
||||
deps.map((dep) => this._getDependency(resolvedProvider.providerType, dep, eager));
|
||||
}
|
||||
@ -338,11 +338,11 @@ export class NgModuleProviderAnalyzer {
|
||||
transformedUseValue = existingDiDep.value;
|
||||
}
|
||||
} else if (isPresent(provider.useFactory)) {
|
||||
var deps = isPresent(provider.deps) ? provider.deps : provider.useFactory.diDeps;
|
||||
var deps = provider.deps || provider.useFactory.diDeps;
|
||||
transformedDeps =
|
||||
deps.map((dep) => this._getDependency(dep, eager, resolvedProvider.sourceSpan));
|
||||
} else if (isPresent(provider.useClass)) {
|
||||
var deps = isPresent(provider.deps) ? provider.deps : provider.useClass.diDeps;
|
||||
var deps = provider.deps || provider.useClass.diDeps;
|
||||
transformedDeps =
|
||||
deps.map((dep) => this._getDependency(dep, eager, resolvedProvider.sourceSpan));
|
||||
}
|
||||
@ -418,7 +418,7 @@ function _normalizeProviders(
|
||||
}
|
||||
if (isPresent(providers)) {
|
||||
providers.forEach((provider) => {
|
||||
if (isArray(provider)) {
|
||||
if (Array.isArray(provider)) {
|
||||
_normalizeProviders(<any[]>provider, sourceSpan, targetErrors, targetProviders);
|
||||
} else {
|
||||
let normalizeProvider: CompileProviderMetadata;
|
||||
|
@ -7,11 +7,13 @@
|
||||
*/
|
||||
|
||||
import {Compiler, ComponentFactory, Injectable, Injector, ModuleWithComponentFactories, NgModuleFactory, SchemaMetadata, Type} from '@angular/core';
|
||||
|
||||
import {AnimationCompiler} from './animation/animation_compiler';
|
||||
import {AnimationParser} from './animation/animation_parser';
|
||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, ProviderMeta, createHostComponentMeta} from './compile_metadata';
|
||||
import {CompilerConfig} from './config';
|
||||
import {DirectiveNormalizer} from './directive_normalizer';
|
||||
import {DirectiveWrapperCompiler} from './directive_wrapper_compiler';
|
||||
import {stringify} from './facade/lang';
|
||||
import {CompileMetadataResolver} from './metadata_resolver';
|
||||
import {NgModuleCompiler} from './ng_module_compiler';
|
||||
@ -22,7 +24,8 @@ import {ComponentStillLoadingError} from './private_import_core';
|
||||
import {CompiledStylesheet, StyleCompiler} from './style_compiler';
|
||||
import {TemplateParser} from './template_parser/template_parser';
|
||||
import {SyncAsyncResult} from './util';
|
||||
import {ComponentFactoryDependency, ViewCompiler, ViewFactoryDependency} from './view_compiler/view_compiler';
|
||||
import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewCompiler, ViewFactoryDependency} from './view_compiler/view_compiler';
|
||||
|
||||
|
||||
/**
|
||||
* An internal module of the Angular compiler that begins with component types,
|
||||
@ -37,6 +40,7 @@ import {ComponentFactoryDependency, ViewCompiler, ViewFactoryDependency} from '.
|
||||
export class RuntimeCompiler implements Compiler {
|
||||
private _compiledTemplateCache = new Map<Type<any>, CompiledTemplate>();
|
||||
private _compiledHostTemplateCache = new Map<Type<any>, CompiledTemplate>();
|
||||
private _compiledDirectiveWrapperCache = new Map<Type<any>, Type<any>>();
|
||||
private _compiledNgModuleCache = new Map<Type<any>, NgModuleFactory<any>>();
|
||||
private _animationParser = new AnimationParser();
|
||||
private _animationCompiler = new AnimationCompiler();
|
||||
@ -45,7 +49,9 @@ export class RuntimeCompiler implements Compiler {
|
||||
private _injector: Injector, private _metadataResolver: CompileMetadataResolver,
|
||||
private _templateNormalizer: DirectiveNormalizer, private _templateParser: TemplateParser,
|
||||
private _styleCompiler: StyleCompiler, private _viewCompiler: ViewCompiler,
|
||||
private _ngModuleCompiler: NgModuleCompiler, private _compilerConfig: CompilerConfig) {}
|
||||
private _ngModuleCompiler: NgModuleCompiler,
|
||||
private _directiveWrapperCompiler: DirectiveWrapperCompiler,
|
||||
private _compilerConfig: CompilerConfig) {}
|
||||
|
||||
get injector(): Injector { return this._injector; }
|
||||
|
||||
@ -80,10 +86,11 @@ export class RuntimeCompiler implements Compiler {
|
||||
const moduleMeta = this._metadataResolver.getNgModuleMetadata(moduleType);
|
||||
const componentFactories: ComponentFactory<any>[] = [];
|
||||
const templates = new Set<CompiledTemplate>();
|
||||
moduleMeta.transitiveModule.modules.forEach((moduleMeta) => {
|
||||
moduleMeta.declaredDirectives.forEach((dirMeta) => {
|
||||
moduleMeta.transitiveModule.modules.forEach((localModuleMeta) => {
|
||||
localModuleMeta.declaredDirectives.forEach((dirMeta) => {
|
||||
if (dirMeta.isComponent) {
|
||||
const template = this._createCompiledHostTemplate(dirMeta.type.reference);
|
||||
const template =
|
||||
this._createCompiledHostTemplate(dirMeta.type.reference, localModuleMeta);
|
||||
templates.add(template);
|
||||
componentFactories.push(template.proxyComponentFactory);
|
||||
}
|
||||
@ -119,7 +126,7 @@ export class RuntimeCompiler implements Compiler {
|
||||
interpretStatements(compileResult.statements, compileResult.ngModuleFactoryVar);
|
||||
} else {
|
||||
ngModuleFactory = jitStatements(
|
||||
`${moduleMeta.type.name}.ngfactory.js`, compileResult.statements,
|
||||
`/${moduleMeta.type.name}/module.ngfactory.js`, compileResult.statements,
|
||||
compileResult.ngModuleFactoryVar);
|
||||
}
|
||||
this._compiledNgModuleCache.set(moduleMeta.type.reference, ngModuleFactory);
|
||||
@ -135,22 +142,32 @@ export class RuntimeCompiler implements Compiler {
|
||||
var loadingPromises: Promise<any>[] = [];
|
||||
|
||||
const ngModule = this._metadataResolver.getNgModuleMetadata(mainModule);
|
||||
const moduleByDirective = new Map<any, CompileNgModuleMetadata>();
|
||||
ngModule.transitiveModule.modules.forEach((localModuleMeta) => {
|
||||
localModuleMeta.declaredDirectives.forEach((dirMeta) => {
|
||||
moduleByDirective.set(dirMeta.type.reference, localModuleMeta);
|
||||
this._compileDirectiveWrapper(dirMeta, localModuleMeta);
|
||||
if (dirMeta.isComponent) {
|
||||
templates.add(this._createCompiledTemplate(dirMeta, localModuleMeta));
|
||||
}
|
||||
});
|
||||
});
|
||||
ngModule.transitiveModule.modules.forEach((localModuleMeta) => {
|
||||
localModuleMeta.declaredDirectives.forEach((dirMeta) => {
|
||||
if (dirMeta.isComponent) {
|
||||
templates.add(this._createCompiledTemplate(dirMeta, localModuleMeta));
|
||||
dirMeta.entryComponents.forEach((entryComponentType) => {
|
||||
templates.add(this._createCompiledHostTemplate(entryComponentType.reference));
|
||||
const moduleMeta = moduleByDirective.get(entryComponentType.reference);
|
||||
templates.add(
|
||||
this._createCompiledHostTemplate(entryComponentType.reference, moduleMeta));
|
||||
});
|
||||
// TODO: what about entryComponents of entryComponents? maybe skip here and just do the
|
||||
// below?
|
||||
}
|
||||
});
|
||||
localModuleMeta.entryComponents.forEach((entryComponentType) => {
|
||||
templates.add(this._createCompiledHostTemplate(entryComponentType.reference));
|
||||
// TODO: what about entryComponents of entryComponents?
|
||||
const moduleMeta = moduleByDirective.get(entryComponentType.reference);
|
||||
templates.add(this._createCompiledHostTemplate(entryComponentType.reference, moduleMeta));
|
||||
});
|
||||
});
|
||||
|
||||
templates.forEach((template) => {
|
||||
if (template.loading) {
|
||||
if (isSync) {
|
||||
@ -189,14 +206,19 @@ export class RuntimeCompiler implements Compiler {
|
||||
this._compiledNgModuleCache.clear();
|
||||
}
|
||||
|
||||
private _createCompiledHostTemplate(compType: Type<any>): CompiledTemplate {
|
||||
private _createCompiledHostTemplate(compType: Type<any>, ngModule: CompileNgModuleMetadata):
|
||||
CompiledTemplate {
|
||||
if (!ngModule) {
|
||||
throw new Error(
|
||||
`Component ${stringify(compType)} is not part of any NgModule or the module has not been imported into your module.`);
|
||||
}
|
||||
var compiledTemplate = this._compiledHostTemplateCache.get(compType);
|
||||
if (!compiledTemplate) {
|
||||
var compMeta = this._metadataResolver.getDirectiveMetadata(compType);
|
||||
assertComponent(compMeta);
|
||||
var hostMeta = createHostComponentMeta(compMeta);
|
||||
compiledTemplate = new CompiledTemplate(
|
||||
true, compMeta.selector, compMeta.type, [compMeta], [], [],
|
||||
true, compMeta.selector, compMeta.type, ngModule, [compMeta],
|
||||
this._templateNormalizer.normalizeDirective(hostMeta));
|
||||
this._compiledHostTemplateCache.set(compType, compiledTemplate);
|
||||
}
|
||||
@ -209,8 +231,7 @@ export class RuntimeCompiler implements Compiler {
|
||||
if (!compiledTemplate) {
|
||||
assertComponent(compMeta);
|
||||
compiledTemplate = new CompiledTemplate(
|
||||
false, compMeta.selector, compMeta.type, ngModule.transitiveModule.directives,
|
||||
ngModule.transitiveModule.pipes, ngModule.schemas,
|
||||
false, compMeta.selector, compMeta.type, ngModule, ngModule.transitiveModule.directives,
|
||||
this._templateNormalizer.normalizeDirective(compMeta));
|
||||
this._compiledTemplateCache.set(compMeta.type.reference, compiledTemplate);
|
||||
}
|
||||
@ -221,13 +242,8 @@ export class RuntimeCompiler implements Compiler {
|
||||
const compiledTemplate = isHost ? this._compiledHostTemplateCache.get(compType) :
|
||||
this._compiledTemplateCache.get(compType);
|
||||
if (!compiledTemplate) {
|
||||
if (isHost) {
|
||||
throw new Error(
|
||||
`Illegal state: Compiled view for component ${stringify(compType)} does not exist!`);
|
||||
} else {
|
||||
throw new Error(
|
||||
`Component ${stringify(compType)} is not part of any NgModule or the module has not been imported into your module.`);
|
||||
}
|
||||
throw new Error(
|
||||
`Illegal state: Compiled view for component ${stringify(compType)} does not exist!`);
|
||||
}
|
||||
return compiledTemplate;
|
||||
}
|
||||
@ -241,6 +257,30 @@ export class RuntimeCompiler implements Compiler {
|
||||
return compiledTemplate;
|
||||
}
|
||||
|
||||
private _assertDirectiveWrapper(dirType: any): Type<any> {
|
||||
const dirWrapper = this._compiledDirectiveWrapperCache.get(dirType);
|
||||
if (!dirWrapper) {
|
||||
throw new Error(
|
||||
`Illegal state: Directive wrapper for ${stringify(dirType)} has not been compiled!`);
|
||||
}
|
||||
return dirWrapper;
|
||||
}
|
||||
|
||||
private _compileDirectiveWrapper(
|
||||
dirMeta: CompileDirectiveMetadata, moduleMeta: CompileNgModuleMetadata): void {
|
||||
const compileResult = this._directiveWrapperCompiler.compile(dirMeta);
|
||||
const statements = compileResult.statements;
|
||||
let directiveWrapperClass: any;
|
||||
if (!this._compilerConfig.useJit) {
|
||||
directiveWrapperClass = interpretStatements(statements, compileResult.dirWrapperClassVar);
|
||||
} else {
|
||||
directiveWrapperClass = jitStatements(
|
||||
`/${moduleMeta.type.name}/${dirMeta.type.name}/wrapper.ngfactory.js`, statements,
|
||||
compileResult.dirWrapperClassVar);
|
||||
}
|
||||
this._compiledDirectiveWrapperCache.set(dirMeta.type.reference, directiveWrapperClass);
|
||||
}
|
||||
|
||||
private _compileTemplate(template: CompiledTemplate) {
|
||||
if (template.isCompiled) {
|
||||
return;
|
||||
@ -275,6 +315,9 @@ export class RuntimeCompiler implements Compiler {
|
||||
depTemplate = this._assertComponentLoaded(cfd.comp.reference, true);
|
||||
cfd.placeholder.reference = depTemplate.proxyComponentFactory;
|
||||
cfd.placeholder.name = `compFactory_${cfd.comp.name}`;
|
||||
} else if (dep instanceof DirectiveWrapperDependency) {
|
||||
let dwd = <DirectiveWrapperDependency>dep;
|
||||
dwd.placeholder.reference = this._assertDirectiveWrapper(dwd.dir.reference);
|
||||
}
|
||||
});
|
||||
const statements =
|
||||
@ -286,8 +329,8 @@ export class RuntimeCompiler implements Compiler {
|
||||
factory = interpretStatements(statements, compileResult.viewFactoryVar);
|
||||
} else {
|
||||
factory = jitStatements(
|
||||
`${template.compType.name}${template.isHost?'_Host':''}.ngfactory.js`, statements,
|
||||
compileResult.viewFactoryVar);
|
||||
`/${template.ngModule.type.name}/${template.compType.name}/${template.isHost?'host':'component'}.ngfactory.js`,
|
||||
statements, compileResult.viewFactoryVar);
|
||||
}
|
||||
template.compiled(factory);
|
||||
}
|
||||
@ -310,7 +353,7 @@ export class RuntimeCompiler implements Compiler {
|
||||
if (!this._compilerConfig.useJit) {
|
||||
return interpretStatements(result.statements, result.stylesVar);
|
||||
} else {
|
||||
return jitStatements(`${result.meta.moduleUrl}.css.js`, result.statements, result.stylesVar);
|
||||
return jitStatements(`/${result.meta.moduleUrl}.css.js`, result.statements, result.stylesVar);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -325,13 +368,17 @@ class CompiledTemplate {
|
||||
isCompiledWithDeps = false;
|
||||
viewComponentTypes: Type<any>[] = [];
|
||||
viewDirectives: CompileDirectiveMetadata[] = [];
|
||||
viewPipes: CompilePipeMetadata[];
|
||||
schemas: SchemaMetadata[];
|
||||
|
||||
constructor(
|
||||
public isHost: boolean, selector: string, public compType: CompileIdentifierMetadata,
|
||||
viewDirectivesAndComponents: CompileDirectiveMetadata[],
|
||||
public viewPipes: CompilePipeMetadata[], public schemas: SchemaMetadata[],
|
||||
public ngModule: CompileNgModuleMetadata,
|
||||
viewDirectiveAndComponents: CompileDirectiveMetadata[],
|
||||
_normalizeResult: SyncAsyncResult<CompileDirectiveMetadata>) {
|
||||
viewDirectivesAndComponents.forEach((dirMeta) => {
|
||||
this.viewPipes = ngModule.transitiveModule.pipes;
|
||||
this.schemas = ngModule.schemas;
|
||||
viewDirectiveAndComponents.forEach((dirMeta) => {
|
||||
if (dirMeta.isComponent) {
|
||||
this.viewComponentTypes.push(dirMeta.type.reference);
|
||||
} else {
|
||||
|
@ -381,7 +381,10 @@ export class ShadowCss {
|
||||
|
||||
if (_polyfillHostRe.test(selector)) {
|
||||
const replaceBy = this.strictStyling ? `[${hostSelector}]` : scopeSelector;
|
||||
return selector.replace(_polyfillHostNoCombinatorRe, (hnc, selector) => selector + replaceBy)
|
||||
return selector
|
||||
.replace(
|
||||
_polyfillHostNoCombinatorRe,
|
||||
(hnc, selector) => selector[0] === ':' ? replaceBy + selector : selector + replaceBy)
|
||||
.replace(_polyfillHostRe, replaceBy + ' ');
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
// Some of the code comes from WebComponents.JS
|
||||
// https://github.com/webcomponents/webcomponentsjs/blob/master/src/HTMLImports/path.js
|
||||
|
||||
import {StringWrapper, isBlank, isPresent} from './facade/lang';
|
||||
import {isBlank, isPresent} from './facade/lang';
|
||||
|
||||
import {UrlResolver} from './url_resolver';
|
||||
|
||||
@ -30,8 +30,8 @@ export function isStyleUrlResolvable(url: string): boolean {
|
||||
export function extractStyleUrls(
|
||||
resolver: UrlResolver, baseUrl: string, cssText: string): StyleWithImports {
|
||||
var foundUrls: string[] = [];
|
||||
var modifiedCssText = StringWrapper.replaceAllMapped(cssText, _cssImportRe, (m: string[]) => {
|
||||
var url = isPresent(m[1]) ? m[1] : m[2];
|
||||
var modifiedCssText = cssText.replace(_cssImportRe, function(...m: string[]) {
|
||||
const url = m[1] || m[2];
|
||||
if (!isStyleUrlResolvable(url)) {
|
||||
// Do not attempt to resolve non-package absolute URLs with URI scheme
|
||||
return m[0];
|
||||
|
@ -10,7 +10,6 @@ import {SecurityContext} from '@angular/core';
|
||||
|
||||
import {CompileDirectiveMetadata, CompileProviderMetadata, CompileTokenMetadata} from '../compile_metadata';
|
||||
import {AST} from '../expression_parser/ast';
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {ParseSourceSpan} from '../parse_util';
|
||||
import {LifecycleHooks} from '../private_import_core';
|
||||
|
||||
@ -84,7 +83,7 @@ export class BoundEventAst implements TemplateAst {
|
||||
return visitor.visitEvent(this, context);
|
||||
}
|
||||
get fullName() {
|
||||
if (isPresent(this.target)) {
|
||||
if (this.target) {
|
||||
return `${this.target}:${this.name}`;
|
||||
} else {
|
||||
return this.name;
|
||||
@ -124,7 +123,8 @@ export class ElementAst implements TemplateAst {
|
||||
public outputs: BoundEventAst[], public references: ReferenceAst[],
|
||||
public directives: DirectiveAst[], public providers: ProviderAst[],
|
||||
public hasViewContainer: boolean, public children: TemplateAst[],
|
||||
public ngContentIndex: number, public sourceSpan: ParseSourceSpan) {}
|
||||
public ngContentIndex: number, public sourceSpan: ParseSourceSpan,
|
||||
public endSourceSpan: ParseSourceSpan) {}
|
||||
|
||||
visit(visitor: TemplateAstVisitor, context: any): any {
|
||||
return visitor.visitElement(this, context);
|
||||
@ -241,6 +241,11 @@ export enum PropertyBindingType {
|
||||
* A visitor for {@link TemplateAst} trees that will process each node.
|
||||
*/
|
||||
export interface TemplateAstVisitor {
|
||||
// Returning a truthy value from `visit()` will prevent `templateVisitAll()` from the call to
|
||||
// the typed method and result returned will become the result included in `visitAll()`s
|
||||
// result array.
|
||||
visit?(ast: TemplateAst, context: any): any;
|
||||
|
||||
visitNgContent(ast: NgContentAst, context: any): any;
|
||||
visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any;
|
||||
visitElement(ast: ElementAst, context: any): any;
|
||||
@ -260,10 +265,13 @@ export interface TemplateAstVisitor {
|
||||
*/
|
||||
export function templateVisitAll(
|
||||
visitor: TemplateAstVisitor, asts: TemplateAst[], context: any = null): any[] {
|
||||
var result: any[] = [];
|
||||
const result: any[] = [];
|
||||
const visit = visitor.visit ?
|
||||
(ast: TemplateAst) => visitor.visit(ast, context) || ast.visit(visitor, context) :
|
||||
(ast: TemplateAst) => ast.visit(visitor, context);
|
||||
asts.forEach(ast => {
|
||||
var astResult = ast.visit(visitor, context);
|
||||
if (isPresent(astResult)) {
|
||||
const astResult = visit(ast);
|
||||
if (astResult) {
|
||||
result.push(astResult);
|
||||
}
|
||||
});
|
||||
|
@ -11,7 +11,7 @@ import {Inject, Injectable, OpaqueToken, Optional, SchemaMetadata, SecurityConte
|
||||
import {CompileDirectiveMetadata, CompilePipeMetadata, CompileTemplateMetadata, CompileTokenMetadata, removeIdentifierDuplicates} from '../compile_metadata';
|
||||
import {AST, ASTWithSource, BindingPipe, EmptyExpr, Interpolation, ParserError, RecursiveAstVisitor, TemplateBinding} from '../expression_parser/ast';
|
||||
import {Parser} from '../expression_parser/parser';
|
||||
import {isPresent, isString} from '../facade/lang';
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {I18NHtmlParser} from '../i18n/i18n_html_parser';
|
||||
import {Identifiers, identifierToken, resolveIdentifierToken} from '../identifiers';
|
||||
import * as html from '../ml_parser/ast';
|
||||
@ -20,7 +20,7 @@ import {expandNodes} from '../ml_parser/icu_ast_expander';
|
||||
import {InterpolationConfig} from '../ml_parser/interpolation_config';
|
||||
import {mergeNsAndName, splitNsName} from '../ml_parser/tags';
|
||||
import {ParseError, ParseErrorLevel, ParseSourceSpan} from '../parse_util';
|
||||
import {Console, MAX_INTERPOLATION_VALUES} from '../private_import_core';
|
||||
import {Console, view_utils} from '../private_import_core';
|
||||
import {ProviderElementContext, ProviderViewContext} from '../provider_analyzer';
|
||||
import {ElementSchemaRegistry} from '../schema/element_schema_registry';
|
||||
import {CssSelector, SelectorMatcher} from '../selector';
|
||||
@ -118,22 +118,18 @@ export class TemplateParser {
|
||||
component: CompileDirectiveMetadata, template: string, directives: CompileDirectiveMetadata[],
|
||||
pipes: CompilePipeMetadata[], schemas: SchemaMetadata[],
|
||||
templateUrl: string): TemplateParseResult {
|
||||
let interpolationConfig: any;
|
||||
if (component.template) {
|
||||
interpolationConfig = InterpolationConfig.fromArray(component.template.interpolation);
|
||||
}
|
||||
let htmlAstWithErrors =
|
||||
this._htmlParser.parse(template, templateUrl, true, interpolationConfig);
|
||||
const errors: ParseError[] = htmlAstWithErrors.errors;
|
||||
let result: TemplateAst[];
|
||||
|
||||
if (errors.length == 0) {
|
||||
// Transform ICU messages to angular directives
|
||||
const expandedHtmlAst = expandNodes(htmlAstWithErrors.rootNodes);
|
||||
errors.push(...expandedHtmlAst.errors);
|
||||
htmlAstWithErrors = new ParseTreeResult(expandedHtmlAst.nodes, errors);
|
||||
}
|
||||
return this.tryParseHtml(
|
||||
this.expandHtml(this._htmlParser.parse(
|
||||
template, templateUrl, true, this.getInterpolationConfig(component))),
|
||||
component, template, directives, pipes, schemas, templateUrl);
|
||||
}
|
||||
|
||||
tryParseHtml(
|
||||
htmlAstWithErrors: ParseTreeResult, component: CompileDirectiveMetadata, template: string,
|
||||
directives: CompileDirectiveMetadata[], pipes: CompilePipeMetadata[],
|
||||
schemas: SchemaMetadata[], templateUrl: string): TemplateParseResult {
|
||||
var result: TemplateAst[];
|
||||
var errors = htmlAstWithErrors.errors;
|
||||
if (htmlAstWithErrors.rootNodes.length > 0) {
|
||||
const uniqDirectives = removeIdentifierDuplicates(directives);
|
||||
const uniqPipes = removeIdentifierDuplicates(pipes);
|
||||
@ -147,7 +143,6 @@ export class TemplateParser {
|
||||
} else {
|
||||
result = [];
|
||||
}
|
||||
|
||||
this._assertNoReferenceDuplicationOnTemplate(result, errors);
|
||||
|
||||
if (errors.length > 0) {
|
||||
@ -162,6 +157,24 @@ export class TemplateParser {
|
||||
return new TemplateParseResult(result, errors);
|
||||
}
|
||||
|
||||
expandHtml(htmlAstWithErrors: ParseTreeResult, forced: boolean = false): ParseTreeResult {
|
||||
const errors: ParseError[] = htmlAstWithErrors.errors;
|
||||
|
||||
if (errors.length == 0 || forced) {
|
||||
// Transform ICU messages to angular directives
|
||||
const expandedHtmlAst = expandNodes(htmlAstWithErrors.rootNodes);
|
||||
errors.push(...expandedHtmlAst.errors);
|
||||
htmlAstWithErrors = new ParseTreeResult(expandedHtmlAst.nodes, errors);
|
||||
}
|
||||
return htmlAstWithErrors;
|
||||
}
|
||||
|
||||
getInterpolationConfig(component: CompileDirectiveMetadata): InterpolationConfig {
|
||||
if (component.template) {
|
||||
return InterpolationConfig.fromArray(component.template.interpolation);
|
||||
}
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_assertNoReferenceDuplicationOnTemplate(result: TemplateAst[], errors: TemplateParseError[]):
|
||||
void {
|
||||
@ -233,8 +246,9 @@ class TemplateParseVisitor implements html.Visitor {
|
||||
if (ast) this._reportParserErrors(ast.errors, sourceSpan);
|
||||
this._checkPipes(ast, sourceSpan);
|
||||
if (isPresent(ast) &&
|
||||
(<Interpolation>ast.ast).expressions.length > MAX_INTERPOLATION_VALUES) {
|
||||
throw new Error(`Only support at most ${MAX_INTERPOLATION_VALUES} interpolation values!`);
|
||||
(<Interpolation>ast.ast).expressions.length > view_utils.MAX_INTERPOLATION_VALUES) {
|
||||
throw new Error(
|
||||
`Only support at most ${view_utils.MAX_INTERPOLATION_VALUES} interpolation values!`);
|
||||
}
|
||||
return ast;
|
||||
} catch (e) {
|
||||
@ -415,10 +429,8 @@ class TemplateParseVisitor implements html.Visitor {
|
||||
let parsedElement: TemplateAst;
|
||||
|
||||
if (preparsedElement.type === PreparsedElementType.NG_CONTENT) {
|
||||
if (isPresent(element.children) && element.children.length > 0) {
|
||||
this._reportError(
|
||||
`<ng-content> element cannot have content. <ng-content> must be immediately followed by </ng-content>`,
|
||||
element.sourceSpan);
|
||||
if (element.children && !element.children.every(_isEmptyTextNode)) {
|
||||
this._reportError(`<ng-content> element cannot have content.`, element.sourceSpan);
|
||||
}
|
||||
|
||||
parsedElement = new NgContentAst(
|
||||
@ -442,7 +454,7 @@ class TemplateParseVisitor implements html.Visitor {
|
||||
nodeName, attrs, elementProps, events, references,
|
||||
providerContext.transformedDirectiveAsts, providerContext.transformProviders,
|
||||
providerContext.transformedHasViewContainer, children,
|
||||
hasInlineTemplates ? null : ngContentIndex, element.sourceSpan);
|
||||
hasInlineTemplates ? null : ngContentIndex, element.sourceSpan, element.endSourceSpan);
|
||||
|
||||
this._findComponentDirectives(directiveAsts)
|
||||
.forEach(
|
||||
@ -833,7 +845,7 @@ class TemplateParseVisitor implements html.Visitor {
|
||||
if (hostProps) {
|
||||
Object.keys(hostProps).forEach(propName => {
|
||||
const expression = hostProps[propName];
|
||||
if (isString(expression)) {
|
||||
if (typeof expression === 'string') {
|
||||
const exprAst = this._parseBinding(expression, sourceSpan);
|
||||
targetPropertyAsts.push(
|
||||
this._createElementPropertyAst(elementName, propName, exprAst, sourceSpan));
|
||||
@ -852,7 +864,7 @@ class TemplateParseVisitor implements html.Visitor {
|
||||
if (hostListeners) {
|
||||
Object.keys(hostListeners).forEach(propName => {
|
||||
const expression = hostListeners[propName];
|
||||
if (isString(expression)) {
|
||||
if (typeof expression === 'string') {
|
||||
this._parseEventOrAnimationEvent(propName, expression, sourceSpan, [], targetEventAsts);
|
||||
} else {
|
||||
this._reportError(
|
||||
@ -1083,7 +1095,7 @@ class NonBindableVisitor implements html.Visitor {
|
||||
const children = html.visitAll(this, ast.children, EMPTY_ELEMENT_CONTEXT);
|
||||
return new ElementAst(
|
||||
ast.name, html.visitAll(this, ast.attrs), [], [], [], [], [], false, children,
|
||||
ngContentIndex, ast.sourceSpan);
|
||||
ngContentIndex, ast.sourceSpan, ast.endSourceSpan);
|
||||
}
|
||||
visitComment(comment: html.Comment, context: any): any { return null; }
|
||||
|
||||
@ -1188,3 +1200,7 @@ export class PipeCollector extends RecursiveAstVisitor {
|
||||
function _isAnimationLabel(name: string): boolean {
|
||||
return name[0] == '@';
|
||||
}
|
||||
|
||||
function _isEmptyTextNode(node: html.Node): boolean {
|
||||
return node instanceof html.Text && node.value.trim().length == 0;
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {Inject, Injectable, PACKAGE_ROOT_URL} from '@angular/core';
|
||||
|
||||
import {StringWrapper, isBlank, isPresent} from './facade/lang';
|
||||
import {isBlank, isPresent} from './facade/lang';
|
||||
|
||||
|
||||
const _ASSET_SCHEME = 'asset:';
|
||||
@ -74,8 +74,8 @@ export class UrlResolver {
|
||||
var pathSegements = path.split(/\//);
|
||||
resolvedUrl = `asset:${pathSegements[0]}/lib/${pathSegements.slice(1).join('/')}`;
|
||||
} else {
|
||||
prefix = StringWrapper.stripRight(prefix, '/');
|
||||
path = StringWrapper.stripLeft(path, '/');
|
||||
prefix = prefix.replace(/\/+$/, '');
|
||||
path = path.replace(/^\/+/, '');
|
||||
return `${prefix}/${path}`;
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,15 @@
|
||||
*/
|
||||
|
||||
import {CompileTokenMetadata} from './compile_metadata';
|
||||
import {StringWrapper, isArray, isBlank, isPresent, isPrimitive, isStrictStringMap} from './facade/lang';
|
||||
import {isBlank, isPresent, isPrimitive, isStrictStringMap} from './facade/lang';
|
||||
import * as o from './output/output_ast';
|
||||
|
||||
export const MODULE_SUFFIX = '';
|
||||
|
||||
var CAMEL_CASE_REGEXP = /([A-Z])/g;
|
||||
const CAMEL_CASE_REGEXP = /([A-Z])/g;
|
||||
|
||||
export function camelCaseToDashCase(input: string): string {
|
||||
return StringWrapper.replaceAllMapped(
|
||||
input, CAMEL_CASE_REGEXP, (m: string[]) => '-' + m[1].toLowerCase());
|
||||
return input.replace(CAMEL_CASE_REGEXP, (...m: any[]) => '-' + m[1].toLowerCase());
|
||||
}
|
||||
|
||||
export function splitAtColon(input: string, defaultValues: string[]): string[] {
|
||||
@ -34,19 +33,23 @@ function _splitAt(input: string, character: string, defaultValues: string[]): st
|
||||
}
|
||||
|
||||
export function sanitizeIdentifier(name: string): string {
|
||||
return StringWrapper.replaceAll(name, /\W/g, '_');
|
||||
return name.replace(/\W/g, '_');
|
||||
}
|
||||
|
||||
export function visitValue(value: any, visitor: ValueVisitor, context: any): any {
|
||||
if (isArray(value)) {
|
||||
if (Array.isArray(value)) {
|
||||
return visitor.visitArray(<any[]>value, context);
|
||||
} else if (isStrictStringMap(value)) {
|
||||
return visitor.visitStringMap(<{[key: string]: any}>value, context);
|
||||
} else if (isBlank(value) || isPrimitive(value)) {
|
||||
return visitor.visitPrimitive(value, context);
|
||||
} else {
|
||||
return visitor.visitOther(value, context);
|
||||
}
|
||||
|
||||
if (isStrictStringMap(value)) {
|
||||
return visitor.visitStringMap(<{[key: string]: any}>value, context);
|
||||
}
|
||||
|
||||
if (isBlank(value) || isPrimitive(value)) {
|
||||
return visitor.visitPrimitive(value, context);
|
||||
}
|
||||
|
||||
return visitor.visitOther(value, context);
|
||||
}
|
||||
|
||||
export interface ValueVisitor {
|
||||
@ -61,9 +64,8 @@ export class ValueTransformer implements ValueVisitor {
|
||||
return arr.map(value => visitValue(value, this, context));
|
||||
}
|
||||
visitStringMap(map: {[key: string]: any}, context: any): any {
|
||||
var result = {};
|
||||
Object.keys(map).forEach(
|
||||
key => { (result as any /** TODO #9100 */)[key] = visitValue(map[key], this, context); });
|
||||
var result: {[key: string]: any} = {};
|
||||
Object.keys(map).forEach(key => { result[key] = visitValue(map[key], this, context); });
|
||||
return result;
|
||||
}
|
||||
visitPrimitive(value: any, context: any): any { return value; }
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
|
||||
import {CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileIdentifierMetadata, CompileProviderMetadata, CompileQueryMetadata, CompileTokenMetadata} from '../compile_metadata';
|
||||
import {DirectiveWrapperCompiler} from '../directive_wrapper_compiler';
|
||||
import {ListWrapper, MapWrapper} from '../facade/collection';
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {Identifiers, identifierToken, resolveIdentifier, resolveIdentifierToken} from '../identifiers';
|
||||
@ -19,7 +20,8 @@ import {createDiTokenExpression} from '../util';
|
||||
import {CompileMethod} from './compile_method';
|
||||
import {CompileQuery, addQueryToTokenMap, createQueryList} from './compile_query';
|
||||
import {CompileView} from './compile_view';
|
||||
import {InjectMethodVars} from './constants';
|
||||
import {InjectMethodVars, ViewProperties} from './constants';
|
||||
import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewFactoryDependency} from './deps';
|
||||
import {getPropertyInView, injectFromViewParentInjector} from './util';
|
||||
|
||||
export class CompileNode {
|
||||
@ -34,7 +36,7 @@ export class CompileNode {
|
||||
|
||||
export class CompileElement extends CompileNode {
|
||||
static createNull(): CompileElement {
|
||||
return new CompileElement(null, null, null, null, null, null, [], [], false, false, []);
|
||||
return new CompileElement(null, null, null, null, null, null, [], [], false, false, [], []);
|
||||
}
|
||||
|
||||
private _compViewExpr: o.Expression = null;
|
||||
@ -42,6 +44,7 @@ export class CompileElement extends CompileNode {
|
||||
public elementRef: o.Expression;
|
||||
public injector: o.Expression;
|
||||
public instances = new Map<any, o.Expression>();
|
||||
public directiveWrapperInstance = new Map<any, o.Expression>();
|
||||
private _resolvedProviders: Map<any, ProviderAst>;
|
||||
|
||||
private _queryCount = 0;
|
||||
@ -57,7 +60,9 @@ export class CompileElement extends CompileNode {
|
||||
sourceAst: TemplateAst, public component: CompileDirectiveMetadata,
|
||||
private _directives: CompileDirectiveMetadata[],
|
||||
private _resolvedProvidersArray: ProviderAst[], public hasViewContainer: boolean,
|
||||
public hasEmbeddedView: boolean, references: ReferenceAst[]) {
|
||||
public hasEmbeddedView: boolean, references: ReferenceAst[],
|
||||
private _targetDependencies:
|
||||
Array<ViewFactoryDependency|ComponentFactoryDependency|DirectiveWrapperDependency>) {
|
||||
super(parent, view, nodeIndex, renderNode, sourceAst);
|
||||
this.referenceTokens = {};
|
||||
references.forEach(ref => this.referenceTokens[ref.name] = ref.value);
|
||||
@ -72,6 +77,9 @@ export class CompileElement extends CompileNode {
|
||||
if (this.hasViewContainer || this.hasEmbeddedView || isPresent(this.component)) {
|
||||
this._createAppElement();
|
||||
}
|
||||
if (this.component) {
|
||||
this._createComponentFactoryResolver();
|
||||
}
|
||||
}
|
||||
|
||||
private _createAppElement() {
|
||||
@ -92,7 +100,13 @@ export class CompileElement extends CompileNode {
|
||||
this.instances.set(resolveIdentifierToken(Identifiers.AppElement).reference, this.appElement);
|
||||
}
|
||||
|
||||
public createComponentFactoryResolver(entryComponents: CompileIdentifierMetadata[]) {
|
||||
private _createComponentFactoryResolver() {
|
||||
let entryComponents =
|
||||
this.component.entryComponents.map((entryComponent: CompileIdentifierMetadata) => {
|
||||
var id = new CompileIdentifierMetadata({name: entryComponent.name});
|
||||
this._targetDependencies.push(new ComponentFactoryDependency(entryComponent, id));
|
||||
return id;
|
||||
});
|
||||
if (!entryComponents || entryComponents.length === 0) {
|
||||
return;
|
||||
}
|
||||
@ -155,20 +169,31 @@ export class CompileElement extends CompileNode {
|
||||
// create all the provider instances, some in the view constructor,
|
||||
// some as getters. We rely on the fact that they are already sorted topologically.
|
||||
MapWrapper.values(this._resolvedProviders).forEach((resolvedProvider) => {
|
||||
const isDirectiveWrapper = resolvedProvider.providerType === ProviderAstType.Component ||
|
||||
resolvedProvider.providerType === ProviderAstType.Directive;
|
||||
var providerValueExpressions = resolvedProvider.providers.map((provider) => {
|
||||
if (isPresent(provider.useExisting)) {
|
||||
return this._getDependency(
|
||||
resolvedProvider.providerType,
|
||||
new CompileDiDependencyMetadata({token: provider.useExisting}));
|
||||
} else if (isPresent(provider.useFactory)) {
|
||||
var deps = isPresent(provider.deps) ? provider.deps : provider.useFactory.diDeps;
|
||||
var deps = provider.deps || provider.useFactory.diDeps;
|
||||
var depsExpr = deps.map((dep) => this._getDependency(resolvedProvider.providerType, dep));
|
||||
return o.importExpr(provider.useFactory).callFn(depsExpr);
|
||||
} else if (isPresent(provider.useClass)) {
|
||||
var deps = isPresent(provider.deps) ? provider.deps : provider.useClass.diDeps;
|
||||
var deps = provider.deps || provider.useClass.diDeps;
|
||||
var depsExpr = deps.map((dep) => this._getDependency(resolvedProvider.providerType, dep));
|
||||
return o.importExpr(provider.useClass)
|
||||
.instantiate(depsExpr, o.importType(provider.useClass));
|
||||
if (isDirectiveWrapper) {
|
||||
const directiveWrapperIdentifier = new CompileIdentifierMetadata(
|
||||
{name: DirectiveWrapperCompiler.dirWrapperClassName(provider.useClass)});
|
||||
this._targetDependencies.push(
|
||||
new DirectiveWrapperDependency(provider.useClass, directiveWrapperIdentifier));
|
||||
return o.importExpr(directiveWrapperIdentifier)
|
||||
.instantiate(depsExpr, o.importType(directiveWrapperIdentifier));
|
||||
} else {
|
||||
return o.importExpr(provider.useClass)
|
||||
.instantiate(depsExpr, o.importType(provider.useClass));
|
||||
}
|
||||
} else {
|
||||
return convertValueToOutputAst(provider.useValue);
|
||||
}
|
||||
@ -177,7 +202,12 @@ export class CompileElement extends CompileNode {
|
||||
var instance = createProviderProperty(
|
||||
propName, resolvedProvider, providerValueExpressions, resolvedProvider.multiProvider,
|
||||
resolvedProvider.eager, this);
|
||||
this.instances.set(resolvedProvider.token.reference, instance);
|
||||
if (isDirectiveWrapper) {
|
||||
this.directiveWrapperInstance.set(resolvedProvider.token.reference, instance);
|
||||
this.instances.set(resolvedProvider.token.reference, instance.prop('context'));
|
||||
} else {
|
||||
this.instances.set(resolvedProvider.token.reference, instance);
|
||||
}
|
||||
});
|
||||
|
||||
for (var i = 0; i < this._directives.length; i++) {
|
||||
@ -435,6 +465,6 @@ function createProviderProperty(
|
||||
class _QueryWithRead {
|
||||
public read: CompileTokenMetadata;
|
||||
constructor(public query: CompileQuery, match: CompileTokenMetadata) {
|
||||
this.read = isPresent(query.meta.read) ? query.meta.read : match;
|
||||
this.read = query.meta.read || match;
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ export class CompileMethod {
|
||||
|
||||
resetDebugInfoExpr(nodeIndex: number, templateAst: TemplateAst): o.Expression {
|
||||
var res = this._updateDebugContext(new _DebugState(nodeIndex, templateAst));
|
||||
return isPresent(res) ? res : o.NULL_EXPR;
|
||||
return res || o.NULL_EXPR;
|
||||
}
|
||||
|
||||
resetDebugInfo(nodeIndex: number, templateAst: TemplateAst) {
|
||||
|
@ -64,7 +64,7 @@ export class CompileQuery {
|
||||
return !this._values.values.some(value => value instanceof ViewQueryValues);
|
||||
}
|
||||
|
||||
afterChildren(targetStaticMethod: any /** TODO #9100 */, targetDynamicMethod: CompileMethod) {
|
||||
afterChildren(targetStaticMethod: CompileMethod, targetDynamicMethod: CompileMethod) {
|
||||
var values = createQueryValues(this._values);
|
||||
var updateStmts = [this.queryList.callMethod('reset', [o.literalArr(values)]).toStmt()];
|
||||
if (isPresent(this.ownerDirectiveExpression)) {
|
||||
|
@ -169,16 +169,16 @@ export class CompileView implements NameResolver {
|
||||
return proxyExpr.callFn(values);
|
||||
}
|
||||
|
||||
createLiteralMap(entries: Array<Array<string|o.Expression>>): o.Expression {
|
||||
createLiteralMap(entries: [string, o.Expression][]): o.Expression {
|
||||
if (entries.length === 0) {
|
||||
return o.importExpr(resolveIdentifier(Identifiers.EMPTY_MAP));
|
||||
}
|
||||
var proxyExpr = o.THIS_EXPR.prop(`_map_${this.literalMapCount++}`);
|
||||
var proxyParams: o.FnParam[] = [];
|
||||
var proxyReturnEntries: Array<Array<string|o.Expression>> = [];
|
||||
var values: o.Expression[] = [];
|
||||
const proxyExpr = o.THIS_EXPR.prop(`_map_${this.literalMapCount++}`);
|
||||
const proxyParams: o.FnParam[] = [];
|
||||
const proxyReturnEntries: [string, o.Expression][] = [];
|
||||
const values: o.Expression[] = [];
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var paramName = `p${i}`;
|
||||
const paramName = `p${i}`;
|
||||
proxyParams.push(new o.FnParam(paramName));
|
||||
proxyReturnEntries.push([entries[i][0], o.variable(paramName)]);
|
||||
values.push(<o.Expression>entries[i][1]);
|
||||
|
24
modules/@angular/compiler/src/view_compiler/deps.ts
Normal file
24
modules/@angular/compiler/src/view_compiler/deps.ts
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* @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 {CompileIdentifierMetadata} from '../compile_metadata';
|
||||
|
||||
export class ViewFactoryDependency {
|
||||
constructor(
|
||||
public comp: CompileIdentifierMetadata, public placeholder: CompileIdentifierMetadata) {}
|
||||
}
|
||||
|
||||
export class ComponentFactoryDependency {
|
||||
constructor(
|
||||
public comp: CompileIdentifierMetadata, public placeholder: CompileIdentifierMetadata) {}
|
||||
}
|
||||
|
||||
export class DirectiveWrapperDependency {
|
||||
constructor(
|
||||
public dir: CompileIdentifierMetadata, public placeholder: CompileIdentifierMetadata) {}
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {CompileDirectiveMetadata} from '../compile_metadata';
|
||||
import {StringWrapper, isPresent} from '../facade/lang';
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {identifierToken} from '../identifiers';
|
||||
import * as o from '../output/output_ast';
|
||||
import {BoundEventAst, DirectiveAst} from '../template_parser/template_ast';
|
||||
@ -40,13 +40,14 @@ export class CompileEventListener {
|
||||
}
|
||||
|
||||
get methodName() { return this._methodName; }
|
||||
get isAnimation() { return !!this.eventPhase; }
|
||||
|
||||
constructor(
|
||||
public compileElement: CompileElement, public eventTarget: string, public eventName: string,
|
||||
public eventPhase: string, listenerIndex: number) {
|
||||
this._method = new CompileMethod(compileElement.view);
|
||||
this._methodName =
|
||||
`_handle_${santitizeEventName(eventName)}_${compileElement.nodeIndex}_${listenerIndex}`;
|
||||
`_handle_${sanitizeEventName(eventName)}_${compileElement.nodeIndex}_${listenerIndex}`;
|
||||
this._eventParam = new o.FnParam(
|
||||
EventHandlerVars.event.name,
|
||||
o.importType(this.compileElement.view.genConfig.renderTypes.renderEvent));
|
||||
@ -59,8 +60,7 @@ export class CompileEventListener {
|
||||
this._hasComponentHostListener = true;
|
||||
}
|
||||
this._method.resetDebugInfo(this.compileElement.nodeIndex, hostEvent);
|
||||
var context = isPresent(directiveInstance) ? directiveInstance :
|
||||
this.compileElement.view.componentContext;
|
||||
var context = directiveInstance || this.compileElement.view.componentContext;
|
||||
var actionStmts = convertCdStatementToIr(
|
||||
this.compileElement.view, context, hostEvent.handler, this.compileElement.nodeIndex);
|
||||
var lastIndex = actionStmts.length - 1;
|
||||
@ -96,7 +96,7 @@ export class CompileEventListener {
|
||||
}
|
||||
|
||||
listenToRenderer() {
|
||||
var listenExpr: any /** TODO #9100 */;
|
||||
var listenExpr: o.Expression;
|
||||
var eventListener = o.THIS_EXPR.callMethod(
|
||||
'eventHandler',
|
||||
[o.THIS_EXPR.prop(this._methodName).callMethod(o.BuiltinMethod.Bind, [o.THIS_EXPR])]);
|
||||
@ -114,21 +114,13 @@ export class CompileEventListener {
|
||||
disposable.set(listenExpr).toDeclStmt(o.FUNCTION_TYPE, [o.StmtModifier.Private]));
|
||||
}
|
||||
|
||||
listenToAnimation() {
|
||||
var outputListener = o.THIS_EXPR.callMethod(
|
||||
'eventHandler',
|
||||
[o.THIS_EXPR.prop(this._methodName).callMethod(o.BuiltinMethod.Bind, [o.THIS_EXPR])]);
|
||||
|
||||
// tie the property callback method to the view animations map
|
||||
var stmt = o.THIS_EXPR
|
||||
.callMethod(
|
||||
'registerAnimationOutput',
|
||||
[
|
||||
this.compileElement.renderNode, o.literal(this.eventName),
|
||||
o.literal(this.eventPhase), outputListener
|
||||
])
|
||||
.toStmt();
|
||||
this.compileElement.view.createMethod.addStmt(stmt);
|
||||
listenToAnimation(animationTransitionVar: o.ReadVarExpr): o.Statement {
|
||||
const callbackMethod = this.eventPhase == 'start' ? 'onStart' : 'onDone';
|
||||
return animationTransitionVar
|
||||
.callMethod(
|
||||
callbackMethod,
|
||||
[o.THIS_EXPR.prop(this.methodName).callMethod(o.BuiltinMethod.Bind, [o.THIS_EXPR])])
|
||||
.toStmt();
|
||||
}
|
||||
|
||||
listenToDirective(directiveInstance: o.Expression, observablePropName: string) {
|
||||
@ -148,13 +140,15 @@ export class CompileEventListener {
|
||||
export function collectEventListeners(
|
||||
hostEvents: BoundEventAst[], dirs: DirectiveAst[],
|
||||
compileElement: CompileElement): CompileEventListener[] {
|
||||
var eventListeners: CompileEventListener[] = [];
|
||||
const eventListeners: CompileEventListener[] = [];
|
||||
|
||||
hostEvents.forEach((hostEvent) => {
|
||||
compileElement.view.bindings.push(new CompileBinding(compileElement, hostEvent));
|
||||
var listener = CompileEventListener.getOrCreate(
|
||||
compileElement, hostEvent.target, hostEvent.name, hostEvent.phase, eventListeners);
|
||||
listener.addAction(hostEvent, null, null);
|
||||
});
|
||||
|
||||
dirs.forEach((directiveAst) => {
|
||||
var directiveInstance =
|
||||
compileElement.instances.get(identifierToken(directiveAst.directive.type).reference);
|
||||
@ -165,6 +159,7 @@ export function collectEventListeners(
|
||||
listener.addAction(hostEvent, directiveAst.directive, directiveInstance);
|
||||
});
|
||||
});
|
||||
|
||||
eventListeners.forEach((listener) => listener.finishMethod());
|
||||
return eventListeners;
|
||||
}
|
||||
@ -174,6 +169,7 @@ export function bindDirectiveOutputs(
|
||||
eventListeners: CompileEventListener[]) {
|
||||
Object.keys(directiveAst.directive.outputs).forEach(observablePropName => {
|
||||
const eventName = directiveAst.directive.outputs[observablePropName];
|
||||
|
||||
eventListeners.filter(listener => listener.eventName == eventName).forEach((listener) => {
|
||||
listener.listenToDirective(directiveInstance, observablePropName);
|
||||
});
|
||||
@ -182,9 +178,9 @@ export function bindDirectiveOutputs(
|
||||
|
||||
export function bindRenderOutputs(eventListeners: CompileEventListener[]) {
|
||||
eventListeners.forEach(listener => {
|
||||
if (listener.eventPhase) {
|
||||
listener.listenToAnimation();
|
||||
} else {
|
||||
// the animation listeners are handled within property_binder.ts to
|
||||
// allow them to be placed next to the animation factory statements
|
||||
if (!listener.isAnimation) {
|
||||
listener.listenToRenderer();
|
||||
}
|
||||
});
|
||||
@ -199,6 +195,6 @@ function convertStmtIntoExpression(stmt: o.Statement): o.Expression {
|
||||
return null;
|
||||
}
|
||||
|
||||
function santitizeEventName(name: string): string {
|
||||
return StringWrapper.replaceAll(name, /[^a-zA-Z_]/g, '_');
|
||||
function sanitizeEventName(name: string): string {
|
||||
return name.replace(/[^a-zA-Z_]/g, '_');
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
import * as cdAst from '../expression_parser/ast';
|
||||
import {isArray, isBlank, isPresent} from '../facade/lang';
|
||||
import {isBlank, isPresent} from '../facade/lang';
|
||||
import {Identifiers, resolveIdentifier} from '../identifiers';
|
||||
import * as o from '../output/output_ast';
|
||||
|
||||
@ -471,7 +471,7 @@ class _AstToIrVisitor implements cdAst.AstVisitor {
|
||||
}
|
||||
|
||||
function flattenStatements(arg: any, output: o.Statement[]) {
|
||||
if (isArray(arg)) {
|
||||
if (Array.isArray(arg)) {
|
||||
(<any[]>arg).forEach((entry) => flattenStatements(entry, output));
|
||||
} else {
|
||||
output.push(arg);
|
||||
|
@ -20,27 +20,6 @@ import {DetectChangesVars} from './constants';
|
||||
var STATE_IS_NEVER_CHECKED = o.THIS_EXPR.prop('numberOfChecks').identical(new o.LiteralExpr(0));
|
||||
var NOT_THROW_ON_CHANGES = o.not(DetectChangesVars.throwOnChange);
|
||||
|
||||
export function bindDirectiveDetectChangesLifecycleCallbacks(
|
||||
directiveAst: DirectiveAst, directiveInstance: o.Expression, compileElement: CompileElement) {
|
||||
var view = compileElement.view;
|
||||
var detectChangesInInputsMethod = view.detectChangesInInputsMethod;
|
||||
var lifecycleHooks = directiveAst.directive.type.lifecycleHooks;
|
||||
if (lifecycleHooks.indexOf(LifecycleHooks.OnChanges) !== -1 && directiveAst.inputs.length > 0) {
|
||||
detectChangesInInputsMethod.addStmt(new o.IfStmt(
|
||||
DetectChangesVars.changes.notIdentical(o.NULL_EXPR),
|
||||
[directiveInstance.callMethod('ngOnChanges', [DetectChangesVars.changes]).toStmt()]));
|
||||
}
|
||||
if (lifecycleHooks.indexOf(LifecycleHooks.OnInit) !== -1) {
|
||||
detectChangesInInputsMethod.addStmt(new o.IfStmt(
|
||||
STATE_IS_NEVER_CHECKED.and(NOT_THROW_ON_CHANGES),
|
||||
[directiveInstance.callMethod('ngOnInit', []).toStmt()]));
|
||||
}
|
||||
if (lifecycleHooks.indexOf(LifecycleHooks.DoCheck) !== -1) {
|
||||
detectChangesInInputsMethod.addStmt(new o.IfStmt(
|
||||
NOT_THROW_ON_CHANGES, [directiveInstance.callMethod('ngDoCheck', []).toStmt()]));
|
||||
}
|
||||
}
|
||||
|
||||
export function bindDirectiveAfterContentLifecycleCallbacks(
|
||||
directiveMeta: CompileDirectiveMetadata, directiveInstance: o.Expression,
|
||||
compileElement: CompileElement) {
|
||||
|
@ -21,6 +21,7 @@ import {CompileElement, CompileNode} from './compile_element';
|
||||
import {CompileMethod} from './compile_method';
|
||||
import {CompileView} from './compile_view';
|
||||
import {DetectChangesVars, ViewProperties} from './constants';
|
||||
import {CompileEventListener} from './event_binder';
|
||||
import {convertCdExpressionToIr, temporaryDeclaration} from './expression_converter';
|
||||
|
||||
function createBindFieldExpr(exprIndex: number): o.ReadPropExpr {
|
||||
@ -31,15 +32,18 @@ function createCurrValueExpr(exprIndex: number): o.ReadVarExpr {
|
||||
return o.variable(`currVal_${exprIndex}`); // fix syntax highlighting: `
|
||||
}
|
||||
|
||||
function bind(
|
||||
view: CompileView, currValExpr: o.ReadVarExpr, fieldExpr: o.ReadPropExpr,
|
||||
parsedExpression: cdAst.AST, context: o.Expression, actions: o.Statement[],
|
||||
method: CompileMethod, bindingIndex: number) {
|
||||
class EvalResult {
|
||||
constructor(public forceUpdate: o.Expression) {}
|
||||
}
|
||||
|
||||
function evalCdAst(
|
||||
view: CompileView, currValExpr: o.ReadVarExpr, parsedExpression: cdAst.AST,
|
||||
context: o.Expression, method: CompileMethod, bindingIndex: number): EvalResult {
|
||||
var checkExpression = convertCdExpressionToIr(
|
||||
view, context, parsedExpression, DetectChangesVars.valUnwrapper, bindingIndex);
|
||||
if (!checkExpression.expression) {
|
||||
// e.g. an empty expression was given
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkExpression.temporaryCount) {
|
||||
@ -48,24 +52,39 @@ function bind(
|
||||
}
|
||||
}
|
||||
|
||||
// private is fine here as no child view will reference the cached value...
|
||||
view.fields.push(new o.ClassField(fieldExpr.name, null, [o.StmtModifier.Private]));
|
||||
view.createMethod.addStmt(o.THIS_EXPR.prop(fieldExpr.name)
|
||||
.set(o.importExpr(resolveIdentifier(Identifiers.UNINITIALIZED)))
|
||||
.toStmt());
|
||||
|
||||
if (checkExpression.needsValueUnwrapper) {
|
||||
var initValueUnwrapperStmt = DetectChangesVars.valUnwrapper.callMethod('reset', []).toStmt();
|
||||
method.addStmt(initValueUnwrapperStmt);
|
||||
}
|
||||
method.addStmt(
|
||||
currValExpr.set(checkExpression.expression).toDeclStmt(null, [o.StmtModifier.Final]));
|
||||
if (checkExpression.needsValueUnwrapper) {
|
||||
return new EvalResult(DetectChangesVars.valUnwrapper.prop('hasWrappedValue'));
|
||||
} else {
|
||||
return new EvalResult(null);
|
||||
}
|
||||
}
|
||||
|
||||
function bind(
|
||||
view: CompileView, currValExpr: o.ReadVarExpr, fieldExpr: o.ReadPropExpr,
|
||||
parsedExpression: cdAst.AST, context: o.Expression, actions: o.Statement[],
|
||||
method: CompileMethod, bindingIndex: number) {
|
||||
const evalResult = evalCdAst(view, currValExpr, parsedExpression, context, method, bindingIndex);
|
||||
if (!evalResult) {
|
||||
return;
|
||||
}
|
||||
|
||||
// private is fine here as no child view will reference the cached value...
|
||||
view.fields.push(new o.ClassField(fieldExpr.name, null, [o.StmtModifier.Private]));
|
||||
view.createMethod.addStmt(o.THIS_EXPR.prop(fieldExpr.name)
|
||||
.set(o.importExpr(resolveIdentifier(Identifiers.UNINITIALIZED)))
|
||||
.toStmt());
|
||||
|
||||
var condition: o.Expression = o.importExpr(resolveIdentifier(Identifiers.checkBinding)).callFn([
|
||||
DetectChangesVars.throwOnChange, fieldExpr, currValExpr
|
||||
]);
|
||||
if (checkExpression.needsValueUnwrapper) {
|
||||
condition = DetectChangesVars.valUnwrapper.prop('hasWrappedValue').or(condition);
|
||||
if (evalResult.forceUpdate) {
|
||||
condition = evalResult.forceUpdate.or(condition);
|
||||
}
|
||||
method.addStmt(new o.IfStmt(
|
||||
condition,
|
||||
@ -90,7 +109,7 @@ export function bindRenderText(
|
||||
|
||||
function bindAndWriteToRenderer(
|
||||
boundProps: BoundElementPropertyAst[], context: o.Expression, compileElement: CompileElement,
|
||||
isHostProp: boolean) {
|
||||
isHostProp: boolean, eventListeners: CompileEventListener[]) {
|
||||
var view = compileElement.view;
|
||||
var renderNode = compileElement.renderNode;
|
||||
boundProps.forEach((boundProp) => {
|
||||
@ -99,10 +118,9 @@ function bindAndWriteToRenderer(
|
||||
view.detectChangesRenderPropertiesMethod.resetDebugInfo(compileElement.nodeIndex, boundProp);
|
||||
var fieldExpr = createBindFieldExpr(bindingIndex);
|
||||
var currValExpr = createCurrValueExpr(bindingIndex);
|
||||
var renderMethod: string;
|
||||
var oldRenderValue: o.Expression = sanitizedValue(boundProp, fieldExpr);
|
||||
var renderValue: o.Expression = sanitizedValue(boundProp, currValExpr);
|
||||
var updateStmts: any[] /** TODO #9100 */ = [];
|
||||
var updateStmts: o.Statement[] = [];
|
||||
var compileMethod = view.detectChangesRenderPropertiesMethod;
|
||||
switch (boundProp.type) {
|
||||
case PropertyBindingType.Property:
|
||||
@ -143,41 +161,45 @@ function bindAndWriteToRenderer(
|
||||
.toStmt());
|
||||
break;
|
||||
case PropertyBindingType.Animation:
|
||||
var animationName = boundProp.name;
|
||||
var targetViewExpr: o.Expression = o.THIS_EXPR;
|
||||
if (isHostProp) {
|
||||
targetViewExpr = compileElement.appElement.prop('componentView');
|
||||
}
|
||||
|
||||
compileMethod = view.animationBindingsMethod;
|
||||
const detachStmts: o.Statement[] = [];
|
||||
|
||||
var animationFnExpr =
|
||||
const animationName = boundProp.name;
|
||||
const targetViewExpr: o.Expression =
|
||||
isHostProp ? compileElement.appElement.prop('componentView') : o.THIS_EXPR;
|
||||
|
||||
const animationFnExpr =
|
||||
targetViewExpr.prop('componentType').prop('animations').key(o.literal(animationName));
|
||||
|
||||
// it's important to normalize the void value as `void` explicitly
|
||||
// so that the styles data can be obtained from the stringmap
|
||||
var emptyStateValue = o.literal(EMPTY_ANIMATION_STATE);
|
||||
|
||||
// void => ...
|
||||
var oldRenderVar = o.variable('oldRenderVar');
|
||||
updateStmts.push(oldRenderVar.set(oldRenderValue).toDeclStmt());
|
||||
updateStmts.push(new o.IfStmt(
|
||||
oldRenderVar.equals(o.importExpr(resolveIdentifier(Identifiers.UNINITIALIZED))),
|
||||
[oldRenderVar.set(emptyStateValue).toStmt()]));
|
||||
|
||||
// ... => void
|
||||
var newRenderVar = o.variable('newRenderVar');
|
||||
updateStmts.push(newRenderVar.set(renderValue).toDeclStmt());
|
||||
updateStmts.push(new o.IfStmt(
|
||||
newRenderVar.equals(o.importExpr(resolveIdentifier(Identifiers.UNINITIALIZED))),
|
||||
[newRenderVar.set(emptyStateValue).toStmt()]));
|
||||
const emptyStateValue = o.literal(EMPTY_ANIMATION_STATE);
|
||||
const unitializedValue = o.importExpr(resolveIdentifier(Identifiers.UNINITIALIZED));
|
||||
const animationTransitionVar = o.variable('animationTransition_' + animationName);
|
||||
|
||||
updateStmts.push(
|
||||
animationFnExpr.callFn([o.THIS_EXPR, renderNode, oldRenderVar, newRenderVar]).toStmt());
|
||||
animationTransitionVar
|
||||
.set(animationFnExpr.callFn([
|
||||
o.THIS_EXPR, renderNode, oldRenderValue.equals(unitializedValue)
|
||||
.conditional(emptyStateValue, oldRenderValue),
|
||||
renderValue.equals(unitializedValue).conditional(emptyStateValue, renderValue)
|
||||
]))
|
||||
.toDeclStmt());
|
||||
|
||||
view.detachMethod.addStmt(
|
||||
animationFnExpr.callFn([o.THIS_EXPR, renderNode, oldRenderValue, emptyStateValue])
|
||||
.toStmt());
|
||||
detachStmts.push(animationTransitionVar
|
||||
.set(animationFnExpr.callFn(
|
||||
[o.THIS_EXPR, renderNode, oldRenderValue, emptyStateValue]))
|
||||
.toDeclStmt());
|
||||
|
||||
eventListeners.forEach(listener => {
|
||||
if (listener.isAnimation && listener.eventName === animationName) {
|
||||
let animationStmt = listener.listenToAnimation(animationTransitionVar);
|
||||
updateStmts.push(animationStmt);
|
||||
detachStmts.push(animationStmt);
|
||||
}
|
||||
});
|
||||
|
||||
view.detachMethod.addStmts(detachStmts);
|
||||
|
||||
break;
|
||||
}
|
||||
@ -219,93 +241,62 @@ function sanitizedValue(
|
||||
}
|
||||
|
||||
export function bindRenderInputs(
|
||||
boundProps: BoundElementPropertyAst[], compileElement: CompileElement): void {
|
||||
bindAndWriteToRenderer(boundProps, compileElement.view.componentContext, compileElement, false);
|
||||
boundProps: BoundElementPropertyAst[], compileElement: CompileElement,
|
||||
eventListeners: CompileEventListener[]): void {
|
||||
bindAndWriteToRenderer(
|
||||
boundProps, compileElement.view.componentContext, compileElement, false, eventListeners);
|
||||
}
|
||||
|
||||
export function bindDirectiveHostProps(
|
||||
directiveAst: DirectiveAst, directiveInstance: o.Expression,
|
||||
compileElement: CompileElement): void {
|
||||
bindAndWriteToRenderer(directiveAst.hostProperties, directiveInstance, compileElement, true);
|
||||
directiveAst: DirectiveAst, directiveInstance: o.Expression, compileElement: CompileElement,
|
||||
eventListeners: CompileEventListener[]): void {
|
||||
bindAndWriteToRenderer(
|
||||
directiveAst.hostProperties, directiveInstance, compileElement, true, eventListeners);
|
||||
}
|
||||
|
||||
export function bindDirectiveInputs(
|
||||
directiveAst: DirectiveAst, directiveInstance: o.Expression, compileElement: CompileElement) {
|
||||
if (directiveAst.inputs.length === 0) {
|
||||
return;
|
||||
}
|
||||
directiveAst: DirectiveAst, directiveWrapperInstance: o.Expression,
|
||||
compileElement: CompileElement) {
|
||||
var view = compileElement.view;
|
||||
var detectChangesInInputsMethod = view.detectChangesInInputsMethod;
|
||||
detectChangesInInputsMethod.resetDebugInfo(compileElement.nodeIndex, compileElement.sourceAst);
|
||||
|
||||
var lifecycleHooks = directiveAst.directive.type.lifecycleHooks;
|
||||
var calcChangesMap = lifecycleHooks.indexOf(LifecycleHooks.OnChanges) !== -1;
|
||||
var isOnPushComp = directiveAst.directive.isComponent &&
|
||||
!isDefaultChangeDetectionStrategy(directiveAst.directive.changeDetection);
|
||||
if (calcChangesMap) {
|
||||
detectChangesInInputsMethod.addStmt(DetectChangesVars.changes.set(o.NULL_EXPR).toStmt());
|
||||
}
|
||||
if (isOnPushComp) {
|
||||
detectChangesInInputsMethod.addStmt(DetectChangesVars.changed.set(o.literal(false)).toStmt());
|
||||
}
|
||||
directiveAst.inputs.forEach((input) => {
|
||||
var bindingIndex = view.bindings.length;
|
||||
view.bindings.push(new CompileBinding(compileElement, input));
|
||||
detectChangesInInputsMethod.resetDebugInfo(compileElement.nodeIndex, input);
|
||||
var fieldExpr = createBindFieldExpr(bindingIndex);
|
||||
var currValExpr = createCurrValueExpr(bindingIndex);
|
||||
var statements: o.Statement[] =
|
||||
[directiveInstance.prop(input.directiveName).set(currValExpr).toStmt()];
|
||||
if (calcChangesMap) {
|
||||
statements.push(new o.IfStmt(
|
||||
DetectChangesVars.changes.identical(o.NULL_EXPR),
|
||||
[DetectChangesVars.changes
|
||||
.set(o.literalMap(
|
||||
[], new o.MapType(o.importType(resolveIdentifier(Identifiers.SimpleChange)))))
|
||||
.toStmt()]));
|
||||
statements.push(DetectChangesVars.changes.key(o.literal(input.directiveName))
|
||||
.set(o.importExpr(resolveIdentifier(Identifiers.SimpleChange))
|
||||
.instantiate([fieldExpr, currValExpr]))
|
||||
.toStmt());
|
||||
const evalResult = evalCdAst(
|
||||
view, currValExpr, input.value, view.componentContext, detectChangesInInputsMethod,
|
||||
bindingIndex);
|
||||
if (!evalResult) {
|
||||
return;
|
||||
}
|
||||
if (isOnPushComp) {
|
||||
statements.push(DetectChangesVars.changed.set(o.literal(true)).toStmt());
|
||||
}
|
||||
if (view.genConfig.logBindingUpdate) {
|
||||
statements.push(
|
||||
logBindingUpdateStmt(compileElement.renderNode, input.directiveName, currValExpr));
|
||||
}
|
||||
bind(
|
||||
view, currValExpr, fieldExpr, input.value, view.componentContext, statements,
|
||||
detectChangesInInputsMethod, bindingIndex);
|
||||
detectChangesInInputsMethod.addStmt(directiveWrapperInstance
|
||||
.callMethod(
|
||||
`check_${input.directiveName}`,
|
||||
[
|
||||
currValExpr, DetectChangesVars.throwOnChange,
|
||||
evalResult.forceUpdate || o.literal(false)
|
||||
])
|
||||
.toStmt());
|
||||
});
|
||||
if (isOnPushComp) {
|
||||
detectChangesInInputsMethod.addStmt(new o.IfStmt(DetectChangesVars.changed, [
|
||||
compileElement.appElement.prop('componentView').callMethod('markAsCheckOnce', []).toStmt()
|
||||
]));
|
||||
}
|
||||
var isOnPushComp = directiveAst.directive.isComponent &&
|
||||
!isDefaultChangeDetectionStrategy(directiveAst.directive.changeDetection);
|
||||
let directiveDetectChangesExpr = directiveWrapperInstance.callMethod(
|
||||
'detectChangesInternal',
|
||||
[o.THIS_EXPR, compileElement.renderNode, DetectChangesVars.throwOnChange]);
|
||||
const directiveDetectChangesStmt = isOnPushComp ?
|
||||
new o.IfStmt(directiveDetectChangesExpr, [compileElement.appElement.prop('componentView')
|
||||
.callMethod('markAsCheckOnce', [])
|
||||
.toStmt()]) :
|
||||
directiveDetectChangesExpr.toStmt();
|
||||
detectChangesInInputsMethod.addStmt(directiveDetectChangesStmt);
|
||||
}
|
||||
|
||||
function logBindingUpdateStmt(
|
||||
renderNode: o.Expression, propName: string, value: o.Expression): o.Statement {
|
||||
const tryStmt =
|
||||
o.THIS_EXPR.prop('renderer')
|
||||
.callMethod(
|
||||
'setBindingDebugInfo',
|
||||
[
|
||||
renderNode, o.literal(`ng-reflect-${camelCaseToDashCase(propName)}`),
|
||||
value.isBlank().conditional(o.NULL_EXPR, value.callMethod('toString', []))
|
||||
])
|
||||
.toStmt();
|
||||
|
||||
const catchStmt = o.THIS_EXPR.prop('renderer')
|
||||
.callMethod(
|
||||
'setBindingDebugInfo',
|
||||
[
|
||||
renderNode, o.literal(`ng-reflect-${camelCaseToDashCase(propName)}`),
|
||||
o.literal('[ERROR] Exception while trying to serialize the value')
|
||||
])
|
||||
.toStmt();
|
||||
|
||||
return new o.TryCatchStmt([tryStmt], [catchStmt]);
|
||||
return o.importExpr(resolveIdentifier(Identifiers.setBindingDebugInfo))
|
||||
.callFn([o.THIS_EXPR.prop('renderer'), renderNode, o.literal(propName), value])
|
||||
.toStmt();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
|
||||
import {CompileDirectiveMetadata, CompileTokenMetadata} from '../compile_metadata';
|
||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileTokenMetadata} from '../compile_metadata';
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {Identifiers, resolveIdentifier} from '../identifiers';
|
||||
import * as o from '../output/output_ast';
|
||||
@ -30,15 +30,28 @@ export function getPropertyInView(
|
||||
throw new Error(
|
||||
`Internal error: Could not calculate a property in a parent view: ${property}`);
|
||||
}
|
||||
if (property instanceof o.ReadPropExpr) {
|
||||
let readPropExpr: o.ReadPropExpr = property;
|
||||
return property.visitExpression(new _ReplaceViewTransformer(viewProp, definedView), null);
|
||||
}
|
||||
}
|
||||
|
||||
class _ReplaceViewTransformer extends o.ExpressionTransformer {
|
||||
constructor(private _viewExpr: o.Expression, private _view: CompileView) { super(); }
|
||||
private _isThis(expr: o.Expression): boolean {
|
||||
return expr instanceof o.ReadVarExpr && expr.builtin === o.BuiltinVar.This;
|
||||
}
|
||||
|
||||
visitReadVarExpr(ast: o.ReadVarExpr, context: any): any {
|
||||
return this._isThis(ast) ? this._viewExpr : ast;
|
||||
}
|
||||
visitReadPropExpr(ast: o.ReadPropExpr, context: any): any {
|
||||
if (this._isThis(ast.receiver)) {
|
||||
// Note: Don't cast for members of the AppView base class...
|
||||
if (definedView.fields.some((field) => field.name == readPropExpr.name) ||
|
||||
definedView.getters.some((field) => field.name == readPropExpr.name)) {
|
||||
viewProp = viewProp.cast(definedView.classType);
|
||||
if (this._view.fields.some((field) => field.name == ast.name) ||
|
||||
this._view.getters.some((field) => field.name == ast.name)) {
|
||||
return this._viewExpr.cast(this._view.classType).prop(ast.name);
|
||||
}
|
||||
}
|
||||
return o.replaceVarInExpression(o.THIS_EXPR.name, viewProp, property);
|
||||
return super.visitReadPropExpr(ast, context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +70,7 @@ export function getViewFactoryName(
|
||||
}
|
||||
|
||||
export function createFlatArray(expressions: o.Expression[]): o.Expression {
|
||||
var lastNonArrayExpressions: any[] /** TODO #9100 */ = [];
|
||||
var lastNonArrayExpressions: o.Expression[] = [];
|
||||
var result: o.Expression = o.literalArr([]);
|
||||
for (var i = 0; i < expressions.length; i++) {
|
||||
var expr = expressions[i];
|
||||
|
@ -11,7 +11,7 @@ import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventA
|
||||
import {CompileElement} from './compile_element';
|
||||
import {CompileView} from './compile_view';
|
||||
import {CompileEventListener, bindDirectiveOutputs, bindRenderOutputs, collectEventListeners} from './event_binder';
|
||||
import {bindDirectiveAfterContentLifecycleCallbacks, bindDirectiveAfterViewLifecycleCallbacks, bindDirectiveDetectChangesLifecycleCallbacks, bindInjectableDestroyLifecycleCallbacks, bindPipeDestroyLifecycleCallbacks} from './lifecycle_binder';
|
||||
import {bindDirectiveAfterContentLifecycleCallbacks, bindDirectiveAfterViewLifecycleCallbacks, bindInjectableDestroyLifecycleCallbacks, bindPipeDestroyLifecycleCallbacks} from './lifecycle_binder';
|
||||
import {bindDirectiveHostProps, bindDirectiveInputs, bindRenderInputs, bindRenderText} from './property_binder';
|
||||
|
||||
export function bindView(view: CompileView, parsedTemplate: TemplateAst[]): void {
|
||||
@ -44,14 +44,15 @@ class ViewBinderVisitor implements TemplateAstVisitor {
|
||||
collectEventListeners(ast.outputs, ast.directives, compileElement).forEach(entry => {
|
||||
eventListeners.push(entry);
|
||||
});
|
||||
bindRenderInputs(ast.inputs, compileElement);
|
||||
bindRenderInputs(ast.inputs, compileElement, eventListeners);
|
||||
bindRenderOutputs(eventListeners);
|
||||
ast.directives.forEach((directiveAst) => {
|
||||
var directiveInstance = compileElement.instances.get(directiveAst.directive.type.reference);
|
||||
bindDirectiveInputs(directiveAst, directiveInstance, compileElement);
|
||||
bindDirectiveDetectChangesLifecycleCallbacks(directiveAst, directiveInstance, compileElement);
|
||||
var directiveWrapperInstance =
|
||||
compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference);
|
||||
bindDirectiveInputs(directiveAst, directiveWrapperInstance, compileElement);
|
||||
|
||||
bindDirectiveHostProps(directiveAst, directiveInstance, compileElement);
|
||||
bindDirectiveHostProps(directiveAst, directiveInstance, compileElement, eventListeners);
|
||||
bindDirectiveOutputs(directiveAst, directiveInstance, eventListeners);
|
||||
});
|
||||
templateVisitAll(this, ast.children, compileElement);
|
||||
@ -76,8 +77,10 @@ class ViewBinderVisitor implements TemplateAstVisitor {
|
||||
var eventListeners = collectEventListeners(ast.outputs, ast.directives, compileElement);
|
||||
ast.directives.forEach((directiveAst) => {
|
||||
var directiveInstance = compileElement.instances.get(directiveAst.directive.type.reference);
|
||||
bindDirectiveInputs(directiveAst, directiveInstance, compileElement);
|
||||
bindDirectiveDetectChangesLifecycleCallbacks(directiveAst, directiveInstance, compileElement);
|
||||
var directiveWrapperInstance =
|
||||
compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference);
|
||||
bindDirectiveInputs(directiveAst, directiveWrapperInstance, compileElement);
|
||||
|
||||
bindDirectiveOutputs(directiveAst, directiveInstance, eventListeners);
|
||||
bindDirectiveAfterContentLifecycleCallbacks(
|
||||
directiveAst.directive, directiveInstance, compileElement);
|
||||
|
@ -10,7 +10,7 @@ import {ViewEncapsulation} from '@angular/core';
|
||||
|
||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileTokenMetadata} from '../compile_metadata';
|
||||
import {ListWrapper} from '../facade/collection';
|
||||
import {StringWrapper, isPresent} from '../facade/lang';
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {Identifiers, identifierToken, resolveIdentifier} from '../identifiers';
|
||||
import * as o from '../output/output_ast';
|
||||
import {ChangeDetectorStatus, ViewType, isDefaultChangeDetectionStrategy} from '../private_import_core';
|
||||
@ -20,6 +20,7 @@ import {createDiTokenExpression} from '../util';
|
||||
import {CompileElement, CompileNode} from './compile_element';
|
||||
import {CompileView} from './compile_view';
|
||||
import {ChangeDetectorStatusEnum, DetectChangesVars, InjectMethodVars, ViewConstructorVars, ViewEncapsulationEnum, ViewProperties, ViewTypeEnum} from './constants';
|
||||
import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewFactoryDependency} from './deps';
|
||||
import {createFlatArray, getViewFactoryName} from './util';
|
||||
|
||||
const IMPLICIT_TEMPLATE_VAR = '\$implicit';
|
||||
@ -30,20 +31,11 @@ const NG_CONTAINER_TAG = 'ng-container';
|
||||
var parentRenderNodeVar = o.variable('parentRenderNode');
|
||||
var rootSelectorVar = o.variable('rootSelector');
|
||||
|
||||
export class ViewFactoryDependency {
|
||||
constructor(
|
||||
public comp: CompileIdentifierMetadata, public placeholder: CompileIdentifierMetadata) {}
|
||||
}
|
||||
|
||||
export class ComponentFactoryDependency {
|
||||
constructor(
|
||||
public comp: CompileIdentifierMetadata, public placeholder: CompileIdentifierMetadata) {}
|
||||
}
|
||||
|
||||
|
||||
export function buildView(
|
||||
view: CompileView, template: TemplateAst[],
|
||||
targetDependencies: Array<ViewFactoryDependency|ComponentFactoryDependency>): number {
|
||||
targetDependencies:
|
||||
Array<ViewFactoryDependency|ComponentFactoryDependency|DirectiveWrapperDependency>):
|
||||
number {
|
||||
var builderVisitor = new ViewBuilderVisitor(view, targetDependencies);
|
||||
templateVisitAll(
|
||||
builderVisitor, template,
|
||||
@ -66,7 +58,8 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
|
||||
|
||||
constructor(
|
||||
public view: CompileView,
|
||||
public targetDependencies: Array<ViewFactoryDependency|ComponentFactoryDependency>) {}
|
||||
public targetDependencies:
|
||||
Array<ViewFactoryDependency|ComponentFactoryDependency|DirectiveWrapperDependency>) {}
|
||||
|
||||
private _isRootNode(parent: CompileElement): boolean { return parent.view !== this.view; }
|
||||
|
||||
@ -79,10 +72,10 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
|
||||
if (this._isRootNode(parent)) {
|
||||
// store appElement as root node only for ViewContainers
|
||||
if (this.view.viewType !== ViewType.COMPONENT) {
|
||||
this.view.rootNodesOrAppElements.push(isPresent(vcAppEl) ? vcAppEl : node.renderNode);
|
||||
this.view.rootNodesOrAppElements.push(vcAppEl || node.renderNode);
|
||||
}
|
||||
} else if (isPresent(parent.component) && isPresent(ngContentIndex)) {
|
||||
parent.addContentNode(ngContentIndex, isPresent(vcAppEl) ? vcAppEl : node.renderNode);
|
||||
parent.addContentNode(ngContentIndex, vcAppEl || node.renderNode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +197,7 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
|
||||
}
|
||||
var compileElement = new CompileElement(
|
||||
parent, this.view, nodeIndex, renderNode, ast, component, directives, ast.providers,
|
||||
ast.hasViewContainer, false, ast.references);
|
||||
ast.hasViewContainer, false, ast.references, this.targetDependencies);
|
||||
this.view.nodes.push(compileElement);
|
||||
var compViewExpr: o.ReadVarExpr = null;
|
||||
if (isPresent(component)) {
|
||||
@ -212,13 +205,6 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
|
||||
new CompileIdentifierMetadata({name: getViewFactoryName(component, 0)});
|
||||
this.targetDependencies.push(
|
||||
new ViewFactoryDependency(component.type, nestedComponentIdentifier));
|
||||
let entryComponentIdentifiers =
|
||||
component.entryComponents.map((entryComponent: CompileIdentifierMetadata) => {
|
||||
var id = new CompileIdentifierMetadata({name: entryComponent.name});
|
||||
this.targetDependencies.push(new ComponentFactoryDependency(entryComponent, id));
|
||||
return id;
|
||||
});
|
||||
compileElement.createComponentFactoryResolver(entryComponentIdentifiers);
|
||||
|
||||
compViewExpr = o.variable(`compView_${nodeIndex}`); // fix highlighting: `
|
||||
compileElement.setComponentView(compViewExpr);
|
||||
@ -273,7 +259,7 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
|
||||
var directives = ast.directives.map(directiveAst => directiveAst.directive);
|
||||
var compileElement = new CompileElement(
|
||||
parent, this.view, nodeIndex, renderNode, ast, null, directives, ast.providers,
|
||||
ast.hasViewContainer, true, ast.references);
|
||||
ast.hasViewContainer, true, ast.references, this.targetDependencies);
|
||||
this.view.nodes.push(compileElement);
|
||||
|
||||
this.nestedViewCount++;
|
||||
@ -376,7 +362,7 @@ function mapToKeyValueArray(data: {[key: string]: string}): string[][] {
|
||||
Object.keys(data).forEach(name => { entryArray.push([name, data[name]]); });
|
||||
// We need to sort to get a defined output order
|
||||
// for tests and for caching generated artifacts...
|
||||
ListWrapper.sort(entryArray, (entry1, entry2) => StringWrapper.compare(entry1[0], entry2[0]));
|
||||
ListWrapper.sort(entryArray);
|
||||
return entryArray;
|
||||
}
|
||||
|
||||
@ -511,10 +497,13 @@ function createViewFactory(
|
||||
templateUrlInfo = view.component.template.templateUrl;
|
||||
}
|
||||
if (view.viewIndex === 0) {
|
||||
var animationsExpr = o.literalMap(view.animations.map(entry => [entry.name, entry.fnExp]));
|
||||
initRenderCompTypeStmts = [new o.IfStmt(
|
||||
var animationsExpr = o.literalMap(
|
||||
view.animations.map((entry): [string, o.Expression] => [entry.name, entry.fnExp]));
|
||||
initRenderCompTypeStmts = [
|
||||
new o.IfStmt(
|
||||
renderCompTypeVar.identical(o.NULL_EXPR),
|
||||
[renderCompTypeVar
|
||||
[
|
||||
renderCompTypeVar
|
||||
.set(ViewConstructorVars.viewUtils.callMethod(
|
||||
'createRenderComponentType',
|
||||
[
|
||||
@ -524,13 +513,16 @@ function createViewFactory(
|
||||
view.styles,
|
||||
animationsExpr,
|
||||
]))
|
||||
.toStmt()])];
|
||||
.toStmt(),
|
||||
]),
|
||||
];
|
||||
}
|
||||
return o
|
||||
.fn(viewFactoryArgs, initRenderCompTypeStmts.concat([new o.ReturnStatement(
|
||||
o.variable(viewClass.name)
|
||||
.instantiate(viewClass.constructorMethod.params.map(
|
||||
(param) => o.variable(param.name))))]),
|
||||
.fn(viewFactoryArgs, initRenderCompTypeStmts.concat([
|
||||
new o.ReturnStatement(o.variable(viewClass.name)
|
||||
.instantiate(viewClass.constructorMethod.params.map(
|
||||
(param) => o.variable(param.name)))),
|
||||
]),
|
||||
o.importType(resolveIdentifier(Identifiers.AppView), [getContextType(view)]))
|
||||
.toDeclStmt(view.viewFactory.name, [o.StmtModifier.Final]);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
import {AnimationCompiler, AnimationEntryCompileResult} from '../animation/animation_compiler';
|
||||
import {AnimationEntryCompileResult} from '../animation/animation_compiler';
|
||||
import {CompileDirectiveMetadata, CompilePipeMetadata} from '../compile_metadata';
|
||||
import {CompilerConfig} from '../config';
|
||||
import * as o from '../output/output_ast';
|
||||
@ -16,27 +16,29 @@ import {TemplateAst} from '../template_parser/template_ast';
|
||||
|
||||
import {CompileElement} from './compile_element';
|
||||
import {CompileView} from './compile_view';
|
||||
import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewFactoryDependency} from './deps';
|
||||
import {bindView} from './view_binder';
|
||||
import {ComponentFactoryDependency, ViewFactoryDependency, buildView, finishView} from './view_builder';
|
||||
import {buildView, finishView} from './view_builder';
|
||||
|
||||
export {ComponentFactoryDependency, ViewFactoryDependency} from './view_builder';
|
||||
export {ComponentFactoryDependency, DirectiveWrapperDependency, ViewFactoryDependency} from './deps';
|
||||
|
||||
export class ViewCompileResult {
|
||||
constructor(
|
||||
public statements: o.Statement[], public viewFactoryVar: string,
|
||||
public dependencies: Array<ViewFactoryDependency|ComponentFactoryDependency>) {}
|
||||
public dependencies:
|
||||
Array<ViewFactoryDependency|ComponentFactoryDependency|DirectiveWrapperDependency>) {}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ViewCompiler {
|
||||
private _animationCompiler = new AnimationCompiler();
|
||||
constructor(private _genConfig: CompilerConfig) {}
|
||||
|
||||
compileComponent(
|
||||
component: CompileDirectiveMetadata, template: TemplateAst[], styles: o.Expression,
|
||||
pipes: CompilePipeMetadata[],
|
||||
compiledAnimations: AnimationEntryCompileResult[]): ViewCompileResult {
|
||||
const dependencies: Array<ViewFactoryDependency|ComponentFactoryDependency> = [];
|
||||
const dependencies:
|
||||
Array<ViewFactoryDependency|ComponentFactoryDependency|DirectiveWrapperDependency> = [];
|
||||
const view = new CompileView(
|
||||
component, this._genConfig, pipes, styles, compiledAnimations, 0,
|
||||
CompileElement.createNull(), []);
|
||||
|
@ -15,7 +15,7 @@ import {CompileMetadataResolver} from '../../src/metadata_resolver';
|
||||
|
||||
export function main() {
|
||||
describe('RuntimeAnimationCompiler', () => {
|
||||
var resolver: any /** TODO #9100 */;
|
||||
var resolver: CompileMetadataResolver;
|
||||
beforeEach(
|
||||
inject([CompileMetadataResolver], (res: CompileMetadataResolver) => { resolver = res; }));
|
||||
|
||||
|
@ -28,9 +28,9 @@ export function main() {
|
||||
(keyframe: AnimationKeyframeAst): {[key: string]: string | number} =>
|
||||
combineStyles(keyframe.styles);
|
||||
|
||||
var collectStepStyles = (step: AnimationStepAst): Array<{[key: string]: string | number}> => {
|
||||
var collectStepStyles = (step: AnimationStepAst): {[key: string]: string | number}[] => {
|
||||
var keyframes = step.keyframes;
|
||||
var styles: any[] /** TODO #9100 */ = [];
|
||||
var styles: {[key: string]: string | number}[] = [];
|
||||
if (step.startingStyles.styles.length > 0) {
|
||||
styles.push(combineStyles(step.startingStyles));
|
||||
}
|
||||
@ -38,7 +38,7 @@ export function main() {
|
||||
return styles;
|
||||
};
|
||||
|
||||
var resolver: any /** TODO #9100 */;
|
||||
var resolver: CompileMetadataResolver;
|
||||
beforeEach(
|
||||
inject([CompileMetadataResolver], (res: CompileMetadataResolver) => { resolver = res; }));
|
||||
|
||||
|
@ -275,7 +275,7 @@ export function main() {
|
||||
it('should throw an error if a selector is being parsed while in the wrong mode', () => {
|
||||
var cssCode = '.class > tag';
|
||||
|
||||
var capturedMessage: any /** TODO #9100 */;
|
||||
var capturedMessage: string;
|
||||
try {
|
||||
tokenize(cssCode, false, CssLexerMode.STYLE_BLOCK);
|
||||
} catch (e) {
|
||||
@ -298,7 +298,7 @@ export function main() {
|
||||
describe('Attribute Mode', () => {
|
||||
it('should consider attribute selectors as valid input and throw when an invalid modifier is used',
|
||||
() => {
|
||||
function tokenizeAttr(modifier: any /** TODO #9100 */) {
|
||||
function tokenizeAttr(modifier: string) {
|
||||
var cssCode = 'value' + modifier + '=\'something\'';
|
||||
return tokenize(cssCode, false, CssLexerMode.ATTRIBUTE_SELECTOR);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class MyVisitor implements CssAstVisitor {
|
||||
* @internal
|
||||
*/
|
||||
_capture(method: string, ast: CssAst, context: any) {
|
||||
this.captures[method] = isPresent(this.captures[method]) ? this.captures[method] : [];
|
||||
this.captures[method] = this.captures[method] || [];
|
||||
this.captures[method].push([ast, context]);
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
*/
|
||||
|
||||
import {hasLifecycleHook} from '@angular/compiler/src/lifecycle_reflector';
|
||||
import {LifecycleHooks} from '@angular/core/src/metadata/lifecycle_hooks';
|
||||
import {describe, expect, it} from '@angular/core/testing/testing_internal';
|
||||
import {SimpleChanges} from '@angular/core';
|
||||
import {LifecycleHooks as Hooks} from '@angular/core/src/metadata/lifecycle_hooks';
|
||||
|
||||
export function main() {
|
||||
describe('Create Directive', () => {
|
||||
@ -16,92 +16,81 @@ export function main() {
|
||||
|
||||
describe('ngOnChanges', () => {
|
||||
it('should be true when the directive has the ngOnChanges method', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.OnChanges, DirectiveWithOnChangesMethod))
|
||||
.toBe(true);
|
||||
expect(hasLifecycleHook(Hooks.OnChanges, DirectiveWithOnChangesMethod)).toBe(true);
|
||||
});
|
||||
|
||||
it('should be false otherwise', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.OnChanges, DirectiveNoHooks)).toBe(false);
|
||||
});
|
||||
it('should be false otherwise',
|
||||
() => { expect(hasLifecycleHook(Hooks.OnChanges, DirectiveNoHooks)).toBe(false); });
|
||||
});
|
||||
|
||||
describe('ngOnDestroy', () => {
|
||||
it('should be true when the directive has the ngOnDestroy method', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.OnDestroy, DirectiveWithOnDestroyMethod))
|
||||
.toBe(true);
|
||||
expect(hasLifecycleHook(Hooks.OnDestroy, DirectiveWithOnDestroyMethod)).toBe(true);
|
||||
});
|
||||
|
||||
it('should be false otherwise', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.OnDestroy, DirectiveNoHooks)).toBe(false);
|
||||
});
|
||||
it('should be false otherwise',
|
||||
() => { expect(hasLifecycleHook(Hooks.OnDestroy, DirectiveNoHooks)).toBe(false); });
|
||||
});
|
||||
|
||||
describe('ngOnInit', () => {
|
||||
it('should be true when the directive has the ngOnInit method', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.OnInit, DirectiveWithOnInitMethod)).toBe(true);
|
||||
});
|
||||
it('should be true when the directive has the ngOnInit method',
|
||||
() => { expect(hasLifecycleHook(Hooks.OnInit, DirectiveWithOnInitMethod)).toBe(true); });
|
||||
|
||||
it('should be false otherwise', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.OnInit, DirectiveNoHooks)).toBe(false);
|
||||
});
|
||||
it('should be false otherwise',
|
||||
() => { expect(hasLifecycleHook(Hooks.OnInit, DirectiveNoHooks)).toBe(false); });
|
||||
});
|
||||
|
||||
describe('ngDoCheck', () => {
|
||||
it('should be true when the directive has the ngDoCheck method', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.DoCheck, DirectiveWithOnCheckMethod)).toBe(true);
|
||||
expect(hasLifecycleHook(Hooks.DoCheck, DirectiveWithOnCheckMethod)).toBe(true);
|
||||
});
|
||||
|
||||
it('should be false otherwise', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.DoCheck, DirectiveNoHooks)).toBe(false);
|
||||
});
|
||||
it('should be false otherwise',
|
||||
() => { expect(hasLifecycleHook(Hooks.DoCheck, DirectiveNoHooks)).toBe(false); });
|
||||
});
|
||||
|
||||
describe('ngAfterContentInit', () => {
|
||||
it('should be true when the directive has the ngAfterContentInit method', () => {
|
||||
expect(hasLifecycleHook(
|
||||
LifecycleHooks.AfterContentInit, DirectiveWithAfterContentInitMethod))
|
||||
expect(hasLifecycleHook(Hooks.AfterContentInit, DirectiveWithAfterContentInitMethod))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it('should be false otherwise', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.AfterContentInit, DirectiveNoHooks)).toBe(false);
|
||||
expect(hasLifecycleHook(Hooks.AfterContentInit, DirectiveNoHooks)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ngAfterContentChecked', () => {
|
||||
it('should be true when the directive has the ngAfterContentChecked method', () => {
|
||||
expect(hasLifecycleHook(
|
||||
LifecycleHooks.AfterContentChecked, DirectiveWithAfterContentCheckedMethod))
|
||||
expect(
|
||||
hasLifecycleHook(Hooks.AfterContentChecked, DirectiveWithAfterContentCheckedMethod))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it('should be false otherwise', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.AfterContentChecked, DirectiveNoHooks))
|
||||
.toBe(false);
|
||||
expect(hasLifecycleHook(Hooks.AfterContentChecked, DirectiveNoHooks)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('ngAfterViewInit', () => {
|
||||
it('should be true when the directive has the ngAfterViewInit method', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit, DirectiveWithAfterViewInitMethod))
|
||||
expect(hasLifecycleHook(Hooks.AfterViewInit, DirectiveWithAfterViewInitMethod))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it('should be false otherwise', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit, DirectiveNoHooks)).toBe(false);
|
||||
});
|
||||
it('should be false otherwise',
|
||||
() => { expect(hasLifecycleHook(Hooks.AfterViewInit, DirectiveNoHooks)).toBe(false); });
|
||||
});
|
||||
|
||||
describe('ngAfterViewChecked', () => {
|
||||
it('should be true when the directive has the ngAfterViewChecked method', () => {
|
||||
expect(hasLifecycleHook(
|
||||
LifecycleHooks.AfterViewChecked, DirectiveWithAfterViewCheckedMethod))
|
||||
expect(hasLifecycleHook(Hooks.AfterViewChecked, DirectiveWithAfterViewCheckedMethod))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it('should be false otherwise', () => {
|
||||
expect(hasLifecycleHook(LifecycleHooks.AfterViewChecked, DirectiveNoHooks)).toBe(false);
|
||||
expect(hasLifecycleHook(Hooks.AfterViewChecked, DirectiveNoHooks)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -111,7 +100,7 @@ export function main() {
|
||||
class DirectiveNoHooks {}
|
||||
|
||||
class DirectiveWithOnChangesMethod {
|
||||
ngOnChanges(_: any /** TODO #9100 */) {}
|
||||
ngOnChanges(_: SimpleChanges) {}
|
||||
}
|
||||
|
||||
class DirectiveWithOnInitMethod {
|
||||
|
@ -435,7 +435,7 @@ export function main() {
|
||||
}
|
||||
|
||||
function programResourceLoaderSpy(spy: SpyResourceLoader, results: {[key: string]: string}) {
|
||||
spy.spy('get').andCallFake((url: string): Promise<any> => {
|
||||
spy.spy('get').and.callFake((url: string): Promise<any> => {
|
||||
var result = results[url];
|
||||
if (result) {
|
||||
return Promise.resolve(result);
|
||||
|
@ -117,6 +117,18 @@ class SomeDirectiveWithSameHostBindingAndInput {
|
||||
@Input() @HostBinding() prop: any;
|
||||
}
|
||||
|
||||
@Directive({selector: 'someDirective'})
|
||||
class SomeDirectiveWithMalformedHostBinding1 {
|
||||
@HostBinding('(a)')
|
||||
onA() {}
|
||||
}
|
||||
|
||||
@Directive({selector: 'someDirective'})
|
||||
class SomeDirectiveWithMalformedHostBinding2 {
|
||||
@HostBinding('[a]')
|
||||
onA() {}
|
||||
}
|
||||
|
||||
class SomeDirectiveWithoutMetadata {}
|
||||
|
||||
export function main() {
|
||||
@ -210,6 +222,17 @@ export function main() {
|
||||
expect(directiveMetadata.host)
|
||||
.toEqual({'(c)': 'onC()', '(a)': 'onA()', '(b)': 'onB($event.value)'});
|
||||
});
|
||||
|
||||
it('should throw when @HostBinding name starts with "("', () => {
|
||||
expect(() => resolver.resolve(SomeDirectiveWithMalformedHostBinding1))
|
||||
.toThrowError('@HostBinding can not bind to events. Use @HostListener instead.');
|
||||
});
|
||||
|
||||
it('should throw when @HostBinding name starts with "["', () => {
|
||||
expect(() => resolver.resolve(SomeDirectiveWithMalformedHostBinding2))
|
||||
.toThrowError(
|
||||
`@HostBinding parameter should be a property name, 'class.<name>', or 'attr.<name>'.`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('queries', () => {
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {ASTWithSource, BindingPipe, Interpolation, ParserError, TemplateBinding} from '@angular/compiler/src/expression_parser/ast';
|
||||
import {Lexer} from '@angular/compiler/src/expression_parser/lexer';
|
||||
import {Parser, TemplateBindingParseResult} from '@angular/compiler/src/expression_parser/parser';
|
||||
import {Parser, SplitInterpolation, TemplateBindingParseResult} from '@angular/compiler/src/expression_parser/parser';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {isBlank, isPresent} from '../../src/facade/lang';
|
||||
@ -39,6 +39,10 @@ export function main() {
|
||||
return createParser().parseInterpolation(text, location);
|
||||
}
|
||||
|
||||
function splitInterpolation(text: string, location: any = null): SplitInterpolation {
|
||||
return createParser().splitInterpolation(text, location);
|
||||
}
|
||||
|
||||
function parseSimpleBinding(text: string, location: any = null): ASTWithSource {
|
||||
return createParser().parseSimpleBinding(text, location);
|
||||
}
|
||||
@ -539,5 +543,18 @@ export function main() {
|
||||
it('should be able to recover from a missing selector in a array literal',
|
||||
() => recover('[[a.], b, c]'));
|
||||
});
|
||||
|
||||
describe('offsets', () => {
|
||||
it('should retain the offsets of an interpolation', () => {
|
||||
const interpolations = splitInterpolation('{{a}} {{b}} {{c}}');
|
||||
expect(interpolations.offsets).toEqual([2, 9, 16]);
|
||||
});
|
||||
|
||||
it('should retain the offsets into the expression AST of interpolations', () => {
|
||||
const source = parseInterpolation('{{a}} {{b}} {{c}}');
|
||||
const interpolation = source.ast as Interpolation;
|
||||
expect(interpolation.expressions.map(e => e.span.start)).toEqual([2, 9, 16]);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import {AST, AstVisitor, Binary, BindingPipe, Chain, Conditional, FunctionCall, ImplicitReceiver, Interpolation, KeyedRead, KeyedWrite, LiteralArray, LiteralMap, LiteralPrimitive, MethodCall, PrefixNot, PropertyRead, PropertyWrite, Quote, SafeMethodCall, SafePropertyRead} from '../../src/expression_parser/ast';
|
||||
import {StringWrapper, isString} from '../../src/facade/lang';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../../src/ml_parser/interpolation_config';
|
||||
|
||||
class Unparser implements AstVisitor {
|
||||
@ -133,8 +132,8 @@ class Unparser implements AstVisitor {
|
||||
}
|
||||
|
||||
visitLiteralPrimitive(ast: LiteralPrimitive, context: any) {
|
||||
if (isString(ast.value)) {
|
||||
this._expression += `"${StringWrapper.replaceAll(ast.value, Unparser._quoteRegExp, '\"')}"`;
|
||||
if (typeof ast.value === 'string') {
|
||||
this._expression += `"${ast.value.replace( Unparser._quoteRegExp, '\"')}"`;
|
||||
} else {
|
||||
this._expression += `${ast.value}`;
|
||||
}
|
||||
|
@ -376,6 +376,82 @@ export function main() {
|
||||
[html.ExpansionCase, '=0', 2, '=0 {msg}'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not report a value span for an attribute without a value', () => {
|
||||
const ast = parser.parse('<div bar></div>', 'TestComp');
|
||||
expect((ast.rootNodes[0] as html.Element).attrs[0].valueSpan).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should report a value span for an attibute with a value', () => {
|
||||
const ast = parser.parse('<div bar="12"></div>', 'TestComp');
|
||||
const attr = (ast.rootNodes[0] as html.Element).attrs[0];
|
||||
expect(attr.valueSpan.start.offset).toEqual(9);
|
||||
expect(attr.valueSpan.end.offset).toEqual(13);
|
||||
});
|
||||
});
|
||||
|
||||
describe('visitor', () => {
|
||||
it('should visit text nodes', () => {
|
||||
const result = humanizeDom(parser.parse('text', 'TestComp'));
|
||||
expect(result).toEqual([[html.Text, 'text', 0]]);
|
||||
});
|
||||
|
||||
it('should visit element nodes', () => {
|
||||
const result = humanizeDom(parser.parse('<div></div>', 'TestComp'));
|
||||
expect(result).toEqual([[html.Element, 'div', 0]]);
|
||||
});
|
||||
|
||||
it('should visit attribute nodes', () => {
|
||||
const result = humanizeDom(parser.parse('<div id="foo"></div>', 'TestComp'));
|
||||
expect(result).toContain([html.Attribute, 'id', 'foo']);
|
||||
});
|
||||
|
||||
it('should visit all nodes', () => {
|
||||
const result =
|
||||
parser.parse('<div id="foo"><span id="bar">a</span><span>b</span></div>', 'TestComp');
|
||||
const accumulator: html.Node[] = [];
|
||||
const visitor = new class {
|
||||
visit(node: html.Node, context: any) { accumulator.push(node); }
|
||||
visitElement(element: html.Element, context: any): any {
|
||||
html.visitAll(this, element.attrs);
|
||||
html.visitAll(this, element.children);
|
||||
}
|
||||
visitAttribute(attribute: html.Attribute, context: any): any {}
|
||||
visitText(text: html.Text, context: any): any {}
|
||||
visitComment(comment: html.Comment, context: any): any {}
|
||||
visitExpansion(expansion: html.Expansion, context: any): any {
|
||||
html.visitAll(this, expansion.cases);
|
||||
}
|
||||
visitExpansionCase(expansionCase: html.ExpansionCase, context: any): any {}
|
||||
};
|
||||
|
||||
html.visitAll(visitor, result.rootNodes);
|
||||
expect(accumulator.map(n => n.constructor)).toEqual([
|
||||
html.Element, html.Attribute, html.Element, html.Attribute, html.Text, html.Element,
|
||||
html.Text
|
||||
]);
|
||||
});
|
||||
|
||||
it('should skip typed visit if visit() returns a truthy value', () => {
|
||||
const visitor = new class {
|
||||
visit(node: html.Node, context: any) { return true; }
|
||||
visitElement(element: html.Element, context: any): any { throw Error('Unexpected'); }
|
||||
visitAttribute(attribute: html.Attribute, context: any): any {
|
||||
throw Error('Unexpected');
|
||||
}
|
||||
visitText(text: html.Text, context: any): any { throw Error('Unexpected'); }
|
||||
visitComment(comment: html.Comment, context: any): any { throw Error('Unexpected'); }
|
||||
visitExpansion(expansion: html.Expansion, context: any): any {
|
||||
throw Error('Unexpected');
|
||||
}
|
||||
visitExpansionCase(expansionCase: html.ExpansionCase, context: any): any {
|
||||
throw Error('Unexpected');
|
||||
}
|
||||
};
|
||||
const result = parser.parse('<div id="foo"></div><div id="bar"></div>', 'TestComp');
|
||||
const traversal = html.visitAll(visitor, result.rootNodes);
|
||||
expect(traversal).toEqual([true, true]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('errors', () => {
|
||||
|
@ -43,7 +43,7 @@ export function main() {
|
||||
describe('output emitter', () => {
|
||||
outputDefs.forEach((outputDef) => {
|
||||
describe(`${outputDef['name']}`, () => {
|
||||
var expressions: any /** TODO #9100 */;
|
||||
var expressions: {[k: string]: any};
|
||||
beforeEach(() => { expressions = outputDef['getExpressions']()(); });
|
||||
|
||||
it('should support literals', () => {
|
||||
@ -109,13 +109,16 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('operators', () => {
|
||||
var ops: any /** TODO #9100 */;
|
||||
var aObj: any /** TODO #9100 */, bObj: any /** TODO #9100 */;
|
||||
var ops: {[k: string]: Function};
|
||||
var aObj: any;
|
||||
var bObj: any;
|
||||
|
||||
beforeEach(() => {
|
||||
ops = expressions['operators'];
|
||||
aObj = new Object();
|
||||
bObj = new Object();
|
||||
aObj = {};
|
||||
bObj = {};
|
||||
});
|
||||
|
||||
it('should support ==', () => {
|
||||
expect(ops['=='](aObj, aObj)).toBe(true);
|
||||
expect(ops['=='](aObj, bObj)).toBe(false);
|
||||
|
@ -53,7 +53,7 @@ export function main() {
|
||||
it('should return an error from the definitions',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var url = '/foo';
|
||||
var response: any /** TODO #9100 */ = null;
|
||||
var response: string = null;
|
||||
resourceLoader.when(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
||||
resourceLoader.flush();
|
||||
@ -71,7 +71,7 @@ export function main() {
|
||||
it('should return an error from the expectations',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var url = '/foo';
|
||||
var response: any /** TODO #9100 */ = null;
|
||||
var response: string = null;
|
||||
resourceLoader.expect(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
||||
resourceLoader.flush();
|
||||
|
@ -117,7 +117,7 @@ export function main() {
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').andCallFake(() => Promise.resolve('hello'));
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve('hello'));
|
||||
let ngModuleFactory: NgModuleFactory<any>;
|
||||
compiler.compileModuleAsync(SomeModule).then((f) => ngModuleFactory = f);
|
||||
tick();
|
||||
@ -132,7 +132,7 @@ export function main() {
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').andCallFake(() => Promise.resolve(''));
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve(''));
|
||||
expect(() => compiler.compileModuleSync(SomeModule))
|
||||
.toThrowError(
|
||||
`Can't compile synchronously as ${stringify(SomeCompWithUrlTemplate)} is still being loaded!`);
|
||||
@ -144,7 +144,7 @@ export function main() {
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').andCallFake(() => Promise.resolve(''));
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve(''));
|
||||
dirResolver.setView(SomeComp, new ViewMetadata({template: ''}));
|
||||
dirResolver.setView(ChildComp, new ViewMetadata({templateUrl: '/someTpl.html'}));
|
||||
expect(() => compiler.compileModuleSync(SomeModule))
|
||||
@ -161,7 +161,7 @@ export function main() {
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').andCallFake(() => Promise.resolve('hello'));
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve('hello'));
|
||||
compiler.compileModuleAsync(SomeModule);
|
||||
tick();
|
||||
|
||||
|
@ -112,10 +112,8 @@ export function main() {
|
||||
it('should handle no context',
|
||||
() => { expect(s(':host {}', 'a', 'a-host')).toEqual('[a-host] {}'); });
|
||||
|
||||
it('should handle tag selector', () => {
|
||||
expect(s(':host(ul) {}', 'a', 'a-host')).toEqual('ul[a-host] {}');
|
||||
|
||||
});
|
||||
it('should handle tag selector',
|
||||
() => { expect(s(':host(ul) {}', 'a', 'a-host')).toEqual('ul[a-host] {}'); });
|
||||
|
||||
it('should handle class selector',
|
||||
() => { expect(s(':host(.x) {}', 'a', 'a-host')).toEqual('.x[a-host] {}'); });
|
||||
@ -141,6 +139,11 @@ export function main() {
|
||||
expect(s(':host([a="b"],[c=d]) {}', 'a', 'a-host'))
|
||||
.toEqual('[a="b"][a-host], [c="d"][a-host] {}');
|
||||
});
|
||||
|
||||
it('should handle pseudo selector', () => {
|
||||
expect(s(':host(:before) {}', 'a', 'a-host')).toEqual('[a-host]:before {}');
|
||||
expect(s(':host:before {}', 'a', 'a-host')).toEqual('[a-host]:before {}');
|
||||
});
|
||||
});
|
||||
|
||||
describe((':host-context'), () => {
|
||||
|
@ -11,7 +11,7 @@ import {UrlResolver} from '@angular/compiler/src/url_resolver';
|
||||
|
||||
export function main() {
|
||||
describe('extractStyleUrls', () => {
|
||||
var urlResolver: any /** TODO #9100 */;
|
||||
var urlResolver: UrlResolver;
|
||||
|
||||
beforeEach(() => { urlResolver = new UrlResolver(); });
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user