Commit graph

335 commits

Author SHA1 Message Date
Paul Gschwendtner
f3f0769ce7 refactor: update packages/core:{core,src} to ts_project (#61336)
Updates `packages/core:core` and `packages/core/src/...` to `ts_project`
of `rules_js`.

PR Close #61336
2025-05-14 08:31:33 -07:00
Paul Gschwendtner
899cb4ab49 refactor: add explicit types for exports relying on inferred call return type (#61316)
As part of the Bazel toolchain migration we noticed that implicit types
generated by the TypeScript compiler sometimes end up referencing types
from other packages (i.e. cross-package imports).

These imports currently work just because the Bazel `ts_library` and
`ng_module` rules automatically inserted a `<amd-module
name="@angular/x" />` into `.d.ts` of packages. This helped TS figure
out how to import a given file. Notably this is custom logic that is not
occuring in vanilla TS or Angular compilations—so we will drop this
magic as part of the toolchain cleanup!

To improve code quality and keep the existing behavior working, we are
doing the following:

- adding a lint rule that reduces the risk of such imports breaking. The
  failure scenario without the rule is that API goldens show unexpected
  diffs, and types might be duplicated in a different package!

- keeping the `<amd-module` headers, but we manually insert them into
  the package entry-points. This should ensure we don't regress
  anywhere; while we also improved general safety around this above.

Long-term, isolated declarations or a lint rule from eslint-typescript
can make this even more robust.

PR Close #61316
2025-05-13 22:46:00 +00:00
Paul Gschwendtner
0e3d4546b9 build: migrate compiler-cli/src/ngtsc to ts_project (#61237)
Migrates all of `compiler-cli/src/ngtsc` to `ts_project`. This change
was generated using Gemini.

PR Close #61237
2025-05-09 16:01:49 +00:00
Andrew Scott
0e82d42774 fix(language-service): Do not provide element completions in end tag (#60616)
Element completions should not be provided when the position is in the
end tag or between the start and end tags.

fixes https://github.com/angular/vscode-ng-language-service/issues/2157

PR Close #60616
2025-04-03 10:36:33 -07:00
Andrew Scott
f4c4b10ea8 fix(compiler-cli): Produce fatal diagnostic on duplicate decorated properties (#60376)
This prevents the compilation and language service from crashing.

fixes https://github.com/angular/vscode-ng-language-service/issues/2091

PR Close #60376
2025-03-27 20:26:42 +00:00
Andrew Kushnir
ee46567475 refactor(language-service): convert scripts within packages/language-service to relative imports (#60540)
This commit updates scripts within `packages/language-service` to relative imports as a prep work to the upcoming infra updates.

PR Close #60540
2025-03-26 20:40:02 -07:00
Paul Gschwendtner
bf899ef0f4 build: prepare testing infrastructure for code splitting of core package (#60487)
When we switch to relative imports, shared `.d.ts` chunks can be
generated.

We need to also pull these into our mock virtual FS testing
environments. Notably this does not cause a test slow-down because we
are talking about very few extra `.d.ts` chunk files. In our experiments
before, with no dts bundling, we saw test time increase from e.g.
20seconds to 100seconds. The 20s are still the same locally!

In addition, since code for definitions can now reside in shared `.d.ts`
chunks, the language service tests need to be adjusted in cases where
they assert for code definition locations in `@angular/core`. A new
helper prepares for more code to be moved into arbitrary `.d.ts` files;
we should simply assert the definition comes out of
`node_modules/@angular/core`.

PR Close #60487
2025-03-20 12:30:58 -07:00
Paul Gschwendtner
044dac98c9 feat(bazel): support bundling .d.ts with code splitting (#60321) (#60332)
Instead of relying on Microsoft's API extractor for `d.ts` bundling,
we are switching to Rollup-based `.d.ts` bundling.

This allows us to support code spliting, even for `.d.ts` files,
allowing for relative imports to be used between entry-points, without
ending up duplicating `.d.ts` definitions in two files. This would otherwise cause
problems with assignability of types.

It also nicely integrates into our existing rollup configuration, and
overall simplifies the `ng_package` rule even further!

Notably `tsup` also uses this rollup plugin, and it seems to work well.
Keep in mind that Microsoft's API extractor is pretty hard to integrate,
caused many problems in the past, and isn't capable of code splitting.
This aligns our d.ts bundling with the .mjs bundling (great alignment).

PR Close #60321

PR Close #60332
2025-03-11 15:33:05 -07:00
Andrew Scott
3f0116607d fix(language-service): Forward the tags for quick info from the type definition (#59524)
Prior to this commit, the tags from the type definition were dropped.
Tags may include, but are not limited to, deprecation information from
the jsdoc.

PR Close #59524
2025-03-04 17:37:23 +00:00
Andrew Scott
176475f0fc fix(language-service): provide correct rename info for elements (#60088)
This commit ensures we do not block element rename if it is supported by
other rename providers.

fixes https://github.com/angular/vscode-ng-language-service/issues/2077

PR Close #60088
2025-02-25 14:10:55 -05:00
Kristiyan Kostadinov
fe8a68329b feat(compiler): support untagged template literals in expressions (#59230)
Updates the compiler to support untagged template literals inside of the expression syntax (e.g. ``hello ${world}``).

PR Close #59230
2025-01-21 12:04:53 -08:00
Kristiyan Kostadinov
c5c20e9d86 fix(compiler-cli): check event side of two-way bindings (#59002)
In the past two-way bindings used to be interpreted as `foo = $event` at the parser level. In #54065 it was changed to preserve the actual expression, because it was problematic for supporting two-way binding to signals. This unintentionally ended up causing the TCB to two-way bindings to look something like `someOutput.subscribe($event => expr);` which does nothing. It largely hasn't been a problem, because the input side of two-way bindings was still being checked, except for the case where the input side of the two-way binding has a wider type than the output side.

These changes re-add type checking for the output side by generating the following TCB instead:

```
someOutput.subscribe($event => {
  var _t1 = unwrapSignalValue(this.someField);
  _t1 = $event;
});
```

PR Close #59002
2024-12-05 16:11:02 -08:00
Kristiyan Kostadinov
dcd27d7921 fix(language-service): add fix for individual unused imports (#58719)
Fixes that `getCodeActions` wasn't implemented for the unused imports fixer which meant that it wouldn't show up in the most common cases.

PR Close #58719
2024-11-19 12:19:14 -08:00
Paul Gschwendtner
6342befff8 feat(language-service): support migrating full classes to signal queries (#58263)
Adds a similar code action as for inputs, where users can migrate full
classes to signal queries.

PR Close #58263
2024-10-18 14:34:47 +00:00
Matthieu Riegler
c7fac7eecb refactor(language-service): Migrate manually ngtsc tests to standalone by default (#58160)
This commit is part of the migration to standalone by default.

PR Close #58160
2024-10-14 14:58:58 +00:00
Matthieu Riegler
09df589e31 refactor(core): Migrate all packages with the explicit-standalone-flag schematic. (#58160)
All components, directives and pipes will now use standalone as default.
Non-standalone decorators have now `standalone: false`.

PR Close #58160
2024-10-14 14:58:57 +00:00
Paul Gschwendtner
2cf88bba9a refactor(language-service): add support for running best-effort queries refactoring (#58168)
This is a follow-up to the VSCode queries code refactoring feature. This
commit adds support for running the refactoring with
`--best-effort-mode`.

PR Close #58168
2024-10-13 16:47:03 +00:00
Paul Gschwendtner
a59dbb7cd6 refactor(migrations): assign incompatibility reasons for query migration (#58152)
Instead of skipping queries without any reasoning, we should categorize
fields that couldn't be migrated. This is also important for the VSCode
integration— similar to how it's done with the inputs migration.

We are fully sharing the problematic pattern detection etc. This means
we are also sharing the enum. Not super ideal, but enables the best
sharing of code.

PR Close #58152
2024-10-11 11:23:38 +00:00
Paul Gschwendtner
5c4305f024 feat(language-service): support migrating full classes to signal inputs in VSCode (#57975)
This commit expands the VScode integration of the signal input migration
to allow migration of full classes and all their inputs. This enables a
faster workflow than just migrating every member individually.

In addition, we now properly support migrating classes that are
unexported and no actual metadata is available in `ngtsc` (but this is
fine for the migration).

PR Close #57975
2024-09-30 13:29:21 -07:00
Enea Jahollari
39ccaf4cc4 fix(compiler-cli): correctly get the type of nested function call expressions (#57010)
This PR fixes a bug where the type of a nested function call expression was incorrectly being returned as null.

PR Close #57010
2024-09-26 14:13:03 -07:00
Joey Perrott
9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00
Kristiyan Kostadinov
39098f3a9b refactor(compiler): finalize hydrate syntax (#57831)
Finalizes compiler implementation of the new `hydrate` triggers by:
* Reworking the logic that was depending on the `hydrateSpan` to distinguish hydrate triggers from non-hydrate triggers.
* Fixing that the `hydrate when` trigger didn't have a `hydrateSpan`.
* Adding an error if a parameter is passed into a `hydrate` trigger.
* Add an error if other `hydrate` triggers are used with `hydrate never`.
* Replacing the `prefetch` and `hydrate` flags in the template pipeline with a `modifiers` field.
* Fixing an error that was being thrown when reifying `hydrate` triggers in the pipeline.
* Adding quick info support for the `hydrate` keyword in the language service.
* Adding some tests for the new logic.

PR Close #57831
2024-09-17 11:05:17 +02:00
Paul Gschwendtner
227d13b86d refactor(migrations): preserve brace spacing when applying imports (#57672)
Currently the import manager always add a space after the import clause
brace. We should only do this if the existing import did the same.

PR Close #57672
2024-09-05 19:33:04 +00:00
Paul Gschwendtner
f694acb587 refactor(language-service): improve error messaging for signal input refactoring (#57659)
Instead of printing the enum name as the reason why migration did not
complete, we should print some human-readable descriptions.

This commit implements this. This logic may also be useful for the
devkit comment generation, or CLI usage.

In addition, we expose another VSCode refactoring to try via best effort
mode. There is no way for prompting, or adding multiple actions for the
same refactoring, so we expose a new refactoring.

PR Close #57659
2024-09-04 20:07:18 +00:00
Paul Gschwendtner
9c31ba95e5 refactor(migrations): properly apply edits in signal input refactoring action (#57659)
The language service expects absolute paths, but Tsurge only deals with
project relative paths. This commit fixes this.

PR Close #57659
2024-09-04 20:07:18 +00:00
Kristiyan Kostadinov
8da9fb49b5 feat(language-service): add code fix for unused standalone imports (#57605)
Adds an automatic code fix to the language service that will remove unused standalone imports.

PR Close #57605
2024-09-03 14:30:56 -07:00
Paul Gschwendtner
2ad9609a8d refactor(migrations): pass project-relative paths for tsurge replacements (#57584)
This allows for the replacements to be conveniently passed between
migration stages. This is especially relevant in 1P where stages may
have different root directories.

Tsunami attempts to relativize paths in general, similar to how we do
here, but this doesn't work with e.g. Funnel-based migrations where
replacements are serialized in between stages; and where the migration
stage at the end doesn't know about the previous root directory anymore.

PR Close #57584
2024-08-29 14:28:02 -07:00
Paul Gschwendtner
1f067f4507 feat(language-service): add code reactoring action to migrate @Input to signal-input (#57214)
(experimental at this point)

Language service refactoring action that can convert `@Input()`
declarations to signal inputs.

The user can click on an `@Input` property declaration in e.g. the VSCode
extension and ask for the input to be migrated. All references, imports and
the declaration are updated automatically.

PR Close #57214
2024-08-29 07:50:41 -07:00
Paul Gschwendtner
4900225aee build: move language-service utils into its own bazel target (#57214)
This allows us to split up the BUILD rules a bit further, so that
refactorings can be their own BUILD target. This is beneficial as
e.g. refactorings may rely on migration code from Angular core etc.
and this allows for more fine-grained visibility and a better conceptual
split.

PR Close #57214
2024-08-29 07:50:40 -07:00
Kristiyan Kostadinov
b063468027 feat(core): support TypeScript 5.6 (#57424)
Updates the repo to add support for the upcoming TypeScript 5.6.

PR Close #57424
2024-08-19 22:45:45 -07:00
Kristiyan Kostadinov
d4ff6bc0b2 fix(compiler-cli): add warning for unused let declarations (#57033)
Adds a new extended diagnostic that will flag `@let` declarations that aren't used within the template. The diagnostic can be turned off through the `extendedDiagnostics` compiler option.

PR Close #57033
2024-07-23 08:27:17 -07:00
Andrew Scott
4ac39aeea9 Revert "fix(compiler-cli): add warning for unused let declarations (#57033)" (#57088)
This reverts commit c76b440ac0.

PR Close #57088
2024-07-22 15:28:03 -07:00
Kristiyan Kostadinov
c76b440ac0 fix(compiler-cli): add warning for unused let declarations (#57033)
Adds a new extended diagnostic that will flag `@let` declarations that aren't used within the template. The diagnostic can be turned off through the `extendedDiagnostics` compiler option.

PR Close #57033
2024-07-19 11:50:32 -07:00
Kristiyan Kostadinov
0a48d584f2 feat(core): add support for let syntax (#56715)
Enables the new `@let` syntax by default.

`@let` declarations are defined as:
1. The `@let` keyword.
2. Followed by one or more whitespaces.
3. Followed by a valid JavaScript name and zero or more whitespaces.
4. Followed by the `=` symbol and zero or more whitespaces.
5. Followed by an Angular expression which can be multi-line.
6. Terminated by the `;` symbol.

Example usage:
```
@let user = user$ | async;
@let greeting = user ? 'Hello, ' + user.name : 'Loading';
<h1>{{greeting}}</h1>
```

Fixes #15280.

PR Close #56715
2024-06-26 12:37:02 -07:00
ivanwonder
67b2c336bc fix(language-service): import the default exported component correctly (#56432)
When importing a component exported by default, the `default` can't be
used as the component name.

For example:

This is the export declarations:

```ts
export default class TestComponent {}
```

Previously, the output generated by LS looked like this:

```ts
import { default } from "./test.component";
```

Now the output looks like this:

```ts
import TestComponent from "./test.component";
```

Fixes #48689

PR Close #56432
2024-06-17 12:48:48 -07:00
ivanwonder
b400e2e4d4 feat(language-service): autocompletion for the component not imported (#55595)
This PR allows the language service to suggest imports for all directives returned from the
compiler, and generate the TypeScript module import and the decorator import when the component
is selected by the user.

PR Close #55595
2024-06-12 13:04:32 -07:00
Kristiyan Kostadinov
dd869e4d68 refactor(language-service): integrate let declarations (#56270)
Integrates let declarations in the various places within the language service (quick info, completions etc).

PR Close #56270
2024-06-05 18:45:23 +00:00
Kristiyan Kostadinov
e5a6f91722 feat(core): support TypeScript 5.5 (#56096)
Updates the repo to add support for TypeScript 5.5. Includes resolving some compilation errors and broken tests.

PR Close #56096
2024-05-29 15:33:33 +02:00
Joey Perrott
ca517d7f2c refactor: migrate language-service to prettier formatting (#55405)
Migrate formatting to prettier for language-service from clang-format

PR Close #55405
2024-04-18 14:18:38 -07:00
Andrea Canciani
f3b624553a refactor: fix a number of typos throughout the codebase (#55018)
Fix some typos detected using spellchecking tools, both in
documentation and in code (comments, identifiers).

PR Close #55018
2024-03-27 10:54:31 -07:00
Kristiyan Kostadinov
cf8fb33a23 refactor(compiler-cli): integrate fallback content for ng-content into template type checker (#54854)
Adds logic to ingest the content of an `ng-content` element in the template type checker. We treat `ng-content` as a `ScopedNode`, because its content is inserted conditionally.

PR Close #54854
2024-03-26 09:17:58 -07:00
Dylan Hunn
ef39107ce5 refactor(language-service): Replace tsserverlibrary -> typescript (#54726)
Typescript recently consolidated `tsserverlibrary` into `typescript`: [blog post](https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/#consolidation-between-tsserverlibrary-js-and-typescript-js)

In this commit, we remove all references to `tsserverlibrary` accordingly. This should be safe, since v18 and later support TS 5.3+.

PR Close #54726
2024-03-07 10:49:01 -08:00
Paul Gschwendtner
2df8584619 refactor(compiler-cli): speed up compiler tests by caching Angular (#54650)
Currently the `makeProgram` utility from `ngtsc/testing` does not use
the test host by default- optimizing for source file caching.

Additionally, the host can be updated to attempt caching of the `.d.ts`
files from `@angular/core`— whether that's fake core, or the real core-
is irrelevant. We are never caching if these changes between tests, so
correctness is guaranteed.

This commit reduces the type check test times form 80s to just 11
seconds, faster than what it was before with `fake_core`. The ngtsc
tests also run significantly faster. From 40s to 30s

PR Close #54650
2024-03-06 12:34:39 +01:00
Paul Gschwendtner
400b739874 test: add language-service tests for outputFromObservable() (#54650)
Adds additional language-service tests for `outputFromObservable()`.
Existing tests already verify the behavior for `output()`.

PR Close #54650
2024-03-06 12:34:39 +01:00
Paul Gschwendtner
c687b8f453 feat(core): expose new output() API (#54650)
This commit exposes the new `output()` API with numerous benefits:

- Symmetrical API to `input()`, `model()` etc.
- Fixed types for `EventEmitter.emit`— current `emit` method of
  `EventEmitter` is broken and accepts `undefined` via `emit(value?: T)`
- Removal of RxJS specific concepts from outputs. error channels,
  completion channels etc. We now have a simple consistent
  interface.
- Automatic clean-up of subscribers upon directive/component destory-
  when subscribed programmatically.

```ts
@Directive({..})
export class MyDir {
  nameChange = output<string>();     // OutputEmitterRef<string>
  onClick = output();                // OutputEmitterRef<void>
}
```

Note: RxJS custom observable cases will be handled in future commits via
explicit helpers from the interop.

PR Close #54650
2024-03-06 12:34:38 +01:00
Paul Gschwendtner
2564b45b47 test: replace fake_core with real @angular/core output (#54650)
This commit replaces `fake_core` with the real `@angular/core`
output. See previous commit for reasons.

Overall, this commit:

* Replaces references of `fake_core`
* Fixes tests that were testing Angular compiler detection that _would_
  already be flagged by type-checking of TS directly. We keep these
  tests for now, and add `@ts-ignore` to verify the Angular checks, in
  case type checking is disabled in user applications- but it's worth
  considering to remove these tests. Follow-up question/non-priority.
* Adds `@ts-ignore` to the tests for `defer` 1P because the property is
  marked as `@internal` and now is (correctly) causing failures in the
  compiler test environment.
* Fixes a couple of tests with typos, wrong properties etc that
  previously weren't detected! A good sign.

PR Close #54650
2024-03-06 12:34:38 +01:00
Kristiyan Kostadinov
981c28c15f refactor(compiler-cli): do not emit signal unwrap calls in versions older than 17.2 (#54423)
In order to allow both signals and non-signals in two-way bindings, we have to pass the expression through `ɵunwrapWritableSignal`. The problem is that the language service uses a bundled compiler that is fairly new, but it may be compiling an older version of Angular that doesn't expose `ɵunwrapWritableSignal` (see https://github.com/angular/vscode-ng-language-service/issues/2001).

These changes add a `_angularCoreVersion` flag to the compiler which the language service can use to pass the parsed Angular version to the compiler which can then decide whether to emit the function.

PR Close #54423
2024-02-13 15:53:42 -08:00
Kristiyan Kostadinov
0b955b867c test(language-service): add tests for model inputs (#54387)
Updates the language service tests to cover `model()` inputs.

PR Close #54387
2024-02-12 11:01:53 -08:00
Kristiyan Kostadinov
153fc61d45 build: reuse fake core in type checking tests (#54344)
Currently we have two fake copies of `@angular/core` in the compiler tests which can be out of sync and cause inconsistent tests. These changes reuse a single copy instead.

PR Close #54344
2024-02-08 19:21:47 +00:00
Paul Gschwendtner
02fdd8d6ee test: add tests to verify language-service supports output() function (#54217)
Adds unit tests to verify that the language service supports
the `output()` function with completions, and definition jumping.

PR Close #54217
2024-02-05 15:08:35 +00:00