-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix(44639): Transpilation of optional chaining combined with type casting results in function call losing its context #44666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0314c4a
fix(44639): Fix emit for optional chain with type assertions
a-tarasyuk d7d0434
Move ASI-blocking parens out of ts transform
rbuckton 511f959
Add missing comments from PartiallyEmittedExpression+minor cleanup
rbuckton 7e124d9
Avoid comment duplication on copied receiver
rbuckton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/optionalChainingInTypeAssertions(target=es2015).js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//// [optionalChainingInTypeAssertions.ts] | ||
class Foo { | ||
m() {} | ||
} | ||
|
||
const foo = new Foo(); | ||
|
||
(foo.m as any)?.(); | ||
(<any>foo.m)?.(); | ||
|
||
/*a1*/(/*a2*/foo.m as any/*a3*/)/*a4*/?.(); | ||
/*b1*/(/*b2*/<any>foo.m/*b3*/)/*b4*/?.(); | ||
|
||
|
||
//// [optionalChainingInTypeAssertions.js] | ||
var _a, _b, _c, _d; | ||
class Foo { | ||
m() { } | ||
} | ||
const foo = new Foo(); | ||
(_a = foo.m) === null || _a === void 0 ? void 0 : _a.call(foo); | ||
(_b = foo.m) === null || _b === void 0 ? void 0 : _b.call(foo); | ||
/*a1*/ (_c = /*a2*/ foo.m /*a3*/ /*a4*/) === null || _c === void 0 ? void 0 : _c.call(foo); | ||
/*b1*/ (_d = /*b2*/ foo.m /*b3*/ /*b4*/) === null || _d === void 0 ? void 0 : _d.call(foo); |
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/optionalChainingInTypeAssertions(target=es2015).symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
=== tests/cases/conformance/expressions/optionalChaining/optionalChainingInTypeAssertions.ts === | ||
class Foo { | ||
>Foo : Symbol(Foo, Decl(optionalChainingInTypeAssertions.ts, 0, 0)) | ||
|
||
m() {} | ||
>m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
} | ||
|
||
const foo = new Foo(); | ||
>foo : Symbol(foo, Decl(optionalChainingInTypeAssertions.ts, 4, 5)) | ||
>Foo : Symbol(Foo, Decl(optionalChainingInTypeAssertions.ts, 0, 0)) | ||
|
||
(foo.m as any)?.(); | ||
>foo.m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
>foo : Symbol(foo, Decl(optionalChainingInTypeAssertions.ts, 4, 5)) | ||
>m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
|
||
(<any>foo.m)?.(); | ||
>foo.m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
>foo : Symbol(foo, Decl(optionalChainingInTypeAssertions.ts, 4, 5)) | ||
>m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
|
||
/*a1*/(/*a2*/foo.m as any/*a3*/)/*a4*/?.(); | ||
>foo.m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
>foo : Symbol(foo, Decl(optionalChainingInTypeAssertions.ts, 4, 5)) | ||
>m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
|
||
/*b1*/(/*b2*/<any>foo.m/*b3*/)/*b4*/?.(); | ||
>foo.m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
>foo : Symbol(foo, Decl(optionalChainingInTypeAssertions.ts, 4, 5)) | ||
>m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
|
45 changes: 45 additions & 0 deletions
45
tests/baselines/reference/optionalChainingInTypeAssertions(target=es2015).types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
=== tests/cases/conformance/expressions/optionalChaining/optionalChainingInTypeAssertions.ts === | ||
class Foo { | ||
>Foo : Foo | ||
|
||
m() {} | ||
>m : () => void | ||
} | ||
|
||
const foo = new Foo(); | ||
>foo : Foo | ||
>new Foo() : Foo | ||
>Foo : typeof Foo | ||
|
||
(foo.m as any)?.(); | ||
>(foo.m as any)?.() : any | ||
>(foo.m as any) : any | ||
>foo.m as any : any | ||
>foo.m : () => void | ||
>foo : Foo | ||
>m : () => void | ||
|
||
(<any>foo.m)?.(); | ||
>(<any>foo.m)?.() : any | ||
>(<any>foo.m) : any | ||
><any>foo.m : any | ||
>foo.m : () => void | ||
>foo : Foo | ||
>m : () => void | ||
|
||
/*a1*/(/*a2*/foo.m as any/*a3*/)/*a4*/?.(); | ||
>(/*a2*/foo.m as any/*a3*/)/*a4*/?.() : any | ||
>(/*a2*/foo.m as any/*a3*/) : any | ||
>foo.m as any : any | ||
>foo.m : () => void | ||
>foo : Foo | ||
>m : () => void | ||
|
||
/*b1*/(/*b2*/<any>foo.m/*b3*/)/*b4*/?.(); | ||
>(/*b2*/<any>foo.m/*b3*/)/*b4*/?.() : any | ||
>(/*b2*/<any>foo.m/*b3*/) : any | ||
><any>foo.m : any | ||
>foo.m : () => void | ||
>foo : Foo | ||
>m : () => void | ||
|
23 changes: 23 additions & 0 deletions
23
tests/baselines/reference/optionalChainingInTypeAssertions(target=esnext).js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// [optionalChainingInTypeAssertions.ts] | ||
class Foo { | ||
m() {} | ||
} | ||
|
||
const foo = new Foo(); | ||
|
||
(foo.m as any)?.(); | ||
(<any>foo.m)?.(); | ||
|
||
/*a1*/(/*a2*/foo.m as any/*a3*/)/*a4*/?.(); | ||
/*b1*/(/*b2*/<any>foo.m/*b3*/)/*b4*/?.(); | ||
|
||
|
||
//// [optionalChainingInTypeAssertions.js] | ||
class Foo { | ||
m() { } | ||
} | ||
const foo = new Foo(); | ||
foo.m?.(); | ||
foo.m?.(); | ||
/*a1*/ /*a2*/ foo.m /*a3*/ /*a4*/?.(); | ||
/*b1*/ /*b2*/ foo.m /*b3*/ /*b4*/?.(); |
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/optionalChainingInTypeAssertions(target=esnext).symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
=== tests/cases/conformance/expressions/optionalChaining/optionalChainingInTypeAssertions.ts === | ||
class Foo { | ||
>Foo : Symbol(Foo, Decl(optionalChainingInTypeAssertions.ts, 0, 0)) | ||
|
||
m() {} | ||
>m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
} | ||
|
||
const foo = new Foo(); | ||
>foo : Symbol(foo, Decl(optionalChainingInTypeAssertions.ts, 4, 5)) | ||
>Foo : Symbol(Foo, Decl(optionalChainingInTypeAssertions.ts, 0, 0)) | ||
|
||
(foo.m as any)?.(); | ||
>foo.m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
>foo : Symbol(foo, Decl(optionalChainingInTypeAssertions.ts, 4, 5)) | ||
>m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
|
||
(<any>foo.m)?.(); | ||
>foo.m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
>foo : Symbol(foo, Decl(optionalChainingInTypeAssertions.ts, 4, 5)) | ||
>m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
|
||
/*a1*/(/*a2*/foo.m as any/*a3*/)/*a4*/?.(); | ||
>foo.m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
>foo : Symbol(foo, Decl(optionalChainingInTypeAssertions.ts, 4, 5)) | ||
>m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
|
||
/*b1*/(/*b2*/<any>foo.m/*b3*/)/*b4*/?.(); | ||
>foo.m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
>foo : Symbol(foo, Decl(optionalChainingInTypeAssertions.ts, 4, 5)) | ||
>m : Symbol(Foo.m, Decl(optionalChainingInTypeAssertions.ts, 0, 11)) | ||
|
45 changes: 45 additions & 0 deletions
45
tests/baselines/reference/optionalChainingInTypeAssertions(target=esnext).types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
=== tests/cases/conformance/expressions/optionalChaining/optionalChainingInTypeAssertions.ts === | ||
class Foo { | ||
>Foo : Foo | ||
|
||
m() {} | ||
>m : () => void | ||
} | ||
|
||
const foo = new Foo(); | ||
>foo : Foo | ||
>new Foo() : Foo | ||
>Foo : typeof Foo | ||
|
||
(foo.m as any)?.(); | ||
>(foo.m as any)?.() : any | ||
>(foo.m as any) : any | ||
>foo.m as any : any | ||
>foo.m : () => void | ||
>foo : Foo | ||
>m : () => void | ||
|
||
(<any>foo.m)?.(); | ||
>(<any>foo.m)?.() : any | ||
>(<any>foo.m) : any | ||
><any>foo.m : any | ||
>foo.m : () => void | ||
>foo : Foo | ||
>m : () => void | ||
|
||
/*a1*/(/*a2*/foo.m as any/*a3*/)/*a4*/?.(); | ||
>(/*a2*/foo.m as any/*a3*/)/*a4*/?.() : any | ||
>(/*a2*/foo.m as any/*a3*/) : any | ||
>foo.m as any : any | ||
>foo.m : () => void | ||
>foo : Foo | ||
>m : () => void | ||
|
||
/*b1*/(/*b2*/<any>foo.m/*b3*/)/*b4*/?.(); | ||
>(/*b2*/<any>foo.m/*b3*/)/*b4*/?.() : any | ||
>(/*b2*/<any>foo.m/*b3*/) : any | ||
><any>foo.m : any | ||
>foo.m : () => void | ||
>foo : Foo | ||
>m : () => void | ||
|
13 changes: 13 additions & 0 deletions
13
tests/cases/conformance/expressions/optionalChaining/optionalChainingInTypeAssertions.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @target: es2015, esnext | ||
|
||
class Foo { | ||
m() {} | ||
} | ||
|
||
const foo = new Foo(); | ||
|
||
(foo.m as any)?.(); | ||
(<any>foo.m)?.(); | ||
|
||
/*a1*/(/*a2*/foo.m as any/*a3*/)/*a4*/?.(); | ||
/*b1*/(/*b2*/<any>foo.m/*b3*/)/*b4*/?.(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.