TrySound / babel-plugin-iife-wrap

Babel plugin to wrap file with iife
MIT License
6 stars 2 forks source link

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

Open AlexanderOtavka opened 8 years ago

AlexanderOtavka commented 8 years ago

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.

magicznyleszek commented 7 years ago

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

rluba commented 7 years ago

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',
            ],
}
TrySound commented 7 years ago

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

hperrin commented 6 years ago

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

hperrin commented 6 years ago

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

TypeError: _typeof is not a function
davidshepherd7 commented 6 years ago

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