add validation.react transformer

This commit is contained in:
Sebastian McKenzie 2015-02-14 19:07:54 +11:00
parent 1adc9bfc70
commit 5fb793b75f
3 changed files with 28 additions and 1 deletions

View File

@ -15,7 +15,8 @@ exports.messages = {
invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue", invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue",
readOnly: "$1 is read-only", readOnly: "$1 is read-only",
modulesIllegalExportName: "Illegal export $1", 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) { exports.get = function (key) {

View File

@ -4,6 +4,7 @@ module.exports = {
"validation.undeclaredVariableCheck": require("./validation/undeclared-variable-check"), "validation.undeclaredVariableCheck": require("./validation/undeclared-variable-check"),
"validation.noForInOfAssignment": require("./validation/no-for-in-of-assignment"), "validation.noForInOfAssignment": require("./validation/no-for-in-of-assignment"),
"validation.setters": require("./validation/setters"), "validation.setters": require("./validation/setters"),
"validation.react": require("./validation/react"),
"spec.blockScopedFunctions": require("./spec/block-scoped-functions"), "spec.blockScopedFunctions": require("./spec/block-scoped-functions"),
"playground.malletOperator": require("./playground/mallet-operator"), "playground.malletOperator": require("./playground/mallet-operator"),

View File

@ -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);
};