5669 Commits

Author SHA1 Message Date
Andrew Kushnir
0bf6e58db2 fix(compiler): process imports first and declarations second while calculating scopes ()
Prior to this commit, while calculating the scope for a module, Ivy compiler processed `declarations` field first and `imports` after that. That results in a couple issues:

* for Pipes with the same `name` and present in `declarations` and in an imported module, Pipe from imported module was selected. In View Engine the logic is opposite: Pipes from `declarations` field receive higher priority.
* for Directives with the same selector and present in `declarations` and in an imported module, we first invoked the logic of a Directive from `declarations` field and after that - imported Directive logic. In View Engine, it was the opposite and the logic of a Directive from the `declarations` field was invoked last.

In order to align Ivy and View Engine behavior, this commit updates the logic in which we populate module scope: we first process all imports and after that handle `declarations` field. As a result, in Ivy both use-cases listed above work similar to View Engine.

Resolves .

PR Close 
2020-03-10 14:16:59 -04:00
crisbeto
191e4d15b5 build: fix elements test failures on IE ()
Fixes the following issues which caused the `elements` unit tests to break on IE:
1. `core.js` wasn't included which caused an error about `Promise` and `Symbol` to be thrown.
2. We were using a version of `@webcomponents/custom-elements` which was shipping ES6 code to npm. As a result, IE was throwing a syntax error.

PR Close 
2020-03-10 14:16:34 -04:00
Alex Rickabaugh
983f48136a test(compiler): add a public API guard for the public compiler options ()
This commit adds a public API test which guards against unintentional
changes to the accepted keys in `angularCompilerOptions`.

PR Close 
2020-03-10 14:15:28 -04:00
Alex Rickabaugh
edf881dbf1 refactor(compiler): split core/api.ts into multiple files ()
This commit splits the ngtsc `core` package's api entrypoint, which
previously was a single `api.ts` file, into an api/ directory with multiple
files. This is done to isolate the parts of the API definitions pertaining
to the public-facing `angularCompilerOptions` field in tsconfig.json into a
single file, which will enable a public API guard test to be added in a
future commit.

PR Close 
2020-03-10 14:15:28 -04:00
Alan Agius
64d6f13b87 fix(platform-browser): add missing peerDependency on @angular/animations ()
`@angular/platform-browser/animations` has a dependency on `@angular/animations` however, this is not listed in `peerDependencies`

With this change we add this package as an optional peerDependency as it's only required when using the `@angular/platform-browser/animations` entrypoint.

Fixes 

PR Close 
2020-03-10 13:28:32 -04:00
Andrew Scott
fc71032dc4 test(router): use pageYOffset in testing when scrollY is not available ()
IE 9, 10, and 11 use the non-standard name `pageYOffset` instead of
`scrollY`.

PR Close 
2020-03-10 13:28:04 -04:00
Keen Yee Liau
81cb54fc15 refactor(compiler): optionalOperator -> consumeOptionalOperator ()
PR Close 
2020-03-10 13:27:37 -04:00
ivanwonder
3d46a45fa8 fix(language-service): resolve the variable from the template context first ()
PR Close 
2020-03-10 13:27:04 -04:00
ayazhafiz
406419bc0f fix(language-service): fix calculation of pipe spans ()
This commit accomplishes two tasks:

- Fixes the span of queried pipes to only be applied on pipe names
- By consequence, fixes how pipes are located in arguments (previously,
  pipes with arguments could not be found because the span of a pipe
  uses a relative span, while the template position is absolute)

The screenshots attached to the PR for this commit demonstrate the
change.

Closes https://github.com/angular/vscode-ng-language-service/issues/677

PR Close 
2020-03-10 13:26:40 -04:00
Andrew Kushnir
71309d223d Revert "feat: Monkey patches MessagePort onproperties (onmessage/onmessageerror) ()" ()
This reverts commit 1882451ec03daeebe32f2355030faf7e2f90ae8a.

Reason: breaks some g3 targets.

PR Close 
2020-03-09 17:31:28 -04:00
Matias Niemelä
15482e7367 Revert "feat(bazel): transform generated shims (in Ivy) with tsickle ()" ()
This reverts commit 9ff9a072e62af9aacc3703936e01c984ad44d6d6.

