Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return rejected promise when stringify import specifier throws (#15290)
Fixes #15261
- Loading branch information
1 parent
6a3421c
commit 64d5a92
Showing
24 changed files
with
149 additions
and
33 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
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-proposal-dynamic-import/test/fixtures/amd/to-string/input.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 @@ | ||
import(2); |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-proposal-dynamic-import/test/fixtures/amd/to-string/output.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,3 @@ | ||
define(["require"], function (_require) { | ||
(specifier => new Promise((_resolve, _reject) => _require([`${specifier}`], imported => _resolve(babelHelpers.interopRequireWildcard(imported)), _reject)))(2); | ||
}); |
1 change: 1 addition & 0 deletions
1
...es/babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-template-literal/1.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 @@ | ||
module.exports = 1; |
3 changes: 3 additions & 0 deletions
3
...babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-template-literal/exec.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,3 @@ | ||
let x = 1; | ||
return expect(import(`./${x}.js`)) | ||
.resolves.toHaveProperty("default", 1); |
5 changes: 5 additions & 0 deletions
5
...-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-template-literal/options.json
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,5 @@ | ||
{ | ||
"parserOpts": { | ||
"allowReturnOutsideFunction": true | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-throw/exec.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,11 @@ | ||
expect(() => { | ||
function f() { throw "should throw"; } | ||
import(f()); | ||
}).toThrow("should throw"); | ||
|
||
expect(() => { | ||
const a = { | ||
get x() { throw "should throw"; }, | ||
}; | ||
import(a.x); | ||
}).toThrow("should throw"); |
6 changes: 6 additions & 0 deletions
6
...ges/babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-to-primitive/exec.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,6 @@ | ||
return expect(import({ | ||
[Symbol.toPrimitive](hint) { | ||
if (hint === "string") return "./foo.js"; | ||
return null; | ||
} | ||
})).resolves.toHaveProperty("default", "foo"); |
1 change: 1 addition & 0 deletions
1
...ages/babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-to-primitive/foo.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 @@ | ||
module.exports = "foo"; |
5 changes: 5 additions & 0 deletions
5
...abel-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-to-primitive/options.json
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,5 @@ | ||
{ | ||
"parserOpts": { | ||
"allowReturnOutsideFunction": true | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ges/babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-to-string-order/1.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 @@ | ||
module.exports = 1; |
7 changes: 7 additions & 0 deletions
7
.../babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-to-string-order/exec.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 @@ | ||
let i = 0; | ||
const promise = expect(import({ toString: () => `./${++i}.js` })) | ||
.resolves.toHaveProperty("default", 1); | ||
expect(i).toBe(1); | ||
++i; | ||
expect(i).toBe(2); | ||
return promise; |
5 changes: 5 additions & 0 deletions
5
...l-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-to-string-order/options.json
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,5 @@ | ||
{ | ||
"parserOpts": { | ||
"allowReturnOutsideFunction": true | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
.../babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-to-string-throw/exec.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,2 @@ | ||
return expect(import({ toString: () => { throw "toString failed"; } })) | ||
.rejects.toBe("toString failed"); |
5 changes: 5 additions & 0 deletions
5
...l-plugin-proposal-dynamic-import/test/fixtures/commonjs/exec-to-string-throw/options.json
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,5 @@ | ||
{ | ||
"parserOpts": { | ||
"allowReturnOutsideFunction": true | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...ges/babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/template-literal/input.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,2 @@ | ||
const x = 1; | ||
import(`./${x}.js`); |
2 changes: 2 additions & 0 deletions
2
...es/babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/template-literal/output.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,2 @@ | ||
const x = 1; | ||
(specifier => new Promise(r => r(specifier)).then(s => babelHelpers.interopRequireWildcard(require(s))))(`./${x}.js`); |
2 changes: 1 addition & 1 deletion
2
packages/babel-plugin-proposal-dynamic-import/test/fixtures/commonjs/to-string/output.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 |
---|---|---|
@@ -1 +1 @@ | ||
Promise.resolve(`${2}`).then(s => babelHelpers.interopRequireWildcard(require(s))); | ||
(specifier => new Promise(r => r(`${specifier}`)).then(s => babelHelpers.interopRequireWildcard(require(s))))(2); |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-proposal-dynamic-import/test/fixtures/systemjs/to-string/input.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 @@ | ||
import(2); |
10 changes: 10 additions & 0 deletions
10
packages/babel-plugin-proposal-dynamic-import/test/fixtures/systemjs/to-string/output.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,10 @@ | ||
System.register([], function (_export, _context) { | ||
"use strict"; | ||
|
||
return { | ||
setters: [], | ||
execute: function () { | ||
(specifier => new Promise(r => r(_context.import(`${specifier}`))))(2); | ||
} | ||
}; | ||
}); |
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