diff --git a/src/babel/messages.js b/src/babel/messages.js index 73c8848ddf..50d7e0d0f5 100644 --- a/src/babel/messages.js +++ b/src/babel/messages.js @@ -18,7 +18,8 @@ export var messages = { unknownForHead: "Unknown node type $1 in ForStatement", didYouMean: "Did you mean $1?", evalInStrictMode: "eval is not allowed in strict mode", - codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2." + codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2.", + missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues" }; export function get(key) { diff --git a/src/babel/util.js b/src/babel/util.js index 9b7230ff67..033f183bea 100644 --- a/src/babel/util.js +++ b/src/babel/util.js @@ -3,6 +3,7 @@ import "./patch"; import buildDebug from "debug/node"; import cloneDeep from "lodash/lang/cloneDeep"; import isBoolean from "lodash/lang/isBoolean"; +import * as messages from "./messages"; import contains from "lodash/collection/contains"; import traverse from "./traversal"; import isString from "lodash/lang/isString"; @@ -71,7 +72,9 @@ var templateVisitor = { return nodes[node.name]; } } -}; +} + +// export function template(name, nodes, keepExpression) { var ast = exports.templates[name]; @@ -101,7 +104,8 @@ export function template(name, nodes, keepExpression) { export function parseTemplate(loc, code) { var ast = parse({ filename: loc }, code).program; - return traverse.removeProperties(ast); + ast = traverse.removeProperties(ast); + return ast; } function loadTemplates() { @@ -109,9 +113,7 @@ function loadTemplates() { var templatesLoc = path.join(__dirname, "transformation/templates"); if (!fs.existsSync(templatesLoc)) { - throw new Error("no templates directory - this is most likely the " + - "result of a broken `npm publish`. Please report to " + - "https://github.com/babel/babel/issues"); + throw new ReferenceError(messages.get("missingTemplatesDirectory")); } each(fs.readdirSync(templatesLoc), function (name) { @@ -134,3 +136,15 @@ try { exports.templates = loadTemplates(); } + +// + +try { + var runtimePackage = require("babel-runtime/package"); + var version = require("../../package").version; + if (runtimePackage.version !== version) { + throw new ReferenceError(`The verison of babel-runtime of ${runtimePackage.runtime} that you have installed does not match the babel verison of ${version}`); + } +} catch (err) { + if (err.code !== "MODULE_NOT_FOUND") throw err; +}