Commit graph

793 commits

Author SHA1 Message Date
Kristiyan Kostadinov
bf2b0253bc refactor(compiler-cli): move typeCheckHostBindings option (#60267)
Moves the `typeCheckHostBindings` option into `StrictTemplateOptions` and renames the latter.

PR Close #60267
2025-03-17 14:28:41 +01:00
Kristiyan Kostadinov
b8f2a50c68 refactor(compiler-cli): track host binding information (#60267)
Sets up the infrastructure to track the host bindings of directives for type checking purposes.

PR Close #60267
2025-03-17 14:28:40 +01:00
Paul Gschwendtner
4fa5d18e5a feat(bazel): support bundling .d.ts with code splitting (#60321)
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
2025-03-11 13:03:08 -07:00
Kristiyan Kostadinov
1b91de3231 refactor(language-service): rename internal symbols to accommodate type checking outside a template (#60191)
Currently the language service has some template-specific terminology around type checking, because that's the only place where we had TCB support. These changes make it more generic to accommodate future functionality.

PR Close #60191
2025-03-06 10:39:31 -08:00
Kristiyan Kostadinov
afea8a9d0c refactor(compiler-cli): rework resource handling to allow directives (#60191)
Currently only components can have resources, because they're the only symbol kinds being type checked. Since we want to add directives to it, these changes rework the resource handling to accommodate them.

PR Close #60191
2025-03-06 10:39:31 -08:00
Kristiyan Kostadinov
44a8de20d5 refactor(compiler-cli): rework source manager to accommodate directives (#60191)
Currently the `TemplateSourceManager` is set up to specifically cater to component templates. These changes make it more generic so we can reuse it for directives.

PR Close #60191
2025-03-06 10:39:31 -08:00
Andrew Scott
d5e91e04ff 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:22 +00:00
Miles Malerba
51b8ff23ce feat(compiler): support tagged template literals in expressions (#59947)
Adds support for using tagged template literals in Angular templates.

Ex:
```
@Component({
  template: '{{ greet`Hello, ${name()}` }}'
})
export class MyComp {
  name = input();

  greet(strings: TemplateStringsArray, name: string) {
    return strings[0] + name + strings[1] + '!';
  }
}
```

PR Close #59947
2025-02-28 19:53:33 +00:00
Miles Malerba
7c9b4892e9 fix(compiler-cli): preserve required parens in exponentiation expressions (#60101)
Parentheses are required around a unary operator used in the base of an
exponentiation expression. For example: `(-1) ** 3`

PR Close #60101
2025-02-28 16:28:10 +00:00
Andrew Scott
b9306719df 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:53 -05:00
Miles Malerba
0361c2d81f feat(compiler): support void operator in templates (#59894)
Add support for the `void` operator in templates and host bindings.

This is useful when binding a listener that may return `false` and
unintentionally prevent the default event behavior.

Ex:
```
@Directive({
  host: { '(mousedown)': 'void handleMousedown()' }
})
```

BREAKING CHANGE: `void` in an expression now refers to the operator

Previously an expression in the template like `{{void}}` referred to a
property on the component class. After this change it now refers to the
`void` operator, which would make the above example invalid. If you have
existing expressions that need to refer to a property named `void`,
change the expression to use `this.void` instead: `{{this.void}}`.

PR Close #59894
2025-02-25 11:03:37 -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
hawkgs
0513fbc9fc docs: set syntax highlighting of code examples MD code blocks (#59026)
Set the syntax highlighting based on the code examples' language.

PR Close #59026
2024-12-04 17:30:28 +01:00
Charles Lyding
67a4a7b27e refactor(language-service): reuse code fixes map for has fix check (#58759)
The error codes that have fixes are present in a Map instance and
can be directly leveraged to determine if an error code can be fixed.
This avoids multiple levels of iteration that would otherwise be needed.

PR Close #58759
2024-11-20 08:10:15 -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
Kristiyan Kostadinov
f5b2b58b3b fix(language-service): allow fixes to run without template info (#58719)
Currently the code fixes won't run if the template information can't be resolved on the diagnostic node. This is incorrect for diagnostics that are reported within `.ts` files. These changes make the `templateInfo` nullable and leave the early exit up to the individual fixes.

PR Close #58719
2024-11-19 12:19:14 -08:00
Charles Lyding
9b309c129a refactor(language-service): suppress inline TCB required diagnostic for syncs (#58619)
The NG8900 diagnostic is a non-actionable error code that does not affect
the build result of a component.

PR Close #58619
2024-11-13 18:36:08 +00:00
Kristiyan Kostadinov
086cb2c40e fix(compiler-cli): report individual diagnostics for unused imports (#58589)
Initially the unused imports check was implemented so that it reports one diagnostic per component with the individual unused imports being highlighted through the `relatedInformation`. This works fine when reporting errors to the command line, but vscode appears to only show `relatedInformation` when the user hovers over a diagnostic which is a sub-par experience.

These changes switch to reporting a diagnostic for each unused import instead.

PR Close #58589
2024-11-11 15:31:00 +00:00
Kristiyan Kostadinov
3061c67539 refactor(language-service): update code fix for unused imports (#58468)
Since the unused imports diagnostic setup has changed, we need to update the code fix to account for it.

PR Close #58468
2024-11-01 14:33:56 +00:00
Alan Agius
7de7c52769 build: remove usages of useDefineForClassFields: false (#58297)
When setting `"useDefineForClassFields": false`, static fields are compiled within a block that relies on the `this` context. This output makes it more difficult for bundlers to treeshake and eliminate unused code.

PR Close #58297
2024-10-28 12:26:05 -07:00
Paul Gschwendtner
dd686edfe9 refactor(migrations): update migrations to combine analysis data in parallel (#58280)
This is necessary given the previous Tsurge refactorings. It should
speed up migrations in the merge phase signficiantly and reduce memory
pressure. In 1P, we already have workers from analyze phase anyway— so
those can be re-used for parallel metadata merging.

PR Close #58280
2024-10-25 18:47:41 +00:00
Matthieu Riegler
8af71c05b2 refactor(language-service): support standalone by default (#58238)
`isStandaloneDecorator()` returns `false` only when the component is explicitly not standalone

PR Close #58238
2024-10-24 12:44:13 -07:00
Andrew Kushnir
1215927e5b Revert "refactor(migrations): update migrations to combine analysis data in parallel (#58280)" (#58313)
This reverts commit 8735543d06.

PR Close #58313
2024-10-22 12:27:53 -07:00
Paul Gschwendtner
8735543d06 refactor(migrations): update migrations to combine analysis data in parallel (#58280)
This is necessary given the previous Tsurge refactorings. It should
speed up migrations in the merge phase signficiantly and reduce memory
pressure. In 1P, we already have workers from analyze phase anyway— so
those can be re-used for parallel metadata merging.

PR Close #58280
2024-10-22 11:29:16 -07:00
Paul Gschwendtner
c1432f939b refactor(language-service): improve name of input full class refactoring action (#58263)
Prefixing the full class refactoring actions with `Full class` makes
them less confusing along with the individual field actions.

PR Close #58263
2024-10-18 14:34:47 +00: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
Dzhavat Ushev
9097b734e5 docs(language-service): fix link URLs (#58143)
PR Close #58143
2024-10-16 14:48:13 +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
19369d78ba refactor(migrations): share best effort logic between input and query migration (#58168)
Allows us to easily implement a best effort mode for both migrations.

PR Close #58168
2024-10-13 16:47:02 +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
66cca86489 refactor(migrations): allow reuse of input incompatibility categorization in query migration (#58139)
This commit moves the incompatibility categorization into a more common
place, and renames it from Input incompatibilities to "field
incompatibilities". This construct can then be used in the queries
migration as well to give insight into why certain fields weren't
migrated.

PR Close #58139
2024-10-09 16:23:33 +00:00
Paul Gschwendtner
bc83fc1e2e feat(language-service): support converting to signal queries in VSCode extension (#58106)
This commit adds support for converting decorator queries to signal queries
via the VSCode extension.

Note that this is not fully finished as we still need to add better
messaging when certain fields could not be migrated.

In addition, it's worth noting that the migration is not as safe as the
input migration because commonly query lists are passed around— this
quickly can break the build— but is an acceptable trade-off for the work
saved. A migration cannot be 100% correct in general; there are always
edge-cases.

PR Close #58106
2024-10-08 06:19:37 +00:00
Paul Gschwendtner
754a857f8c refactor(migrations): support extra return info for TsurgeMigration#migrate (#58106)
This allows us to return extra properties along with `#migrate`
replacements. Useful for language service integration or other
integrations of Tsurge migrations in special runners.

PR Close #58106
2024-10-08 06:19:37 +00:00
Matthieu Riegler
84b6896956 refactor(platform-server): Add an ssr benchmark setup. (#57647)
In order to investigate the performances of SSR, this commit introduces a benchmark suite which will measure several step of the rendering.

PR Close #57647
2024-10-04 10:45:22 -07: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
Dylan Hunn
7ecfd89592 fix(language-service): The suppress diagnostics option should work for external templates (#57873)
Previously, due to a bug, this option only worked for inline templates.

PR Close #57873
2024-09-23 12:03:30 +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
6cdcf5d6ca refactor(compiler-cli): respect configured file system when parsing tsconfig (#57805)
Whenever the `ngc` binary is used directly to parse configurations, we
should try to respect the configured file system like we do in all other
places. Right now one spot where we escape the FS is for reading
directories to e.g. support tsconfig#includes.

This commit fixes this, implementing TypeScript's read directory method
leveraging the configured FS. The approach taken here was used for a
couple of months/years for Angular Material migrations and no issues
were found.

PR Close #57805
2024-09-16 18:06:49 +02:00
Paul Gschwendtner
2e60eb08f4 refactor(migrations): ensure project paths respect root directories (#57677)
Migrations may resolve files in e.g. `blaze-out` and try to compute a
path for the file that is "recognizable" across workers. E.g. in one
worker, it may be the actual `.ts` file inside the source tree, while in
the other, the file may be inside `blaze-out`.

Tsurge currently expects project relative paths to be passed around.
Those project relative paths are currently only based on the single root
directory. Hence paths inside `blaze-out` would actually not be
recognizable.

The fix idea here is that we introduce a structure for Project files.
This structure will contain two fields:

- an ID of a file. This is similar to a module ID in the project. Those
  are resolved with respect to all root directories. This matches the
  conceptual virtual roots of `tsconfig#rootDirs`. The IDs can be used
  for matching files across workers, assuming those are executing using
  the same root directories, and handle the same overall project (e.g.
  google3).

- a path relative to the primary project root. Multiple roots may be
  configured, but the primary project root, is the directory that
  contains all others. See: `tsconfig.rootDir`. This path is NOT
  necessarily useful for matching files between stages etc, but it's
  useful for writing replacements for a given file to disk.

Note that those two things cannot be combind into one conceptual
"project relative path" because a path relative to the most appropriate
root directory cannot be used for safe replacements. E.g. consider a
replacement matches a file from a root directory like `/sub/`. The path
inside `/sub/` would then omit the `/sub/` and later on when writing
replacements, we wouldn't know which root directory it actually was part
of. Hence the concept of a "project root relative path" and the "ID".

ds

PR Close #57677
2024-09-06 19:44:07 +00:00
Dylan Hunn
f063a75eae refactor(language-service): Allow language service diagnostics to be ignored (#57675)
Add a check to the language service that ignores specified diagnostic codes. This will be useful in g3.

The codes to ignore are exposed as part of the PluginConfig.

Fixes github.com/angular/vscode-ng-language-service/issues/1243

PR Close #57675
2024-09-06 14:14:47 +00: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
cf88d8a8c1 refactor(language-service): align signal input refactoring messages (#57672)
This ensures they follow the same pattern.

PR Close #57672
2024-09-05 19:33:04 +00:00
Paul Gschwendtner
f6c40f1ba1 refactor(migrations): expose all input migration helpers (#57659)
Instead of encouraging deep imports, we should expose commonly accessed
exports in a `index.ts` barrel file.

PR Close #57659
2024-09-04 20:07:18 +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