Commit graph

3229 commits

Author SHA1 Message Date
Kristiyan Kostadinov
2e891ad72a fix(compiler): add math elements to schema (#55631)
Fixes that we didn't have the MathML elements in the schema. Note that we can't discover which tag names are available by looking at globally-available classes, because all MathML elements are `MathMLElement` rather than something like `SVGCircleElement`. As such, I ended up having to hardcode the currently-available tags.

Fixes #55608.

PR Close #55631
2024-05-02 11:12:14 -07:00
Payam Valadkhan
1f2e791c57 refactor(compiler-cli): optimize extra import generation in local compilation mode (#55548)
Currently we add global extra imports to all the files in the compilation unit. However not all the files need extra imports. For example non-Angular files definitely do not need such extra imports, and in some cases these extra imports causes problems as the file is meant to be run the Node but it has Angular dependencies which are not compatible with Node. This change tries to limit extra import generation to a subset of files. Wit hthis change we create extra imports only for the files that contain at least one component whose NgModule is in a different file. This is because all other files do not need extra imports since they are either not Angular files or they already have all the imports that the components need.

PR Close #55548
2024-05-02 10:57:41 -07:00
Paul Gschwendtner
0a77825042 build: improve incremental rebuilds of compliance tests (#55594)
Currently whenever a compliance test case TS file is modified, all
compliance tests in repository are rebuilt in partial compilation mode.
This is inefficient and also slows down local development where one may
use a wildcard to run all test targets inside `/test/compliance/...`.

This commit fixes this.

PR Close #55594
2024-04-30 09:22:38 -07:00
Doug Parker
292c987791 refactor(compiler): add handler attribute to XMB output (#54865)
This allows tracking of which tools generated which XMB files and helps attribute Angular usage.

PR Close #54865
2024-04-29 11:56:31 -07:00
Joey Perrott
0d78a92431 refactor: migrate compiler-cli to prettier formatting (#55485)
Migrate formatting to prettier for compiler-cli from clang-format

PR Close #55485
2024-04-29 10:25:43 -07:00
Matthieu Riegler
1bea1fe8a0 docs: improvements for API pages (#55388)
* add link for source files
* add deprecation message for methods
* add usage notes for methods

Fixes #55196
Fixes #52641

PR Close #55388
2024-04-19 06:30:34 -07:00
Kristiyan Kostadinov
7a16d7e969 fix(compiler-cli): don't type check the bodies of control flow nodes in basic mode (#55360)
Angular only checks the contents of template nodes in full type checking mode. After v17, the new control flow always had its body checked, even in basic mode, which started revealing compilation errors for apps that were using the schematic to automatically switch to the new syntax.

These changes mimic the old behavior by not checking the bodies of `if`, `switch` and `for` blocks in basic mode. Note that the expressions of the blocks are still going to be checked.

Fixes #52969.

PR Close #55360
2024-04-19 06:29:56 -07:00
Kristiyan Kostadinov
4eb0165750 fix(compiler): remove support for unassignable expressions in two-way bindings (#55342)
Two-way bindings are meant to represent a property binding to an input and an event binding to an output, e.g. `[(ngModel)]="foo"` represents `[ngModel]="foo" (ngModelChange)="foo = $event"`. Previously due to a quirk in the template parser, we accidentally supported unassignable expressions in two-way bindings.

In #54154 the quirk was fixed, but we kept support or some common expression because of internal usages. Now the internal usages have been cleaned up so the backwards-compatibility code can be deleted.

Externally a migration was added in #54630 that will automatically fix any places that depended on the old behavior.

BREAKING CHANGE:
Angular only supports writable expressions inside of two-way bindings.

PR Close #55342
2024-04-16 17:26:09 +02:00
Kristiyan Kostadinov
7d5bc1c628 fix(compiler): remove container index from conditional instruction (#55190)
Stops passing in the `containerIndex` argument to the `conditional` instruction since it isn't being used anymore.

PR Close #55190
2024-04-16 10:23:30 +02:00
Matthieu Riegler
9afa2ea345 refactor(compiler-cli): include filepath for DocEntry (#55201)
This is allow the API docs to provide a direct link to implementation on github.

PR Close #55201
2024-04-15 17:41:45 +02:00
Angular Robot
c3e34f1822 build: update babel dependencies to v7.24.4 (#55257)
See associated pull request for more information.

PR Close #55257
2024-04-12 10:21:24 -07:00
Chinthoorie
0a8c48e76e refactor(compiler-cli): move config initialization into constructor (#54975)
refactor(compiler-cli): move config initialization into constructor
PR Close #54975
2024-04-11 11:20:17 +02:00
Matthieu Riegler
1c6553e823 refactor(compiler-cli): Link to adev (#55043)
Replace aio links with to adev guides

PR Close #55043
2024-04-09 12:23:09 -07:00
Kristiyan Kostadinov
39624c6b12 fix(compiler): output input flags as a literal (#55215)
Previously the input flags were being generated as a reference to an enum member for better readability and under the assumption that minifiers would inline the values. That doesn't appear to be the case so these changes switch to using the literal values instead.

PR Close #55215
2024-04-04 11:13:52 -07:00
Dylan Hunn
f824911510 fix(compiler): For FatalDiagnosticError, hide the message field without affecting the emit (#55160)
We want to hide `.message` from users, but the previous approach is not compatible with a specific [TS 3.7 flag](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier) ("using class fields to specialize properties from base classes also won’t work"). I received a request from the TS team to fix this, so they can enable that flag.

Instead, we just override `message` to `never` in the .d.ts using `declare`.

PR Close #55160
2024-04-02 16:20:23 +00:00
Kristiyan Kostadinov
c04ffb1fa6 fix(compiler-cli): use switch statements to narrow Angular switch blocks (#55168)
In #52110 we had to use `if` statements to represent `switch` blocks, because TypeScript had a bug when narrowing the type of parenthesized `switch` statements. Now that it has been fixed by TypeScript and we don't support any version that has the broken behavior, we can go back to generating `switch` statements in the TCB which are simpler and better represent the user's code.

PR Close #55168
2024-04-02 16:19:47 +00:00
Angular Robot
218c5bd2b3 build: update dependency @babel/core to v7.24.3 (#55038)
See associated pull request for more information.

PR Close #55038
2024-03-29 09:44:58 -07:00
Kristiyan Kostadinov
336916ceb0 refactor(compiler-cli): allow source file validator rule to produce a single diagnostic (#54993)
Allows for `SourceFileValidatorRule.checkNode` to produce a single diagnostic. The most common case should be one diagnostic per node so this allows us to save some array allocations.

PR Close #54993
2024-03-28 09:17:04 -07:00
Kristiyan Kostadinov
694ba79cbf fix(compiler-cli): report cases where initializer APIs are used in a non-directive class (#54993)
Expands the check for initializer APIs to also flag when the function is called on a class that isn't a component or directive.

PR Close #54993
2024-03-28 09:17:03 -07:00
Kristiyan Kostadinov
78188e877a fix(compiler-cli): add diagnostic if initializer API is used outside of an initializer (#54993)
Adds a rule that will produce a diagnostic when an initializer-based API is used outside of an initializer.

Fixes #54381.

PR Close #54993
2024-03-28 09:17:02 -07:00
Kristiyan Kostadinov
8226be6abf refactor(compiler-cli): introduce infrastructure for running additional checks against TypeScript files (#54993)
Adds the new `SourceFileValidator` that will be used to check for file-level issues that may prevent Angular from working, like invoking the `input()` function outside of an initializer. Currently only one check is planned, but this setup will allow us to easily add more in the future.

PR Close #54993
2024-03-28 09:17:01 -07:00
Kristiyan Kostadinov
3d9f01c6ec refactor(compiler-cli): add API to check if imports exist (#54993)
Adds a couple of APIs to the `ImportedSymbolsTracker` that allow us to quickly check if a specific symbol is imported in a file.

PR Close #54993
2024-03-28 09:17:00 -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
Matthieu Riegler
b230bbc90d refactor(compiler): Do not extract internal methods. (#54850)
internal methods are not exposed to end users and should not be extracted.

PR Close #54850
2024-03-27 10:48:05 -07:00
Paul Gschwendtner
03b1ac3ce7 refactor(compiler-cli): improve error message for uncaught FatalDiagnosticError (#54981)
For `FatalDiagnosticError` we are currently hiding the `message` string
field in favor of the actual TS `diagnosticMessage`.

This works as expected, but makes these errors hard to debug in certain
environments (e.g. Jasmine). That is because `null` is the value of
`message` at runtime. We fix this by just overriding the type, like we
originally intended to do.

In addition, we properly render message chains in the `Error#message`
field— so that these errors, when uncaught, are somewhat reasonable and
can be useful.

PR Close #54981
2024-03-27 09:54:46 -07:00
Paul Gschwendtner
6219341d26 fix(compiler-cli): report errors when initializer APIs are used on private fields (#54981)
This commit ensures that the new APIs like `input`, `model`, `output`,
or signal-based queries are not accidentally used on fields that have a
problematic visibility/access level that won't work.

For example, queries defined using a private identifier (e.g. `#bla`)
will not be accessible by the Angular runtime and therefore _dont_ work.

This commit ensures:

- `input` is only declared via public and protected fields.
- `output` is only declared via public and protected fields.
- `model` is only declared via public and protected fields.
- signal queries are only declared via public, protected and TS private
  fields (`private` works, while `#bla` does not).

Fixes #54863.

PR Close #54981
2024-03-27 09:54:45 -07:00
Paul Gschwendtner
64ae07766e refactor(compiler-cli): support enforcing field access for initializer APIs (#54981)
An initializer API like `input`, `output`, or signal queries may not be
compatible with certain access levels. E.g. queries cannot work with ES
private class fields.

This commit introduces a check for access levels into the initializer
API recognition— enforcing that every initializer API *clearly*
specifies what type of access is allowed.

PR Close #54981
2024-03-27 09:54:45 -07:00
Paul Gschwendtner
9366a94781 refactor(compiler-cli): reflection should inspect ES private fields and visibility (#54981)
This commit changes the TypeScript reflection host to:

* inspect / process ES private fields. e.g. `#someField` — those are
  ignored right now and we would want to check them to issue
  diagnostics.

* determine an access level of a class member. E.g. a member may be
  public, may be private, may be ES private, or public readonly. This
  can then be used in various checks later.

PR Close #54981
2024-03-27 09:54:45 -07:00
Kristiyan Kostadinov
6b725c9dfd refactor(compiler-cli): expand type of initializer parsing function (#54981)
Updates the function that parses initializer APIs to check any `Expression`, instead of expecting a class member. This will be useful for the upcoming changes.

PR Close #54981
2024-03-27 09:54:45 -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
Kristiyan Kostadinov
8997837f3c refactor(compiler): pass default content to projection instruction (#54854)
Updates the code that generates the `projection` instruction to pass the template function containing the default content into it.

PR Close #54854
2024-03-26 09:17:58 -07:00
Paul Gschwendtner
e53e36bba9 refactor(compiler-cli): support ignoring specific doc entries during extraction (#54925)
This commit adds support for ignoring specific doc entries when
extracting doc entries. This allows us to drop e.g. `InputFunction` from
the API docs, given that the `input` API entry holds all the relevant
information.

`InputFunction` only exists for type purposes in the `.d.ts`.

PR Close #54925
2024-03-26 09:17:21 -07:00
Paul Gschwendtner
72adf0dac7 refactor(core): improve API documentation for input after angular.dev support (#54925)
This commit improves the API documentation for `input` after
we added support for initializer APIs in angular.dev docs generation.

Changes:

- Rename `ReadT` to `T`. This conceptually makes it easy to talk about
  inputs of type `T` if there is no transform involved. The common case.
- Rename `WriteT` to `TransformT`. This makes it clear that this is the
  type that the "transform" needs to handle.
- Improves the "overall" description of the input function so that it
  can be shown as a general overview for the API site.
- Improves usage notes to be a little more helpful, yielding more useful
  content in the API docs usage notes section.
- Add short JSDoc description for each individual overload.

PR Close #54925
2024-03-26 09:17:20 -07:00
Paul Gschwendtner
5672c6442c refactor(compiler-cli): support extracting initializer API functions (#54925)
This commit adds support for extracting initializer API functions.
Initialixer API functions are functions conceptually that can are
intended to be used as class member initializers.

Angular started introducing a few of these for the new signal
APIs, like `input`, `model` or signal-based queries.

These APIs are currently confusingly represented in the API docs because
the API extraction:

- does not properly account for call signatures of interfaces
- does not expose information about sub-property objects and call
  signatures (e.g. `input.required`)
- the docs rendering syntax highlighting is too bloated and confusing
  with all types being included.

This commit adds support for initializer API functions, namely two
variants:

- interface-based initializer APIs. e.g. `export const input:
  InputFunction`- which is a pattern for `input` and `input.required`.
- function-based simpler initializer APIs with overloads. e.g.
  `contentChildren` has many signatures but doesn't need to be an
  interface as there are no sub-property call signatures.

PR Close #54925
2024-03-26 09:17:20 -07:00
Kristiyan Kostadinov
5bd188a394 feat(compiler-cli): add partial compilation support for deferred blocks (#54908)
Builds on top of the previous changes to add support for deferred blocks during partial compilation. To do this, the following changes had to be made:
* The metadata passed into `ɵɵngDeclareComponent` has an additional field called `deferBlockDependencies` which has an array of the dependency loading functions for each defer block in the template. During linking, the dependency functions are loaded by matching their template index to the index in the `deferBlockDependencies` array.
* There's a new `ɵɵngDeclareClassMetadataAsync` function that is created for components that have deferred dependencies. It gets transpiled to `setClassMetadataAsync` and works in the same way by capturing a dependency loading function and setting the metadata after the dependencies are resolved. It also has some extra fields for capturing the version which are standard in linker-generated code.
* Deferred import statements are now stripped in partial compilation mode, similar to full compilation.

PR Close #54908
2024-03-21 22:15:32 -07:00
Kristiyan Kostadinov
ffa217eabd refactor(compiler-cli): add method for extracting function parameters (#54908)
Updates the linker's AST host to add the ability to extract a function's parameters. This will be required for the next commits.

PR Close #54908
2024-03-21 22:15:30 -07:00
Kristiyan Kostadinov
102688bf83 refactor(compiler): widen type of resolver function (#54908)
Updates the type of the resolver function to be any `Expression` since JIT may receive a function reference rather than a `ArrowFunctionExpr`.

PR Close #54908
2024-03-21 22:15:30 -07:00
Kristiyan Kostadinov
fc13144ef9 refactor(compiler-cli): exit early when checking content projection (#54921)
Updates the logic that detects if a node should be checked for control flow content projection to exit as soon as it detects a second root node, instead of counting the total and then checking if it's more than one.

PR Close #54921
2024-03-21 22:14:17 -07:00
Kristiyan Kostadinov
a369f43fbd fix(compiler): capture switch block cases for content projection (#54921)
Captures the individual cases in `switch` blocks for content projection purposes.

PR Close #54921
2024-03-21 22:14:17 -07:00
Kristiyan Kostadinov
7fc7f3f05f fix(compiler): capture all control flow branches for content projection in if blocks (#54921)
Previously only the first branch of an `if` block was captured for content projection. This was done because of some planned refactors in the future. Since we've decided not to apply those refactors to conditionals, these changes update the compiler to capture each branch individually for content projection purposes.

PR Close #54921
2024-03-21 22:14:16 -07:00
Kristiyan Kostadinov
eb625d3783 fix(compiler): declare for loop aliases in addition to new name (#54942)
Currently when aliasing a `for` loop variable with `let`, we replace the variable's old name with the new one. Since users have found this to be confusing, these changes switch to a model where the variable is available both under the original name and the new one.

Fixes #52528.

PR Close #54942
2024-03-21 22:13:14 -07:00
Kristiyan Kostadinov
bfd0bd574e fix(compiler): invoke method-based tracking function with context (#54960)
Previously we assumed that if a `for` loop tracking function is in the form of `someMethod($index, $item)`, it will be pure so we didn't pass the parameter to bind the context to it. This appears to be risky, because we don't know if the method is trying to access `this`.

These changes play it safe by always binding method-based tracking functions.

Fixes #53628.

PR Close #54960
2024-03-21 22:08:40 -07:00
Kristiyan Kostadinov
b02b31a915 feat(compiler-cli): drop support for TypeScript older than 5.4 (#54961)
Drops support for TypeScript versions older than 5.4.

BREAKING CHANGE:
* Angular no longer supports TypeScript versions older than 5.4.

PR Close #54961
2024-03-21 22:07:45 -07:00
Andrew Scott
7b070c30c2 ci: temporarily disable failing test (#54970)
this test is failing after #54711

PR Close #54970
2024-03-20 13:31:23 -07:00
Alex Rickabaugh
6aff144232 fix(compiler-cli): symbol feature detection for the compiler (#54711)
Use the actual symbol presence in the .d.ts to detect whether two-way
binding to writable signals should be template type-checked.

PR Close #54711
2024-03-20 12:14:41 -07:00
Angular Robot
353eae5d82 build: update babel dependencies to v7.24.1 (#54933)
See associated pull request for more information.

PR Close #54933
2024-03-19 17:01:29 +00:00
Paul Gschwendtner
5a63a475fb test(compiler-cli): add unit tests for output() JIT transform (#54841)
We are already testing the JIT transforms via integration tests, but
this commit adds dedicated unit tests for the transform behavior for
proper test coverage (planned follow-up).

PR Close #54841
2024-03-15 15:14:32 -07:00
Kristiyan Kostadinov
879bd80b57 fix(compiler): capture data bindings for content projection purposes in blocks (#54876)
Fixes a regression in the template pipeline where data bindings weren't being captured for content projection purposes.

Fixes #54872.

PR Close #54876
2024-03-15 15:11:19 -07:00
Chinthoorie
b961075f92 refactor(compiler-cli): move DelegatingPerfRecorder initialization into constructor (#54834)
Move the initialization of class field `DelegatingPerfRecorder` into the constructor.

This fixes the error : `TypeError: Cannot read properties of undefined (reading 'eventCount')`

This is blocking the roll-out of public class.

PR Close #54834
2024-03-15 15:10:46 -07:00
Paul Gschwendtner
d01576b104 refactor(compiler-cli): properly preserve file overview comments (#54819)
This commit updates the logic for preserving file overview comments
to be more reliable and less dependent on previous transforms.

Previously, with the old import manager, we had a utility called
`addImport` that always separated import statements and non-import
statements. This meant that the non-emitted statement from Tsickle
for the synthetic file-overview comments no longer lived at the
beginning of the file.

`addImports` tried to overcome this by adding another new non-emitted
statement *before* all imports. This then was later used by the
transform (or was assumed!) to attach the synthetic file overview
comments if the original tsickle AST Node is no longer at the top.

This logic can be improved, because the import manager shouldn't need to
bother about this fileoverview non-emitted statement, and the logic for
re-attaching the fileoverview comment should be local. This commit fixes
this and makes it a local transform.

PR Close #54819
2024-03-15 15:09:41 -07:00