Commit Graph

20575 Commits

Author SHA1 Message Date
Pete Bacon Darwin d04515cf53 refactor(compiler): separate `compileFactoryFunction()` from `compileInjector()` (#41022)
This commit moves the creation of the injector's factory function
out so that it can be more easily refactored further.

PR Close #41022
2021-03-08 15:31:30 -08:00
Alex Rickabaugh bdf13fe376 docs(compiler-cli): add README.md for template type checking system (#41004)
This commit adds a semi-comprehensive README file which describes the
design goals and implementation of the template type checking engine,
which powers the Angular Language Service as well as the main compiler's
understanding of types in templates.

PR Close #41004
2021-03-08 12:07:04 -08:00
JoostK 87bca2a5c6 perf(compiler-cli): avoid module resolution in cycle analysis (#40948)
The compiler performs cycle analysis for the used directives and pipes
of a component's template to avoid introducing a cyclic import into the
generated output. The used directives and pipes are represented by their
output expression which would typically be an `ExternalExpr`; those are
responsible for the generation of an `import` statement. Cycle analysis
needs to determine the `ts.SourceFile` that would end up being imported
by these `ExternalExpr`s, as the `ts.SourceFile` is then checked against
the program's `ImportGraph` to determine if the import is allowed, i.e.
does not introduce a cycle. To accomplish this, the `ExternalExpr` was
dissected and ran through module resolution to obtain the imported
`ts.SourceFile`.

This module resolution step is relatively expensive, as it typically
needs to hit the filesystem. Even in the presence of a module resolution
cache would these module resolution requests generally see cache misses,
as the generated import originates from a file for which the cache has
not previously seen the imported module specifier.

This commit removes the need for the module resolution by wrapping the
generated `Expression` in an `EmittedReference` struct. This allows the
reference emitter mechanism that is responsible for generating the
`Expression` to also communicate from which `ts.SourceFile` the
generated `Expression` would be imported, precluding the need for module
resolution down the road.

PR Close #40948
2021-03-08 12:05:49 -08:00
JoostK 9cec94a008 perf(compiler-cli): use bound symbol in import graph in favor of module resolution (#40948)
The import graph scans source files for its import and export statements
to extract the source files that it imports/exports. Such statements
contain a module specifier string and this module specifier used to be
resolved to the actual source file using an explicit module resolution
step. This is especially expensive in incremental rebuilds, as the
module resolution cache has not been primed during program creation
(assuming that the incremental program was able to reuse the module
resolution results from a prior compilation). This meant that all module
resolution requests would have to hit the filesystem, which is
relatively slow.

This commit is able to replace the module resolution with TypeScript's
bound symbol of the module specifier. This symbol corresponds with the
`ts.SourceFile` that is being imported/exported, which is exactly what
the import graph was interested in. As a result, no filesystem accesses
are done anymore.

PR Close #40948
2021-03-08 12:05:48 -08:00
Joey Perrott 153e3a8960 test(dev-infra): fix test order failure in tests for the release command (#41023)
Depending on test order, the `_npmPackageInfoCache` contains information
which causes the prompt results to be slightly different text.

PR Close #41023
2021-03-08 10:33:07 -08:00
Igor Minar 03d47d5701 feat(core): manually annotate de-sugarred core tree-shakable providers with @pureOrBreakMyCode (#41096)
This is necessary for closure compiler in order to support cross chunk code motion.

I'm intentionally not annotating these call sites with @__PURE__ at the moment because
build-optimizer does it within the Angular CLI build. In the future we might want to consider
having both annotations here in case we change how build-optimizer works.

PR Close #41096
2021-03-08 10:30:08 -08:00
Igor Minar 9c210281d4 feat(compiler): emit @__PURE__ or @pureOrBreakMyCode annotations in the generated code (#41096)
This change marks all relevant define* callsites as pure, causing the compiler to
emmit either @__PURE__ or @pureOrBreakMyCode annotation based on whether we are
compiling code annotated for closure or terser.

This change is needed in g3 where we don't run build optimizer but we
need the code to be annotated for the closure compiler.

Additionally this change allows for simplification of CLI and build optimizer as they
will no longer need to rewrite the generated code (there are still other places where
a build optimizer rewrite will be necessary so we can't remove it, we can only simplify it).

PR Close #41096
2021-03-08 10:30:08 -08:00
Jason Bedard 5c4914deff fix(bazel): fix incorrect rollup plugin method signature (#41101)
Update the resolveBazel method signature to align with the rollup plugin
resolveId API: https://rollupjs.org/guide/en/#resolveid

PR Close #41101
2021-03-08 10:06:46 -08:00
Kristiyan Kostadinov 1735430476 feat(localize): add scripts to migrate away from legacy message IDs (#41026)
Adds a new flag to `localize-extract` called `--migrateMapFile` which will generate a JSON file
that can be used to map legacy message IDs to cannonical ones.

Also includes a new script called `localize-migrate` that can take the mapping file which was
generated by `localize-extract` and migrate all of the IDs in the files that were passed in.

PR Close #41026
2021-03-08 10:05:42 -08:00
George Kalpakas 531f0bfb4a ci: improve error message when payload size check fails (#41116)
Previously, when a payload size check failed, the error message prompted
the user to update the size limits using a CI-specific file path, which
was confusing (esp. for external contributors). See, for example,
https://circleci.com/gh/angular/angular/932733.

This commit improves the error message by printing the file path
relative to the repository root instead.

PR Close #41116
2021-03-08 10:03:59 -08:00
Sagar Pandita c1a93fcf32 docs: remove augury resource (#41107)
Partially addresses #41030.

PR Close #41107
2021-03-08 10:00:13 -08:00
abarghoud cf5f86386f docs(core): add usage examples for APP_INITIALIZER token (#41095)
Add multiple usage examples for APP_INITIALIZER using Promise, Observable and multi providers

Closes #40730

PR Close #41095
2021-03-08 09:58:18 -08:00
JoostK fed6a7ce7d perf(compiler-cli): detect semantic changes and their effect on an incremental rebuild (#40947)
In Angular programs, changing a file may require other files to be
emitted as well due to implicit NgModule dependencies. For example, if
the selector of a directive is changed then all components that have
that directive in their compilation scope need to be recompiled, as the
change of selector may affect the directive matching results.

Until now, the compiler solved this problem using a single dependency
graph. The implicit NgModule dependencies were represented in this
graph, such that a changed file would correctly also cause other files
to be re-emitted. This approach is limited in a few ways:

1. The file dependency graph is used to determine whether it is safe to
   reuse the analysis data of an Angular decorated class. This analysis
   data is invariant to unrelated changes to the NgModule scope, but
   because the single dependency graph also tracked the implicit
   NgModule dependencies the compiler had to consider analysis data as
   stale far more often than necessary.
2. It is typical for a change to e.g. a directive to not affect its
   public API—its selector, inputs, outputs, or exportAs clause—in which
   case there is no need to re-emit all declarations in scope, as their
   compilation output wouldn't have changed.

This commit implements a mechanism by which the compiler is able to
determine the impact of a change by comparing it to the prior
compilation. To achieve this, a new graph is maintained that tracks all
public API information of all Angular decorated symbols. During an
incremental compilation this information is compared to the information
that was captured in the most recently succeeded compilation. This
determines the exact impact of the changes to the public API, which
is then used to determine which files need to be re-emitted.

Note that the file dependency graph remains, as it is still used to
track the dependencies of analysis data. This graph does no longer track
the implicit NgModule dependencies, which allows for better reuse of
analysis data.

These changes also fix a bug where template type-checking would fail to
incorporate changes made to a transitive base class of a
directive/component. This used to be a problem because transitive base
classes were not recorded as a transitive dependency in the file
dependency graph, such that prior type-check blocks would erroneously
be reused.

This commit also fixes an incorrectness where a change to a declaration
in NgModule `A` would not cause the declarations in NgModules that
import from NgModule `A` to be re-emitted. This was intentionally
incorrect as otherwise the performance of incremental rebuilds would
have been far worse. This is no longer a concern, as the compiler is now
able to only re-emit when actually necessary.

Fixes #34867
Fixes #40635
Closes #40728

PR Close #40947
2021-03-08 08:41:19 -08:00
Igor Minar 8c062493a0 refactor(core): don't use innerHTML in DOMTestComponentRenderer (#41099)
The use of innerHTML is unnecessary and causes TrustedType violations.

PR Close #41099
2021-03-08 08:39:09 -08:00
Andrew Kushnir 32dd3c5dd1 refactor(core): co-locate read/write patched data functions (#41097)
This commit refactors Ivy runtime code to move `readPatchedData` and `attachPatchedData` functions to a single
location for better maintainability and to make it easier to do further changes if needed.  The `readPatchedLView`
function was also moved to the same location (since it's a layer on top of the `readPatchedData` function).

PR Close #41097
2021-03-08 08:38:00 -08:00
LordMsz 2d69f0c9ca docs: extend :host selector documentation (#41055)
explain behavior of selectors *before* `:host` that escape encapsulation
and explain preferred usage of `:host-context`

PR Close #41055
2021-03-08 08:36:04 -08:00
George Kalpakas 681c3417fe docs: add Discord, YouTube, StackOverflow to the "Community" section in `README.md` (#41086)
PR Close #41086
2021-03-08 08:35:22 -08:00
Pete Bacon Darwin 2893b925c3 build(docs-infra): capture all decorators in doc-gen (#41091)
In 6cff877 we broke the decorator docs because the
doc-gen no longer knew how to identify them.

This commit updates the dgeni processor responsible
for identifying the decorators in the code and ensures
that the docs are now generated correctly.

Fixes #40851

PR Close #41091
2021-03-08 08:34:40 -08:00
George Kalpakas 7854c4ddbe test(docs-infra): run a11y tests against `/tutorial` and update a11y scores (#41103)
This commit adds `/tutorial` to the list of angular.io pages that we run
a11y tests against and updates the required scores to match the current
ones (to avoid a future regression going unnoticed).

PR Close #41103
2021-03-08 08:33:47 -08:00
George Kalpakas e59246cf5c test(docs-infra): print the browser version in `audit-web-app.js` to help debugging (#41103)
This commit updates the `audit-web-app.js` script (used to run PWA and
a11y tests on angular.io) to also print the version of the browser used
to run the tests. This can help when debugging a CI failure.

PR Close #41103
2021-03-08 08:33:47 -08:00
Sivamuthu Kumar 44bb78dbbd docs: update repo link to auto scroll to readme section (#41105)
Co-authored-by: George Kalpakas <kalpakas.g@gmail.com>
PR Close #41105
2021-03-08 08:33:00 -08:00
Sivamuthu Kumar 3d3ab4aa5d docs: add angular-eslint and remove codelyzer from tooling (#41105)
fixes #41029

PR Close #41105
2021-03-08 08:33:00 -08:00
Raj Sekhar 13681d94d6 docs: fix typo in `CHANGELOG.md` (find-tuned --> fine-tuned) (#41113)
PR Close #41113
2021-03-08 08:31:42 -08:00
Quentin Monmert c676ec1ce5 docs: fix some typos in angular.io examples (#41093)
This commit updates example code to make the spacing more consistent.

PR Close #41093
2021-03-05 15:08:11 -08:00
Carl Fredrik Samson e7453f15d5 docs: fix issue #40941 (#40942)
setting the `hero` property as an optional property fixes the compilation
error: `Property 'hero' has no initializer and is not definitely assigned
in the constructor` when having the ts transpiler set to "strict" mode.

PR Close #40942
2021-03-05 09:47:44 -08:00
Andrew Kushnir 4637df5551 test(forms): add integration test app to keep track of payload size (#41045)
This commit adds a Forms-based test app into the `integration` folder to have an ability to measure and keep
track of payload size for the changes in Forms package.

PR Close #41045
2021-03-05 09:45:42 -08:00
Alex Rickabaugh fbc9df181e feat(compiler-cli): support producing Closure-specific PURE annotations (#41021)
For certain generated function calls, the compiler emits a 'PURE' annotation
which informs Terser (the optimizer) about the purity of a specific function
call. This commit expands that system to produce a new Closure-specific
'pureOrBreakMyCode' annotation when targeting the Closure optimizer instead
of Terser.

PR Close #41021
2021-03-04 16:04:38 -08:00
Andrew Scott 45216ccc0d fix(language-service): Only provide dom completions for inline templates (#41078)
We currently provide completions for DOM elements in the schema as well
as attributes when we are in the context of an external template.
However, these completions are already provided by other extensions for
HTML contexts (like Emmet). To avoid duplication of results, this commit
updates the language service to exclude DOM completions for external
templates. They are still provided for inline templates because those
are not handled by the HTML language extensions.

PR Close #41078
2021-03-04 14:51:06 -08:00
arturovt 38524c4d29 fix(common): cleanup location change listeners when the root view is removed (#40867)
In the new behavior Angular cleanups `popstate` and `hashchange` event listeners
when the root view gets destroyed, thus event handlers are not added twice
when the application is bootstrapped again.

BREAKING CHANGE:

Methods of the `PlatformLocation` class, namely `onPopState` and `onHashChange`,
used to return `void`. Now those methods return functions that can be called
to remove event handlers.

PR Close #31546

PR Close #40867
2021-03-04 13:09:04 -08:00
abarghoud ca721c2972 feat(core): more precise type for `APP_INITIALIZER` token (#40986)
This commit updates the type of the `APP_INITIALIZER` injection token to
better document the expected types of values that Angular handles. Only
Promises and Observables are awaited and other types of values are ignored,
so the type of `APP_INITIALIZER` has been updated to
`Promise<unknown> | Observable<unknown> | void` to reflect this behavior.

BREAKING CHANGE:

The type of the `APP_INITIALIZER` token has been changed to more accurately
reflect the types of return values that are handled by Angular. Previously,
each initializer callback was typed to return `any`, this is now
`Promise<unknown> | Observable<unknown> | void`. In the unlikely event that
your application uses the `Injector.get` or `TestBed.inject` API to inject
the `APP_INITIALIZER` token, you may need to update the code to account for
the stricter type.

Additionally, TypeScript may report the TS2742 error if the `APP_INITIALIZER`
token is used in an expression of which its inferred type has to be emitted
into a .d.ts file. To workaround this, an explicit type annotation is needed,
which would typically be `Provider` or `Provider[]`.

Closes #40729

PR Close #40986
2021-03-04 12:01:07 -08:00
cexbrayat bf158e7ff0 fix(core): remove duplicated EMPTY_OBJ constant (#41066)
The codebase currently contains several `EMPTY_OBJ` constants,
and they can end up in the bundle of an application.
A recent commit 6fbe219 tipped us off
as it introduced several `noop` occurrences in the golden symbol files.
After investigating, we decided to remove the duplicated symbols.

This probably shaves only a few bytes,
but this commit removes the duplicated functions,
by always using the one in `core/src/utils/empty`.

PR Close #41066
2021-03-04 11:08:49 -08:00
Pete Bacon Darwin d44c7c209d refactor(compiler): remove unused `__BUILD_OPTIMIZER_*` constants (#41040)
These constants were created in a very early phase of Ivy development.
They have never been used in the framework, no the build-optimizer tool.

PR Close #41040
2021-03-04 11:04:27 -08:00
Pete Bacon Darwin 11e16c7b41 refactor(core): do not publish `ɵɵgetFactoryOf()` (#41040)
Previously, `ɵɵgetFactoryOf()` was "privately" published from
`@angular/core` since in the past it was assumed that this
might be an instruction generated by the compiler.

This is not currently the case, so this commit removes it from
the private exports and renames it to indicate that it is a local
helper function.

PR Close #41040
2021-03-04 11:04:27 -08:00
Pete Bacon Darwin 326f167075 refactor(core): remove `getFactoryOf` from `angularCoreDiEnv` (#41040)
This function is never actually generated directly so it can be removed
from the context passed to the JIT compiler.

PR Close #41040
2021-03-04 11:04:27 -08:00
Pete Bacon Darwin 89563442b8 refactor(compiler): remove unused `emitAllPartialModules()` and associated code (#41040)
This method does not appear to be used in the project.
This commit removes it and code that it exclusively
depended upon, or depended upon it.

PR Close #41040
2021-03-04 11:04:26 -08:00
Pete Bacon Darwin 7f24937f1c refactor(compiler): remove unused function (#41040)
The `accessExportScope()` function is not used anymore.

PR Close #41040
2021-03-04 11:04:26 -08:00
Pete Bacon Darwin 0f818f36d7 refactor(core): use `unknown` rather than `never` for private properties (#41040)
Before `unknown` was available, the `never` type was used to discourage
application developers from using "private" properties. The `unknown` type
is much better suited for this.

PR Close #41040
2021-03-04 11:04:26 -08:00
Chris d9acaa8547 docs: remove Codelyzer recommendation from style guide (#40992)
Fixes #40903

PR Close #40992
2021-03-04 11:01:48 -08:00
Chris ad40fcae7a docs: improve documentation on how to pass a stringified parameter list to HttpClient (#41010)
Fixes #40618

PR Close #41010
2021-03-04 11:00:23 -08:00
pavlenko 9ae0faa00a docs(router): fix typo for the equivalent `exactMatchOptions` value (#41075)
When `Router.isActive` is called with `true` the `exactMatchOptions` value is set for this case.

PR Close #41075
2021-03-04 10:58:30 -08:00
MG 84b8f250f9 docs: add ng-mocks to tooling resources (#41027)
closes #41025

PR Close #41027
2021-03-03 23:31:38 +00:00
Zach Arend a10fe450d9 release: cut the v12.0.0-next.3 release 2021-03-03 23:09:28 +00:00
Zach Arend 4606a6097b docs: release notes for the v11.2.4 release 2021-03-03 22:59:26 +00:00
Alex Rickabaugh bb6e5e2dd0 fix(language-service): don't show external template diagnostics in ts files (#41070)
The compiler considers template diagnostics to "belong" to the source file
of the component using the template. This means that when diagnostics for
a source file are reported, it returns diagnostics of TS structures in the
actual source file, diagnostics for any inline templates, and diagnostics of
any external templates.

The Language Service uses a different model, and wants to show template
diagnostics in the actual .html file. Thus, it's not necessary (and in fact
incorrect) to include such diagnostics for the actual .ts file as well.
Doing this currently causes a bug where external diagnostics appear in the
TS file with "random" source spans.

This commit changes the Language Service to filter the set of diagnostics
returned by the compiler and only include those diagnostics with spans
actually within the .ts file itself.

Fixes #41032

PR Close #41070
2021-03-03 21:40:50 +00:00
Andrew Scott 0847a0353b fix(language-service): Always attempt HTML AST to template AST conversion for LS (#41068)
The current logic in the compiler is to bail when there are errors when
parsing a template into an HTML AST or when there are errors in the i18n
metadata. As a result, a template with these types of parse errors
_will not have any information for the language service_. This is because we
never attempt to conver the HTML AST to a template AST in these
scenarios, so there are no template AST nodes for the language service
to look at for information. In addition, this also means that the errors
are never displayed in the template to the user because there are no
nodes to map the error to.

This commit adds an option to the template parser to temporarily ignore
the html parse and i18n meta errors and always perform the template AST
conversion. At the end, the i18n and HTML parse errors are appended to
the returned errors list. While this seems risky, it at least provides
us with more information than we had before (which was 0) and it's only
done in the context of the language service, when the compiler is
configured to use poisoned data (HTML parse and i18n meta errors can be
interpreted as a "poisoned" template).

fixes angular/vscode-ng-language-service#1140

PR Close #41068
2021-03-03 21:13:58 +00:00
Andrew Scott 1e3c870ee6 fix(language-service): provide element completions after open tag < (#41068)
An opening tag `<` without any characters after it is interperted as a
text node (just a "less than" character) rather than the start of an
element in the template AST. This commit adjusts the autocomplete engine
to provide element autocompletions when the nearest character to the
left of the cursor is `<`.

Part of the fix for angular/vscode-ng-language-service#1140

PR Close #41068
2021-03-03 21:13:58 +00:00
David Pine 7765b648e7 docs: update Angular Global Summit on event pages (#41050)
After my speaker meeting with the Geekle team, they communicated that
they moved the date to avoid colliding with ng-conf. Originally added
in#40697, per @mgechev.

PR Close #41050
2021-03-03 10:04:56 -08:00
David Shevitz d10599459d docs: update @reviewed date (#41060)
PR Close #41060
2021-03-03 10:03:57 -08:00
Kristiyan Kostadinov 97b88f3631 fix(compiler): allow binding to autocomplete property on select and textarea elements (#40928)
Updates the schema to allow binding to the `autocomplete` property of a `textarea` or `select`.

Fixes #39490.

PR Close #40928
2021-03-03 10:00:27 -08:00
Andrew Scott 736b1f9fd4 fix(compiler): recover from an incomplete open tag at the end of a file (#41054)
The compiler's parsing code has logic to recover from incomplete open
tags (i.e. `<div`) but the recovery logic does not handle when the
incomplete tag is terminated by an EOF. This commit updates the logic to
allow for the EOF character to be interpreted as the end of the tag open
so that the parser can continue processing. It will then fail to find
the end tag and recover by marking the open tag as incomplete.

Part of https://github.com/angular/vscode-ng-language-service/issues/1140

PR Close #41054
2021-03-03 09:58:56 -08:00