[typeof-symbol] Guard against undefined built-in globals
This commit is contained in:
@@ -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(
|
||||
|
||||
1
packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/input.mjs
vendored
Normal file
1
packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/input.mjs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
typeof Reflect === "object";
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["transform-typeof-symbol"]
|
||||
}
|
||||
@@ -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";
|
||||
6
packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/exec.js
vendored
Normal file
6
packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/exec.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
class MyDate extends Date {
|
||||
constructor(time) {
|
||||
super(time);
|
||||
}
|
||||
}
|
||||
let myDate = new MyDate();
|
||||
6
packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/input.mjs
vendored
Normal file
6
packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/input.mjs
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
class MyDate extends Date {
|
||||
constructor(time) {
|
||||
super(time);
|
||||
}
|
||||
}
|
||||
let myDate = new MyDate();
|
||||
4
packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/options.json
vendored
Normal file
4
packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [],
|
||||
"presets": ["es2015"]
|
||||
}
|
||||
39
packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/output.js
vendored
Normal file
39
packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/output.js
vendored
Normal file
@@ -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();
|
||||
Reference in New Issue
Block a user