Commit graph

2274 commits

Author SHA1 Message Date
Daniel Trevino
95cfd0b0e1 test(compiler-cli): add tests for NullishCoalescingNotNullableCheck (#43232)
Add tests to make sure the nullish coalescing check is generating the
correct diagnostics.

Refs #42966

PR Close #43232
2021-08-26 16:36:32 -07:00
Daniel Trevino
0802b59a7b refactor(compiler-cli): add NullishCoalescingNotNullableCheck (#43232)
Add a template check that returns diagnostics if the left side of a
nullish coalescing operation is not nullable.

Refs #42966

PR Close #43232
2021-08-26 16:36:32 -07:00
Daniel Trevino
fc85fa85ba refactor(compiler-cli): use TemplateCheckWithVisitor in InvalidBananaInBoxCheck (#43232)
Modify the existing template check to use the new abstract class. This
makes template checks easier to read and understand.

Refs #42966

PR Close #43232
2021-08-26 16:36:32 -07:00
Daniel Trevino
46e68df2cd refactor(compiler-cli): add abstract TemplateCheckWithVisitor class (#43232)
Add an abstract class that has a default implementation of the run
function and visits all nodes. Authors of template checks can extend
this class and override the `visitNode` method to return diagnostics.

Refs #42966

PR Close #43232
2021-08-26 16:36:32 -07:00
Daniel Trevino
dee04bd96e refactor(compiler-cli): move component out of TemplateContext (#43232)
Move `component` out of the `TemplateContext` so the context can be
reused for multiple components.

Refs #42966

PR Close #43232
2021-08-26 16:36:31 -07:00
Daniel Trevino
50249827f1 refactor(compiler-cli): change checks folder structure (#43232)
Change template checks into `extended/checks` instead of
`extended/src/template_checks`.

Refs #42966

PR Close #43232
2021-08-26 16:36:31 -07:00
Daniel Trevino
98a648d33d refactor(compiler-cli): remove whitespace (#43232)
Remove extra whitespace introduced in a previous PR.

PR Close #43232
2021-08-26 16:36:31 -07:00
JoostK
030ff0d7a1 test(ngcc): use @angular npm packages in integration test (#43234)
In anticipation of the removal of the View Engine npm package output,
the integration tests of ngcc are switched to use @angular packages for
from npm. The version 12 packages are guaranteed to always be View
Engine format which makes them suitable to be processed in the ngcc
integration tests.

PR Close #43234
2021-08-26 09:45:43 -07:00
nickreid
4341a5f4cb fix(compiler-cli): Emit type annotations for synthesized decorator fields (#43021)
Previously, the decorator transformer was annotating the synthesized properties with TS type annotations. However, because it ran after the JSDoc transformer, the TS types were just dropped from the emitted JS. Attempting to move the decorator transformer before the JSDoc transformer causes tsickle crashes because synthetic AST fragments are not attached to a SourceFile node.

PR Close #43021
2021-08-25 15:05:28 -07:00
Daniel Trevino
b34a9a1eb2 refactor(compiler-cli): integrate extended diagnostics with the language service (#43134)
Add the call to get the extended template diagnostics in
the compiler's `getDiagnosticsForComponent`. This makes showing
extended diagnostics in non-ts files posible.

Refs #42966

PR Close #43134
2021-08-25 10:43:01 -07:00
Daniel Trevino
de215a4b21 refactor(compiler-cli): rename ExtendedTemplateChecker get diagnostics fucntion (#43134)
Rename `getExtendedTemplateDiagnosticsForComponent` to
`getDiagnosticsForComponent` since it's implied they are extended
diagnostics.

Refs #42966

PR Close #43134
2021-08-25 10:43:01 -07:00
Daniel Trevino
68bb13ea0f refactor(compiler-cli): move getDiagnosticsForComponent to compiler (#43134)
Change the language service to call `getDiagnosticsForComponent` from
the compiler instead of the `TemplateTypeChecker`.

Refs #42966

PR Close #43134
2021-08-25 10:43:00 -07:00
Daniel Trevino
6af6de7328 refactor(compiler-cli): move ExtendedTemplateChecker to LazyCompilationState (#43134)
Create the `ExtendedTemplateChecker` during `makeCompilation`, that way
it's avaiblable in the whole compiler.

Refs #42966

PR Close #43134
2021-08-25 10:43:00 -07:00
Daniel Trevino
2d8fc4a7ce refactor(compiler-cli): use TemplateDiagnostic in extended package (#43134)
Return `TemplateDiagnostic` instead of `ts.Diagnostic` when getting the
extended template diagnostics. This makes the integration with the
language service easier. This also fixes the error code and now uses the
`ngErrorCode` for extended template diagnostics.

Refs #42966

PR Close #43134
2021-08-25 10:43:00 -07:00
Daniel Trevino
4d42a3ab10 test(compiler-cli): add extended template diagnostics end-to-end tests (#43107)
This commit adds extended template diagnostics end-to-end tests, to make
sure the diagnostics are generated correctly. Template checks are
already tested with unit tests.

Refs #42966

PR Close #43107
2021-08-19 11:55:27 -07:00
Daniel Trevino
ff858ac9d8 refactor(compiler-cli): add extendedTemplateCheck phase to compiler (#43107)
This commit integrates extended template checks with the compiler, by
adding another phase of diagnostics generation. This integration is
under the `_extendedTemplateDiagnostics` flag.

Refs #42966

PR Close #43107
2021-08-19 11:55:27 -07:00
Daniel Trevino
cb654d1c53 refactor(compiler-cli): export ExtendedTemplateCheckerImpl and template checks (#43107)
This commit exports the implementation of `ExtendedTemplateChecker` to
generate extended template diagnostics and all the template checks.

Refs #42966

PR Close #43107
2021-08-19 11:55:27 -07:00
Daniel Trevino
3932480ddb refactor(compiler-cli): add ExtendedTemplateChecker (#43107)
Change the current way to run template checks to the
`ExtendedTemplateChecker` instead of just the
`getExtendedTemplateDiagnosticsForComponent` function. Refactored the
tests that used the previous function to use the new class.

Refs #42966

PR Close #43107
2021-08-19 11:55:27 -07:00
Paul Gschwendtner
bed121c34f feat(compiler-cli): inline resources when generating class metadata calls (#43178)
Previously with View Engine output, the `enableResourceInlining` option
could be set to inline external templates and styles (also for the
resulting `.metadata.json` files). We want to do the same for the Ivy
compilation pipeline (regardless of the compilation mode). The full
compilation definitions, and partial declarations currently already
inline resources in a way that no external requests need to be made.

Although there is one exception currently. These are the calls for
setting class metadata (for testbed overrides). This commit updates
the set class metadata calls (for both partial and full compilation)
to always inline resources. This means that libraries do not need
to start shipping external styles/templates just for the
`setClassMetadata` calls.

Note: Only doing this for partial compilation has been considered, but
it seems like it would be simpler implementation-wise to do this for
full compilation as well. Given the external resources are already
inlined (through their `ecmp` definitions), it seems acceptable (or
even more aligned) to do the same for the set class metadata calls.

PR Close #43178
2021-08-19 11:27:15 -07:00
dario-piotrowicz
cf338493bf refactor(compiler-cli): remove unused closureCompilerEnabled from NgtscProgram (#43148)
remove the NgtscProgram's private field closureCompilerEnabled as that
is not being used in the class itself

PR Close #43148
2021-08-16 17:19:53 -07:00
Pete Bacon Darwin
9e18b65e9a test(compiler-cli): clarify source-map expectations in compliance tests (#43129)
The compliance tests can check source-map segments against expectations
encoded into the expectation files. Previously, the encoding of the expected
segment was only delimited by whitespace, but this made it difficult to identify
segments that started or ended with whitespace.

Now these segment expectations are wrapped in double-quotes which makes
it easier to read and understand the expectation files.

PR Close #43129
2021-08-16 13:07:23 -07:00
Pete Bacon Darwin
c5250aebae refactor(ngcc): remove unused import (#43129)
This import is not used in the file, so can be removed.

PR Close #43129
2021-08-16 13:07:22 -07:00
dario-piotrowicz
971f8572d2 refactor(compiler-cli): remove extra 'diagnostic' from readResource comment (#43147)
remove the extra 'diagnostic' present in the comment for the
ResourceHost's readResource method

PR Close #43147
2021-08-16 09:23:39 -07:00
Andrew Scott
c7d305b072 refactor(compiler): Remove compileUndecoratedClasses config file (#43043)
This config file was added to support g3 patches. Now that the patch is removed internally,
we can remove the file completely

PR Close #43043
2021-08-12 15:35:07 -07:00
Daniel Trevino
e25d35f4cb refactor(compiler-cli): add test for BananaInBoxCheck (#42984)
Create the test package for extended_template_diagnostics and add a unit
test for the `BananaInBoxCheck`.

Refs #42966

PR Close #42984
2021-08-10 15:55:49 -07:00
Daniel Trevino
d6411c2729 refactor(compiler-cli): add BananaInBoxCheck to the template checks (#42984)
Add the implementation of a Template Check that ensures the correct
use of two-way binding syntax. Generates a warning when
'([foo])="bar"' is found instead of '[(foo)]="bar"'.

Refs #42966

PR Close #42984
2021-08-10 15:55:49 -07:00
Daniel Trevino
29a5a90111 refactor(compiler-cli): move getSourceCodeForDiagnostic to utils (#42984)
Export `getSourceCodeForDiagnostic` from `ngtsc/testing` to make it
available for other packages. This will help confirm that the source
code is correct in other tests.

Refs #42966

PR Close #42984
2021-08-10 15:55:49 -07:00
Daniel Trevino
29e2bc7d91 refactor(compiler-cli): move typecheck test utils into its own package (#42984)
This commit moves the test utils used in the typechecking tests into its
own package. This makes them available to be used in the tests of a
different package.

Refs #42966

PR Close #42984
2021-08-10 15:55:49 -07:00
Daniel Trevino
be8a8e17a8 refactor(compiler-cli): introduce getExtendedTemplateDiagnosticsForComponent function (#42984)
Add function to get extended template diagnostics generated by all the template checks.

Refs #42966

PR Close #42984
2021-08-10 15:55:49 -07:00
Daniel Trevino
c055cfe281 refactor(compiler-cli): make makeTemplateDiagnostic wrapper error (#42984)
specific

This commit makes the wrapper function `makeTemplateDiagnostic` take an
ErrorCode as a type for the `ts.Diagnostic`s to be generated.

Refs #42966

PR Close #42984
2021-08-10 15:55:49 -07:00
Daniel Trevino
3a092d6cea refactor(compiler-cli): introduce extended package to typecheck with it's API (#42984)
This commit introduces //packages/compiler-cli/src/ngtsc/typecheck/extended
as a container for a new phase of diagnostics generation. The API provides an
interface for new template checks to implement and generate template diagnostics.

Refs #42966

PR Close #42984
2021-08-10 15:55:49 -07:00
atscott
f99ec27596 Revert "refactor(ngcc): remove unused import (#42062)" (#43033)
This reverts commit 42265cca1c.

PR Close #43033
2021-08-03 15:38:55 -07:00
atscott
064e705eef Revert "test(compiler-cli): clarify source-map expectations in compliance tests (#42062)" (#43033)
This reverts commit 29f9888a98.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott
dd82bbfa27 Revert "fix(compiler): include leading whitespace in source-spans of i18n messages (#42062)" (#43033)
This reverts commit f08516db09.

PR Close #43033
2021-08-03 15:38:54 -07:00
ivanwonder
f0c5ba08f6 fix(language-service): global autocomplete doesn't work when the user tries to modify the symbol (#42923)
When the user tries to trigger suggestions from an interruption,
the LS should provide the global completions. For example,
`[input]="t¦"`, the `t` can be the `true` or the symbol from
the component context.

PR Close #42923
2021-08-02 17:08:30 -07:00
Pete Bacon Darwin
f08516db09 fix(compiler): include leading whitespace in source-spans of i18n messages (#42062)
Previously, the way templates were tokenized meant that we lost information
about the location of interpolations if the template contained encoded HTML
entities. This meant that the mapping back to the source interpolated strings
could be offset incorrectly.

Also, the source-span assigned to an i18n message did not include leading
whitespace. This confused the output source-mappings so that the first text
nodes of the message stopped at the first non-whitespace character.

This commit makes use of the previous refactorings, where more fine grain
information was provided in text tokens, to enable the parser to identify
the location of the interpolations in the original source more accurately.

Fixes #41034

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin
29f9888a98 test(compiler-cli): clarify source-map expectations in compliance tests (#42062)
The compliance tests can check source-map segments against expectations
encoded into the expectation files. Previously, the encoding of the expected
segment was only delimited by whitespace, but this made it difficult to identify
segments that started or ended with whitespace.

Now these segment expectations are wrapped in double-quotes which makes
it easier to read and understand the expectation files.

PR Close #42062
2021-08-02 09:53:12 -07:00
Pete Bacon Darwin
42265cca1c refactor(ngcc): remove unused import (#42062)
This import is not used in the file, so can be removed.

PR Close #42062
2021-08-02 09:53:12 -07:00
ivanwonder
7c35ca0e00 feat(language-service): support autocomplete string literal union types in templates (#42729)
The native TS language service has the ability to provide autocompletions for
string literal union types. This pr is for Angular to do the same in templates.

Fixes https://github.com/angular/vscode-ng-language-service/issues/1096

PR Close #42729
2021-07-28 10:52:34 -07:00
Daniel Trevino
057e577403 refactor(compiler-cli): add makeTemplateDiagnostic wrapper (#42937)
Add a `makeTemplateDiagnostic` wrapper in the `TemplateTypeChecker`. This requiers less parameters to create template diagnostics, since the `TemplateTypeChecker` can get the templateId and mapping from it's scope with the `ts.ClassDeclartion`. The `TemplateTypeChecker` is often used to determine if a diagnostic should be produced, so it makes sense to have a function in it that helps create them.

Refs #42966

PR Close #42937
2021-07-26 18:00:44 -07:00
JoostK
ed9cfb674f fix(compiler-cli): use correct module resolution context for absolute imports in .d.ts files (#42879)
The compiler keeps track of how a declaration has been referenced
using absolute module imports and from which path the absolute module
should be resolved from. There was a bug in how the .d.ts metadata
extraction would incorrectly use the .d.ts file itself as resolution
context for symbols that had been imported using a relative module
specifier. This could result in module resolution failures.

For example, when extracting NgModule metadata from
`/node_modules/lib/index.d.ts` that looks like

```
import {LibDirective} from './dir';

@NgModule({
  declarations: [LibDirective],
  exports: [LibDirective],
})
export class LibModule {}
```

and `/app.module.ts` that contains

```
import {LibModule} from 'lib';

@NgModule({
  imports: [LibModule],
})
export class AppModule {}
```

then `AppModule` would have recorded a reference to `LibModule` using
the `'lib'` module specifier. When extracting the NgModule metadata from
the `/node_modules/lib/index.d.ts` file the relative import into `./dir`
should also be assumed to be importable from `'lib'` (according to APF
where symbols need to be exported from a single entry-point)
so the reference to `LibDirective` should have `'lib'` as absolute
module specifier, but it would incorrectly have
`/node_modules/lib/index.d.ts` as resolution context path. The latter is
incorrect as `'lib'` needs to be resolved from `/app.module.ts` and not
from within the library itself.

Fixes #42810

PR Close #42879
2021-07-26 13:17:44 -07:00
JoostK
5fb23eccea perf(compiler-cli): skip analysis in incremental builds for files without Angular behavior (#42562)
In an incremental rebuild, the compiler attempts to reuse as much
analysis data from a prior compilation as possible to avoid doing the
analysis work again. For source files without Angular behavior however,
no analysis data would be recorded such that the source file had to be
reanalyzed each rebuild, even if it has not changed.

This commit avoids the analysis of such source files by registering
these files as not containing any Angular behavior; allowing subsequent
rebuilds to avoid the analysis work.

PR Close #42562
2021-07-21 22:40:38 +00:00
JoostK
70c3461be3 fix(compiler-cli): use correct module import for types behind a forwardRef (#42887)
The static interpreter assumed that a foreign function expression would
have to be imported from the absolute module specifier that was used for
the foreign function itself. This assumption does not hold for the
`forwardRef` foreign function resolver, as that extracts the resolved
expression from the function's argument, which is not behind the
absolute module import of the `forwardRef` function.

The prior behavior has worked for the typical usage of `forwardRef`,
when it is contained within the same source file as where the static
evaluation started. In that case, the resulting reference would
incorrectly have an absolute module guess of `@angular/core`, but the
local identifier emit strategy was capable of emitting the reference
without generating an import using the absolute module guess.

In the scenario where the static interpreter would first have to follow
a reference to a different source that contained the `forwardRef` would
the compilation fail. In that case, there is no local identifier
available such that the absolute module emitter would try to locate the
imported symbol from `@angular/core`. which fails as the symbol is not
exported from there.

This commit fixes the issue by checking whether a foreign expression
occurs in the same source file as the call expression. If it does, then
the absolute module specifier that was used to resolve the call
expression is ignored.

Fixes #42865

PR Close #42887
2021-07-20 11:56:05 -07:00
JoostK
07d7e6034f perf(compiler-cli): optimize cycle detection using a persistent cache (#41271)
For the compilation of a component, the compiler verifies that the
imports it needs to generate to reference the used directives and pipes
would not create an import cycle in the program. This requires visiting
the transitive import graphs of all directive/pipe usage in search of
the component file. The observation can be made that all directive/pipe
usages can leverage the exploration work in search of the component
file, thereby allowing sub-graphs of the import graph to be only visited
once instead of repeatedly per usage. Additionally, the transitive
imports of a file are no longer collected into a set to reduce memory
pressure.

PR Close #41271
2021-07-15 13:13:48 -07:00
JoostK
51156f3f07 fix(core): allow proper type inference when ngFor is used with a trackBy function (#42692)
In #41995 the type of `TrackByFunction` was changed such that the
declaration of a `trackBy` function did not cause the item type to be
widened to the `trackBy`'s item type, which may be a supertype of the
iterated type. This has introduced situations where the template type
checker is now reporting errors for cases where a `trackBy` function is
no longer assignable to `TrackByFunction`.

This commit fixes the error by also including the item type `T` in
addition to the constrained type parameter `U`, allowing TypeScript to
infer an appropriate `T`.

Fixes #42609

PR Close #42692
2021-07-13 14:08:05 -07:00
Daniel Trevino
81dce5c664 fix(compiler-cli): check split two way binding (#42601)
Check for split two way binding when output is not declared to make error message clearer.

PR Close #42601
2021-07-13 08:47:11 -07:00
Paul Gschwendtner
b5ab7aff43 refactor: add override keyword to members implementing abstract declarations (#42512)
In combination with the TS `noImplicitOverride` compatibility changes,
we also want to follow the best-practice of adding `override` to
members which are implemented as part of abstract classes. This
commit fixes all instances which will be flagged as part of the
custom `no-implicit-override-abstract` TSLint rule.

PR Close #42512
2021-07-12 13:11:17 -07:00
Paul Gschwendtner
ccbb913f4b refactor(compiler-cli): ensure compatibility with noImplicitOverride (#42512)
Adds the `override` keyword to the `compiler-cli` sources to ensure
compatibility with `noImplicitOverride`.

PR Close #42512
2021-07-12 13:11:14 -07:00
Kristiyan Kostadinov
404c8d0d88 fix(compiler): incorrect context object being referenced from listener instructions inside embedded views (#42755)
Currently unless a listener inside of an embedded view tries to reference something from the parent view, or if the reference is a local ref, we don't generate the view restoration instructions and we allow for the value to be picked up from the context object in the function parameters. The problem is that the listener is only run during creation mode and the context object may have been swapped out afterwards.

These changes fix the issue by always generating the view restoration instructions for listeners inside templates.

Fixes #42698.

PR Close #42755
2021-07-12 11:58:18 -07:00
JoostK
4c482bf3f1 fix(compiler-cli): properly emit literal types when recreating type parameters in a different file (#42761)
In #42492 the template type checker became capable of replicating a
wider range of generic type parameters for use in template type-check
files. Any literal types within a type parameter would however emit
invalid code, as TypeScript was emitting the literals using the text as
extracted from the template type-check file instead of the original
source file where the type node was taken from.

This commit works around the issue by cloning any literal types and
marking them as synthetic, signalling to TypeScript that the literal
text has to be extracted from the node itself instead from the source
file.

This commit also excludes `import()` type nodes from being supported,
as their module specifier may potentially need to be rewritten.

Fixes #42667

PR Close #42761
2021-07-12 11:48:34 -07:00