Skip to content

Commit

Permalink
fix(smart-inline): fix stale scoping information
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Oct 15, 2023
1 parent 6e97cc8 commit ab5d695
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,29 @@ const { useRef } = s;
`,
)

inlineTest('indirect call from required module with existing import',
`
import p from "r2";
const s = require("react");
var countRef = (0, s.useRef)(0);
var secondRef = (0, p.useRef)(0);
`,
`
import { useRef as useRef$0 } from "r2";
const s = require("react");
const {
useRef
} = s;
var countRef = useRef(0);
var secondRef = useRef$0(0);
`,
)

inlineTest('indirect call from multiple required modules',
`
const s = require("react");
Expand Down
3 changes: 3 additions & 0 deletions packages/unminify/src/transformations/un-indirect-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const transformAST: ASTTransformation = (context) => {
* 5. else, add `import { useRef as useRef$1 } from 'react'`
* 6. replace `(0, s.useRef)(0)` with `useRef(0)`
*/

const defaultSpecifierName = object.name
const namedSpecifierName = property.name
const key = `${defaultSpecifierName}.${namedSpecifierName}`
Expand Down Expand Up @@ -210,6 +211,8 @@ export const transformAST: ASTTransformation = (context) => {

const newCallExpression = j.callExpression(j.identifier(valueName), node.arguments)
path.replace(newCallExpression)
rootScope.markAsStale()

return
}

Expand Down

0 comments on commit ab5d695

Please sign in to comment.