8355 Commits

Author SHA1 Message Date
Alex Castle ae34dbca1b feat(common): Backport NgOptimizedImage to v13
Backport the image optimization features from verion 15 to version 13
2023-04-06 11:26:25 -06:00
Andrew Kushnir 4ea399a6d7 docs(core): add an error details page for unsafe <iframe> bindings (#48027) (#48029)
PR Close #48027

PR Close #48029
2022-11-21 12:21:06 -08:00
Andrew Kushnir b1d7b79ff4 fix(core): hardening attribute and property binding rules for <iframe> elements (#48029)
This commit updates the logic related to the attribute and property binding rules for <iframe> elements. There is a set of <iframe> attributes that may affect the behavior of an iframe and this change enforces that these attributes are only applied as static attributes, making sure that they are taken into account while creating an <iframe>.

If Angular detects that some of the security-sensitive attributes are applied as an attribute or property binding, it throws an error message, which contains the name of an attribute that is causing the problem and the name of a Component where an iframe is located.

BREAKING CHANGE:

Existing iframe usages may have security-sensitive attributes applied as an attribute or property binding in a template or via host bindings in a directive. Such usages would require an update to ensure compliance with the new stricter rules around iframe bindings.

PR Close #48029
2022-11-21 12:21:06 -08:00
Andrew Scott 94c2cfbe25 docs(router): Adjust example for scrollPositionRestoration (#46201)
This makes a small update to the example so that it shows a use-case
that's not already covered by the 'enabled' option. The existing example
would get identical behavior to `scrollPositionRestoration: 'enabled'`
with `anchorScrolling: 'enabled'`.

The updated example shows a use-case for when custom scrolling _would_
be needed. For example, when data is fetched because it is not available
immediately or through a resolver. This is one of the cases described in #24547

This update is sufficient to address all of the documentation problems
noted in the aforementioned issue. Another fix should be made to address
the problem that scroll restoration needs to be delayed until after CD
has run so the update block of the activated component's template is
run.

PR Close #46201
2022-06-01 11:06:52 -07:00
dario-piotrowicz 4a7e724238 refactor(compiler-cli): fix "for to" typo in code comment (#46113)
fix the typo/extra for in a code comment saying
"this is used for to determine" so that it only says
"this is used to determine"

PR Close #46113
2022-05-24 10:52:18 -07:00
dario-piotrowicz c58e925f4e docs: make structural directives guide generic (#44895)
tweak the current structural directives guide (currently mainly targeted
at the creation of custom structural directives) so that is more generic
and a point of reference for structural directives in general

this also includes the re-addition of the one-per-element section
removed in PR #40015

resolves #44786

PR Close #44895
2022-05-23 13:44:42 -07:00
Andrew Scott b4eb9ed884 fix(language-service): Prevent TSServer from removing templates from project (#45965)
As part of the `updateProjectIfDirty` process and inside `updateNonInferredProjectFiles`
TS Server will remove the template files that we added as roots in
`readResource`.
https://sourcegraph.com/github.com/microsoft/TypeScript@c300fea3250abd7f75920d95a58d9e742ac730ee/-/blob/src/server/editorServices.ts?L2363

The external files are added to the list here so ensuring that the
templates are included in the `getExternalFiles` will prevent this from
happening
https://sourcegraph.com/github.com/microsoft/TypeScript@c300fea3250abd7f75920d95a58d9e742ac730ee/-/blob/src/server/editorServices.ts?L2395:18

PR Close #45965
2022-05-12 09:25:20 -07:00
Andrew Scott 5ca3bcf4f8 fix(language-service): Add resource files as roots to their associated projects (#45601)
When an external template is read, adds the template file to to the project which contains.
This is necessary to keep the projects open when navigating away from HTML files.
Since a `tsconfig` cannot express including non-TS files,
we need another way to indicate the template files are considered part of the project.

Note that this does not ensure that the project in question _directly_ contains the component
file. That is, the project might just include the component file through the program rather
than directly in the `include` glob of the `tsconfig`. This distinction is somewhat important
because the TypeScript language service/server prefers projects which _directly_ contain the TS
file (see `projectContainsInfoDirectly` in the TS codebase). What this means it that there can
possibly be a different project used between the TS and HTML files.

For example, in Nx projects, the referenced configs are `tsconfig.app.json` and
`tsconfig.editor.json`. `tsconfig.app.json` comes first in the base `tsconfig.json` and
contains the entry point of the app. `tsconfig.editor.json` contains the `**.ts` glob of all TS
files. This means that `tsconfig.editor.json` will be preferred by the TS server for TS files
but the `tsconfig.app.json` will be used for HTML files since it comes first and we cannot
effectively express `projectContainsInfoDirectly` for HTML files.

We could consider also updating the language server implementation to attempt
to select the project to use for the template file based on which project
contains its component file directly, using either the internal `project.projectContainsInfoDirectly`
or as a workaround, check `project.isRoot(componentTsFile)`.

Finally, keeping the projects open is hugely important in the solution style config case like
Nx. When a TS file is opened, TypeScript will only retain `tsconfig.editor.json` and not
`tsconfig.app.json`. However, if our extension does not also know to select
`tsconfig.editor.json`, it will automatically select `tsconfig.app.json` since it is defined
first in the `tsconfig.json` file. So we need to teach TS server that we are (1) interested in
keeping projects open when there is an HTML file open and (2) optionally attempt to do this
_only_ for projects that we know the TS language service will prioritize in TS files (i.e.,
attempt to only keep `tsconfig.editor.json` open and allow `tsconfig.app.json` to close)
and prioritize that project for all requests.

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

PR Close #45601
2022-05-10 09:36:28 -07:00
JoostK 73bbee2c0d perf(core): allow checkNoChanges mode to be tree-shaken in production (#45936)
This commit guards all logic that exists for the `checkNoChanges` mode
with `ngDevMode` checks such that the logic can be tree-shaken.

PR Close #45936
2022-05-09 13:24:41 -07:00
Paul Gschwendtner 09280257a2 build: clean up references to old master branch (#45890)
Cleans up all references to the `master` branch we renamed to
`main` across Angular.

PR Close #45890
2022-05-05 10:53:13 -07:00
Ryan Day e59ed8ca14 build(bazel): change ngc-wrapped to use new bazelOpts.devmode (#45804)
bazelOpts.es5Mode is being removed and replaced with devmode. Adding a
check for either will allow a smooth migration.

PR Close #45804
2022-05-02 13:10:07 -07:00
Joey Perrott 63398e0eb4 fix(bazel): add this_is_bazel marker (#45728)
Add marker for noting that this check confirms we are running in a bazel environment.

PR Close #45728
2022-04-22 12:46:24 -07:00
Paul Gschwendtner 1d204fcf2c Revert "test(common): Fix flaky Location test (#45683)" (#45691)
This reverts commit 254d6cea9a.

This test has only been introduced in the next branch with
https://github.com/angular/angular/pull/44901. The cherry-pick
of the flaky test fix does not work in the patch branch due to
some other missing changes and the test did not exist in 13.3.x
anyway.

PR Close #45691
2022-04-20 08:58:46 -07:00
Andrew Scott 254d6cea9a test(common): Fix flaky Location test (#45683)
This test has proven to be flaky. This commit greatly simplifies the
test and moves it to a more appropriate location (pun intended).

PR Close #45683
2022-04-19 20:17:56 -07:00
Andrew Kushnir ed832b4dd7 test: reset counters before running a styling test (#45670)
This commit updates one of the styling tests to reset perf counters, making it order-independent and non-flaky (previously the test got random failures depending on whether there are other tests invoked before).

PR Close #45670
2022-04-19 09:14:10 -07:00
Kristiyan Kostadinov 9317f513d5 fix(core): better error message when directive extends a component (#45658)
We throw an error when a directive is trying to extend a component, but we don't actually say which class is responsible which can be difficult to track down. These changes add the two class names to the error message.

PR Close #45658
2022-04-18 09:24:24 -07:00
ivanwonder d68333e508 fix(language-service): two-way binding completion should not remove the trailing quote (#45582)
We allow the path to contain both the `t.BoundAttribute` and `t.BoundEvent` for two-way
bindings but do not want the path to contain both the `t.BoundAttribute` with its
children when the position is in the value span because we would then logically create a path
that also contains the `PropertyWrite` from the `t.BoundEvent`. This early return condition
ensures we target just `t.BoundAttribute` for this case and exclude `t.BoundEvent` children.

Fixes https://github.com/angular/vscode-ng-language-service/issues/1626

PR Close #45582
2022-04-15 13:53:49 -07:00
Andrew Kushnir 4766817f02 fix(core): improve multiple components match error (#45645)
This commit improves the error message that is thrown at runtime when multiple components match the same element. Now the error message contains names of classes that represent those components.

PR Close #45645
2022-04-15 13:52:20 -07:00
Andrew Kushnir 575cafc163 test(core): add a test for multiple named interpolations with the same name (#45651)
The test from this commit verifies that i18n logic can handle multiple named interpolations with the same name.

PR Close #45651
2022-04-15 13:51:56 -07:00
Andrew Kushnir ec115a31b8 refactor(core): avoid referencing PlatformRef in bootstrap code (#45519)
This commit updates an existing bootstrap logic to avoid referencing the `PlatformRef` instance to keep track of the platform status. Instead, we use platform injector, so that the `PlatformRef`can be tree-shaken away in the bootstrap logic for Standalone Components.

The motivation for this change is that retaining the `PlatformRef` class also retains NgModule-based bootstrap code, which would not be needed in case of Standalone Components.

PR Close #45519
2022-04-13 15:34:48 -07:00
Kristiyan Kostadinov e50fd9ee87 fix(compiler): avoid errors with extremely long instruction chains (#45574)
Our logic for generating code from an AST uses recursion which limits the number of expressions we can nest before we reach the call stack limit. These changes add a limit in order to avoid errors in some cases where the chains become extremely long.

Fixes #45564.

PR Close #45574
2022-04-13 16:18:56 +00:00
Andrew Kushnir fc145d024b refactor(core): make ComponentFactoryResolver lazily instantiated in ApplicationRef (#45507)
This commit removes the `ComponentFactoryResolver` as a constructor argument of the `ApplicationRef` class. This makes it lazily instantiated + simplifies further refactoring in a context of Standalone Components.

PR Close #45507
2022-04-12 22:29:17 +00:00
Andrew Kushnir 44b9d89917 refactor(core): make platform core providers tree-shakable (#45506)
This commit refactors the set of hardcoded platform core providers into tree-shakable providers.
In addition to making them tree-shakable, this would also avoid the need to rely on the platform creation logic in an upcoming bootstrap logic for Standalone Components.

PR Close #45506
2022-04-12 22:28:24 +00:00
Joe Martin (Crowdstaffing) 61894570f1 docs: improve markdown (#45590)
improve markdown for documentation. Duplicate of #45325 that targets 13.3.x.

PR Close #45590
2022-04-11 22:35:01 +00:00
Renovate Bot 09c5c18c7d build: update dependency google-closure-compiler to v20220405 (#45568)
PR Close #45568
2022-04-11 16:26:26 +00:00
Cédric Exbrayat 208d81921d refactor(core): validate property (#45528)
Simplifies and documents the `validateProperty` function (in a similar fashion that #45492 simplified `validateElementIsKnown`).

PR Close #45528
2022-04-07 22:03:13 +00:00
Hossein Mousavi dbd6e75b37 docs(forms): remove the incorrect set value from previous commit (#45533)
in the validators documentation, the value for the formControl for both required and requiredTrue validators is an empty string. This is OK for required since it gives us an error. But I think if we set the value of formControl responsible for requiredTrue to something other than an empty string (e.g.: 'some value'), it would demonstrate the difference between required and requiredTrue better.

PR Close #45533
2022-04-07 21:00:26 +00:00
Hossein Mousavi 6a5ee688df docs(forms): add value to formControl for better demonstration of requiredTrue validator (#45533)
in the validators documentation, the value for the formControl for both required and requiredTrue validators is an empty string. This is OK for required since it gives us an error. But I think if we set the value of formControl responsible for requiredTrue to something other than an empty string (e.g.: 'some value'), it would demonstrate the difference between required and requiredTrue better.

PR Close #45533
2022-04-07 21:00:26 +00:00
Andrew Kushnir 05121c0381 test(animations): update test to use an object instead of a Map (#45531)
The code in the patch branch is slightly different from the master branch: the master branch contains some changes where Map are used instead of objects in animations. As a result, one of the tests is failing in patch, since it expects Maps, but receives objects.

PR Close #45531
2022-04-05 10:31:48 -07:00
Christoph Guttandin a92bceda54 test(animations): add test for buildAnimationAst() function (#31107)
This commit adds a test for the buildAnimationAst() function.

PR Close #31107
2022-04-05 08:41:40 -07:00
Christoph Guttandin b46b25c562 fix(animations): handle structured AnimateTimings (#31107)
This commit makes sure structured AnimateTimings are not procesed any further when building the AST.

Fixes: #22752

PR Close #31107
2022-04-05 08:41:40 -07:00
Cédric Exbrayat 9fcc1b7758 refactor(core): validate element is known in JIT mode (#45492)
Renames, simplifies and documents the function in charge of validating if an element is known in JIT mode.

PR Close #45492
2022-04-04 09:34:42 -07:00
JoostK 7f53c0f4ac fix(compiler-cli): handle inline type-check blocks in nullish coalescing extended check (#45478)
This commit fixes an inconsistency where a type check location for an inline
type check block would be interpreted to occur in a type-checking shim instead.
This resulted in a missing template mapping, causing a crash due to an unsafe
non-null assertion operator.

In the prior commit the `TcbLocation` has been extended with an `isShimFile`
field that is now being used to look for the template mapping in the correct
location. Additionally, the non-null assertion operator is refactored such
that a missing template mapping will now ignore the warning instead of crashing
the compiler.

Fixes #45413

PR Close #45478
2022-03-30 11:34:41 -07:00
JoostK 3f55567111 refactor(compiler-cli): track whether a TcbPosition corresponds with a shim file (#45478)
Extends `TcbPosition` with a field that indicates whether the `tcbPath` is a
type-checking shim file, or an original source file with an inline type check
block.

This field is used in an upcoming commit that fixes an inconsistency with how
inline type check blocks are incorrectly interpreted as a type-checking shim
file instead.

PR Close #45478
2022-03-30 11:34:41 -07:00
JoostK fa90c74a73 refactor(compiler-cli): rename ShimLocation to TcbLocation (#45478)
Inline type check blocks (TCBs) are emitted into the original source file, but
node positions would still be represented as a `ShimLocation` with a `shimPath`
corresponding with the type-checking shim file. This results in inconsistencies,
as the `positionInShimFile` field of `ShimLocation` would not correspond with
the `shimPath` of that `ShimLocation`.

This commit is a precursor to letting `ShimLocation` also represent the correct
location for inline type check blocks, by renaming the interface to
`TcbLocation`. A followup commit addresses the actual inconsistency.

PR Close #45478
2022-03-30 11:34:41 -07:00
Paul Gschwendtner 63539489da test: update api goldens to reflect api-golden bazel rule change (#45469)
The API golden Bazel rule has changed in the shared dev-infra code. Instead
of putting golden API reports into the golden folder as per their original
location in the NPM package, golden reports are now stored based on the
package exports. This makes it more obvious how entry-points are consumable

As part of this change, since the API golden rule now consutls the NPM package
`exports` field, the `localize/tools` entry-point golden file is now generated.

Previously it wasn't generated due to it not having a secondary entry-point
`package.json` file. Such package json files should not be needed anymore
and will be gone in future APF versions.

PR Close #45469
2022-03-29 13:13:08 -07:00
JiaLiPassion c08705899f fix(zone.js): should ignore multiple resolve call (#45283)
Close #44913

The following case is not handled correctly by `zone.js`.
```
const delayedPromise = new Promise((resolve) => {
  setTimeout(resolve, 1, 'timeout');
});

new Promise((resolve) => {
  resolve(delayedPromise);
  resolve('second call');
}).then(console.log);
```

It should output `timeout`, since the promise is resolved by the
1st resolve, the `second call` should be ignored.

So this is a bug that the original implementation not ensure the
`resolve` is only called once.

PR Close #45283
2022-03-25 17:31:04 -07:00
arturovt 0dd532bcd6 fix(zone.js): swallow the error when the element callback is not patchable (#45400)
The `patchCallbacks` is used for patching the `document.registerElement` and
`customElements.define`. We explicitly wrap the patching code into try-catch since
callbacks may be already patched by other web components frameworks (e.g. LWC), and they
make those properties non-writable. This means that patching callback will throw an error
`cannot assign to read-only property`. See this code as an example:
https://github.com/salesforce/lwc/blob/master/packages/@lwc/engine-core/src/framework/base-bridge-element.ts#L180-L186
We don't want to stop the application rendering if we couldn't patch some
callback, e.g. `attributeChangedCallback`.

PR Close #42546

PR Close #45400
2022-03-25 16:31:10 -07:00
Paul Gschwendtner 88dbeda931 build: shorten partial compilation test case target names for windows (#45443)
Shortens the partial compilation test case target names as the paths/
manifest paths in Bazel became too large, exceeding some Windows path
length limits.

Relevant context/resources:
* https://angular-team.slack.com/archives/C02PARQNMC1/p1648137933069659 (internal)
* https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd
* https://github.com/bazelbuild/rules_nodejs/pull/3215/files#r782271592

PR Close #45443
2022-03-25 13:45:08 -07:00
Paul Gschwendtner c24ea4b4f5 test: refactor compiler-cli compliance test to work on windows (#45443)
Recent changes in `rules_nodejs` caused the test case copy file actions
to be transitioned into the `exec` configuration, resulting in much larger
file paths. These paths break on Windows with the shell argument limit, and
with the path limit, causing errors like:

```
ERROR: C:/users/circleci/ng/packages/compiler-cli/test/compliance/test_cases/BUILD.bazel:9:12: Copying file packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/value_composition/structural_directives_if_directive_def.js failed: (Exit 1): cmd.exe failed: error executing command
  cd /d C:/users/circleci/_bazel_circleci/u4uoan2j/execroot/angular
  SET PATH=C:\Program Files\Git\usr\bin;C:\Program Files\Git\bin;C:\Windows;C:\Windows\System32;C:\Windows\System32\WindowsPowerShell\v1.0
    SET RUNFILES_MANIFEST_ONLY=1
  cmd.exe /C bazel-out\x64_windows-opt-exec-2B5CBBC6\bin\packages\compiler-cli\test\compliance\test_cases\test_cases--1973427149-cmd.bat
The system cannot find the path specified
```

https://app.circleci.com/pipelines/github/angular/angular/44038/workflows/4b530cb2-f232-4e1d-b35a-e6e085151d08/jobs/1140017

PR Close #45443
2022-03-25 13:45:07 -07:00
Paul Gschwendtner 3f5e685ca9 refactor: remove unused variables in starlark code to satisfy buildifier (#45443)
We updated buildifier and a few warnings became errors now. This commit
cleans up the failing unused variable instances, making the linter happy.

Additionally for the API extractor BUILD file, the package defaults
need to move to satisfy buildifier.

PR Close #45443
2022-03-25 13:45:07 -07:00
Paul Gschwendtner 69e4c9813e build: migrate more usages from @bazel/typescript to @bazel/concatjs (#45443)
As mentioned in previous commits (check them for more details), `@bazel/typescript`
no longer contains `ts_library`-specific code, so we no longer need that dependency.

PR Close #45443
2022-03-25 13:45:07 -07:00
Paul Gschwendtner 1eaaa5d1cc refactor(bazel): update api-extractor to account for @bazel/typescript change (#45443)
`@bazel/typescript` code moved to `@bazel/concatjs` for the tsc-wrapped code.

Note that this code is likely going to be removed anyway soon when we
move dts bundling from `ng_module` to `ng_package`.

PR Close #45443
2022-03-25 13:45:07 -07:00
Paul Gschwendtner 1a149bb50d refactor(bazel): update ngc-wrapped to account for tsc-wrapped move to @bazel/concatjs (#45443)
Previously `tsc-wrapped` which is the foundation for `ngc-wrapped`, resided
in `@bazel/typescript`. It has been moved to `@bazel/concatjs` in rules_nodejs
so we need to account for that as part of our rules_nodejs v5 update.

PR Close #45443
2022-03-25 13:45:07 -07:00
Renovate Bot 29d4b78ada build: update bazel (#45443)
Update `@bazel` packages to the latest 5.x version.

Some of the changes here are modeled after
angular/dev-infra@40c0ac8559.

Co-Authored-By: George Kalpakas <kalpakas.g@gmail.com>

PR Close #45443
2022-03-25 13:45:06 -07:00
arturovt dbd6be829f fix(zone.js): read Symbol.species safely (#45369)
We must read `Symbol.species` safely because `this` may be anything. For instance, `this`
may be an object without a prototype (created through `Object.create(null)`); thus
`this.constructor` will be undefined. One of the use cases is SystemJS creating
prototype-less objects (modules) via `Object.create(null)`. The SystemJS creates an empty
object and copies promise properties into that object (within the `getOrCreateLoad`
function). The zone.js then checks if the resolved value has the `then` method and invokes
it with the `value` context. Otherwise, this will throw an error: `TypeError: Cannot read
properties of undefined (reading 'Symbol(Symbol.species)')`.

PR Close #45369
2022-03-24 18:56:37 -07:00
arturovt 2b0da62937 fix(zone.js): check if process is defined when patching the GlobalErrors.install (#45392)
Jasmine checks internally if `process` and `process.on` is defined. Otherwise,
it installs the browser rejection handler through the `global.addEventListener`.
This code may be run in the browser environment where `process` is not defined, and
this will lead to a runtime exception since Webpack 5 removed automatic Node.js polyfills.

PR Close #42260

PR Close #45392
2022-03-24 10:52:35 -07:00
Paul Gschwendtner 960e42b2ac fix(bazel): ng module compilation workers are subject to linker race-conditions (#45393)
The Bazel NodeJS rules provide two ways of accessing node modules:

* A linker which creates a `node_modules` directory in the execroot/or in the runfiles.
* A patched module resolution where no node modules directory necessarily needs to exist.

The first is the default in `rules_nodejs` and the second is technically the most idiomatic
resolution mechanism in Bazel (as it matches with a runfile resolution library).

The linker is prone to race conditions in persistent workers, or non-sandbox environments (like
windows). This is because the linker for all workers will operate on a shared `execroot` directory
and the same `node_modules` directory is modified all the time / potentially conflicting with other
linker processes from other concurrently-running workers.

We rely on the patched module resolution anyway, but just need to disable the unused linker to avoid
issues like the following:

```
---8<---8<--- Start of log, file at /private/var/tmp/_bazel_splaktar/280f06d55552a0d01f89f0955b5acd78/bazel-workers/worker-8-TypeScriptCompile.log ---8<---8<---
[link_node_modules.js] An error has been reported: [Error: ENOENT: no such file or directory, unlink 'node_modules'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'unlink',
  path: 'node_modules'
} Error: ENOENT: no such file or directory, unlink 'node_modules'
---8<---8<--- End of log ---8<---8<---
INFO: Elapsed time: 12.796s, Critical Path: 5.39s
INFO: 645 processes: 477 internal, 12 darwin-sandbox, 156 worker.
```

PR Close #45393
2022-03-24 10:52:13 -07:00
Mike cc90fd55b2 docs(router): Fix typo on segments (#45411)
PR Close #45411
2022-03-24 10:49:36 -07:00
JoostK 3714305f84 fix(compiler): scope css rules within @layer blocks (#45396)
This commit starts scoping CSS rules nested within `@layer` blocks.

Fixes #45389

PR Close #45396
2022-03-21 14:51:46 -07:00