aboutsummaryrefslogtreecommitdiff
path: root/src/js_ast.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-29 21:37:04 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-29 21:37:04 -0700
commitc3dc64d468997f2841e8f1c9383a8c1c76e56cdc (patch)
tree98decd3c2ae7f22f9e62aa9c54e735509aa48f85 /src/js_ast.zig
parentbd1f9d8370ada6cc4fb145689a3b42f1d7da28a1 (diff)
downloadbun-c3dc64d468997f2841e8f1c9383a8c1c76e56cdc.tar.gz
bun-c3dc64d468997f2841e8f1c9383a8c1c76e56cdc.tar.zst
bun-c3dc64d468997f2841e8f1c9383a8c1c76e56cdc.zip
Fix a load order issue
Diffstat (limited to 'src/js_ast.zig')
-rw-r--r--src/js_ast.zig44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig
index 410539761..69177d4e6 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -765,6 +765,44 @@ pub const G = struct {
close_brace_loc: logger.Loc = logger.Loc.Empty,
properties: []Property = &([_]Property{}),
has_decorators: bool = false,
+
+ pub fn canBeMoved(this: *const Class) bool {
+ if (this.extends != null)
+ return false;
+
+ if (this.has_decorators) {
+ return false;
+ }
+
+ for (this.properties) |property| {
+ if (property.kind == .class_static_block)
+ return false;
+
+ const flags = property.flags;
+ if (flags.contains(.is_computed) or flags.contains(.is_spread)) {
+ return false;
+ }
+
+ if (property.kind == .normal) {
+ if (flags.contains(.is_static)) {
+ for ([2]?Expr{ property.value, property.initializer }) |val_| {
+ if (val_) |val| {
+ switch (val.data) {
+ .e_arrow, .e_function => {},
+ else => {
+ if (!val.canBeConstValue()) {
+ return false;
+ }
+ },
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return true;
+ }
};
// invalid shadowing if left as Comment
@@ -5207,15 +5245,15 @@ pub const S = struct {
default_name: LocRef, // value may be a SFunction or SClass
value: StmtOrExpr,
- pub fn canBeMovedAround(self: ExportDefault) bool {
+ pub fn canBeMoved(self: *const ExportDefault) bool {
return switch (self.value) {
.expr => |e| switch (e.data) {
- .e_class => |class| class.extends == null,
+ .e_class => |class| class.canBeMoved(),
.e_arrow, .e_function => true,
else => e.canBeConstValue(),
},
.stmt => |s| switch (s.data) {
- .s_class => |class| class.class.extends == null,
+ .s_class => |class| class.class.canBeMoved(),
.s_function => true,
else => false,
},