For super calls to work in IE9, you must enable "loose" mode for the class transform. For inherited static properties to work in IE9, you must also add the babel-plugin-transform-proto-to-assign
plugin.
Last active
September 30, 2016 15:39
-
-
Save zertosh/4f818163e4d68d58c0fa to your computer and use it in GitHub Desktop.
solution - super() not calling parent's constructor on IE9 - https://github.com/babel/babelify/issues/133
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var browserify = require('browserify'); | |
browserify('./index.js') | |
.transform('babelify', { | |
plugins: [ | |
'transform-es2015-block-scoping', | |
['transform-es2015-classes', {loose: true}], | |
'transform-proto-to-assign', | |
], | |
}) | |
.bundle() | |
.pipe(fs.createWriteStream('./out.js')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class test { | |
constructor() { | |
console.log('test'); | |
} | |
} | |
class test2 extends test { | |
constructor() { | |
super(); | |
console.log('test2'); | |
} | |
} | |
new test2(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | |
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | |
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var test = function test() { | |
_classCallCheck(this, test); | |
console.log('test'); | |
}; | |
var test2 = function (_test) { | |
_inherits(test2, _test); | |
function test2() { | |
_classCallCheck(this, test2); | |
var _this = _possibleConstructorReturn(this, _test.call(this)); | |
console.log('test2'); | |
return _this; | |
} | |
return test2; | |
}(test); | |
new test2(); | |
},{}]},{},[1]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "ie9-class-inherit-super-demo", | |
"version": "0.0.0", | |
"description": "https://github.com/babel/babelify/issues/133", | |
"scripts": { | |
"build": "node build.js", | |
"test": "node out.js" | |
}, | |
"author": "Andres Suarez <[email protected]>", | |
"license": "MIT", | |
"dependencies": { | |
"babel": "^6.3.26", | |
"babel-plugin-transform-es2015-block-scoping": "^6.4.0", | |
"babel-plugin-transform-es2015-classes": "^6.4.0", | |
"babel-plugin-transform-proto-to-assign": "^6.4.0", | |
"babelify": "^7.2.0", | |
"browserify": "^13.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're a life saver. Took me forever to hunt down this bug -- this solution worked for me.