diff --git a/packages/babel-plugin-transform-typeof-symbol/src/index.js b/packages/babel-plugin-transform-typeof-symbol/src/index.js index 598c841cff..70d1a65ca0 100644 --- a/packages/babel-plugin-transform-typeof-symbol/src/index.js +++ b/packages/babel-plugin-transform-typeof-symbol/src/index.js @@ -50,7 +50,7 @@ export default declare(api => { const call = t.callExpression(helper, [node.argument]); const arg = path.get("argument"); - if (arg.isIdentifier() && !path.scope.hasBinding(arg.node.name)) { + if (arg.isIdentifier() && !path.scope.hasBinding(arg.node.name, true)) { const unary = t.unaryExpression("typeof", t.cloneNode(node.argument)); path.replaceWith( t.conditionalExpression( diff --git a/packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/input.mjs b/packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/input.mjs new file mode 100644 index 0000000000..7cff6b4320 --- /dev/null +++ b/packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/input.mjs @@ -0,0 +1 @@ +typeof Reflect === "object"; \ No newline at end of file diff --git a/packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/options.json b/packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/options.json new file mode 100644 index 0000000000..5730916af9 --- /dev/null +++ b/packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-typeof-symbol"] +} diff --git a/packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/output.mjs b/packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/output.mjs new file mode 100644 index 0000000000..8b1124c31b --- /dev/null +++ b/packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/output.mjs @@ -0,0 +1,3 @@ +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; }; } else { _typeof = function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +(typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object"; diff --git a/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/exec.js b/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/exec.js new file mode 100644 index 0000000000..928ee1da87 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/exec.js @@ -0,0 +1,6 @@ +class MyDate extends Date { + constructor(time) { + super(time); + } +} +let myDate = new MyDate(); diff --git a/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/input.mjs b/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/input.mjs new file mode 100644 index 0000000000..928ee1da87 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/input.mjs @@ -0,0 +1,6 @@ +class MyDate extends Date { + constructor(time) { + super(time); + } +} +let myDate = new MyDate(); diff --git a/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/options.json b/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/options.json new file mode 100644 index 0000000000..12adf73345 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [], + "presets": ["es2015"] +} \ No newline at end of file diff --git a/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/output.js b/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/output.js new file mode 100644 index 0000000000..309d39b134 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/output.js @@ -0,0 +1,39 @@ +"use strict"; + +function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } } + +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _gPO = Object.getPrototypeOf || function _gPO(o) { return o.__proto__; }; + +var _sPO = Object.setPrototypeOf || function _sPO(o, p) { o.__proto__ = p; return o; }; + +var _construct = (typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && Reflect.construct || function _construct(Parent, args, Class) { var Constructor, a = [null]; a.push.apply(a, args); Constructor = Parent.bind.apply(Parent, a); return _sPO(new Constructor(), Class.prototype); }; + +var _cache = typeof Map === "function" && new Map(); + +function _wrapNativeSuper(Class) { if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() {} Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writeable: true, configurable: true } }); return _sPO(Wrapper, _sPO(function Super() { return _construct(Class, arguments, _gPO(this).constructor); }, Class)); } + +var MyDate = +/*#__PURE__*/ +function (_Date) { + _inherits(MyDate, _Date); + + function MyDate(time) { + _classCallCheck(this, MyDate); + + return _possibleConstructorReturn(this, (MyDate.__proto__ || Object.getPrototypeOf(MyDate)).call(this, time)); + } + + return MyDate; +}(_wrapNativeSuper(Date)); + +var myDate = new MyDate();