Skip to content

Commit

Permalink
convert @babel/plugin-transform-react-jsx to typescript (#13221)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zxbodya committed May 13, 2021
1 parent 7c9f618 commit 379bc77
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/babel-plugin-transform-react-jsx/package.json
Expand Up @@ -28,6 +28,7 @@
},
"devDependencies": {
"@babel/core": "workspace:*",
"@babel/helper-plugin-test-runner": "workspace:*"
"@babel/helper-plugin-test-runner": "workspace:*",
"@babel/traverse": "workspace:*"
}
}
Expand Up @@ -149,7 +149,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
let pragmaFragSet = !!options.pragmaFrag;

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(
comment.value,
);
Expand Down Expand Up @@ -313,6 +313,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
if (node.name === "this" && t.isReferenced(node, parent)) {
return t.thisExpression();
} else if (t.isValidIdentifier(node.name, false)) {
// @ts-expect-error todo(flow->ts)
node.type = "Identifier";
} else {
return t.stringLiteral(node.name);
Expand Down Expand Up @@ -416,7 +417,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
const openingPath = path.get("openingElement");
const args = [getTag(openingPath)];

let attribs = [];
const attribsArray = [];
const extracted = Object.create(null);

// for React.jsx, key, __source (dev), and __self (dev) is passed in as
Expand All @@ -443,17 +444,23 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
break;
}
default:
attribs.push(attr);
attribsArray.push(attr);
}
} else {
attribs.push(attr);
attribsArray.push(attr);
}
}

const children = t.react.buildChildren(path.node);

if (attribs.length || children.length) {
attribs = buildJSXOpeningElementAttributes(attribs, file, children);
let attribs: t.ObjectExpression;

if (attribsArray.length || children.length) {
attribs = buildJSXOpeningElementAttributes(
attribsArray,
file,
children,
);
} else {
// attributes should never be null
attribs = t.objectExpression([]);
Expand Down Expand Up @@ -555,6 +562,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
if (t.isIdentifier(tagExpr)) {
tagName = tagExpr.name;
} else if (t.isLiteral(tagExpr)) {
// @ts-expect-error todo(flow->ts) value in missing for NullLiteral
tagName = tagExpr.value;
}

Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Expand Up @@ -25,6 +25,7 @@
"./packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/src/**/*.ts",
"./packages/babel-plugin-proposal-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-traverse/src/**/*.ts",
"./packages/babel-types/src/**/*.ts"
Expand Down Expand Up @@ -100,6 +101,9 @@
"@babel/plugin-syntax-async-do-expressions": [
"./packages/babel-plugin-syntax-async-do-expressions/src"
],
"@babel/plugin-transform-react-jsx": [
"./packages/babel-plugin-transform-react-jsx/src"
],
"@babel/template": [
"./packages/babel-template/src"
],
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Expand Up @@ -643,6 +643,7 @@ __metadata:
resolution: "@babel/helper-module-transforms@condition:BABEL_8_BREAKING?:workspace:^7.14.2#5131c1"
dependencies:
"@babel/helper-module-transforms-BABEL_8_BREAKING-false": "npm:@babel/helper-module-transforms@workspace:^7.14.2"
checksum: 99b7a76ae03cc33a6d7a2e970aa72831e096f15bc2c58be10fb297e3fa411d9ba344cd0f93590c1b802a1b4450b7ea29db9aeeb7aeb7b2f9241e751c20a5079c
languageName: node
linkType: hard

Expand Down Expand Up @@ -2750,6 +2751,7 @@ __metadata:
"@babel/helper-plugin-test-runner": "workspace:*"
"@babel/helper-plugin-utils": "workspace:^7.13.0"
"@babel/plugin-syntax-jsx": "workspace:^7.12.13"
"@babel/traverse": "workspace:*"
"@babel/types": "workspace:^7.13.12"
peerDependencies:
"@babel/core": ^7.0.0-0
Expand Down

0 comments on commit 379bc77

Please sign in to comment.