Skip to content

Commit 5a8f414

Browse files
committed
[core][rewriter] hide destructure rewrites behind a flag
1 parent 7f35a85 commit 5a8f414

File tree

6 files changed

+14
-0
lines changed

6 files changed

+14
-0
lines changed

rewriter/js/src/cfg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ pub struct Flags {
3737
pub scramitize: bool,
3838
pub do_sourcemaps: bool,
3939
pub strict_rewrites: bool,
40+
pub destructure_rewrites: bool,
4041
}

rewriter/js/src/visitor.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ where
414414
}
415415

416416
fn visit_binding_pattern(&mut self, it: &BindingPattern<'data>) {
417+
if !self.flags.destructure_rewrites {
418+
return;
419+
}
420+
417421
match &it.kind {
418422
BindingPatternKind::BindingIdentifier(p) => {
419423
// let a = 0;
@@ -498,6 +502,10 @@ where
498502
walk::walk_expression(self, &s.expression);
499503
}
500504
AssignmentTarget::ObjectAssignmentTarget(o) => {
505+
if !self.flags.destructure_rewrites {
506+
return;
507+
}
508+
501509
let mut restids: Vec<Atom<'data>> = Vec::new();
502510
self.recurse_object_assignment_target(o, &mut restids);
503511

rewriter/native/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ pub struct RewriterOptions {
5757
scramitize: bool,
5858
#[clap(long, default_value_t = false)]
5959
strict_rewrites: bool,
60+
#[clap(long, default_value_t = false)]
61+
destructure_rewrites: bool,
6062
}
6163

6264
impl Default for RewriterOptions {

rewriter/native/src/rewriter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl NativeRewriter {
9090
do_sourcemaps: cfg.do_sourcemaps,
9191
scramitize: cfg.scramitize,
9292
strict_rewrites: cfg.strict_rewrites,
93+
destructure_rewrites: cfg.destructure_rewrites,
9394
},
9495
)
9596
.context("failed to rewrite file")

src/controller/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class ScramjetController {
4343
cleanErrors: false,
4444
scramitize: false,
4545
sourcemaps: true,
46+
destructureRewrites: false,
4647
},
4748
siteFlags: {},
4849
codec: {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type ScramjetFlags = {
1313
cleanErrors: boolean;
1414
scramitize: boolean;
1515
sourcemaps: boolean;
16+
destructureRewrites: boolean;
1617
};
1718

1819
export interface ScramjetConfig {

0 commit comments

Comments
 (0)