diff --git a/lib/6to5/transformation/transformers/es6/classes.js b/lib/6to5/transformation/transformers/es6/classes.js index 22fc26ff84..66b6240932 100644 --- a/lib/6to5/transformation/transformers/es6/classes.js +++ b/lib/6to5/transformation/transformers/es6/classes.js @@ -6,13 +6,13 @@ var defineMap = require("../../helpers/define-map"); var util = require("../../../util"); var t = require("../../../types"); -exports.check = t.isClass; +exports.check = t.isClassTransformer; -exports.ClassDeclaration = function (node, parent, scope, file) { - return new Class(node, file, scope, true).run(); +exports.ClassTransformerDeclaration = function (node, parent, scope, file) { + return new ClassTransformer(node, file, scope, true).run(); }; -exports.ClassExpression = function (node, parent, scope, file) { +exports.ClassTransformerExpression = function (node, parent, scope, file) { if (!node.id) { if (t.isProperty(parent) && parent.value === node && !parent.computed && t.isIdentifier(parent.key)) { // var o = { foo: class {} }; @@ -25,7 +25,7 @@ exports.ClassExpression = function (node, parent, scope, file) { } } - return new Class(node, file, scope, false).run(); + return new ClassTransformer(node, file, scope, false).run(); }; /** @@ -37,7 +37,7 @@ exports.ClassExpression = function (node, parent, scope, file) { * @param {Boolean} closure */ -function Class(node, file, scope, isStatement) { +function ClassTransformer(node, file, scope, isStatement) { this.isStatement = isStatement; this.scope = scope; this.node = node; @@ -50,8 +50,8 @@ function Class(node, file, scope, isStatement) { this.staticMutatorMap = {}; this.hasConstructor = false; this.className = node.id || scope.generateUidIdentifier("class"); - this.superName = node.superClass || t.identifier("Function"); - this.hasSuper = !!node.superClass; + this.superName = node.superClassTransformer || t.identifier("Function"); + this.hasSuper = !!node.superClassTransformer; this.isLoose = file.isLoose("es6.classes"); } @@ -61,7 +61,7 @@ function Class(node, file, scope, isStatement) { * @returns {Array} */ -Class.prototype.run = function () { +ClassTransformer.prototype.run = function () { var superName = this.superName; var className = this.className; var file = this.file; @@ -138,7 +138,7 @@ Class.prototype.run = function () { * Description */ -Class.prototype.buildBody = function () { +ClassTransformer.prototype.buildBody = function () { var constructor = this.constructor; var className = this.className; var superName = this.superName; @@ -209,7 +209,7 @@ Class.prototype.buildBody = function () { * @param {Node} node MethodDefinition */ -Class.prototype.pushMethod = function (node) { +ClassTransformer.prototype.pushMethod = function (node) { var methodName = node.key; var kind = node.kind; @@ -251,7 +251,7 @@ Class.prototype.pushMethod = function (node) { * @param {Node} method MethodDefinition */ -Class.prototype.pushConstructor = function (method) { +ClassTransformer.prototype.pushConstructor = function (method) { if (method.kind) { throw this.file.errorWithNode(method, "illegal kind for constructor method"); } diff --git a/lib/6to5/transformation/transformers/es6/destructuring.js b/lib/6to5/transformation/transformers/es6/destructuring.js index 48bb576f2f..cbcdda2f88 100644 --- a/lib/6to5/transformation/transformers/es6/destructuring.js +++ b/lib/6to5/transformation/transformers/es6/destructuring.js @@ -4,7 +4,7 @@ var t = require("../../../types"); exports.check = t.isPattern; -function Destructuring(opts) { +function DestructuringTransformer(opts) { this.blockHoist = opts.blockHoist; this.operator = opts.operator; this.nodes = opts.nodes; @@ -13,7 +13,7 @@ function Destructuring(opts) { this.kind = opts.kind; } -Destructuring.prototype.buildVariableAssignment = function (id, init) { +DestructuringTransformer.prototype.buildVariableAssignment = function (id, init) { var op = this.operator; if (t.isMemberExpression(id)) op = "="; @@ -32,7 +32,7 @@ Destructuring.prototype.buildVariableAssignment = function (id, init) { return node; }; -Destructuring.prototype.buildVariableDeclaration = function (id, init) { +DestructuringTransformer.prototype.buildVariableDeclaration = function (id, init) { var declar = t.variableDeclaration("var", [ t.variableDeclarator(id, init) ]); @@ -40,7 +40,7 @@ Destructuring.prototype.buildVariableDeclaration = function (id, init) { return declar; }; -Destructuring.prototype.push = function (elem, parentId) { +DestructuringTransformer.prototype.push = function (elem, parentId) { if (t.isObjectPattern(elem)) { this.pushObjectPattern(elem, parentId); } else if (t.isArrayPattern(elem)) { @@ -52,7 +52,7 @@ Destructuring.prototype.push = function (elem, parentId) { } }; -Destructuring.prototype.pushAssignmentPattern = function (pattern, parentId) { +DestructuringTransformer.prototype.pushAssignmentPattern = function (pattern, parentId) { var tempParentId = this.scope.generateUidBasedOnNode(parentId); var declar = t.variableDeclaration("var", [ @@ -71,7 +71,7 @@ Destructuring.prototype.pushAssignmentPattern = function (pattern, parentId) { )); }; -Destructuring.prototype.pushObjectSpread = function (pattern, parentId, prop, i) { +DestructuringTransformer.prototype.pushObjectSpread = function (pattern, parentId, prop, i) { // get all the keys that appear in this object before the current spread var keys = []; for (var i2 = 0; i2 < pattern.properties.length; i2++) { @@ -92,7 +92,7 @@ Destructuring.prototype.pushObjectSpread = function (pattern, parentId, prop, i) this.nodes.push(this.buildVariableAssignment(prop.argument, value)); }; -Destructuring.prototype.pushObjectProperty = function (prop, parentId) { +DestructuringTransformer.prototype.pushObjectProperty = function (prop, parentId) { if (t.isLiteral(prop.key)) prop.computed = true; var pattern2 = prop.value; @@ -105,7 +105,7 @@ Destructuring.prototype.pushObjectProperty = function (prop, parentId) { } }; -Destructuring.prototype.pushObjectPattern = function (pattern, parentId) { +DestructuringTransformer.prototype.pushObjectPattern = function (pattern, parentId) { if (!pattern.properties.length) { this.nodes.push(t.expressionStatement( t.callExpression(this.file.addHelper("object-destructuring-empty"), [parentId]) @@ -137,7 +137,7 @@ var hasRest = function (pattern) { return false; }; -Destructuring.prototype.pushArrayPattern = function (pattern, parentId) { +DestructuringTransformer.prototype.pushArrayPattern = function (pattern, parentId) { if (!pattern.elements) return; // if we have a rest then we need all the elements @@ -173,7 +173,7 @@ Destructuring.prototype.pushArrayPattern = function (pattern, parentId) { } }; -Destructuring.prototype.init = function (pattern, parentId) { +DestructuringTransformer.prototype.init = function (pattern, parentId) { if (!t.isArrayExpression(parentId) && !t.isMemberExpression(parentId) && !t.isIdentifier(parentId)) { var key = this.scope.generateUidBasedOnNode(parentId); this.nodes.push(this.buildVariableDeclaration(key, parentId)); @@ -217,7 +217,7 @@ exports.ForOfStatement = function (node, parent, scope, file) { var nodes = []; - var destructuring = new Destructuring({ + var destructuring = new DestructuringTransformer({ kind: left.kind, file: file, scope: scope, @@ -235,15 +235,15 @@ exports.ForOfStatement = function (node, parent, scope, file) { exports.Function = function (node, parent, scope, file) { var nodes = []; - var hasDestructuring = false; + var hasDestructuringTransformer = false; node.params = node.params.map(function (pattern, i) { if (!t.isPattern(pattern)) return pattern; - hasDestructuring = true; + hasDestructuringTransformer = true; var parentId = scope.generateUidIdentifier("ref"); - var destructuring = new Destructuring({ + var destructuring = new DestructuringTransformer({ blockHoist: node.params.length - i, nodes: nodes, scope: scope, @@ -255,7 +255,7 @@ exports.Function = function (node, parent, scope, file) { return parentId; }); - if (!hasDestructuring) return; + if (!hasDestructuringTransformer) return; t.ensureBlock(node); @@ -272,7 +272,7 @@ exports.CatchClause = function (node, parent, scope, file) { var nodes = []; - var destructuring = new Destructuring({ + var destructuring = new DestructuringTransformer({ kind: "let", file: file, scope: scope, @@ -298,7 +298,7 @@ exports.ExpressionStatement = function (node, parent, scope, file) { t.variableDeclarator(ref, expr.right) ])); - var destructuring = new Destructuring({ + var destructuring = new DestructuringTransformer({ operator: expr.operator, file: file, scope: scope, @@ -321,7 +321,7 @@ exports.AssignmentExpression = function (node, parent, scope, file) { var nodes = []; nodes.push(t.assignmentExpression("=", ref, node.right)); - var destructuring = new Destructuring({ + var destructuring = new DestructuringTransformer({ operator: node.operator, file: file, scope: scope, @@ -356,7 +356,7 @@ exports.VariableDeclaration = function (node, parent, scope, file) { var patternId = declar.init; var pattern = declar.id; - var destructuring = new Destructuring({ + var destructuring = new DestructuringTransformer({ nodes: nodes, scope: scope, kind: node.kind, diff --git a/lib/6to5/transformation/transformers/es6/tail-call.js b/lib/6to5/transformation/transformers/es6/tail-call.js index 52c8baad2f..3f8888f84e 100644 --- a/lib/6to5/transformation/transformers/es6/tail-call.js +++ b/lib/6to5/transformation/transformers/es6/tail-call.js @@ -8,7 +8,7 @@ function returnBlock(expr) { return t.blockStatement([t.returnStatement(expr)]); } -function TailCall(node, scope, file) { +function TailCallTransformer(node, scope, file) { this.hasTailRecursion = false; this.needsArguments = false; this.setsArguments = false; @@ -21,23 +21,23 @@ function TailCall(node, scope, file) { this.node = node; } -TailCall.prototype.getArgumentsId = function () { +TailCallTransformer.prototype.getArgumentsId = function () { return this.argumentsId = this.argumentsId || this.scope.generateUidIdentifier("arguments"); }; -TailCall.prototype.getThisId = function () { +TailCallTransformer.prototype.getThisId = function () { return this.thisId = this.thisId || this.scope.generateUidIdentifier("this"); }; -TailCall.prototype.getLeftId = function () { +TailCallTransformer.prototype.getLeftId = function () { return this.leftId = this.leftId || this.scope.generateUidIdentifier("left"); }; -TailCall.prototype.getFunctionId = function () { +TailCallTransformer.prototype.getFunctionId = function () { return this.functionId = this.functionId || this.scope.generateUidIdentifier("function"); }; -TailCall.prototype.getParams = function () { +TailCallTransformer.prototype.getParams = function () { var params = this.params; if (!params) { @@ -58,7 +58,7 @@ TailCall.prototype.getParams = function () { return this.params = params; }; -TailCall.prototype.run = function () { +TailCallTransformer.prototype.run = function () { var scope = this.scope; var node = this.node; @@ -131,12 +131,12 @@ TailCall.prototype.run = function () { } }; -TailCall.prototype.subTransform = function (node) { +TailCallTransformer.prototype.subTransform = function (node) { var handler = this["subTransform" + node.type]; if (handler) return handler.call(this, node); }; -TailCall.prototype.subTransformConditionalExpression = function (node) { +TailCallTransformer.prototype.subTransformConditionalExpression = function (node) { var callConsequent = this.subTransform(node.consequent); var callAlternate = this.subTransform(node.alternate); if (!callConsequent && !callAlternate) { @@ -156,7 +156,7 @@ TailCall.prototype.subTransformConditionalExpression = function (node) { return [node]; }; -TailCall.prototype.subTransformLogicalExpression = function (node) { +TailCallTransformer.prototype.subTransformLogicalExpression = function (node) { // only call in right-value of can be optimized var callRight = this.subTransform(node.right); if (!callRight) return; @@ -176,7 +176,7 @@ TailCall.prototype.subTransformLogicalExpression = function (node) { return [t.ifStatement(testExpr, returnBlock(leftId))].concat(callRight); }; -TailCall.prototype.subTransformSequenceExpression = function (node) { +TailCallTransformer.prototype.subTransformSequenceExpression = function (node) { var seq = node.expressions; // only last element can be optimized @@ -194,7 +194,7 @@ TailCall.prototype.subTransformSequenceExpression = function (node) { return [t.expressionStatement(node)].concat(lastCall); }; -TailCall.prototype.subTransformCallExpression = function (node) { +TailCallTransformer.prototype.subTransformCallExpression = function (node) { var callee = node.callee, prop, thisBinding, args; if (t.isMemberExpression(callee, { computed: false }) && @@ -337,6 +337,6 @@ var thirdPass = { }; exports.Function = function (node, parent, scope, file) { - var tailCall = new TailCall(node, scope, file); + var tailCall = new TailCallTransformer(node, scope, file); tailCall.run(); };