add validation.react transformer
This commit is contained in:
parent
1adc9bfc70
commit
5fb793b75f
@ -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) {
|
||||
|
||||
@ -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"),
|
||||
|
||||
25
lib/6to5/transformation/transformers/validation/react.js
vendored
Normal file
25
lib/6to5/transformation/transformers/validation/react.js
vendored
Normal 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);
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user