Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/compiler/utilitiesPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,8 @@ function isLeftHandSideExpressionKind(kind: SyntaxKind): boolean {
case SyntaxKind.MetaProperty:
case SyntaxKind.ImportKeyword: // technically this is only an Expression if it's in a CallExpression
case SyntaxKind.MissingDeclaration:
case SyntaxKind.PartiallyEmittedExpression:
case SyntaxKind.AwaitExpression:
return true;
default:
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//// [tests/cases/compiler/partiallyEmittedExpressionLeftHandSide.ts] ////

//// [partiallyEmittedExpressionLeftHandSide.ts]
async function testNonNullWithAwait() {
const result = (await null as any)!;
return result;
}

async function testNonNullWithComplexExpression() {
const obj = { prop: Promise.resolve("test") };
const result = (await obj.prop as string)!;
return result;
}

//// [partiallyEmittedExpressionLeftHandSide.js]
async function testNonNullWithAwait() {
const result = await null;
return result;
}
async function testNonNullWithComplexExpression() {
const obj = { prop: Promise.resolve("test") };
const result = await obj.prop;
return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//// [tests/cases/compiler/partiallyEmittedExpressionLeftHandSide.ts] ////

=== partiallyEmittedExpressionLeftHandSide.ts ===
async function testNonNullWithAwait() {
>testNonNullWithAwait : Symbol(testNonNullWithAwait, Decl(partiallyEmittedExpressionLeftHandSide.ts, 0, 0))

const result = (await null as any)!;
>result : Symbol(result, Decl(partiallyEmittedExpressionLeftHandSide.ts, 1, 9))

return result;
>result : Symbol(result, Decl(partiallyEmittedExpressionLeftHandSide.ts, 1, 9))
}

async function testNonNullWithComplexExpression() {
>testNonNullWithComplexExpression : Symbol(testNonNullWithComplexExpression, Decl(partiallyEmittedExpressionLeftHandSide.ts, 3, 1))

const obj = { prop: Promise.resolve("test") };
>obj : Symbol(obj, Decl(partiallyEmittedExpressionLeftHandSide.ts, 6, 9))
>prop : Symbol(prop, Decl(partiallyEmittedExpressionLeftHandSide.ts, 6, 17))
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))

const result = (await obj.prop as string)!;
>result : Symbol(result, Decl(partiallyEmittedExpressionLeftHandSide.ts, 7, 9))
>obj.prop : Symbol(prop, Decl(partiallyEmittedExpressionLeftHandSide.ts, 6, 17))
>obj : Symbol(obj, Decl(partiallyEmittedExpressionLeftHandSide.ts, 6, 9))
>prop : Symbol(prop, Decl(partiallyEmittedExpressionLeftHandSide.ts, 6, 17))

return result;
>result : Symbol(result, Decl(partiallyEmittedExpressionLeftHandSide.ts, 7, 9))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//// [tests/cases/compiler/partiallyEmittedExpressionLeftHandSide.ts] ////

=== partiallyEmittedExpressionLeftHandSide.ts ===
async function testNonNullWithAwait() {
>testNonNullWithAwait : () => Promise<any>
> : ^^^^^^^^^^^^^^^^^^

const result = (await null as any)!;
>result : any
>(await null as any)! : any
>(await null as any) : any
>await null as any : any
>await null : null
> : ^^^^

return result;
>result : any
}

async function testNonNullWithComplexExpression() {
>testNonNullWithComplexExpression : () => Promise<string>
> : ^^^^^^^^^^^^^^^^^^^^^

const obj = { prop: Promise.resolve("test") };
>obj : { prop: Promise<string>; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
>{ prop: Promise.resolve("test") } : { prop: Promise<string>; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
>prop : Promise<string>
> : ^^^^^^^^^^^^^^^
>Promise.resolve("test") : Promise<string>
> : ^^^^^^^^^^^^^^^
>Promise.resolve : { (): Promise<void>; <T>(value: T): Promise<Awaited<T>>; <T>(value: T | PromiseLike<T>): Promise<Awaited<T>>; }
> : ^^^^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^
>Promise : PromiseConstructor
> : ^^^^^^^^^^^^^^^^^^
>resolve : { (): Promise<void>; <T>(value: T): Promise<Awaited<T>>; <T>(value: T | PromiseLike<T>): Promise<Awaited<T>>; }
> : ^^^^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^
>"test" : "test"
> : ^^^^^^

const result = (await obj.prop as string)!;
>result : string
> : ^^^^^^
>(await obj.prop as string)! : string
> : ^^^^^^
>(await obj.prop as string) : string
> : ^^^^^^
>await obj.prop as string : string
> : ^^^^^^
>await obj.prop : string
> : ^^^^^^
>obj.prop : Promise<string>
> : ^^^^^^^^^^^^^^^
>obj : { prop: Promise<string>; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
>prop : Promise<string>
> : ^^^^^^^^^^^^^^^

return result;
>result : string
> : ^^^^^^
}
12 changes: 12 additions & 0 deletions tests/cases/compiler/partiallyEmittedExpressionLeftHandSide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @target: es2018

async function testNonNullWithAwait() {
const result = (await null as any)!;
return result;
}

async function testNonNullWithComplexExpression() {
const obj = { prop: Promise.resolve("test") };
const result = (await obj.prop as string)!;
return result;
}
Loading