From 8c7d4b55c99ff34cb9d493d452472e59b5ed1e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 18 Nov 2018 23:02:58 +0100 Subject: [PATCH] Add plugins name (#8769) * Add plugins name * Add missing names found by the plugin * Add eslint plugin --- .eslintrc.json | 7 + eslint-local-rules.js | 2 + .../src/index.js | 1 + .../src/index.js | 2 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 2 + .../src/index.js | 2 + .../babel-plugin-syntax-bigint/src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../babel-plugin-syntax-flow/src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + packages/babel-plugin-syntax-jsx/src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 4 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 3 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 5 +- .../src/index.js | 2 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 1 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + .../src/index.js | 2 + scripts/eslint_rules/no-deprecated-clone.js | 163 +---------------- scripts/eslint_rules/plugin-name.js | 62 +++++++ scripts/eslint_rules/utils/eslint-types.js | 34 ++++ .../utils/get-reference-origin.js | 166 ++++++++++++++++++ 94 files changed, 431 insertions(+), 163 deletions(-) create mode 100644 scripts/eslint_rules/plugin-name.js create mode 100644 scripts/eslint_rules/utils/eslint-types.js create mode 100644 scripts/eslint_rules/utils/get-reference-origin.js diff --git a/.eslintrc.json b/.eslintrc.json index d26b40aa6c..00d48dfc3b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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" + } } ] } diff --git a/eslint-local-rules.js b/eslint-local-rules.js index 73af83e484..8b3b7ea497 100644 --- a/eslint-local-rules.js +++ b/eslint-local-rules.js @@ -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, }; diff --git a/packages/babel-plugin-external-helpers/src/index.js b/packages/babel-plugin-external-helpers/src/index.js index 089986cd24..8ca1526bca 100644 --- a/packages/babel-plugin-external-helpers/src/index.js +++ b/packages/babel-plugin-external-helpers/src/index.js @@ -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 diff --git a/packages/babel-plugin-proposal-async-generator-functions/src/index.js b/packages/babel-plugin-proposal-async-generator-functions/src/index.js index f68cdaa6a2..82bfa1d32a 100644 --- a/packages/babel-plugin-proposal-async-generator-functions/src/index.js +++ b/packages/babel-plugin-proposal-async-generator-functions/src/index.js @@ -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 diff --git a/packages/babel-plugin-proposal-class-properties/src/index.js b/packages/babel-plugin-proposal-class-properties/src/index.js index 70a21da854..247fce7609 100644 --- a/packages/babel-plugin-proposal-class-properties/src/index.js +++ b/packages/babel-plugin-proposal-class-properties/src/index.js @@ -336,6 +336,7 @@ export default declare((api, options) => { : buildClassStaticPrivatePropertySpec; return { + name: "proposal-class-properties", inherits: syntaxClassProperties, visitor: { diff --git a/packages/babel-plugin-proposal-decorators/src/index.js b/packages/babel-plugin-proposal-decorators/src/index.js index 5467f115eb..1bcb52ae82 100644 --- a/packages/babel-plugin-proposal-decorators/src/index.js +++ b/packages/babel-plugin-proposal-decorators/src/index.js @@ -32,6 +32,7 @@ export default declare((api, options) => { } return { + name: "proposal-decorators", inherits: syntaxDecorators, manipulateOptions({ generatorOpts }) { diff --git a/packages/babel-plugin-proposal-do-expressions/src/index.js b/packages/babel-plugin-proposal-do-expressions/src/index.js index b9e8d6180a..73a3226789 100644 --- a/packages/babel-plugin-proposal-do-expressions/src/index.js +++ b/packages/babel-plugin-proposal-do-expressions/src/index.js @@ -5,6 +5,7 @@ export default declare(api => { api.assertVersion(7); return { + name: "proposal-do-expressions", inherits: syntaxDoExpressions, visitor: { diff --git a/packages/babel-plugin-proposal-export-default-from/src/index.js b/packages/babel-plugin-proposal-export-default-from/src/index.js index 204bdaa2e4..d460b88865 100644 --- a/packages/babel-plugin-proposal-export-default-from/src/index.js +++ b/packages/babel-plugin-proposal-export-default-from/src/index.js @@ -6,6 +6,7 @@ export default declare(api => { api.assertVersion(7); return { + name: "proposal-export-default-from", inherits: syntaxExportDefaultFrom, visitor: { diff --git a/packages/babel-plugin-proposal-export-namespace-from/src/index.js b/packages/babel-plugin-proposal-export-namespace-from/src/index.js index 3d9e4f4812..3b8b307c42 100644 --- a/packages/babel-plugin-proposal-export-namespace-from/src/index.js +++ b/packages/babel-plugin-proposal-export-namespace-from/src/index.js @@ -6,6 +6,7 @@ export default declare(api => { api.assertVersion(7); return { + name: "proposal-export-namespace-from", inherits: syntaxExportNamespaceFrom, visitor: { diff --git a/packages/babel-plugin-proposal-function-bind/src/index.js b/packages/babel-plugin-proposal-function-bind/src/index.js index 57a6a759e3..ea62953863 100644 --- a/packages/babel-plugin-proposal-function-bind/src/index.js +++ b/packages/babel-plugin-proposal-function-bind/src/index.js @@ -39,6 +39,7 @@ export default declare(api => { } return { + name: "proposal-function-bind", inherits: syntaxFunctionBind, visitor: { diff --git a/packages/babel-plugin-proposal-function-sent/src/index.js b/packages/babel-plugin-proposal-function-sent/src/index.js index 16237e0ac4..959b86c41a 100644 --- a/packages/babel-plugin-proposal-function-sent/src/index.js +++ b/packages/babel-plugin-proposal-function-sent/src/index.js @@ -35,6 +35,7 @@ export default declare(api => { }; return { + name: "proposal-function-sent", inherits: syntaxFunctionSent, visitor: { diff --git a/packages/babel-plugin-proposal-json-strings/src/index.js b/packages/babel-plugin-proposal-json-strings/src/index.js index dd555f98d0..3d2cdcaa05 100644 --- a/packages/babel-plugin-proposal-json-strings/src/index.js +++ b/packages/babel-plugin-proposal-json-strings/src/index.js @@ -15,6 +15,7 @@ export default declare(api => { } return { + name: "proposal-json-strings", inherits: syntaxJsonStrings, visitor: { diff --git a/packages/babel-plugin-proposal-logical-assignment-operators/src/index.js b/packages/babel-plugin-proposal-logical-assignment-operators/src/index.js index cffeca9a12..813dcd761f 100644 --- a/packages/babel-plugin-proposal-logical-assignment-operators/src/index.js +++ b/packages/babel-plugin-proposal-logical-assignment-operators/src/index.js @@ -6,6 +6,7 @@ export default declare(api => { api.assertVersion(7); return { + name: "proposal-logical-assignment-operators", inherits: syntaxLogicalAssignmentOperators, visitor: { diff --git a/packages/babel-plugin-proposal-nullish-coalescing-operator/src/index.js b/packages/babel-plugin-proposal-nullish-coalescing-operator/src/index.js index 454b4c057a..5b3c2a3a4d 100644 --- a/packages/babel-plugin-proposal-nullish-coalescing-operator/src/index.js +++ b/packages/babel-plugin-proposal-nullish-coalescing-operator/src/index.js @@ -6,6 +6,7 @@ export default declare((api, { loose = false }) => { api.assertVersion(7); return { + name: "proposal-nullish-coalescing-operator", inherits: syntaxNullishCoalescingOperator, visitor: { diff --git a/packages/babel-plugin-proposal-numeric-separator/src/index.js b/packages/babel-plugin-proposal-numeric-separator/src/index.js index 822ade1b8c..99c29d700e 100644 --- a/packages/babel-plugin-proposal-numeric-separator/src/index.js +++ b/packages/babel-plugin-proposal-numeric-separator/src/index.js @@ -19,6 +19,7 @@ export default declare(api => { } return { + name: "proposal-numeric-separator", inherits: syntaxNumericSeparator, visitor: { diff --git a/packages/babel-plugin-proposal-object-rest-spread/src/index.js b/packages/babel-plugin-proposal-object-rest-spread/src/index.js index 0103816a23..067be9fdb8 100644 --- a/packages/babel-plugin-proposal-object-rest-spread/src/index.js +++ b/packages/babel-plugin-proposal-object-rest-spread/src/index.js @@ -178,6 +178,7 @@ export default declare((api, opts) => { } return { + name: "proposal-object-rest-spread", inherits: syntaxObjectRestSpread, visitor: { diff --git a/packages/babel-plugin-proposal-optional-catch-binding/src/index.js b/packages/babel-plugin-proposal-optional-catch-binding/src/index.js index f3f0daa99a..04c615bb1d 100644 --- a/packages/babel-plugin-proposal-optional-catch-binding/src/index.js +++ b/packages/babel-plugin-proposal-optional-catch-binding/src/index.js @@ -5,6 +5,7 @@ export default declare(api => { api.assertVersion(7); return { + name: "proposal-optional-catch-binding", inherits: syntaxOptionalCatchBinding, visitor: { diff --git a/packages/babel-plugin-proposal-optional-chaining/src/index.js b/packages/babel-plugin-proposal-optional-chaining/src/index.js index 0da7c84238..586e334f3c 100644 --- a/packages/babel-plugin-proposal-optional-chaining/src/index.js +++ b/packages/babel-plugin-proposal-optional-chaining/src/index.js @@ -127,6 +127,7 @@ export default declare((api, options) => { } return { + name: "proposal-optional-chaining", inherits: syntaxOptionalChaining, visitor: { diff --git a/packages/babel-plugin-proposal-pipeline-operator/src/index.js b/packages/babel-plugin-proposal-pipeline-operator/src/index.js index c56b5c8425..be90528b4d 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/src/index.js +++ b/packages/babel-plugin-proposal-pipeline-operator/src/index.js @@ -6,6 +6,7 @@ export default declare(api => { api.assertVersion(7); return { + name: "proposal-pipeline-operator", inherits: syntaxPipelineOperator, visitor: { diff --git a/packages/babel-plugin-proposal-throw-expressions/src/index.js b/packages/babel-plugin-proposal-throw-expressions/src/index.js index 17cc945784..5cb1ff73a9 100644 --- a/packages/babel-plugin-proposal-throw-expressions/src/index.js +++ b/packages/babel-plugin-proposal-throw-expressions/src/index.js @@ -6,6 +6,7 @@ export default declare(api => { api.assertVersion(7); return { + name: "proposal-throw-expressions", inherits: syntaxThrowExpressions, visitor: { diff --git a/packages/babel-plugin-proposal-unicode-property-regex/src/index.js b/packages/babel-plugin-proposal-unicode-property-regex/src/index.js index e48298ed89..b024589231 100644 --- a/packages/babel-plugin-proposal-unicode-property-regex/src/index.js +++ b/packages/babel-plugin-proposal-unicode-property-regex/src/index.js @@ -11,6 +11,8 @@ export default declare((api, options) => { } return { + name: "proposal-unicode-property-regex", + visitor: { RegExpLiteral(path) { const node = path.node; diff --git a/packages/babel-plugin-syntax-async-generators/src/index.js b/packages/babel-plugin-syntax-async-generators/src/index.js index 44e1b1dd52..e18612556b 100644 --- a/packages/babel-plugin-syntax-async-generators/src/index.js +++ b/packages/babel-plugin-syntax-async-generators/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-async-generators", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("asyncGenerators"); }, diff --git a/packages/babel-plugin-syntax-bigint/src/index.js b/packages/babel-plugin-syntax-bigint/src/index.js index 085614f0a6..89129a5f06 100644 --- a/packages/babel-plugin-syntax-bigint/src/index.js +++ b/packages/babel-plugin-syntax-bigint/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-bigint", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("bigInt"); }, diff --git a/packages/babel-plugin-syntax-class-properties/src/index.js b/packages/babel-plugin-syntax-class-properties/src/index.js index fc3f176e03..f5d26ed80a 100644 --- a/packages/babel-plugin-syntax-class-properties/src/index.js +++ b/packages/babel-plugin-syntax-class-properties/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-class-properties", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("classProperties", "classPrivateProperties"); }, diff --git a/packages/babel-plugin-syntax-decorators/src/index.js b/packages/babel-plugin-syntax-decorators/src/index.js index 5185a067f9..a825adfd77 100644 --- a/packages/babel-plugin-syntax-decorators/src/index.js +++ b/packages/babel-plugin-syntax-decorators/src/index.js @@ -30,6 +30,8 @@ export default declare((api, options) => { } return { + name: "syntax-decorators", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push( legacy diff --git a/packages/babel-plugin-syntax-do-expressions/src/index.js b/packages/babel-plugin-syntax-do-expressions/src/index.js index 5105beed9c..f42c925550 100644 --- a/packages/babel-plugin-syntax-do-expressions/src/index.js +++ b/packages/babel-plugin-syntax-do-expressions/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-do-expressions", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("doExpressions"); }, diff --git a/packages/babel-plugin-syntax-dynamic-import/src/index.js b/packages/babel-plugin-syntax-dynamic-import/src/index.js index bb6dde61e4..13914e3ada 100644 --- a/packages/babel-plugin-syntax-dynamic-import/src/index.js +++ b/packages/babel-plugin-syntax-dynamic-import/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-dynamic-import", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("dynamicImport"); }, diff --git a/packages/babel-plugin-syntax-export-default-from/src/index.js b/packages/babel-plugin-syntax-export-default-from/src/index.js index fcb0b79449..078a1be36e 100644 --- a/packages/babel-plugin-syntax-export-default-from/src/index.js +++ b/packages/babel-plugin-syntax-export-default-from/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-export-default-from", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("exportDefaultFrom"); }, diff --git a/packages/babel-plugin-syntax-export-namespace-from/src/index.js b/packages/babel-plugin-syntax-export-namespace-from/src/index.js index 21446499a6..3bf85c5183 100644 --- a/packages/babel-plugin-syntax-export-namespace-from/src/index.js +++ b/packages/babel-plugin-syntax-export-namespace-from/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-export-namespace-from", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("exportNamespaceFrom"); }, diff --git a/packages/babel-plugin-syntax-flow/src/index.js b/packages/babel-plugin-syntax-flow/src/index.js index 7f80f4843a..0062dbee50 100644 --- a/packages/babel-plugin-syntax-flow/src/index.js +++ b/packages/babel-plugin-syntax-flow/src/index.js @@ -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. diff --git a/packages/babel-plugin-syntax-function-bind/src/index.js b/packages/babel-plugin-syntax-function-bind/src/index.js index 98c5082f88..f7486f73cf 100644 --- a/packages/babel-plugin-syntax-function-bind/src/index.js +++ b/packages/babel-plugin-syntax-function-bind/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-function-bind", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("functionBind"); }, diff --git a/packages/babel-plugin-syntax-function-sent/src/index.js b/packages/babel-plugin-syntax-function-sent/src/index.js index cb8471dd4a..4dfad81d44 100644 --- a/packages/babel-plugin-syntax-function-sent/src/index.js +++ b/packages/babel-plugin-syntax-function-sent/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-function-sent", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("functionSent"); }, diff --git a/packages/babel-plugin-syntax-import-meta/src/index.js b/packages/babel-plugin-syntax-import-meta/src/index.js index 36e22743b0..efdbcba095 100644 --- a/packages/babel-plugin-syntax-import-meta/src/index.js +++ b/packages/babel-plugin-syntax-import-meta/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-import-meta", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("importMeta"); }, diff --git a/packages/babel-plugin-syntax-json-strings/src/index.js b/packages/babel-plugin-syntax-json-strings/src/index.js index c6200a4b17..0a61997b8a 100644 --- a/packages/babel-plugin-syntax-json-strings/src/index.js +++ b/packages/babel-plugin-syntax-json-strings/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-json-strings", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("jsonStrings"); }, diff --git a/packages/babel-plugin-syntax-jsx/src/index.js b/packages/babel-plugin-syntax-jsx/src/index.js index 33b751f6c7..e9d2ae4938 100644 --- a/packages/babel-plugin-syntax-jsx/src/index.js +++ b/packages/babel-plugin-syntax-jsx/src/index.js @@ -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. diff --git a/packages/babel-plugin-syntax-logical-assignment-operators/src/index.js b/packages/babel-plugin-syntax-logical-assignment-operators/src/index.js index d283645e1c..26499ffcb1 100644 --- a/packages/babel-plugin-syntax-logical-assignment-operators/src/index.js +++ b/packages/babel-plugin-syntax-logical-assignment-operators/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-logical-assignment-operators", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("logicalAssignment"); }, diff --git a/packages/babel-plugin-syntax-nullish-coalescing-operator/src/index.js b/packages/babel-plugin-syntax-nullish-coalescing-operator/src/index.js index 69578ca419..0bd6c5d700 100644 --- a/packages/babel-plugin-syntax-nullish-coalescing-operator/src/index.js +++ b/packages/babel-plugin-syntax-nullish-coalescing-operator/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-nullish-coalescing-operator", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("nullishCoalescingOperator"); }, diff --git a/packages/babel-plugin-syntax-numeric-separator/src/index.js b/packages/babel-plugin-syntax-numeric-separator/src/index.js index 8a9cd625ed..f4849990d9 100644 --- a/packages/babel-plugin-syntax-numeric-separator/src/index.js +++ b/packages/babel-plugin-syntax-numeric-separator/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-numeric-separator", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("numericSeparator"); }, diff --git a/packages/babel-plugin-syntax-object-rest-spread/src/index.js b/packages/babel-plugin-syntax-object-rest-spread/src/index.js index 7cd1b759a4..66f909c5a1 100644 --- a/packages/babel-plugin-syntax-object-rest-spread/src/index.js +++ b/packages/babel-plugin-syntax-object-rest-spread/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-object-rest-spread", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("objectRestSpread"); }, diff --git a/packages/babel-plugin-syntax-optional-catch-binding/src/index.js b/packages/babel-plugin-syntax-optional-catch-binding/src/index.js index 466b78e570..68de2be52c 100644 --- a/packages/babel-plugin-syntax-optional-catch-binding/src/index.js +++ b/packages/babel-plugin-syntax-optional-catch-binding/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-optional-catch-binding", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("optionalCatchBinding"); }, diff --git a/packages/babel-plugin-syntax-optional-chaining/src/index.js b/packages/babel-plugin-syntax-optional-chaining/src/index.js index 5677a39ee9..968f34dd72 100644 --- a/packages/babel-plugin-syntax-optional-chaining/src/index.js +++ b/packages/babel-plugin-syntax-optional-chaining/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-optional-chaining", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("optionalChaining"); }, diff --git a/packages/babel-plugin-syntax-pipeline-operator/src/index.js b/packages/babel-plugin-syntax-pipeline-operator/src/index.js index 9d58042b20..420737ed8d 100644 --- a/packages/babel-plugin-syntax-pipeline-operator/src/index.js +++ b/packages/babel-plugin-syntax-pipeline-operator/src/index.js @@ -15,6 +15,8 @@ export default declare((api, { proposal }) => { } return { + name: "syntax-pipeline-operator", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push(["pipelineOperator", { proposal }]); }, diff --git a/packages/babel-plugin-syntax-throw-expressions/src/index.js b/packages/babel-plugin-syntax-throw-expressions/src/index.js index 62150d3655..d9164eea2b 100644 --- a/packages/babel-plugin-syntax-throw-expressions/src/index.js +++ b/packages/babel-plugin-syntax-throw-expressions/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "syntax-throw-expressions", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("throwExpressions"); }, diff --git a/packages/babel-plugin-syntax-typescript/src/index.js b/packages/babel-plugin-syntax-typescript/src/index.js index 3986ca4aaf..5db350c2d4 100644 --- a/packages/babel-plugin-syntax-typescript/src/index.js +++ b/packages/babel-plugin-syntax-typescript/src/index.js @@ -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 diff --git a/packages/babel-plugin-transform-arrow-functions/src/index.js b/packages/babel-plugin-transform-arrow-functions/src/index.js index bc74d0eedf..3e323707a8 100644 --- a/packages/babel-plugin-transform-arrow-functions/src/index.js +++ b/packages/babel-plugin-transform-arrow-functions/src/index.js @@ -6,6 +6,8 @@ export default declare((api, options) => { const { spec } = options; return { + name: "transform-arrow-functions", + visitor: { ArrowFunctionExpression( path: NodePath, diff --git a/packages/babel-plugin-transform-async-to-generator/src/index.js b/packages/babel-plugin-transform-async-to-generator/src/index.js index d0aaf7d5c0..55669063f1 100644 --- a/packages/babel-plugin-transform-async-to-generator/src/index.js +++ b/packages/babel-plugin-transform-async-to-generator/src/index.js @@ -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; diff --git a/packages/babel-plugin-transform-block-scoped-functions/src/index.js b/packages/babel-plugin-transform-block-scoped-functions/src/index.js index 1f1783dc9e..79b9b27e2b 100644 --- a/packages/babel-plugin-transform-block-scoped-functions/src/index.js +++ b/packages/babel-plugin-transform-block-scoped-functions/src/index.js @@ -26,6 +26,8 @@ export default declare(api => { } return { + name: "transform-block-scoped-functions", + visitor: { BlockStatement(path) { const { node, parent } = path; diff --git a/packages/babel-plugin-transform-block-scoping/src/index.js b/packages/babel-plugin-transform-block-scoping/src/index.js index a72bd1a28e..ef91aa55b9 100644 --- a/packages/babel-plugin-transform-block-scoping/src/index.js +++ b/packages/babel-plugin-transform-block-scoping/src/index.js @@ -20,6 +20,8 @@ export default declare((api, opts) => { } return { + name: "transform-block-scoping", + visitor: { VariableDeclaration(path) { const { node, parent, scope } = path; diff --git a/packages/babel-plugin-transform-classes/src/index.js b/packages/babel-plugin-transform-classes/src/index.js index 176c0a2ae3..8f0ecfc202 100644 --- a/packages/babel-plugin-transform-classes/src/index.js +++ b/packages/babel-plugin-transform-classes/src/index.js @@ -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; diff --git a/packages/babel-plugin-transform-computed-properties/src/index.js b/packages/babel-plugin-transform-computed-properties/src/index.js index e751f50088..8107332542 100644 --- a/packages/babel-plugin-transform-computed-properties/src/index.js +++ b/packages/babel-plugin-transform-computed-properties/src/index.js @@ -115,6 +115,8 @@ export default declare((api, options) => { } return { + name: "transform-computed-properties", + visitor: { ObjectExpression: { exit(path, state) { diff --git a/packages/babel-plugin-transform-destructuring/src/index.js b/packages/babel-plugin-transform-destructuring/src/index.js index 9d58303612..ccc76fb918 100644 --- a/packages/babel-plugin-transform-destructuring/src/index.js +++ b/packages/babel-plugin-transform-destructuring/src/index.js @@ -411,6 +411,8 @@ export default declare((api, options) => { } return { + name: "transform-destructuring", + visitor: { ExportNamedDeclaration(path) { const declaration = path.get("declaration"); diff --git a/packages/babel-plugin-transform-dotall-regex/src/index.js b/packages/babel-plugin-transform-dotall-regex/src/index.js index e1303cd903..af11660ea0 100644 --- a/packages/babel-plugin-transform-dotall-regex/src/index.js +++ b/packages/babel-plugin-transform-dotall-regex/src/index.js @@ -6,6 +6,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-dotall-regex", + visitor: { RegExpLiteral(path) { const node = path.node; diff --git a/packages/babel-plugin-transform-duplicate-keys/src/index.js b/packages/babel-plugin-transform-duplicate-keys/src/index.js index ff69a0b49f..003d5e6699 100644 --- a/packages/babel-plugin-transform-duplicate-keys/src/index.js +++ b/packages/babel-plugin-transform-duplicate-keys/src/index.js @@ -12,6 +12,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-duplicate-keys", + visitor: { ObjectExpression(path) { const { node } = path; diff --git a/packages/babel-plugin-transform-exponentiation-operator/src/index.js b/packages/babel-plugin-transform-exponentiation-operator/src/index.js index 92fa3a95bc..680b8b24e8 100644 --- a/packages/babel-plugin-transform-exponentiation-operator/src/index.js +++ b/packages/babel-plugin-transform-exponentiation-operator/src/index.js @@ -6,6 +6,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-exponentiation-operator", + visitor: build({ operator: "**", diff --git a/packages/babel-plugin-transform-flow-comments/src/index.js b/packages/babel-plugin-transform-flow-comments/src/index.js index 2ea870857e..bf948197f2 100644 --- a/packages/babel-plugin-transform-flow-comments/src/index.js +++ b/packages/babel-plugin-transform-flow-comments/src/index.js @@ -27,6 +27,7 @@ export default declare(api => { } return { + name: "transform-flow-comments", inherits: syntaxFlow, visitor: { diff --git a/packages/babel-plugin-transform-flow-strip-types/src/index.js b/packages/babel-plugin-transform-flow-strip-types/src/index.js index ed34e32462..7399d65c9f 100644 --- a/packages/babel-plugin-transform-flow-strip-types/src/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/src/index.js @@ -10,6 +10,7 @@ export default declare(api => { let skipStrip = false; return { + name: "transform-flow-strip-types", inherits: syntaxFlow, visitor: { diff --git a/packages/babel-plugin-transform-for-of/src/index.js b/packages/babel-plugin-transform-for-of/src/index.js index 057a6846fb..582e47bdb1 100644 --- a/packages/babel-plugin-transform-for-of/src/index.js +++ b/packages/babel-plugin-transform-for-of/src/index.js @@ -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"); diff --git a/packages/babel-plugin-transform-function-name/src/index.js b/packages/babel-plugin-transform-function-name/src/index.js index 733a56096a..4c9c56f083 100644 --- a/packages/babel-plugin-transform-function-name/src/index.js +++ b/packages/babel-plugin-transform-function-name/src/index.js @@ -5,6 +5,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-function-name", + visitor: { FunctionExpression: { exit(path) { diff --git a/packages/babel-plugin-transform-instanceof/src/index.js b/packages/babel-plugin-transform-instanceof/src/index.js index dc9d402880..442bd3f8bd 100644 --- a/packages/babel-plugin-transform-instanceof/src/index.js +++ b/packages/babel-plugin-transform-instanceof/src/index.js @@ -5,6 +5,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-instanceof", + visitor: { BinaryExpression(path) { const { node } = path; diff --git a/packages/babel-plugin-transform-jscript/src/index.js b/packages/babel-plugin-transform-jscript/src/index.js index 868f94c000..06bbad6d36 100644 --- a/packages/babel-plugin-transform-jscript/src/index.js +++ b/packages/babel-plugin-transform-jscript/src/index.js @@ -5,6 +5,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-jscript", + visitor: { FunctionExpression: { exit(path) { diff --git a/packages/babel-plugin-transform-literals/src/index.js b/packages/babel-plugin-transform-literals/src/index.js index 82c90e8604..879a37c49f 100644 --- a/packages/babel-plugin-transform-literals/src/index.js +++ b/packages/babel-plugin-transform-literals/src/index.js @@ -4,6 +4,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-literals", + visitor: { NumericLiteral({ node }) { // number octal like 0b10 or 0o70 diff --git a/packages/babel-plugin-transform-member-expression-literals/src/index.js b/packages/babel-plugin-transform-member-expression-literals/src/index.js index d31b955247..78e4f94733 100644 --- a/packages/babel-plugin-transform-member-expression-literals/src/index.js +++ b/packages/babel-plugin-transform-member-expression-literals/src/index.js @@ -5,6 +5,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-member-expression-literals", + visitor: { MemberExpression: { exit({ node }) { diff --git a/packages/babel-plugin-transform-modules-amd/src/index.js b/packages/babel-plugin-transform-modules-amd/src/index.js index 2bceb843c3..5a9937018d 100644 --- a/packages/babel-plugin-transform-modules-amd/src/index.js +++ b/packages/babel-plugin-transform-modules-amd/src/index.js @@ -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) { diff --git a/packages/babel-plugin-transform-modules-commonjs/src/index.js b/packages/babel-plugin-transform-modules-commonjs/src/index.js index 6bf6ff4829..69d303308a 100644 --- a/packages/babel-plugin-transform-modules-commonjs/src/index.js +++ b/packages/babel-plugin-transform-modules-commonjs/src/index.js @@ -116,6 +116,8 @@ export default declare((api, options) => { }; return { + name: "transform-modules-commonjs", + visitor: { Program: { exit(path, state) { diff --git a/packages/babel-plugin-transform-modules-systemjs/src/index.js b/packages/babel-plugin-transform-modules-systemjs/src/index.js index 242d132163..afc41a2133 100644 --- a/packages/babel-plugin-transform-modules-systemjs/src/index.js +++ b/packages/babel-plugin-transform-modules-systemjs/src/index.js @@ -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) { diff --git a/packages/babel-plugin-transform-modules-umd/src/index.js b/packages/babel-plugin-transform-modules-umd/src/index.js index 0e7979d9c8..cd8000febb 100644 --- a/packages/babel-plugin-transform-modules-umd/src/index.js +++ b/packages/babel-plugin-transform-modules-umd/src/index.js @@ -125,6 +125,8 @@ export default declare((api, options) => { } return { + name: "transform-modules-umd", + visitor: { Program: { exit(path) { diff --git a/packages/babel-plugin-transform-object-assign/src/index.js b/packages/babel-plugin-transform-object-assign/src/index.js index 856405ce2f..a5467dfe1c 100644 --- a/packages/babel-plugin-transform-object-assign/src/index.js +++ b/packages/babel-plugin-transform-object-assign/src/index.js @@ -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")) { diff --git a/packages/babel-plugin-transform-object-set-prototype-of-to-assign/src/index.js b/packages/babel-plugin-transform-object-set-prototype-of-to-assign/src/index.js index 84f4399a97..b0a0a02f01 100644 --- a/packages/babel-plugin-transform-object-set-prototype-of-to-assign/src/index.js +++ b/packages/babel-plugin-transform-object-set-prototype-of-to-assign/src/index.js @@ -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")) { diff --git a/packages/babel-plugin-transform-object-super/src/index.js b/packages/babel-plugin-transform-object-super/src/index.js index d56ae749d9..c810a49d22 100644 --- a/packages/babel-plugin-transform-object-super/src/index.js +++ b/packages/babel-plugin-transform-object-super/src/index.js @@ -16,6 +16,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-object-super", + visitor: { ObjectExpression(path, state) { let objectRef; diff --git a/packages/babel-plugin-transform-parameters/src/index.js b/packages/babel-plugin-transform-parameters/src/index.js index 733ff83083..5ba89ba9ee 100644 --- a/packages/babel-plugin-transform-parameters/src/index.js +++ b/packages/babel-plugin-transform-parameters/src/index.js @@ -7,6 +7,8 @@ export default declare((api, options) => { const { loose } = options; return { + name: "transform-parameters", + visitor: { Function(path) { if ( diff --git a/packages/babel-plugin-transform-property-literals/src/index.js b/packages/babel-plugin-transform-property-literals/src/index.js index 812cf1a3b5..8e35fa027b 100644 --- a/packages/babel-plugin-transform-property-literals/src/index.js +++ b/packages/babel-plugin-transform-property-literals/src/index.js @@ -5,6 +5,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-property-literals", + visitor: { ObjectProperty: { exit({ node }) { diff --git a/packages/babel-plugin-transform-property-mutators/src/index.js b/packages/babel-plugin-transform-property-mutators/src/index.js index 6428f9a862..bb20e860fc 100644 --- a/packages/babel-plugin-transform-property-mutators/src/index.js +++ b/packages/babel-plugin-transform-property-mutators/src/index.js @@ -6,6 +6,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-property-mutators", + visitor: { ObjectExpression(path, file) { const { node } = path; diff --git a/packages/babel-plugin-transform-proto-to-assign/src/index.js b/packages/babel-plugin-transform-proto-to-assign/src/index.js index 1a8fea57e5..e8699699fb 100644 --- a/packages/babel-plugin-transform-proto-to-assign/src/index.js +++ b/packages/babel-plugin-transform-proto-to-assign/src/index.js @@ -24,6 +24,8 @@ export default declare(api => { } return { + name: "transform-proto-to-assign", + visitor: { AssignmentExpression(path, file) { if (!isProtoAssignmentExpression(path.node)) return; diff --git a/packages/babel-plugin-transform-react-constant-elements/src/index.js b/packages/babel-plugin-transform-react-constant-elements/src/index.js index 70c6fb115b..15589bd808 100644 --- a/packages/babel-plugin-transform-react-constant-elements/src/index.js +++ b/packages/babel-plugin-transform-react-constant-elements/src/index.js @@ -78,6 +78,8 @@ export default declare((api, options) => { }; return { + name: "transform-react-constant-elements", + visitor: { JSXElement(path) { if (HOISTED.has(path.node)) return; diff --git a/packages/babel-plugin-transform-react-display-name/src/index.js b/packages/babel-plugin-transform-react-display-name/src/index.js index e0d88d8569..cc8479cbd8 100644 --- a/packages/babel-plugin-transform-react-display-name/src/index.js +++ b/packages/babel-plugin-transform-react-display-name/src/index.js @@ -53,6 +53,8 @@ export default declare(api => { } return { + name: "transform-react-display-name", + visitor: { ExportDefaultDeclaration({ node }, state) { if (isCreateClass(node.declaration)) { diff --git a/packages/babel-plugin-transform-react-inline-elements/src/index.js b/packages/babel-plugin-transform-react-inline-elements/src/index.js index a5c2ef3ff8..ab81b6b51a 100644 --- a/packages/babel-plugin-transform-react-inline-elements/src/index.js +++ b/packages/babel-plugin-transform-react-inline-elements/src/index.js @@ -64,5 +64,8 @@ export default declare(api => { } }, }); - return { visitor }; + return { + name: "transform-react-inline-elements", + visitor, + }; }); diff --git a/packages/babel-plugin-transform-react-jsx-compat/src/index.js b/packages/babel-plugin-transform-react-jsx-compat/src/index.js index 844b255d4c..294607ba79 100644 --- a/packages/babel-plugin-transform-react-jsx-compat/src/index.js +++ b/packages/babel-plugin-transform-react-jsx-compat/src/index.js @@ -6,6 +6,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-react-jsx-compat", + manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("jsx"); }, diff --git a/packages/babel-plugin-transform-react-jsx-self/src/index.js b/packages/babel-plugin-transform-react-jsx-self/src/index.js index 375f223256..208de870d8 100644 --- a/packages/babel-plugin-transform-react-jsx-self/src/index.js +++ b/packages/babel-plugin-transform-react-jsx-self/src/index.js @@ -29,6 +29,7 @@ export default declare(api => { }; return { + name: "transform-react-jsx-self", visitor, }; }); diff --git a/packages/babel-plugin-transform-react-jsx-source/src/index.js b/packages/babel-plugin-transform-react-jsx-source/src/index.js index 70820c61e0..ce7d66b1b7 100644 --- a/packages/babel-plugin-transform-react-jsx-source/src/index.js +++ b/packages/babel-plugin-transform-react-jsx-source/src/index.js @@ -75,6 +75,7 @@ export default declare(api => { }; return { + name: "transform-react-jsx-source", visitor, }; }); diff --git a/packages/babel-plugin-transform-react-jsx/src/index.js b/packages/babel-plugin-transform-react-jsx/src/index.js index 75de317916..778e5f960b 100644 --- a/packages/babel-plugin-transform-react-jsx/src/index.js +++ b/packages/babel-plugin-transform-react-jsx/src/index.js @@ -93,6 +93,7 @@ export default declare((api, options) => { }; return { + name: "transform-react-jsx", inherits: jsx, visitor, }; diff --git a/packages/babel-plugin-transform-reserved-words/src/index.js b/packages/babel-plugin-transform-reserved-words/src/index.js index b691947ac6..014e7b9648 100644 --- a/packages/babel-plugin-transform-reserved-words/src/index.js +++ b/packages/babel-plugin-transform-reserved-words/src/index.js @@ -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)) { diff --git a/packages/babel-plugin-transform-runtime/src/index.js b/packages/babel-plugin-transform-runtime/src/index.js index 4f3a854028..54468b94e3 100644 --- a/packages/babel-plugin-transform-runtime/src/index.js +++ b/packages/babel-plugin-transform-runtime/src/index.js @@ -135,6 +135,8 @@ export default declare((api, options, dirname) => { } return { + name: "transform-runtime", + pre(file) { if (useRuntimeHelpers) { file.set("helperGenerator", name => { diff --git a/packages/babel-plugin-transform-shorthand-properties/src/index.js b/packages/babel-plugin-transform-shorthand-properties/src/index.js index 482607c370..191e67d726 100644 --- a/packages/babel-plugin-transform-shorthand-properties/src/index.js +++ b/packages/babel-plugin-transform-shorthand-properties/src/index.js @@ -5,6 +5,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-shorthand-properties", + visitor: { ObjectMethod(path) { const { node } = path; diff --git a/packages/babel-plugin-transform-spread/src/index.js b/packages/babel-plugin-transform-spread/src/index.js index 50592fafbf..17428ca362 100644 --- a/packages/babel-plugin-transform-spread/src/index.js +++ b/packages/babel-plugin-transform-spread/src/index.js @@ -48,6 +48,8 @@ export default declare((api, options) => { } return { + name: "transform-spread", + visitor: { ArrayExpression(path) { const { node, scope } = path; diff --git a/packages/babel-plugin-transform-sticky-regex/src/index.js b/packages/babel-plugin-transform-sticky-regex/src/index.js index ee7a0aa5db..e5961dfee6 100644 --- a/packages/babel-plugin-transform-sticky-regex/src/index.js +++ b/packages/babel-plugin-transform-sticky-regex/src/index.js @@ -6,6 +6,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-sticky-regex", + visitor: { RegExpLiteral(path) { const { node } = path; diff --git a/packages/babel-plugin-transform-strict-mode/src/index.js b/packages/babel-plugin-transform-strict-mode/src/index.js index 4dd2823b12..9be2ae2f15 100644 --- a/packages/babel-plugin-transform-strict-mode/src/index.js +++ b/packages/babel-plugin-transform-strict-mode/src/index.js @@ -5,6 +5,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-strict-mode", + visitor: { Program(path) { const { node } = path; diff --git a/packages/babel-plugin-transform-template-literals/src/index.js b/packages/babel-plugin-transform-template-literals/src/index.js index b595678374..9126a64b45 100644 --- a/packages/babel-plugin-transform-template-literals/src/index.js +++ b/packages/babel-plugin-transform-template-literals/src/index.js @@ -44,6 +44,8 @@ export default declare((api, options) => { } return { + name: "transform-template-literals", + visitor: { TaggedTemplateExpression(path) { const { node } = path; diff --git a/packages/babel-plugin-transform-typeof-symbol/src/index.js b/packages/babel-plugin-transform-typeof-symbol/src/index.js index 70d1a65ca0..b969f216d7 100644 --- a/packages/babel-plugin-transform-typeof-symbol/src/index.js +++ b/packages/babel-plugin-transform-typeof-symbol/src/index.js @@ -5,6 +5,8 @@ export default declare(api => { api.assertVersion(7); return { + name: "transform-typeof-symbol", + visitor: { Scope({ scope }) { if (!scope.getBinding("Symbol")) { diff --git a/packages/babel-plugin-transform-typescript/src/index.js b/packages/babel-plugin-transform-typescript/src/index.js index 34261f0393..e579d2a8a3 100644 --- a/packages/babel-plugin-transform-typescript/src/index.js +++ b/packages/babel-plugin-transform-typescript/src/index.js @@ -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, diff --git a/packages/babel-plugin-transform-unicode-regex/src/index.js b/packages/babel-plugin-transform-unicode-regex/src/index.js index 6b0e434dda..88593e0559 100644 --- a/packages/babel-plugin-transform-unicode-regex/src/index.js +++ b/packages/babel-plugin-transform-unicode-regex/src/index.js @@ -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; diff --git a/scripts/eslint_rules/no-deprecated-clone.js b/scripts/eslint_rules/no-deprecated-clone.js index 323e5ed225..69c9970260 100644 --- a/scripts/eslint_rules/no-deprecated-clone.js +++ b/scripts/eslint_rules/no-deprecated-clone.js @@ -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"; diff --git a/scripts/eslint_rules/plugin-name.js b/scripts/eslint_rules/plugin-name.js new file mode 100644 index 0000000000..52465824f0 --- /dev/null +++ b/scripts/eslint_rules/plugin-name.js @@ -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." + ); + } + }, + }; + }, +}; diff --git a/scripts/eslint_rules/utils/eslint-types.js b/scripts/eslint_rules/utils/eslint-types.js new file mode 100644 index 0000000000..6a0545d24c --- /dev/null +++ b/scripts/eslint_rules/utils/eslint-types.js @@ -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, + 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, +}; +*/ diff --git a/scripts/eslint_rules/utils/get-reference-origin.js b/scripts/eslint_rules/utils/get-reference-origin.js new file mode 100644 index 0000000000..6608ddf1cd --- /dev/null +++ b/scripts/eslint_rules/utils/get-reference-origin.js @@ -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; +}