diff options
author | 2023-06-14 08:35:17 -0700 | |
---|---|---|
committer | 2023-06-14 08:35:51 -0700 | |
commit | 7f535a20a24581696337871e6717c0c8e626c0ca (patch) | |
tree | bee33ce90b56845a08f20d7c9199c4f1f258e53d | |
parent | bac7526c03edee6e7cf947c0ea4a64d0ba411270 (diff) | |
download | bun-7f535a20a24581696337871e6717c0c8e626c0ca.tar.gz bun-7f535a20a24581696337871e6717c0c8e626c0ca.tar.zst bun-7f535a20a24581696337871e6717c0c8e626c0ca.zip |
Workaround issue with module.require =
-rw-r--r-- | src/js_parser.zig | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig index 7c227ce75..971abd32e 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -21181,16 +21181,72 @@ fn NewParser_( logger.Loc.Empty, ); var call_args = allocator.alloc(Expr, 6) catch unreachable; - + const this_module = p.newExpr( + E.Dot{ + .name = "module", + .target = p.newExpr(E.This{}, logger.Loc.Empty), + .name_loc = logger.Loc.Empty, + }, + logger.Loc.Empty, + ); // - // (function(module, exports, require, __dirname, __filename) {}).call(exports, module, exports, require, __dirname, __filename) + // (function(module, exports, require, __dirname, __filename) {}).call(this.exports, this.module, this.exports, this.require, __dirname, __filename) call_args[0..6].* = .{ - p.newExpr(E.Identifier{ .ref = p.exports_ref }, logger.Loc.Empty), - p.newExpr(E.Identifier{ .ref = p.module_ref }, logger.Loc.Empty), - p.newExpr(E.Identifier{ .ref = p.exports_ref }, logger.Loc.Empty), - p.newExpr(E.Identifier{ .ref = p.require_ref }, logger.Loc.Empty), - p.newExpr(E.Identifier{ .ref = p.dirname_ref }, logger.Loc.Empty), - p.newExpr(E.Identifier{ .ref = p.filename_ref }, logger.Loc.Empty), + p.newExpr( + E.Dot{ + .name = "exports", + .target = p.newExpr(E.This{}, logger.Loc.Empty), + .name_loc = logger.Loc.Empty, + }, + logger.Loc.Empty, + ), + this_module, + p.newExpr( + E.Dot{ + .name = "exports", + .target = p.newExpr(E.This{}, logger.Loc.Empty), + .name_loc = logger.Loc.Empty, + }, + logger.Loc.Empty, + ), + p.newExpr( + E.Binary{ + .left = p.newExpr( + E.Dot{ + .name = "require", + .target = this_module, + .name_loc = logger.Loc.Empty, + }, + logger.Loc.Empty, + ), + .op = .bin_assign, + .right = p.newExpr( + E.Dot{ + .name = "require", + .target = p.newExpr(E.This{}, logger.Loc.Empty), + .name_loc = logger.Loc.Empty, + }, + logger.Loc.Empty, + ), + }, + logger.Loc.Empty, + ), + p.newExpr( + E.Dot{ + .name = "__dirname", + .target = p.newExpr(E.This{}, logger.Loc.Empty), + .name_loc = logger.Loc.Empty, + }, + logger.Loc.Empty, + ), + p.newExpr( + E.Dot{ + .name = "__filename", + .target = p.newExpr(E.This{}, logger.Loc.Empty), + .name_loc = logger.Loc.Empty, + }, + logger.Loc.Empty, + ), }; const call = p.newExpr( |