Skip to content

Commit 0dd1d9b

Browse files
committed
fix Function.prototype when transformed evaluating to undefined
1 parent 15a2ce8 commit 0dd1d9b

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/processScript/transform.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -751,21 +751,11 @@ export function transform(
751751
return { file, seclevel }
752752

753753
function createGetFunctionPrototypeNode() {
754-
for (const globalFunction of globalFunctionsUnder7Characters) {
755-
if (!program.scope.hasOwnBinding(globalFunction)) {
756-
return t.memberExpression(
757-
t.memberExpression(t.identifier(globalFunction), t.identifier(`constructor`)),
758-
t.identifier(`prototype`)
759-
)
760-
}
761-
}
754+
const name = globalFunctionsUnder7Characters.find(name => !program.scope.hasOwnBinding(name))
762755

763756
return t.memberExpression(
764-
t.memberExpression(
765-
t.arrowFunctionExpression([ t.identifier(`_`) ], t.identifier(`_`)),
766-
t.identifier(`constructor`)
767-
),
768-
t.identifier(`prototype`)
757+
name ? t.identifier(name) : t.arrowFunctionExpression([ t.identifier(`_`) ], t.identifier(`_`)),
758+
t.identifier(`__proto__`)
769759
)
770760
}
771761

0 commit comments

Comments
 (0)