mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +03:00
fix(es/parser): Fix conditional compilation (#8343)
**Description:** `swc_ecma_parser` crate has a `typescript` feature which enables TS parsing, the `Syntax::Typescript` variant is behind the `typescript` feature, compiling without this feature fails as `Syntax::Typescript` is referenced at many places without `#[cfg(feature = "typescript")]`
This commit is contained in:
parent
7e8b6c0f04
commit
a423681df8
@ -171,6 +171,7 @@ impl Syntax {
|
||||
auto_accessors: true,
|
||||
..
|
||||
}) => true,
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -181,16 +182,19 @@ impl Syntax {
|
||||
Syntax::Es(EsConfig {
|
||||
import_attributes, ..
|
||||
}) => import_attributes,
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(_) => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Should we parse jsx?
|
||||
pub fn jsx(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Syntax::Es(EsConfig { jsx: true, .. }) | Syntax::Typescript(TsConfig { tsx: true, .. })
|
||||
)
|
||||
match self {
|
||||
Syntax::Es(EsConfig { jsx: true, .. }) => true,
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(TsConfig { tsx: true, .. }) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fn_bind(self) -> bool {
|
||||
@ -198,26 +202,28 @@ impl Syntax {
|
||||
}
|
||||
|
||||
pub fn decorators(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
match self {
|
||||
Syntax::Es(EsConfig {
|
||||
decorators: true,
|
||||
..
|
||||
}) | Syntax::Typescript(TsConfig {
|
||||
decorators: true,
|
||||
..
|
||||
})
|
||||
)
|
||||
decorators: true, ..
|
||||
}) => true,
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(TsConfig {
|
||||
decorators: true, ..
|
||||
}) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decorators_before_export(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
match self {
|
||||
Syntax::Es(EsConfig {
|
||||
decorators_before_export: true,
|
||||
..
|
||||
}) | Syntax::Typescript(..)
|
||||
)
|
||||
}) => true,
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Should we parse typescript?
|
||||
@ -244,6 +250,7 @@ impl Syntax {
|
||||
|
||||
pub fn dts(self) -> bool {
|
||||
match self {
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(t) => t.dts,
|
||||
_ => false,
|
||||
}
|
||||
@ -255,6 +262,7 @@ impl Syntax {
|
||||
allow_super_outside_method,
|
||||
..
|
||||
}) => allow_super_outside_method,
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(_) => true,
|
||||
}
|
||||
}
|
||||
@ -265,12 +273,14 @@ impl Syntax {
|
||||
allow_return_outside_function,
|
||||
..
|
||||
}) => allow_return_outside_function,
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn early_errors(self) -> bool {
|
||||
match self {
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(t) => !t.no_early_errors,
|
||||
Syntax::Es(..) => true,
|
||||
}
|
||||
@ -278,6 +288,7 @@ impl Syntax {
|
||||
|
||||
fn disallow_ambiguous_jsx_like(self) -> bool {
|
||||
match self {
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(t) => t.disallow_ambiguous_jsx_like,
|
||||
_ => false,
|
||||
}
|
||||
@ -289,6 +300,7 @@ impl Syntax {
|
||||
explicit_resource_management: using_decl,
|
||||
..
|
||||
}) => *using_decl,
|
||||
#[cfg(feature = "typescript")]
|
||||
Syntax::Typescript(_) => true,
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ mod pat;
|
||||
mod stmt;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
#[cfg(feature = "typescript")]
|
||||
mod typescript;
|
||||
mod util;
|
||||
|
||||
@ -66,10 +67,13 @@ impl<'a> Parser<Lexer<'a>> {
|
||||
|
||||
impl<I: Tokens> Parser<I> {
|
||||
pub fn new_from(mut input: I) -> Self {
|
||||
#[cfg(feature = "typescript")]
|
||||
let in_declare = matches!(
|
||||
input.syntax(),
|
||||
Syntax::Typescript(TsConfig { dts: true, .. })
|
||||
);
|
||||
#[cfg(not(feature = "typescript"))]
|
||||
let in_declare = false;
|
||||
let ctx = Context {
|
||||
in_declare,
|
||||
..input.ctx()
|
||||
|
Loading…
Reference in New Issue
Block a user