--no-macros flag, disable macros in node_modules

This commit is contained in:
Jarred Sumner
2023-05-31 15:05:38 -07:00
parent 68c1568075
commit 7057cb1982
13 changed files with 91 additions and 11 deletions

View File

@@ -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_ } };