Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28c4c18ee2 | ||
|
|
968db67d0a | ||
|
|
b22ef22e36 | ||
|
|
044ce45d98 | ||
|
|
69f2a0d3f1 | ||
|
|
4b66dcb738 | ||
|
|
dfc6f1d1cf | ||
|
|
a64e040ac7 | ||
|
|
4f9414dbb0 | ||
|
|
bc6b31efbc | ||
|
|
244aed1ae9 |
11
CHANGELOG.md
11
CHANGELOG.md
@@ -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**
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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>"
|
||||
}
|
||||
Reference in New Issue
Block a user