aboutsummaryrefslogtreecommitdiff
path: root/src/js_ast.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/js_ast.zig')
-rw-r--r--src/js_ast.zig41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig
index 35fe6b6ec..3cf99211b 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -1354,6 +1354,47 @@ pub const E = struct {
return this.items.slice();
}
+ pub fn inlineSpreadOfArrayLiterals(
+ this: *Array,
+ allocator: std.mem.Allocator,
+ estimated_count: usize,
+ ) !ExprNodeList {
+ var out = try allocator.alloc(
+ Expr,
+ // This over-allocates a little but it's fine
+ estimated_count + @as(usize, this.items.len),
+ );
+ var remain = out;
+ for (this.items.slice()) |item| {
+ switch (item.data) {
+ .e_spread => |val| {
+ if (val.value.data == .e_array) {
+ for (val.value.data.e_array.items.slice()) |inner_item| {
+ if (inner_item.data == .e_missing) {
+ remain[0] = Expr.init(E.Undefined, .{}, inner_item.loc);
+ remain = remain[1..];
+ } else {
+ remain[0] = inner_item;
+ remain = remain[1..];
+ }
+ }
+
+ // skip empty arrays
+ // don't include the inlined spread.
+ continue;
+ }
+ // non-arrays are kept in
+ },
+ else => {},
+ }
+
+ remain[0] = item;
+ remain = remain[1..];
+ }
+
+ return ExprNodeList.init(out[0 .. out.len - remain.len]);
+ }
+
pub fn toJS(this: @This(), ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef {
var stack = std.heap.stackFallback(32 * @sizeOf(ExprNodeList), JSC.getAllocator(ctx));
var allocator = stack.get();