From ed40ec03d1e9d63f5b36c434308f8718d49b7f67 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 3 Mar 2015 22:31:49 +1100 Subject: [PATCH] more es6, template literals and modules --- src/babel/api/browser.js | 2 +- src/babel/api/register/node.js | 2 +- src/babel/api/register/resolve-rc.js | 2 +- src/babel/generation/buffer.js | 2 +- .../generation/generators/expressions.js | 11 ++-- src/babel/generation/generators/methods.js | 7 ++- src/babel/generation/generators/modules.js | 2 +- src/babel/generation/generators/playground.js | 2 +- src/babel/generation/generators/statements.js | 4 +- src/babel/generation/generators/types.js | 24 ++++---- src/babel/generation/index.js | 8 +-- src/babel/helpers/code-frame.js | 3 +- src/babel/helpers/parse.js | 2 +- src/babel/messages.js | 6 +- .../transformation/helpers/define-map.js | 2 +- .../helpers/explode-assignable-expression.js | 2 +- src/babel/transformation/helpers/strict.js | 2 +- src/babel/transformation/index.js | 4 +- src/babel/transformation/transformer-pass.js | 2 +- .../transformers/es6/block-scoping-tdz.js | 6 +- .../transformers/es6/block-scoping.js | 2 +- .../transformers/es6/classes.js | 2 +- .../transformers/es6/tail-call.js | 2 +- .../utility/dead-code-elimination.js | 8 +-- .../utility/inline-expressions.js | 8 ++- src/babel/traversal/index.js | 2 +- src/babel/traversal/scope.js | 37 +++++++++++- src/babel/types/index.js | 57 +++++++++++++++---- src/babel/util.js | 6 +- 29 files changed, 146 insertions(+), 73 deletions(-) diff --git a/src/babel/api/browser.js b/src/babel/api/browser.js index 248d668e37..82671a3712 100644 --- a/src/babel/api/browser.js +++ b/src/babel/api/browser.js @@ -25,7 +25,7 @@ transform.load = function (url, callback, opts = {}, hold) { if (!hold) transform.run.apply(transform, param); if (callback) callback(param); } else { - throw new Error("Could not load " + url); + throw new Error(`Could not load ${url}`); } }; diff --git a/src/babel/api/register/node.js b/src/babel/api/register/node.js index e344ca0ab6..3dcc25499a 100644 --- a/src/babel/api/register/node.js +++ b/src/babel/api/register/node.js @@ -46,7 +46,7 @@ var compile = function (filename) { var opts = extend({}, transformOpts); resolveRc(filename, opts); - var cacheKey = filename + ":" + JSON.stringify(opts); + var cacheKey = `${filename}:${JSON.stringify(opts)}`; if (cache) { var cached = cache[cacheKey]; diff --git a/src/babel/api/register/resolve-rc.js b/src/babel/api/register/resolve-rc.js index 4728f214ba..ae63083e88 100644 --- a/src/babel/api/register/resolve-rc.js +++ b/src/babel/api/register/resolve-rc.js @@ -23,7 +23,7 @@ export default function (loc, opts = {}) { try { json = JSON.parse(content); } catch (err) { - err.message = file + ": " + err.message; + err.message = `${file}: ${err.message}`; throw err; } diff --git a/src/babel/generation/buffer.js b/src/babel/generation/buffer.js index f47199d51d..2e909cf525 100644 --- a/src/babel/generation/buffer.js +++ b/src/babel/generation/buffer.js @@ -140,7 +140,7 @@ export default class Buffer { var indent = this.getIndent(); // replace all newlines with newlines with the indentation - str = str.replace(/\n/g, "\n" + indent); + str = str.replace(/\n/g, `\n${indent}`); // we've got a newline before us so prepend on the indentation if (this.isLast("\n")) this._push(indent); diff --git a/src/babel/generation/generators/expressions.js b/src/babel/generation/generators/expressions.js index e13ddba8f0..650d3d9b68 100644 --- a/src/babel/generation/generators/expressions.js +++ b/src/babel/generation/generators/expressions.js @@ -109,16 +109,19 @@ export function ExpressionStatement(node, print) { this.semicolon(); } -exports.BinaryExpression = -exports.LogicalExpression = -exports.AssignmentPattern = -exports.AssignmentExpression = function (node, print) { +export function AssignmentExpression(node, print) { // todo: add cases where the spaces can be dropped when in compact mode print(node.left); this.push(" "); this.push(node.operator); this.push(" "); print(node.right); +} + +export { + AssignmentExpression as BinaryExpression, + AssignmentExpression as LogicalExpression, + AssignmentExpression as AssignmentPattern }; var SCIENTIFIC_NOTATION = /e/i; diff --git a/src/babel/generation/generators/methods.js b/src/babel/generation/generators/methods.js index 3c170ab785..d20bcf7add 100644 --- a/src/babel/generation/generators/methods.js +++ b/src/babel/generation/generators/methods.js @@ -44,8 +44,7 @@ export function _method(node, print) { print(value.body); } -exports.FunctionDeclaration = -exports.FunctionExpression = function (node, print) { +export function FunctionExpression(node, print) { if (node.async) this.push("async "); this.push("function"); if (node.generator) this.push("*"); @@ -60,7 +59,9 @@ exports.FunctionExpression = function (node, print) { this._params(node, print); this.space(); print(node.body); -}; +} + +export { FunctionExpression as FunctionDeclaration }; export function ArrowFunctionExpression(node, print) { if (node.async) this.push("async "); diff --git a/src/babel/generation/generators/modules.js b/src/babel/generation/generators/modules.js index a051127446..b1299335d0 100644 --- a/src/babel/generation/generators/modules.js +++ b/src/babel/generation/generators/modules.js @@ -5,7 +5,7 @@ export function ImportSpecifier(node, print) { if (t.isSpecifierDefault(node)) { print(t.getSpecifierName(node)); } else { - return exports.ExportSpecifier.apply(this, arguments); + return ExportSpecifier.apply(this, arguments); } } diff --git a/src/babel/generation/generators/playground.js b/src/babel/generation/generators/playground.js index 6c26bc34d1..f3a7e5bf8c 100644 --- a/src/babel/generation/generators/playground.js +++ b/src/babel/generation/generators/playground.js @@ -2,6 +2,6 @@ import each from "lodash/collection/each"; each(["BindMemberExpression", "BindFunctionExpression"], function (type) { exports[type] = function () { - throw new ReferenceError("Trying to render non-standard playground node " + JSON.stringify(type)); + throw new ReferenceError(`Trying to render non-standard playground node ${JSON.stringify(type)}`); }; }); diff --git a/src/babel/generation/generators/statements.js b/src/babel/generation/generators/statements.js index 7ffdbd015f..86edb6005e 100644 --- a/src/babel/generation/generators/statements.js +++ b/src/babel/generation/generators/statements.js @@ -60,7 +60,7 @@ var buildForXStatement = function (op) { this.keyword("for"); this.push("("); print(node.left); - this.push(" " + op + " "); + this.push(` ${op} `); print(node.right); this.push(")"); print.block(node.body); @@ -192,7 +192,7 @@ export function VariableDeclaration(node, print, parent) { var sep = ","; if (!this.format.compact && hasInits) { - sep += "\n" + repeating(" ", node.kind.length + 1); + sep += `\n${repeating(" ", node.kind.length + 1)}`; } else { sep += " "; } diff --git a/src/babel/generation/generators/types.js b/src/babel/generation/generators/types.js index 87b6d5da4a..dcc685e3f7 100644 --- a/src/babel/generation/generators/types.js +++ b/src/babel/generation/generators/types.js @@ -4,12 +4,12 @@ export function Identifier(node) { this.push(node.name); } -exports.RestElement = -exports.SpreadElement = -exports.SpreadProperty = function (node, print) { +export function RestElement(node, print) { this.push("..."); print(node.argument); -}; +} + +export { RestElement as SpreadElement, RestElement as SpreadProperty }; export function VirtualPropertyExpression(node, print) { print(node.object); @@ -17,8 +17,7 @@ export function VirtualPropertyExpression(node, print) { print(node.property); } -exports.ObjectExpression = -exports.ObjectPattern = function (node, print) { +export function ObjectExpression(node, print) { var props = node.properties; if (props.length) { @@ -32,7 +31,9 @@ exports.ObjectPattern = function (node, print) { } else { this.push("{}"); } -}; +} + +export { ObjectExpression as ObjectPattern }; export function Property(node, print) { if (node.method || node.kind === "get" || node.kind === "set") { @@ -53,8 +54,7 @@ export function Property(node, print) { } } -exports.ArrayExpression = -exports.ArrayPattern = function (node, print) { +export function ArrayExpression(node, print) { var elems = node.elements; var len = elems.length; @@ -76,7 +76,9 @@ exports.ArrayPattern = function (node, print) { }); this.push("]"); -}; +} + +export { ArrayExpression as ArrayPattern }; export function Literal(node) { var val = node.value; @@ -89,7 +91,7 @@ export function Literal(node) { } else if (type === "boolean") { this.push(val ? "true" : "false"); } else if (node.regex) { - this.push("/" + node.regex.pattern + "/" + node.regex.flags); + this.push(`/${node.regex.pattern}/${node.regex.flags}`); } else if (val === null) { this.push("null"); } diff --git a/src/babel/generation/index.js b/src/babel/generation/index.js index 6fdadfe589..6c0394d8e8 100644 --- a/src/babel/generation/index.js +++ b/src/babel/generation/index.js @@ -187,7 +187,7 @@ class CodeGenerator { this.printTrailingComments(node, parent); } else { - throw new ReferenceError("unknown node of type " + JSON.stringify(node.type) + " with constructor " + JSON.stringify(node && node.constructor.name)); + throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`); } this.format.concise = oldConcise; @@ -238,9 +238,9 @@ class CodeGenerator { generateComment(comment) { var val = comment.value; if (comment.type === "Line") { - val = "//" + val; + val = `//${val}`; } else { - val = "/*" + val + "*/"; + val = `/*${val}*/`; } return val; } @@ -319,7 +319,7 @@ class CodeGenerator { } var indent = Math.max(this.indentSize(), column); - val = val.replace(/\n/g, "\n" + repeating(" ", indent)); + val = val.replace(/\n/g, `\n${repeating(" ", indent)}`); } if (column === 0) { diff --git a/src/babel/helpers/code-frame.js b/src/babel/helpers/code-frame.js index 9c8505ae85..caafa4e87d 100644 --- a/src/babel/helpers/code-frame.js +++ b/src/babel/helpers/code-frame.js @@ -81,8 +81,7 @@ module.exports = function (lines, lineNumber, colNumber) { return; } if (colNumber) { - params.line += "\n" + params.before + repeating(" ", params.width) + - params.after + repeating(" ", colNumber - 1) + "^"; + params.line += `\n${params.before}${repeating(" ", params.width)}${params.after}${repeating(" ", colNumber - 1)}^`; } params.before = params.before.replace(/^./, ">"); } diff --git a/src/babel/helpers/parse.js b/src/babel/helpers/parse.js index 858f01e083..20997af4f5 100644 --- a/src/babel/helpers/parse.js +++ b/src/babel/helpers/parse.js @@ -32,7 +32,7 @@ module.exports = function (opts, code, callback) { } catch (err) { if (!err._babel) { err._babel = true; - var message = opts.filename + ": " + err.message; + var message = `${opts.filename}: ${err.message}`; var loc = err.loc; if (loc) { diff --git a/src/babel/messages.js b/src/babel/messages.js index b3f0ebe155..73c8848ddf 100644 --- a/src/babel/messages.js +++ b/src/babel/messages.js @@ -22,14 +22,14 @@ export var messages = { }; export function get(key) { - var msg = exports.messages[key]; - if (!msg) throw new ReferenceError("Unknown message `" + key + "`"); + var msg = messages[key]; + if (!msg) throw new ReferenceError(`Unknown message ${JSON.stringify(key)}`); var args = []; for (var i = 1; i < arguments.length; i++) { args.push(arguments[i]); } - args = exports.parseArgs(args); + args = parseArgs(args); return msg.replace(/\$(\d+)/g, function (str, i) { return args[--i]; diff --git a/src/babel/transformation/helpers/define-map.js b/src/babel/transformation/helpers/define-map.js index fdc2099ba2..a951974cf5 100644 --- a/src/babel/transformation/helpers/define-map.js +++ b/src/babel/transformation/helpers/define-map.js @@ -10,7 +10,7 @@ export function push(mutatorMap, key, kind, computed, value) { if (t.isIdentifier(key)) { alias = key.name; - if (computed) alias = "computed:" + alias; + if (computed) alias = `computed:${alias}`; } else if (t.isLiteral(key)) { alias = String(key.value); } else { diff --git a/src/babel/transformation/helpers/explode-assignable-expression.js b/src/babel/transformation/helpers/explode-assignable-expression.js index 52f79ead83..bfecd0f26b 100644 --- a/src/babel/transformation/helpers/explode-assignable-expression.js +++ b/src/babel/transformation/helpers/explode-assignable-expression.js @@ -23,7 +23,7 @@ var getObjRef = function (node, nodes, file, scope) { return ref; } } else { - throw new Error("We can't explode this node type " + node.type); + throw new Error(`We can't explode this node type ${node.type}`); } var temp = scope.generateUidBasedOnNode(ref); diff --git a/src/babel/transformation/helpers/strict.js b/src/babel/transformation/helpers/strict.js index a5c959fe20..d5dbe31b41 100644 --- a/src/babel/transformation/helpers/strict.js +++ b/src/babel/transformation/helpers/strict.js @@ -7,7 +7,7 @@ export function has(node) { export function wrap(node, callback) { var useStrictNode; - if (exports.has(node)) { + if (has(node)) { useStrictNode = node.body.shift(); } diff --git a/src/babel/transformation/index.js b/src/babel/transformation/index.js index b56db8ab88..2aa34a2008 100644 --- a/src/babel/transformation/index.js +++ b/src/babel/transformation/index.js @@ -30,7 +30,7 @@ transform._ensureTransformerNames = function (type, rawKeys) { keys.push(aliasKey); } else if (deprecatedKey) { // deprecated key, remap it to the new one - console.error("The transformer " + key + " has been renamed to " + deprecatedKey); + console.error(`The transformer ${key} has been renamed to ${deprecatedKey}`); rawKeys.push(deprecatedKey); } else if (transform.transformers[key]) { // valid key @@ -40,7 +40,7 @@ transform._ensureTransformerNames = function (type, rawKeys) { keys = keys.concat(transform.namespaces[key]); } else { // invalid key - throw new ReferenceError("Unknown transformer " + key + " specified in " + type); + throw new ReferenceError(`Unknown transformer ${key} specified in ${type}`); } } diff --git a/src/babel/transformation/transformer-pass.js b/src/babel/transformation/transformer-pass.js index d691b42ebc..6282aa7a48 100644 --- a/src/babel/transformation/transformer-pass.js +++ b/src/babel/transformation/transformer-pass.js @@ -56,7 +56,7 @@ export default class TransformerPass { var file = this.file; - file.debug("Running transformer " + this.transformer.key); + file.debug(`Running transformer ${this.transformer.key}`); file.scope.traverse(file.ast, this.handlers, file); } diff --git a/src/babel/transformation/transformers/es6/block-scoping-tdz.js b/src/babel/transformation/transformers/es6/block-scoping-tdz.js index 563923beaf..5fbb842573 100644 --- a/src/babel/transformation/transformers/es6/block-scoping-tdz.js +++ b/src/babel/transformation/transformers/es6/block-scoping-tdz.js @@ -32,12 +32,10 @@ export function BlockStatement(node, parent, scope, file) { var letRefs = node._letReferences; if (!letRefs) return; - var state = { + scope.traverse(node, visitor, { letRefs: letRefs, file: file - }; - - scope.traverse(node, visitor, state); + }); } export { BlockStatement as Program, BlockStatement as Loop }; diff --git a/src/babel/transformation/transformers/es6/block-scoping.js b/src/babel/transformation/transformers/es6/block-scoping.js index 39d43664d7..0e2aa04581 100644 --- a/src/babel/transformation/transformers/es6/block-scoping.js +++ b/src/babel/transformation/transformers/es6/block-scoping.js @@ -189,7 +189,7 @@ var loopVisitor = { return; } - loopText = loopText + "|" + node.label.name; + loopText = `${loopText}|${node.label.name}`; } else { // we shouldn't be transforming these statements because // they don't refer to the actual loop we're scopifying diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index e77857fa53..2386c5b995 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -182,7 +182,7 @@ class ClassTransformer { } // we have no constructor, we have a super, and the super doesn't appear to be falsy - if (!this.hasConstructor && this.hasSuper && t.evaluateTruthy(superName) !== false) { + if (!this.hasConstructor && this.hasSuper && t.evaluateTruthy(superName, this.scope) !== false) { var helperName = "class-super-constructor-call"; if (this.isLoose) helperName += "-loose"; constructor.body.body.push(util.template(helperName, { diff --git a/src/babel/transformation/transformers/es6/tail-call.js b/src/babel/transformation/transformers/es6/tail-call.js index 439b3f1712..7cb201b002 100644 --- a/src/babel/transformation/transformers/es6/tail-call.js +++ b/src/babel/transformation/transformers/es6/tail-call.js @@ -229,7 +229,7 @@ class TailCallTransformer { subTransform(node) { if (!node) return; - var handler = this["subTransform" + node.type]; + var handler = this[`subTransform${node.type}`]; if (handler) return handler.call(this, node); } diff --git a/src/babel/transformation/transformers/utility/dead-code-elimination.js b/src/babel/transformation/transformers/utility/dead-code-elimination.js index a8e4430dbe..486b31edee 100644 --- a/src/babel/transformation/transformers/utility/dead-code-elimination.js +++ b/src/babel/transformation/transformers/utility/dead-code-elimination.js @@ -19,8 +19,8 @@ function toStatements(node) { export var optional = true; -export function ConditionalExpression(node) { - var evaluateTest = t.evaluateTruthy(node.test); +export function ConditionalExpression(node, parent, scope) { + var evaluateTest = t.evaluateTruthy(node.test, scope); if (evaluateTest === true) { return node.consequent; } else if (evaluateTest === false) { @@ -29,12 +29,12 @@ export function ConditionalExpression(node) { } export var IfStatement = { - exit(node) { + exit(node, parent, scope) { var consequent = node.consequent; var alternate = node.alternate; var test = node.test; - var evaluateTest = t.evaluateTruthy(test); + var evaluateTest = t.evaluateTruthy(test, scope); // we can check if a test will be truthy 100% and if so then we can inline // the consequent and completely ignore the alternate diff --git a/src/babel/transformation/transformers/utility/inline-expressions.js b/src/babel/transformation/transformers/utility/inline-expressions.js index 6dada3a898..b95ee1585c 100644 --- a/src/babel/transformation/transformers/utility/inline-expressions.js +++ b/src/babel/transformation/transformers/utility/inline-expressions.js @@ -2,7 +2,11 @@ import t from "../../../types"; export var optional = true; -export function Expression(node) { - var res = t.evaluate(node); +export function Expression(node, parent, scope) { + var res = t.evaluate(node, scope); if (res.confident) return t.valueToNode(res.value); } + +export function Identifier() { + // override Expression +} diff --git a/src/babel/traversal/index.js b/src/babel/traversal/index.js index 31a45c6462..062dd40459 100644 --- a/src/babel/traversal/index.js +++ b/src/babel/traversal/index.js @@ -9,7 +9,7 @@ function traverse(parent, opts, scope, state) { if (!opts.noScope && !scope) { if (parent.type !== "Program" && parent.type !== "File") { - throw new Error("Must pass a scope unless traversing a Program/File got a " + parent.type + " node"); + throw new Error(`Must pass a scope unless traversing a Program/File got a ${parent.type} node`); } } diff --git a/src/babel/traversal/scope.js b/src/babel/traversal/scope.js index e24dbc5f27..2585102bbc 100644 --- a/src/babel/traversal/scope.js +++ b/src/babel/traversal/scope.js @@ -143,7 +143,7 @@ export default class Scope { _generateUid(name, i) { var id = name; if (i > 1) id += i; - return "_" + id; + return `_${id}`; } /* @@ -415,7 +415,7 @@ export default class Scope { registerVariableDeclaration(declar) { var declars = declar.declarations; for (var i = 0; i < declars.length; i++) { - this.registerBinding(declars[i], declar.kind); + this.registerBinding(declar.kind, declars[i]); } } @@ -538,7 +538,7 @@ export default class Scope { init: opts.init }; } else { - throw new TypeError("cannot add a declaration here in node type " + block.type); + throw new TypeError(`cannot add a declaration here in node type ${block.type}`); } } @@ -626,6 +626,37 @@ export default class Scope { return binding && binding.identifier; } + + getOwnImmutableBindingValue(name) { + return this._immutableBindingInfoToValue(this.getOwnBindingInfo(name)); + } + + getImmutableBindingValue(name) { + return this._immutableBindingInfoToValue(this.getBindingInfo(name)); + } + + _immutableBindingInfoToValue(info) { + if (!info) return; + + // can't guarantee this value is the same + if (info.reassigned) return; + + var node = info.node; + if (t.isVariableDeclarator(node)) { + if (t.isIdentifier(node.id)) { + node = node.init; + } else { + // otherwise it's probably a destructuring like: + // var { foo } = "foo"; + return; + } + } + + if (t.isImmutable(node)) { + return node; + } + } + // has hasOwnBinding(name) { diff --git a/src/babel/types/index.js b/src/babel/types/index.js index 931d1a8aad..91c36ed9e3 100644 --- a/src/babel/types/index.js +++ b/src/babel/types/index.js @@ -21,14 +21,14 @@ export default t; */ function registerType(type, skipAliasCheck) { - var is = t["is" + type] = function (node, opts) { + var is = t[`is${type}`] = function (node, opts) { return t.is(type, node, opts, skipAliasCheck); }; - t["assert" + type] = function (node, opts) { + t[`assert${type}`] = function (node, opts) { opts ||= {}; if (!is(node, opts)) { - throw new Error("Expected type " + JSON.stringify(type) + " with option " + JSON.stringify(opts)); + throw new Error(`Expected type ${JSON.stringify(type)} with option ${JSON.stringify(opts)}`); } }; } @@ -395,7 +395,7 @@ t.toIdentifier = function (name) { }); if (!t.isValidIdentifier(name)) { - name = "_" + name; + name = `_${name}`; } return name || "_"; @@ -506,7 +506,7 @@ t.toStatement = function (node, ignore) { if (ignore) { return false; } else { - throw new Error("cannot turn " + node.type + " to a statement"); + throw new Error(`cannot turn ${node.type} to a statement`); } } @@ -536,7 +536,7 @@ t.toExpression = function (node) { if (t.isExpression(node)) { return node; } else { - throw new Error("cannot turn " + node.type + " to an expression"); + throw new Error(`cannot turn ${node.type} to an expression`); } }; @@ -807,6 +807,35 @@ t.isScope = function (node, parent) { return t.isScopable(node); }; +/** + * Description + * + * @param {Node} node + * @returns {Boolean} + */ + +t.isImmutable = function (node) { + if (t.isLiteral(node)) { + if (node.regex) { + // regexes are mutable + return false; + } else { + // immutable! + return true; + } + } else if (t.isIdentifier(node)) { + if (node.name === "undefined") { + // immutable! + return true; + } else { + // no idea... + return false; + } + } + + return false; +}; + /** * Walk the input `node` and statically evaluate if it's truthy. * @@ -824,11 +853,12 @@ t.isScope = function (node, parent) { * if (!t.evaluateTruthy(node)) falsyLogic(); * * @param {Node} node + * @param {Scope} scope * @returns {Boolean} */ -t.evaluateTruthy = function (node) { - var res = t.evaluate(node); +t.evaluateTruthy = function (node, scope) { + var res = t.evaluate(node, scope); if (res.confident) return !!res.value; }; @@ -846,10 +876,11 @@ t.evaluateTruthy = function (node) { * t.evaluate(parse("foo + foo")) // { confident: false, value: undefined } * * @param {Node} node + * @param {Scope} scope * @returns {Object} */ -t.evaluate = function (node) { +t.evaluate = function (node, scope) { var confident = true; var value = evaluate(node); @@ -882,8 +913,12 @@ t.evaluate = function (node) { } } - if (t.isIdentifier(node, { name: "undefined" })) { - return undefined; + if (t.isIdentifier(node)) { + if (node.name === "undefined") { + return undefined; + } else { + return evaluate(scope.getImmutableBindingValue(node.name)); + } } if (t.isUnaryExpression(node, { prefix: true })) { diff --git a/src/babel/util.js b/src/babel/util.js index d6140bd490..9b7230ff67 100644 --- a/src/babel/util.js +++ b/src/babel/util.js @@ -20,7 +20,7 @@ export { inherits, inspect } from "util"; export var debug = buildDebug("babel"); export function canCompile(filename, altExts) { - var exts = altExts || exports.canCompile.EXTENSIONS; + var exts = altExts || canCompile.EXTENSIONS; var ext = path.extname(filename); return contains(exts, ext); } @@ -50,7 +50,7 @@ export function regexify(val) { export function arrayify(val) { if (!val) return []; if (isBoolean(val)) return [val]; - if (isString(val)) return exports.list(val); + if (isString(val)) return list(val); if (Array.isArray(val)) return val; throw new TypeError("illegal type for arrayify"); } @@ -75,7 +75,7 @@ var templateVisitor = { export function template(name, nodes, keepExpression) { var ast = exports.templates[name]; - if (!ast) throw new ReferenceError("unknown template " + name); + if (!ast) throw new ReferenceError(`unknown template ${name}`); if (nodes === true) { keepExpression = true;