Commit Graph

1159 Commits

Author SHA1 Message Date
Daniel Trevino 9a0a2b6e75 refactor(compiler-cli): visit inputs and outputs for elements and templates (#42984)
This commit adds to the exisiting `RecursiveVisitor` and visits inputs
and outputs for elements and templates.

Refs #42966

PR Close #42984
2021-08-10 15:55:49 -07:00
atscott 9436f4bf77 Revert "refactor(compiler): remove cyclic dependencies (#42062)" (#43033)
This reverts commit 75855196e3.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott dda75ca1d0 Revert "refactor(compiler): support interpolation tokens when lexing markup (#42062)" (#43033)
This reverts commit c8a46bfdcd.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott 443ece4587 Revert "refactor(compiler): share `isQuote()` via `chars.ts` (#42062)" (#43033)
This reverts commit 3d3b69ff81.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott 77731b8fe8 Revert "refactor(compiler): support interpolation tokens when lexing attribute values (#42062)" (#43033)
This reverts commit c516e252fc.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott 8d8ab4775c Revert "refactor(compiler): support encoded entity tokens when lexing markup (#42062)" (#43033)
This reverts commit 942b24d5ea.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott ea5ed4e4d4 Revert "refactor(compiler): expose token parts in Text nodes (#42062)" (#43033)
This reverts commit 8a54896a91.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott 6f05dd8062 Revert "test(compiler): check `fullStart` source-span (#42062)" (#43033)
This reverts commit 973f9b8d19.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott dd82bbfa27 Revert "fix(compiler): include leading whitespace in source-spans of i18n messages (#42062)" (#43033)
This reverts commit f08516db09.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott 8b6f7ac36b Revert "refactor(compiler): define interfaces for each lexer token (#42062)" (#43033)
This reverts commit 9b3d4f5575.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott fac6ea5fae Revert "test(compiler): check that the parser supports prematurely terminated interpolations (#42062)" (#43033)
This reverts commit 11ebe21d0d.

PR Close #43033
2021-08-03 15:38:54 -07:00
atscott 28651eb9c1 Revert "refactor(compiler): use `===` rather than `==` in the ml_parser (#42062)" (#43033)
This reverts commit 28b0c45fde.

PR Close #43033
2021-08-03 15:38:53 -07:00
atscott f85b5f9dbd Revert "test(compiler): add a test for parsing multiline expressions in attributes (#42062)" (#43033)
This reverts commit fe12651580.

PR Close #43033
2021-08-03 15:38:53 -07:00
Pete Bacon Darwin fe12651580 test(compiler): add a test for parsing multiline expressions in attributes (#42062)
This tests a scenario that was failing in an internal project.

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin 28b0c45fde refactor(compiler): use `===` rather than `==` in the ml_parser (#42062)
This is a simple tidy up commit to move to the more specific `===`
comparison operator in the HTML lexer/parser.

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin 11ebe21d0d test(compiler): check that the parser supports prematurely terminated interpolations (#42062)
Such interpolations turned up during internal testing at Google, so this
commit adds a test to prevent regressions.

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin 9b3d4f5575 refactor(compiler): define interfaces for each lexer token (#42062)
These token interfaces will make it easier to reason about tokens in the
parser and in specs.

Previously, it was never clear what items could appear in the `parts`
array of a token given a particular `TokenType`. Now, each token interface
declares a labelled tuple for the parts, which helps to document the token
better.

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin f08516db09 fix(compiler): include leading whitespace in source-spans of i18n messages (#42062)
Previously, the way templates were tokenized meant that we lost information
about the location of interpolations if the template contained encoded HTML
entities. This meant that the mapping back to the source interpolated strings
could be offset incorrectly.

Also, the source-span assigned to an i18n message did not include leading
whitespace. This confused the output source-mappings so that the first text
nodes of the message stopped at the first non-whitespace character.

This commit makes use of the previous refactorings, where more fine grain
information was provided in text tokens, to enable the parser to identify
the location of the interpolations in the original source more accurately.

Fixes #41034

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin 973f9b8d19 test(compiler): check `fullStart` source-span (#42062)
The tests were checking that the source-span of parsed HTML nodes were
accurate, but they were not checking the span when it includes the
"leading trivia", which are given by the `fullStart` rather than `start`
location.

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin 8a54896a91 refactor(compiler): expose token parts in Text nodes (#42062)
When it was tokenized, text content is split into parts that can include
interpolations and encoded entities tokens.

To make this information available to downstream processing, this commit
adds these tokens to the `Text` AST nodes, with suitable processing.

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin 942b24d5ea refactor(compiler): support encoded entity tokens when lexing markup (#42062)
The lexer now splits encoded entity tokens out from text and attribute value tokens.

Previously encoded entities would be decoded and the decoded value would be
included as part of the text token of the surrounding text. Now the entities
have their own tokens. There are two scenarios: text and attribute values.

Previously the contents of `<div>Hello &amp; goodbye</div>` would be a single
TEXT token. Now it will be three tokens:

```
TEXT: "Hello "
ENCODED_ENTITY: "&", "&amp;"
TEXT: " goodbye"
```

Previously the attribute value in `<div title="Hello &amp; goodbye">` would be
a single text token. Now it will be three tokens:

```
ATTR_VALUE_TEXT: "Hello "
ENCODED_ENTITY: "&", "&amp;"
ATTR_VALUE_TEXT: " goodbye"
```

- ENCODED_ENTITY tokens have two parts: "decoded" and "encoded".
- ENCODED_ENTITY tokens are always preceded and followed by either TEXT tokens
  or ATTR_VALUE_TEXT tokens, depending upon the context, even if they represent
  an empty string.

The HTML parser has been modified to recombine these tokens to allow this
refactoring to have limited effect in this commit. Further refactorings
to use these new tokens will follow in subsequent commits.

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin c516e252fc refactor(compiler): support interpolation tokens when lexing attribute values (#42062)
The lexer now splits interpolation tokens out from attribute value tokens.
Previously the attribute value of `<div attr="Hello, {{ name}}">` would be a single
token. Now it will be three tokens:

```
ATTR_VALUE_TEXT: "Hello, "
ATTR_VALUE_INTERPOLATION: "{{", " name", "}}"
ATTR_VALUE_TEXT: ""
```

- ATTR_VALUE_INTERPOLATION tokens have three parts, "start marker",
  "expression" and "end marker".
- ATTR_VALUE_INTERPOLATION tokens are always preceded and followed
  by TEXT tokens, even if they represent an empty string.

The HTML parser has been modified to recombine these tokens to allow this
refactoring to have limited effect in this commit. Further refactorings
to use these new tokens will follow in subsequent commits.

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin 3d3b69ff81 refactor(compiler): share `isQuote()` via `chars.ts` (#42062)
This function is general purpose and by moving it into the
`chars.ts` file along with similar helpers, it can be reused
in the lexer, for instance.

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin c8a46bfdcd refactor(compiler): support interpolation tokens when lexing markup (#42062)
The lexer now splits interpolation tokens out from text tokens.

Previously the contents of `<div>Hello, {{ name}}<div>` would be a single
text token. Now it will be three tokens:

```
TEXT: "Hello, "
INTERPOLATION: "{{", " name", "}}"
TEXT: ""
```

- INTERPOLATION tokens have three parts, "start marker", "expression"
  and "end marker".
- INTERPOLATION tokens are always preceded and followed by TEXT tokens,
  even if they represent an empty string.

The HTML parser has been modified to recombine these tokens to allow this
refactoring to have limited effect in this commit. Further refactorings
to use these new tokens will follow in subsequent commits.

PR Close #42062
2021-08-02 09:53:13 -07:00
Pete Bacon Darwin 75855196e3 refactor(compiler): remove cyclic dependencies (#42062)
This commit removes 9 cycles in the dependency graph of the compiler code.

PR Close #42062
2021-08-02 09:53:12 -07:00
Alex Rickabaugh d8183c94d4 refactor(compiler): remove unnecessary escapes (#42990)
This commit is part of a larger scale change to eliminate unnecessary
escapes in string literals, in advance of enabling stricter checks in
`ts_library` rules in g3.

PR Close #42990
2021-07-30 09:28:46 -07:00
Minko Gechev f5baa55b81 docs: remove reference to an obsolete design doc (#42842)
The type checking design document is no longer relevant. This PR
removes the reference to it. Close #42424.

PR Close #42842
2021-07-15 13:24:58 -07:00
Kristiyan Kostadinov b33665ab2c fix(compiler): add mappings for all HTML entities (#42818)
Angular inserts text either through text nodes (`document.createTextNode`) or using `textContent`, but the drawback of doing so is that HTML entities won't be decoded. In order to work around it, the compiler has some logic that maps the entities to their unicode representation which can safely be inserted. The problem is that our current mapping is arbitrarily limited which means that some entities will be mapped while others will throw an error, even though they're valid.

These changes expand the list to cover all entities that are supported by the HTML spec.

Fixes #41186.

PR Close #42818
2021-07-12 14:41:20 -07:00
Paul Gschwendtner b5ab7aff43 refactor: add override keyword to members implementing abstract declarations (#42512)
In combination with the TS `noImplicitOverride` compatibility changes,
we also want to follow the best-practice of adding `override` to
members which are implemented as part of abstract classes. This
commit fixes all instances which will be flagged as part of the
custom `no-implicit-override-abstract` TSLint rule.

PR Close #42512
2021-07-12 13:11:17 -07:00
Paul Gschwendtner 96c93260a2 refactor(compiler): ensure compatibility with noImplicitOverride (#42512)
Adds the `override` keyword to the `compiler` sources to ensure
compatibility with `noImplicitOverride`.

PR Close #42512
2021-07-12 13:11:14 -07:00
Kristiyan Kostadinov 404c8d0d88 fix(compiler): incorrect context object being referenced from listener instructions inside embedded views (#42755)
Currently unless a listener inside of an embedded view tries to reference something from the parent view, or if the reference is a local ref, we don't generate the view restoration instructions and we allow for the value to be picked up from the context object in the function parameters. The problem is that the listener is only run during creation mode and the context object may have been swapped out afterwards.

These changes fix the issue by always generating the view restoration instructions for listeners inside templates.

Fixes #42698.

PR Close #42755
2021-07-12 11:58:18 -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
dario-piotrowicz 56fb4eb08d docs(compiler): interally typo fixed (#42676)
PR Close #42676
2021-06-28 09:32:23 -07: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
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 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
Andrew Scott 8c1e0e6ad0 fix(compiler): always match close tag to the nearest open element (#42554)
This commit updates the parser logic to continue to try to match an end
tag to an unclosed open tag on the stack. Previously, it would only
push an error to the list and stop looking at unclosed elements.

For example, the invalid HTML of `<li><div></li>`, has an unclosed
element stack of [`li`, `div`] when it encounters the close `li` tag.
We compare against the previously unclosed tag `div` and see that this is
unexpected. Instead of simply giving up here, we continue to move up the
unclosed tags until we find a match (if there is one).

PR Close #42554
2021-06-14 14:10:46 -07:00
Paul Gschwendtner 25f763cff8 feat(core): support TypeScript 4.3 (#42022)
Switches the repository to TypeScript 4.3 and the latest
version of tslib. This involves updating the peer dependency
ranges on `typescript` for the compiler CLI and for the Bazel
package. Tests for new TypeScript features have been added to
ensure compatibility with Angular's ngtsc compiler.

PR Close #42022
2021-06-04 11:17:09 -07:00
Kristiyan Kostadinov ba084857ea feat(compiler): support safe keyed read expressions (#41911)
Currently we support safe property (`a?.b`) and method (`a?.b()`) accesses, but we don't handle safe keyed reads (`a?.[0]`) which is inconsistent. These changes expand the compiler in order to support safe key read expressions as well.

PR Close #41911
2021-06-03 13:22:41 -07:00
Kristiyan Kostadinov a787f78074 test: clean up internal testing utilities (#42177)
We have some internal proxies for all of the Jasmine functions, as well as some other helpers. This code hasn't been touched in more than 5 years, it can lead to confusion and it isn't really necessary since the same can be achieved using Jasmine.

These changes remove most of the code and clean up our existing unit tests.

PR Close #42177
2021-05-26 20:07:25 +00:00
Joey Perrott e29afbc373 build(compiler): update supported range of node versions to be less restrictive (#42205)
Update the supported range of node versions for to be less restrictive, no longer causing
yarn or npm to fail engine's checks for future versions of node.

While this change will no longer cause yarn or npm to fail these engine's check, this does
not reflect a change in the officially supported versions of node for Angular.  Angular
continues to maintain support for Active LTS and Maintenance LTS versions of node.

PR Close #42205
2021-05-25 17:48:45 +00:00
Joey Perrott 2dd956421c build: remove publishConfig entry from package.json entries (#42104)
Remove publishConfig property from the package.json entry for each of the entries in
the publish configuration.  Using the wombat proxy is now ensured/managed by the
ng-dev release tooling.

PR Close #42104
2021-05-18 15:41:33 -07:00
Paul Gschwendtner 3c726c3516 fix(compiler): unclear lexer error when using private identifier in expressions (#42027)
TypeScript supports ECMAScript private identifiers. It can happen that
developers intend to access such members from within an expression.

This currently results in an unclear error from the lexer. e.g.

```
'Parser Error: Unexpected token # at column 1 in [{{#myField}}] in C:/test.ts@5:2
```

We could improve such errors by tokenizing private identifiers similar to
how the TypeScript scanner processes them. Later we can report better
errors in the expression parser or in the typecheck block. This commit
causes all private identifier tokens to be disallowed, so it never
reaches the type checker. This is done intentionally as private
identifiers should not be considered valid Angular syntax, especially
because private fields are not guaranteed to be accessible from within
a component/directive definition (e.g. there cases where a template
function is generated outside of the class; which results in private
members not being accessible; and this results in mixed/confusing
behavior).

Fixes #36003.

PR Close #42027
2021-05-18 10:15:12 -07:00
Alex Rickabaugh a74eb52589 Revert "refactor(core): optimize calls to `split` and `slice` while computing version parts (#41208)"
This reverts commit 744bd2b64f.

This commit seems to cause issues in Safari.
2021-05-12 14:13:50 -04:00
Julien Marcou 744bd2b64f refactor(core): optimize calls to `split` and `slice` while computing version parts (#41208)
Reduce the number of calls made to `split` and `slice` while computing version parts by deconstructing the result.

PR Close #41208
2021-05-10 10:26:34 -04:00
Julien Marcou 562a782114 docs: fix package name in version.ts files in different packages (#41208)
PR Close #41208
2021-05-10 10:26:34 -04:00
Georgii Dolzhykov 209768a570 refactor(compiler): stricter types for HTML AST (#41360)
A Node can only be an instance of one of the six classes.
This relation can be accurately expressed using a union type.

PR Close #41360
2021-05-06 17:34:52 -04:00
Kristiyan Kostadinov abcd4bbfaa fix(compiler): preserve @page rules in encapsulated styles (#41915)
Currently the compiler treats `@page` rules in the same way as `@media`, however that is incorrect and it results in invalid CSS, because `@page` allows style declarations at the root (e.g. `@page (margin: 50%) {}`) and it only allows a limited set of at-rules to be nested into it. Given these restrictions, we can't really encapsulate the styles since they apply at the document level when the user tries to print.

These changes make it so that `@page` rules are preserved so that we don't break the user's CSS.

More information: https://www.w3.org/TR/css-page-3

Fixes #26269.

PR Close #41915
2021-05-06 09:33:56 -04:00
nirmal bhagwani 1758d02972 feat(compiler): support directive selectors with attributes containing `$` (#41567)
This commit adds support for `$` in when selecting attributes.

Resolves #41244.

test(language-service): Add test to expose bug caused by source file change (#41500)

This commit adds a test to expose the bug caused by source file change in
between typecheck programs.

PR Close #41500

PR Close #41567
2021-05-04 21:06:58 -07:00