diff --git a/lib/6to5/transformation/transformers/es6-default-parameters.js b/lib/6to5/transformation/transformers/es6-default-parameters.js index 408c1a7e63..af1b163e5b 100644 --- a/lib/6to5/transformation/transformers/es6-default-parameters.js +++ b/lib/6to5/transformation/transformers/es6-default-parameters.js @@ -17,7 +17,7 @@ exports.Function = function (node, parent, scope, context, file) { var checkTDZ = function (ids) { var check = function (node, parent) { - if (!t.isIdentifier(node) || !t.isReferenced(node, parent)) return; + if (!t.isReferencedIdentifier(node, parent)) return; if (ids.indexOf(node.name) >= 0) { throw file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized"); diff --git a/lib/6to5/transformation/transformers/es6-let-scoping.js b/lib/6to5/transformation/transformers/es6-let-scoping.js index b7d7f5fbb2..4d0f13910e 100644 --- a/lib/6to5/transformation/transformers/es6-let-scoping.js +++ b/lib/6to5/transformation/transformers/es6-let-scoping.js @@ -146,8 +146,7 @@ LetScoping.prototype.remap = function () { // var replace = function (node, parent, scope, context, remaps) { - if (!t.isIdentifier(node)) return; - if (!t.isReferenced(node, parent)) return; + if (!t.isReferencedIdentifier(node, parent)) return; var remap = remaps[node.name]; if (!remap) return; @@ -266,11 +265,8 @@ LetScoping.prototype.getLetReferences = function () { if (t.isFunction(node)) { traverse(node, { enter: function (node, parent) { - // not an identifier so we have no use - if (!t.isIdentifier(node)) return; - // not a direct reference - if (!t.isReferenced(node, parent)) return; + if (!t.isReferencedIdentifier(node, parent)) return; // this scope has a variable with the same name so it couldn't belong // to our let scope diff --git a/lib/6to5/transformation/transformers/optional-block-scoping-tdz.js b/lib/6to5/transformation/transformers/optional-block-scoping-tdz.js index 972cca4567..27472f8bdf 100644 --- a/lib/6to5/transformation/transformers/optional-block-scoping-tdz.js +++ b/lib/6to5/transformation/transformers/optional-block-scoping-tdz.js @@ -16,8 +16,7 @@ exports.BlockStatement = function (node, parent, scope, context, file) { traverse(node, { enter: function (node, parent, scope, context, state) { - if (!t.isIdentifier(node)) return; - if (!t.isReferenced(node, parent)) return; + if (!t.isReferencedIdentifier(node, parent)) return; var declared = state.letRefs[node.name]; if (!declared) return; diff --git a/lib/6to5/transformation/transformers/optional-core-aliasing.js b/lib/6to5/transformation/transformers/optional-core-aliasing.js index c0db8bd9bd..90bb4621a7 100644 --- a/lib/6to5/transformation/transformers/optional-core-aliasing.js +++ b/lib/6to5/transformation/transformers/optional-core-aliasing.js @@ -42,7 +42,7 @@ exports.ast = { context.skip(); return t.prependToMemberExpression(node, file._coreId); } - } else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && _.contains(ALIASABLE_CONSTRUCTORS, node.name)) { + } else if (t.isReferencedIdentifier(node, parent) && !t.isMemberExpression(parent) && _.contains(ALIASABLE_CONSTRUCTORS, node.name)) { // Symbol() -> _core.Symbol(); new Promise -> new _core.Promise return t.memberExpression(file._coreId, node); } else if (t.isCallExpression(node)) { diff --git a/lib/6to5/types/index.js b/lib/6to5/types/index.js index 31c783dc1f..8bc6cb5d75 100644 --- a/lib/6to5/types/index.js +++ b/lib/6to5/types/index.js @@ -263,6 +263,18 @@ t.isReferenced = function (node, parent) { return false; }; +/** + * Description + * + * @param {Object} node + * @param {Object} parent + * @returns {Boolean} + */ + +t.isReferencedIdentifier = function (node, parent) { + return t.isIdentifier(node) && t.isReferenced(node, parent); +}; + /** * Description *