PR Close 
2020-03-09 17:00:14 -04:00
Alex Rickabaugh
9ff9a072e6 feat(bazel): transform generated shims (in Ivy) with tsickle ()
Currently, when Angular code is built with Bazel and with Ivy, generated
factory shims (.ngfactory files) are not processed via the majority of
tsickle's transforms. This is a subtle effect of the build infrastructure,
but it boils down to a TsickleHost method `shouldSkipTsickleProcessing`.

For ngc_wrapped builds (Bazel + Angular), this method is defined in the
`@bazel/typescript` (aka bazel rules_typescript) implementation of
`CompilerHost`. The default behavior is to skip tsickle processing for files
which are not present in the original `srcs[]` of the build rule. In
Angular's case, this includes all generated shim files.

For View Engine factories this is probably desirable as they're quite
complex and they've never been tested with tsickle. Ivy factories however
are smaller and very straightforward, and it makes sense to treat them like
any other output.

This commit adjusts two independent implementations of
`shouldSkipTsickleProcessing` to enable transformation of Ivy shims:

* in `@angular/bazel` aka ngc_wrapped, the upstream `@bazel/typescript`
  `CompilerHost` is patched to treat .ngfactory files the same as their
  original source file, with respect to tsickle processing.

  It is currently not possible to test this change as we don't have any test
  that inspects tsickle output with bazel. It will be extensively tested in
  g3.

* in `ngc`, Angular's own implementation is adjusted to allow for the
  processing of shims when compiling with Ivy. This enables a unit test to
  be written to validate the correct behavior of tsickle when given a host
  that's appropriately configured to process factory shims.

For ngtsc-as-a-plugin, a similar fix will need to be submitted upstream in
tsc_wrapped.

PR Close 
2020-03-09 13:06:33 -04:00
Pete Bacon Darwin
fc4c3c3eb5 fix(localize): merge translation from all XLIFF <file> elements ()
XLIFF translation files can contain multiple `<file>` elements,
each of which contains translations. In ViewEngine all these
translations are merged into a single translation bundle.

Previously in Ivy only the translations from the last `<file>`
element were being loaded. Now all the translations from each
`<file>` are merged into a single translation bundle.

Fixes 

PR Close 
2020-03-09 13:06:05 -04:00
JiaLiPassion
1882451ec0 feat: Monkey patches MessagePort onproperties (onmessage/onmessageerror) ()
Close 

PR Close 
2020-03-09 12:20:46 -04:00
Ayaz Hafiz
11f7e275e6 feat(compiler): type TemplateAst values as ASTWithSource ()
TemplateAst values are currently typed as the base class AST, but they
are actually constructed with ASTWithSource. Type them as such, because
ASTWithSource gives more information about the consumed expression AST
to downstream customers (namely, the expression AST source).

Unblocks 

PR Close 
2020-03-09 12:14:09 -04:00
Pete Bacon Darwin
0e2a577b42 fix(localize): improve matching and parsing of XTB translation files ()
This commit improves the `canParse()` method to check that the file is
valid XML and has the expected root node. Previously it was relying upon
a regular expression to do this.

PR Close 
2020-03-09 12:11:58 -04:00
Pete Bacon Darwin
08071e5634 fix(localize): improve matching and parsing of XLIFF 2.0 translation files ()
Previously, the `Xliff2TranslationParser` only matched files that had a narrow
choice of extensions (e.g. `xlf`) and also relied upon a regular expression
match of an optional XML namespace directive.

This commit relaxes the requirement on both of these and, instead, relies
upon parsing the file into XML and identifying an element of the form
`<xliff version="2.0">` which is the minimal requirement for such files.

PR Close 
2020-03-09 12:11:58 -04:00
Pete Bacon Darwin
350ac11554 fix(localize): improve matching and parsing of XLIFF 1.2 translation files ()
Previously, the `Xliff1TranslationParser` only matched files that had a narrow
choice of extensions (e.g. `xlf`) and also relied upon a regular expression
match of an optional XML namespace directive.

This commit relaxes the requirement on both of these and, instead, relies
upon parsing the file into XML and identifying an element of the form
`<xliff version="1.2">` which is the minimal requirement for such files.

