diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js b/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js index 9c6a3d1d2a..d92e4b394d 100644 --- a/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js @@ -33,7 +33,9 @@ export default function({ types: t }) { const isUnderHelper = path.findParent(path => { return ( (path.isVariableDeclarator() && path.node.id === helper) || - (path.isFunctionDeclaration() && path.node.id.name === helper.name) + (path.isFunctionDeclaration() && + path.node.id && + path.node.id.name === helper.name) ); }); diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/test/fixtures/symbols/default-export/actual.js b/packages/babel-plugin-transform-es2015-typeof-symbol/test/fixtures/symbols/default-export/actual.js new file mode 100644 index 0000000000..f03d8e5451 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/test/fixtures/symbols/default-export/actual.js @@ -0,0 +1,3 @@ +export default function() { + typeof {} === "object"; +} diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/test/fixtures/symbols/default-export/expected.js b/packages/babel-plugin-transform-es2015-typeof-symbol/test/fixtures/symbols/default-export/expected.js new file mode 100644 index 0000000000..fd697ccdc9 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/test/fixtures/symbols/default-export/expected.js @@ -0,0 +1,5 @@ +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); } + +export default function () { + _typeof({}) === "object"; +} diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/test/fixtures/symbols/default-export/options.json b/packages/babel-plugin-transform-es2015-typeof-symbol/test/fixtures/symbols/default-export/options.json new file mode 100644 index 0000000000..a9b95ca6a3 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/test/fixtures/symbols/default-export/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-typeof-symbol"] +}