Commit Graph

486 Commits

Author SHA1 Message Date
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 c92efc15fb fix(compiler): don’t type check templates with `skipTemplateCodegen` (#19909)
This change is needed to prevent users’ builds from breaking.

If a user sets `fullTemlateTypeCheck` to true, we will
continue to check the templates even when `skipTemplateCodegen` is true
as well.

Related to #19906

PR Close #19909
2017-10-24 17:06:34 -04:00
Chuck Jazdzewski a0ae120093 fix(compiler-cli): report all diagnostic error messages (#19886)
This fixes a problem introduced in 8d45fefc31
which modified how diagnostic error messages are reported for structural
metadata errors causing some of the diagnostics to be lost.

PR Close #19886
2017-10-23 22:41:10 -04:00
Tobias Bosch fc0b1d5b61 fix(compiler): correctly calculate the outDir if it repeats a parts of the `rootDir`. (#19836)
Fixes #19718

PR Close #19836
2017-10-23 18:46:04 -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
Alex Eagle 56774dfb79 fix(compiler-cli): diagnostics file paths relative to cwd, not tsconfig (#19748)
PR Close #19748
2017-10-18 11:18:17 -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 d30ce19231 fix(compiler): correctly calculate the out path on windows (#19601)
Fixes #19543
PR Close #19601
2017-10-10 10:15:06 -07:00
Chuck Jazdzewski f83989bb0d fix(compiler-cli): produce smaller source maps for templates (#19578)
Assocating each template node with a the generated TypeScript
generated overly verbose source maps. Changed to creating a
source map entry per unique source span instead of each
unique template ast node.

Fixes: #19537

PR Close #19578
2017-10-06 14:48:25 -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 696af79dc7 fix(compiler): properly work on windows
Verified manually on a windows surface tablet.

Fixes #19492
2017-10-04 14:58:08 -07:00
Tobias Bosch caa51950e8 fix(compiler): only don’t emit already emitted files in incremental compilation 2017-10-04 14:55:21 -07:00
Tobias Bosch c4129137e7 fix(compiler): set `emitSkipped` to false for incremental compilation 2017-10-03 09:57:12 -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 7c1d3e0f5a fix(compiler): make watch mode work with `declaration: false`
closes #19464
2017-09-28 14:21:05 -07:00
Tobias Bosch 2f6ae527d1 fix(compiler): make sure our out path calculation is correct 2017-09-28 14:20:20 -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 f24ea59f74 fix(compiler-cli): don't rewrite imports when annotating for closure (#19444)
Closure no longer needs to have the imports rewritten avoid rewriting
as this can cause issues when the source directory structure differs
from what is deployed.

Fixes: #19026
2017-09-28 09:31:28 -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 27c6638913 fix(compiler-cli): set source file ranges in node emitter (#19348)
Enables source mapping from the template to the generated files.
2017-09-26 09:26:18 -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 3799f43c71 fix(compiler): add parens around binary / ternary expressions
This fixes cases where binary / ternary operators are nested
(e.g. a nested ternary operator).
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
Chuck Jazdzewski 476790290e fix(compiler-cli): do not validate metadata from declaration files (#19324)
Upgrading metadata files causes spurious reports of metadata errors.

Fixes #18867
2017-09-25 12:36:08 -07:00
Olivier Combe 0f5c70d563 build: update npm dependencies (#19328)
PR Close #19328
2017-09-22 13:20:52 -07:00
Chuck Jazdzewski f96142cd7c build: remove references to `tsc-wrapped` (#19298)
With this commit `ngc` is used instead of `tsc-wrapped` for
collecting metadata and tsickle rewriting and `tsc-wrapped`
is removed from the repository.

`@angular/tsc-wrapped@5` is now deprecated and is no longer
used, updated, or maintained as part as of Angular 5.x.x.

`@angular/tsc-wrapped@4` is still maintained and required by
Angular 4.x.x and will be maintained as long as 4.x.x is in
LTS.

PR Close #19298
2017-09-21 13:55:52 -07:00
Tobias Bosch f2bad195bc fix(compiler): correctly derive `fileExists` for generated files (#19301)
PR Close #19301
2017-09-21 09:59:40 -07:00
Tobias Bosch 1a647c399b fix(compiler): also create `.ngfactory.js` files in non obvious cases (#19301)
E.g. when an exported class contains a ctor argument which is
from another compilation unit.

PR Close #19301
2017-09-21 09:59:40 -07:00
Tobias Bosch c76da27240 fix(compiler): support `noResolve` (#19301)
PR Close #19301
2017-09-21 09:59:40 -07:00
Tobias Bosch 04997c8418 fix(compiler): don’t type check property access of literal maps (#19301)
This was the behavior in Ng4, so we put the stricter
check behind the `fullTemplateTypeCheck` flag.
PR Close #19301
2017-09-21 09:59:40 -07:00
Tobias Bosch 45747ed531 fix(compiler): don’t lower property accesses of exported symbols (#19301)
E.g. this allows the following to work:
```
@Decorator({
  useValue: MyClass.someMethod
})
class MyClass {
  static someMethod() {}
}
```
PR Close #19301
2017-09-21 09:59:40 -07:00
Tobias Bosch 62602b9bd8 fix(compiler): collect non exported symbols in d.ts files (#19301)
TS treats all symbols in d.ts files as exported,
whether they have an `export` keyword or not.

PR Close #19301
2017-09-21 09:59:40 -07:00
Tobias Bosch 6665d76fbb perf(compiler): speed up watch mode (#19275)
- don’t regenerate code for .d.ts files when
  an oldProgram is passed to `createProgram`
- cache `fileExists` / `getSourceFile` / `readFile` in watch mode
- refactor tests to share common code in `test_support`
- support `—diagnostic` command line to print total time
  used per watch mode compilation.
PR Close #19275
2017-09-19 16:55:23 -07:00
Tobias Bosch edd5f5a333 perf(compiler): make the creation of `ts.Program` faster. (#19275)
We now create 2 programs with exactly the same fileNames and
exactly the same `import` / `export` declarations,
allowing TS to reuse the structure of first program
completely. When passing in an oldProgram and the files didn’t change,
TS can also reuse the old program completely.

This is possible buy adding generated files to TS
in `host.geSourceFile` via `ts.SourceFile.referencedFiles`.

This commit also:
- has a minor side effect on how we generate shared stylesheets:
  - previously every import in a stylesheet would generate a new
    `.ngstyles.ts` file.
  - now, we only generate 1 `.ngstyles.ts` file per entry in `@Component.styleUrls`.
  This was required as we need to be able to determine the program files
  without loading the resources (which can be async).
- makes all angular related methods in `CompilerHost`
  optional, allowing to just use a regular `ts.CompilerHost` as `CompilerHost`.
- simplifies the logic around `Compiler.analyzeNgModules` by introducing `NgAnalyzedFile`.

Perf impact: 1.5s improvement in compiling angular io
PR Close #19275
2017-09-19 16:55:23 -07:00
Olivier Combe b6b18c1d7f fix(tsc-wrapped): deduplicate metadata only when the module is the same (#19249)
Fixes #19219
PR Close #19249
2017-09-18 21:15:49 -07:00
Tobias Bosch 996c7c2dde feat(compiler): reuse the TypeScript typecheck for template typechecking. (#19152)
This speeds up the compilation process significantly.

Also introduces a new option `fullTemplateTypeCheck` to do more checks in templates:
- check expressions inside of templatized content (e.g. inside of `<div *ngIf>`).
- check the arguments of calls to the `transform` function of pipes
- check references to directives that were exposed as variables via `exportAs`
PR Close #19152
2017-09-14 13:37:08 -04:00
Matias Niemelä 4695c69cf1 refactor(compiler): remove all source-level traces to tsc-wrapped (#18966)
- temporarily keeps the old sources under packages/tsc-wrapped
  until the build scripts are changed to use compiler-cli everywhere.
- removes the compiler options `disableTransformerPipeline` that was introduced
  in a previous beta of Angular 5, i.e. the transformer based compiler
  is now always enabled.

PR Close #18966
2017-09-13 20:47:37 -04:00
Tobias Bosch bf94f878bc refactor(compiler): use new ngc for i18n (#19095)
This also changes ngc to support all tsc command line arguments.
PR Close #19095
2017-09-12 18:55:32 -04:00
Tobias Bosch ca5aebaa6b refactor: update angular to support TypeScript 2.4
Detailed updates:
- rxjs@5.0.x
- tsickle@0.24.x
- typescript@2.4.x
- @bazel/typescript@0.10.0
- protractor@5.1.x
- selenium-webdriver@3.0.x

BREAKING CHANGE:
- the Angular compiler now requires TypeScript 2.4.x.
2017-09-12 10:31:30 -07:00
Tobias Bosch 5ef6e6366f fix(compiler): lower variables with a closure by exporting the variable.
This e.g. leaves comments at the right place, which is important for closure.
2017-09-07 18:28:00 -04:00
Tobias Bosch fce7ae16f5 fix(compiler): treat absolute imports as package imports (#18912)
This is a corner case, and converting them is what
was expected in G3. This also fits the fact that
we already convert package paths into relative paths.


PR Close #18912
2017-08-31 13:27:56 -07:00
Chuck Jazdzewski cf7d47dda0 feat(compiler-cli): add watch mode to `ngc` (#18818)
With this change ngc now accepts a `-w` or a `--watch`
command-line option that will automatically perform a
recompile whenever any source files change on disk.

PR Close #18818
2017-08-31 09:46:24 -07:00
Chuck Jazdzewski 0e64261f26 feat(compiler-cli): lower metadata `useValue` and `data` literal fields (#18905)
With this commit the compiler will "lower" expressions into exported
variables for values the compiler does not need to know statically
in order to be able to generate a factory. For example:

```
  providers: [{provider: 'token', useValue: calculated()}]
```

produced an error as the expression `calculated()` is not supported
by the compiler because `calculated` is not a
[known function](https://angular.io/guide/metadata#annotationsdecorators)

With this commit this is rewritten, during emit of the .js file, into
something like:

```
export var ɵ0 = calculated();

  ...

  provdiers: [{provider: 'token', useValue: ɵ0}]
```

The compiler then will now generate a reference to the exported `ɵ0`
instead of failing to evaluate `calculated()`.

PR Close #18905
2017-08-31 09:46:16 -07:00
Jason Aden c7e1bda32f Revert "feat(compiler-cli): lower metadata `useValue` and `data` literal fields (#18905)"
This reverts commit c685cc2f0a.
2017-08-30 19:02:17 -07:00
Jason Aden 3a6d270bb8 Revert "feat(compiler-cli): add watch mode to `ngc` (#18818)"
This reverts commit 06d01b2287.
2017-08-30 19:02:03 -07:00
Chuck Jazdzewski 06d01b2287 feat(compiler-cli): add watch mode to `ngc` (#18818)
With this change ngc now accepts a `-w` or a `--watch`
command-line option that will automatically perform a
recompile whenever any source files change on disk.

PR Close #18818
2017-08-30 18:00:52 -07:00
Chuck Jazdzewski c685cc2f0a feat(compiler-cli): lower metadata `useValue` and `data` literal fields (#18905)
With this commit the compiler will "lower" expressions into exported
variables for values the compiler does not need to know statically
in order to be able to generate a factory. For example:

```
  providers: [{provider: 'token', useValue: calculated()}]
```

produced an error as the expression `calculated()` is not supported
by the compiler because `calculated` is not a
[known function](https://angular.io/guide/metadata#annotationsdecorators)

With this commit this is rewritten, during emit of the .js file, into
something like:

```
export var ɵ0 = calculated();

  ...

  provdiers: [{provider: 'token', useValue: ɵ0}]
```

The compiler then will now generate a reference to the exported `ɵ0`
instead of failing to evaluate `calculated()`.

PR Close #18905
2017-08-30 18:00:38 -07:00
Tobias Bosch 506d2e98a4 fix(compiler): don’t emit stubs when we didn’t generate code for a file. (#18788)
Applies to the new transformer compiler.

PR Close #18788
2017-08-28 18:46:43 -05:00
Tobias Bosch 0262e37301 fix(compiler): always emit ngfactories with reexports (#18788)
Previously, we only did this when setting the `generateCodeForLibraries: false`.

This is needed so that libraries compiled with `generateCodeForLibraries: true` can be used as dependencies of other compilation units.

PR Close #18788
2017-08-28 18:46:43 -05:00
Tobias Bosch 2fbc92fd2e fix(compiler): quote non identifiers in map keys. (#18788)
PR Close #18788
2017-08-28 18:46:43 -05:00
Tobias Bosch 43226cb93d feat(compiler): use typescript for resolving resource paths
This can also be customized via the new method `resourceNameToFileName` in the
`CompilerHost`.
2017-08-16 15:24:48 -07:00
Tobias Bosch 2572bf508f feat(compiler): make `.ngsummary.json` files portable
This also allows to customize the filePaths in `.ngsummary.json` file
via the new methods `toSummaryFileName` and `fromSummaryFileName`
on the `CompilerHost`.
2017-08-16 15:24:48 -07:00
Tobias Bosch 6a1ab61cce refactor(compiler): simplify the `CompilerHost` used for transformers
- remove unneeded methods (`getNgCanonicalFileName`, `assumeFileExists`)
- simplify moduleName <-> fileName conversion logic as we don’t need to
  account for `genDir` anymore.
- rename `createNgCompilerHost` -> `createCompilerHost`
2017-08-16 15:24:48 -07:00
Tobias Bosch 27d901a51d refactor(compiler-cli): cleanup API for transformer based ngc
This is in preparation for watch mode.
2017-08-11 13:20:45 -07:00
Victor Berchet 679608db65 refactor(compiler-cli): use the transformer based compiler by default
The source map does not currently work with the transformer pipeline.
It will be re-enabled after TypeScript 2.4 is made the min version.

To revert to the former compiler, use the `disableTransformerPipeline` in
tsconfig.json:

```
{
  "angularCompilerOptions": {
    "disableTransformerPipeline": true
  }
}
```
2017-08-10 20:30:40 -07:00
Chuck Jazdzewski 6f2038cc85 fix(compiler-cli): fix and re-enble expression lowering (#18570)
Fixes issue uncovered by #18388 and re-enables expression
lowering disabled by #18513.
2017-08-08 12:40:08 -07:00
Chuck Jazdzewski 5b7432b6ea fix(compiler-cli): remove minimist dependency of compiler-cli/index (#18532)
Indirectly removes the minimist dependency in the language service
package was added with the addition of `ngc.ts`.
2017-08-07 14:30:35 -07:00
Victor Berchet ca695e0632 fix(compiler-cli): disable buggy expression lowering (#18513) 2017-08-03 14:31:23 -07:00
Victor Berchet 9479a106bb build: enable TSLint on the packages folder 2017-07-31 15:47:57 -07:00
Chuck Jazdzewski b6c4af6495 feat(compiler-cli): automatically lower lambda expressions in metadata 2017-07-31 11:30:44 -07:00
Abhimanyu Deora ce47546188 refactor(compiler-cli): add support for browser compiler bundle (#17979)
PR Close #17979
2017-07-25 15:51:46 -05:00
Chuck Jazdzewski c1474f33be feat(compiler-cli): add parameters to ngc main needed by bazel rules (#17885) 2017-07-07 16:29:39 -07:00
Victor Berchet 9c1f6fd06f fix(compiler): emits quoted keys only iff they are quoted in the original template
fixes #14292
2017-07-07 16:17:33 -07:00
Chuck Jazdzewski 227dbbcfba fix(language-service): ignore hover of symbols not in the TypeScript program (#17969)
Fixes: #17965
2017-07-07 08:47:28 -07:00
Chuck Jazdzewski 3097083277 feat(compiler-cli): new compiler api and command-line using TypeScript transformers 2017-06-23 16:18:44 -07:00
Tobias Bosch ed73d4f3ac refactor(compiler): don’t always compile `.ngfactory.ts` files by default
This puts the behavior introduced in 573b8611bc behind the new flag
`alwaysCompileGeneratedCode` to not break users that might have relied
on this behavior.
2017-06-12 15:27:02 -07:00
Tobias Bosch 90b0713e32 refactor(compiler): don’t write summaries for jit by default
The default is false externally but true internally at Google.
2017-06-09 15:58:53 -07:00
Chuck Jazdzewski 230255f887 feat(compiler-cli): produce template diagnostics error messages (#17125)
Refactoring the compiler to use transformers moves the code generation
after type-checking which suppresses the errors TypeScript would
generate in the user code.

`TypeChecker` currently produces the same factory code that was
generated prior the switch to transfomers, getting back the same
diagnostics as before. The refactoring will allow the code to
diverge from the factory code and allow better diagnostic error
messages than was previously possible by type-checking the factories.
2017-06-01 10:13:50 -07:00
Chuck Jazdzewski 18bf77204e feat(compiler): emit typescript nodes from an output ast (#16823) 2017-05-30 10:43:13 -07:00
Tobias Bosch 573b8611bc fix(compiler): compile `.ngfactory.ts` files even if nobody references them. (#16899)
This is especially important for library authors, as they will
not reference the .ngfactory.ts files.

Fixes #16741
2017-05-25 11:00:26 -06:00
Tobias Bosch 5af143e8e4 refactor(compiler): allow sync AOT compilation (#16832).
AOT compilation can be executed synchronously now,
if the `ReosurceLoader` returns a string directly
(and no `Promise`).
2017-05-23 10:41:23 -06:00
Tobias Bosch 50abca4583 refactor(compiler): don’t rely on global reflector (#16832)
Using the global reflector made it impossible
to compile multiple programs at the same time.
2017-05-23 10:41:23 -06:00
Chuck Jazdzewski d761059e4d fix(compiler-cli): allow '==' to compare nullable types (#16731)
Fixes: #16729

* fix(compiler-cli): diagnose issues in conditional of ternary

Fixes: #16730
2017-05-16 16:36:51 -07:00
Chuck Jazdzewski b9521b568f feat(compiler): support a non-null postfix assert (#16672)
Template expressions can now use a post-fix `!` operator
that asserts the target of the operator is not null. This is
similar to the TypeScript non-null assert operator. Expressions
generated in factories will be generated with the non-null assert
operator.

Closes: #10855
2017-05-11 10:15:54 -07:00
Chuck Jazdzewski bb0902c592 refactor(compiler-cli): move the expression expression type checker (#16562)
The expression type checker moved from the language service
to the compiler-cli in preparation to using it to check
template expressions.
2017-05-09 16:16:50 -07:00
Miško Hevery 5293794316 fix: turn on nullability in the code base. 2017-04-18 12:07:33 -07:00
Chuck Jazdzewski 16e0423085 revert: feat(compiler-cli): support metadata file aliases (#15331)
This reverts commit 0ab49d4cec.

PR Close #15331
2017-03-21 12:20:14 -05:00
Jason Aden 410aa33005 build: fix paths to typings files so tsickle resolves imports correctly
Fixes #15080
2017-03-16 17:34:29 -07:00
Chuck Jazdzewski 0ab49d4cec feat(compiler-cli): support metadata file aliases 2017-03-16 17:34:29 -07:00
Jason Aden 3e51a19983 refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00