Comparing version 3.0.8 to 3.0.9
"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"); | ||
@@ -4,0 +10,0 @@ |
@@ -229,3 +229,3 @@ "use strict"; | ||
/** | ||
* Description | ||
* Check if the input `node` is going to be evaluated, ie. is a refernece. | ||
* | ||
@@ -238,41 +238,66 @@ * @param {Object} node | ||
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.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; | ||
} | ||
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 (param === node) return false; | ||
} | ||
return parent.id !== node; | ||
} | ||
if (t.isMethodDefinition(parent) && parent.key === node && !parent.computed) { | ||
if (t.isClass(parent)) { | ||
return parent.id !== node; | ||
} | ||
if (t.isMethodDefinition(parent)) { | ||
return parent.key === node && parent.computed; | ||
} | ||
if (t.isImportSpecifier(parent)) { | ||
return false; | ||
} | ||
// we're a catch clause param | ||
if (t.isCatchClause(parent) && parent.param === node) return false; | ||
if (t.isImportBatchSpecifier(parent)) { | ||
return false; | ||
} | ||
// we're a variable declarator id so we aren't referenced | ||
if (t.isVariableDeclarator(parent) && parent.id === node) return false; | ||
if (t.isLabeledStatement(parent)) { | ||
return false; | ||
} | ||
var isMemberExpression = t.isMemberExpression(parent); | ||
if (t.isCatchClause(parent)) { | ||
return parent.param !== node; | ||
} | ||
// we're in a member expression and we're the computed property so we're referenced | ||
var isComputedProperty = isMemberExpression && parent.property === node && parent.computed; | ||
if (t.isVariableDeclarator(parent)) { | ||
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.isMemberExpression(parent)) { | ||
if (parent.property === node && parent.computed) { // PARENT[NODE] | ||
return true; | ||
} else if (parent.object === node) { // NODE.child | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
// we are referenced | ||
if (!isMemberExpression || isComputedProperty || isObject) return true; | ||
return false; | ||
return true; | ||
}; | ||
@@ -322,9 +347,6 @@ | ||
// 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)) { | ||
@@ -331,0 +353,0 @@ name = "_" + name; |
{ | ||
"name": "6to5-core", | ||
"description": "Turn ES6 code into readable vanilla ES5 with source maps", | ||
"version": "3.0.8", | ||
"version": "3.0.9", | ||
"author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
@@ -6,0 +6,0 @@ "homepage": "https://6to5.org/", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1358894
11390