babel-plugin-iife-wrap icon indicating copy to clipboard operation
babel-plugin-iife-wrap copied to clipboard

Doesn't work with babel-plugin-transform-es2015-typeof-symbol

Open AlexanderOtavka opened this issue 8 years ago • 6 comments

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. Try npm start again and watch it compile successfullly, and print "symbol" as it should.

AlexanderOtavka avatar Apr 10 '16 21:04 AlexanderOtavka

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).

magicznyleszek avatar Sep 27 '16 07:09 magicznyleszek

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',
            ],
}

rluba avatar Aug 21 '17 14:08 rluba

I don't have enough time to maintain this project, but I can accept pull request if you are interested in this plugin.

TrySound avatar Aug 21 '17 18:08 TrySound

@rluba Thanks for the solution. It worked for me.

hperrin avatar Feb 14 '18 21:02 hperrin

For those searching on the Google in the future, the error message I was seeing is:

TypeError: _typeof is not a function

hperrin avatar Feb 14 '18 21:02 hperrin

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})();`);
            },
        },
    ],
},

davidshepherd7 avatar May 09 '18 09:05 davidshepherd7