Compare commits

...

5 Commits

Author SHA1 Message Date
Sebastian McKenzie
ddfb492ed9 v3.0.10 2015-01-28 23:14:43 +11:00
Sebastian McKenzie
3d98364adb in types.getIds make sure the declaration inside of ExportDeclaration is actually a Declaration, clean up types.isReferenced - fixes #614 2015-01-28 23:12:53 +11:00
Sebastian McKenzie
3affa543ef add yes/no comments to describe what we're actually testing for in types.isReferenced 2015-01-28 20:21:25 +11:00
Sebastian McKenzie
2a47afebde more accurate types.isReferenced comment 2015-01-28 20:09:37 +11:00
Sebastian McKenzie
f2fc6d8852 3.0.9 2015-01-28 20:09:20 +11:00
4 changed files with 64 additions and 32 deletions

View File

@@ -11,6 +11,11 @@
_Note: Gaps between patch versions are faulty/broken releases._
## 3.0.10
* **Bug Fix**
* In `types.getIds` make sure the `declaration` inside of `ExportDeclaration` is actually a `Declaration`.
## 3.0.9
* **Bug Fix**

View File

@@ -226,7 +226,7 @@ t.prependToMemberExpression = function (member, append) {
};
/**
* Check if the input `node` is going to be evaluated, ie. is a refernece.
* Check if the input `node` is a reference to a bound variable.
*
* @param {Object} node
* @param {Object} parent
@@ -234,22 +234,32 @@ t.prependToMemberExpression = function (member, append) {
*/
t.isReferenced = function (node, parent) {
// yes: PARENT[NODE]
// yes: NODE.child
// no: parent.CHILD
if (t.isMemberExpression(parent)) {
if (parent.property === node && parent.computed) {
return true;
} else if (parent.object === node) {
return true;
} else {
return false;
}
}
// yes: { [NODE]: "" }
if (t.isProperty(parent)) {
return parent.key === node && parent.computed;
}
if (t.isRestElement(parent)) {
return false;
}
if (t.isAssignmentPattern(parent)) {
return parent.right !== node;
}
if (t.isPattern(parent)) {
return false;
// no: var NODE = init;
// yes: var id = NODE;
if (t.isVariableDeclarator(parent)) {
return parent.id !== node;
}
// 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,42 +269,56 @@ 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;
}
if (t.isImportSpecifier(parent)) {
return false;
}
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;
}
if (t.isVariableDeclarator(parent)) {
return parent.id !== node;
// no: function foo(...NODE) {}
if (t.isRestElement(parent)) {
return false;
}
if (t.isMemberExpression(parent)) {
if (parent.property === node && parent.computed) { // PARENT[NODE]
return true;
} else if (parent.object === node) { // NODE.child
return true;
} else {
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: import NODE from "bar";
if (t.isImportSpecifier(parent)) {
return false;
}
// no: import * as NODE from "foo";
if (t.isImportBatchSpecifier(parent)) {
return false;
}
// no: class Foo { private NODE; }
if (t.isPrivateDeclaration(parent)) {
return false;
}
return true;
@@ -492,6 +516,10 @@ t.getIds = function (node, map, ignoreTypes) {
if (t.isIdentifier(id)) {
ids[id.name] = id;
} else if (t.isExportDeclaration(id)) {
if (t.isDeclaration(node.declaration)) {
search.push(node.declaration);
}
} else if (nodeKeys) {
for (i = 0; i < nodeKeys.length; i++) {
key = nodeKeys[i];
@@ -531,7 +559,6 @@ t.getIds.nodes = {
t.getIds.arrays = {
PrivateDeclaration: ["declarations"],
ComprehensionExpression: ["blocks"],
ExportDeclaration: ["specifiers", "declaration"],
ImportDeclaration: ["specifiers"],
VariableDeclaration: ["declarations"],
ArrayPattern: ["elements"],

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "3.0.9",
"version": "3.0.10",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://6to5.org/",
"repository": "6to5/6to5",

View File

@@ -1,7 +1,7 @@
{
"name": "6to5-runtime",
"description": "6to5 selfContained runtime",
"version": "3.0.8",
"version": "3.0.9",
"repository": "6to5/6to5",
"author": "Sebastian McKenzie <sebmck@gmail.com>"
}