Commit Graph

7609 Commits

Author SHA1 Message Date
Alan Agius 4c78984ad2 fix(compiler-cli): support reflecting namespace declarations (#42728)
DTS bundling, will cause originally namespaced imports become namespace declarations within the same file. Example:

Before bundling
```ts
import * as i1 from './router';

export declare class RouterModule {
    constructor(guard: any, router: Router);

    static ɵmod: i0.ɵɵNgModuleDeclaration<RouterModule, [typeof i1.RouterOutlet...]>;
}
```

After bundling
```
declare namespace i1 {
  export {
    RouterOutletContract,
    RouterOutlet
  }
}

export declare class RouterModule {
    constructor(guard: any, router: Router);

    static ɵmod: i0.ɵɵNgModuleDeclaration<RouterModule, [typeof i1.RouterOutlet...]>;
}
```

And therefore this commit adds support for reflecting types that are defined in such namespace declarations.

Closes #42064

PR Close #42728
2021-07-02 15:15:04 -07:00
Alan Agius 7e04116d15 fix(bazel): enable dts bundling for Ivy packages (#42728)
It is now possible to bundle DTS files of Ivy libraries since the blocker https://github.com/microsoft/rushstack/issues/1029 has been addressed upstream.

PR Close #42728
2021-07-02 15:15:04 -07:00
Paul Gschwendtner 2feb4bc9de build: update api-extractor dependency to support typescript 4.3 (#42737)
Updates the api-extractor dependencies of the repository, and within
the `@angular/bazel` package so that TypeScript 4.3 is supported when
a flattened typings file is generated. Without this update, the api
extractor could fail if a referenced tsconfig use a TS 4.3-only option such as
`noImplicitOverride`.

Note: This could also be considered a `feat:` for `@angular/bazel`,
but this package is not part of the public API anyway and we'd want
that change to land in the patch branches too (to keep the goldens
in sync between release branches as much as possible)

PR Close #42737
2021-07-02 10:08:03 -07:00
Andrew Scott ffeea63f43 fix(language-service): Do not override TS LS methods not supported by VE NgLS (#42727)
Historically, our Language Service was built with the potential to be a
drop-in replacement for the TypeScript Language Service with the added
benefit of being able to provide Angular-specific information as well.
While our VSCode extension does not use the Language Service in this
way, it appears that other community-contributed plugins do. We don't
really officially support this use-case but there's not real reason for
us to override the TypeScript Language Service's
implementation in the VE Angular Language Service so that it returns
`undefined`. As with other non-implemented methods, we can just allow
this to be deferred to TSLS.

fixes #42715

PR Close #42727
2021-07-01 15:23:50 -07:00
ivanwonder 74350a5cf1 fix(compiler-cli): return directives for an element on a microsyntax template (#42640)
When the template type checker try to get a symbol of a template node, it will
not return the directives intended for an element on a microsyntax template,
for example, `<div *ngFor="let user of users;" dir>`, the `dir` will be skipped,
but it's needed in language service.

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

PR Close #42640
2021-07-01 09:35:24 -07:00
Kristiyan Kostadinov 0f23f7343e fix(core): error in TestBed if module is reset mid-compilation in ViewEngine (#42669)
When `TestBed.compileComponents` is called under ViewEngine, we kick off a compilation and return a promise that resolves once the compilation is done. In most cases the consumer doesn't _have_ to await the returned promise, unless their components have external resources.

The problem is that the test could be over by the time the promise has resolved, in which case we still cache the factory of the test module. This becomes a problem if another compilation is triggered right afterwards, because it'll see that we still have a `_moduleFactory` and it won't recreate the factory.

These changes resolve the issue by saving a reference to the module type that is being compiled and checking against it when the promise resolves.

Note that while this problem was discovered while trying to roll out the new test module teardown behavior in the Components repo (https://github.com/angular/components/pull/23070), it has been there for a long time. The new test behavior made it more apparent.

PR Close #42669
2021-06-30 14:32:23 -07:00
Paul Gschwendtner 59fe159b78 build: update API goldens to reflect new tool (#42688)
Updates the TS API guardian goldens with their equivalents
based on the new shared dev-infra tool.

PR Close #42688
2021-06-30 11:43:48 -07:00
Paul Gschwendtner 9db69a9c9e build: use api-golden tool from dev-infra for testing public API (#42688)
Switches our TS API guardian targets to rather use the new tool from
dev-infra that relies on Microsoft's API extractor.

PR Close #42688
2021-06-30 11:43:48 -07:00
Kristiyan Kostadinov 9f5cc7c808 feat(compiler): support number separators in templates (#42672)
As of ES2021, JavaScript allows using underscores as separators inside numbers, in order to make them more readable (e.g. `1_000_000` vs `1000000`). TypeScript has had support for separators for a while so these changes expand the template parser to handle them as well.

PR Close #42672
2021-06-30 10:36:15 -07:00
Pete Bacon Darwin 234b5edcc7 fix(platform-browser): in `Meta.addTag()` do not add duplicate meta tags (#42703)
Previously, if there were two tags with the same "name" or "property" attribute selector,
then only the first was checked for duplicates when deciding whether to add a new meta
tag.

Fixes #42700
Fixes #19606

PR Close #42703
2021-06-30 10:35:30 -07:00
Dario Piotrowicz 4bea630baa docs(core): add context jsdoc param to createEmbeddedView (#42675)
PR Close #42675
2021-06-28 09:34:17 -07:00
dario-piotrowicz 56fb4eb08d docs(compiler): interally typo fixed (#42676)
PR Close #42676
2021-06-28 09:32:23 -07:00
Zach Arend 37a740c659 fix(compiler-cli): add support for partially evaluating types (#41661)
Add support to the partial evaluator for evaluating literal types and
tuples.

resolves #41338

PR Close #41661
2021-06-25 09:59:27 -07:00
George Kalpakas cc30dc0713 fix(service-worker): ensure obsolete caches are always cleaned up (#42622)
Previously, the SW was only able to clean up caches for app-versions
found in the `Driver`'s `versions` map. If (for some reason) the
`Driver` failed to load a valid stored state (including app-versions)
and ended up with an [empty `versions` map][1], any obsolete versions
would remain in the cache storage. This case was rare but possible.

This commit makes the cache clean-up logic more robust by ensuring that
all app-version caches are removed unless they are currently used by the
SW to serve active clients (with the exception of the latest
app-version, which is always retained).

Fixes #41728

[1]: 9de65dbdce/packages/service-worker/worker/src/driver.ts (L515-L529)

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 01128f5b5d fix(service-worker): ensure caches are cleaned up when failing to load state (#42622)
Previously, obsolete caches were only cleaned up when successfully
loading the stored state. When the state failed to be loaded, cleaning
up the caches would be skipped until the next SW initialization.

This commit changes this, ensuring that the caches are cleaned up
regardless if the stored state was loaded successfully or not.

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 356dd2107b refactor(service-worker): simplify accessing `CacheStorage` throughout the ServiceWorker (#42622)
This commit simplifies/systemizes accessing the `CacheStorage` through a
wrapper, with the following benefits:
- Ensuring a consistent cache name prefix is used for all caches
  (without having to repeat the prefix in different places).
- Allowing referring to caches using their name without the common
  cache name prefix.
- Exposing the cache name on cache instances, which for example makes it
  easier to delete caches without having to keep track of the name used
  to create them.

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 73b0275dc2 fix(service-worker): improve ServiceWorker cache names (#42622)
This commit improves the cache names generated by the ServiceWorker by
making them shorter and non-repetitive. In particular, the following
changes are made:

- Data-group cache names no longer include the `dynamic` infix, since it
  does not add any value.
  Before: `ngsw:<...>:data:dynamic:<...>`
  After:  `ngsw:<...>:data:<...>`

- `CacheDatabase` table names no longer include the `ngsw:<path>` prefix
  twice.
  Before: `ngsw:<path>:db:ngsw:<path>:<...>`
  After:  `ngsw:<path>:db:<...>`

NOTE 1:
This change will result in different cache names being generated for the
same app-versions with the new SericeWorker script. This means that some
of the previously cached data will need to be re-downloaded (because the
ServiceWorker will not be able to re-use the old caches), but that
should be transparent for the end user.
While possible, adding logic to allow the ServiceWorker to retrieve data
from the old caches is not worth the extra complecity and maintenance
cost.

NOTE 2:
Generating different cache names for some of the caches means that the
ServiceWorker will not be able to clean-up some of the old caches. This
will be taken care of in a subsequent commit that will rework the
clean-up logic to be more robust (covering changes such as this one and
other edgecases).

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 7507ed2e54 fix(service-worker): use correct names when listing `CacheDatabase` tables (#42622)
`CacheDatabase` uses the un-prefixed table names to interact with
database tables. However, the `list()` method returns the raw, prefixed
table names (which are not useful, since they cannot be used to
open/delete a table).

This commit fixes this by removing the prefix from the cache names
returned by the `list()` method.

NOTE:
This method is currently not used anywhere, so this change does not
affect the ServiceWorker behavior.

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 53fe557da7 feat(service-worker): include ServiceWorker version in debug info (#42622)
This commit includes the ServiceWorker version in the debug info shown
at `/ngsw/state` to make it easier to know what version of the
ServiceWorker script is controlling the page.

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 4962ef5330 refactor(service-worker): minor refactorings to improve readability/maintainability (#42622)
This commit makes some minor refactorings to improve the code
readability and maintainability, including:
- Avoiding code duplication.
- Using more descriptive variable names.
- Using `async/await` instead of `Promise#then()`.
- Accessing variables directly instead of via `this` when possible.

PR Close #42622
2021-06-24 09:55:32 -07:00
Pete Bacon Darwin 874de59d35 fix(compiler-cli): change default ngcc hash algorithm to be FIPS compliant (#42582)
The previous default algorithm was `md5`, which is not compliant with FIPS.
The default is now set to `sha256`, which is compliant.

Fixes #42577

PR Close #42582
2021-06-24 08:42:38 -07:00
Pete Bacon Darwin b8ef83b10f refactor(compiler-cli): ngcc entry-point manifest hash is now configurable (#42582)
The hash algorithm for the entry-point manifest was hardcoded to `md5`.
This can now be configured by the `hashAlgorithm` property on the
ngcc.config.js project configuration.

PR Close #42582
2021-06-24 08:42:38 -07:00
Pete Bacon Darwin a3b6d65580 refactor(compiler-cli): make ngcc configuration hash algorithm configurable! (#42582)
The ngcc configuration gets hashed to be used when caching
but it was hardcoded to use the `md5` algorithm, which is
not FIPS compliant.

Now the hash algorithm can be configured in the ngcc.config.js
file at the project level.

PR Close #42582
2021-06-24 08:42:38 -07:00
Renovate Bot 356723158a build: lock file maintenance (#42568)
PR Close #42568
2021-06-23 17:36:41 +00:00
codingnuclei d546501ab5 feat(service-worker): add `openWindow`, `focusLastFocusedOrOpen` and `navigateLastFocusedOrOpen` (#42520)
Add `openWindow`, `focusLastFocusedOrOpen` and `navigateLastFocusedOrOpen` abilty to the notificationclick handler such that when either a notification or notification action is clicked the service-worker can act accordinly without the need for the app to be open

PR Close #26907

PR Close #42520
2021-06-23 16:31:09 +00:00
Pete Bacon Darwin 9de65dbdce fix(compiler): should not break a text token on a non-valid start tag (#42605)
Previously the lexer would break out of consuming a text token if it contains
a `<` character. Then if the next characters did not indicate an HTML syntax
item, such as a tag or comment, then it would start a new text token. These
consecutive text tokens are then merged into each other in a post tokenization
step.

In the commit before this, interpolation no longer leaks across text tokens.
The approach given above to handling `<` characters that appear in text is
no longer adequate. This change ensures that the lexer only breaks out of
a text token if the next characters indicate a valid HTML tag, comment,
CDATA etc.

PR Close #42605
2021-06-22 16:37:00 +00:00
Pete Bacon Darwin c873440ad2 fix(compiler): do not allow unterminated interpolation to leak into later tokens (#42605)
When consuming a text token, the lexer tracks whether it is reading characters
from inside an interpolation so that it can identify invalid ICU expressions.
Inside an interpolation there will be no ICU expression so it is safe to
have unmatched `{` characters, but outside an interpolation this is an error.

Previously, if an interpolation was started, by an opening marker (e.g. `{{`)
in a text token but the text came to an end before the closing marker (e.g. `}}`)
then the lexer was not clearing its internal state that tracked that it was
inside an interpolation. When the next text token was being consumed,
the lexer, incorrectly thought it was already within an interpolation.
This resulted in invalid ICU expression errors not being reported.

For example, in the following snippet, the first text block has a prematurely
ended interpolation, and the second text block contains an invalid `{` character.

```
<div>{{</div>
<div>{</div>
```

Previously, the lexer would not have identified this as an error. Now there
will be an EOF error that looks like:

```
TS-995002: Unexpected character "EOF"
(Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.)
```

PR Close #42605
2021-06-22 16:37:00 +00:00
Umair Hafeez 8a67770687 docs(core): improve applicationref.bootstrap docs (#42407)
add proper examples and update usage notes
add references to the method at relevant places in the docs

PR Close #42407
2021-06-22 16:30:37 +00:00
George Kalpakas 9498da1038 fix(service-worker): correctly determine client ID on navigation requests (#42607)
The ServiceWorker assigns an app-version to a each client to ensure that
all subsequent requests for a client are served using the same
app-version. The assignment is done based on the client ID.

Previously, the ServiceWorker would only try to read the client's ID off
of the `FetchEvent`'s `clientId` property. However, for navigation
requests the new client's ID will be set on [resultingClientId][1],
while `clientId` will either be empty or hold the ID of the client where
the request initiated from. See also related discussions in
w3c/ServiceWorker#870 and w3c/ServiceWorker#1266.

In theory, this could lead to the navigation request (i.e. `index.html`)
being served from a different app-version than the subsequent
sub-resource requests (i.e. assets). In practice, the likelihood of this
happening is probably very low though, since it would require the latest
app-version to be updated between the initial navigation request and the
first sub-resource request, which should happen very shortly after the
navigation request.

This commit ensures that the correct client ID is determined even for
navigation requests by also taking the `resultingClientId` property into
account.

[1]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId

PR Close #42607
2021-06-22 16:28:24 +00:00
Kristiyan Kostadinov cc672f05bf feat(compiler): add support for shorthand property declarations in templates (#42421)
Adds support for shorthand property declarations inside Angular templates. E.g. doing `{foo, bar}` instead of `{foo: foo, bar: bar}`.

Fixes #10277.

PR Close #42421
2021-06-21 23:40:47 +00:00
Kristiyan Kostadinov 699a8b43cb test(compiler-cli): add additional safe keyed read tests (#42421)
This commit adds some tests that were mistakenly omitted from the original
change for safe keyed reads/writes.

PR Close #42421
2021-06-21 23:40:47 +00:00
JoostK a9dd7e21a2 refactor(compiler-cli): enable relative imports in the type parameter emitter (#42492)
Previously, the template type checker would only opt-in to inline type
constructors if it could import all type references from absolute module
specifiers. This limitation was put into place in an abundance of
caution as there was a safe, but less performant, fallback available.

The language service is not capable of using this fallback, which now
means that the limitation of absolute module specifiers limits the
language service's ability to use accurate types for component/directive
classes that have generic type parameters.

This commit loosens the restriction such that type references are now
eligible for emit as long as they are exported.

PR Close #42492
2021-06-21 18:34:05 +00:00
JoostK 729eea5716 fix(compiler-cli): transform type references in generic type parameter default (#42492)
When a component/directive has a generic type parameter, the template
type checker attempts to translate the type parameter such that the
type parameters can be replicated in the type constructor that is
emitted into the typecheck file.

Type parameters with a default clause would incorrectly be emitted into
the typecheck file using the original `ts.TypeNode` for the default
clause, such that `ts.TypeReferenceNode`s within the default clause
would likely be invalid (i.e. referencing a type for which no import is
present in the typecheck file). This did not result in user-facing
type-check errors as errors reported in type constructors are not
translated into template positions Regardless, this commit ensures that
`ts.TypeReferenceNode`s within defaults are properly translated into the
typecheck file.

PR Close #42492
2021-06-21 18:34:05 +00:00
JoostK 16aaa23d4e refactor(compiler-cli): use TypeScript transform to emit type parameters (#42492)
The template type checker is capable of recreating generic type bounds
in a different context, rewriting type references along the way (if
possible). This was previously done using a visitor that only supported
a limited set of types, resulting in the inability to emit all sorts of
types (even if they don't contain type references at all).

The inability to emit generic type bounds was not critical when the type
parameter emitting logic was introduced, as the compiler also has a
fallback strategy of creating inline type constructors. However, this
fallback is not available to the language service, resulting in
inaccurate types when components/directives use a complex generic type.

To mitigate this problem, the specialized visitor has been replaced with
a generalized TypeScript transform, where only type references get
special treatment. This allows for more complex types to be emitted,
such as union and intersection types, object literal types and tuple
types.

PR Close #42492
2021-06-21 18:34:05 +00:00
Kristiyan Kostadinov f52df99fe3 fix(compiler): generate view restoration for keyed write inside template listener (#42603)
If an implcit receiver is accessed in a listener inside of an `ng-template`, we generate some extra code in order to ensure that we're assigning to the correct object. The problem is that the logic wasn't covering keyed writes which caused it to write to the wrong object and throw an assertion error at runtime.

These changes expand the logic to cover keyed writes.

Fixes #41267.

PR Close #42603
2021-06-21 18:30:37 +00:00
Alex Rickabaugh e83d7cb2d3 refactor(compiler-cli): support xi18n in ngtsc (#42485)
xi18n is the operation of extracting i18n messages from templates in the
compilation. Previously, only View Engine was able to perform xi18n. This
commit implements xi18n in the Ivy compiler, and a copy of the View Engine
test for Ivy verifies that the results are identical.

PR Close #42485
2021-06-21 16:50:28 +00:00
Alex Rickabaugh 4538bd6c96 refactor(compiler-cli): extract xi18n utility functions to a separate file (#42485)
This commit moves some xi18n-related functions in the View Engine
ng.Program into a new file. This is necessary in order to depend on them
from the Ivy ng.Program while avoiding a cycle.

PR Close #42485
2021-06-21 16:50:28 +00:00
Paul Gschwendtner d77f560403 build: update to typescript 4.3.4 (#42600)
Updates to TypeScript 4.3.4 which contains a fix for a printer
regression that caused unexpected JavaScript output with our
compiler transforms.

See: https://github.com/microsoft/TypeScript/pull/44070.
Updates to TypeScript 4.3.4 which contains a fix for a printer

PR Close #42600
2021-06-21 16:42:49 +00:00
Paul Gschwendtner b8eb24e0fb Revert "test: update compiler-cli compliance goldens due to TS 4.3 emit format regression (#42022)" (#42600)
This reverts commit 71e14a71f5.

PR Close #42600
2021-06-21 16:42:48 +00:00
Pete Bacon Darwin 983c540191 docs: fix pipe params (#42593)
The addition of overloads to some of the number pipes caused
the documentation to lose the parameter descriptions.

This change fixes that by moving the JSDOC block in from of the
primary method signature, rather than the first overload.

Fixes #42590

PR Close #42593
2021-06-17 23:03:08 +00:00
Kristiyan Kostadinov 07c1ddc487 fix(router): error if module is destroyed before location is initialized (#42560)
This is something I ran into while working on a fix for the `TestBed` module teardown behavior for #18831. In the `RouterInitializer.appInitializer` we have a callback to the `LOCATION_INITIALIZED` which has to do some DI lookups. The problem is that if the module is destroyed before the location promise resolves, the `Injector.get` calls will fail. This is unlikely to happen in a real app, but it'll show up in unit tests once the test module teardown behavior is fixed.

PR Close #42560
2021-06-17 18:11:53 +00:00
Kristiyan Kostadinov 873229f24b feat(core): add opt-in test module teardown configuration (#42566)
We currently have two long-standing issues related to how `TestBed` tests are torn down:
1. The dynamically-created test module isn't going to be destroyed, preventing the `ngOnDestroy` hooks on providers from running and keeping the component `style` nodes in the DOM.
2. The test root elements aren't going to be removed from the DOM. Instead, they will be removed whenever another test component is created.

By themselves, these issues are easy to resolve, but given how long they've been around, there are a lot of unit tests out there that depend on the broken behavior.

These changes address the issues by introducing APIs that allow users to opt into the correct test teardown behavior either at the application level via `TestBed.initTestEnvironment` or the test suite level via `TestBed.configureTestingModule`.

At the moment, the new teardown behavior is opt-in, but the idea is that we'll eventually make it opt-out before removing the configuration altogether.

Fixes #18831.

PR Close #42566
2021-06-17 18:03:47 +00:00
Marius Bethge f3a79878af docs(forms): correct sample code for FormArray.reset (#42477)
Remove unexpected this, correct output comment for arr.value and correct parameter type for FormArray.get().

PR Close #42477
2021-06-16 14:01:55 -07:00
Alex Rickabaugh 2d1347b2ce Revert "refactor: remove checked-in locale files (#42230)" (#42583)
This reverts commit 5822771946.

PR Close #42583
2021-06-16 09:49:38 -07:00
Alex Rickabaugh ec6dc78f1d Revert "build: convert CLDR locale extraction from Gulp to Bazel tool (#42230)" (#42583)
This reverts commit 1eaeb23c75.

PR Close #42583
2021-06-16 09:49:37 -07:00
Alex Rickabaugh 877cde8897 Revert "build: wire up new CLDR generation tool within Bazel (#42230)" (#42583)
This reverts commit 4957da82d3.

PR Close #42583
2021-06-16 09:49:37 -07:00
Alex Rickabaugh 76484f95c3 Revert "build: add documentation for `generate-locales-tool` (#42230)" (#42583)
This reverts commit d4c880b467.

PR Close #42583
2021-06-16 09:49:37 -07:00
Alex Rickabaugh 2cd1c6c2bd Revert "build: simplify generation of closure locale file (#42230)" (#42583)
This reverts commit 8f24d71142.

PR Close #42583
2021-06-16 09:49:37 -07:00
Alex Rickabaugh d6cca3cf9d Revert "build: generate alias locale data for closure locale (#42230)" (#42583)
This reverts commit 044e0229bd.

PR Close #42583
2021-06-16 09:49:37 -07:00
Andrew Scott 4001e9d808 fix(language-service): 'go to defininition' for objects defined in template (#42559)
Previously, the "go to definition" action did no account for the
possibility that something may actually be defined in a template. This
change updates the logic in the definition builder to convert any
results that are locations in template typecheck files to their
corresponding locations in the template.

PR Close #42559
2021-06-14 14:13:48 -07:00