PR Close 
2020-03-09 12:11:58 -04:00
Pete Bacon Darwin
cd32085a75 refactor(localize): allow hints from canParse() to parse() ()
This enables complex work to be done in `TranslationParser.canParse()`
without duplicating the work in `TranslationParser.parse()`.

PR Close 
2020-03-09 12:11:58 -04:00
Pete Bacon Darwin
d88b237f1e refactor(localize): add support for TranslationParser diagnostics ()
This modifies the internal (but shared with CLI) API for loading/parsing
translation files. Now the parsers will return a new `Diagnostics` object
along with any translations and locale extracted from the file.

It is up to the caller to decide what to do about this, if there are errors
it is suggested that an error is thrown, which is what the `TranslationLoader`
class does.

PR Close 
2020-03-09 12:11:58 -04:00
JiaLiPassion
55b3f97be0 fix(zone.js): tickOptions's processNewMacroTasksSynchronously should default to true when flag omitted ()
Calling `tick(0, null)` defaults `processNewMacroTasksSynchronously` flag to `true`, however calling  `tick(0, null, {})` defaults `processNewMacroTasksSynchronously` to `undefined`. This is undesirable behavior since unless the flag is set explicitly it should still default to `true`.

PR Close 
2020-03-06 17:33:57 -05:00
Paul Gschwendtner
958165888c fix(bazel): do not use manifest paths for generated imports within compilation unit ()
Currently, the `ng_module` rule incorrectly uses manifest paths for
generated imports from the Angular compiler.

This breaks packaging as prodmode output (i.e. `esnext`) is copied in
various targets (`es5` and `es2015`) to the npm package output.

e.g. imports are generated like:

_node_modules/my-pkg/es2015/imports/public-api.js_
```ts
import * as i1 from "angular/packages/bazel/test/ng_package/example/imports/second";
```

while it should be actually:

```ts
import * as i1 from "./second";
```

The imports can, and should be relative so that the files are
self-contained and do not rely on custom module resolution.

PR Close 
2020-03-06 17:31:10 -05:00
Paul Gschwendtner
68bebd67f7 test: add entry-point with generated imports to ng_package test ()
PR Close 
2020-03-06 17:31:10 -05:00
JiaLiPassion
86a45ff561 docs(zone.js): update coments of zone configuration API definition ()
PR Close 
2020-03-06 16:55:32 -05:00
JiaLiPassion
84c2458ea7 refactor: cleanup zone.js test instruction ()
PR Close 
2020-03-06 16:53:21 -05:00
Paul Gschwendtner
59607dc495 fix(core): undecorated-classes-with-di migration should handle libraries generated with CLI versions past v6.2.0 ()
The options for `flatModuleId` and `flatModuleOutFile` had been removed in the CLI
from generated libraries with 718ee15b9a.

This has been done because `ng-packagr` (which is used to build the
libraries) automatically set these options in-memory when it compiles the library.
No migration has been created for this because there was no actual need to get rid of
this. Keeping the options in the library `tsconfig` does not cause any problems unless
the `tsconfig` is used outside of `ng-packagr`. This was not anticipated, but is now
commonly done in `ng update` migrations.

The `ng update` migrations try to create an instance of the `AngularCompilerProgram` by
simply parsing the `tsconfig`. The migrations make the valid assumption that `tsconfig` files
are not incomplete/invalid. They _definitely_ are in the file system though. It just works for
libraries because `ng-packagr` in-memory completes the invalid `tsconfig` files, so that they
can be passed to the `@angular/compiler-cli`.

We can't have this logic in the `ng update` migrations because it's
out-of-scope for individual migrations to distinguish between libraries
and applications. Also it would be out-of-scope to parse the
`ng-packagr` configuration and handle the tsconfig in-memory completion.

As a workaround though, we can remove the flat-module bundle options
in-memory when creating the compiler program. This is acceptable since
we don't emit the program and the flat module bundles are not needed.

Fixes .

PR Close 
2020-03-06 12:40:18 -05:00
Keen Yee Liau
bef14cf424 refactor(compiler): rename _ParseAST.optionalCharacter TemplateBinding.expression ()
This commit renames
1. _ParseAST.optionalCharacter -> consumeOptionalCharacter
2. TemplateBinding.expression -> value

