Skip to content

Commit

Permalink
refactor(un-jsx): remove array inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed May 7, 2024
1 parent bd0d74f commit 6726af4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 59 deletions.
42 changes: 0 additions & 42 deletions packages/unminify/src/transformations/__tests__/un-jsx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,48 +299,6 @@ function fn() {
`,
)

inlineTest('jsx with dynamic Component tag - tag name in an array',
`
function fn() {
const components = ["div", "a"]
return React.createElement(
components[0],
null,
"Hello",
);
}
`,
`
function fn() {
return <div>Hello</div>;
}
`,
)

inlineTest('jsx with dynamic Component tag - tag name in an array #invalid',
`
function fn() {
const components = ["div", "a"]
return React.createElement(
components[3],
null,
"Hello",
);
}
`,
`
function fn() {
const components = ["div", "a"]
const Component = components[3];
return React.createElement(
Component,
null,
"Hello",
);
}
`,
)

inlineTest('jsx with child text that should be wrapped',
`
function fn() {
Expand Down
17 changes: 0 additions & 17 deletions packages/unminify/src/transformations/un-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,6 @@ function toJSX(j: JSCodeshift, path: ASTPath<CallExpression>, pragmas: string[],
tag = j.jsxIdentifier(name)

const variableDeclaration = j.variableDeclaration('const', [j.variableDeclarator(j.identifier(name), type)])

// if variable has array
const isVariableDeclarationArray = root.find(j.VariableDeclarator, {
id: {
type: 'Identifier',
name: variableDeclaration.declarations[0].init?.object?.name,
},
})

if (isVariableDeclarationArray.length) {
isVariableDeclarationArray.forEach((path: any) => {
removeDeclarationIfUnused(j, path, path.node.id.name)
// this will pick value against index
tag = { ...tag, name: path.node.init.elements[variableDeclaration.declarations[0].init.property.value].value }
})
}

const isVariableDeclaration = root.find(j.VariableDeclarator, {
id: {
type: 'Identifier',
Expand Down

0 comments on commit 6726af4

Please sign in to comment.