-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flow] Explicitly unsoundly unbind methods during cjs exports extraction
Summary: Normally, given something like ``` declare class Foo { bar(): void } declare const foo: Foo; const {bar} = foo; bar(); ``` we will get a method-unbinding error. However, this error is hidden if the code is in the following form due to CJS-ESM export extraction magic (likely unintentional). ``` // a.js declare class Foo { bar(): void } declare const foo: Foo; module.exports = foo; // b.js import {bar} from './a'; bar(); ``` Right now, there are way too many existing code that depends on this unsoundness issue, which is blocking me from fixing the issue of inconsistent this-typing for class methods. Therefore, in this diff, I decide to formally codify the unsoundness issue in the code for CJS exports extraction, instead of relying on other bugs that accidentally does this. Changelog: [internal] Reviewed By: gkz Differential Revision: D68961697 fbshipit-source-id: 36b33d3b359952ef780b62da5c4fc9fe19f27b27
- Loading branch information
1 parent
fa03a66
commit 60cfefd
Showing
4 changed files
with
41 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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,10 @@ | ||
class Foo { | ||
#v: string = ''; | ||
|
||
foo(): string { | ||
return this.#v; | ||
} | ||
} | ||
|
||
const instance: Foo = new Foo(); | ||
module.exports = instance; |
This file contains 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,2 @@ | ||
import {foo} from './unsound_extract_exports'; // TODO unsound: no method-unbinding error | ||
foo(); |