PR Close 
2020-03-06 12:39:49 -05:00
ivanwonder
4e1d780554 fix(language-service): resolve the real path for symlink ()
when AOT resolves the module name, it will preserve the path of the symlink, but the ts-server will return the real path for symlink.

PR Close 
2020-03-06 12:38:55 -05:00
Joey Perrott
a1b90619ba test(zone.js): sets rollup_bundle to use the --silent flag in karma tests ()
PR Close 
2020-03-06 12:37:55 -05:00
Pete Bacon Darwin
c55f900081 fix(ngcc): a new LockFile implementation that uses a child-process ()
This version of `LockFile` creates an "unlocker" child-process that monitors
the main ngcc process and deletes the lock file if it exits unexpectedly.

This resolves the issue where the main process could not be killed by pressing
Ctrl-C at the terminal.

Fixes 

PR Close 
2020-03-05 18:17:15 -05:00
Pete Bacon Darwin
4acd658635 refactor(ngcc): move locking code into its own folder ()
PR Close 
2020-03-05 18:17:15 -05:00
Pete Bacon Darwin
94fa140888 refactor(ngcc): separate (Async/Sync)Locker and LockFile ()
The previous implementation mixed up the management
of locking a piece of code (both sync and async) with the
management of writing and removing the lockFile that is
used as the flag for which process has locked the code.

This change splits these two concepts up. Apart from
avoiding the awkward base class it allows the `LockFile`
implementation to be replaced cleanly.

PR Close 
2020-03-05 18:17:15 -05:00
Pete Bacon Darwin
bdaab4184d refactor(ngcc): expose logging level on the logger ()
PR Close 
2020-03-05 18:17:15 -05:00
Matias Niemelä
98a9daf4f4 Revert "fix(router): state data missing in routerLink ()" ()
This reverts commit de67978a7d0d867ccbb91615a09e4471584569da.

PR Close 
2020-03-05 17:43:03 -05:00
Keen Yee Liau
716d50aa21 refactor(compiler): Break up parseTemplateBindings() for microsyntax ()
This commit is purely a refactoring of the logic in
`parseTemplateBindings` method for parsing the microsyntax expression.
This is done to enable the introduction of `keySpan` and `valueSpan` in
subsequent PR.

For a detailed explanation of this work and the subsequent work items,
please see https://docs.google.com/document/d/1mEVF2pSSMSnOloqOPQTYNiAJO0XQxA1H0BZyESASOrE/edit?usp=sharing

PR Close 
2020-03-05 16:04:41 -05:00
Alan Agius
e0a35e13d5 perf(ngcc): reduce directory traversing ()
This reduces the time that `findEntryPoints` takes from 9701.143ms to 4177.278ms, by reducing the file operations done.

Reference: 

PR Close 
2020-03-05 15:57:31 -05:00
JiaLiPassion
8ef29b65ff fix: fix flaky test cases of passive events ()
PR Close 
2020-03-05 15:56:53 -05:00
Santosh Yadav
de67978a7d fix(router): state data missing in routerLink ()
Fixes 33173

PR Close 
2020-03-04 16:51:13 -05:00
Andrew Scott
25ab4647c5 Revert "fix(animations): process shorthand margin and padding styles correctly ()" ()
This reverts commit 35c9f0dc2f3665d4f9d9ece328cee4559bbec9c6, breaks
internal tests

PR Close 
2020-03-04 18:22:09 +00:00
Andrew Scott
3ce5be7715 Revert "fix(animations): allow computeStyle to work on elements created in Node ()" ()
This reverts commit 17cf04ebea6a7d2857881c13140af4ba0ffb6990;
breaking internal tests.

PR Close 
2020-03-04 18:22:09 +00:00
Yiting Wang
c296bfcaf9 fix(compiler-cli): suppress extraRequire errors in Closure Compiler ()
This is needed to support https://github.com/angular/tsickle/pull/1133
because it will add an extra require on `tslib`.

PR Close 
2020-03-04 08:37:03 -08:00
Andrew Scott
d543b13e5c Revert "fix(core): log error instead of warning for unknown properties and elements ()" ()
This reverts commit 00f3c58bb929d9afa10ab3c4f1b9ee7a0077ba57.
Rolling back because it could be breaking e2e tests that assert that
there are no errors in the console after the assertions have run. We can
re-add this in v10.

