aboutsummaryrefslogtreecommitdiff
path: root/src/js_parser.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-31 15:05:38 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-31 15:05:49 -0700
commit7057cb1982782dcf95ae3f97331fdb9c6d283f76 (patch)
tree598d85ef6fca9b98f4ef89f594250d96c060fa4f /src/js_parser.zig
parent68c15680753c7cc3ab9a7d9d6e42dfbeafb529df (diff)
downloadbun-7057cb1982782dcf95ae3f97331fdb9c6d283f76.tar.gz
bun-7057cb1982782dcf95ae3f97331fdb9c6d283f76.tar.zst
bun-7057cb1982782dcf95ae3f97331fdb9c6d283f76.zip
`--no-macros` flag, disable macros in node_modules
Diffstat (limited to 'src/js_parser.zig')
-rw-r--r--src/js_parser.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig
index 0fc4f794a..0c4b5dcb3 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -15361,6 +15361,18 @@ fn NewParser_(
if (p.is_control_flow_dead) {
return p.newExpr(E.Undefined{}, e_.tag.?.loc);
}
+
+ // this ordering incase someone wants ot use a macro in a node_module conditionally
+ if (p.options.features.no_macros) {
+ p.log.addError(p.source, tag.loc, "Macros are disabled") catch unreachable;
+ return p.newExpr(E.Undefined{}, e_.tag.?.loc);
+ }
+
+ if (p.source.path.isNodeModule()) {
+ p.log.addError(p.source, expr.loc, "For security reasons, macros cannot be run from node_modules.") catch unreachable;
+ return p.newExpr(E.Undefined{}, expr.loc);
+ }
+
p.macro_call_count += 1;
const record = &p.import_records.items[import_record_id];
// We must visit it to convert inline_identifiers and record usage
@@ -16510,6 +16522,17 @@ fn NewParser_(
if (p.is_control_flow_dead) {
return p.newExpr(E.Undefined{}, e_.target.loc);
}
+
+ if (p.options.features.no_macros) {
+ p.log.addError(p.source, expr.loc, "Macros are disabled") catch unreachable;
+ return p.newExpr(E.Undefined{}, expr.loc);
+ }
+
+ if (p.source.path.isNodeModule()) {
+ p.log.addError(p.source, expr.loc, "For security reasons, macros cannot be run from node_modules.") catch unreachable;
+ return p.newExpr(E.Undefined{}, expr.loc);
+ }
+
const name = p.symbols.items[ref.innerIndex()].original_name;
const record = &p.import_records.items[import_record_id];
const copied = Expr{ .loc = expr.loc, .data = .{ .e_call = e_ } };