Commit Graph

3892 Commits

Author SHA1 Message Date
Ben Lesh abe4433202 test(ivy): add tests around directive attribute ghosting (#30544)
This battery of tests is to ensure the instructions we are generating have the same behavior in Ivy has they did in ViewEngine.

PR Close #30544
2019-05-21 09:03:03 -07:00
janith c79bffaacb docs: remove gender prefixes from examples (#29972)
PR Close #29972
2019-05-20 16:42:59 -07:00
Keen Yee Liau e688e02ee4 fix(bazel): ng test should run specific ts_web_test_suite (#30526)
PR closes https://github.com/angular/angular/issues/30191

PR Close #30526
2019-05-20 16:40:11 -07:00
Ben Lesh d7eaae6f22 refactor(ivy): Move instructions back to ɵɵ (#30546)
There is an encoding issue with using delta `Δ`, where the browser will attempt to detect the file encoding if the character set is not explicitly declared on a `<script/>` tag, and Chrome will find the `Δ` character and decide it is window-1252 encoding, which misinterprets the `Δ` character to be some other character that is not a valid JS identifier character

So back to the frog eyes we go.

```
    __
   /ɵɵ\
  ( -- ) - I am ineffable. I am forever.
 _/    \_
/  \  /  \
==  ==  ==
```

PR Close #30546
2019-05-20 16:37:47 -07:00
Miško Hevery 6454f76cf6 refactor(ivy): remove ngPrivateData megamorphic prop access (#30548)
PR Close #30548
2019-05-20 10:12:07 -07:00
Miško Hevery 28ae22ecb9 refactor(ivy): move `renderTemplate` into render_util.ts because it is only used in tests (#30548)
PR Close #30548
2019-05-20 10:12:07 -07:00
cexbrayat 95830ee584 feat(common): stricter types for SlicePipe (#30156)
Adds overloads to the `transform` methods of `SlicePipe`,
to have better types than `any` for `value` and `any` as a return.
With this commit, using `slice` in an `ngFor` still allow to type-check the content of the `ngFor`
with `fullTemplateTypeCheck` enabled in Ivy:

    <div *ngFor="let user of users | slice:0:2">{{ user.typo }}</div>
                                                        |
                                                        `typo` does not exist on type `UserModel`

whereas it is currently not catched (as the return of `slice` is `any`) neither in VE nor in Ivy.

BREAKING CHANGE
`SlicePipe` now only accepts an array of values, a string, null or undefined.
This was already the case in practice, and it still throws at runtime if another type is given.
But it is now a compilation error to try to call it with an unsupported type.

PR Close #30156
2019-05-17 14:21:36 -07:00
Alan a39f4e2301 test: fix paths tests to work cross platform (#30472)
In Windows when `/test.txt` is resolved it will be resolved to `[DRIVE]:/test.txt`

PR Close #30472
2019-05-17 13:34:11 -07:00
Paul Gschwendtner 8e2e9dcee6 test(ivy): move render3 view_container_ref tests to acceptance (#30488)
Moves all manual render3 view_container_ref tests that use property
bindings to acceptance tests with TestBed.

Two issues surfaced and refer to a difference between Ivy and View
engine:

* Multi-slot projection is not working with Ivy: FW-1331
* ViewContainerRef throws if index is invalid while View Engine clamped index: FW-1330

PR Close #30488
2019-05-17 13:33:22 -07:00
Alan fd7dd4d9fc refactor: clean up language service from unused code and imports (#30534)
PR Close #30534
2019-05-17 13:32:06 -07:00
Ben Lesh 01919fbaae test(ivy): Add TODOs (#30522)
PR Close #30522
2019-05-17 09:56:49 -07:00
Ben Lesh 80d4fc5e26 test(ivy): remove `new Component` use from inheritance tests (#30522)
PR Close #30522
2019-05-17 09:56:49 -07:00
Pete Bacon Darwin eda09e69ea fix(ivy): ngtsc - do not wrap arguments unnecessarily (#30349)
Previously we defensively wrapped expressions in case they ran afoul of
precedence rules. For example, it would be easy to create the TS AST structure
Call(Ternary(a, b, c)), but might result in printed code of:

```
a ? b : c()
```

Whereas the actual structure we meant to generate is:

```
(a ? b : c)()
```

However the TypeScript renderer appears to be clever enough to provide
parenthesis as necessary.

This commit removes these defensive paraenthesis in the cases of binary
and ternary operations.

FW-1273

PR Close #30349
2019-05-17 09:55:46 -07:00
JoostK 0937062a64 fix(ivy): type-checking should infer string type for interpolations (#30177)
Previously, interpolations were generated into TCBs as a comma-separated
list of expressions, letting TypeScript infer the type of the expression
as the type of the last expression in the chain. This is undesirable, as
interpolations always result in a string type at runtime. Therefore,
type-checking of bindings such as `<img src="{{ link }}"/>` where `link`
is an object would incorrectly report a type-error.

This commit adjusts the emitted TCB code for interpolations, where a
chain of string concatenations is emitted, starting with the empty string.
This ensures that the inferred type of the interpolation is of type string.

PR Close #30177
2019-05-17 09:55:11 -07:00
JoostK 6f073885b0 refactor(ivy): translate template nodes to typescript using a visitor (#30177)
PR Close #30177
2019-05-17 09:55:11 -07:00
Matias Niemelä f03475cac8 refactor(ivy): evaluate prop-based styling bindings with a new algorithm (#30469)
This is the first refactor PR designed to change how styling bindings
(i.e. `[style]` and `[class]`) behave in Ivy. Instead of having a heavy
element-by-element context be generated for each element, this new
refactor aims to use a single context for each `tNode` element that is
examined and iterated over when styling values are to be applied to the
element.

This patch brings this new functionality to prop-based bindings such as
`[style.prop]` and `[class.name]`.

PR Close #30469
2019-05-17 09:54:19 -07:00
George Kalpakas 848e53efd0 test(platform-browser-dynamic): avoid swallowing error in `CachedResourceLoader` test (#30515)
Previously, in order to assert that the promise was not resolved, an
error was thrown when the promise was resolved successfully. At the
same, `.catch()` was used to silence the (expected) promise rejection.
However, the chained `.catch()` handler would also catch (and swallow)
the error thrown on resolving the promise, making the test pass, even if
the promise was not rejected.

This commit fixes it by ensuring that the error thrown on resolving the
promise is not caught by the rejection handler.

PR Close #30515
2019-05-16 20:14:04 -07:00
George Kalpakas 6bf8b1007c test(platform-browser-dynamic): make `CachedResourceLoader` tests more reliable (#30515)
Previously, [this test][1] would occasionally fail (e.g. on CI) with
"Template cache was not found in $templateCache". This was due to a
combination of:
1. [That test][2] (which removes the cache) being run right before the
   failing test.
2. The async `TestBed.compileComponents()` operation run in the
   `beforeEach()` block (which sets the cache) not having completed
   before the `it()` block.

This commit fixes the issue by ensuring the cache is always set, before
instantiating `CachedResourceLoader`.

This commit also moves some operations that are only needed in one test
from the `beforeEach()` block to that test's `it()` block.

[1]: 79903b1842/packages/platform-browser-dynamic/test/resource_loader/resource_loader_cache_spec.ts (L50)
[2]: 79903b1842/packages/platform-browser-dynamic/test/resource_loader/resource_loader_cache_spec.ts (L37)

Fixes #30499

PR Close #30515
2019-05-16 20:14:03 -07:00
Kristiyan Kostadinov 1714451a6d test(ivy): move integration tests into acceptance (#30461)
Moves most of the tests from `render3/integration_spec` into `acceptance`. Note that there are still a handful of tests left in render3, because we don't have a way of moving all of them to go through `TestBed` since they either have r3-specific assertions or we don't have access to the same APIs as the raw instructions.

PR Close #30461
2019-05-16 14:40:47 -07:00
crisbeto 1f6fcb6cd3 fix(ivy): unable to bind SafeValue to clip-path (#30491)
Fixes not being able to pass in a `SafeValue` to a `clip-path` binding, because `clip-path` wasn't in the list of exceptions.

PR Close #30491
2019-05-16 14:40:21 -07:00
Ben Lesh 60235b5aef test(ivy): add additional lifecycle hook acceptance tests (#30445)
Moves additional lifecycle hook tests from render3 to acceptance

PR Close #30445
2019-05-16 14:39:22 -07:00
Ben Lesh d18c58816f test(ivy): add onChanges acceptance tests (#30445)
- moves render3 tests to acceptance tests.

PR Close #30445
2019-05-16 14:39:22 -07:00
Ben Lesh 222dde129d test(ivy): add onDestroy acceptance tests (#30445)
Ports render3 onDestroy tests over to be acceptance tests. Removes old render3 tests if possible.

Note the onlyInIvy test for one area where Ivy has a different behavior than ViewEngine

PR Close #30445
2019-05-16 14:39:22 -07:00
Ben Lesh 257e9646d0 test(ivy): add afterViewInit acceptance tests (#30445)
Migrates afterViewInit and afterViewChecked render3 tests to acceptance tests

PR Close #30445
2019-05-16 14:39:22 -07:00
Ben Lesh a5e06ba629 test(ivy): onAfterContentInit acceptance tests (#30445)
- Ports onAfterContentInit tests from render3 to acceptance tests

PR Close #30445
2019-05-16 14:39:22 -07:00
Ben Lesh 9a6d298ca7 test(ivy): doCheck lifecycle acceptance tests (#30445)
- ports render3 doCheck tests to acceptance tests

PR Close #30445
2019-05-16 14:39:21 -07:00
Ben Lesh 6ec621b72d test(ivy): onInit lifecycle acceptance tests (#30445)
Ports render3 lifecycle onInit tests to acceptance tests

PR Close #30445
2019-05-16 14:39:21 -07:00
Pawel Kozlowski 07ebe9624f docs(ivy): document rules for the global state access (#30485)
PR Close #30485
2019-05-16 14:38:46 -07:00
Pete Bacon Darwin 73e3f565e0 test(ivy): ngcc - fix tests to work on Windows (#30520)
PR Close #30520
2019-05-16 13:32:02 -07:00
Pete Bacon Darwin 757d4c33df refactor(ivy): ngcc - use `.has()` to check Map membership (#25445)
Previously we were relying upon the `.get()` method to return `undefined`
but it is clearer and safer to always check with `.has()` first.

PR Close #25445
2019-05-16 12:11:05 -07:00
Pete Bacon Darwin edd775eabc feat(ivy): ngcc - implement UmdDependencyHost (#25445)
The dependency resolution that works out the order in which
to process entry-points must also understand UMD formats.

PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin c613596658 fix(ivy): ngcc - separate typings rendering from src rendering (#25445)
Previously the same `Renderer` was used to render typings (.d.ts)
files. But the new `UmdRenderer` is not able to render typings files
correctly.

This commit splits out the typings rendering from the src rendering.
To achieve this the previous renderers have been refactored from
sub-classes of the abstract `Renderer` class to  classes that implement
the `RenderingFormatter` interface, which are then passed to the
`Renderer` and `DtsRenderer` to modify its rendering behaviour.

Along the way a few utility interfaces and classes have been moved
around and renamed for clarity.

PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin f4655ea98a feat(ivy): ngcc - turn on UMD processing (#25445)
PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin f6aa60c03c feat(ivy): ngcc - implement `UmdRenderer` (#25445)
PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin 7fec1771fc feat(ivy): ngcc - implement `UmdReflectionHost` (#25445)
PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin c9b588b349 feat(ivy): ngtsc - support namespaced `forwardRef` calls (#25445)
In some cases the `forwardRef` helper has been imported via a namespace,
e.g. `core.forwardRef(...)`.

This commit adds support for unwrapping such namespaced imports when
ngtsc is statically evaluating code.

PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin 37f69eddc7 test(ivy): ngcc - remove unnecessary code (#25445)
PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin 0fa72a8bc8 refactor(ivy): ngcc - fake core and tslib should be typings files (#25445)
Previously these fake files were full TypeScript source
files (`.ts`) but this is not necessary as we only need the
typings not the implementation.

PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin 48b77459ef refactor(ivy): ngcc - abstract how module statements are found (#25445)
This will be important for UMD support.

PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin 989bfd2e97 fix(ivy): ngcc - support namespaced identifiers (#25445)
In UMD formats, imports are always namespaced. This commit makes
ngcc more tolerant of such structures.

PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin aeec66b657 test(ivy): enhance the in-memory-typescript helper (#25445)
The `getDeclaration()` function now searches down into the AST for
matching nodes, which is needed for UMD testing.

PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin e68490c5e4 test(ivy): fix ESM5 test code to use `var` rather than `const` (#25445)
PR Close #25445
2019-05-16 12:11:04 -07:00
Pete Bacon Darwin 95c5b1a7f6 refactor(ivy): use a named type for ImportManager import structures (#25445)
Previously we were using an anonymous type `{specifier: string; qualifier: string;}`
throughout the code base. This commit gives this type a name and ensures it
is only defined in one place.

PR Close #25445
2019-05-16 12:11:03 -07:00
Pete Bacon Darwin 8e201f713a test(ivy): ngcc - check the actual file that is passed to `renderImports` (#25445)
Previously we were just checking that the object was "any" object but now
we check that it is the file object that we expected.

PR Close #25445
2019-05-16 12:11:03 -07:00
Filipe Silva ac34a1429b refactor: remove toplevel property accesses (#29329)
PR Close #29329
2019-05-16 12:08:49 -07:00
Brandon 0e92332491 refactor(common): update argument length in UrlCodec.areEqual method and AngularJSUrlCodec.areEqual methods (#30331)
dgeni requires that method arguments be at least 2 characters long

PR Close #30331
2019-05-16 11:47:16 -07:00
JoostK 1b613c3ebf fix(ivy): evaluate external declaration usages as dynamic (#30247)
Previously, ngtsc would fail to evaluate expressions that access properties
from e.g. the `window` object. This resulted in hard to debug error messages
as no indication on where the problem originated was present in the output.

This commit cleans up the handling of unknown property accesses, such that
evaluating such expressions no longer fail but instead result in a `DynamicValue`.

Fixes #30226

PR Close #30247
2019-05-16 11:46:00 -07:00
Ben Lesh 3f7e823b80 test(ivy): add exhaustive inheritance tests (#30442)
- Adds inheritance tests for many combinations of directive, component and bare class inheritance
- Adds tests that are failing in ivy, but should work, marks them with `xit` and a TODO.
- Removes render3 unit tests that cover the same things.

PR Close #30442
2019-05-16 11:45:17 -07:00
JoostK e9ead2bc09 feat(ivy): more accurate type narrowing for `ngIf` directive (#30248)
A structural directive can specify a template guard for an input, such that
the type of that input's binding can be narrowed based on the guard's return
type. Previously, such template guards could only be methods, of which an
invocation would be inserted into the type-check block (TCB). For `NgIf`,
the template guard narrowed the type of its expression to be `NonNullable`
using the following declaration:

```typescript
export declare class NgIf {
  static ngTemplateGuard_ngIf<E>(dir: NgIf, expr: E): expr is NonNullable<E>
}
```

This works fine for usages such as `*ngIf="person"` but starts to introduce
false-positives when e.g. an explicit non-null check like
`*ngIf="person !== null"` is used, as the method invocation in the TCB
would not have the desired effect of narrowing `person` to become
non-nullable:

```typescript
if (NgIf.ngTemplateGuard_ngIf(directive, ctx.person !== null)) {
  // Usages of `ctx.person` within this block would
  // not have been narrowed to be non-nullable.
}
```

This commit introduces a new strategy for template guards to allow for the
binding expression itself to be used as template guard in the TCB. Now,
the TCB generated for `*ngIf="person !== null"` would look as follows:

```typescript
if (ctx.person !== null) {
  // This time `ctx.person` will successfully have
  // been narrowed to be non-nullable.
}
```

This strategy can be activated by declaring the template guard as a
property declaration with `'binding'` as literal return type.

See #30235 for an example where this led to a false positive.

PR Close #30248
2019-05-16 09:48:40 -07:00
Keen Yee Liau b6b1aec22b fix(bazel): Disable sandbox on Mac OS (#30460)
Removing the sandbox improves build time by almost 40%.

For a hello world (ng new) application:
ng build with sandbox: 22.0 seconds
ng build without sandbox: 13.3 seconds

PR Close #30460
2019-05-16 09:43:54 -07:00