diff --git a/lib/6to5/file.js b/lib/6to5/file.js index e7c2badea5..73c10aef1f 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -17,7 +17,7 @@ function File(opts) { this.ast = {}; } -File.declarations = [ +File.helpers = [ "inherits", "defaults", "prototype-properties", @@ -33,7 +33,7 @@ File.declarations = [ "async-to-generator" ]; -File.excludeDeclarationsFromRuntime = [ +File.excludeHelpersFromRuntime = [ "async-to-generator" ]; @@ -121,7 +121,7 @@ File.prototype.toArray = function (node, i) { if (t.isArrayExpression(node)) { return node; } else if (t.isIdentifier(node) && node.name === "arguments") { - return t.callExpression(t.memberExpression(this.addDeclaration("slice"), t.identifier("call")), [node]); + return t.callExpression(t.memberExpression(this.addHelper("slice"), t.identifier("call")), [node]); } else { var declarationName = "to-array"; var args = [node]; @@ -129,7 +129,7 @@ File.prototype.toArray = function (node, i) { args.push(t.literal(i)); declarationName = "sliced-to-array"; } - return t.callExpression(this.addDeclaration(declarationName), args); + return t.callExpression(this.addHelper(declarationName), args); } }; @@ -167,8 +167,8 @@ File.prototype.addImport = function (id, source) { this.dynamicImports.push(declar); }; -File.prototype.addDeclaration = function (name) { - if (!_.contains(File.declarations, name)) { +File.prototype.addHelper = function (name) { + if (!_.contains(File.helpers, name)) { throw new ReferenceError("unknown declaration " + name); } @@ -179,7 +179,7 @@ File.prototype.addDeclaration = function (name) { var ref; var runtimeNamespace = this.opts.runtime; - if (runtimeNamespace && !_.contains(File.excludeDeclarationsFromRuntime, name)) { + if (runtimeNamespace && !_.contains(File.excludeHelpersFromRuntime, name)) { name = t.identifier(t.toIdentifier(name)); return t.memberExpression(t.identifier(runtimeNamespace), name); } else { diff --git a/lib/6to5/runtime-generator.js b/lib/6to5/runtime-generator.js index 59ad533466..ec9924ecc5 100644 --- a/lib/6to5/runtime-generator.js +++ b/lib/6to5/runtime-generator.js @@ -18,8 +18,8 @@ module.exports = function (namespace) { ) ])); - _.each(File.declarations, function (name) { - if (_.contains(File.excludeDeclarationsFromRuntime, name)) { + _.each(File.helpers, function (name) { + if (_.contains(File.excludeHelpersFromRuntime, name)) { return false; } diff --git a/lib/6to5/transformation/modules/amd.js b/lib/6to5/transformation/modules/amd.js index 48ba860fe5..bb4b4137ae 100644 --- a/lib/6to5/transformation/modules/amd.js +++ b/lib/6to5/transformation/modules/amd.js @@ -85,7 +85,7 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) { // import * as bar from "foo"; } else if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) { // import foo from "foo"; - ref = t.callExpression(this.file.addDeclaration("interop-require"), [ref]); + ref = t.callExpression(this.file.addHelper("interop-require"), [ref]); } else { // import {foo} from "foo"; ref = t.memberExpression(ref, specifier.id, false); diff --git a/lib/6to5/transformation/modules/common.js b/lib/6to5/transformation/modules/common.js index d2735ecd2d..d527e49e73 100644 --- a/lib/6to5/transformation/modules/common.js +++ b/lib/6to5/transformation/modules/common.js @@ -26,7 +26,7 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes) if (t.isSpecifierDefault(specifier)) { nodes.push(t.variableDeclaration("var", [ t.variableDeclarator(variableName, - t.callExpression(this.file.addDeclaration("interop-require"), [util.template("require", { + t.callExpression(this.file.addHelper("interop-require"), [util.template("require", { MODULE_NAME: node.source })]) ) diff --git a/lib/6to5/transformation/transformers/es6-classes.js b/lib/6to5/transformation/transformers/es6-classes.js index 62048733fa..f0922ebb8b 100644 --- a/lib/6to5/transformation/transformers/es6-classes.js +++ b/lib/6to5/transformation/transformers/es6-classes.js @@ -96,7 +96,7 @@ Class.prototype.run = function () { superName = superRef; this.superName = superName; - body.push(t.expressionStatement(t.callExpression(file.addDeclaration("inherits"), [className, superName]))); + body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName]))); } this.buildBody(); @@ -175,7 +175,7 @@ Class.prototype.buildBody = function () { if (instanceProps) args.push(instanceProps); body.push(t.expressionStatement( - t.callExpression(this.file.addDeclaration("prototype-properties"), args) + t.callExpression(this.file.addHelper("prototype-properties"), args) )); } }; diff --git a/lib/6to5/transformation/transformers/es6-computed-property-names.js b/lib/6to5/transformation/transformers/es6-computed-property-names.js index 2ae78da58f..57312902e5 100644 --- a/lib/6to5/transformation/transformers/es6-computed-property-names.js +++ b/lib/6to5/transformation/transformers/es6-computed-property-names.js @@ -68,7 +68,7 @@ exports.ObjectExpression = function (node, parent, file, scope) { prop.value ); } else { - bodyNode = t.callExpression(file.addDeclaration("define-property"), [objId, key, prop.value]); + bodyNode = t.callExpression(file.addHelper("define-property"), [objId, key, prop.value]); } body.push(t.expressionStatement(bodyNode)); diff --git a/lib/6to5/transformation/transformers/es6-destructuring.js b/lib/6to5/transformation/transformers/es6-destructuring.js index 8858790d77..c8b7bffb36 100644 --- a/lib/6to5/transformation/transformers/es6-destructuring.js +++ b/lib/6to5/transformation/transformers/es6-destructuring.js @@ -45,7 +45,7 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) { } keys = t.arrayExpression(keys); - var value = t.callExpression(opts.file.addDeclaration("object-without-properties"), [parentId, keys]); + var value = t.callExpression(opts.file.addHelper("object-without-properties"), [parentId, keys]); nodes.push(buildVariableAssign(opts, prop.argument, value)); } else { var pattern2 = prop.value; diff --git a/lib/6to5/transformation/transformers/es6-spread.js b/lib/6to5/transformation/transformers/es6-spread.js index bde318aa6d..214a765f03 100644 --- a/lib/6to5/transformation/transformers/es6-spread.js +++ b/lib/6to5/transformation/transformers/es6-spread.js @@ -107,5 +107,5 @@ exports.NewExpression = function (node, parent, file) { args = first; } - return t.callExpression(file.addDeclaration("apply-constructor"), [node.callee, args]); + return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]); }; diff --git a/lib/6to5/transformation/transformers/es6-template-literals.js b/lib/6to5/transformation/transformers/es6-template-literals.js index 5a5f4ce445..4be21d4269 100644 --- a/lib/6to5/transformation/transformers/es6-template-literals.js +++ b/lib/6to5/transformation/transformers/es6-template-literals.js @@ -17,7 +17,7 @@ exports.TaggedTemplateExpression = function (node, parent, file) { raw.push(t.literal(elem.value.raw)); } - args.push(t.callExpression(file.addDeclaration("tagged-template-literal"), [ + args.push(t.callExpression(file.addHelper("tagged-template-literal"), [ t.arrayExpression(strings), t.arrayExpression(raw) ])); diff --git a/lib/6to5/transformation/transformers/optional-async-to-generator.js b/lib/6to5/transformation/transformers/optional-async-to-generator.js index 9886b8d6bd..551c9f7c71 100644 --- a/lib/6to5/transformation/transformers/optional-async-to-generator.js +++ b/lib/6to5/transformation/transformers/optional-async-to-generator.js @@ -7,5 +7,5 @@ exports.manipulateOptions = bluebirdCoroutines.manipulateOptions; exports.Function = function (node, parent, file) { if (!node.async || node.generator) return; - return bluebirdCoroutines._Function(node, file.addDeclaration("async-to-generator")); + return bluebirdCoroutines._Function(node, file.addHelper("async-to-generator")); }; diff --git a/lib/6to5/transformation/transformers/optional-proto-to-assign.js b/lib/6to5/transformation/transformers/optional-proto-to-assign.js index 3101abf474..0f18f5a547 100644 --- a/lib/6to5/transformation/transformers/optional-proto-to-assign.js +++ b/lib/6to5/transformation/transformers/optional-proto-to-assign.js @@ -13,7 +13,7 @@ var isProtoAssignmentExpression = function (node) { }; var buildDefaultsCallExpression = function (expr, ref, file) { - return t.expressionStatement(t.callExpression(file.addDeclaration("defaults"), [ref, expr.right])); + return t.expressionStatement(t.callExpression(file.addHelper("defaults"), [ref, expr.right])); }; exports.optional = true; diff --git a/lib/6to5/transformation/transformers/playground-memoization-operator.js b/lib/6to5/transformation/transformers/playground-memoization-operator.js index c8cf35b4d8..d8aad48236 100644 --- a/lib/6to5/transformation/transformers/playground-memoization-operator.js +++ b/lib/6to5/transformation/transformers/playground-memoization-operator.js @@ -30,7 +30,7 @@ var buildHasOwn = function (obj, prop, file) { return t.unaryExpression( "!", t.callExpression( - t.memberExpression(file.addDeclaration("has-own"), t.identifier("call")), + t.memberExpression(file.addHelper("has-own"), t.identifier("call")), [obj, prop] ), true diff --git a/lib/6to5/transformation/transformers/playground-object-getter-memoization.js b/lib/6to5/transformation/transformers/playground-object-getter-memoization.js index 3fdb70beb6..9c3f0bb6d0 100644 --- a/lib/6to5/transformation/transformers/playground-object-getter-memoization.js +++ b/lib/6to5/transformation/transformers/playground-object-getter-memoization.js @@ -20,7 +20,7 @@ exports.MethodDefinition = function (node, parent, file) { if (t.isFunction(node)) return; if (t.isReturnStatement(node) && node.argument) { - node.argument = t.memberExpression(t.callExpression(file.addDeclaration("define-property"), [ + node.argument = t.memberExpression(t.callExpression(file.addHelper("define-property"), [ t.thisExpression(), key, node.argument diff --git a/test/api.js b/test/api.js index 260c7f4483..5559760643 100644 --- a/test/api.js +++ b/test/api.js @@ -13,10 +13,10 @@ suite("api", function () { assert.ok(!result.ast); }); - test("addDeclaration unknown", function () { + test("addHelper unknown", function () { var file = new File; assert.throws(function () { - file.addDeclaration("foob"); + file.addHelper("foob"); }, /unknown declaration foob/); }); });