mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
fix(es/typescript): Rename wrong unresolved_mark
(#8018)
**Related issue:** - Closes: #8016
This commit is contained in:
parent
8231f874e7
commit
58172689ce
@ -49,7 +49,7 @@ use crate::{
|
||||
/// [export and import require]: https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct Transform {
|
||||
unresolved_mark: Mark,
|
||||
top_level_mark: Mark,
|
||||
top_level_ctxt: SyntaxContext,
|
||||
|
||||
import_export_assign_config: TsImportExportAssignConfig,
|
||||
@ -64,13 +64,13 @@ pub(crate) struct Transform {
|
||||
}
|
||||
|
||||
pub fn transform(
|
||||
unresolved_mark: Mark,
|
||||
top_level_mark: Mark,
|
||||
import_export_assign_config: TsImportExportAssignConfig,
|
||||
verbatim_module_syntax: bool,
|
||||
) -> impl Fold + VisitMut {
|
||||
as_folder(Transform {
|
||||
unresolved_mark,
|
||||
top_level_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark),
|
||||
top_level_mark,
|
||||
top_level_ctxt: SyntaxContext::empty().apply_mark(top_level_mark),
|
||||
import_export_assign_config,
|
||||
verbatim_module_syntax,
|
||||
..Default::default()
|
||||
@ -502,7 +502,7 @@ impl Transform {
|
||||
&id.to_id(),
|
||||
&default_init,
|
||||
&self.record,
|
||||
self.unresolved_mark,
|
||||
self.top_level_mark,
|
||||
);
|
||||
|
||||
default_init = value.inc();
|
||||
@ -560,14 +560,14 @@ impl Transform {
|
||||
enum_id: &Id,
|
||||
default_init: &TsEnumRecordValue,
|
||||
record: &TsEnumRecord,
|
||||
unresolved_mark: Mark,
|
||||
top_level_mark: Mark,
|
||||
) -> TsEnumRecordValue {
|
||||
member
|
||||
.init
|
||||
.map(|expr| {
|
||||
EnumValueComputer {
|
||||
enum_id,
|
||||
unresolved_mark,
|
||||
top_level_mark,
|
||||
record,
|
||||
}
|
||||
.compute(expr)
|
||||
@ -934,9 +934,13 @@ impl Transform {
|
||||
let mut should_inject = false;
|
||||
let create_require = private_ident!("_createRequire");
|
||||
let require = private_ident!("__require");
|
||||
let global_span = DUMMY_SP.apply_mark(self.unresolved_mark);
|
||||
let cjs_require = quote_ident!(global_span, "require");
|
||||
let cjs_exports = quote_ident!(global_span, "exports");
|
||||
|
||||
// NOTE: This is not correct!
|
||||
// However, all unresolved_span are used in TsImportExportAssignConfig::Classic
|
||||
// which is deprecated and not used in real world.
|
||||
let unresolved_span = DUMMY_SP.apply_mark(self.top_level_mark);
|
||||
let cjs_require = quote_ident!(unresolved_span, "require");
|
||||
let cjs_exports = quote_ident!(unresolved_span, "exports");
|
||||
|
||||
let mut cjs_export_assign = None;
|
||||
|
||||
@ -1097,16 +1101,10 @@ impl Transform {
|
||||
n.push(
|
||||
Stmt::Expr(ExprStmt {
|
||||
span,
|
||||
expr: Box::new(
|
||||
expr.make_assign_to(
|
||||
op!("="),
|
||||
member_expr!(
|
||||
DUMMY_SP.apply_mark(self.unresolved_mark),
|
||||
module.exports
|
||||
)
|
||||
.as_pat_or_expr(),
|
||||
),
|
||||
),
|
||||
expr: Box::new(expr.make_assign_to(
|
||||
op!("="),
|
||||
member_expr!(unresolved_span, module.exports).as_pat_or_expr(),
|
||||
)),
|
||||
})
|
||||
.into(),
|
||||
);
|
||||
|
@ -91,7 +91,7 @@ impl From<f64> for TsEnumRecordValue {
|
||||
|
||||
pub(crate) struct EnumValueComputer<'a> {
|
||||
pub enum_id: &'a Id,
|
||||
pub unresolved_mark: Mark,
|
||||
pub top_level_mark: Mark,
|
||||
pub record: &'a TsEnumRecord,
|
||||
}
|
||||
|
||||
@ -111,12 +111,12 @@ impl<'a> EnumValueComputer<'a> {
|
||||
span,
|
||||
sym: js_word!("NaN"),
|
||||
..
|
||||
}) if span.ctxt.has_mark(self.unresolved_mark) => TsEnumRecordValue::Number(f64::NAN),
|
||||
}) if span.ctxt.has_mark(self.top_level_mark) => TsEnumRecordValue::Number(f64::NAN),
|
||||
Expr::Ident(Ident {
|
||||
span,
|
||||
sym: js_word!("Infinity"),
|
||||
..
|
||||
}) if span.ctxt.has_mark(self.unresolved_mark) => {
|
||||
}) if span.ctxt.has_mark(self.top_level_mark) => {
|
||||
TsEnumRecordValue::Number(f64::INFINITY)
|
||||
}
|
||||
Expr::Ident(ref ident) => self
|
||||
|
@ -12,21 +12,21 @@ use swc_ecma_visit::{as_folder, Fold, VisitMut, VisitMutWith};
|
||||
pub use crate::config::*;
|
||||
use crate::{strip_import_export::StripImportExport, strip_type::StripType, transform::transform};
|
||||
|
||||
pub fn typescript(config: Config, unresolved_mark: Mark) -> impl Fold + VisitMut {
|
||||
pub fn typescript(config: Config, top_level_mark: Mark) -> impl Fold + VisitMut {
|
||||
as_folder(TypeScript {
|
||||
config,
|
||||
unresolved_mark,
|
||||
top_level_mark,
|
||||
id_usage: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn strip(unresolved_mark: Mark) -> impl Fold + VisitMut {
|
||||
typescript(Config::default(), unresolved_mark)
|
||||
pub fn strip(top_level_mark: Mark) -> impl Fold + VisitMut {
|
||||
typescript(Config::default(), top_level_mark)
|
||||
}
|
||||
|
||||
pub(crate) struct TypeScript {
|
||||
pub config: Config,
|
||||
pub unresolved_mark: Mark,
|
||||
pub top_level_mark: Mark,
|
||||
|
||||
id_usage: AHashSet<Id>,
|
||||
}
|
||||
@ -45,7 +45,7 @@ impl VisitMut for TypeScript {
|
||||
n.visit_mut_with(&mut StripType::default());
|
||||
|
||||
n.visit_mut_with(&mut transform(
|
||||
self.unresolved_mark,
|
||||
self.top_level_mark,
|
||||
self.config.import_export_assign_config,
|
||||
self.config.verbatim_module_syntax,
|
||||
));
|
||||
@ -104,7 +104,7 @@ pub fn tsx<C>(
|
||||
config: Config,
|
||||
tsx_config: TsxConfig,
|
||||
comments: C,
|
||||
unresolved_mark: Mark,
|
||||
top_level_mark: Mark,
|
||||
) -> impl Fold + VisitMut
|
||||
where
|
||||
C: Comments,
|
||||
@ -115,7 +115,7 @@ where
|
||||
id_usage: Default::default(),
|
||||
comments,
|
||||
cm,
|
||||
unresolved_mark,
|
||||
top_level_mark,
|
||||
})
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ where
|
||||
id_usage: AHashSet<Id>,
|
||||
comments: C,
|
||||
cm: Lrc<SourceMap>,
|
||||
unresolved_mark: Mark,
|
||||
top_level_mark: Mark,
|
||||
}
|
||||
|
||||
impl<C> VisitMut for TypeScriptReact<C>
|
||||
@ -162,7 +162,7 @@ where
|
||||
.pragma
|
||||
.clone()
|
||||
.unwrap_or_else(|| "React.createElement".to_string()),
|
||||
self.unresolved_mark,
|
||||
self.top_level_mark,
|
||||
);
|
||||
|
||||
let pragma_frag = parse_expr_for_jsx(
|
||||
@ -172,7 +172,7 @@ where
|
||||
.pragma_frag
|
||||
.clone()
|
||||
.unwrap_or_else(|| "React.Fragment".to_string()),
|
||||
self.unresolved_mark,
|
||||
self.top_level_mark,
|
||||
);
|
||||
|
||||
let pragma_id = id_for_jsx(&pragma);
|
||||
@ -190,7 +190,7 @@ where
|
||||
pragma_frag,
|
||||
..
|
||||
} = self.comments.with_leading(span.lo, |comments| {
|
||||
JsxDirectives::from_comments(&self.cm, span, comments, self.unresolved_mark)
|
||||
JsxDirectives::from_comments(&self.cm, span, comments, self.top_level_mark)
|
||||
});
|
||||
|
||||
if let Some(pragma) = pragma {
|
||||
@ -214,7 +214,7 @@ where
|
||||
|
||||
n.visit_mut_with(&mut TypeScript {
|
||||
config: mem::take(&mut self.config),
|
||||
unresolved_mark: self.unresolved_mark,
|
||||
top_level_mark: self.top_level_mark,
|
||||
id_usage: mem::take(&mut self.id_usage),
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user