Skip to content

Commit

Permalink
chore: update ImportPhase
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Nov 13, 2023
1 parent bbb2e29 commit f35c67f
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions crates/swc_bundler/src/bundler/import/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ where
src: Box::new(src.clone()),
type_only: false,
with: None,
phase: None,
phase: Default::default(),
};

if self.top_level {
Expand Down Expand Up @@ -646,7 +646,7 @@ where
src: Box::new(src),
type_only: false,
with: None,
phase: None,
phase: Default::default(),
};

// if self.top_level {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_bundler/src/bundler/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ where
src: Box::new(src),
type_only: false,
with: None,
phase: None,
phase: Default::default(),
},
true,
false,
Expand Down
9 changes: 6 additions & 3 deletions crates/swc_ecma_ast/src/module_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ pub struct ImportDecl {
pub with: Option<Box<ObjectLit>>,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub phase: Option<ImportPhase>,
pub phase: ImportPhase,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, EqIgnoreSpan)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl"),
Expand All @@ -100,6 +100,9 @@ pub struct ImportDecl {
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub enum ImportPhase {
#[default]
#[cfg_attr(feature = "serde-impl", serde(rename = "evaluation"))]
Evaluation,
#[cfg_attr(feature = "serde-impl", serde(rename = "source"))]
Source,
#[cfg_attr(feature = "serde-impl", serde(rename = "defer"))]
Expand All @@ -114,7 +117,7 @@ impl Take for ImportDecl {
src: Take::dummy(),
type_only: Default::default(),
with: Take::dummy(),
phase: None,
phase: Default::default(),
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,15 @@ where
keyword!("type");
}

if let Some(phase) = n.phase {
space!();

match phase {
ImportPhase::Source => keyword!("source"),
ImportPhase::Defer => keyword!("defer"),
match n.phase {
ImportPhase::Evaluation => {}
ImportPhase::Source => {
space!();
keyword!("source");
}
ImportPhase::Defer => {
space!();
keyword!("defer");
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_compat_es2020/src/export_namespace_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl VisitMut for ExportNamespaceFrom {
src: src.clone(),
type_only: false,
with: with.clone(),
phase: None,
phase: Default::default(),
})));

stmts.push(ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_ecma_parser/src/parser/stmt/module_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<I: Tokens> Parser<I> {

let mut specifiers = vec![];

let mut phase = None;
let mut phase = Default::default();
let mut default_ident = None;

if is!(self, BindingIdent) {
Expand All @@ -111,8 +111,8 @@ impl<I: Tokens> Parser<I> {
&& (!is!(self, "from") || peeked_is!(self, "from"));

match &*ident.sym {
"source" if is_phase => phase = Some(ImportPhase::Source),
"defer" if is_phase => phase = Some(ImportPhase::Defer),
"source" if is_phase => phase = ImportPhase::Source,
"defer" if is_phase => phase = ImportPhase::Defer,
_ => default_ident = Some(ident),
};
}
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_preset_env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ impl VisitMut for Polyfills {
.into(),
type_only: false,
with: None,
phase: None,
phase: Default::default(),
}))
}),
);
Expand All @@ -487,7 +487,7 @@ impl VisitMut for Polyfills {
.into(),
type_only: false,
with: None,
phase: None,
phase: Default::default(),
}))
}),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_transforms_typescript/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ impl Transform {
src: Box::new(quote_str!("module")),
type_only: false,
with: None,
phase: None,
phase: Default::default(),
})
.into(),
// const __require = _createRequire(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_visit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ define!({
pub src: Box<Str>,
pub type_only: bool,
pub with: Option<Box<ObjectLit>>,
pub phase: Option<ImportPhase>,
pub phase: ImportPhase,
}
pub struct ExportAll {
pub span: Span,
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_estree_compat/src/swcify/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ impl Swcify for ImportDeclaration {
.into()
}),
// TODO
phase: None,
phase: Default::default(),
}
}
}
Expand Down

0 comments on commit f35c67f

Please sign in to comment.