PR Close 
2020-03-03 16:02:58 -08:00
crisbeto
00f3c58bb9 fix(core): log error instead of warning for unknown properties and elements ()
Changes the Ivy unknown element/property messages from being logged with `console.warn` to `console.error`. This should make them a bit more visible without breaking existing apps. Furthermore, a lot of folks filter out warning messages in the dev tools' console, whereas errors are usually still shown.

Fixes .

PR Close 
2020-03-03 13:55:22 -08:00
Joey Perrott
ed44073a58 build(zone.js): sets rollup_bundle to use the --silent flag ()
Using the --silent flag prevents the spammy logging messages in the
bazel execution logs.

```
INFO: From Bundling JavaScript packages/zone.js/dist/zone-rollup.umd.js [rollup]:

bazel-out/k8-fastbuild/bin/packages/zone.js/lib/browser/rollup-legacy-main.mjs → bazel-out/k8-fastbuild/bin/packages/zone.js/dist/zone-rollup.umd.js...
created bazel-out/k8-fastbuild/bin/packages/zone.js/dist/zone-rollup.umd.js in 736ms
```

PR Close 
2020-03-03 13:53:52 -08:00
Alex Rickabaugh
2c41bb8490 fix(compiler): type-checking error for duplicate variables in templates ()
It's an error to declare a variable twice on a specific template:

```html
<div *ngFor="let i of items; let i = index">
</div>
```

This commit introduces a template type-checking error which helps to detect
and diagnose this problem.

Fixes 

PR Close 
2020-03-03 13:52:50 -08:00
crisbeto
1f8a243b67 fix(core): unable to NgModuleRef.injector in module constructor ()
This is a follow up to  which resolved a similar issue for `ComponentFactoryResolver`, but not the root cause. When a `NgModuleRef` is created, it instantiates an `Injector` internally which in turn resolves all of injector types. This can result in a circular call that results in an error, because the module is one of the injector types being resolved.

These changes work around the issue by allowing the constructor to run before resolving the injector types.

Fixes .
Fixes .

PR Close 
2020-03-03 13:51:51 -08:00
Matias Niemelä
17cf04ebea fix(animations): allow computeStyle to work on elements created in Node ()
This patch is a follow-up patch to 35c9f0dc2f3665d4f9d9ece328cee4559bbec9c6.
It changes the `computeStyle` function to handle situations where
non string based values are returned from `window.getComputedStyle`.
This situation usually ocurrs in Node-based test environments where
the element or `window.getComputedStyle` is mocked out.

PR Close 
2020-03-03 13:38:26 -08:00
Andrew Scott
c7d0567d37 Revert "docs: add comment markers for internal goog.define replacement ()" ()
This reverts commit 32b6c2285e9b3cdcc860e6e87092b54865e12694 as this is
no longer used.

PR Close 
2020-03-03 09:34:17 -08:00
Paul Gschwendtner
5615928df9 build: no longer run tslint from within gulp task ()
Switches our tslint setup to the standard `tslint.json` linter excludes.
The set of files that need to be linted is specified through a Yarn script.

For IDEs, open files are linted with the closest tslint configuration, if the
tslint IDE extension is set up, and the source file is not excluded.

We cannot use the language service plugin for tslint as we have multiple nested
tsconfig files, and we don't want to add the plugin to each tsconfig. We
could reduce that bloat by just extending from a top-level tsconfig that
defines the language service plugin, but unfortunately the tslint plugin does
not allow the use of tslint configs which are not part of the tsconfig project.

This is problematic since the tslint configuration is at the project root, and we
don't want to copy tslint configurations next to each tsconfig file.

Additionally, linting of `d.ts` files has been re-enabled. This has been
disabled in the past and a TODO has been left. This commit fixes the
lint issues and re-enables linting.

PR Close 
2020-03-03 09:20:49 -08:00
Paul Gschwendtner
5349e46b46 build: update tslint to latest version ()
The old version we currently use does not properly implement the
option to exclude files from within the `tslint.json` file.

PR Close 
2020-03-03 09:20:48 -08:00