Skip to content

Commit

Permalink
fix(jsx): should not transform document.createElement to JSX
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Feb 15, 2024
1 parent 3fc39cd commit 86469e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/unminify/src/transformations/__tests__/un-jsx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,14 @@ dom(DomFrag, null);
<></>;
`,
)

inlineTest('should not transform document.createElement calls',
`
var x = document.createElement("div", attrs);
var y = window.document.createElement("div", attrs);
`,
`
var x = document.createElement("div", attrs);
var y = window.document.createElement("div", attrs);
`,
)
3 changes: 3 additions & 0 deletions packages/unminify/src/transformations/un-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ function getPragma(j: JSCodeshift, node: ExpressionKind, pragmas: string[]): str
&& j.Identifier.check(node.object)
&& j.Identifier.check(node.property)
) {
if (node.object.name === 'document' && node.property.name === 'createElement') {
return null
}
return pragmas.includes(node.property.name) ? node.property.name : null
}

Expand Down

0 comments on commit 86469e7

Please sign in to comment.