Commit Graph

219 Commits

Author SHA1 Message Date
Chuck Jazdzewski 33c0ee3441 fix(compiler): report an error for recursive module references
Modules that directly or indirectly export or imported themselves
reports an error instead of generating a stack fault.

Fixes: #19979
2017-12-20 10:54:45 -08:00
Chuck Jazdzewski 82bcd83566 feat(compiler): allow ngIf to use the ngIf expression directly as a guard
Allows a directive to use the expression passed directly to a property
as a guard instead of filtering the type through a type expression.

This more accurately matches the intent of the ngIf usage of its template
enabling better type inference.

Moved NgIf to using this type of guard instead of a function guard.

Closes: #20967
2017-12-18 12:09:21 -08:00
Trotyl 05ff6c09ca fix(compiler): make tsx file aot compatible
fixes #20555
2017-12-15 07:53:46 -08:00
Chuck Jazdzewski d91ff17adc fix(compiler): generate the correct imports for summary type-check
Summaries should be ignored when importing the types used in a
type-check block.
2017-12-15 07:53:11 -08:00
Chuck Jazdzewski 634d33f5dd fix(compiler): support referencing enums in namespaces (#20947)
Due to an overly agressive assert the compiler would generate
an internal error when referencing an enum declared in
namspace.

Fixes #18170

PR Close #20947
2017-12-12 11:55:55 -08:00
Chuck Jazdzewski 70cd124ede feat(compiler): add a pseudo $any() function to disable type checking (#20876)
`$any()` can now be used in a binding expression to disable type
checking for the rest of the expression. This similar to `as any` in
TypeScript and allows expression that work at runtime but do not
type-check.

PR Close #20876
2017-12-11 14:34:38 -08:00
Chuck Jazdzewski e7d9cb3e4c feat(compiler): narrow types of expressions used in *ngIf (#20702)
Structural directives can now specify a type guard that describes
what types can be inferred for an input expression inside the
directive's template.

NgIf was modified to declare an input guard on ngIf.

After this change, `fullTemplateTypeCheck` will infer that
usage of `ngIf` expression inside it's template is truthy.

For example, if a component has a property `person?: Person`
and a template of `<div *ngIf="person"> {{person.name}} </div>`
the compiler will no longer report that `person` might be null or
undefined.

The template compiler will generate code similar to,

```
  if (NgIf.ngIfTypeGuard(instance.person)) {
    instance.person.name
  }
```

to validate the template's use of the interpolation expression.
Calling the type guard in this fashion allows TypeScript to infer
that `person` is non-null.

Fixes: #19756?

PR Close #20702
2017-12-08 10:24:26 -08:00
Alex Eagle ef534c0cc1 build: upgrade bazel rules to latest (#20768)
Add enough BUILD files to make it possible to
`bazel build packages/core/test`

Also re-format BUILD.bazel files with Buildifier.
Add a CI lint check that they stay formatted.

PR Close #20768
2017-12-07 11:27:50 -08:00
Chuck Jazdzewski 8bb42df47e fix(compiler): correctly detect when to serialze summary metadata (#20668)
The change to improve error messages broke the summary serialization
of summaries.

PR Close #20668
2017-11-28 16:43:35 -06:00
Chuck Jazdzewski 8ecda94899 feat(compiler-cli): improve error messages produced during structural errors (#20459)
The errors produced when error were encountered while interpreting the
content of a directive was often incomprehencible. With this change
these kind of error messages should be easier to understand and diagnose.

PR Close #20459
2017-11-27 16:59:57 -06:00
Chuck Jazdzewski 4ed04392d3 fix(compiler): support event bindings in `fullTemplateTypeCheck` (#20490)
The type-check block now disables type checking event access instead
of generating a reference to an undefined variable.

PR Close #20490
2017-11-20 18:39:42 -06:00
Chuck Jazdzewski 68b53c07fd fix(compiler): emit correct type-check-blocks with TemplateRef's (#20463)
The type-check block generated with `"fullTemplateTypeCheck"` was
invalid if the it contained a template ref as would be generated
using the `else` micro-syntax of `NgIf`.

Fixes: #19485

PR Close #20463
2017-11-16 16:19:54 -06:00
Chuck Jazdzewski c33a57666b fix(compiler): recognize @NgModule with a redundant @Injectable (#20320)
The compiler now, again, recognizes `@NgModule()` decorators on
classes with a redundant `@Injectable()` decorator.

Fixes: #19544

PR Close #20320
2017-11-10 11:51:52 -08:00
Chuck Jazdzewski 3257fcdcee fix(compiler): show explanatory text in template errors (#20313)
Fixes: #20076

PR Close #20313
2017-11-09 15:46:30 -08:00
Victor Berchet 9bcd7097d0 test(compiler): do not use `a` as a content selector
As it might trigger false positive in the RegExp from `_makeScopeMatcher`

closes #20256
2017-11-08 15:52:21 -08:00
Victor Berchet c32f5fd393 fix(compiler): fix corner cases in shadow CSS
`cmp:host {}` and `cmp:host some-other-selector {}` were not handled
consistently.

Note those should not match anything but are made equivalent to respectively
`:host(cmp)` and `:host(cmp) some-other-selector` to avoid breaking legacy apps.
2017-11-08 15:20:19 -08:00
Victor Berchet 6e8e3bd248 refactor(core): misc changes and integrate review feedback on #19996
closes #20224
2017-11-06 14:13:02 -08:00
Tobias Bosch 05d96dc507 feat(core): allow to pass in aot summaries also to `TestBed.configureTestingModule`
Also adds caching for summaries.

Closes #19817.
2017-11-06 14:12:30 -08:00
Chuck Jazdzewski bf22f2df88 fix(compiler): report a reasonable error with invalid metadata (#20062)
The compiler would throw an internal exception if an import using
the `ngModule` syntax and the module as not a resolvable symbol.

Fixes: #20049
2017-11-06 10:01:27 -08:00
Olivier Combe 26f82995f6 fix(compiler): don't overwrite missingTranslation's value in JIT (#19952) 2017-11-03 11:08:39 -07:00
Hans Larsen b6abcb2500 refactor: make all rollup config ES5 compatible (#20028)
So they can be required by other Node scripts.

PR Close #20028
2017-10-30 23:09:17 -04:00
Tobias Bosch 420852e2f5 fix(compiler): reexport less symbols in `.ngfactory.ts` files (#19884)
* don't reexport symbols that the user already reexported
* never reexport symbols that are part of arguments of non simple function calls

Fixes #19883

PR Close #19884
2017-10-30 20:11:29 -04:00
Tobias Bosch 957be960d2 fix(compiler): recover from structural errors in watch mode (#19953)
This also changes the compiler so that we throw less often
on structural changes and produce a meaningful state
in the `ng.Program` in case of errors.

Related to #19951

PR Close #19953
2017-10-26 18:43:00 -04:00
Tobias Bosch 18e9d86a3b fix(compiler): translate emit diagnostics with `noEmitOnError: true`. (#19953)
This prevents errors reported against `.ngfactory.ts` files show up
as the result of running `ngc`.

Closes #19935
PR Close #19953
2017-10-26 18:42:59 -04:00
Tobias Bosch a869aeecd2 fix(compiler): don’t store invalid state when using `listLazyRoutes` (#19953)
Previously, `listLazyRoute` would store invalid information in a compiler
internal cache, which lead to incorrect paths that were used during emit.
This commit fixes this.

PR Close #19953
2017-10-26 18:42:59 -04:00
Chuck Jazdzewski 7bfeac746e fix(compiler-cli): only use error collector when needed. (#19912)
The error collector changes behavior of the metadata resolver
in ways that haven't been fully hardened. This changes limits
its use to the lazy route detection and the language service.

Issue: #19906

PR Close #19912
2017-10-24 17:06:41 -04:00
Tobias Bosch 8d45fefc31 refactor(compiler): remove old ngtools api and add listLazyRoutes to new api (#19836)
Usages of `NgTools_InternalApi_NG_2` from `@angular/compiler-cli` will now
throw an error.

Adds `listLazyRoutes` to `@angular/compiler-cli/ngtools2.ts` for getting
the lazy routes of a `ng.Program`.
PR Close #19836
2017-10-23 18:46:04 -04:00
Chuck Jazdzewski 25cbc98979 fix(compiler-cli): do not add references to files outside of `rootDir` (#19770)
References to resources (such as .css files) that are generated into
the `outDir` directory outside of `rootDir` would cause a spurious
compiler error about not being able to find a files that ends in
'.ngstyle.ts'.

Also fixed a minor issue in compiler error reporting

Fixes: #19765, #19767

PR Close #19770
2017-10-18 11:18:50 -07:00
Chuck Jazdzewski 60bdcd6f5f fix(compiler): generate correct imports for type check blocks (#19582)
Fixes: #19485

PR Close #19582
2017-10-17 10:37:55 -07:00
Tobias Bosch 653a211743 Revert "Revert "Revert "perf(compiler): skip type check and emit in bazel in some cases. (#19646)"""
This reverts commit 6b7cead0c5.
2017-10-12 16:09:49 -07:00
Chuck Jazdzewski 6b7cead0c5 Revert "Revert "perf(compiler): skip type check and emit in bazel in some cases. (#19646)""
This reverts commit 94a925a1b0.
2017-10-12 10:32:21 -07:00
Chuck Jazdzewski 94a925a1b0 Revert "perf(compiler): skip type check and emit in bazel in some cases. (#19646)"
This reverts commit a22121d65d.
2017-10-12 10:26:53 -07:00
Tobias Bosch a22121d65d perf(compiler): skip type check and emit in bazel in some cases. (#19646)
If no user files changed:
- only type check the changed generated files

Never emit non changed generated files
- we still calculate them, but don’t send them through
  TypeScript to emit them but cache the written files instead.
PR Close #19646
2017-10-11 15:54:02 -07:00
Tobias Bosch 01f711281c fix(compiler): don’t use `ng://` in AOT source maps, and never point to the original source file
This is important to not confuse users nor downstream tools that
consume our source maps. For generated content for which we don’t
have an original source file, we use the generated file now.

Fixes #19538
2017-10-04 16:20:55 -07:00
Tobias Bosch 5b5108363d refactor(compiler): remove stale metadata classes for animations
These are no longer needed as animations are a purely
runtime concept.
2017-10-04 16:20:55 -07:00
Vikram Subramanian fbc9537952 perf(compiler): fix perf issue in loading aot summaries in jit compiler
The current `flattenSummaries` function re-process the same NgModule
summary even if it has been processed before. Certain modules like
CommonModule are repeated multiple times in the module tree and it is
expanded out every time.

This was making unit tests using AOT summaries really slow. This will
also slow down JIT bootstrap applications that load AOT summaries for
component libraries.

The fix is to remember which summaries were seen before and not to
process them again.
2017-10-04 15:04:23 -07:00
Victor Berchet 0833b59aab refactor(core): add a checkIndex to the compiler view nodes
Each node now has two index: nodeIndex and checkIndex.

nodeIndex is the index in both the view definition and the view data.
checkIndex is the index in in the update function (update directives and update
renderer).

While nodeIndex and checkIndex have the same value for now, having both of them
will allow changing the structure of view definition after compilation (ie for
runtime translations).
2017-10-04 14:55:54 -07:00
Chuck Jazdzewski f3f4c3d835 fix(compiler): disallow references for select and index evaluation
Also fixes an issue where enum values of 0 or '``' where not treated
correctly.

Fixes: #18170
2017-10-04 14:54:39 -07:00
Tobias Bosch 745b59f49c perf(compiler): only emit changed files for incremental compilation
For now, we always create all generated files, but diff them
before we pass them to TypeScript.

For the user files, we compare the programs and only emit changed
TypeScript files.

This also adds more diagnostic messages if the `—diagnostics` flag
is passed to the command line.
2017-10-02 08:24:50 -07:00
Tobias Bosch b0868915ae perf(compiler): don’t emit summaries for jit by default
This re-adds the flag `enableSummariesForJit` to the compiler options
that already existed in Angular 4.
2017-10-02 08:24:50 -07:00
Tobias Bosch ec2be5dccb fix(compiler): allow to use flat modules and summaries
The combination of flat modules, flat module redirects and summaries
lead to errors before.
2017-09-28 14:20:20 -07:00
Chuck Jazdzewski ff5b050a92 fix(compiler): correctly map error message locations (#19424) 2017-09-28 10:53:04 -07:00
Chuck Jazdzewski b3db3f80ba fix(compiler): do not consider a reference with members as a reference (#19454)
Fixes: #18170
2017-09-28 10:52:52 -07:00
Chuck Jazdzewski c1b029a413 fix(language-service): do not report errors for `OpaqueToken` (#19427)
`OpaqueToken` was removed from angular but the language-service
should not report errors when it is used for older versions of
angular.
2017-09-28 09:30:34 -07:00
Alex Eagle 82e49230ff build: Give names to the AMD modules nested in Angular UMD distro (#19425) 2017-09-28 09:29:22 -07:00
Chuck Jazdzewski dfb8d21ef4 feat(compiler): enabled strict checking of parameters to an `@Injectable` (#19412)
Added the compiler options `strictInjectionParameters` that defaults
to `false`. If enabled the compiler will report errors for parameters
of an `@Injectable` that cannot be determined instead of generating a
warning.

This is planned to be switched to default to `true` for Angular 6.0.
2017-09-26 13:40:47 -07:00
Chuck Jazdzewski a75040d0a1 refactor(compiler): bump metadata version to 4 (#19338)
Also adds auto upgrade from lower version based
on the .d.ts file (e.g. from version 3 to 4).

This is needed as we are now also capturing type aliases
in metadata files (and we rely on this),
see 6e3498ca8e.
2017-09-26 13:31:59 -07:00
Chuck Jazdzewski f57b7df4d7 fix(compiler): remove deprecated `Compiler.ngGetContentSelectors()` (#19347)
BREAKING CHANGE:

The method `ngGetConentSelectors()`, deprecated in Angular 4.0, has been
removed.

Use `ComponentFactory.ngContentSelectors` instead.
2017-09-26 10:18:10 -07:00
Tobias Bosch e31a76ce24 fix(compiler): allow to use lowering with `export *`.
Previously, we generated incorrect code when a file
had lowerings and also exported another file via `export *`
that also had lowerings in it.
2017-09-25 13:36:00 -07:00
Tobias Bosch a8a9660112 fix(compiler): various squashed fixes for the new ngc
introduce the option `allowEmptyCodegenFiles` to generate all generated files,
even if they are empty.
- also provides the original source files from which the file was generated
  in the write file callback
- needed e.g. for G3 when copying over pinto mod names from the original component
  to all generated files

use `importAs` from flat modules when writing summaries
- i.e. prevents incorrect entries like @angular/common/common in the .ngsummary.json files.

change interaction between ng and ts to prevent race conditions
- before Angular would rely on TS to first read the file for which we generate files,
  and then the generated files. However, this can break easily when we reuse an old program.

don’t generate files for sources that are outside of `rootDir`
(see #19337)
2017-09-25 13:36:00 -07:00