From c188fc41ef204d9e7cbd79b1ac5b9b925ff3094c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 22 Oct 2019 23:50:27 +0200 Subject: [PATCH] declareFields -> allowDeclareFields --- .../babel-plugin-transform-typescript/src/index.js | 12 ++++++++---- .../fixtures/class/declare-not-enabled/options.json | 2 +- .../class/declare-not-initialized/options.json | 2 +- .../test/fixtures/class/declare/options.json | 2 +- .../options.json | 2 +- .../class/transform-properties-declare/options.json | 2 +- .../options.json | 2 +- packages/babel-preset-typescript/src/index.js | 4 ++-- 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/babel-plugin-transform-typescript/src/index.js b/packages/babel-plugin-transform-typescript/src/index.js index ed22e0562e36..ed7d927fe595 100644 --- a/packages/babel-plugin-transform-typescript/src/index.js +++ b/packages/babel-plugin-transform-typescript/src/index.js @@ -46,7 +46,11 @@ function registerGlobalType(programScope, name) { export default declare( ( api, - { jsxPragma = "React", allowNamespaces = false, declareFields = false }, + { + jsxPragma = "React", + allowNamespaces = false, + allowDeclareFields = false, + }, ) => { api.assertVersion(7); @@ -56,9 +60,9 @@ export default declare( field(path) { const { node } = path; - if (!declareFields && node.declare) { + if (!allowDeclareFields && node.declare) { throw path.buildCodeFrameError( - `The 'declare' modifier is only allowed when the 'declareFields' option of ` + + `The 'declare' modifier is only allowed when the 'allowDeclareFields' option of ` + `@babel/plugin-transform-typescript or @babel/preset-typescript is enabled.`, ); } @@ -71,7 +75,7 @@ export default declare( } path.remove(); - } else if (!declareFields && !node.value && !node.decorators) { + } else if (!allowDeclareFields && !node.value && !node.decorators) { path.remove(); } diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/declare-not-enabled/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/declare-not-enabled/options.json index 5c6fffa91912..c844b0ad736c 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/class/declare-not-enabled/options.json +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/declare-not-enabled/options.json @@ -1,4 +1,4 @@ { "plugins": ["transform-typescript"], - "throws": "The 'declare' modifier is only allowed when the 'declareFields' option of @babel/plugin-transform-typescript or @babel/preset-typescript is enabled." + "throws": "The 'declare' modifier is only allowed when the 'allowDeclareFields' option of @babel/plugin-transform-typescript or @babel/preset-typescript is enabled." } diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/declare-not-initialized/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/declare-not-initialized/options.json index 91ea7a4e40ab..a6d406a50e49 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/class/declare-not-initialized/options.json +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/declare-not-initialized/options.json @@ -1,3 +1,3 @@ { - "plugins": [["transform-typescript", { "declareFields": true }]] + "plugins": [["transform-typescript", { "allowDeclareFields": true }]] } diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/declare/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/declare/options.json index 91ea7a4e40ab..a6d406a50e49 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/class/declare/options.json +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/declare/options.json @@ -1,3 +1,3 @@ { - "plugins": [["transform-typescript", { "declareFields": true }]] + "plugins": [["transform-typescript", { "allowDeclareFields": true }]] } diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/transform-properties-declare-wrong-order/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/transform-properties-declare-wrong-order/options.json index 041e470f5ff4..8a07f1cc2003 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/class/transform-properties-declare-wrong-order/options.json +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/transform-properties-declare-wrong-order/options.json @@ -1,7 +1,7 @@ { "plugins": [ "proposal-class-properties", - ["transform-typescript", { "declareFields": true }] + ["transform-typescript", { "allowDeclareFields": true }] ], "throws": "TypeScript 'declare' fields must first be transformed by @babel/plugin-transform-typescript.\nIf you have already enabled that plugin (or '@babel/preset-typescript'), make sure that it runs before any plugin related to additional class features:\n - @babel/plugin-proposal-class-properties\n - @babel/plugin-proposal-private-methods\n - @babel/plugin-proposal-decorators" } diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/transform-properties-declare/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/transform-properties-declare/options.json index df785dc0572c..18a1de9a1531 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/class/transform-properties-declare/options.json +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/transform-properties-declare/options.json @@ -1,6 +1,6 @@ { "plugins": [ - ["transform-typescript", { "declareFields": true }], + ["transform-typescript", { "allowDeclareFields": true }], "proposal-class-properties" ] } \ No newline at end of file diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/uninitialized-definite-with-declare-enabled/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/uninitialized-definite-with-declare-enabled/options.json index 91ea7a4e40ab..a6d406a50e49 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/class/uninitialized-definite-with-declare-enabled/options.json +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/uninitialized-definite-with-declare-enabled/options.json @@ -1,3 +1,3 @@ { - "plugins": [["transform-typescript", { "declareFields": true }]] + "plugins": [["transform-typescript", { "allowDeclareFields": true }]] } diff --git a/packages/babel-preset-typescript/src/index.js b/packages/babel-preset-typescript/src/index.js index 68ae4577c055..f7dc5eefae00 100644 --- a/packages/babel-preset-typescript/src/index.js +++ b/packages/babel-preset-typescript/src/index.js @@ -9,7 +9,7 @@ export default declare( allExtensions = false, isTSX = false, allowNamespaces, - declareFields, + allowDeclareFields, }, ) => { api.assertVersion(7); @@ -29,7 +29,7 @@ export default declare( jsxPragma, isTSX, allowNamespaces, - declareFields, + allowDeclareFields, }); return {