Add plugins name (#8769)
* Add plugins name * Add missing names found by the plugin * Add eslint plugin
This commit is contained in:
parent
88696601e1
commit
8c7d4b55c9
@ -26,6 +26,13 @@
|
||||
"env": {
|
||||
"jest": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["packages/babel-plugin-*/src/index.js"],
|
||||
"excludedFiles": ["packages/babel-plugin-transform-regenerator/**/*.js"],
|
||||
"rules": {
|
||||
"local-rules/plugin-name": "error"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -2,8 +2,10 @@
|
||||
|
||||
const noDeprecatedClone = require("./scripts/eslint_rules/no-deprecated-clone");
|
||||
const noUndefinedIdentifier = require("./scripts/eslint_rules/no-undefined-identifier");
|
||||
const pluginName = require("./scripts/eslint_rules/plugin-name");
|
||||
|
||||
module.exports = {
|
||||
"no-deprecated-clone": noDeprecatedClone,
|
||||
"no-undefined-identifier": noUndefinedIdentifier,
|
||||
"plugin-name": pluginName,
|
||||
};
|
||||
|
||||
@ -18,6 +18,7 @@ export default declare((api, options) => {
|
||||
const helperWhitelist = whitelist ? new Set(whitelist) : null;
|
||||
|
||||
return {
|
||||
name: "external-helpers",
|
||||
pre(file) {
|
||||
file.set("helperGenerator", name => {
|
||||
// If the helper didn't exist yet at the version given, we bail
|
||||
|
||||
@ -78,7 +78,9 @@ export default declare(api => {
|
||||
};
|
||||
|
||||
return {
|
||||
name: "proposal-async-generator-functions",
|
||||
inherits: syntaxAsyncGenerators,
|
||||
|
||||
visitor: {
|
||||
Program(path, state) {
|
||||
// We need to traverse the ast here (instead of just vising Function
|
||||
|
||||
@ -336,6 +336,7 @@ export default declare((api, options) => {
|
||||
: buildClassStaticPrivatePropertySpec;
|
||||
|
||||
return {
|
||||
name: "proposal-class-properties",
|
||||
inherits: syntaxClassProperties,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -32,6 +32,7 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "proposal-decorators",
|
||||
inherits: syntaxDecorators,
|
||||
|
||||
manipulateOptions({ generatorOpts }) {
|
||||
|
||||
@ -5,6 +5,7 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "proposal-do-expressions",
|
||||
inherits: syntaxDoExpressions,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -6,6 +6,7 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "proposal-export-default-from",
|
||||
inherits: syntaxExportDefaultFrom,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -6,6 +6,7 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "proposal-export-namespace-from",
|
||||
inherits: syntaxExportNamespaceFrom,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -39,6 +39,7 @@ export default declare(api => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "proposal-function-bind",
|
||||
inherits: syntaxFunctionBind,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -35,6 +35,7 @@ export default declare(api => {
|
||||
};
|
||||
|
||||
return {
|
||||
name: "proposal-function-sent",
|
||||
inherits: syntaxFunctionSent,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -15,6 +15,7 @@ export default declare(api => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "proposal-json-strings",
|
||||
inherits: syntaxJsonStrings,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -6,6 +6,7 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "proposal-logical-assignment-operators",
|
||||
inherits: syntaxLogicalAssignmentOperators,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -6,6 +6,7 @@ export default declare((api, { loose = false }) => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "proposal-nullish-coalescing-operator",
|
||||
inherits: syntaxNullishCoalescingOperator,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -19,6 +19,7 @@ export default declare(api => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "proposal-numeric-separator",
|
||||
inherits: syntaxNumericSeparator,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -178,6 +178,7 @@ export default declare((api, opts) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "proposal-object-rest-spread",
|
||||
inherits: syntaxObjectRestSpread,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -5,6 +5,7 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "proposal-optional-catch-binding",
|
||||
inherits: syntaxOptionalCatchBinding,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -127,6 +127,7 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "proposal-optional-chaining",
|
||||
inherits: syntaxOptionalChaining,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -6,6 +6,7 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "proposal-pipeline-operator",
|
||||
inherits: syntaxPipelineOperator,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -6,6 +6,7 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "proposal-throw-expressions",
|
||||
inherits: syntaxThrowExpressions,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -11,6 +11,8 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "proposal-unicode-property-regex",
|
||||
|
||||
visitor: {
|
||||
RegExpLiteral(path) {
|
||||
const node = path.node;
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-async-generators",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("asyncGenerators");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-bigint",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("bigInt");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-class-properties",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("classProperties", "classPrivateProperties");
|
||||
},
|
||||
|
||||
@ -30,6 +30,8 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "syntax-decorators",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push(
|
||||
legacy
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-do-expressions",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("doExpressions");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-dynamic-import",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("dynamicImport");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-export-default-from",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("exportDefaultFrom");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-export-namespace-from",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("exportNamespaceFrom");
|
||||
},
|
||||
|
||||
@ -12,6 +12,8 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "syntax-flow",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
// If the file has already enabled TS, assume that this is not a
|
||||
// valid Flowtype file.
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-function-bind",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("functionBind");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-function-sent",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("functionSent");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-import-meta",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("importMeta");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-json-strings",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("jsonStrings");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-jsx",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
// If the Typescript plugin already ran, it will have decided whether
|
||||
// or not this is a TSX file.
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-logical-assignment-operators",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("logicalAssignment");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-nullish-coalescing-operator",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("nullishCoalescingOperator");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-numeric-separator",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("numericSeparator");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-object-rest-spread",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("objectRestSpread");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-optional-catch-binding",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("optionalCatchBinding");
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-optional-chaining",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("optionalChaining");
|
||||
},
|
||||
|
||||
@ -15,6 +15,8 @@ export default declare((api, { proposal }) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "syntax-pipeline-operator",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push(["pipelineOperator", { proposal }]);
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-throw-expressions",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("throwExpressions");
|
||||
},
|
||||
|
||||
@ -19,6 +19,8 @@ export default declare((api, { isTSX }) => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "syntax-typescript",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
const { plugins } = parserOpts;
|
||||
// If the Flow syntax plugin already ran, remove it since Typescript
|
||||
|
||||
@ -6,6 +6,8 @@ export default declare((api, options) => {
|
||||
|
||||
const { spec } = options;
|
||||
return {
|
||||
name: "transform-arrow-functions",
|
||||
|
||||
visitor: {
|
||||
ArrowFunctionExpression(
|
||||
path: NodePath<BabelNodeArrowFunctionExpression>,
|
||||
|
||||
@ -10,6 +10,8 @@ export default declare((api, options) => {
|
||||
|
||||
if (method && module) {
|
||||
return {
|
||||
name: "transform-async-to-generator",
|
||||
|
||||
visitor: {
|
||||
Function(path, state) {
|
||||
if (!path.node.async || path.node.generator) return;
|
||||
@ -28,6 +30,8 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-async-to-generator",
|
||||
|
||||
visitor: {
|
||||
Function(path, state) {
|
||||
if (!path.node.async || path.node.generator) return;
|
||||
|
||||
@ -26,6 +26,8 @@ export default declare(api => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-block-scoped-functions",
|
||||
|
||||
visitor: {
|
||||
BlockStatement(path) {
|
||||
const { node, parent } = path;
|
||||
|
||||
@ -20,6 +20,8 @@ export default declare((api, opts) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-block-scoping",
|
||||
|
||||
visitor: {
|
||||
VariableDeclaration(path) {
|
||||
const { node, parent, scope } = path;
|
||||
|
||||
@ -25,6 +25,8 @@ export default declare((api, options) => {
|
||||
const VISITED = Symbol();
|
||||
|
||||
return {
|
||||
name: "transform-classes",
|
||||
|
||||
visitor: {
|
||||
ExportDefaultDeclaration(path: NodePath) {
|
||||
if (!path.get("declaration").isClassDeclaration()) return;
|
||||
|
||||
@ -115,6 +115,8 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-computed-properties",
|
||||
|
||||
visitor: {
|
||||
ObjectExpression: {
|
||||
exit(path, state) {
|
||||
|
||||
@ -411,6 +411,8 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-destructuring",
|
||||
|
||||
visitor: {
|
||||
ExportNamedDeclaration(path) {
|
||||
const declaration = path.get("declaration");
|
||||
|
||||
@ -6,6 +6,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-dotall-regex",
|
||||
|
||||
visitor: {
|
||||
RegExpLiteral(path) {
|
||||
const node = path.node;
|
||||
|
||||
@ -12,6 +12,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-duplicate-keys",
|
||||
|
||||
visitor: {
|
||||
ObjectExpression(path) {
|
||||
const { node } = path;
|
||||
|
||||
@ -6,6 +6,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-exponentiation-operator",
|
||||
|
||||
visitor: build({
|
||||
operator: "**",
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ export default declare(api => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-flow-comments",
|
||||
inherits: syntaxFlow,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -10,6 +10,7 @@ export default declare(api => {
|
||||
let skipStrip = false;
|
||||
|
||||
return {
|
||||
name: "transform-flow-strip-types",
|
||||
inherits: syntaxFlow,
|
||||
|
||||
visitor: {
|
||||
|
||||
@ -14,6 +14,8 @@ export default declare((api, options) => {
|
||||
|
||||
if (assumeArray) {
|
||||
return {
|
||||
name: "transform-for-of",
|
||||
|
||||
visitor: {
|
||||
ForOfStatement(path) {
|
||||
const { scope } = path;
|
||||
@ -176,6 +178,7 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-for-of",
|
||||
visitor: {
|
||||
ForOfStatement(path, state) {
|
||||
const right = path.get("right");
|
||||
|
||||
@ -5,6 +5,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-function-name",
|
||||
|
||||
visitor: {
|
||||
FunctionExpression: {
|
||||
exit(path) {
|
||||
|
||||
@ -5,6 +5,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-instanceof",
|
||||
|
||||
visitor: {
|
||||
BinaryExpression(path) {
|
||||
const { node } = path;
|
||||
|
||||
@ -5,6 +5,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-jscript",
|
||||
|
||||
visitor: {
|
||||
FunctionExpression: {
|
||||
exit(path) {
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-literals",
|
||||
|
||||
visitor: {
|
||||
NumericLiteral({ node }) {
|
||||
// number octal like 0b10 or 0o70
|
||||
|
||||
@ -5,6 +5,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-member-expression-literals",
|
||||
|
||||
visitor: {
|
||||
MemberExpression: {
|
||||
exit({ node }) {
|
||||
|
||||
@ -20,6 +20,8 @@ export default declare((api, options) => {
|
||||
|
||||
const { loose, allowTopLevelThis, strict, strictMode, noInterop } = options;
|
||||
return {
|
||||
name: "transform-modules-amd",
|
||||
|
||||
visitor: {
|
||||
Program: {
|
||||
exit(path) {
|
||||
|
||||
@ -116,6 +116,8 @@ export default declare((api, options) => {
|
||||
};
|
||||
|
||||
return {
|
||||
name: "transform-modules-commonjs",
|
||||
|
||||
visitor: {
|
||||
Program: {
|
||||
exit(path, state) {
|
||||
|
||||
@ -166,6 +166,8 @@ export default declare((api, options) => {
|
||||
};
|
||||
|
||||
return {
|
||||
name: "transform-modules-systemjs",
|
||||
|
||||
visitor: {
|
||||
CallExpression(path, state) {
|
||||
if (path.node.callee.type === TYPE_IMPORT) {
|
||||
|
||||
@ -125,6 +125,8 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-modules-umd",
|
||||
|
||||
visitor: {
|
||||
Program: {
|
||||
exit(path) {
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-object-assign",
|
||||
|
||||
visitor: {
|
||||
CallExpression: function(path, file) {
|
||||
if (path.get("callee").matchesPattern("Object.assign")) {
|
||||
|
||||
@ -4,6 +4,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-object-set-prototype-of-to-assign",
|
||||
|
||||
visitor: {
|
||||
CallExpression(path, file) {
|
||||
if (path.get("callee").matchesPattern("Object.setPrototypeOf")) {
|
||||
|
||||
@ -16,6 +16,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-object-super",
|
||||
|
||||
visitor: {
|
||||
ObjectExpression(path, state) {
|
||||
let objectRef;
|
||||
|
||||
@ -7,6 +7,8 @@ export default declare((api, options) => {
|
||||
|
||||
const { loose } = options;
|
||||
return {
|
||||
name: "transform-parameters",
|
||||
|
||||
visitor: {
|
||||
Function(path) {
|
||||
if (
|
||||
|
||||
@ -5,6 +5,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-property-literals",
|
||||
|
||||
visitor: {
|
||||
ObjectProperty: {
|
||||
exit({ node }) {
|
||||
|
||||
@ -6,6 +6,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-property-mutators",
|
||||
|
||||
visitor: {
|
||||
ObjectExpression(path, file) {
|
||||
const { node } = path;
|
||||
|
||||
@ -24,6 +24,8 @@ export default declare(api => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-proto-to-assign",
|
||||
|
||||
visitor: {
|
||||
AssignmentExpression(path, file) {
|
||||
if (!isProtoAssignmentExpression(path.node)) return;
|
||||
|
||||
@ -78,6 +78,8 @@ export default declare((api, options) => {
|
||||
};
|
||||
|
||||
return {
|
||||
name: "transform-react-constant-elements",
|
||||
|
||||
visitor: {
|
||||
JSXElement(path) {
|
||||
if (HOISTED.has(path.node)) return;
|
||||
|
||||
@ -53,6 +53,8 @@ export default declare(api => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-react-display-name",
|
||||
|
||||
visitor: {
|
||||
ExportDefaultDeclaration({ node }, state) {
|
||||
if (isCreateClass(node.declaration)) {
|
||||
|
||||
@ -64,5 +64,8 @@ export default declare(api => {
|
||||
}
|
||||
},
|
||||
});
|
||||
return { visitor };
|
||||
return {
|
||||
name: "transform-react-inline-elements",
|
||||
visitor,
|
||||
};
|
||||
});
|
||||
|
||||
@ -6,6 +6,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-react-jsx-compat",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("jsx");
|
||||
},
|
||||
|
||||
@ -29,6 +29,7 @@ export default declare(api => {
|
||||
};
|
||||
|
||||
return {
|
||||
name: "transform-react-jsx-self",
|
||||
visitor,
|
||||
};
|
||||
});
|
||||
|
||||
@ -75,6 +75,7 @@ export default declare(api => {
|
||||
};
|
||||
|
||||
return {
|
||||
name: "transform-react-jsx-source",
|
||||
visitor,
|
||||
};
|
||||
});
|
||||
|
||||
@ -93,6 +93,7 @@ export default declare((api, options) => {
|
||||
};
|
||||
|
||||
return {
|
||||
name: "transform-react-jsx",
|
||||
inherits: jsx,
|
||||
visitor,
|
||||
};
|
||||
|
||||
@ -5,6 +5,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-reserved-words",
|
||||
|
||||
visitor: {
|
||||
"BindingIdentifier|ReferencedIdentifier"(path) {
|
||||
if (!t.isValidES3Identifier(path.node.name)) {
|
||||
|
||||
@ -135,6 +135,8 @@ export default declare((api, options, dirname) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-runtime",
|
||||
|
||||
pre(file) {
|
||||
if (useRuntimeHelpers) {
|
||||
file.set("helperGenerator", name => {
|
||||
|
||||
@ -5,6 +5,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-shorthand-properties",
|
||||
|
||||
visitor: {
|
||||
ObjectMethod(path) {
|
||||
const { node } = path;
|
||||
|
||||
@ -48,6 +48,8 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-spread",
|
||||
|
||||
visitor: {
|
||||
ArrayExpression(path) {
|
||||
const { node, scope } = path;
|
||||
|
||||
@ -6,6 +6,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-sticky-regex",
|
||||
|
||||
visitor: {
|
||||
RegExpLiteral(path) {
|
||||
const { node } = path;
|
||||
|
||||
@ -5,6 +5,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-strict-mode",
|
||||
|
||||
visitor: {
|
||||
Program(path) {
|
||||
const { node } = path;
|
||||
|
||||
@ -44,6 +44,8 @@ export default declare((api, options) => {
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-template-literals",
|
||||
|
||||
visitor: {
|
||||
TaggedTemplateExpression(path) {
|
||||
const { node } = path;
|
||||
|
||||
@ -5,6 +5,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-typeof-symbol",
|
||||
|
||||
visitor: {
|
||||
Scope({ scope }) {
|
||||
if (!scope.getBinding("Symbol")) {
|
||||
|
||||
@ -26,7 +26,9 @@ export default declare((api, { jsxPragma = "React" }) => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-typescript",
|
||||
inherits: syntaxTypeScript,
|
||||
|
||||
visitor: {
|
||||
//"Pattern" alias doesn't include Identifier or RestElement.
|
||||
Pattern: visitPattern,
|
||||
|
||||
@ -6,6 +6,8 @@ export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
return {
|
||||
name: "transform-unicode-regex",
|
||||
|
||||
visitor: {
|
||||
RegExpLiteral({ node }) {
|
||||
if (!regex.is(node, "u")) return;
|
||||
|
||||
@ -2,168 +2,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
function getVariableDefinition(name /*: string */, scope /*: Scope */) {
|
||||
let currentScope = scope;
|
||||
do {
|
||||
const variable = currentScope.set.get(name);
|
||||
if (variable && variable.defs[0]) {
|
||||
return { scope: currentScope, definition: variable.defs[0] };
|
||||
}
|
||||
} while ((currentScope = currentScope.upper));
|
||||
}
|
||||
|
||||
/*::
|
||||
type ReferenceOriginImport = { kind: "import", source: string, name: string };
|
||||
type ReferenceOriginParam = {
|
||||
kind: "export param",
|
||||
exportName: string,
|
||||
index: number,
|
||||
};
|
||||
|
||||
type ReferenceOrigin =
|
||||
| ReferenceOriginImport
|
||||
| ReferenceOriginParam
|
||||
| { kind: "import *", source: string }
|
||||
| {
|
||||
kind: "property",
|
||||
base: ReferenceOriginImport | ReferenceOriginParam,
|
||||
path: string,
|
||||
};
|
||||
*/
|
||||
|
||||
// Given a node and a context, returns a description of where its value comes
|
||||
// from.
|
||||
// It resolves imports, parameters of exported functions and property accesses.
|
||||
// See the ReferenceOrigin type for more informations.
|
||||
function getReferenceOrigin(
|
||||
node /*: Node */,
|
||||
scope /*: Scope */
|
||||
) /*: ?ReferenceOrigin */ {
|
||||
if (node.type === "Identifier") {
|
||||
const variable = getVariableDefinition(node.name, scope);
|
||||
if (!variable) return null;
|
||||
|
||||
const definition = variable.definition;
|
||||
const defNode = definition.node;
|
||||
|
||||
if (definition.type === "ImportBinding") {
|
||||
if (defNode.type === "ImportSpecifier") {
|
||||
return {
|
||||
kind: "import",
|
||||
source: definition.parent.source.value,
|
||||
name: defNode.imported.name,
|
||||
};
|
||||
}
|
||||
if (defNode.type === "ImportNamespaceSpecifier") {
|
||||
return {
|
||||
kind: "import *",
|
||||
source: definition.parent.source.value,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (definition.type === "Variable" && defNode.init) {
|
||||
const origin = getReferenceOrigin(defNode.init, variable.scope);
|
||||
return origin && patternToProperty(definition.name, origin);
|
||||
}
|
||||
|
||||
if (definition.type === "Parameter") {
|
||||
const parent = defNode.parent;
|
||||
let exportName /*: string */;
|
||||
if (parent.type === "ExportDefaultDeclaration") {
|
||||
exportName = "default";
|
||||
} else if (parent.type === "ExportNamedDeclaration") {
|
||||
exportName = defNode.id.name;
|
||||
} else if (
|
||||
parent.type === "AssignmentExpression" &&
|
||||
parent.left.type === "MemberExpression" &&
|
||||
parent.left.object.type === "Identifier" &&
|
||||
parent.left.object.name === "module" &&
|
||||
parent.left.property.type === "Identifier" &&
|
||||
parent.left.property.name === "exports"
|
||||
) {
|
||||
exportName = "module.exports";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return patternToProperty(definition.name, {
|
||||
kind: "export param",
|
||||
exportName,
|
||||
index: definition.index,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (node.type === "MemberExpression" && !node.computed) {
|
||||
const origin = getReferenceOrigin(node.object, scope);
|
||||
return origin && addProperty(origin, node.property.name);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function patternToProperty(
|
||||
id /*: Node */,
|
||||
base /*: ReferenceOrigin */
|
||||
) /*: ?ReferenceOrigin */ {
|
||||
const path = getPatternPath(id);
|
||||
return path && path.reduce(addProperty, base);
|
||||
}
|
||||
|
||||
// Adds a property to a given origin. If it was a namespace import it becomes
|
||||
// a named import, so that `import * as x from "foo"; x.bar` and
|
||||
// `import { bar } from "foo"` have the same origin.
|
||||
function addProperty(
|
||||
origin /*: ReferenceOrigin */,
|
||||
name /*: string */
|
||||
) /* ReferenceOrigin */ {
|
||||
if (origin.kind === "import *") {
|
||||
return {
|
||||
kind: "import",
|
||||
source: origin.source,
|
||||
name,
|
||||
};
|
||||
}
|
||||
if (origin.kind === "property") {
|
||||
return {
|
||||
kind: "property",
|
||||
base: origin.base,
|
||||
path: origin.path + "." + name,
|
||||
};
|
||||
}
|
||||
return {
|
||||
kind: "property",
|
||||
base: origin,
|
||||
path: name,
|
||||
};
|
||||
}
|
||||
|
||||
// if "node" is c of { a: { b: c } }, the result is ["a","b"]
|
||||
function getPatternPath(node /*: Node */) /*: ?string[] */ {
|
||||
let current = node;
|
||||
const path = [];
|
||||
|
||||
// Unshift keys to path while going up
|
||||
do {
|
||||
const property = current.parent;
|
||||
if (
|
||||
property.type === "ArrayPattern" ||
|
||||
property.type === "AssignmentPattern" ||
|
||||
property.computed
|
||||
) {
|
||||
// These nodes are not supported.
|
||||
return null;
|
||||
}
|
||||
if (property.type === "Property") {
|
||||
path.unshift(property.key.name);
|
||||
} else {
|
||||
// The destructuring pattern is finished
|
||||
break;
|
||||
}
|
||||
} while ((current = current.parent.parent));
|
||||
|
||||
return path;
|
||||
}
|
||||
const getReferenceOrigin = require("./utils/get-reference-origin");
|
||||
|
||||
function reportError(context /*: Context */, node /*: Node */) {
|
||||
const isMemberExpression = node.type === "MemberExpression";
|
||||
|
||||
62
scripts/eslint_rules/plugin-name.js
Normal file
62
scripts/eslint_rules/plugin-name.js
Normal file
@ -0,0 +1,62 @@
|
||||
"use strict";
|
||||
|
||||
const getReferenceOrigin = require("./utils/get-reference-origin");
|
||||
|
||||
function reportNoPlugin(context /*: Context */, node /*: Node */) {
|
||||
context.report({
|
||||
node,
|
||||
message: "This file does not export a Babel plugin",
|
||||
});
|
||||
}
|
||||
|
||||
function is(type /*: string */) /*: (node: Node) => boolean */ {
|
||||
return node => node.type === type;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
schema: [],
|
||||
},
|
||||
create(context /*: Context */) {
|
||||
return {
|
||||
Program(program /*: Node */) {
|
||||
if (!program.body.some(is("ExportDefaultDeclaration"))) {
|
||||
return reportNoPlugin(context, program);
|
||||
}
|
||||
},
|
||||
ExportDefaultDeclaration(exportDefaultDecl) {
|
||||
let plugin = exportDefaultDecl.declaration;
|
||||
|
||||
if (plugin.type === "CallExpression") {
|
||||
// export default declare(api => { ... });
|
||||
const origin = getReferenceOrigin(plugin.callee, context.getScope());
|
||||
|
||||
if (
|
||||
origin &&
|
||||
origin.kind === "import" &&
|
||||
origin.name === "declare" &&
|
||||
origin.source === "@babel/helper-plugin-utils"
|
||||
) {
|
||||
plugin = plugin.arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.type.includes("Function")) {
|
||||
return reportNoPlugin(context, exportDefaultDecl.parent);
|
||||
}
|
||||
|
||||
const returnNode = plugin.body.body.find(is("ReturnStatement"));
|
||||
if (!returnNode || returnNode.argument.type !== "ObjectExpression") {
|
||||
return reportNoPlugin(context, exportDefaultDecl.parent);
|
||||
}
|
||||
|
||||
if (!returnNode.argument.properties.some(p => p.key.name === "name")) {
|
||||
context.report(
|
||||
returnNode,
|
||||
"This Babel plugin doesn't have a 'name' property."
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
34
scripts/eslint_rules/utils/eslint-types.js
Normal file
34
scripts/eslint_rules/utils/eslint-types.js
Normal file
@ -0,0 +1,34 @@
|
||||
/*:: // ESLint types
|
||||
|
||||
type Node = { type: string, [string]: any };
|
||||
|
||||
type Definition = {
|
||||
type: "ImportedBinding",
|
||||
name: Node,
|
||||
node: Node,
|
||||
parent: Node,
|
||||
};
|
||||
|
||||
type Variable = {
|
||||
defs: Definition[],
|
||||
};
|
||||
|
||||
type Scope = {
|
||||
set: Map<string, Variable>,
|
||||
upper: ?Scope,
|
||||
};
|
||||
|
||||
type Context = {
|
||||
report(options: {
|
||||
node: Node,
|
||||
message: string,
|
||||
fix?: (fixer: Fixer) => ?Fixer,
|
||||
}): void,
|
||||
|
||||
getScope(): Scope,
|
||||
};
|
||||
|
||||
type Fixer = {
|
||||
replaceText(node: Node, replacement: string): Fixer,
|
||||
};
|
||||
*/
|
||||
166
scripts/eslint_rules/utils/get-reference-origin.js
Normal file
166
scripts/eslint_rules/utils/get-reference-origin.js
Normal file
@ -0,0 +1,166 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = getReferenceOrigin;
|
||||
|
||||
/*::
|
||||
type ReferenceOriginImport = { kind: "import", source: string, name: string };
|
||||
type ReferenceOriginParam = {
|
||||
kind: "export param",
|
||||
exportName: string,
|
||||
index: number,
|
||||
};
|
||||
|
||||
type ReferenceOrigin =
|
||||
| ReferenceOriginImport
|
||||
| ReferenceOriginParam
|
||||
| { kind: "import *", source: string }
|
||||
| {
|
||||
kind: "property",
|
||||
base: ReferenceOriginImport | ReferenceOriginParam,
|
||||
path: string,
|
||||
};
|
||||
*/
|
||||
|
||||
// Given a node and a context, returns a description of where its value comes
|
||||
// from.
|
||||
// It resolves imports, parameters of exported functions and property accesses.
|
||||
// See the ReferenceOrigin type for more informations.
|
||||
function getReferenceOrigin(
|
||||
node /*: Node */,
|
||||
scope /*: Scope */
|
||||
) /*: ?ReferenceOrigin */ {
|
||||
if (node.type === "Identifier") {
|
||||
const variable = getVariableDefinition(node.name, scope);
|
||||
if (!variable) return null;
|
||||
|
||||
const definition = variable.definition;
|
||||
const defNode = definition.node;
|
||||
|
||||
if (definition.type === "ImportBinding") {
|
||||
if (defNode.type === "ImportSpecifier") {
|
||||
return {
|
||||
kind: "import",
|
||||
source: definition.parent.source.value,
|
||||
name: defNode.imported.name,
|
||||
};
|
||||
}
|
||||
if (defNode.type === "ImportNamespaceSpecifier") {
|
||||
return {
|
||||
kind: "import *",
|
||||
source: definition.parent.source.value,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (definition.type === "Variable" && defNode.init) {
|
||||
const origin = getReferenceOrigin(defNode.init, variable.scope);
|
||||
return origin && patternToProperty(definition.name, origin);
|
||||
}
|
||||
|
||||
if (definition.type === "Parameter") {
|
||||
const parent = defNode.parent;
|
||||
let exportName /*: string */;
|
||||
if (parent.type === "ExportDefaultDeclaration") {
|
||||
exportName = "default";
|
||||
} else if (parent.type === "ExportNamedDeclaration") {
|
||||
exportName = defNode.id.name;
|
||||
} else if (
|
||||
parent.type === "AssignmentExpression" &&
|
||||
parent.left.type === "MemberExpression" &&
|
||||
parent.left.object.type === "Identifier" &&
|
||||
parent.left.object.name === "module" &&
|
||||
parent.left.property.type === "Identifier" &&
|
||||
parent.left.property.name === "exports"
|
||||
) {
|
||||
exportName = "module.exports";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return patternToProperty(definition.name, {
|
||||
kind: "export param",
|
||||
exportName,
|
||||
index: definition.index,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (node.type === "MemberExpression" && !node.computed) {
|
||||
const origin = getReferenceOrigin(node.object, scope);
|
||||
return origin && addProperty(origin, node.property.name);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getVariableDefinition(name /*: string */, scope /*: Scope */) {
|
||||
let currentScope = scope;
|
||||
do {
|
||||
const variable = currentScope.set.get(name);
|
||||
if (variable && variable.defs[0]) {
|
||||
return { scope: currentScope, definition: variable.defs[0] };
|
||||
}
|
||||
} while ((currentScope = currentScope.upper));
|
||||
}
|
||||
|
||||
function patternToProperty(
|
||||
id /*: Node */,
|
||||
base /*: ReferenceOrigin */
|
||||
) /*: ?ReferenceOrigin */ {
|
||||
const path = getPatternPath(id);
|
||||
return path && path.reduce(addProperty, base);
|
||||
}
|
||||
|
||||
// Adds a property to a given origin. If it was a namespace import it becomes
|
||||
// a named import, so that `import * as x from "foo"; x.bar` and
|
||||
// `import { bar } from "foo"` have the same origin.
|
||||
function addProperty(
|
||||
origin /*: ReferenceOrigin */,
|
||||
name /*: string */
|
||||
) /* ReferenceOrigin */ {
|
||||
if (origin.kind === "import *") {
|
||||
return {
|
||||
kind: "import",
|
||||
source: origin.source,
|
||||
name,
|
||||
};
|
||||
}
|
||||
if (origin.kind === "property") {
|
||||
return {
|
||||
kind: "property",
|
||||
base: origin.base,
|
||||
path: origin.path + "." + name,
|
||||
};
|
||||
}
|
||||
return {
|
||||
kind: "property",
|
||||
base: origin,
|
||||
path: name,
|
||||
};
|
||||
}
|
||||
|
||||
// if "node" is c of { a: { b: c } }, the result is ["a","b"]
|
||||
function getPatternPath(node /*: Node */) /*: ?string[] */ {
|
||||
let current = node;
|
||||
const path = [];
|
||||
|
||||
// Unshift keys to path while going up
|
||||
do {
|
||||
const property = current.parent;
|
||||
if (
|
||||
property.type === "ArrayPattern" ||
|
||||
property.type === "AssignmentPattern" ||
|
||||
property.computed
|
||||
) {
|
||||
// These nodes are not supported.
|
||||
return null;
|
||||
}
|
||||
if (property.type === "Property") {
|
||||
path.unshift(property.key.name);
|
||||
} else {
|
||||
// The destructuring pattern is finished
|
||||
break;
|
||||
}
|
||||
} while ((current = current.parent.parent));
|
||||
|
||||
return path;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user