-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: use `trait` instead of `enum` for `SourceMutation` * Remobe all old impl and add new impl
- Loading branch information
Showing
14 changed files
with
150 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use super::SourceMutation; | ||
|
||
#[derive(Debug)] | ||
pub struct Append { | ||
pub content: String, | ||
} | ||
|
||
impl SourceMutation for Append { | ||
fn apply<'me>(&'me self, _ctx: &super::Context, s: &mut string_wizard::MagicString<'me>) { | ||
s.append(&self.content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pub mod append; | ||
pub mod overwrite; | ||
pub mod remove_range; | ||
pub mod rename_symbol; | ||
|
||
use std::fmt::Debug; | ||
|
||
use string_wizard::MagicString; | ||
|
||
#[derive(Debug)] | ||
pub struct Context {} | ||
|
||
pub trait SourceMutation: Debug + Sync + Send { | ||
#[allow(unused_variables)] | ||
fn apply<'me>(&'me self, ctx: &Context, s: &mut MagicString<'me>) {} | ||
} | ||
|
||
pub type BoxedSourceMutation = Box<dyn SourceMutation>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use oxc::span::Span; | ||
use string_wizard::UpdateOptions; | ||
|
||
use super::SourceMutation; | ||
|
||
#[derive(Debug)] | ||
pub struct Overwrite { | ||
pub span: Span, | ||
pub content: String, | ||
} | ||
|
||
impl SourceMutation for Overwrite { | ||
fn apply<'me>(&'me self, _ctx: &super::Context, s: &mut string_wizard::MagicString<'me>) { | ||
s.update_with( | ||
self.span.start, | ||
self.span.end, | ||
&self.content, | ||
UpdateOptions { | ||
overwrite: true, | ||
..Default::default() | ||
}, | ||
); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
crates/rolldown/src/bundler/source_mutations/remove_node.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use oxc::span::Span; | ||
|
||
use super::SourceMutation; | ||
|
||
pub struct RemoveNode { | ||
pub span: Span, | ||
} | ||
|
||
impl SourceMutation for RemoveNode { | ||
fn apply<'me>(&'me self, _ctx: &super::Context, s: &mut string_wizard::MagicString<'me>) { | ||
s.remove(self.span.start, self.span.end); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
crates/rolldown/src/bundler/source_mutations/remove_range.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use oxc::span::Span; | ||
|
||
use super::SourceMutation; | ||
|
||
#[derive(Debug)] | ||
pub struct RemoveRange { | ||
pub span: Span, | ||
} | ||
|
||
impl SourceMutation for RemoveRange { | ||
fn apply<'me>(&'me self, _ctx: &super::Context, s: &mut string_wizard::MagicString<'me>) { | ||
s.remove(self.span.start, self.span.end); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
crates/rolldown/src/bundler/source_mutations/rename_symbol.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use oxc::span::{Atom, Span}; | ||
|
||
use super::SourceMutation; | ||
|
||
#[derive(Debug)] | ||
pub struct RenameSymbol { | ||
pub span: Span, | ||
pub name: Atom, | ||
} | ||
|
||
impl SourceMutation for RenameSymbol { | ||
fn apply<'me>(&'me self, _ctx: &super::Context, s: &mut string_wizard::MagicString<'me>) { | ||
s.update(self.span.start, self.span.end, self.name.as_str()); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
crates/rolldown/src/bundler/source_mutations/rewrite_default_export.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use oxc::span::Span; | ||
|
||
// | ||
pub struct RewriteDefaultExport { | ||
pub span: Span, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters