7853 Commits

Author SHA1 Message Date
Andrew Kushnir ac284dbe68 docs(core): add an error details page for unsafe <iframe> bindings (#48027)
PR Close #48027
2022-11-21 12:24:37 -08:00
Andrew Kushnir b871db57da fix(core): hardening attribute and property binding rules for <iframe> elements
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.
2022-11-21 12:24:37 -08:00
JoostK 460befd693 fix(ngcc): support element accesses for export declarations (#44824)
Bundlers like Rollup may use an element access expression for an export
declaration, which causes ngcc to ignore those export declarations possibly
resulting in incomplete processing of packages.

Element access syntax may be used when the declared name is not considered
as valid JS identifier, but bundlers may be conservative in determining whether
an identifier can be used (to emit a property access) and opt for a string
literal in an element access instead.

The element access syntax introduces a problem for ngcc, where it wouldn't
consider such export as class declaration, causing them to be skipped. The
ngtsc compiler is implemented with the assumption that all class declarations
use a `ts.Identifier` as name, whereas the element access is using a string
literal for the declared name. This makes it troublesome for ngcc to support
this syntax form in UMD bundles.

To work around the problem, this function transforms these access expressions
into regular property accesses. The source text is parsed to an AST to allow
finding the element accesses in a robust way, after which the affected text
ranges are replaced with property accesses in the original source text.

Closes #44037

PR Close #44824
2022-01-25 14:16:41 -08:00
George Kalpakas b6554d75cd fix(ngcc): correctly resolve UMD dependencies (#44382)
Previously, when processing UMD, ngcc assumed that the `exports`
argument of the CommonJS factory call (if present) would be the first
argument of the call. This is generally true for the supported UMD
formats, but can change if ngcc prepends more imports (and thus factory
arguments) while processing the module. This could lead to errors when
trying to collect dependencies of an already processed module.
(This was accidentally broken in #44245 (commit 2bc3522e16).)

This commit fixes it by not making any assumptions about the position of
an `exports` argument in the CommonJS factory call.

Fixes #44380

PR Close #44382
2021-12-07 08:33:35 -05:00
George Kalpakas a1bd9d7eb1 test(ngcc): use main property in test package.json files for UMD tests (#44245)
Previously, the mock packages created for `UmdDependencyHost`'s tests,
specified the entry-point as `esm2015`. This does not matter in tests,
since the packages are explicitly passed to the `UmdDependencyHost`
(while in reality the appropriate host would be determined based on the
name of the entry-point property - in this case, detecting the
entry-point as ES2015 and not UMD).

However, in order to avoid confusion, this commit updates the test
packages to use `main` (the default property used for the UMD format in
`package.json` files).

PR Close #44245
2021-11-30 17:24:43 +02:00
George Kalpakas a8be244113 fix(ngcc): correctly report error when collecting dependencies of UMD module (#44245)
Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
https://github.com/angular/angular/issues/44019#issuecomment-959954121
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.

PR Close #44245
2021-11-30 17:24:43 +02:00
George Kalpakas ee855b8b73 test(ngcc): run more tests against more supported UMD formats (#44245)
This commit utilizes the infrastructure added in the previous commit to
run more tests against more of the supported UMD formats. This shall
give us more confidence that all aspects of UMD processing work
correctly with the various formats.

PR Close #44245
2021-11-30 17:24:43 +02:00
George Kalpakas 6b1a69e583 test(ngcc): use helper function for generating UMD modules for tests (#44245)
Previously, several ngcc test suites used their own helper to generate
test UMD modules.

This commit switches to using the same helper for generating UMD modules
across test suites. This improves DRYness (ensuring changes/fixes to the
UMD format need only be applied once) and makes it easier to test
different UMD formats in all test suites.

PR Close #44245
2021-11-30 17:24:43 +02:00
George Kalpakas fc072935ee fix(ngcc): support the UMD wrapper function format emitted by Webpack (#44245)
Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes #44019

PR Close #44245
2021-11-30 17:24:43 +02:00
George Kalpakas 2e31f92a69 refactor(ngcc): make it easy to support more UMD wrapper function formats (#44245)
Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup. However, this failed to account for a different format, using
`if/else` statements, such as the one [emitted by Webpack][1].

This commit prepares ngcc for supporting different UMD wrapper function
formats by decoupling the operation of parsing the wrapper function body
to capture the various factory function calls and that of operating on
the factory function calls (for example, to read or update their
arguments). In a subsequent commit, this will be used to add support for
the Webpack format.

[1]: https://webpack.js.org/configuration/output/#type-umd

PR Close #44245
2021-11-30 17:24:42 +02:00
Pete Bacon Darwin e3db0385b6 fix(compiler): ensure that partially compiled queries can handle forward references (#44124)
When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907

PR Close #44124
2021-11-16 09:50:05 -08:00
Pete Bacon Darwin 8354e23e9a refactor(compiler): rename R3ProviderExpression and associated helpers (#44124)
This interface will be used in other situations so this change renames it to be more general as `MaybeForwardRefExpression`.

PR Close #44124
2021-11-16 09:50:04 -08:00
JoostK 656f574962 refactor(compiler-cli): extract error documentation base url into separate file (#43965)
Prior refactorings caused unexpected g3 sync issues due to a patch that
changes the error documentation URL. This commit moves the base url into
a separate file to make this more apparent.

PR Close #43965
2021-11-02 16:38:54 -07:00
JoostK 9a89db790f fix(compiler-cli): avoid broken references in .d.ts files due to @internal markers (#43965)
The `ErrorCode` enum in the `error_code.ts` file is governed by public
api guards but the other top-level exports from that file are exempt
from public api documentation and are therefore marked as `@internal`.
However, TypeScript is configured with the `stripInternal` compiler
option such that declarations with `@internal` markers are not emitted
into the `.d.ts` files, but this means that the reexports in the barrel
file end up referring to missing declarations.

The `stripInternal` option is considered internal and its documentation
states to use at your own risk (as per https://github.com/microsoft/TypeScript/issues/45307).
Having the option enabled is desirable for us as it works well for
hiding class fields that are marked `@internal`, which is an effective
way to hide members from the .d.ts file. As a workaround for the issue
with top-level symbols, the declarations with `@internal` markers are
moved to dedicated files for which no public api guard is setup,
therefore allowing their `@internal` markers to be dropped.

Fixes #43097

PR Close #43965
2021-11-02 16:38:54 -07:00
Jochen Kraushaar 25959f9e14 docs(common): describe behavior when reference changes (#42863)
PR Close #42863
2021-10-28 11:34:24 -07:00
vthinkxie 8f402c9d06 fix(core): support InjectFlags argument in NodeInjector.get() (#41592)
The `InjectFlags` argument was defined for both `getOrCreateInjectable()` and `Injector`, but was ignored in `NodeInjector`.
This PR adds support for getting parent token via `NodeInjector.get()`.

close #31776

PR Close #41592
2021-10-28 11:20:00 -07:00
Jessica Janiuk e25ebb6058 Revert "fix(compiler-cli): avoid broken references in .d.ts files due to @internal markers" (#43961)
This reverts commit 69821fcef6.

PR Close #43961
2021-10-26 23:51:22 +00:00
Jessica Janiuk 728926412d Revert "refactor(compiler-cli): extract error documentation base url into separate file" (#43961)
This reverts commit bd5acf60f2.

PR Close #43961
2021-10-26 23:51:22 +00:00
Jessica Janiuk 2d9d270ed8 Revert "fixup! refactor(compiler-cli): extract error documentation base url into separate file" (#43961)
This reverts commit 3d82d566d2.

PR Close #43961
2021-10-26 23:51:21 +00:00
JoostK bf59401473 refactor(compiler-cli): extract error documentation base url into separate file (#43527)
Prior refactorings caused unexpected g3 sync issues due to a patch that
changes the error documentation URL. This commit moves the base url into
a separate file to make this more apparent.

PR Close #43527
2021-10-26 18:22:33 +00:00
JoostK 112557497c fix(compiler-cli): avoid broken references in .d.ts files due to @internal markers (#43527)
The `ErrorCode` enum in the `error_code.ts` file is governed by public
api guards but the other top-level exports from that file are exempt
from public api documentation and are therefore marked as `@internal`.
However, TypeScript is configured with the `stripInternal` compiler
option such that declarations with `@internal` markers are not emitted
into the `.d.ts` files, but this means that the reexports in the barrel
file end up referring to missing declarations.

The `stripInternal` option is considered internal and its documentation
states to use at your own risk (as per https://github.com/microsoft/TypeScript/issues/45307).
Having the option enabled is desirable for us as it works well for
hiding class fields that are marked `@internal`, which is an effective
way to hide members from the .d.ts file. As a workaround for the issue
with top-level symbols, the declarations with `@internal` markers are
moved to dedicated files for which no public api guard is setup,
therefore allowing their `@internal` markers to be dropped.

Fixes #43097

PR Close #43527
2021-10-26 18:22:33 +00:00
amayer42 5e482c4f0c docs(localize): fix spelling of documentation link (#43941)
Fixes the spelling of 'i18n' in a documentation link.
PR Close #43941
2021-10-25 22:05:17 +00:00
Andrew Kushnir c831c67c00 test(platform-browser): complete component bootstrap before switching to the next test (#43933)
The bootstrap tests that reused the same component (the `HelloRootCmp` one) were randomly failing due to the incomplete cleanup between tests. This commit ensures that the component bootstrap is fully cimpleted and there are no pending async actions before going to the next test.

PR Close #43933
2021-10-25 17:58:26 +00:00
George Kalpakas 067ae54d46 fix(ngcc): support alternate UMD layout when adding new imports (#43931)
In #43879, `UmdReflectionHost` was updated to deal with the new UMD
format used by Rollup, where the parenthesis is around the wrapper
function and not the wrapper function call.
For reference, this caused failures in the `ngcc-validation` repo
([example 1][1], [example 2][2]).

This commit updates `UmdRenderingFormatter` to also handle both UMD
formats. In order to validate the change, this commit also updates the
`UmdRenderingFormatter` tests to run against both UMD formats.

[1]: https://circleci.com/gh/angular/ngcc-validation/65916
[2]: https://circleci.com/gh/angular/ngcc-validation/65758

PR Close #43931
2021-10-25 17:56:27 +00:00
ericcheng2005 7817892684 refactor(core): made comment structure consistent in index.ts (#43684)
changed second big block of comments to use multi-line comment structure instead of multiple single-line comments

PR Close #43684
2021-10-21 18:39:59 +00:00
George Kalpakas e09556fe2b refactor(service-worker): avoid unnecessary writes to cache when version fails (#43680)
When an app version is detected as broken, the SW calls the
`Driver#versionFailed()` method. Previously, this method would in turn
call the `Driver#sync()` method, which writes some metadata about the
SW's state to the `ngsw:/:db:contol` cache. More specifically,
`Driver#sync()` persists info about all known app versions, which one is
the latest and also what version each client is assigned to.

However, no relevant info is changed inside `Driver#versionFailed()`, so
the call to `Driver#sync()` is redundant (since there are no changes
that need to be synced with the cache). This is a left-over from
before #43518, when `Driver#versionFailed()` used to update version
assignments and thus did require synchronization with the cache.

This commit removes the redundant `Driver#sync()` call to avoid an
unnecessary write to the cache.

PR Close #43680
2021-10-21 14:20:51 +00:00
Pete Bacon Darwin cab21cea7a fix(ngcc): support alternate wrapper function layout for UMD (#43879)
Recently rollup, used by ng-packagr, changed the position of parentheses
around its generated UMD wrapper functions.

This commit ensures that ngcc can handle both.

Fixes #43870

PR Close #43879
2021-10-18 14:57:01 -07:00
Andrew Kushnir 242a09998a Revert "fix(compiler): support i18n interpolated only attribute bindings (#43815)" (#43882)
This reverts commit bba0a87055.

The reason for rollback: this change is breaking some targets in Google's codebase when there is no attribute value is displayed (attr.aria-label) when translated.

PR Close #43882
2021-10-18 13:15:59 -07:00
George Kalpakas e88ab20119 docs: fix a couple of random typos (#43878)
PR Close #43878
2021-10-18 10:41:33 -07:00
Andrew Scott 58c11865ac fix(router): Do not clear currentNavigation if already set to next one (#43852)
Experimentation with the Router URL management exposed a situation where
the `currentNavigation` was being cleared in the `finalize` after the
`currentNavigation` was already set to the next one.

This change ensures that the `currentNavigation` is only cleared if the
id of the finalized transition matches the one on the
`currentNavigation` object.

PR Close #43852
2021-10-18 10:30:52 -07:00
Pete Bacon Darwin b9c885b960 fix(compiler): support i18n interpolated only attribute bindings (#43815)
While fully dynamic bound properties (and attributes) cannot be marked for localization, properties that only contain interpolation can.

This commit ensure that attribute bindings that only contain interpolation can also be marked for localization.

Closes #43260

PR Close #43815
2021-10-18 09:24:41 -07:00
Joe Martin (Crowdstaffing) 6cc6036fb6 docs: internationalization topics (#43819)
Update links and code-examples.  Remove redundant comments.

PR Close #43819
2021-10-14 15:53:25 -07:00
dario-piotrowicz d050b57478 docs(core): apply minor improvements to the InjectionToken's api docs (#43693)
PR Close #43693
2021-10-13 16:46:27 +00:00
Kristiyan Kostadinov df7fd87084 refactor(language-service): fix typo in method name (#43698)
The `fineRenameLocations` method should be called `findRenameLocations`.

PR Close #43698
2021-10-06 09:21:34 -07:00
George Kalpakas c4ecc07838 fix(service-worker): make ngsw.json generation deterministic and correct (#43679)
Previously, all asset-groups from `ngsw-config.json` were processed in
parallel. For each asset-group, we retrieved all files for the current
build, filtered out files that were already matched by other
asset-groups, determined which of the remaining files belonged to the
current asset-group and generated entries for the `ngsw.json` manifest.
This process was susceptible to race conditions when there were files
that would be matched by multiple asset-groups. This made the generation
of the `ngsw.json` manifest non-deterministic and violated the rule that
each file would belong to the first asset-group that matched it (based
on the asset-groups' order of appearance in `ngsw-config.json`), thus
leading to broken ServiceWorker behavior.

This commit fixes it by ensuring that the generation process is
deterministic and that asset-groups are processed in the proper order.

NOTE 1:
The generation process has been broken since the beginning, but we have
only noticed this recently. This is possibly related to the CLI's
switching from a virtual file system host (which has more consistent
timing characteristics) to the Node.js built-in `fs.promises` in
angular/angular-cli@d3bc530c10.

NOTE 2:
This commit also ensures that files in the `ngsw.json` hash-table are in
alphabetic order. Previously, the files were added to the hash-table in
blocks corresponding to each asset-group.
This change is not necessary (i.e. the order of keys in the hash-table
makes no difference in behavior), but it makes it easier to scan for a
file (for example, for debugging purposes).

PR Close #43679
2021-10-05 13:34:31 -07:00
Wey-Han Liaw 7f6050587d fix(router): unset attachRef when router-outlet is destroyed to avoid mounting a destroyed component (#43697)
Previously, when a router-outlet is conditionally shown with an ngIf, and a sub-route was re-attached
via a custom RouteReuseStrategy, router-outlet would try to mount a destroyed component into the view
if the router-outlet is destroyed and re-initialized.

This commit fixes it by unsetting context.attachRef when router-outlet is destroyed, so when the
router-outlet is being initialized again, it no longer sees an attachRef that it needs to mount to the
view.

Fixes #43696

PR Close #43697
2021-10-05 09:48:41 -07:00
JoostK b4b441077a fix(core): handle invalid constructor parameters in partial factory declarations (#43619)
This commit fixes an oversight in the JIT compilation of partial factory
declarations, where the literal `'invalid'` was not accounted for
(unlike the AOT linker).

Fixes #43609

PR Close #43619
2021-10-01 12:24:31 -04:00
Alex Rickabaugh ca6bcb7d66 Revert "fix(language-service): provide dom event completions (#43299)"
This reverts commit c8f8d7d3b1.

This commit breaks in IE11, which is still supported by v12, likely due to
the usage of `Array.from()`.
2021-09-30 10:15:56 -07:00
Andrew Scott ca0f057491 test(router): refactor tests to not use deprecated loadChildren (#43578)
Many of the tests in the router code use the deprecated loadChildren as a string. This
has been deprecated for years and can easily be changed to just a function that
returns the module.

PR Close #43578
2021-09-29 11:14:09 -07:00
wszgrcy c1338bf837 fix(compiler-cli): correctly interpret token arrays in @Injectable deps (#43226)
When specifying the `deps` array in the `@Injectable` decorator to
inject dependencies into the injectable's factory function, it should
be possible to use an array literal to configure how the dependency
should be resolved by the DI system.

For example, the following example is allowed:

```ts
@Injectable({
  providedIn: 'root',
  useFactory: a => new AppService(a),
  deps: [[new Optional(), 'a']],
})
export class AppService {
  constructor(a) {}
}
```

Here, the `'a'` string token should be injected as optional. However,
the AOT compiler incorrectly used the array literal itself as injection
token, resulting in a failure at runtime. Only if the token were to be
provided using `[new Optional(), new Inject('a')]` would it work
correctly.

This commit fixes the issue by using the last non-decorator in the
array literal as the token value, instead of the array literal itself.

Note that this is a loose interpretation of array literals: if a token
is omitted from the array literal then the array literal itself is used
as token, but any decorator such as `new Optional()` would still have
been applied. When there's multiple tokens in the list then only the
last one will be used as actual token, any prior tokens are silently
ignored. This behavior mirrors the JIT interpretation so is kept as is
for now, but may benefit from some stricter checking and better error
reporting in the future.

Fixes #42987

PR Close #43226
2021-09-28 14:15:49 -07:00
JoostK 69299f7d4d fix(ngcc): do not fail for packages which correspond with Object members (#43589)
Prior to this commit ngcc stored its package configuration in JavaScript
objects, which caused the builtin `Object` members to be found as
package configuration. This would subsequently crash as their shape was
not as expected.

This commit moves away from using raw JavaScript objects in favor of a
Map. To code was refactored such that `PartiallyProcessedConfig` is
now a class.

Fixes #43570

PR Close #43589
2021-09-27 14:21:54 -07:00
Andrew Scott c8f8d7d3b1 fix(language-service): provide dom event completions (#43299)
Native DOM events were previously not included in the completions
because the dom schema registry would filter out events completely. This
change updates the registry to include events in the private
element->property map and excludes events from lookups outside of the
new `allKnownEventsOfElement` function.

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

PR Close #43299
2021-09-27 10:45:59 -07:00
George Kalpakas 3cf41354ae fix(service-worker): do not unassign clients from a broken version (#43518)
Previously, when a version was found to be broken, any clients assigned
to that version were unassigned (and either assigned to the latest
version or to none if the latest version was the broken one). A version
could be considered broken for several reasons, but most often it is a
response for a hashed asset that eiher does not exist or contains
different content than the SW expects. See
https://github.com/angular/angular/issues/28114#issuecomment-923122967
for more details.

However, assigning a client to a different version (or the network) in
the middle of a session, turned out to be more risky than keeping it on
the same version. For angular.io, for example, it has led to #28114.

This commit avoids making things worse when identifying a broken version
by keeping existing clients to their assigned version (but ensuring that
no new clients are assigned to the broken version).

NOTE:
Reloading the page generates a new client ID, so it is like a new client
for the SW, even if the tab and URL are the same.

PR Close #43518
2021-09-24 10:54:22 -07:00
George Kalpakas 70b194abe3 test(service-worker): use correct assertion in tests (#43518)
Previously, a ServiceWorker test was using the
`MockServerState#sawRequestFor()` method. This method, however, only
returns a boolean indicating whether a request had been seen, but would
not throw an error in either case.

Since the intention was to assert that a specific request was made, this
commit switches to the correct `MockServerState#assertSawRequestFor()`
method.

PR Close #43518
2021-09-24 10:54:22 -07:00
Joe Martin (Crowdstaffing) c3f8ee35b8 docs: add new internationalization links (#43245)
Update link for subtopics of internationalization guide.

PR Close #43245
2021-09-23 15:40:35 -07:00
Daniel Díaz 2306a3250f docs(router): fix typo in router event API documentation (#43555)
PR Close #43555
2021-09-23 14:45:28 -07:00
Daniel Díaz 9b7cdaefe8 docs(http): get rid of not needed space at the end of the sentence (#43528)
PR Close #43528
2021-09-22 16:18:08 +00:00
Andrew Scott c73e000243 test(compiler-cli): rename test files to be more descriptive (#43419)
The test files simply named `spec.ts` are hard to find when searching
for files by name.

PR Close #43419
2021-09-22 16:01:57 +00:00
Andrew Scott 9bd17e8c55 refactor(compiler-cli): Add test to document use-case for invalid pipe argument nullish coallesce (#43419)
Adds a test to the nullish coalescing diagnostic check to serve as
self-documentation on how it works with nullish coalescing on pipes that
are often misconfigured.

This also removes that non null assertion operator, which is incorrect
because there _are_ situations where a symbol cannot be retrieved.

PR Close #43419
2021-09-22 16:01:57 +00:00
Kristiyan Kostadinov 2bb4bf1468 fix(common): titlecase pipe incorrectly handling numbers (#43476)
Fixes that the `titlecase` pipe wasn't picking up numbers which meant that cases like `1st` would be tranformed to `1St`.

Fixes #43459.

PR Close #43476
2021-09-20 21:56:46 +00:00