From 6726af4dfab378dc466caa53e95a47c13da11308 Mon Sep 17 00:00:00 2001 From: Pionxzh Date: Tue, 7 May 2024 23:06:29 +0800 Subject: [PATCH] refactor(un-jsx): remove array inlining --- .../transformations/__tests__/un-jsx.spec.ts | 42 ------------------- .../unminify/src/transformations/un-jsx.ts | 17 -------- 2 files changed, 59 deletions(-) diff --git a/packages/unminify/src/transformations/__tests__/un-jsx.spec.ts b/packages/unminify/src/transformations/__tests__/un-jsx.spec.ts index 6df29cc3..7283f5ae 100644 --- a/packages/unminify/src/transformations/__tests__/un-jsx.spec.ts +++ b/packages/unminify/src/transformations/__tests__/un-jsx.spec.ts @@ -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
Hello
; -} -`, -) - -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() { diff --git a/packages/unminify/src/transformations/un-jsx.ts b/packages/unminify/src/transformations/un-jsx.ts index e5fb38e6..ecd53df6 100644 --- a/packages/unminify/src/transformations/un-jsx.ts +++ b/packages/unminify/src/transformations/un-jsx.ts @@ -154,23 +154,6 @@ function toJSX(j: JSCodeshift, path: ASTPath, 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',