This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rslint_parser): Update Literals AST Facade
Refines the AST Facade for literals to match the grammar proposed in #1719. This change is part of #1725. * Introduce new `JsAnyLiteral` * Split `Literal` into `JsStringLiteral`, `JsBooleanLiteral`, `JsNullLiteral`, `JsRegexLiteral`, and `JsBigIntLiteral`. This allows to implement custom methods on the corresponding literal nodes. * Renames the `number` and kinds to `JS_NUMBER_LITERAL_TOKEN` `JS_STRING_LITERAL_TOKEN` to avoid conflicts with the TS `number` keyword (and keep symmetry). * Removed some unused keywords and special handling inside of the code gen.
- Loading branch information
1 parent
124d5a5
commit b5e5af8
Showing
66 changed files
with
765 additions
and
623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,61 @@ | ||
use rslint_parser::ast::Literal; | ||
use crate::{token, FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rslint_parser::ast::{ | ||
JsAnyLiteral, JsBigIntLiteral, JsBooleanLiteral, JsNullLiteral, JsNumberLiteral, | ||
JsStringLiteral, | ||
}; | ||
|
||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
impl ToFormatElement for JsStringLiteral { | ||
fn to_format_element(&self, _: &Formatter) -> FormatResult<FormatElement> { | ||
let value_token = self.value_token()?; | ||
let quoted = value_token.text(); | ||
|
||
impl ToFormatElement for Literal { | ||
// uses single quotes | ||
if quoted.starts_with('\'') { | ||
let mut double_quoted = String::from(quoted); | ||
double_quoted.replace_range(0..1, "\""); | ||
double_quoted.replace_range(double_quoted.len() - 1..double_quoted.len(), "\""); | ||
Ok(token(double_quoted.as_str())) | ||
} else { | ||
Ok(token(quoted)) | ||
} | ||
} | ||
} | ||
|
||
impl ToFormatElement for JsBooleanLiteral { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
formatter.format_token(&self.value_token()?) | ||
} | ||
} | ||
|
||
impl ToFormatElement for JsNullLiteral { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
formatter.format_token(&self.value_token()?) | ||
} | ||
} | ||
|
||
impl ToFormatElement for JsNumberLiteral { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
formatter.format_token(&self.value_token()?) | ||
} | ||
} | ||
|
||
impl ToFormatElement for JsBigIntLiteral { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
formatter.format_token(&self.value_token()?) | ||
} | ||
} | ||
|
||
impl ToFormatElement for JsAnyLiteral { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
formatter.format_token(&self.token()) | ||
match self { | ||
JsAnyLiteral::JsBooleanLiteral(boolean) => boolean.to_format_element(formatter), | ||
JsAnyLiteral::JsStringLiteral(string_literal) => { | ||
string_literal.to_format_element(formatter) | ||
} | ||
JsAnyLiteral::JsNumberLiteral(number) => number.to_format_element(formatter), | ||
JsAnyLiteral::JsBigIntLiteral(big_int) => big_int.to_format_element(formatter), | ||
JsAnyLiteral::JsNullLiteral(null_literal) => null_literal.to_format_element(formatter), | ||
JsAnyLiteral::JsRegexLiteral(_) => todo!(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ mod script; | |
mod setter; | ||
mod spread; | ||
mod statements; | ||
mod tokens; | ||
|
||
#[cfg(test)] | ||
mod test { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.