Skip to content

Commit

Permalink
Option
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Feb 28, 2023
1 parent cdc8128 commit a89e851
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 14 additions & 0 deletions crates/swc_ecma_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ impl Default for Syntax {
}

impl Syntax {
fn auto_accessor(self) -> bool {
match self {
Syntax::Es(EsConfig {
auto_accessor: true,
..
}) => true,
Syntax::Typescript(_) => true,
_ => false,
}
}

pub fn import_assertions(self) -> bool {
match self {
Syntax::Es(EsConfig {
Expand Down Expand Up @@ -317,6 +328,9 @@ pub struct EsConfig {

#[serde(default, rename = "allowReturnOutsideFunction")]
pub allow_return_outside_function: bool,

#[serde(default)]
pub auto_accessor: bool,
}

/// Syntactic context.
Expand Down
14 changes: 10 additions & 4 deletions crates/swc_ecma_parser/src/parser/class_and_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,15 @@ impl<I: Tokens> Parser<I> {
}
};

let accessor_token = {
let accessor_token = if self.syntax().auto_accessor() {
let start = cur_pos!(self);
if eat!(self, "accessor") {
Some(span!(self, start))
} else {
None
}
} else {
None
};

if let Some(static_token) = static_token {
Expand Down Expand Up @@ -622,9 +624,13 @@ impl<I: Tokens> Parser<I> {
}

let accessor_token = accessor_token.or_else(|| {
let start = cur_pos!(self);
if eat!(self, "accessor") {
Some(span!(self, start))
if self.syntax().auto_accessor() {
let start = cur_pos!(self);
if eat!(self, "accessor") {
Some(span!(self, start))
} else {
None
}
} else {
None
}
Expand Down

0 comments on commit a89e851

Please sign in to comment.