Allow optional chaining in ecmascript (#619)

Fixes #618
This commit is contained in:
kdy1 2020-01-31 15:59:47 +00:00
parent 8afa3413ea
commit 196740cdcd
2 changed files with 15 additions and 1 deletions

View File

@ -137,6 +137,17 @@ impl Syntax {
}
}
pub fn optional_chaining(self) -> bool {
match self {
Syntax::Es(EsConfig {
optional_chaining: true,
..
})
| Syntax::Typescript(TsConfig { .. }) => true,
_ => false,
}
}
pub fn dynamic_import(self) -> bool {
match self {
Syntax::Es(EsConfig {
@ -361,6 +372,9 @@ pub struct EsConfig {
#[serde(default)]
pub nullish_coalescing: bool,
#[serde(default)]
pub optional_chaining: bool,
/// Stage 3.
#[serde(default)]
pub import_meta: bool,

View File

@ -888,7 +888,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
}
let is_optional_chaining =
self.input.syntax().typescript() && is!('?') && peeked_is!('.') && eat!('?');
self.input.syntax().optional_chaining() && is!('?') && peeked_is!('.') && eat!('?');
/// Wrap with optional chaining
macro_rules! wrap {