Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve correct
this
for named/default imports (#7956)
- Loading branch information
Showing
9 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/core/integration-tests/test/integration/js-import-this/index.js
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,17 @@ | ||
import returnThisDefault, { returnThis } from "./other.js"; | ||
import * as other from "./other.js"; | ||
|
||
import returnThisWrappedDefault, { returnThis as returnThisWrapped } from "./other-wrapped.js"; | ||
import * as otherWrapped from "./other-wrapped.js"; | ||
|
||
let result = { | ||
unwrappedNamed: returnThis(), | ||
unwrappedDefault: returnThisDefault(), | ||
unwrappedNamespace: other.returnThis(), | ||
wrappedNamed: returnThisWrapped(), | ||
wrappedDefault: returnThisWrappedDefault(), | ||
wrappedNamespace: otherWrapped.returnThis(), | ||
}; | ||
|
||
output = result; | ||
export default result; |
13 changes: 13 additions & 0 deletions
13
packages/core/integration-tests/test/integration/js-import-this/other-wrapped.js
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,13 @@ | ||
import * as ns from "./other-wrapped.js"; | ||
|
||
let y = typeof module !== "undefined" ? module : {}; | ||
|
||
export function returnThis() { | ||
if (y != null) { | ||
return [this === undefined, this === ns]; | ||
} else { | ||
throw new Error(); | ||
} | ||
} | ||
|
||
export default returnThis; |
7 changes: 7 additions & 0 deletions
7
packages/core/integration-tests/test/integration/js-import-this/other.js
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,7 @@ | ||
import * as ns from "./other.js"; | ||
|
||
export function returnThis() { | ||
return [this === undefined, this === ns]; | ||
} | ||
|
||
export default returnThis; |
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
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