does not work with babel-plugin-transform-builtin-extend
See original GitHub issueI’ve got a source file, myError.js
, being transpiled with babel-plugin-transform-builtin-extend
:
export default class MyError extends Error {
constructor() {
super('this is a MyError');
}
}
{
"presets": [
[ "es2015" ]
],
"plugins": [
[ "transform-builtin-extend", {
"globals": [ "Error" ]
} ]
]
}
the result is a file containing this:
/* _classCallCheck, _possibleConstructorReturn, etc. omitted for brevity... */
function _extendableBuiltin(cls) {
/* some magic provided by transform-builtin-extend */
// ...
}
var MyError = function (_extendableBuiltin2) {
_inherits(MyError, _extendableBuiltin2);
function MyError() {
_classCallCheck(this, MyError);
return _possibleConstructorReturn(this, (MyError.__proto__ || Object.getPrototypeOf(MyError)).call(this, "this is a MyError"));
}
return MyError;
}(_extendableBuiltin(Error));
But when I add istanbul
to my list of plugins in .babelrc
…
"plugins": [
[ "transform-builtin-extend", {
"globals": [ "Error" ]
- } ]
+ } ],
+ [ "istanbul" ]
]
…some of the code generated by transform-builtin-extend
seems to be missing:
/* _classCallCheck and friends are still present */
/* the '_extendableBuiltin' function is now gone :( */
var MyError = function (_ref) {
_inherits(MyError, _ref);
function MyError() {
_classCallCheck(this, MyError);
cov_1jzxyjd0v8.f[0]++;
cov_1jzxyjd0v8.s[0]++;
return _possibleConstructorReturn(this, (MyError.__proto__ || Object.getPrototypeOf(MyError)).call(this, "this is a MyError"));
}
return MyError;
}((Error)) // <-- no longer a function call, but instead an object reference
Applying istanbul
without transform-builtin-extend
results in the same output as described above; rearranging the order of my babel plugins does too.
I suspect the problem might be somewhere in istanbul-lib-instrument
as that’s where the visitor enter and exit functions are built? But I’m not 100% sure.
I’m running node 8.9.3 with these packages:
"dependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-istanbul": "^4.1.5",
"babel-plugin-transform-builtin-extend": "^1.1.2",
"babel-preset-es2015": "^6.24.1",
"jest": "^22.0.3"
}
thanks for any help you can provide!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:7
Top Results From Across the Web
babel-plugin-transform-builtin-extend - npm
A plugin for Babel 6 supports extending from builtin types based on static analysis.. Latest version: 1.1.2, last published: 6 years ago.
Read more >transform-builtin-extend seems does not working
@Bergi In Firefox and Chrome new class MyFormData extends FormData {} works fine. – Michał Perłakowski. Sep 18, 2016 at 12:24.
Read more >babel/plugin-transform-classes - Babel.js
When extending a native class (e.g., class extends Array {} ), the super class needs to be wrapped. This is needed to workaround...
Read more >babel-plugin-transform-builtin-extend - npm package - Snyk
Learn more about babel-plugin-transform-builtin-extend: package health score, ... not work on IE<=10 and any other browsers that don't support __proto__ .
Read more >babel-plugin-transform-builtin-extend | Yarn - Package Manager
Babel Builtin Constructor extension plugin. This is a Babel 6 plugin to enable extending builtin types like "Error" and "Array" and such, which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is a workaround for this issue.
Use babel-plugin-transform-builtin-extend, but for any subclasses extending built-ins like
Error
orArray
, you need to explicitly defineconstructor
and__proto__
, as described by @xpl in this issue comment.Is there a workaround for babel 7? The workarounds mentioned above don’t seem to work 😦