Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,22 @@ function patchRequireReactDomServerEdge(config: Config) {
const parameterName = p[0]!.getName();
const bodyChildren = arrowFunction.getBody().getChildren();
if (
bodyChildren.length !== 3 ||
bodyChildren[0]!.getFullText() !== "{" ||
bodyChildren[2]!.getFullText() !== "}"
!(
bodyChildren.length === 3 &&
bodyChildren[0]!.getFullText() === "{" &&
bodyChildren[2]!.getFullText() === "}"
)
) {
return;
}
const bodyStatements = bodyChildren[1]?.getChildren();

// the function has only two statements: "use strict" and e.exports=require("react-dom/server.edge")
if (
bodyStatements?.length !== 2 ||
bodyStatements.some((statement) => !statement.isKind(ts.SyntaxKind.ExpressionStatement))
!(
bodyStatements?.length === 2 &&
bodyStatements.every((statement) => statement.isKind(ts.SyntaxKind.ExpressionStatement))
)
) {
return;
}
Expand All @@ -129,13 +133,13 @@ function patchRequireReactDomServerEdge(config: Config) {
);

// the first statement needs to be "use strict"
if (!stringLiteralExpression || stringLiteralExpression.getText() !== '"use strict"') {
if (stringLiteralExpression?.getText() !== '"use strict"') {
return;
}

// the second statement (e.exports=require("react-dom/server.edge")) needs to be a binary expression
const binaryExpression = bodyExpressionStatements[1].getExpressionIfKind(ts.SyntaxKind.BinaryExpression);
if (!binaryExpression || !binaryExpression.getOperatorToken().isKind(ts.SyntaxKind.EqualsToken)) {
if (!binaryExpression?.getOperatorToken().isKind(ts.SyntaxKind.EqualsToken)) {
return;
}

Expand Down
Loading