Compare commits

...

11 Commits

Author SHA1 Message Date
Sebastian McKenzie
28c4c18ee2 v3.0.9 2015-01-28 20:08:49 +11:00
Sebastian McKenzie
968db67d0a add in pattern support to t.isReferenced 2015-01-28 20:06:49 +11:00
Sebastian McKenzie
b22ef22e36 add missing semicolon 2015-01-28 20:03:29 +11:00
Sebastian McKenzie
044ce45d98 add 3.0.9 changelog 2015-01-28 20:02:49 +11:00
Sebastian McKenzie
69f2a0d3f1 better t.toIdentifier behaviour that doesn't camelcase on underscores - fixes #610 2015-01-28 20:01:55 +11:00
Sebastian McKenzie
4b66dcb738 more reliable t.isReferenced - fixes #610 2015-01-28 19:58:20 +11:00
Sebastian McKenzie
dfc6f1d1cf add comment explaining what the modules-split transformer does 2015-01-28 18:40:33 +11:00
Sebastian McKenzie
a64e040ac7 3.0.8 2015-01-28 18:36:45 +11:00
Sebastian McKenzie
4f9414dbb0 v3.0.8 2015-01-28 18:36:22 +11:00
Sebastian McKenzie
bc6b31efbc split up function declarations from their exports - fixes #609 2015-01-28 18:34:43 +11:00
Sebastian McKenzie
244aed1ae9 3.0.7 2015-01-28 18:20:04 +11:00
5 changed files with 79 additions and 35 deletions

View File

@@ -11,6 +11,17 @@
_Note: Gaps between patch versions are faulty/broken releases._
## 3.0.9
* **Bug Fix**
* Make `t.isReferenced` more powerful, actually take into consideration all contexts were identifier nodes aren't actually references.
* Don't camelcase underscores when converting a string to a valid identifier.
## 3.0.8
* **Bug Fix**
* Split up default function declaration exports due to regenerator destroying the parent export declaration.
## 3.0.7
* **Internal**

View File

@@ -1,5 +1,11 @@
"use strict";
// in this transformer we have to split up classes and function declarations
// from their exports. why? because sometimes we need to replace classes with
// nodes that aren't allowed in the same contexts. also, if you're exporting
// a generator function as a default then regenerator will destroy the export
// declaration and leave a variable declaration in it's place... yeah, handy.
var t = require("../../../types");
exports.ExportDeclaration = function (node, parent, scope) {
@@ -16,6 +22,10 @@ exports.ExportDeclaration = function (node, parent, scope) {
]);
node.declaration = temp;
return [declar, node];
} else if (t.isFunctionDeclaration(declar)) {
node._blockHoist = 2;
node.declaration = declar.id;
return [declar, node];
}
} else {
if (t.isFunctionDeclaration(declar)) {

View File

@@ -226,7 +226,7 @@ t.prependToMemberExpression = function (member, append) {
};
/**
* Description
* Check if the input `node` is going to be evaluated, ie. is a refernece.
*
* @param {Object} node
* @param {Object} parent
@@ -234,45 +234,70 @@ t.prependToMemberExpression = function (member, append) {
*/
t.isReferenced = function (node, parent) {
// we're a property key and we aren't computed so we aren't referenced
if (t.isProperty(parent) && parent.key === node && !parent.computed) return false;
if (t.isFunction(parent)) {
// we're a function param
if (_.contains(parent.params, node)) return false;
for (var i = 0; i < parent.params.length; i++) {
var param = parent.params[i];
if (param === node) {
return false;
} else if (t.isRestElement(param) && param.argument === node) {
return false;
}
}
if (t.isProperty(parent)) {
return parent.key === node && parent.computed;
}
if (t.isMethodDefinition(parent) && parent.key === node && !parent.computed) {
if (t.isRestElement(parent)) {
return false;
}
// we're a catch clause param
if (t.isCatchClause(parent) && parent.param === node) return false;
if (t.isAssignmentPattern(parent)) {
return parent.right !== node;
}
// we're a variable declarator id so we aren't referenced
if (t.isVariableDeclarator(parent) && parent.id === node) return false;
if (t.isPattern(parent)) {
return false;
}
var isMemberExpression = t.isMemberExpression(parent);
if (t.isFunction(parent)) {
for (var i = 0; i < parent.params.length; i++) {
var param = parent.params[i];
if (param === node) return false;
}
// we're in a member expression and we're the computed property so we're referenced
var isComputedProperty = isMemberExpression && parent.property === node && parent.computed;
return parent.id !== node;
}
// we're in a member expression and we're the object so we're referenced
var isObject = isMemberExpression && parent.object === node;
if (t.isClass(parent)) {
return parent.id !== node;
}
// we are referenced
if (!isMemberExpression || isComputedProperty || isObject) return true;
if (t.isMethodDefinition(parent)) {
return parent.key === node && parent.computed;
}
return false;
if (t.isImportSpecifier(parent)) {
return false;
}
if (t.isImportBatchSpecifier(parent)) {
return false;
}
if (t.isLabeledStatement(parent)) {
return false;
}
if (t.isCatchClause(parent)) {
return parent.param !== node;
}
if (t.isVariableDeclarator(parent)) {
return parent.id !== node;
}
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;
}
}
return true;
};
/**
@@ -317,13 +342,10 @@ t.toIdentifier = function (name) {
name = name.replace(/^[-0-9]+/, "");
// camel case
name = name.replace(/[-_\s]+(.)?/g, function (match, c) {
name = name.replace(/[-\s]+(.)?/g, function (match, c) {
return c ? c.toUpperCase() : "";
});
// remove underscores from start of name
name = name.replace(/^\_/, "");
if (!t.isValidIdentifier(name)) {
name = "_" + name;
}

View File

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

View File

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