Skip to content

Commit

Permalink
feat: add basic non-configurable prose plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Nov 5, 2022
1 parent 5ed8834 commit d88a744
Show file tree
Hide file tree
Showing 3 changed files with 486 additions and 7 deletions.
22 changes: 22 additions & 0 deletions crates/swc-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ pub fn to_lit(items: &[(&str, &str)]) -> ObjectLit {
}
}

pub fn named_literal(name: &str, items: &[(&str, &str)]) -> ObjectLit {
ObjectLit {
span: DUMMY_SP,
props: vec![PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
key: if is_ident(name) {
PropName::Ident(Ident {
span: DUMMY_SP,
optional: false,
sym: (*name).into(),
})
} else {
PropName::Str(Str {
span: DUMMY_SP,
raw: None,
value: (*name).into(),
})
},
value: Box::new(Expr::Object(to_lit(items))),
})))],
}
}

/// Simple heuristic to determine ident vs string key name
fn is_ident(s: &str) -> bool {
s.chars()
Expand Down
Loading

0 comments on commit d88a744

Please sign in to comment.