babel-plugin-iife-wrap
babel-plugin-iife-wrap copied to clipboard
Doesn't work with babel-plugin-transform-es2015-typeof-symbol
I made a gist to demonstrate: https://gist.github.com/AlexanderOtavka/698b83a1ffab9b2141d01b6cd25753c7
Babel will transpile the js file just fine if either the iife-wrap plugin or the transform-es2015-typeof-symbol plugin are commented out, but will not work if they are both present
iife-wrap seems to make transform-es2015-typeof-symbol run twice on the same code but I am not sure exactly what is going on
See for yourself. Download and unzip the gist, then run
npm install && npm start
. It will error. Then comment out one of the two plugins identified by my comments in the gulpfile. Trynpm start
again and watch it compile successfullly, and print "symbol" as it should.
I have the same problem. It took me half a day to pin-point it 😢 For a quick ~fix I've used grunt-iife instead (and it's a bit better for my case).
I had the same problem. You can work around it by using passPerPreset
to run iife-wrap
before the es2015
transforms:
{
passPerPreset: true,
presets: [
{
plugins: ['babel-plugin-iife-wrap'],
},
'babel-preset-es2015',
],
}
I don't have enough time to maintain this project, but I can accept pull request if you are interested in this plugin.
@rluba Thanks for the solution. It worked for me.
For those searching on the Google in the future, the error message I was seeing is:
TypeError: _typeof is not a function
In case it's useful to anyone: you can implement the equivalent transform in a karma preprocessor very easily with karma-generic-preprocessor, something like this:
preprocessors : {
'**/*.js': ['generic', /* other preprocessors here */ ],
},
genericPreprocessor: {
rules: [
// This is the equivalent of what gulp-iife does outside of the tests
{
process: function(content, file, done, log) {
file.path = file.originalPath.replace(/\.js$/g, '.iife.js');
done(`(function() {\n'use strict';\n${content}\n})();`);
},
},
],
},