Skip to content

Instantly share code, notes, and snippets.

@AlexanderOtavka
Created April 10, 2016 20:58
Show Gist options
  • Save AlexanderOtavka/698b83a1ffab9b2141d01b6cd25753c7 to your computer and use it in GitHub Desktop.
Save AlexanderOtavka/698b83a1ffab9b2141d01b6cd25753c7 to your computer and use it in GitHub Desktop.
Example of babel-plugin-iife-wrap issue when combined with babel-plugin-transform-es2015-typeof-symbol.
'use strict';
const gulp = require('gulp');
const babel = require('gulp-babel');
gulp.task('default', () =>
gulp.src('iife-bug-reproduction.js')
.pipe(babel({ plugins: [
// To make it work, either comment out this one...
'iife-wrap',
require('babel-plugin-transform-es2015-template-literals'),
require('babel-plugin-transform-es2015-literals'),
require('babel-plugin-transform-es2015-function-name'),
require('babel-plugin-transform-es2015-arrow-functions'),
require('babel-plugin-transform-es2015-block-scoped-functions'),
require('babel-plugin-transform-es2015-classes'),
require('babel-plugin-transform-es2015-object-super'),
require('babel-plugin-transform-es2015-shorthand-properties'),
require('babel-plugin-transform-es2015-duplicate-keys'),
require('babel-plugin-transform-es2015-computed-properties'),
require('babel-plugin-transform-es2015-for-of'),
require('babel-plugin-transform-es2015-sticky-regex'),
require('babel-plugin-transform-es2015-unicode-regex'),
require('babel-plugin-check-es2015-constants'),
require('babel-plugin-transform-es2015-spread'),
require('babel-plugin-transform-es2015-parameters'),
require('babel-plugin-transform-es2015-destructuring'),
require('babel-plugin-transform-es2015-block-scoping'),
// ...or this one
require('babel-plugin-transform-es2015-typeof-symbol'),
require('babel-plugin-transform-es2015-modules-commonjs'),
[require('babel-plugin-transform-regenerator'), { async: false, asyncGenerators: false }],
]}))
.pipe(gulp.dest('dist/'))
);
// My example es2015 code with typeof Symbol
// Babel will transpile this 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 these three files, put them in a folder, 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.
let mySymbol = Symbol('foo');
console.log(typeof mySymbol);
{
"name": "iife-bug-reproduction",
"version": "1.0.0",
"main": "index.js",
"license": "ISC",
"scripts": {
"start": "gulp && echo '--- BUILD DONE ---' && node dist/iife-bug-reproduction.js"
},
"dependencies": {
"babel-plugin-iife-wrap": "^1.1.0",
"babel-preset-es2015": "^6.6.0",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment