Skip to content

Commit

Permalink
Merge pull request #5 from tajo/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
tajo committed Jul 6, 2023
2 parents c981457 + 0b5022d commit ac466e1
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 85 deletions.
11 changes: 4 additions & 7 deletions packages/fusion/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swc-plugin-fusion",
"version": "1.0.9",
"description": "SWC plugin for fusion",
"description": "SWC plugin for Fusion",
"main": "plugin_fusion.wasm",
"publishConfig": {
"access": "public",
Expand All @@ -10,13 +10,10 @@
"scripts": {
"prepack": "cp ../../target/wasm32-wasi/release/plugin_fusion.wasm ."
},
"homepage": "https://github/tajo/swc-plugins",
"repository": {
"type": "git",
"url": "+https://github.com/tajo/swc-plugins.git"
},
"homepage": "https://github/tajo/swc-plugin-fusion",
"repository": "git@github.com:tajo/swc-plugin-fusion.git",
"bugs": {
"url": "https://github.com/tajo/swc-plugins/issues"
"url": "https://github.com/tajo/swc-plugin-fusion/issues"
},
"author": "Vojtech Miksu <vojtech@uber.com>",
"keywords": [],
Expand Down
33 changes: 10 additions & 23 deletions packages/fusion/transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,32 @@ mod visitors;
#[derive(Debug, Default, Clone, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Config {
#[serde(default = "true_by_default")]
pub display_name: bool,

#[serde(default = "true_by_default")]
pub ssr: bool,

#[serde(default = "true_by_default")]
pub file_name: bool,

#[serde(default = "default_index_file_name")]
pub meaningless_file_names: Vec<String>,
pub transform_asseturl: bool,

#[serde(default)]
pub namespace: String,
#[serde(default = "true_by_default")]
pub transform_gql: bool,

#[serde(default)]
pub top_level_import_paths: Vec<JsWord>,
#[serde(default = "true_by_default")]
pub transform_i18n: bool,

#[serde(default)]
pub transpile_template_literals: bool,
#[serde(default = "true_by_default")]
pub transform_split: bool,

#[serde(default)]
pub minify: bool,
#[serde(default = "true_by_default")]
pub transform_dirname: bool,

#[serde(default)]
pub pure: bool,

#[serde(default = "true_by_default")]
pub css_prop: bool,
pub top_level_import_paths: Vec<JsWord>,
}

fn true_by_default() -> bool {
true
}

fn default_index_file_name() -> Vec<String> {
vec!["index".to_string()]
}

impl Config {}

