diff --git a/lib/6to5/messages.js b/lib/6to5/messages.js index 21d4ad4eec..36ac74c64b 100644 --- a/lib/6to5/messages.js +++ b/lib/6to5/messages.js @@ -15,7 +15,8 @@ exports.messages = { invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue", readOnly: "$1 is read-only", modulesIllegalExportName: "Illegal export $1", - unknownForHead: "Unknown node type $1 in ForStatement" + unknownForHead: "Unknown node type $1 in ForStatement", + didYouMean: "Did you mean $1?" }; exports.get = function (key) { diff --git a/lib/6to5/transformation/transformers/index.js b/lib/6to5/transformation/transformers/index.js index 698fb05da5..3631235068 100644 --- a/lib/6to5/transformation/transformers/index.js +++ b/lib/6to5/transformation/transformers/index.js @@ -4,6 +4,7 @@ module.exports = { "validation.undeclaredVariableCheck": require("./validation/undeclared-variable-check"), "validation.noForInOfAssignment": require("./validation/no-for-in-of-assignment"), "validation.setters": require("./validation/setters"), + "validation.react": require("./validation/react"), "spec.blockScopedFunctions": require("./spec/block-scoped-functions"), "playground.malletOperator": require("./playground/mallet-operator"), diff --git a/lib/6to5/transformation/transformers/validation/react.js b/lib/6to5/transformation/transformers/validation/react.js new file mode 100644 index 0000000000..d8bbd88b53 --- /dev/null +++ b/lib/6to5/transformation/transformers/validation/react.js @@ -0,0 +1,25 @@ +var messages = require("../../../messages"); +var t = require("../../../types"); + +// check if the input Literal `source` is an alternate casing of "react" +var check = function (source, file) { + if (t.isLiteral(source)) { + var name = source.value; + var lower = name.toLowerCase(); + + if (lower === "react" && name !== lower) { + throw file.errorWithNode(source, messages.get("didYouMean", "react")); + } + } +}; + +exports.CallExpression = function (node, parent, scope, file) { + if (t.isIdentifier(node.callee, { name: "require" }) && node.arguments.length === 1) { + check(node.arguments[0], file); + } +}; + +exports.ImportDeclaration = +exports.ExportDeclaration = function (node, parent, scope, file) { + check(node.source, file); +};