diff --git a/lib/6to5/generation/buffer.js b/lib/6to5/generation/buffer.js index f881c8f533..6d731a17f0 100644 --- a/lib/6to5/generation/buffer.js +++ b/lib/6to5/generation/buffer.js @@ -2,10 +2,10 @@ module.exports = Buffer; -var util = require("../util"); -var isNumber = require("lodash/lang/isNumber"); var isBoolean = require("lodash/lang/isBoolean"); var contains = require("lodash/collection/contains"); +var isNumber = require("lodash/lang/isNumber"); +var util = require("../util"); function Buffer(position, format) { this.position = position; diff --git a/lib/6to5/generation/index.js b/lib/6to5/generation/index.js index 3c284bf009..c9ea55b912 100644 --- a/lib/6to5/generation/index.js +++ b/lib/6to5/generation/index.js @@ -12,12 +12,12 @@ var Whitespace = require("./whitespace"); var SourceMap = require("./source-map"); var Position = require("./position"); var Buffer = require("./buffer"); +var extend = require("lodash/object/extend"); +var merge = require("lodash/object/merge"); +var each = require("lodash/collection/each"); var util = require("../util"); var n = require("./node"); var t = require("../types"); -var each = require("lodash/collection/each"); -var extend = require("lodash/object/extend"); -var merge = require("lodash/object/merge"); function CodeGenerator(ast, opts, code) { opts = opts || {}; @@ -25,6 +25,7 @@ function CodeGenerator(ast, opts, code) { this.comments = ast.comments || []; this.tokens = ast.tokens || []; this.format = CodeGenerator.normalizeOptions(code, opts); + this.opts = opts; this.ast = ast; this.whitespace = new Whitespace(this.tokens, this.comments); diff --git a/lib/6to5/transformation/helpers/define-map.js b/lib/6to5/transformation/helpers/define-map.js index cd7f82b0f1..abbd846fda 100644 --- a/lib/6to5/transformation/helpers/define-map.js +++ b/lib/6to5/transformation/helpers/define-map.js @@ -1,6 +1,6 @@ var cloneDeep = require("lodash/lang/cloneDeep"); var traverse = require("../../traversal"); -var clone = require("lodash/lang/clone"); +var clone = require("lodash/lang/clone"); var each = require("lodash/collection/each"); var has = require("lodash/object/has"); var t = require("../../types"); diff --git a/lib/6to5/transformation/modules/amd.js b/lib/6to5/transformation/modules/amd.js index eca421f199..4ee4b44268 100644 --- a/lib/6to5/transformation/modules/amd.js +++ b/lib/6to5/transformation/modules/amd.js @@ -29,9 +29,8 @@ AMDFormatter.prototype.buildDependencyLiterals = function () { * Wrap the entire body in a `define` wrapper. */ -AMDFormatter.prototype.transform = function (ast) { - var program = ast.program; - var body = program.body; +AMDFormatter.prototype.transform = function (program) { + var body = program.body; // build an array of module names diff --git a/lib/6to5/transformation/modules/system.js b/lib/6to5/transformation/modules/system.js index 555023c7e9..4f0f3f0208 100644 --- a/lib/6to5/transformation/modules/system.js +++ b/lib/6to5/transformation/modules/system.js @@ -158,9 +158,7 @@ var hoistFunctionsVisitor = { } }; -SystemFormatter.prototype.transform = function (ast) { - var program = ast.program; - +SystemFormatter.prototype.transform = function (program) { var hoistDeclarators = []; var moduleName = this.getModuleName(); var moduleNameLiteral = t.literal(moduleName); diff --git a/lib/6to5/transformation/modules/umd.js b/lib/6to5/transformation/modules/umd.js index da86b4dfb5..a4bdf92ec1 100644 --- a/lib/6to5/transformation/modules/umd.js +++ b/lib/6to5/transformation/modules/umd.js @@ -13,9 +13,8 @@ function UMDFormatter() { util.inherits(UMDFormatter, AMDFormatter); -UMDFormatter.prototype.transform = function (ast) { - var program = ast.program; - var body = program.body; +UMDFormatter.prototype.transform = function (program) { + var body = program.body; // build an array of module names diff --git a/lib/6to5/transformation/transformers/internal/module-formatter.js b/lib/6to5/transformation/transformers/internal/module-formatter.js index f1a7c81c89..3bacf0a1dd 100644 --- a/lib/6to5/transformation/transformers/internal/module-formatter.js +++ b/lib/6to5/transformation/transformers/internal/module-formatter.js @@ -2,16 +2,16 @@ var useStrict = require("../../helpers/use-strict"); -exports.ast = { - exit: function (ast, file) { +exports.Program = { + exit: function (program, parent, scope, context, file) { if (!file.transformers["es6.modules"].canRun()) return; - useStrict.wrap(ast.program, function () { - ast.program.body = file.dynamicImports.concat(ast.program.body); + useStrict.wrap(program, function () { + program.body = file.dynamicImports.concat(program.body); }); if (file.moduleFormatter.transform) { - file.moduleFormatter.transform(ast); + file.moduleFormatter.transform(program); } } }; diff --git a/lib/6to5/transformation/transformers/other/regenerator.js b/lib/6to5/transformation/transformers/other/regenerator.js index d4a9119e7a..766956e95d 100644 --- a/lib/6to5/transformation/transformers/other/regenerator.js +++ b/lib/6to5/transformation/transformers/other/regenerator.js @@ -1,16 +1,14 @@ "use strict"; var regenerator = require("regenerator-6to5"); -var t = require("../../../types"); exports.check = function (node) { return t.isFunction(node) && (node.async || node.generator); }; -exports.ast = { - before: function (ast, file) { - regenerator.transform(ast, { - includeRuntime: file.opts.includeRegenerator && "if used" - }); +exports.Program = { + enter: function (ast) { + regenerator.transform(ast); + this.stop(); } }; diff --git a/lib/6to5/transformation/transformers/other/self-contained.js b/lib/6to5/transformation/transformers/other/self-contained.js index d1e7749138..3ff1c8d9da 100644 --- a/lib/6to5/transformation/transformers/other/self-contained.js +++ b/lib/6to5/transformation/transformers/other/self-contained.js @@ -64,8 +64,8 @@ exports.manipulateOptions = function (opts) { if (opts.whitelist.length) opts.whitelist.push("es6.modules"); }; -exports.ast = { - enter: function (ast, file) { +exports.Program = { + enter: function (node, parent, scope, context, file) { file.setDynamic("runtimeIdentifier", function () { return file.addImport("6to5-runtime/helpers", "to5Helpers"); }); @@ -79,8 +79,8 @@ exports.ast = { }); }, - after: function (ast, file) { - file.scope.traverse(ast, astVisitor, file); + exit: function (node, parent, scope, context, file) { + file.scope.traverse(node, astVisitor, file); } }; diff --git a/lib/6to5/transformation/transformers/other/use-strict.js b/lib/6to5/transformation/transformers/other/use-strict.js index 12751e4ba3..87d9672cc8 100644 --- a/lib/6to5/transformation/transformers/other/use-strict.js +++ b/lib/6to5/transformation/transformers/other/use-strict.js @@ -3,10 +3,10 @@ var useStrict = require("../../helpers/use-strict"); var t = require("../../../types"); -exports.ast = { - exit: function (ast) { - if (!useStrict.has(ast.program)) { - ast.program.body.unshift(t.expressionStatement(t.literal("use strict"))); +exports.Program = { + exit: function (program) { + if (!useStrict.has(program)) { + program.body.unshift(t.expressionStatement(t.literal("use strict"))); } } };