Commit graph

17 commits

Author SHA1 Message Date
Cédric Exbrayat
49e1912e1d refactor(compiler-cli): remove unused error codes (#46847)
A few codes were unused, or no longer used.

PR Close #46847
2022-08-01 09:50:12 -07:00
JoostK
93c65e7b14 feat(compiler-cli): add extended diagnostic for non-nullable optional chains (#46686)
This commit adds an extended diagnostics check that is similar to the nullish
coalescing check, but targeting optional chains. If the receiver expression
of the optional chain is non-nullable, then the extended diagnostic can report
an error or warning that can be fixed by changing the optional chain into a
regular access.

Closes #44870

PR Close #46686
2022-07-12 17:45:00 +00:00
Andrew Scott
9e836c232f feat(compiler): warn when style suffixes are used with attribute bindings (#46651)
This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes #36256

PR Close #46651
2022-07-08 18:32:58 +00:00
Jessica Janiuk
33ce3883a5 feat(compiler): Add extended diagnostic to warn when missing let on ngForOf (#46683)
In the case that a user accidentally forgot the let keyword, they dont get a very clear indicator of there being a problem.
They get an issue in the template iteration at runtime. This diagnostic will warn the user when the let keyword is missing.

PR Close #46683
2022-07-07 13:04:33 -07:00
Andrew Scott
6f11a58040 feat(compiler): Add extended diagnostic to warn when text attributes are intended to be bindings (#46161)
https://angular.io/guide/attribute-binding#attribute-class-and-style-bindings

Angular supports `attr.`, `style.`, and `class.` binding prefixes to
bind attributes, styles, and classes. If the key does not have the
binding syntax `[]` or the value does not have an interpolation `{{}}`,
the attribute will not be interpreted as a binding.

This diagnostic warns the user when the attributes listed above will not
be interpreted as bindings.

resolves #46137

PR Close #46161
2022-06-30 14:05:47 -07:00
Andrew Kushnir
131d029da1 feat(compiler-cli): detect missing control flow directive imports in standalone components (#46146)
This commit adds an extended diagnostics check that verifies that all control flow directives (such as `ngIf`, `ngFor`) have the necessary directives imported in standalone components. Currently there is no diagnostics produced for such cases, which makes it harder to detect and find problems.

PR Close #46146
2022-06-10 21:22:53 +00:00
Dylan Hunn
a2d5358c9b Revert "feat(compiler-cli): exclude abstract classes from strictInjectionParameters requirement (#44615)" (#45862)
This reverts commit 9cf14ff03d.

PR Close #45862
2022-05-03 17:03:25 -07:00
JoostK
9cf14ff03d feat(compiler-cli): exclude abstract classes from strictInjectionParameters requirement (#44615)
In AOT compilations, the `strictInjectionParameters` compiler option can
be enabled to report errors when an `@Injectable` annotated class has a
constructor with parameters that do not provide an injection token, e.g.
only a primitive type or interface.

Since Ivy it's become required that any class with Angular behavior
(e.g. the `ngOnDestroy` lifecycle hook) is decorated using an Angular
decorator, which meant that `@Injectable()` may need to have been added
to abstract base classes. Doing so would then report an error if
`strictInjectionParameters` is enabled, if the abstract class has an
incompatible constructor for DI purposes. This may be fine though, as
a subclass may call the constructor explicitly without relying on
Angular's DI mechanism.

Therefore, this commit excludes abstract classes from the
`strictInjectionParameters` check. This avoids an error from being
reported at compile time. If the constructor ends up being used by
Angular's DI system at runtime, then the factory function of the
abstract class will throw an error by means of the `ɵɵinvalidFactory`
instruction.

In addition to the runtime error, this commit also analyzes the inheritance
chain of an injectable without a constructor to verify that their inherited
constructor is valid.

Closes #37914

PR Close #44615
2022-05-03 10:39:56 -07:00
Andrew Kushnir
fde4942cdf fix(core): throw if standalone components are present in @NgModule.bootstrap (#45825)
This commit updates the logic to detect a situation when a standalone component is used in the NgModule-based bootstrap (`@NgModule.bootstrap`). Both AOT and JIT compilers are updated to handle this situation.

PR Close #45825
2022-05-02 11:43:17 -07:00
Alex Rickabaugh
8155428ba6 perf(compiler-cli): ignore the module.id anti-pattern for NgModule ids (#45024)
In early versions of Angular, it was sometimes necessary to provide a
`moduleId` to `@Component` metadata, and the common pattern for doing this
was to set `moduleId: module.id`. This relied on the bundler to fill in a
value for `module.id`.

However, due to the superficial similarity between `Component.moduleId` and
`NgModule.id`, many users ended up setting `id: module.id` in their
NgModules. This is an anti-pattern that has a few negative effects,
including preventing the NgModule from tree-shaking properly.

This commit changes the compiler to ignore `id: module.id` in NgModules, and
instead provide a warning which suggests removing the line entirely.

PR Close #45024
2022-03-22 11:11:54 -07:00
Alex Rickabaugh
0072eb48ba feat(compiler-cli): initial implementation of standalone components (#44812)
This commit implements the first phase of standalone components in the Angular
compiler. This mainly includes the scoping rules for standalone components
(`@Component({imports})`).

Significant functionality from the design is _not_ implemented by this PR,
including:

* imports of standalone components into NgModules.
* the provider aspect of standalone components

Future commits will address these issues, as we proceed with the design of
this feature.

PR Close #44812
2022-02-03 08:55:25 -08:00
Doug Parker
83e6db4081 refactor(compiler-cli): add validation to extended template diagnostics configuration (#44391)
Refs #42966.

This validates the `tsconfig.json` options for extended template diagnostics. It verifies:
* `strictTemplates` must be enabled if `extendedDiagnostics` have any explicit configuration.
* `extendedDiagnostics.defaultCategory` must be a valid `DiagnosticCategoryLabel`.
* `extendedDiagnostics.checks` keys must all be real diagnostics.
* `extendedDiagnostics.checks` values must all be valid `DiagnosticCategoryLabel`s.

These include new error codes, each of which prints out the exact property that was the issue and what the available options are to fix them.

It does disallow the config:

```json
{
  "angularCompilerOptions": {
    "strictTemplates": false,
    "extendedDiagnostics": {
      "defaultCategory": "suppress"
    }
  }
}
```

Such a configuration is technically valid and could be executed, but will be rejected by this verification logic. There isn't much reason to ever do this, since users could just drop `extendedDiagnostics` altogether and get the intended effect. This is unlikely to be a significant issue for users, so it is considered invalid for now to keep the implementation simple.

PR Close #44391
2022-01-11 17:33:16 +00:00
JoostK
7052e27677 refactor(compiler-cli): improve DX for reference emit failures (#44587)
In certain scenarios, the compiler may have crashed with an
`Unable to write a reference` error which would be particularly hard
to diagnose. One of the primary reasons for this failure is when the
`rootDir` option is configured---typically the case for libraries---
and a source file is imported using a relative import from an external
entry-point. This would normally report TS6059 for the invalid relative
import, but the crash prevents this error from being surfaced.

This commit refactors the reference emit logic to result in an explicit
`Failure` state with a reason as to why the failure occurred. This state
is then used to report a `FatalDiagnosticException`, preventing a hard
crash.

Closes #44414

PR Close #44587
2022-01-06 23:44:24 +00: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
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
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
59fe159b78 build: update API goldens to reflect new tool (#42688)
Updates the TS API guardian goldens with their equivalents
based on the new shared dev-infra tool.

PR Close #42688
2021-06-30 11:43:48 -07:00
Renamed from goldens/public-api/compiler-cli/error_code.d.ts (Browse further)