-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05d3d72
commit ebfadee
Showing
18 changed files
with
3,705 additions
and
7 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
pub trait Processor { | ||
use std::fmt::Debug; | ||
|
||
pub mod params; | ||
pub mod replacement_value; | ||
|
||
pub trait Processor: Debug { | ||
fn id(&self) -> &str; | ||
|
||
fn transform(&self) -> String; | ||
} | ||
|
||
pub struct ProcessorTarget { | ||
pub specifier: String, | ||
pub source: String, | ||
pub processor: Box<dyn Processor>, | ||
} |
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,101 @@ | ||
use crate::Processor; | ||
use oxc::span::{Atom, Span}; | ||
use std::borrow::Cow; | ||
use std::fmt::Debug; | ||
use std::path::PathBuf; | ||
use wyw_traverse::local_identifier::LocalIdentifier; | ||
|
||
#[derive(Debug)] | ||
pub enum ConstValue<'a> { | ||
BigInt(Span, Atom<'a>), | ||
Boolean(Span, bool), | ||
Null(Span), | ||
Number(Span, f64), | ||
String(Span, Atom<'a>), | ||
Undefined(Span), | ||
} | ||
|
||
pub enum ExpressionValue<'a> { | ||
ConstValue(ConstValue<'a>), | ||
Function(Span), | ||
Ident(Span, Atom<'a>), | ||
Source(Span), | ||
TemplateValue { | ||
cooked: Option<Atom<'a>>, | ||
raw: Atom<'a>, | ||
span: Span, | ||
}, | ||
} | ||
|
||
impl<'a> Debug for ExpressionValue<'a> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
ExpressionValue::ConstValue(value) => write!(f, "{:?}", value), | ||
ExpressionValue::Function(span) => write!(f, "Function({:?})", span), | ||
ExpressionValue::Ident(span, ident) => { | ||
write!(f, "Ident({:?}..{:?}, {:?})", span.start, span.end, ident) | ||
} | ||
ExpressionValue::Source(span) => write!(f, "Source({:?}..{:?})", span.start, span.end), | ||
ExpressionValue::TemplateValue { span, raw, .. } => { | ||
write!( | ||
f, | ||
"TemplateValue({:?}..{:?}, {:?})", | ||
span.start, span.end, raw | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub enum Param<'a> { | ||
Callee(Span, LocalIdentifier<'a>), | ||
Call(Span, Vec<ExpressionValue<'a>>), | ||
Member(Span, Atom<'a>), | ||
Template(Span, Vec<ExpressionValue<'a>>), | ||
} | ||
|
||
impl<'a> Debug for Param<'a> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Param::Callee(span, ident) => { | ||
write!(f, "Callee({:?}..{:?}, {:?})", span.start, span.end, ident) | ||
} | ||
Param::Call(span, args) => write!(f, "Call({:?}..{:?}, {:?}))", span.start, span.end, args), | ||
Param::Member(span, prop) => { | ||
write!(f, "Member({:?}..{:?}, {:?}))", span.start, span.end, prop) | ||
} | ||
Param::Template(span, exprs) => write!( | ||
f, | ||
"Template({:?}..{:?}, {:?}))", | ||
span.start, span.end, exprs | ||
), | ||
} | ||
} | ||
} | ||
|
||
pub struct ProcessorParams<'a> { | ||
pub idx: usize, | ||
pub display_name: Cow<'a, str>, | ||
pub params: Vec<Param<'a>>, | ||
pub root: &'a PathBuf, | ||
pub filename: &'a PathBuf, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ProcessorCall<'a> { | ||
pub span: Span, | ||
pub processor: Box<dyn Processor>, | ||
pub params: ProcessorParams<'a>, | ||
} | ||
|
||
impl<'a> Debug for ProcessorParams<'a> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("ProcessorParams") | ||
.field("idx", &self.idx) | ||
.field("display_name", &self.display_name) | ||
.field("params", &self.params) | ||
.finish() | ||
} | ||
} | ||
|
||
pub type ProcessorCalls<'a> = Vec<ProcessorCall<'a>>; |
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,19 @@ | ||
use oxc::span::Span; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum ReplacementValue { | ||
Del, | ||
Span(Span), | ||
Str(String), | ||
Undefined, | ||
} | ||
|
||
impl ReplacementValue { | ||
pub fn from_string(s: &str) -> Self { | ||
if s == "undefined" { | ||
Self::Undefined | ||
} else { | ||
Self::Str(s.to_string()) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "wyw_shaker" | ||
version = "0.1.0" | ||
|
||
edition.workspace = true | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
wyw_processor = { workspace = true } | ||
wyw_traverse = { workspace = true } | ||
|
||
indoc = { workspace = true } | ||
itertools = { workspace = true } | ||
normalize-path = { workspace = true } | ||
oxc = { workspace = true } | ||
oxc_index = { workspace = true } | ||
oxc_resolver = { workspace = true } | ||
oxc_semantic = { workspace = true } | ||
regex = { workspace = true } | ||
serde_json = { workspace = true } | ||
tempfile = { workspace = true } |
Oops, something went wrong.