Comparing version 3.3.4 to 3.3.5
@@ -7,12 +7,13 @@ "use strict"; | ||
var isFunction = require("lodash/lang/isFunction"); | ||
var transform = require("./transformation"); | ||
var generate = require("./generation"); | ||
var defaults = require("lodash/object/defaults"); | ||
var contains = require("lodash/collection/contains"); | ||
var clone = require("./helpers/clone"); | ||
var Scope = require("./traverse/scope"); | ||
var util = require("./util"); | ||
var path = require("path"); | ||
var each = require("lodash/collection/each"); | ||
var t = require("./types"); | ||
var contains = require("lodash/collection/contains"); | ||
var each = require("lodash/collection/each"); | ||
var defaults = require("lodash/object/defaults"); | ||
var isFunction = require("lodash/lang/isFunction"); | ||
@@ -28,3 +29,3 @@ function File(opts) { | ||
this.lastStatements = []; | ||
this.opts = this.normaliseOptions(opts); | ||
this.opts = this.normalizeOptions(opts); | ||
this.ast = {}; | ||
@@ -55,3 +56,5 @@ | ||
"get", | ||
"set" | ||
"set", | ||
"class-call-check", | ||
"class-super-constructor-call" | ||
]; | ||
@@ -91,3 +94,3 @@ | ||
File.prototype.normaliseOptions = function (opts) { | ||
File.prototype.normalizeOptions = function (opts) { | ||
opts = clone(opts); | ||
@@ -122,5 +125,7 @@ | ||
// normalise windows path separators to unix | ||
// normalize windows path separators to unix | ||
opts.filename = opts.filename.replace(/\\/g, "/"); | ||
opts.basename = path.basename(opts.filename, path.extname(opts.filename)); | ||
opts.blacklist = util.arrayify(opts.blacklist); | ||
@@ -410,3 +415,3 @@ opts.whitelist = util.arrayify(opts.whitelist); | ||
i++; | ||
} while (scope.has(uid)); | ||
} while (scope.hasReference(uid)); | ||
return uid; | ||
@@ -418,3 +423,3 @@ }; | ||
var id = t.identifier(this.generateUid(name, scope)); | ||
scope.add(id); | ||
scope.addDeclarationToFunctionScope("var", id); | ||
return id; | ||
@@ -421,0 +426,0 @@ }; |
@@ -27,3 +27,3 @@ "use strict"; | ||
this.tokens = ast.tokens || []; | ||
this.format = CodeGenerator.normaliseOptions(code, opts); | ||
this.format = CodeGenerator.normalizeOptions(code, opts); | ||
this.ast = ast; | ||
@@ -43,3 +43,3 @@ | ||
CodeGenerator.normaliseOptions = function (code, opts) { | ||
CodeGenerator.normalizeOptions = function (code, opts) { | ||
var style = " "; | ||
@@ -46,0 +46,0 @@ if (code) { |
@@ -75,3 +75,5 @@ "use strict"; | ||
var istanbulLoader = function (m, filename, old) { | ||
var istanbulMonkey = {}; | ||
if (process.env.running_under_istanbul) { // jshint ignore:line | ||
// we need to monkey patch fs.readFileSync so we can hook into | ||
@@ -81,7 +83,16 @@ // what istanbul gets, it's extremely dirty but it's the only way | ||
fs.readFileSync = function () { | ||
fs.readFileSync = _readFileSync; | ||
return compile(filename); | ||
fs.readFileSync = function (filename) { | ||
if (istanbulMonkey[filename]) { | ||
delete istanbulMonkey[filename]; | ||
var code = compile(filename); | ||
istanbulMonkey[filename] = true; | ||
return code; | ||
} else { | ||
return _readFileSync.apply(this, arguments); | ||
} | ||
}; | ||
} | ||
var istanbulLoader = function (m, filename, old) { | ||
istanbulMonkey[filename] = true; | ||
old(m, filename); | ||
@@ -125,3 +136,3 @@ }; | ||
module.exports = function (opts) { | ||
// normalise options | ||
// normalize options | ||
opts = opts || {}; | ||
@@ -128,0 +139,0 @@ |
@@ -8,3 +8,3 @@ "use strict"; | ||
if (t.isIdentifier(node)) { | ||
if (scope.has(node.name, true)) { | ||
if (scope.hasBinding(node.name)) { | ||
// this variable is declared in scope so we can be 100% sure | ||
@@ -22,3 +22,3 @@ // that evaluating it multiple times wont trigger a getter | ||
if (t.isIdentifier(ref) && scope.has(ref.name)) { | ||
if (t.isIdentifier(ref) && scope.hasReference(ref.name)) { | ||
// the object reference that we need to save is locally declared | ||
@@ -25,0 +25,0 @@ // so as per the previous comment we can be 100% sure evaluating |
@@ -17,3 +17,3 @@ "use strict"; | ||
// for the wrapper | ||
var localDeclar = scope.get(state.id, true); | ||
var localDeclar = scope.getBinding(state.id); | ||
if (localDeclar !== state.outerDeclar) return; | ||
@@ -36,3 +36,3 @@ | ||
selfReference: false, | ||
outerDeclar: scope.get(id, true), | ||
outerDeclar: scope.getBinding(id), | ||
}; | ||
@@ -39,0 +39,0 @@ |
@@ -17,3 +17,3 @@ "use strict"; | ||
transform.fromAst = function (ast, code, opts) { | ||
ast = util.normaliseAst(ast); | ||
ast = util.normalizeAst(ast); | ||
@@ -20,0 +20,0 @@ var file = new File(opts); |
@@ -48,3 +48,3 @@ "use strict"; | ||
if (declar && t.isStatement(declar)) { | ||
extend(formatter.localExports, t.getDeclarations(declar)); | ||
extend(formatter.localExports, t.getBindingIdentifiers(declar)); | ||
} | ||
@@ -71,3 +71,3 @@ | ||
formatter.hasLocalImports = true; | ||
extend(formatter.localImports, t.getDeclarations(node)); | ||
extend(formatter.localImports, t.getBindingIdentifiers(node)); | ||
formatter.bumpImportOccurences(node); | ||
@@ -152,3 +152,3 @@ } | ||
var name = node.name; | ||
return t.isIdentifier(node) && localExports[name] && localExports[name] === scope.get(name, true); | ||
return t.isIdentifier(node) && localExports[name] && localExports[name] === scope.getBinding(name); | ||
}; | ||
@@ -177,3 +177,3 @@ | ||
// remove extension | ||
filenameRelative = filenameRelative.replace(/\.(.*?)$/, ""); | ||
filenameRelative = filenameRelative.replace(/\.(\w*?)$/, ""); | ||
} | ||
@@ -183,3 +183,3 @@ | ||
// normalise path separators | ||
// normalize path separators | ||
moduleName = moduleName.replace(/\\/g, "/"); | ||
@@ -220,2 +220,8 @@ | ||
DefaultFormatter.prototype.checkExportIdentifier = function (node) { | ||
if (t.isIdentifier(node, { name: "__esModule" })) { | ||
throw this.file.errorWithNode(node, "Illegal export __esModule - this is used internally for CommonJS interop"); | ||
} | ||
}; | ||
DefaultFormatter.prototype.exportSpecifier = function (specifier, node, nodes) { | ||
@@ -233,3 +239,3 @@ var inherits = false; | ||
if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) { | ||
// importing a default so we need to normalise it | ||
// importing a default so we need to normalize it | ||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]); | ||
@@ -261,2 +267,3 @@ } else { | ||
DefaultFormatter.prototype.buildExportsAssignment = function (id, init) { | ||
this.checkExportIdentifier(id); | ||
return util.template("exports-assign", { | ||
@@ -263,0 +270,0 @@ VALUE: init, |
@@ -23,3 +23,3 @@ "use strict"; | ||
this.optional = !!transformer.optional; | ||
this.handlers = this.normalise(transformer); | ||
this.handlers = this.normalize(transformer); | ||
this.opts = opts || {}; | ||
@@ -29,3 +29,3 @@ this.key = key; | ||
Transformer.prototype.normalise = function (transformer) { | ||
Transformer.prototype.normalize = function (transformer) { | ||
var self = this; | ||
@@ -32,0 +32,0 @@ |
"use strict"; | ||
var util = require("../../../util"); | ||
var t = require("../../../types"); | ||
var defineMap = require("../../helpers/define-map"); | ||
var t = require("../../../types"); | ||
@@ -13,3 +13,3 @@ exports.ObjectExpression = function (node) { | ||
hasAny = true; | ||
util.pushMutatorMap(mutatorMap, prop.key, prop.kind, prop.computed, prop.value); | ||
defineMap.push(mutatorMap, prop.key, prop.kind, prop.computed, prop.value); | ||
return false; | ||
@@ -25,4 +25,4 @@ } else { | ||
t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")), | ||
[node, util.buildDefineProperties(mutatorMap)] | ||
[node, defineMap.build(mutatorMap)] | ||
); | ||
}; |
@@ -14,3 +14,3 @@ "use strict"; | ||
// declared node is different in this scope | ||
if (scope.get(node.name, true) !== declared) return; | ||
if (scope.getBinding(node.name) !== declared) return; | ||
@@ -17,0 +17,0 @@ var declaredLoc = declared.loc; |
@@ -32,3 +32,3 @@ "use strict"; | ||
var standardiseLets = function (declars) { | ||
var standardizeLets = function (declars) { | ||
for (var i = 0; i < declars.length; i++) { | ||
@@ -49,4 +49,4 @@ delete declars[i]._let; | ||
} | ||
var letScoping = new LetScoping(node, node.body, parent, scope, file); | ||
letScoping.run(); | ||
var blockScoping = new BlockScoping(node, node.body, parent, scope, file); | ||
blockScoping.run(); | ||
}; | ||
@@ -57,4 +57,4 @@ | ||
if (!t.isLoop(parent)) { | ||
var letScoping = new LetScoping(false, block, parent, scope, file); | ||
letScoping.run(); | ||
var blockScoping = new BlockScoping(false, block, parent, scope, file); | ||
blockScoping.run(); | ||
} | ||
@@ -73,3 +73,3 @@ }; | ||
function LetScoping(loopParent, block, parent, scope, file) { | ||
function BlockScoping(loopParent, block, parent, scope, file) { | ||
this.loopParent = loopParent; | ||
@@ -91,3 +91,3 @@ this.parent = parent; | ||
LetScoping.prototype.run = function () { | ||
BlockScoping.prototype.run = function () { | ||
var block = this.block; | ||
@@ -118,7 +118,7 @@ if (block._letDone) return; | ||
var own = scope.get(node.name, true); | ||
if (own === remap.node) { | ||
var ownBinding = scope.getBinding(node.name); | ||
if (ownBinding === remap.binding) { | ||
node.name = remap.uid; | ||
} else { | ||
// scope already has it's own declaration that doesn't | ||
// scope already has it's own binding that doesn't | ||
// match the one we have a stored replacement for | ||
@@ -142,3 +142,3 @@ if (context) context.skip(); | ||
LetScoping.prototype.remap = function () { | ||
BlockScoping.prototype.remap = function () { | ||
var hasRemaps = false; | ||
@@ -159,3 +159,3 @@ var letRefs = this.letReferences; | ||
if (scope.parentHas(key)) { | ||
if (scope.parentHasReference(key)) { | ||
var uid = scope.generateUidIdentifier(ref.name).name; | ||
@@ -166,3 +166,3 @@ ref.name = uid; | ||
remaps[key] = remaps[uid] = { | ||
node: ref, | ||
binding: ref, | ||
uid: uid | ||
@@ -191,3 +191,3 @@ }; | ||
LetScoping.prototype.needsClosure = function () { | ||
BlockScoping.prototype.needsClosure = function () { | ||
var block = this.block; | ||
@@ -240,3 +240,3 @@ | ||
// to our let scope | ||
if (scope.hasOwn(node.name, true)) return; | ||
if (scope.hasOwnBinding(node.name)) return; | ||
@@ -263,3 +263,3 @@ // not a part of our scope | ||
LetScoping.prototype.getLetReferences = function () { | ||
BlockScoping.prototype.getLetReferences = function () { | ||
var block = this.block; | ||
@@ -273,3 +273,3 @@ | ||
declar = declarators[i]; | ||
extend(this.outsideLetReferences, t.getDeclarations(declar)); | ||
extend(this.outsideLetReferences, t.getBindingIdentifiers(declar)); | ||
} | ||
@@ -290,3 +290,3 @@ | ||
declar = declarators[i]; | ||
var keys = t.getDeclarations(declar); | ||
var keys = t.getBindingIdentifiers(declar); | ||
extend(this.letReferences, keys); | ||
@@ -300,3 +300,3 @@ this.hasLetReferences = true; | ||
// set let references to plain var references | ||
standardiseLets(declarators); | ||
standardizeLets(declarators); | ||
@@ -392,3 +392,3 @@ var state = { | ||
LetScoping.prototype.checkLoop = function () { | ||
BlockScoping.prototype.checkLoop = function () { | ||
var state = { | ||
@@ -432,3 +432,3 @@ hasBreakContinue: false, | ||
LetScoping.prototype.hoistVarDeclarations = function () { | ||
BlockScoping.prototype.hoistVarDeclarations = function () { | ||
traverse(this.block, hoistVarDeclarationsVisitor, this.scope, this); | ||
@@ -445,3 +445,3 @@ }; | ||
LetScoping.prototype.pushDeclar = function (node) { | ||
BlockScoping.prototype.pushDeclar = function (node) { | ||
this.body.push(t.variableDeclaration(node.kind, node.declarations.map(function (declar) { | ||
@@ -471,3 +471,3 @@ return t.variableDeclarator(declar.id); | ||
LetScoping.prototype.build = function (ret, call) { | ||
BlockScoping.prototype.build = function (ret, call) { | ||
var has = this.has; | ||
@@ -488,3 +488,3 @@ if (has.hasReturn || has.hasBreakContinue) { | ||
LetScoping.prototype.buildHas = function (ret, call) { | ||
BlockScoping.prototype.buildHas = function (ret, call) { | ||
var body = this.body; | ||
@@ -491,0 +491,0 @@ |
@@ -5,2 +5,3 @@ "use strict"; | ||
var nameMethod = require("../../helpers/name-method"); | ||
var defineMap = require("../../helpers/define-map"); | ||
var util = require("../../../util"); | ||
@@ -70,8 +71,15 @@ var t = require("../../../types"); | ||
var constructorBody = t.blockStatement([ | ||
t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [ | ||
t.thisExpression(), | ||
className | ||
])) | ||
]); | ||
var constructor; | ||
if (this.node.id) { | ||
constructor = t.functionDeclaration(className, [], t.blockStatement([])); | ||
constructor = t.functionDeclaration(className, [], constructorBody); | ||
body.push(constructor); | ||
} else { | ||
constructor = t.functionExpression(null, [], t.blockStatement([])); | ||
constructor = t.functionExpression(null, [], constructorBody); | ||
body.push(t.variableDeclaration("var", [ | ||
@@ -165,9 +173,16 @@ t.variableDeclarator(className, constructor) | ||
if (!this.hasConstructor && superName && !t.isFalsyExpression(superName)) { | ||
var defaultConstructorTemplate = "class-super-constructor-call"; | ||
if (this.isLoose) defaultConstructorTemplate += "-loose"; | ||
var helperName = "class-super-constructor-call"; | ||
constructor.body.body.push(util.template(defaultConstructorTemplate, { | ||
CLASS_NAME: className, | ||
SUPER_NAME: this.superName | ||
}, true)); | ||
if (this.isLoose) { | ||
constructor.body.body.push(util.template(helperName + "-loose", { | ||
CLASS_NAME: className, | ||
SUPER_NAME: this.superName | ||
}, true)); | ||
} else { | ||
constructor.body.body.push( | ||
t.expressionStatement( | ||
t.callExpression(this.file.addHelper(helperName), [t.thisExpression(), className]) | ||
) | ||
); | ||
} | ||
} | ||
@@ -179,7 +194,7 @@ | ||
if (this.hasInstanceMutators) { | ||
instanceProps = util.buildDefineProperties(this.instanceMutatorMap); | ||
instanceProps = defineMap.build(this.instanceMutatorMap); | ||
} | ||
if (this.hasStaticMutators) { | ||
staticProps = util.buildDefineProperties(this.staticMutatorMap); | ||
staticProps = defineMap.build(this.staticMutatorMap); | ||
} | ||
@@ -237,4 +252,4 @@ | ||
util.pushMutatorMap(mutatorMap, methodName, kind, node.computed, node); | ||
util.pushMutatorMap(mutatorMap, methodName, "enumerable", node.computed, false); | ||
defineMap.push(mutatorMap, methodName, kind, node.computed, node); | ||
defineMap.push(mutatorMap, methodName, "enumerable", node.computed, false); | ||
}; | ||
@@ -263,3 +278,3 @@ | ||
construct.params = fn.params; | ||
construct.body = fn.body; | ||
construct.body.body = construct.body.body.concat(fn.body.body); | ||
}; |
@@ -8,4 +8,4 @@ "use strict"; | ||
enter: function (node, parent, scope, context, state) { | ||
if (t.isDeclaration(node) || t.isAssignmentExpression(node)) { | ||
var ids = t.getDeclarations(node); | ||
if (t.isAssignmentExpression(node) || t.isUpdateExpression(node)) { | ||
var ids = t.getBindingIdentifiers(node); | ||
@@ -25,2 +25,5 @@ for (var key in ids) { | ||
var localBinding = scope.getBinding(key); | ||
if (localBinding !== constant) continue; | ||
throw state.file.errorWithNode(id, key + " is read-only"); | ||
@@ -27,0 +30,0 @@ } |
@@ -29,3 +29,3 @@ "use strict"; | ||
if (node.declaration) { | ||
// make sure variable exports have an initialiser | ||
// make sure variable exports have an initializer | ||
// this is done here to avoid duplicating it in the module formatters | ||
@@ -32,0 +32,0 @@ if (t.isVariableDeclaration(node.declaration)) { |
@@ -16,3 +16,3 @@ "use strict"; | ||
enter: function (node, parent, scope, context, state) { | ||
if (t.isReferencedIdentifier(node, parent) && state.scope.hasOwn(node.name)) { | ||
if (t.isReferencedIdentifier(node, parent) && state.scope.hasOwnReference(node.name)) { | ||
state.iife = true; | ||
@@ -52,3 +52,3 @@ context.stop(); | ||
if (!state.iife) { | ||
if (t.isIdentifier(right) && scope.hasOwn(right.name)) { | ||
if (t.isIdentifier(right) && scope.hasOwnReference(right.name)) { | ||
state.iife = true; | ||
@@ -55,0 +55,0 @@ } else { |
@@ -61,3 +61,3 @@ "use strict"; | ||
// normalise key | ||
// normalize key | ||
@@ -64,0 +64,0 @@ for (var i = 0; i < props.length; i++) { |
@@ -174,3 +174,12 @@ "use strict"; | ||
for (var i = 0; i < lines.length; i++) { | ||
var lastNonEmptyLine = 0; | ||
var i; | ||
for (i = 0; i < lines.length; i++) { | ||
if (lines[i].match(/[^ \t]/)) { | ||
lastNonEmptyLine = i; | ||
} | ||
} | ||
for (i = 0; i < lines.length; i++) { | ||
var line = lines[i]; | ||
@@ -180,2 +189,3 @@ | ||
var isLastLine = i === lines.length - 1; | ||
var isLastNonEmptyLine = i === lastNonEmptyLine; | ||
@@ -196,2 +206,6 @@ // replace rendered whitespace tabs with spaces | ||
if (trimmedLine) { | ||
if (!isLastNonEmptyLine) { | ||
trimmedLine += " "; | ||
} | ||
args.push(t.literal(trimmedLine)); | ||
@@ -205,4 +219,2 @@ } | ||
var addDisplayName = function (id, call) { | ||
if (!react.isCreateClass(call)) return; | ||
var props = call.arguments[0].properties; | ||
@@ -224,2 +236,8 @@ var safe = true; | ||
exports.ExportDeclaration = function (node, parent, scope, context, file) { | ||
if (node.default && react.isCreateClass(node.declaration)) { | ||
addDisplayName(file.opts.basename, node.declaration); | ||
} | ||
}; | ||
exports.AssignmentExpression = | ||
@@ -245,5 +263,5 @@ exports.Property = | ||
if (t.isIdentifier(left)) { | ||
if (t.isIdentifier(left) && react.isCreateClass(right)) { | ||
addDisplayName(left.name, right); | ||
} | ||
}; |
@@ -38,3 +38,3 @@ "use strict"; | ||
} | ||
} else if (t.isReferencedIdentifier(node, parent) && !t.isMemberExpression(parent) && contains(ALIASABLE_CONSTRUCTORS, node.name) && !scope.get(node.name, true)) { | ||
} else if (t.isReferencedIdentifier(node, parent) && !t.isMemberExpression(parent) && contains(ALIASABLE_CONSTRUCTORS, node.name) && !scope.getBinding(node.name)) { | ||
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise | ||
@@ -41,0 +41,0 @@ return t.memberExpression(file.get("coreIdentifier"), node); |
@@ -10,3 +10,3 @@ "use strict"; | ||
if (!t.isReferenced(node, parent)) return; | ||
if (scope.has(node.name, true)) return; | ||
if (scope.hasBinding(node.name)) return; | ||
@@ -18,3 +18,3 @@ var msg = "Reference to undeclared variable"; | ||
var declarations = scope.getAllDeclarations(); | ||
var bindings = scope.getAllBindings(); | ||
@@ -24,3 +24,3 @@ var closest; | ||
for (var name in declarations) { | ||
for (var name in bindings) { | ||
var distance = levenshtein(node.name, name); | ||
@@ -27,0 +27,0 @@ if (distance <= 0 || distance > 3) continue; |
@@ -5,16 +5,15 @@ "use strict"; | ||
var contains = require("lodash/collection/contains"); | ||
var traverse = require("./index"); | ||
var defaults = require("lodash/object/defaults"); | ||
var globals = require("globals"); | ||
var flatten = require("lodash/array/flatten"); | ||
var extend = require("lodash/object/extend"); | ||
var object = require("../helpers/object"); | ||
var t = require("../types"); | ||
var each = require("lodash/collection/each"); | ||
var has = require("lodash/object/has"); | ||
var contains = require("lodash/collection/contains"); | ||
var flatten = require("lodash/array/flatten"); | ||
var defaults = require("lodash/object/defaults"); | ||
var t = require("../types"); | ||
var FOR_KEYS = ["left", "init"]; | ||
/** | ||
* This searches the current "scope" and collects all references/declarations | ||
* This searches the current "scope" and collects all references/bindings | ||
* within. | ||
@@ -36,4 +35,5 @@ * | ||
var info = this.getInfo(); | ||
this.references = info.references; | ||
this.declarations = info.declarations; | ||
this.references = info.references; | ||
this.bindings = info.bindings; | ||
this.declarationKinds = info.declarationKinds; | ||
@@ -44,18 +44,2 @@ } | ||
Scope.prototype._add = function (node, references, throwOnDuplicate) { | ||
if (!node) return; | ||
var ids = t.getDeclarations(node); | ||
for (var key in ids) { | ||
var id = ids[key]; | ||
if (throwOnDuplicate && references[key]) { | ||
throw this.file.errorWithNode(id, "Duplicate declaration", TypeError); | ||
} | ||
references[key] = id; | ||
} | ||
}; | ||
/** | ||
@@ -136,3 +120,3 @@ * Description | ||
Scope.prototype.generateTempBasedOnNode = function (node) { | ||
if (t.isIdentifier(node) && this.has(node.name, true)) { | ||
if (t.isIdentifier(node) && this.hasBinding(node.name)) { | ||
return null; | ||
@@ -152,3 +136,3 @@ } | ||
if (t.isFor(node)) { | ||
each(FOR_KEYS, function (key) { | ||
each(t.FOR_INIT_KEYS, function (key) { | ||
var declar = node[key]; | ||
@@ -166,7 +150,10 @@ if (t.isVar(declar)) state.add(declar); | ||
// delegate block scope handling to the `blockVariableVisitor` | ||
if (t.isBlockScoped(node)) return; | ||
// this will be hit again once we traverse into it after this iteration | ||
if (t.isExportDeclaration(node) && t.isDeclaration(node.declaration)) return; | ||
// we've ran into a declaration! | ||
// we'll let the BlockStatement scope deal with `let` declarations unless | ||
if (t.isDeclaration(node) && !t.isBlockScoped(node)) { | ||
state.add(node); | ||
} | ||
if (t.isDeclaration(node)) state.add(node); | ||
} | ||
@@ -177,3 +164,3 @@ }; | ||
enter: function (node, parent, scope, context, add) { | ||
if (t.isReferencedIdentifier(node, parent) && !scope.has(node.name)) { | ||
if (t.isReferencedIdentifier(node, parent) && !scope.hasReference(node.name)) { | ||
add(node, true); | ||
@@ -187,3 +174,3 @@ } | ||
if (t.isBlockScoped(node)) { | ||
add(node, false, t.isLet(node)); | ||
add(node, false); | ||
} else if (t.isScope(node)) { | ||
@@ -202,17 +189,39 @@ context.skip(); | ||
var info = block._scopeInfo = {}; | ||
var references = info.references = object(); | ||
var declarations = info.declarations = object(); | ||
var declarationKinds = info.declarationKinds = {}; | ||
var add = function (node, reference, throwOnDuplicate) { | ||
self._add(node, references); | ||
var bindings = info.bindings = object(); | ||
var references = info.references = object(); | ||
var types = info.types = object(); | ||
var declarationKinds = info.declarationKinds = { | ||
"const": object(), | ||
"var": object(), | ||
"let": object() | ||
}; | ||
var add = function (node, reference) { | ||
var ids = t.getBindingIdentifiers(node); | ||
extend(references, ids); | ||
if (!reference) { | ||
self._add(node, declarations, throwOnDuplicate); | ||
self._add(node, declarationKinds[node.kind] = declarationKinds[node.kind] || object()); | ||
for (var key in ids) { | ||
var id = ids[key]; | ||
if (id.typeAnnotation) { | ||
types[id] = id.typeAnnotation; | ||
} | ||
if (declarationKinds["let"][key] || declarationKinds["const"][key]) { | ||
throw self.file.errorWithNode(id, "Duplicate declaration " + key, TypeError); | ||
} | ||
} | ||
extend(bindings, ids); | ||
var kinds = declarationKinds[node.kind]; | ||
if (kinds) extend(kinds, ids); | ||
} | ||
}; | ||
if (parent && t.isBlockStatement(block) && t.isFor(parent.block, { body: block })) { | ||
// delegate block let declarations to the parent loop | ||
if (parent && t.isBlockStatement(block) && t.isLoop(parent.block, { body: block })) { | ||
// delegate let bindings to the parent loop | ||
return info; | ||
@@ -223,4 +232,4 @@ } | ||
if (t.isFor(block)) { | ||
each(FOR_KEYS, function (key) { | ||
if (t.isLoop(block)) { | ||
each(t.FOR_INIT_KEYS, function (key) { | ||
var node = block[key]; | ||
@@ -317,8 +326,16 @@ if (t.isBlockScoped(node)) add(node, false, true); | ||
* | ||
* @param {String} kind | ||
* @param {Object} node | ||
*/ | ||
Scope.prototype.add = function (node) { | ||
Scope.prototype.addDeclarationToFunctionScope = function (kind, node) { | ||
var scope = this.getFunctionParent(); | ||
scope._add(node, scope.references); | ||
var ids = t.getBindingIdentifiers(node); | ||
extend(scope.bindings, ids); | ||
extend(scope.references, ids); | ||
// this ignores the duplicate declaration logic specified in `getInfo` | ||
// but it doesn't really matter | ||
extend(scope.declarationKinds[kind], ids); | ||
}; | ||
@@ -340,3 +357,3 @@ | ||
/** | ||
* Walks the scope tree and gathers **all** declarations. | ||
* Walks the scope tree and gathers **all** bindings. | ||
* | ||
@@ -346,3 +363,3 @@ * @returns {Object} | ||
Scope.prototype.getAllDeclarations = function () { | ||
Scope.prototype.getAllBindings = function () { | ||
var ids = object(); | ||
@@ -352,3 +369,3 @@ | ||
do { | ||
defaults(ids, scope.declarations); | ||
defaults(ids, scope.bindings); | ||
scope = scope.parent; | ||
@@ -379,49 +396,25 @@ } while (scope); | ||
/** | ||
* Description | ||
* | ||
* @param {String} [id] | ||
* @param {Boolean} [decl] | ||
*/ | ||
// | ||
Scope.prototype.get = function (id, decl) { | ||
return id && (this.getOwn(id, decl) || this.parentGet(id, decl)); | ||
Scope.prototype.get = function (id, type) { | ||
return id && (this.getOwn(id, type) || this.parentGet(id, type)); | ||
}; | ||
/** | ||
* Description | ||
* | ||
* @param {String} [id] | ||
* @param {Boolean} [decl] | ||
*/ | ||
Scope.prototype.getOwn = function (id, decl) { | ||
var refs = this.references; | ||
if (decl) refs = this.declarations; | ||
return has(refs, id) && refs[id]; | ||
Scope.prototype.getOwn = function (id, type) { | ||
var refs = { | ||
reference: this.references, | ||
binding: this.bindings, | ||
type: this.types | ||
}[type]; | ||
return refs && has(refs, id) && refs[id]; | ||
}; | ||
/** | ||
* Description | ||
* | ||
* @param {String} [id] | ||
* @param {Boolean} [decl] | ||
*/ | ||
Scope.prototype.parentGet = function (id, decl) { | ||
return this.parent && this.parent.get(id, decl); | ||
Scope.prototype.parentGet = function (id, type) { | ||
return this.parent && this.parent.get(id, type); | ||
}; | ||
/** | ||
* Description | ||
* | ||
* @param {String} [id] | ||
* @param {Boolean} [decl] | ||
* @returns {Boolean} | ||
*/ | ||
Scope.prototype.has = function (id, decl) { | ||
Scope.prototype.has = function (id, type) { | ||
if (!id) return false; | ||
if (this.hasOwn(id, decl)) return true; | ||
if (this.parentHas(id, decl)) return true; | ||
if (this.hasOwn(id, type)) return true; | ||
if (this.parentHas(id, type)) return true; | ||
if (contains(Scope.defaultDeclarations, id)) return true; | ||
@@ -431,24 +424,27 @@ return false; | ||
/** | ||
* Description | ||
* | ||
* @param {String} [id] | ||
* @param {Boolean} [decl] | ||
* @returns {Boolean} | ||
*/ | ||
Scope.prototype.hasOwn = function (id, type) { | ||
return !!this.getOwn(id, type); | ||
}; | ||
Scope.prototype.hasOwn = function (id, decl) { | ||
return !!this.getOwn(id, decl); | ||
Scope.prototype.parentHas = function (id, type) { | ||
return this.parent && this.parent.has(id, type); | ||
}; | ||
/** | ||
* Description | ||
* | ||
* @param {String} [id] | ||
* @param {Boolean} [decl] | ||
* @returns {Boolean} | ||
*/ | ||
Scope.prototype.parentHas = function (id, decl) { | ||
return this.parent && this.parent.has(id, decl); | ||
}; | ||
each({ | ||
reference: "Reference", | ||
binding: "Binding", | ||
type: "Type" | ||
}, function (title, type) { | ||
each([ | ||
"get", | ||
"has", | ||
"getOwn", | ||
"hasOwn", | ||
"parentGet", | ||
"parentHas", | ||
], function (methodName) { | ||
Scope.prototype[methodName + title] = function (id) { | ||
return this[methodName](id, type); | ||
}; | ||
}); | ||
}); |
@@ -6,3 +6,3 @@ { | ||
"DebuggerStatement": ["Statement"], | ||
"DoWhileStatement": ["Statement", "Loop", "While"], | ||
"DoWhileStatement": ["Statement", "Loop", "While", "Scope"], | ||
"IfStatement": ["Statement"], | ||
@@ -13,3 +13,3 @@ "ReturnStatement": ["Statement"], | ||
"TryStatement": ["Statement"], | ||
"WhileStatement": ["Statement", "Loop", "While"], | ||
"WhileStatement": ["Statement", "Loop", "While", "Scope"], | ||
"WithStatement": ["Statement"], | ||
@@ -16,0 +16,0 @@ "EmptyStatement": ["Statement"], |
@@ -37,8 +37,8 @@ "use strict"; | ||
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body"]; | ||
t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"]; | ||
t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"]; | ||
t.FOR_INIT_KEYS = ["left", "init"]; | ||
t.VISITOR_KEYS = require("./visitor-keys"); | ||
t.ALIAS_KEYS = require("./alias-keys"); | ||
t.ALIAS_KEYS = require("./alias-keys"); | ||
t.FLIPPED_ALIAS_KEYS = {}; | ||
@@ -564,8 +564,5 @@ | ||
/** | ||
* Return a list of identifiers that will be assigned | ||
* as a result of runtime evaluation. | ||
* Return a list of binding identifiers associated with | ||
* the input `node`. | ||
* | ||
* If an identifier is passed as `node` instead of a | ||
* declaration then it's assumed to be an assignable. | ||
* | ||
* @param {Object} node | ||
@@ -575,3 +572,3 @@ * @returns {Array|Object} | ||
t.getDeclarations = function (node) { | ||
t.getBindingIdentifiers = function (node) { | ||
var search = [].concat(node); | ||
@@ -584,3 +581,3 @@ var ids = object(); | ||
var keys = t.getDeclarations.keys[id.type]; | ||
var keys = t.getBindingIdentifiers.keys[id.type]; | ||
@@ -604,3 +601,3 @@ if (t.isIdentifier(id)) { | ||
t.getDeclarations.keys = { | ||
t.getBindingIdentifiers.keys = { | ||
AssignmentExpression: ["left"], | ||
@@ -616,2 +613,3 @@ ImportBatchSpecifier: ["name"], | ||
RestElement: ["argument"], | ||
UpdateExpression: ["argument"], | ||
Property: ["value"], | ||
@@ -647,3 +645,3 @@ ComprehensionBlock: ["left"], | ||
t.isBlockScoped = function (node) { | ||
return t.isFunctionDeclaration(node) || t.isLet(node); | ||
return t.isFunctionDeclaration(node) || t.isClassDeclaration(node) || t.isLet(node); | ||
}; | ||
@@ -650,0 +648,0 @@ |
@@ -19,3 +19,2 @@ "use strict"; | ||
var isEmpty = require("lodash/lang/isEmpty"); | ||
var clone = require("lodash/lang/clone"); | ||
var cloneDeep = require("lodash/lang/cloneDeep"); | ||
@@ -85,69 +84,2 @@ var has = require("lodash/object/has"); | ||
exports.pushMutatorMap = function (mutatorMap, key, kind, computed, value) { | ||
var alias; | ||
if (t.isIdentifier(key)) { | ||
alias = key.name; | ||
if (computed) alias = "computed:" + alias; | ||
} else if (t.isLiteral(key)) { | ||
alias = String(key.value); | ||
} else { | ||
alias = JSON.stringify(traverse.removeProperties(cloneDeep(key))); | ||
} | ||
var map; | ||
if (has(mutatorMap, alias)) { | ||
map = mutatorMap[alias]; | ||
} else { | ||
map = {}; | ||
} | ||
mutatorMap[alias] = map; | ||
map._key = key; | ||
if (computed) { | ||
map._computed = true; | ||
} | ||
map[kind] = value; | ||
}; | ||
exports.buildDefineProperties = function (mutatorMap) { | ||
var objExpr = t.objectExpression([]); | ||
each(mutatorMap, function (map) { | ||
var mapNode = t.objectExpression([]); | ||
var propNode = t.property("init", map._key, mapNode, map._computed); | ||
if (!map.get && !map.set) { | ||
map.writable = t.literal(true); | ||
} | ||
if (map.enumerable === false) { | ||
delete map.enumerable; | ||
} else { | ||
map.enumerable = t.literal(true); | ||
} | ||
map.configurable = t.literal(true); | ||
each(map, function (node, key) { | ||
if (key[0] === "_") return; | ||
node = clone(node); | ||
var inheritNode = node; | ||
if (t.isMethodDefinition(node)) node = node.value; | ||
var prop = t.property("init", t.identifier(key), node); | ||
t.inheritsComments(prop, inheritNode); | ||
t.removeComments(inheritNode); | ||
mapNode.properties.push(prop); | ||
}); | ||
objExpr.properties.push(propNode); | ||
}); | ||
return objExpr; | ||
}; | ||
var templateVisitor = { | ||
@@ -196,3 +128,3 @@ enter: function (node, parent, scope, context, nodes) { | ||
exports.normaliseAst = function (ast, comments, tokens) { | ||
exports.normalizeAst = function (ast, comments, tokens) { | ||
if (ast && ast.type === "Program") { | ||
@@ -224,3 +156,3 @@ return t.file(ast, comments || [], tokens || []); | ||
ast = exports.normaliseAst(ast, comments, tokens); | ||
ast = exports.normalizeAst(ast, comments, tokens); | ||
@@ -227,0 +159,0 @@ if (callback) { |
# Notes | ||
* Wildcard exports/imports wont normalise if `export default` is a non-object. See [#224](https://github.com/6to5/6to5/issues/224). | ||
* Wildcard exports/imports wont normalize if `export default` is a non-object. See [#224](https://github.com/6to5/6to5/issues/224). |
{ | ||
"name": "6to5-core", | ||
"description": "Turn ES6 code into readable vanilla ES5 with source maps", | ||
"version": "3.3.4", | ||
"version": "3.3.5", | ||
"author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
@@ -6,0 +6,0 @@ "homepage": "https://6to5.org/", |
@@ -1,1 +0,1 @@ | ||
(function(global){var to5Runtime=global.to5Runtime={};to5Runtime.inherits=function(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)subClass.__proto__=superClass};to5Runtime.defaults=function(obj,defaults){for(var key in defaults){if(obj[key]===undefined){obj[key]=defaults[key]}}return obj};to5Runtime.prototypeProperties=function(child,staticProps,instanceProps){if(staticProps)Object.defineProperties(child,staticProps);if(instanceProps)Object.defineProperties(child.prototype,instanceProps)};to5Runtime.applyConstructor=function(Constructor,args){var instance=Object.create(Constructor.prototype);var result=Constructor.apply(instance,args);return result!=null&&(typeof result=="object"||typeof result=="function")?result:instance};to5Runtime.taggedTemplateLiteral=function(strings,raw){return Object.freeze(Object.defineProperties(strings,{raw:{value:Object.freeze(raw)}}))};to5Runtime.taggedTemplateLiteralLoose=function(strings,raw){strings.raw=raw;return strings};to5Runtime.interopRequire=function(obj){return obj&&obj.__esModule?obj.default:obj};to5Runtime.toArray=function(arr){return Array.isArray(arr)?arr:Array.from(arr)};to5Runtime.slicedToArray=function(arr,i){if(Array.isArray(arr)){return arr}else{var _arr=[];for(var _iterator=arr[Symbol.iterator](),_step;!(_step=_iterator.next()).done;){_arr.push(_step.value);if(i&&_arr.length===i)break}return _arr}};to5Runtime.objectWithoutProperties=function(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i]}return target};to5Runtime.hasOwn=Object.prototype.hasOwnProperty;to5Runtime.slice=Array.prototype.slice;to5Runtime.bind=Function.prototype.bind;to5Runtime.defineProperty=function(obj,key,value){return Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})};to5Runtime.asyncToGenerator=function(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){var callNext=step.bind(null,"next");var callThrow=step.bind(null,"throw");function step(key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(callNext,callThrow)}}callNext()})}};to5Runtime.interopRequireWildcard=function(obj){return obj&&obj.__esModule?obj:{"default":obj}};to5Runtime._typeof=function(obj){return obj&&obj.constructor===Symbol?"symbol":typeof obj};to5Runtime._extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};to5Runtime.get=function get(object,property,receiver){var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined}else{return get(parent,property,receiver)}}else if("value"in desc&&desc.writable){return desc.value}else{var getter=desc.get;if(getter===undefined){return undefined}return getter.call(receiver)}};to5Runtime.set=function set(object,property,value,receiver){var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return}else{return set(parent,property,value,receiver)}}else if("value"in desc&&desc.writable){desc.value=value;return}else{var setter=desc.set;if(setter===undefined){return}return setter.call(receiver,value)}}})(typeof global==="undefined"?self:global); | ||
(function(global){var to5Runtime=global.to5Runtime={};to5Runtime.inherits=function(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)subClass.__proto__=superClass};to5Runtime.defaults=function(obj,defaults){for(var key in defaults){if(obj[key]===undefined){obj[key]=defaults[key]}}return obj};to5Runtime.prototypeProperties=function(child,staticProps,instanceProps){if(staticProps)Object.defineProperties(child,staticProps);if(instanceProps)Object.defineProperties(child.prototype,instanceProps)};to5Runtime.applyConstructor=function(Constructor,args){var instance=Object.create(Constructor.prototype);var result=Constructor.apply(instance,args);return result!=null&&(typeof result=="object"||typeof result=="function")?result:instance};to5Runtime.taggedTemplateLiteral=function(strings,raw){return Object.freeze(Object.defineProperties(strings,{raw:{value:Object.freeze(raw)}}))};to5Runtime.taggedTemplateLiteralLoose=function(strings,raw){strings.raw=raw;return strings};to5Runtime.interopRequire=function(obj){return obj&&obj.__esModule?obj.default:obj};to5Runtime.toArray=function(arr){return Array.isArray(arr)?arr:Array.from(arr)};to5Runtime.slicedToArray=function(arr,i){if(Array.isArray(arr)){return arr}else{var _arr=[];for(var _iterator=arr[Symbol.iterator](),_step;!(_step=_iterator.next()).done;){_arr.push(_step.value);if(i&&_arr.length===i)break}return _arr}};to5Runtime.objectWithoutProperties=function(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i]}return target};to5Runtime.hasOwn=Object.prototype.hasOwnProperty;to5Runtime.slice=Array.prototype.slice;to5Runtime.bind=Function.prototype.bind;to5Runtime.defineProperty=function(obj,key,value){return Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})};to5Runtime.asyncToGenerator=function(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){var callNext=step.bind(null,"next");var callThrow=step.bind(null,"throw");function step(key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(callNext,callThrow)}}callNext()})}};to5Runtime.interopRequireWildcard=function(obj){return obj&&obj.__esModule?obj:{"default":obj}};to5Runtime._typeof=function(obj){return obj&&obj.constructor===Symbol?"symbol":typeof obj};to5Runtime._extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};to5Runtime.get=function get(object,property,receiver){var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined}else{return get(parent,property,receiver)}}else if("value"in desc&&desc.writable){return desc.value}else{var getter=desc.get;if(getter===undefined){return undefined}return getter.call(receiver)}};to5Runtime.set=function set(object,property,value,receiver){var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return}else{return set(parent,property,value,receiver)}}else if("value"in desc&&desc.writable){desc.value=value;return}else{var setter=desc.set;if(setter===undefined){return}return setter.call(receiver,value)}};to5Runtime.classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}};to5Runtime.classSuperConstructorCall=function(instance,Constructor){if(Object.getPrototypeOf(Constructor)!==null){Object.getPrototypeOf(Constructor).apply(instance,arguments)}}})(typeof global==="undefined"?self:global); |
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
1403517
142
11874
43