convert @babel/plugin-transform-react-jsx to typescript (#13221)

* babel-plugin-transform-react-jsx flowts rename

* babel-plugin-transform-react-jsx flowts convert

* babel-plugin-transform-react-jsx

* babel-plugin-transform-react-jsx fix

* make generate-tsconfig

* yarn install

* babel-plugin-transform-react-jsx remove unused typecast
This commit is contained in:
Bogdan Savluk 2021-05-13 03:15:31 +02:00 committed by GitHub
parent 7c9f618dfc
commit 379bc775ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 7 deletions

View File

@ -28,6 +28,7 @@
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "workspace:*", "@babel/core": "workspace:*",
"@babel/helper-plugin-test-runner": "workspace:*" "@babel/helper-plugin-test-runner": "workspace:*",
"@babel/traverse": "workspace:*"
} }
} }

View File

@ -149,7 +149,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
let pragmaFragSet = !!options.pragmaFrag; let pragmaFragSet = !!options.pragmaFrag;
if (file.ast.comments) { if (file.ast.comments) {
for (const comment of (file.ast.comments: Array<Object>)) { for (const comment of file.ast.comments) {
const sourceMatches = JSX_SOURCE_ANNOTATION_REGEX.exec( const sourceMatches = JSX_SOURCE_ANNOTATION_REGEX.exec(
comment.value, comment.value,
); );
@ -313,6 +313,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
if (node.name === "this" && t.isReferenced(node, parent)) { if (node.name === "this" && t.isReferenced(node, parent)) {
return t.thisExpression(); return t.thisExpression();
} else if (t.isValidIdentifier(node.name, false)) { } else if (t.isValidIdentifier(node.name, false)) {
// @ts-expect-error todo(flow->ts)
node.type = "Identifier"; node.type = "Identifier";
} else { } else {
return t.stringLiteral(node.name); return t.stringLiteral(node.name);
@ -416,7 +417,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
const openingPath = path.get("openingElement"); const openingPath = path.get("openingElement");
const args = [getTag(openingPath)]; const args = [getTag(openingPath)];
let attribs = []; const attribsArray = [];
const extracted = Object.create(null); const extracted = Object.create(null);
// for React.jsx, key, __source (dev), and __self (dev) is passed in as // for React.jsx, key, __source (dev), and __self (dev) is passed in as
@ -443,17 +444,23 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
break; break;
} }
default: default:
attribs.push(attr); attribsArray.push(attr);
} }
} else { } else {
attribs.push(attr); attribsArray.push(attr);
} }
} }
const children = t.react.buildChildren(path.node); const children = t.react.buildChildren(path.node);
if (attribs.length || children.length) { let attribs: t.ObjectExpression;
attribs = buildJSXOpeningElementAttributes(attribs, file, children);
if (attribsArray.length || children.length) {
attribs = buildJSXOpeningElementAttributes(
attribsArray,
file,
children,
);
} else { } else {
// attributes should never be null // attributes should never be null
attribs = t.objectExpression([]); attribs = t.objectExpression([]);
@ -555,6 +562,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
if (t.isIdentifier(tagExpr)) { if (t.isIdentifier(tagExpr)) {
tagName = tagExpr.name; tagName = tagExpr.name;
} else if (t.isLiteral(tagExpr)) { } else if (t.isLiteral(tagExpr)) {
// @ts-expect-error todo(flow->ts) value in missing for NullLiteral
tagName = tagExpr.value; tagName = tagExpr.value;
} }

View File

@ -25,6 +25,7 @@
"./packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/src/**/*.ts", "./packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/src/**/*.ts",
"./packages/babel-plugin-proposal-async-do-expressions/src/**/*.ts", "./packages/babel-plugin-proposal-async-do-expressions/src/**/*.ts",
"./packages/babel-plugin-syntax-async-do-expressions/src/**/*.ts", "./packages/babel-plugin-syntax-async-do-expressions/src/**/*.ts",
"./packages/babel-plugin-transform-react-jsx/src/**/*.ts",
"./packages/babel-template/src/**/*.ts", "./packages/babel-template/src/**/*.ts",
"./packages/babel-traverse/src/**/*.ts", "./packages/babel-traverse/src/**/*.ts",
"./packages/babel-types/src/**/*.ts" "./packages/babel-types/src/**/*.ts"
@ -100,6 +101,9 @@
"@babel/plugin-syntax-async-do-expressions": [ "@babel/plugin-syntax-async-do-expressions": [
"./packages/babel-plugin-syntax-async-do-expressions/src" "./packages/babel-plugin-syntax-async-do-expressions/src"
], ],
"@babel/plugin-transform-react-jsx": [
"./packages/babel-plugin-transform-react-jsx/src"
],
"@babel/template": [ "@babel/template": [
"./packages/babel-template/src" "./packages/babel-template/src"
], ],

View File

@ -643,6 +643,7 @@ __metadata:
resolution: "@babel/helper-module-transforms@condition:BABEL_8_BREAKING?:workspace:^7.14.2#5131c1" resolution: "@babel/helper-module-transforms@condition:BABEL_8_BREAKING?:workspace:^7.14.2#5131c1"
dependencies: dependencies:
"@babel/helper-module-transforms-BABEL_8_BREAKING-false": "npm:@babel/helper-module-transforms@workspace:^7.14.2" "@babel/helper-module-transforms-BABEL_8_BREAKING-false": "npm:@babel/helper-module-transforms@workspace:^7.14.2"
checksum: 99b7a76ae03cc33a6d7a2e970aa72831e096f15bc2c58be10fb297e3fa411d9ba344cd0f93590c1b802a1b4450b7ea29db9aeeb7aeb7b2f9241e751c20a5079c
languageName: node languageName: node
linkType: hard linkType: hard
@ -2750,6 +2751,7 @@ __metadata:
"@babel/helper-plugin-test-runner": "workspace:*" "@babel/helper-plugin-test-runner": "workspace:*"
"@babel/helper-plugin-utils": "workspace:^7.13.0" "@babel/helper-plugin-utils": "workspace:^7.13.0"
"@babel/plugin-syntax-jsx": "workspace:^7.12.13" "@babel/plugin-syntax-jsx": "workspace:^7.12.13"
"@babel/traverse": "workspace:*"
"@babel/types": "workspace:^7.13.12" "@babel/types": "workspace:^7.13.12"
peerDependencies: peerDependencies:
"@babel/core": ^7.0.0-0 "@babel/core": ^7.0.0-0