1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 |
|
5 | var _symbol = require("babel-runtime/core-js/symbol");
|
6 |
|
7 | var _symbol2 = _interopRequireDefault(_symbol);
|
8 |
|
9 | exports.default = function (_ref) {
|
10 | var t = _ref.types;
|
11 |
|
12 | var IGNORE = (0, _symbol2.default)();
|
13 |
|
14 | return {
|
15 | visitor: {
|
16 | Scope: function Scope(_ref2) {
|
17 | var scope = _ref2.scope;
|
18 |
|
19 | if (!scope.getBinding("Symbol")) {
|
20 | return;
|
21 | }
|
22 |
|
23 | scope.rename("Symbol");
|
24 | },
|
25 | UnaryExpression: function UnaryExpression(path) {
|
26 | var node = path.node,
|
27 | parent = path.parent;
|
28 |
|
29 | if (node[IGNORE]) return;
|
30 | if (path.find(function (path) {
|
31 | return path.node && !!path.node._generated;
|
32 | })) return;
|
33 |
|
34 | if (path.parentPath.isBinaryExpression() && t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0) {
|
35 | var opposite = path.getOpposite();
|
36 | if (opposite.isLiteral() && opposite.node.value !== "symbol" && opposite.node.value !== "object") {
|
37 | return;
|
38 | }
|
39 | }
|
40 |
|
41 | if (node.operator === "typeof") {
|
42 | var call = t.callExpression(this.addHelper("typeof"), [node.argument]);
|
43 | if (path.get("argument").isIdentifier()) {
|
44 | var undefLiteral = t.stringLiteral("undefined");
|
45 | var unary = t.unaryExpression("typeof", node.argument);
|
46 | unary[IGNORE] = true;
|
47 | path.replaceWith(t.conditionalExpression(t.binaryExpression("===", unary, undefLiteral), undefLiteral, call));
|
48 | } else {
|
49 | path.replaceWith(call);
|
50 | }
|
51 | }
|
52 | }
|
53 | }
|
54 | };
|
55 | };
|
56 |
|
57 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
58 |
|
59 | module.exports = exports["default"]; |
\ | No newline at end of file |