Comparing version 3.1.1 to 3.2.0
@@ -56,6 +56,3 @@ var outputFileSync = require("output-file-sync"); | ||
watcher.on(type, function (filename) { | ||
// chop off the dirname plus the path separator | ||
var relative = filename.slice(dirname.length + 1); | ||
console.log(type, filename); | ||
var relative = path.relative(dirname, filename) || filename; | ||
write(filename, relative); | ||
@@ -62,0 +59,0 @@ }); |
@@ -52,3 +52,4 @@ "use strict"; | ||
"extends", | ||
"get" | ||
"get", | ||
"set" | ||
]; | ||
@@ -78,2 +79,3 @@ | ||
"experimental", | ||
"resolveModuleSource", | ||
@@ -83,3 +85,4 @@ // these are used by plugins | ||
"only", | ||
"extensions" | ||
"extensions", | ||
"accept" | ||
]; | ||
@@ -98,2 +101,3 @@ | ||
keepModuleIdExtensions: false, | ||
resolveModuleSource: null, | ||
experimental: false, | ||
@@ -339,4 +343,8 @@ reactCompat: false, | ||
this.scope = new Scope(ast.program, ast, null, this); | ||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules); | ||
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules); | ||
if (modFormatter.init && this.transformers["es6.modules"].canRun()) { | ||
modFormatter.init(); | ||
} | ||
var astRun = function (key) { | ||
@@ -343,0 +351,0 @@ each(self.transformerStack, function (pass) { |
@@ -25,2 +25,32 @@ "use strict"; | ||
/** | ||
* Sets a super class value of the named property. | ||
* | ||
* @example | ||
* | ||
* _set(Object.getPrototypeOf(CLASS.prototype), "METHOD", "VALUE", this) | ||
* | ||
* @param {Node} property | ||
* @param {boolean} isStatic | ||
* @param {boolean} isComputed | ||
* | ||
* @returns {Node} | ||
*/ | ||
ReplaceSupers.prototype.setSuperProperty = function (property, value, isStatic, isComputed, thisExpression) { | ||
return t.callExpression( | ||
this.file.addHelper("set"), | ||
[ | ||
t.callExpression( | ||
t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")), | ||
[ | ||
isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype")) | ||
] | ||
), | ||
isComputed ? property : t.literal(property.name), | ||
value, | ||
thisExpression | ||
] | ||
); | ||
}; | ||
/** | ||
* Gets a node representing the super class value of the named property. | ||
@@ -195,2 +225,3 @@ * | ||
var args; | ||
var thisReference; | ||
@@ -231,2 +262,9 @@ if (t.isIdentifier(node, { name: "super" })) { | ||
computed = node.computed; | ||
} else if (t.isAssignmentExpression(node)) { | ||
if (!t.isIdentifier(node.left.object, { name: "super" })) return; | ||
if (methodNode.kind !== "set") return; | ||
thisReference = getThisReference(); | ||
// super.name = "val"; -> _set(Object.getPrototypeOf(ClassName.prototype), "name", this); | ||
return this.setSuperProperty(node.left.property, node.right, methodNode.static, node.left.computed, thisReference); | ||
} | ||
@@ -236,3 +274,3 @@ | ||
var thisReference = getThisReference(); | ||
thisReference = getThisReference(); | ||
var superProperty = this.superProperty(property, methodNode.static, computed, thisReference); | ||
@@ -239,0 +277,0 @@ if (args) { |
@@ -48,3 +48,3 @@ "use strict"; | ||
if (declar && t.isStatement(declar)) { | ||
extend(formatter.localExports, t.getIds(declar, true)); | ||
extend(formatter.localExports, t.getDeclarations(declar)); | ||
} | ||
@@ -71,3 +71,3 @@ | ||
formatter.hasLocalImports = true; | ||
extend(formatter.localImports, t.getIds(node, true)); | ||
extend(formatter.localImports, t.getDeclarations(node)); | ||
formatter.bumpImportOccurences(node); | ||
@@ -74,0 +74,0 @@ } |
@@ -18,2 +18,4 @@ "use strict"; | ||
AMDFormatter.prototype.init = CommonFormatter.prototype.init; | ||
AMDFormatter.prototype.buildDependencyLiterals = function () { | ||
@@ -20,0 +22,0 @@ var names = []; |
@@ -10,12 +10,14 @@ "use strict"; | ||
function CommonJSFormatter(file) { | ||
function CommonJSFormatter() { | ||
DefaultFormatter.apply(this, arguments); | ||
} | ||
util.inherits(CommonJSFormatter, DefaultFormatter); | ||
CommonJSFormatter.prototype.init = function () { | ||
if (this.hasNonDefaultExports) { | ||
file.ast.program.body.push(util.template("exports-module-declaration", true)); | ||
this.file.ast.program.body.push(util.template("exports-module-declaration", true)); | ||
} | ||
} | ||
}; | ||
util.inherits(CommonJSFormatter, DefaultFormatter); | ||
CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes) { | ||
@@ -22,0 +24,0 @@ var variableName = t.getSpecifierName(specifier); |
@@ -24,2 +24,4 @@ "use strict"; | ||
SystemFormatter.prototype.init = function () {}; | ||
SystemFormatter.prototype._addImportSource = function (node, exportNode) { | ||
@@ -26,0 +28,0 @@ node._importSource = exportNode.source && exportNode.source.value; |
@@ -5,2 +5,3 @@ "use strict"; | ||
var object = require("../../../helpers/object"); | ||
var clone = require("lodash/lang/clone"); | ||
var util = require("../../../util"); | ||
@@ -49,15 +50,4 @@ var t = require("../../../types"); | ||
} | ||
if (t.isLabeledStatement(parent)) { | ||
// set label so `run` has access to it | ||
node.label = parent.label; | ||
} | ||
var letScoping = new LetScoping(node, node.body, parent, scope, file); | ||
letScoping.run(); | ||
if (node.label && !t.isLabeledStatement(parent)) { | ||
// we've been given a label so let's wrap ourselves | ||
return t.labeledStatement(node.label, node); | ||
} | ||
}; | ||
@@ -274,3 +264,3 @@ | ||
declar = declarators[i]; | ||
extend(this.outsideLetReferences, t.getIds(declar, true)); | ||
extend(this.outsideLetReferences, t.getDeclarations(declar)); | ||
} | ||
@@ -291,3 +281,3 @@ | ||
declar = declarators[i]; | ||
var keys = t.getIds(declar, true); | ||
var keys = t.getDeclarations(declar); | ||
extend(this.letReferences, keys); | ||
@@ -315,2 +305,10 @@ this.hasLetReferences = true; | ||
var loopNodeTo = function (node) { | ||
if (t.isBreakStatement(node)) { | ||
return "break"; | ||
} else if (t.isContinueStatement(node)) { | ||
return "continue"; | ||
} | ||
}; | ||
var loopVisitor = { | ||
@@ -320,2 +318,8 @@ enter: function (node, parent, scope, context, state) { | ||
if (t.isLoop(node)) { | ||
state = clone(state); | ||
state.ignoreLabeless = true; | ||
traverse(node, loopVisitor, scope, state); | ||
} | ||
if (t.isFunction(node) || t.isLoop(node)) { | ||
@@ -325,12 +329,18 @@ return context.skip(); | ||
if (node && !node.label && state.isLoop) { | ||
if (t.isBreakStatement(node)) { | ||
if (t.isSwitchCase(parent)) return; | ||
var loopText = loopNodeTo(node); | ||
state.hasBreak = true; | ||
replace = t.returnStatement(t.literal("break")); | ||
} else if (t.isContinueStatement(node)) { | ||
state.hasContinue = true; | ||
replace = t.returnStatement(t.literal("continue")); | ||
if (loopText) { | ||
if (node.label) { | ||
loopText = loopText + "|" + node.label.name; | ||
} else { | ||
// we shouldn't be dealing with this | ||
if (state.ignoreLabeless) return; | ||
// break statements mean something different in this context | ||
if (t.isBreakStatement(node) && t.isSwitchCase(parent)) return; | ||
} | ||
state.hasBreakContinue = true; | ||
state.map[loopText] = node; | ||
replace = t.literal(loopText); | ||
} | ||
@@ -340,8 +350,11 @@ | ||
state.hasReturn = true; | ||
replace = t.returnStatement(t.objectExpression([ | ||
replace = t.objectExpression([ | ||
t.property("init", t.identifier("v"), node.argument || t.identifier("undefined")) | ||
])); | ||
]); | ||
} | ||
if (replace) return t.inherits(replace, node); | ||
if (replace) { | ||
replace = t.returnStatement(replace); | ||
return t.inherits(replace, node); | ||
} | ||
} | ||
@@ -361,6 +374,7 @@ }; | ||
var state = { | ||
hasContinue: false, | ||
hasReturn: false, | ||
hasBreak: false, | ||
isLoop: !!this.loopParent | ||
hasBreakContinue: false, | ||
ignoreLabeless: false, | ||
hasReturn: false, | ||
isLoop: !!this.loopParent, | ||
map: {} | ||
}; | ||
@@ -434,3 +448,3 @@ | ||
var has = this.has; | ||
if (has.hasReturn || has.hasBreak || has.hasContinue) { | ||
if (has.hasReturn || has.hasBreakContinue) { | ||
this.buildHas(ret, call); | ||
@@ -468,3 +482,3 @@ } else { | ||
if (has.hasBreak || has.hasContinue) { | ||
if (has.hasBreakContinue) { | ||
if (!loopParent) { | ||
@@ -475,14 +489,6 @@ throw new Error("Has no loop parent but we're trying to reassign breaks " + | ||
// ensure that the parent has a label as we're building a switch and we | ||
// need to be able to access it | ||
var label = loopParent.label = loopParent.label || this.scope.generateUidIdentifier("loop"); | ||
if (has.hasBreak) { | ||
cases.push(t.switchCase(t.literal("break"), [t.breakStatement(label)])); | ||
for (var key in has.map) { | ||
cases.push(t.switchCase(t.literal(key), [has.map[key]])); | ||
} | ||
if (has.hasContinue) { | ||
cases.push(t.switchCase(t.literal("continue"), [t.continueStatement(label)])); | ||
} | ||
if (has.hasReturn) { | ||
@@ -489,0 +495,0 @@ cases.push(t.switchCase(null, [retCheck])); |
@@ -9,3 +9,3 @@ "use strict"; | ||
if (t.isDeclaration(node) || t.isAssignmentExpression(node)) { | ||
var ids = t.getIds(node, true); | ||
var ids = t.getDeclarations(node); | ||
@@ -12,0 +12,0 @@ for (var key in ids) { |
@@ -16,3 +16,3 @@ "use strict"; | ||
enter: function (node, parent, scope, context, state) { | ||
if (t.isReferencedIdentifier(node, parent) && scope.hasOwn(node.name)) { | ||
if (t.isReferencedIdentifier(node, parent) && state.scope.hasOwn(node.name)) { | ||
state.iife = true; | ||
@@ -19,0 +19,0 @@ context.stop(); |
@@ -16,3 +16,3 @@ module.exports = { | ||
_modulesSplit: require("./internal/modules-split"), | ||
_modules: require("./internal/modules"), | ||
@@ -19,0 +19,0 @@ // needs to be before `regenerator` due to generator comprehensions |
@@ -20,3 +20,3 @@ "use strict"; | ||
exports.ThisExpression = function (node, parent, scope, context, file) { | ||
throw file.errorWithNode(node, "Top level `this` is not allowed", ReferenceError); | ||
throw file.errorWithNode(node, "Top level `this` is `undefined` in strict mode", ReferenceError); | ||
}; |
@@ -6,3 +6,3 @@ "use strict"; | ||
exports.BlockStatement = function (node, parent) { | ||
if (t.isFunction(parent) || t.isExportDeclaration(parent)) { | ||
if ((t.isFunction(parent) && parent.body === node) || t.isExportDeclaration(parent)) { | ||
return; | ||
@@ -13,3 +13,3 @@ } | ||
var func = node.body[i]; | ||
if (!t.isFunctionDeclaration(i)) continue; | ||
if (!t.isFunctionDeclaration(func)) continue; | ||
@@ -26,4 +26,4 @@ var declar = t.variableDeclaration("let", [ | ||
func.body[i] = declar; | ||
node.body[i] = declar; | ||
} | ||
}; |
@@ -6,2 +6,3 @@ "use strict"; | ||
var traverse = require("./index"); | ||
var globals = require("globals"); | ||
var object = require("../helpers/object"); | ||
@@ -12,2 +13,3 @@ var t = require("../types"); | ||
var contains = require("lodash/collection/contains"); | ||
var flatten = require("lodash/array/flatten"); | ||
var defaults = require("lodash/object/defaults"); | ||
@@ -40,3 +42,3 @@ | ||
Scope.defaultDeclarations = require("./global-keys"); | ||
Scope.defaultDeclarations = flatten([globals.builtin, globals.browser, globals.node].map(Object.keys)); | ||
@@ -46,3 +48,3 @@ Scope.prototype._add = function (node, references, throwOnDuplicate) { | ||
var ids = t.getIds(node, true); | ||
var ids = t.getDeclarations(node); | ||
@@ -392,4 +394,7 @@ for (var key in ids) { | ||
Scope.prototype.has = function (id, decl) { | ||
return (id && (this.hasOwn(id, decl) || this.parentHas(id, decl))) || | ||
contains(Scope.defaultDeclarations, id); | ||
if (!id) return false; | ||
if (this.hasOwn(id, decl)) return true; | ||
if (this.parentHas(id, decl)) return true; | ||
if (contains(Scope.defaultDeclarations, id)) return true; | ||
return false; | ||
}; | ||
@@ -396,0 +401,0 @@ |
@@ -11,3 +11,2 @@ "use strict"; | ||
var defaults = require("lodash/object/defaults"); | ||
var keys = require("lodash/object/keys"); | ||
var isString = require("lodash/lang/isString"); | ||
@@ -17,6 +16,2 @@ | ||
t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"]; | ||
// | ||
/** | ||
@@ -44,5 +39,4 @@ * Registers `is[Type]` and `assert[Type]` generated functions for a given `type`. | ||
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body"]; | ||
t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"]; | ||
// | ||
t.VISITOR_KEYS = require("./visitor-keys"); | ||
@@ -72,2 +66,3 @@ | ||
* Returns whether `node` is of given `type`. | ||
* | ||
* For better performance, use this instead of `is[Type]` when `type` is unknown. | ||
@@ -163,2 +158,5 @@ * Optionally, pass `skipAliasCheck` to directly compare `node.type` with `type`. | ||
* Expression statements are just resolved to their standard expression. | ||
* | ||
* @param {Array} nodes | ||
* @param {Scope} scope | ||
*/ | ||
@@ -193,13 +191,19 @@ | ||
// | ||
/* | ||
* Description | ||
* | ||
* @param {Object} actual | ||
* @param {Object} expected | ||
* @returns {Boolean} | ||
*/ | ||
t.shallowEqual = function (actual, expected) { | ||
var keys = Object.keys(expected); | ||
var key; | ||
for (var i = 0; i < keys.length; i++) { | ||
key = keys[i]; | ||
var key = keys[i]; | ||
if (actual[key] !== expected[key]) | ||
if (actual[key] !== expected[key]) { | ||
return false; | ||
} | ||
} | ||
@@ -339,3 +343,3 @@ | ||
/** | ||
* Description | ||
* Check if the input `node` is an `Identifier` and `isReferenced`. | ||
* | ||
@@ -352,3 +356,4 @@ * @param {Object} node | ||
/** | ||
* Description | ||
* Check if the input `name` is a valid identifier name | ||
* and isn't a reserved word. | ||
* | ||
@@ -513,8 +518,6 @@ * @param {String} name | ||
* @param {Object} node | ||
* @param {Boolean} [map] | ||
* @param {Array} [ignoreTypes] | ||
* @returns {Array|Object} | ||
*/ | ||
t.getIds = function (node, map, ignoreTypes) { | ||
t.getDeclarations = function (node) { | ||
var search = [].concat(node); | ||
@@ -527,10 +530,4 @@ var ids = object(); | ||
// blacklist types | ||
if (ignoreTypes && ignoreTypes.indexOf(id.type) >= 0) continue; | ||
var keys = t.getDeclarations.keys[id.type]; | ||
var nodeKeys = t.getIds.nodes[id.type]; | ||
var arrKeys = t.getIds.arrays[id.type]; | ||
var i, key; | ||
if (t.isIdentifier(id)) { | ||
@@ -542,13 +539,5 @@ ids[id.name] = id; | ||
} | ||
} else if (nodeKeys) { | ||
for (i = 0; i < nodeKeys.length; i++) { | ||
key = nodeKeys[i]; | ||
if (id[key]) { | ||
search.push(id[key]); | ||
break; | ||
} | ||
} | ||
} else if (arrKeys) { | ||
for (i = 0; i < arrKeys.length; i++) { | ||
key = arrKeys[i]; | ||
} else if (keys) { | ||
for (var i = 0; i < keys.length; i++) { | ||
var key = keys[i]; | ||
search = search.concat(id[key] || []); | ||
@@ -559,7 +548,6 @@ } | ||
if (!map) ids = keys(ids); | ||
return ids; | ||
}; | ||
t.getIds.nodes = { | ||
t.getDeclarations.keys = { | ||
AssignmentExpression: ["left"], | ||
@@ -577,6 +565,3 @@ ImportBatchSpecifier: ["name"], | ||
ComprehensionBlock: ["left"], | ||
AssignmentPattern: ["left"] | ||
}; | ||
t.getIds.arrays = { | ||
AssignmentPattern: ["left"], | ||
PrivateDeclaration: ["declarations"], | ||
@@ -583,0 +568,0 @@ ComprehensionExpression: ["blocks"], |
{ | ||
"name": "6to5", | ||
"description": "Turn ES6 code into readable vanilla ES5 with source maps", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
@@ -45,4 +45,4 @@ "homepage": "https://6to5.org/", | ||
"esutils": "1.1.6", | ||
"esvalid": "1.1.0", | ||
"fs-readdir-recursive": "0.1.0", | ||
"globals": "^5.1.0", | ||
"js-tokenizer": "1.3.3", | ||
@@ -63,2 +63,3 @@ "lodash": "3.0.0", | ||
"chai": "1.10.0", | ||
"esvalid": "1.1.0", | ||
"istanbul": "0.3.5", | ||
@@ -65,0 +66,0 @@ "jscs": "1.10.0", |
Sorry, the diff of this file is too big to display
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
1374044
11450
11
132
+ Addedglobals@^5.1.0
+ Addedglobals@5.1.0(transitive)
- Removedesvalid@1.1.0
- Removedesvalid@1.1.0(transitive)
- Removedobject-assign@0.3.1(transitive)