mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #9767 from RyanCavanaugh/fix9766
Emit parens around type-asserted binary operators
This commit is contained in:
19
tests/baselines/reference/asOpEmitParens.js
Normal file
19
tests/baselines/reference/asOpEmitParens.js
Normal file
@@ -0,0 +1,19 @@
|
||||
//// [asOpEmitParens.ts]
|
||||
declare var x;
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
|
||||
|
||||
//// [asOpEmitParens.js]
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1) * 3;
|
||||
// Should still emit as x.y
|
||||
x.y;
|
||||
// Emit as new (x())
|
||||
new (x());
|
||||
16
tests/baselines/reference/asOpEmitParens.symbols
Normal file
16
tests/baselines/reference/asOpEmitParens.symbols
Normal file
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/conformance/expressions/asOperator/asOpEmitParens.ts ===
|
||||
declare var x;
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
30
tests/baselines/reference/asOpEmitParens.types
Normal file
30
tests/baselines/reference/asOpEmitParens.types
Normal file
@@ -0,0 +1,30 @@
|
||||
=== tests/cases/conformance/expressions/asOperator/asOpEmitParens.ts ===
|
||||
declare var x;
|
||||
>x : any
|
||||
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
>(x + 1 as number) * 3 : number
|
||||
>(x + 1 as number) : number
|
||||
>x + 1 as number : number
|
||||
>x + 1 : any
|
||||
>x : any
|
||||
>1 : number
|
||||
>3 : number
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
>(x as any).y : any
|
||||
>(x as any) : any
|
||||
>x as any : any
|
||||
>x : any
|
||||
>y : any
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
>new (x() as any) : any
|
||||
>(x() as any) : any
|
||||
>x() as any : any
|
||||
>x() : any
|
||||
>x : any
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
tests/cases/compiler/b.d.ts(2,20): error TS2305: Module '"tests/cases/compiler/a".ns' has no exported member 'IFoo'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.d.ts (0 errors) ====
|
||||
export = ns;
|
||||
|
||||
export as namespace ns;
|
||||
|
||||
declare namespace ns {
|
||||
export var x: number;
|
||||
export interface IFoo { }
|
||||
}
|
||||
|
||||
==== tests/cases/compiler/b.d.ts (1 errors) ====
|
||||
declare namespace ns.something {
|
||||
export var p: ns.IFoo;
|
||||
~~~~
|
||||
!!! error TS2305: Module '"tests/cases/compiler/a".ns' has no exported member 'IFoo'.
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// @filename: a.d.ts
|
||||
export = ns;
|
||||
|
||||
export as namespace ns;
|
||||
|
||||
declare namespace ns {
|
||||
export var x: number;
|
||||
export interface IFoo { }
|
||||
}
|
||||
|
||||
// @filename: b.d.ts
|
||||
declare namespace ns.something {
|
||||
export var p: ns.IFoo;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
declare var x;
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
Reference in New Issue
Block a user