Skip to content

Commit

Permalink
Revert "Revert "feat!: implement facebook/react#21104 close Jack-Works#4
Browse files Browse the repository at this point in the history
 (Jack-Works#5)", close Jack-Works#2"

This reverts commit 9458493.
  • Loading branch information
Aleksey Kolesnikov committed May 22, 2021
1 parent 7d87f3d commit 4389cf3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/hooks-support-IIFE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// ? works with IIFE
while (item) {
;((item) => {
useFoo()
})(item)
}
10 changes: 10 additions & 0 deletions typescript/__snapshots__/hooks-support-IIFE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var _a;
_a = $RefreshSig$();
// ? works with IIFE
while (item) {
;
(_a((item) => {
_a();
useFoo();
}, "useFoo{}", true))(item);
}
7 changes: 7 additions & 0 deletions typescript/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export default function (opts: Options = {}): TransformerFactory<SourceFile> {
node = newFunction
// if it is an inner decl, we can update it safely
if (findAncestor(oldNode.parent, ts.isFunctionLike)) node = wrapped
else if (isIIFEFunction(oldNode)) return wrapped
}
}
return updateStatements(node, addSignatureReport)
Expand Down Expand Up @@ -646,6 +647,12 @@ export default function (opts: Options = {}): TransformerFactory<SourceFile> {
if (['createElement', 'jsx', 'jsxs', 'jsxDEV'].includes(f)) return true
return false
}
function isIIFEFunction(f: HandledFunction): boolean {
let node: Node = f
while (ts.isParenthesizedExpression(node.parent)) node = node.parent
if (ts.isCallExpression(node.parent) && node.parent.expression === node) return true
return false
}
}

function startsWithLowerCase(str: string) {
Expand Down

0 comments on commit 4389cf3

Please sign in to comment.