aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-30 22:33:36 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-30 22:33:36 -0700
commitdb24a27e61364d540ababce0cd3ca6354e89dcc9 (patch)
tree7f660aec58fb5301b643355f368d104e94fbd691
parentf8297aee4de2ad331c122ce71d3894fe0d10b976 (diff)
downloadbun-db24a27e61364d540ababce0cd3ca6354e89dcc9.tar.gz
bun-db24a27e61364d540ababce0cd3ca6354e89dcc9.tar.zst
bun-db24a27e61364d540ababce0cd3ca6354e89dcc9.zip
Fix potential infinite loop on calling macros
-rw-r--r--src/js_parser/js_parser.zig34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig
index afba7c1a5..5891cd17a 100644
--- a/src/js_parser/js_parser.zig
+++ b/src/js_parser/js_parser.zig
@@ -11337,7 +11337,7 @@ pub fn NewParser(
const name = p.symbols.items[ref.inner_index].original_name;
const record = &p.import_records.items[import_record_id];
// We must visit it to convert inline_identifiers and record usage
- return p.visitExpr(p.options.macro_context.call(
+ const macro_result = (p.options.macro_context.call(
record.path.text,
p.source.path.sourceDir(),
p.log,
@@ -11349,6 +11349,9 @@ pub fn NewParser(
MacroVisitor,
MacroVisitor{ .p = p, .loc = expr.loc },
) catch return expr);
+ if (macro_result.data != .e_template) {
+ return p.visitExpr(macro_result);
+ }
}
}
}
@@ -12252,20 +12255,23 @@ pub fn NewParser(
const name = p.symbols.items[ref.inner_index].original_name;
const record = &p.import_records.items[import_record_id];
const copied = Expr{ .loc = expr.loc, .data = .{ .e_call = e_ } };
- return p.visitExpr(
+ const macro_result =
p.options.macro_context.call(
- record.path.text,
- p.source.path.sourceDir(),
- p.log,
- p.source,
- record.range,
- copied,
- &.{},
- name,
- MacroVisitor,
- MacroVisitor{ .p = p, .loc = expr.loc },
- ) catch return expr,
- );
+ record.path.text,
+ p.source.path.sourceDir(),
+ p.log,
+ p.source,
+ record.range,
+ copied,
+ &.{},
+ name,
+ MacroVisitor,
+ MacroVisitor{ .p = p, .loc = expr.loc },
+ ) catch return expr;
+
+ if (macro_result.data != .e_call) {
+ return p.visitExpr(macro_result);
+ }
}
}