Skip to content

Commit

Permalink
test: add test case for smart-inline with computed property accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Aug 10, 2024
1 parent 7d3a3c2 commit e853d04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ inlineTest('property access path renaming',
const t = s.target;
const p = t.parentElement;
const v = p.value;
const x = v[index];
const t2 = s.target.parentElement;
`,
`
const s_target = s.target;
const s_target_parentElement = s_target.parentElement;
const s_target_parentElement_value = s_target_parentElement.value;
const s_target_parentElement_value_index = s_target_parentElement_value[index];
const t2 = s.target.parentElement;
`,
Expand Down
4 changes: 3 additions & 1 deletion packages/unminify/src/transformations/smart-inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ function handleDestructuring(j: JSCodeshift, body: StatementKind[], scope: Scope
if (declarations.size === 1) {
declarations.forEach((declaration) => {
// If there's only one declaration, we can rename it to the combined name.
// for example, `const a = b.c;` -> `const b_c = b.c;`
// for example
// `const a = b.c;` -> `const b_c = b.c;`
// `const a = b[c];` -> `const b_c = b[c];`
if (
j.VariableDeclaration.check(declaration)
&& declaration.declarations.length === 1
Expand Down

0 comments on commit e853d04

Please sign in to comment.