forked from rome/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rome_js_formatter): Support arbitrarily deep binary expressi…
…ons (rome#2376) `format_binarish` used to use recursion to format the binary expressions. While this led to somewhat simpler code it had the downside that it stack overflowed for binary expressions with deep left subtrees. This PR rewrites the implementation to use an `Iterator` instead that visits the left-hand sides of binary-like-expressions in post order (first visiting the deepest left-hand side, then traversing upwards). This PR further fixes a unicode issue in the diff printing logic and renames `operator` to `operator_token` for a consistent naming.
- Loading branch information
1 parent
73452bd
commit 38e10b7
Showing
92 changed files
with
1,355 additions
and
1,347 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
8 changes: 5 additions & 3 deletions
8
crates/rome_js_formatter/src/js/expressions/binary_expression.rs
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,10 +1,12 @@ | ||
use crate::utils::format_binaryish_expression; | ||
use crate::utils::{format_binary_like_expression, JsAnyBinaryLikeExpression}; | ||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::JsBinaryExpression; | ||
use rome_rowan::AstNode; | ||
|
||
impl ToFormatElement for JsBinaryExpression { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
format_binaryish_expression(self.syntax(), formatter) | ||
format_binary_like_expression( | ||
JsAnyBinaryLikeExpression::JsBinaryExpression(self.clone()), | ||
formatter, | ||
) | ||
} | ||
} |
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,10 +1,12 @@ | ||
use crate::utils::format_binaryish_expression; | ||
use crate::utils::{format_binary_like_expression, JsAnyBinaryLikeExpression}; | ||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::JsInExpression; | ||
use rome_rowan::AstNode; | ||
|
||
impl ToFormatElement for JsInExpression { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
format_binaryish_expression(self.syntax(), formatter) | ||
format_binary_like_expression( | ||
JsAnyBinaryLikeExpression::JsInExpression(self.clone()), | ||
formatter, | ||
) | ||
} | ||
} |
8 changes: 5 additions & 3 deletions
8
crates/rome_js_formatter/src/js/expressions/instanceof_expression.rs
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,10 +1,12 @@ | ||
use crate::utils::format_binaryish_expression; | ||
use crate::utils::{format_binary_like_expression, JsAnyBinaryLikeExpression}; | ||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::JsInstanceofExpression; | ||
use rome_rowan::AstNode; | ||
|
||
impl ToFormatElement for JsInstanceofExpression { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
format_binaryish_expression(self.syntax(), formatter) | ||
format_binary_like_expression( | ||
JsAnyBinaryLikeExpression::JsInstanceofExpression(self.clone()), | ||
formatter, | ||
) | ||
} | ||
} |
8 changes: 5 additions & 3 deletions
8
crates/rome_js_formatter/src/js/expressions/logical_expression.rs
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,10 +1,12 @@ | ||
use crate::utils::format_binaryish_expression; | ||
use crate::utils::{format_binary_like_expression, JsAnyBinaryLikeExpression}; | ||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::JsLogicalExpression; | ||
use rome_rowan::AstNode; | ||
|
||
impl ToFormatElement for JsLogicalExpression { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
format_binaryish_expression(self.syntax(), formatter) | ||
format_binary_like_expression( | ||
JsAnyBinaryLikeExpression::JsLogicalExpression(self.clone()), | ||
formatter, | ||
) | ||
} | ||
} |
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
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.