angular-cn/packages/language-service
JoostK 874792dc43 feat(compiler): support unary operators for more accurate type checking (#37918)
Prior to this change, the unary + and - operators would be parsed as `x - 0`
and `0 - x` respectively. The runtime semantics of these expressions are
equivalent, however they may introduce inaccurate template type checking
errors as the literal type is lost, for example:

```ts
@Component({
  template: `<button [disabled]="isAdjacent(-1)"></button>`
})
export class Example {
  isAdjacent(direction: -1 | 1): boolean { return false; }
}
```

would incorrectly report a type-check error:

> error TS2345: Argument of type 'number' is not assignable to parameter
  of type '-1 | 1'.

Additionally, the translated expression for the unary + operator would be
considered as arithmetic expression with an incompatible left-hand side:

> error TS2362: The left-hand side of an arithmetic operation must be of
  type 'any', 'number', 'bigint' or an enum type.

To resolve this issues, the implicit transformation should be avoided.
This commit adds a new unary AST node to represent these expressions,
allowing for more accurate type-checking.

Fixes #20845
Fixes #36178

PR Close #37918
2020-08-21 12:25:53 -07:00
..
bundles build(language-service): remove typescript from ivy bundle (#38088) 2020-07-16 11:04:57 -07:00
ivy refactor(language-service): [Ivy] remove temporary compiler (#38310) 2020-08-17 11:30:33 -07:00
src feat(compiler): support unary operators for more accurate type checking (#37918) 2020-08-21 12:25:53 -07:00
test feat(compiler): support unary operators for more accurate type checking (#37918) 2020-08-21 12:25:53 -07:00
BUILD.bazel build(language-service): Remove ls_rollup_bundle (#38086) 2020-07-16 11:04:28 -07:00
build.sh build(language-service): add script to build package locally (#38103) 2020-07-16 16:39:54 -07:00
index.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
language-service.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
package.json build(language-service): Remove ls_rollup_bundle (#38086) 2020-07-16 11:04:28 -07:00