Skip to content

Commit

Permalink
declareFields -> allowDeclareFields
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 22, 2019
1 parent 54aa6e2 commit c188fc4
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
12 changes: 8 additions & 4 deletions packages/babel-plugin-transform-typescript/src/index.js
Expand Up @@ -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);

Expand All @@ -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.`,
);
}
Expand All @@ -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();
}

Expand Down
@@ -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."
}
@@ -1,3 +1,3 @@
{
"plugins": [["transform-typescript", { "declareFields": true }]]
"plugins": [["transform-typescript", { "allowDeclareFields": true }]]
}
@@ -1,3 +1,3 @@
{
"plugins": [["transform-typescript", { "declareFields": true }]]
"plugins": [["transform-typescript", { "allowDeclareFields": true }]]
}
@@ -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"
}
@@ -1,6 +1,6 @@
{
"plugins": [
["transform-typescript", { "declareFields": true }],
["transform-typescript", { "allowDeclareFields": true }],
"proposal-class-properties"
]
}
@@ -1,3 +1,3 @@
{
"plugins": [["transform-typescript", { "declareFields": true }]]
"plugins": [["transform-typescript", { "allowDeclareFields": true }]]
}
4 changes: 2 additions & 2 deletions packages/babel-preset-typescript/src/index.js
Expand Up @@ -9,7 +9,7 @@ export default declare(
allExtensions = false,
isTSX = false,
allowNamespaces,
declareFields,
allowDeclareFields,
},
) => {
api.assertVersion(7);
Expand All @@ -29,7 +29,7 @@ export default declare(
jsxPragma,
isTSX,
allowNamespaces,
declareFields,
allowDeclareFields,
});

return {
Expand Down

0 comments on commit c188fc4

Please sign in to comment.