add t.isReferencedIdentifier
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user