From 3affa543efcc4e60201515ded555f3a6b3658e6f Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 28 Jan 2015 20:21:25 +1100 Subject: [PATCH] add yes/no comments to describe what we're actually testing for in types.isReferenced --- lib/6to5/types/index.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/6to5/types/index.js b/lib/6to5/types/index.js index 78c79f52b9..968d27f7a7 100644 --- a/lib/6to5/types/index.js +++ b/lib/6to5/types/index.js @@ -234,22 +234,30 @@ t.prependToMemberExpression = function (member, append) { */ t.isReferenced = function (node, parent) { + // yes: { [NODE]: "" } if (t.isProperty(parent)) { return parent.key === node && parent.computed; } + // no: function foo(...NODE) {} if (t.isRestElement(parent)) { return false; } + // no: [NODE = foo] = []; + // yes: [foo = NODE] = []; if (t.isAssignmentPattern(parent)) { return parent.right !== node; } + // no: [NODE] = []; + // no: ({ NODE }) = []; if (t.isPattern(parent)) { return false; } + // no: function NODE() {} + // no: function foo(NODE) {} if (t.isFunction(parent)) { for (var i = 0; i < parent.params.length; i++) { var param = parent.params[i]; @@ -259,38 +267,49 @@ t.isReferenced = function (node, parent) { return parent.id !== node; } + // no: class NODE {} if (t.isClass(parent)) { return parent.id !== node; } + // yes: class { [NODE](){} } if (t.isMethodDefinition(parent)) { return parent.key === node && parent.computed; } + // no: import NODE from "bar"; if (t.isImportSpecifier(parent)) { return false; } + // no: import * as NODE from "foo"; if (t.isImportBatchSpecifier(parent)) { return false; } + // no: NODE: for (;;) {} if (t.isLabeledStatement(parent)) { return false; } + // no: try {} catch (NODE) {} if (t.isCatchClause(parent)) { return parent.param !== node; } + // no: var NODE = init; + // yes: var id = NODE; if (t.isVariableDeclarator(parent)) { return parent.id !== node; } + // yes: PARENT[NODE] + // yes: NODE.child + // no: parent.CHILD if (t.isMemberExpression(parent)) { - if (parent.property === node && parent.computed) { // PARENT[NODE] + if (parent.property === node && parent.computed) { return true; - } else if (parent.object === node) { // NODE.child + } else if (parent.object === node) { return true; } else { return false;