pub fn i18n_macro(file_name: FileName) -> impl Fold + VisitMut {
Expand Down
16 changes: 5 additions & 11 deletions packages/fusion/transform/src/visitors/asseturl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ use tracing::{

use crate::{asseturl_utils::State, shared::converters::JsVarConverter};

pub fn asseturl(
// file_name: FileName,
// src_file_hash: u128,
// config: Rc<Config>,
state: Rc<RefCell<State>>,
) -> impl Fold + VisitMut {
as_folder(DisplayNameAndId {
pub fn asseturl(state: Rc<RefCell<State>>) -> impl Fold + VisitMut {
as_folder(AsseturlVisitor {
state,
to_prepend: BTreeSet::new(),
converter: JsVarConverter::new("asseturl"),
Expand All @@ -46,18 +41,17 @@ pub fn asseturl(

#[derive(Debug, PartialEq, Hash, Eq, Ord, PartialOrd)]
struct Thing {
// ident: Ident,
file_path: String,
}

#[derive(Debug)]
struct DisplayNameAndId {
struct AsseturlVisitor {
state: Rc<RefCell<State>>,
to_prepend: BTreeSet<Thing>,
converter: JsVarConverter,
}

impl DisplayNameAndId {
impl AsseturlVisitor {
fn replace_asseturl_call(&mut self, expr: &mut Expr) {
if let Expr::Call(call_expr) = expr {
if let Callee::Expr(callee) = &call_expr.callee {
Expand Down Expand Up @@ -86,7 +80,7 @@ impl DisplayNameAndId {
}
}

impl VisitMut for DisplayNameAndId {
impl VisitMut for AsseturlVisitor {
noop_visit_mut_type!();

fn visit_mut_module(&mut self, n: &mut Module) {
Expand Down
6 changes: 3 additions & 3 deletions packages/fusion/transform/src/visitors/dirname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use swc_core::{
use tracing::debug;

pub fn dirname(file_name: FileName) -> impl VisitMut + Fold {
as_folder(DisplayNameAndId { file_name })
as_folder(DirnameVisitor { file_name })
}

#[derive(Debug)]
struct DisplayNameAndId {
struct DirnameVisitor {
file_name: FileName,
}

impl VisitMut for DisplayNameAndId {
impl VisitMut for DirnameVisitor {
noop_visit_mut_type!();

fn visit_mut_expr(&mut self, expr: &mut Expr) {
Expand Down
41 changes: 8 additions & 33 deletions packages/fusion/transform/src/visitors/gql.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
use std::collections::BTreeSet;
use std::{
cell::RefCell,
// path::Path,
rc::Rc,
};
use std::{cell::RefCell, collections::BTreeSet, rc::Rc};

use swc_core::{
common::{errors::HANDLER, DUMMY_SP},
ecma::{
ast::*,
// atoms::JsWord,
utils::prepend_stmt,
visit::{
as_folder,
// noop_fold_type,
noop_visit_mut_type,
Fold,
// FoldWith,
VisitMut,
VisitMutWith,
},
visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith},
},
};
use tracing::{
debug,
span,
// trace,
Level,
};
use tracing::{debug, span, Level};

use crate::{gql_utils::State, shared::converters::JsVarConverter};

pub fn gql(
// file_name: FileName,
// src_file_hash: u128,
// config: Rc<Config>,
state: Rc<RefCell<State>>,
) -> impl Fold + VisitMut {
as_folder(DisplayNameAndId {
pub fn gql(state: Rc<RefCell<State>>) -> impl Fold + VisitMut {
as_folder(GqlVisitor {
state,
to_prepend: BTreeSet::new(),
converter: JsVarConverter::new("gql"),
Expand All @@ -46,18 +22,17 @@ pub fn gql(

#[derive(Debug, PartialEq, Hash, Eq, Ord, PartialOrd)]
struct Thing {
// ident: Ident,
file_path: String,
}

#[derive(Debug)]
struct DisplayNameAndId {
struct GqlVisitor {
state: Rc<RefCell<State>>,
to_prepend: BTreeSet<Thing>,
converter: JsVarConverter,
}

impl DisplayNameAndId {
impl GqlVisitor {
fn replace_gql_call(&mut self, expr: &mut Expr) {
if let Expr::Call(call_expr) = expr {
if let Callee::Expr(callee) = &call_expr.callee {
Expand Down Expand Up @@ -85,7 +60,7 @@ impl DisplayNameAndId {
}
}

impl VisitMut for DisplayNameAndId {
impl VisitMut for GqlVisitor {
noop_visit_mut_type!();

fn visit_mut_module(&mut self, n: &mut Module) {
Expand Down
6 changes: 3 additions & 3 deletions packages/fusion/transform/src/visitors/i18n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ use tracing::debug;
use crate::i18n::State;

pub fn i18n_report_ids(file_name: FileName, state: Rc<RefCell<State>>) -> impl Fold + VisitMut {
as_folder(DisplayNameAndId { file_name, state })
as_folder(I18nVisitor { file_name, state })
}

#[derive(Debug)]
struct DisplayNameAndId {
struct I18nVisitor {
file_name: FileName,
state: Rc<RefCell<State>>,
}

impl VisitMut for DisplayNameAndId {
impl VisitMut for I18nVisitor {
noop_visit_mut_type!();

fn visit_mut_module(&mut self, n: &mut Module) {
Expand Down
6 changes: 3 additions & 3 deletions packages/fusion/transform/src/visitors/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use swc_core::{
};

pub fn split(file_name: FileName) -> impl VisitMut + Fold {
as_folder(DisplayNameAndId { file_name })
as_folder(SplitVisitor { file_name })
}

#[derive(Debug)]
struct DisplayNameAndId {
struct SplitVisitor {
file_name: FileName,
}

impl VisitMut for DisplayNameAndId {
impl VisitMut for SplitVisitor {
noop_visit_mut_type!();

fn visit_mut_call_expr(&mut self, call_expr: &mut CallExpr) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"namespace": "test-namespace"
"ssr": true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"namespace": "test-namespace"
"ssr": true
}

0 comments on commit ac466e1

Please sign in to comment.