-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: throw error when targets are used with regenerator
- the polyfill-regenerator plugin actually does not support targets and does not use them - it instead detects whether the `regeneratorRuntime` variable has been injected by `transform-regenerator`, which already supports targets - so targets are not needed twice in that sense - instead of silently ignoring the targets option, error out when it is given as it is an unsupported option - this should hopefully make it easier for developers to realize what's going on when debugging issues with this (as I did) - but it shouldn't error if top-level targets are configured, as those aren't specific to this plugin - caveat: if a user specifies both and they are the same, there's currently no way to tell, so it won't error in that case - but will catch the common mistake - add a test for this new error as well as a basic "harness" based on the one in `define-polyfill-provider` - remove `targets` from any fixtures that had them for this polyfill so that this test passes - and because they didn't do anything previously anyway - also add a test that ensures that top-level targets still work - and change some fixtures to use top-level targets instead, ensuring that those fixture tests still pass as well
- Loading branch information
Showing
7 changed files
with
69 additions
and
26 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 |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
} | ||
] | ||
] | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
} | ||
] | ||
] | ||
} | ||
} |
15 changes: 6 additions & 9 deletions
15
...el-plugin-polyfill-regenerator/test/fixtures/usage-pure/preset-env-supported/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 |
---|---|---|
@@ -1,24 +1,21 @@ | ||
{ | ||
"targets": { | ||
"chrome": 70 | ||
}, | ||
"plugins": [ | ||
[ | ||
"@@/polyfill-regenerator", | ||
{ | ||
"method": "usage-pure", | ||
"targets": { | ||
"chrome": 70 | ||
} | ||
"method": "usage-pure" | ||
} | ||
] | ||
], | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"modules": false, | ||
"targets": { | ||
"chrome": 70 | ||
} | ||
"modules": false | ||
} | ||
] | ||
] | ||
} | ||
} |
15 changes: 6 additions & 9 deletions
15
...-plugin-polyfill-regenerator/test/fixtures/usage-pure/preset-env-unsupported/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 |
---|---|---|
@@ -1,24 +1,21 @@ | ||
{ | ||
"targets": { | ||
"chrome": 40 | ||
}, | ||
"plugins": [ | ||
[ | ||
"@@/polyfill-regenerator", | ||
{ | ||
"method": "usage-pure", | ||
"targets": { | ||
"chrome": 40 | ||
} | ||
"method": "usage-pure" | ||
} | ||
] | ||
], | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"modules": false, | ||
"targets": { | ||
"chrome": 40 | ||
} | ||
"modules": false | ||
} | ||
] | ||
] | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/babel-plugin-polyfill-regenerator/test/options.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,39 @@ | ||
import * as babel from "@babel/core"; | ||
import polyfillRegenerator from "../lib"; | ||
|
||
function transform(code, babelOpts, pluginOpts) { | ||
return babel.transformSync(code, { | ||
configFile: false, | ||
...babelOpts, | ||
plugins: [[polyfillRegenerator, pluginOpts]], | ||
}); | ||
} | ||
|
||
describe("targets", () => { | ||
it("is not supported", () => { | ||
expect(() => | ||
transform( | ||
"code", | ||
{}, | ||
{ | ||
method: "usage-pure", | ||
targets: { chrome: 50 }, | ||
}, | ||
), | ||
).toThrow(/targets/); | ||
}); | ||
}); | ||
|
||
describe("top-level targets", () => { | ||
it("is supported", () => { | ||
expect(() => | ||
transform( | ||
"code", | ||
{ targets: { chrome: 50 } }, | ||
{ | ||
method: "usage-pure", | ||
}, | ||
), | ||
).not.toThrow(/targets/); | ||
}); | ||
}); |