Commit graph

2615 commits

Author SHA1 Message Date
Andrew Kushnir
b98ecbc0ce build: update minimum supported Node version from 16.13.0 -> 16.14.0 (#49771)
This commit updates the minimum supported Node version across packages from 16.13.0 -> 16.14.0 to ensure compatibility with dependencies.

PR Close #49771
2023-04-11 07:56:31 -07:00
JoostK
6ca1a53a19 refactor(compiler-cli): workaround for CI failure in Windows (#49136)
It seems that changes in prior commits led to a new error in the Windows CI job,
likely due to its sandboxing setup in Bazel. This commit adds an explicit type
annotation that should avoid the error.

PR Close #49136
2023-04-03 19:20:01 -07:00
JoostK
ff6608c5fe refactor(compiler-cli): remove a flag that is always true in ngtsc (#49136)
This flag was set to `true` by ngcc, but now that ngcc is gone this flag can be removed.

PR Close #49136
2023-04-03 19:20:01 -07:00
JoostK
2d6e6a1510 refactor(compiler-cli): update comments to account for ngcc removal (#49136)
This commit updates comments to account for the removal of ngcc.

PR Close #49136
2023-04-03 19:20:01 -07:00
JoostK
e5a30d92d2 refactor(compiler-cli): update compilation error message to not mention ngcc (#49136)
No longer refer to an ngcc incompatibility now that ngcc has been removed.

PR Close #49136
2023-04-03 19:20:00 -07:00
JoostK
3f47535fbf refactor(compiler-cli): update TraitCompiler to account for ngcc deletion (#49136)
There used to be a subclass of `TraitCompiler` in ngcc, but now that ngcc has been removed
we can update `TraitCompiler` to no longer expose certain fields and methods.

PR Close #49136
2023-04-03 19:20:00 -07:00
JoostK
cfa9f31fff refactor(compiler-cli): avoid clang-format inconsistency (#49136)
There's an issue where formatting with `clang-format` doesn't agree with itself on how
the docblock for a field named `import` should be indented; if it is indented then it
removes the indentation, but then linting the source file reports an error where it
wants to revert the indentation change. By using computed property syntax this bug
is avoided.

PR Close #49136
2023-04-03 19:20:00 -07:00
JoostK
c20deb7e8d refactor(compiler-cli): only use a single type expression (#49136)
The concept of "internal" and "adjacent" type expression used to be necessary to support
ngcc, as it had to process downleveled class declarations using an IIFE, where the class
name within the IIFE could be different from the outer class name. With the removal of
ngcc we no longer need to make this distinction, so this commit removes these concepts
entirely.

PR Close #49136
2023-04-03 19:20:00 -07:00
JoostK
9540f6d118 refactor(compiler-cli): remove unused dts declaration logic (#49136)
This logic used to be in place to support ngcc, but with the removal of ngcc
this is no longer relevant.

PR Close #49136
2023-04-03 19:20:00 -07:00
JoostK
d9060d9cfb refactor(compiler-cli): remove ngcc-only builtin functions (#49136)
ngcc's reflection host would recognize tslib helpers and some JS builtin methods to allow
the static interpreter to evaluate compiled and downleveled JS code, but now that ngcc
has been removed this functionality is no longer being used.

PR Close #49136
2023-04-03 19:20:00 -07:00
JoostK
bbe4590b9d refactor(compiler-cli): remove support for ngcc-only declaration formats (#49136)
This commit simplifies various parts of ngtsc to no longer support synthetic decorators,
downleveled enum members and inline declarations. These concepts were present to support
ngcc, but can be dropped now that ngcc has been removed.

PR Close #49136
2023-04-03 19:20:00 -07:00
Matthieu Riegler
03d1d00ad9 feat(compiler-cli): Add an extended diagnostic for nSkipHydration (#49512)
This diagnostic ensures that the special attribute `ngSkipHydration` is not a binding and has no other value than `"true"` or an empty value.

Fixes #49501

PR Close #49512
2023-03-23 13:54:03 -07:00
tomalaforge
d47fef72cb fix(common): strict type checking for ngtemplateoutlet (#48374)
When we create a context to inject inside our ngTemplateOutlet, the context was declare as Object, therefore, there are no compilation error.

Now if we add a context, we get error at compile type.

BREAKING CHANGE:  If the 'ngTemplateOutletContext' is different from the context, it will result in a compile-time error.

Before the change, the following template was compiling:

```typescript
interface MyContext {
  $implicit: string;
}

@Component({
  standalone: true,
  imports: [NgTemplateOutlet],
  selector: 'person',
  template: `
    <ng-container
      *ngTemplateOutlet="
        myTemplateRef;
        context: { $implicit: 'test', xxx: 'xxx' }
      "></ng-container>
  `,
})
export class PersonComponent {
  myTemplateRef!: TemplateRef<MyContext>;
}
```
However, it does not compile now because the 'xxx' property does not exist in 'MyContext', resulting in the error: 'Type '{ $implicit: string; xxx: string; }' is not assignable to type 'MyContext'.'

The solution is either:
- add the 'xxx' property to 'MyContext' with the correct type or
- add '$any(...)' inside the template to make the error disappear. However, adding '$any(...)' does not correct the error but only preserves the previous behavior of the code.

fix #43510

PR Close #48374
2023-03-23 11:35:07 -07:00
Kristiyan Kostadinov
585e34bf6c feat(core): remove entryComponents (#49484)
`entryComponents` have been deprecated since version 9, because with Ivy they weren't necessary. These changes remove any remaining references.

BREAKING CHANGE:
* `entryComponents` has been deleted from the `@NgModule` and `@Component` public APIs. Any usages can be removed since they weren't doing anyting.
* `ANALYZE_FOR_ENTRY_COMPONENTS` injection token has been deleted. Any references can be removed.

PR Close #49484
2023-03-23 10:38:03 -07:00
Alan Agius
0f2937ef83 refactor: update code to be ES2022 compliant (#49559)
This commit updates parts of the FW to be ES2022 complaint.

These changes are needed to fix the following problems problems with using properties before they are initialized.

Example
```ts
class Foo {
   bar = this.buz;
   constructor(private buz: unknown){}
}
```

PR Close #49559
2023-03-23 08:18:45 -07:00
Andrew Scott
4d455e06c7 Revert "refactor: update code to be ES2022 compliant (#49332)" (#49554)
This reverts commit 349ff01c4b.

PR Close #49554
2023-03-22 14:34:25 -07:00
Alan Agius
349ff01c4b refactor: update code to be ES2022 compliant (#49332)
This commit updates parts of the FW to be ES2022 complaint.

These changes are needed to fix the following problems problems with using properties before they are initialized.

Example
```ts
class Foo {
   bar = this.buz;
   constructor(private buz: unknown){}
}
```

PR Close #49332
2023-03-22 14:00:19 -07:00
Kristiyan Kostadinov
8f539c11f4 feat(compiler): add support for compile-time required inputs (#49468)
Adds support for marking a directive input as required. During template type checking, the compiler will verify that all required inputs have been specified and will raise a diagnostic if one or more are missing. Some specifics:
* Inputs are marked as required by passing an object literal with a `required: true` property to the `Input` decorator or into the `inputs` array.
* Required inputs imply that the directive can't work without them. This is why there's a new check that enforces that all required inputs of a host directive are exposed on the host.
* Required input diagnostics are reported through the `OutOfBandDiagnosticRecorder`, rather than generating a new structure in the TCB, because it allows us to provide a better error message.
* Currently required inputs are only supported during AOT compilation, because knowing which bindings are present during JIT can be tricky and may lead to increased bundle sizes.

Fixes #37706.

PR Close #49468
2023-03-20 13:10:30 +01:00
Andrew Scott
8d99ad0a39 Revert "feat(compiler): add support for compile-time required inputs (#49453)" (#49467)
This reverts commit 13dd614cd1.

This breaks a g3 Typescript compilation tests where diagnostics are
expected for a missing input in the component.

PR Close #49467
2023-03-17 18:29:14 +01:00
Kristiyan Kostadinov
13dd614cd1 feat(compiler): add support for compile-time required inputs (#49453)
Adds support for marking a directive input as required. During template type checking, the compiler will verify that all required inputs have been specified and will raise a diagnostic if one or more are missing. Some specifics:
* Inputs are marked as required by passing an object literal with a `required: true` property to the `Input` decorator or into the `inputs` array.
* Required inputs imply that the directive can't work without them. This is why there's a new check that enforces that all required inputs of a host directive are exposed on the host.
* Required input diagnostics are reported through the `OutOfBandDiagnosticRecorder`, rather than generating a new structure in the TCB, because it allows us to provide a better error message.
* Currently required inputs are only supported during AOT compilation, because knowing which bindings are present during JIT can be tricky and may lead to increased bundle sizes.

Fixes #37706.

PR Close #49453
2023-03-17 11:49:17 +01:00
Alex Rickabaugh
560b226a43 Revert "feat(compiler): add support for compile-time required inputs (#49304)" (#49449)
This reverts commit 1a6ca68154.

This breaks tests in google3 which might be depending on private APIs. We
need to update these tests before we can land this PR.

PR Close #49449
2023-03-16 10:38:04 -07:00
Alan Agius
cf98777153 test: update tests to remove deprecated withServerTransition (#49422)
This commit removes the usages of `withServerTransition` form tests.

PR Close #49422
2023-03-15 17:08:18 -07:00
Kristiyan Kostadinov
1a6ca68154 feat(compiler): add support for compile-time required inputs (#49304)
Adds support for marking a directive input as required. During template type checking, the compiler will verify that all required inputs have been specified and will raise a diagnostic if one or more are missing. Some specifics:
* Inputs are marked as required by passing an object literal with a `required: true` property to the `Input` decorator or into the `inputs` array.
* Required inputs imply that the directive can't work without them. This is why there's a new check that enforces that all required inputs of a host directive are exposed on the host.
* Required input diagnostics are reported through the `OutOfBandDiagnosticRecorder`, rather than generating a new structure in the TCB, because it allows us to provide a better error message.
* Currently required inputs are only supported during AOT compilation, because knowing which bindings are present during JIT can be tricky and may lead to increased bundle sizes.

Fixes #37706.

PR Close #49304
2023-03-15 16:59:24 -07:00
Kristiyan Kostadinov
be97c87023 refactor(compiler): required inputs prerequisite refactors (#49333)
Based on the discussion in https://github.com/angular/angular/pull/49304#discussion_r1124732608. Reworks the compiler internals to allow for additional information about inputs to be stored. This is a prerequisite for required inputs.

PR Close #49333
2023-03-14 09:27:49 -07:00
Paul Gschwendtner
c241f63e8d refactor(compiler-cli): remove unused class decorator downlevel code (#49351)
The decorator downlevel transform is never used for actual class
decorators because Angular class decorators rely on immediate execution
for JIT. Initially we also supported downleveling of class decorators
for View Engine library output, but libraries are shipped using partial
compilation output and are not using this transform anymore.

The transform is exclusively used for JIT processing, commonly for
test files to help ease temporal dead-zone/forward-ref issues. We can
remove the class decorator downlevel logic to remove technical debt.

PR Close #49351
2023-03-08 17:59:12 +00:00
Alan Agius
1418d1937f test(compiler): add test case for merging objects in tsconfig (#49125)
This commit adds a test case for validate that we do not deep merge objects like like 'paths' and `extendedDiagnostics`.

PR Close #49125
2023-03-06 16:57:28 +00:00
Alan Agius
1407a9aeaf feat(compiler): support multiple configuration files in extends (#49125)
TypeScript 5 support `extends` to be an array, this commit adds support to allow extending `angularCompilerOptions` from multiple config files.

See: https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#supporting-multiple-configuration-files-in-extends

PR Close #49125
2023-03-06 16:57:28 +00:00
Alan Agius
f594725951 refactor(core): remove Node.js v14 support (#49255)
BREAKING CHANGE: Node.js v14 support has been removed

Node.js v14 is planned to be End-of-Life on 2023-04-30. Angular will stop supporting Node.js v14 in Angular v16. Angular v16 will continue to officially support Node.js versions v16 and v18.

PR Close #49255
2023-02-28 11:00:25 -08:00
Kristiyan Kostadinov
99d874fe3b feat(core): add support for TypeScript 5.0 (#49126)
Updates the project to support TypeScript 5.0 and to resolve any errors that came up as a result of the update.

PR Close #49126
2023-02-28 08:24:47 -08:00
Paul Gschwendtner
b6c6dfd278 fix(compiler-cli): do not persist component analysis if template/styles are missing (#49184)
Consider the following scenario:

1. A TS file with a component and templateUrl exists
2. The template file does not exist.
3. First build: ngtsc will properly report the error, via a FatalDiagnosticError
4. The template file is now created
5. Second build: ngtsc still reports the same errror.

ngtsc persists the analysis data of the component and never invalidates
it when the template/style file becomes available later.

This breaks incremental builds and potentially common workflows
where resource files are added later after the TS file is created. This
did surface as an issue in the Angular CLI yet because Webpack requires
users to re-start the process when a new file is added. With ESBuild
this will change and this also breaks incremental builds with
Bazel/Blaze workers.

To fix this, we have a few options:

* Invalidate the analysis when e.g. the template file is missing. Never
  caching it means that it will be re-analyzed on every build iteration.
* Add the resource dependency to ngtsc's incremental file graph. ngtsc
  will then know via `host.getModifiedResources` when the file becomes
  available- and fresh analysis of component would occur.

The first approach is straightforward to implement and was chosen here.
The second approach would allow ngtsc to re-use more of the analysis
when we know that e.g. the template file still not there, but it
increases complexity unnecessarily because there is no **single**
obvious resource path for e.g. a `templateUrl`. The URL is attempted
to be resolved using multiple strategies, such as TS program root dirs,
or there is support for a custom resolution through
`host.resourceNameToFileName`.

It would be possible to determine some candidate paths and add them to
the dependency tracker, but it seems incomplete given possible external
resolvers like `resourceNameToFileName` and also would likely not have
a sufficient-enough impact given that a broken component decorator is
not expected to remain for too long between N incremental build
iterations.

PR Close #49184
2023-02-24 08:24:07 -08:00
Kristiyan Kostadinov
79cdfeb392 feat(compiler): drop support for TypeScript 4.8 (#49155)
Drops support for TypeScript 4.8 from the compiler and removes all of the compatibility code we had for it.

BREAKING CHANGE:
* TypeScript 4.8 is no longer supported.

PR Close #49155
2023-02-23 10:39:43 -08:00
Andrew Kushnir
83a6e203e3 refactor(compiler): drop obsolete NgFactory and NgSummary config options (#48268)
The options to generate NgFactory and NgSummary files were added to Ivy for backwards compatibility with ViewEngine. Since ViewEngine was deprecated and removed, the NgFactory and NgSummary files are no longer used as well.

This commit drops obsolete options to generate NgFactory and NgSummary files. Also, the logic that generates those files is also removed.

PR Close #48268
2023-02-21 13:03:59 -08:00
Alan Agius
48aa96ea13 refactor: remove Angular Compatibility Compiler (ngcc) (#49101)
This commit removes the NGCC code and all the related infra setup required to support it.

BREAKING CHANGE: Angular Compatibility Compiler (ngcc) has been removed and as a result Angular View Engine libraries will no longer work

PR Close #49101
2023-02-16 16:01:17 -08:00
Kristiyan Kostadinov
f3f139942c refactor(compiler): remove remaining usage of getMutableClone (#49070)
Uses an alternate approach of preserving default imports that doesn't involve the `getMutableClone` function that is being removed in TypeScript 5.0.

The alternate approach was already used in the downlevel transform and it works by patching the EmitResolver of the current transformation context to tell TypeScript to preserve the import.

PR Close #49070
2023-02-16 15:30:52 -08:00
Kristiyan Kostadinov
0cf11167f1 fix(compiler-cli): incorrectly detecting forward refs when symbol already exists in file (#48988)
In #48898 the `isForwardRef` flag was added to indicate whether a reference should be wrapped in a `forwardRef`. This logic assumed that the node can't be referring to another node within the same file, however from testing it looks like that's not actually the case, because we hit the same code path when an external import to the same symbol exists already.

PR Close #48988
2023-02-07 09:00:46 -08:00
Kristiyan Kostadinov
d0145033bd fix(language-service): generate forwardRef for same file imports (#48898)
Adds some logic that will generate a `forwardRef` if necessary when automatically fixing an import.

PR Close #48898
2023-02-02 13:40:17 -08:00
Kristiyan Kostadinov
59c0106654 refactor(compiler): indicate whether potential import is forward reference (#48898)
In the `PotentialImport` we indicate if it's in the same file by not setting a `moduleSpecifier`, but if that's the case, the imported symbol might need to be wrapped in a `forwardRef` to avoid generating an error. These changes expose this information so the various tools can take advantage of it.

PR Close #48898
2023-02-02 13:40:17 -08:00
Payam Valadkhan
9250afbffd refactor(compiler-cli): Export the interface PluginCompilerHost for 1p use. (#48874)
Some 1p module which uses the method TscPlugin.wrapHost requires to import this type to make its internal class definitions compatible with this type.

PR Close #48874
2023-02-02 09:44:18 -08:00
Kristiyan Kostadinov
06e161f2dd fix(compiler): incorrect code when non-null assertion is used after a safe access (#48801)
Fixes that the expression converter was producing code that throws a runtime error if a non-null assertion is used as a part of a safe read, write or call.

Fixes #48742.

PR Close #48801
2023-01-25 18:31:37 +00:00
JoostK
4da1f2948c fix(compiler-cli): resolve deprecation warning (#48812)
This commit updates one usage of the `ts.factory.createMethodDeclaration` API
to avoid a deprecated function signature, which avoids logging a warning.

PR Close #48812
2023-01-24 16:45:12 +00:00
Kristiyan Kostadinov
6beff5e8d7 refactor(compiler): rework and expose APIs to be used in schematics (#48730)
Reworks some of the existing compiler APIs to make them easier to use in a schematic and exposes a few new ones to surface information we already had. High-level list of changes:
* `getPotentialImportsFor` now requires a class reference, instead of a `PotentialDirective | PotentialPipe`.
* New `getNgModuleMetadata` method has been added to the type checker.
* New `getPipeMetadata` method has been added to the type checker.
* New `getUsedDirectives` method has been added to the type checker.
* New `getUsedPipes` method has been added to the type checker.
* The `decorator` property was exposed on the `TypeCheckableDirectiveMeta`. The property was already present at runtime, but it wasn't specified on the interface.

PR Close #48730
2023-01-13 12:24:32 -08:00
Dylan Hunn
141333411e feat(language-service): Introduce a new NgModuleIndex, and use it to suggest re-exports. (#48354)
NgModules can re-export other NgModules, which transitively includes all traits exported by the re-exported NgModule. We want to be able to suggest *all* re-exports of a component when trying to auto-import it.

Previously, we used an approximation when importing from NgModules: we looked at a Component's metadata, and just imported the declaring NgModule. However, this is not technically correct -- the declaring NgModule it is not necessarily the same one that exports it for the current scope. (Indeed, there could be multiple re-exports!) As a replacement, I have implemented a more general solution.

This PR introduces a new class on the template type checker, called `NgModuleIndex`. When queried, it conducts a depth-first-search over the NgModule import/export graph, in order to find all NgModules anywhere in the current dependency graph, as well as all exports of those NgModules. This allows the language service to suggest all of the re-exports, in addition to the original export.

PR Close #48354
2023-01-12 13:46:46 -08:00
Dylan Hunn
ea8b33934b refactor(compiler-cli): Make getKnown return an array of nodes. (#48354)
`MetadataReaderWithIndex.getKnown` currently returns an iterator. It will be easier to work with for upcoming usages if it returns an array instead.

PR Close #48354
2023-01-12 13:46:46 -08:00
Kristiyan Kostadinov
7243ae64a6 fix(compiler): resolve deprecation warning (#48652)
Fixes a deprecation warning that was being logged by compiler when generating aliases, because we weren't going through `ts.factory` to create an AST node.

PR Close #48652
2023-01-10 08:13:25 -08:00
Matthieu Riegler
123c95209f docs(compiler-cli): fix commands to run compliance unit test (#48559)
PR Close #48559
2023-01-10 07:59:52 -08:00
Kristiyan Kostadinov
33f35b04ef fix(compiler): type-only symbols incorrectly retained when downlevelling custom decorators (#48638)
In #47167 an `updateClassDeclaration` call was swapped out with a `createClassDeclaration` which caused a regression where interface references were being retained when using a custom decorator in a project that has `emitDecoratorMetadata` enabled.

These changes switch back to use `updateClassDeclaration`.

Fixes #48448.

PR Close #48638
2023-01-04 12:29:16 -08:00
Kristiyan Kostadinov
a532d71975 feat(compiler): allow self-closing tags on custom elements (#48535)
Allows for self-closing tags to be used for non-native tag names, e.g. `<foo [input]="bar"></foo>` can now be written as `<foo [input]="bar"/>`. Native tag names still have to have closing tags.

Fixes #39525.

PR Close #48535
2023-01-04 12:07:37 -08:00
Paul Gschwendtner
caedef0f5b fix(compiler-cli): update @babel/core dependency and lock version (#48634)
Similar to how the `@babel/core` dependency is managed for the localize
NPM package, the version should be locked. Also the version should
correspond to the version we install for building & testing.

Currently the Babel version allowed by the compiler-cli may not
work given the ESM -> CJS interop. causing errors like:

```
import { types as t } from "@babel/core";
         ^^^^^
SyntaxError: Named export 'types' not found. The requested module '@babel/core' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@babel/core';
const { types: t } = pkg;
```

We can only be confident about the interop if we know the version
installed- is the one we test.

PR Close #48634
2023-01-03 16:36:50 +00:00
Kristiyan Kostadinov
50f95f831e refactor(compiler): remove TypeScript 4.7 compatibility code (#48470)
We dropped support for TypeScript 4.7 in version 15, but we had to keep around the runtime code, because of g3. Now that g3 is on 4.8, we can remove the additional code.

PR Close #48470
2023-01-02 13:47:22 +00:00
Paul Gschwendtner
90c2088679 build: make devmode a noop and ensure it never runs (#48521)
This is basically a pre-step for combining devmode and prodmode into a
single compilation. We are already achieving this now, and can claim
with confidence that we reduced possible actions by half. This is
especially important now that prodmode is used more often, but rules
potentially still using the devmode ESM sources. We can avoid double
compilations (which existed before the whole ESM migration too!).

We will measure this more when we have more concrete documentation
of the changes & a better planning document.

Changes:

  * ts_library will no longer generate devmode `d.ts`. Definitions are
    generated as part of prodmode. That way only prodmode can be exposed
    via providers.
  * applied the same to `ng_module`.
  * updates migrations to bundle because *everything* using `ts_library`
    is now ESM. This is actually also useful in the future if
    schematics rely on e.g. the compiler.
  * updates schematics for localize to also bundle. similar reason as
    above.

PR Close #48521
2022-12-19 19:50:45 +00:00