Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
chore: update to rust 1.70.0 (#4563)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Jun 13, 2023
1 parent 8fc4c6f commit 36311b0
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 122 deletions.
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,14 @@ rome_js_analyze = { path = "./crates/rome_js_analyze" }
schemars = { version = "0.8.10" }


[profile.dev.package.rome_wasm]
opt-level = 1
debug = true

[profile.test.package.rome_wasm]
opt-level = 1
debug = true

[profile.release.package.rome_wasm]
opt-level = 3
debug = false
2 changes: 1 addition & 1 deletion crates/rome_formatter/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@ impl<Context> Format<Context> for BestFitting<'_, Context> {
// SAFETY: The constructor guarantees that there are always at least two variants. It's, therefore,
// safe to call into the unsafe `from_vec_unchecked` function
let element = unsafe {
FormatElement::BestFitting(format_element::BestFitting::from_vec_unchecked(
FormatElement::BestFitting(format_element::BestFittingElement::from_vec_unchecked(
formatted_variants,
))
};
Expand Down
8 changes: 4 additions & 4 deletions crates/rome_formatter/src/format_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub enum FormatElement {

/// A list of different variants representing the same content. The printer picks the best fitting content.
/// Line breaks inside of a best fitting don't propagate to parent groups.
BestFitting(BestFitting),
BestFitting(BestFittingElement),

/// A [Tag] that marks the start/end of some content to which some special formatting is applied.
Tag(Tag),
Expand Down Expand Up @@ -279,14 +279,14 @@ impl FormatElements for FormatElement {
///
/// Best fitting is defined as the variant that takes the most horizontal space but fits on the line.
#[derive(Clone, Eq, PartialEq)]
pub struct BestFitting {
pub struct BestFittingElement {
/// The different variants for this element.
/// The first element is the one that takes up the most space horizontally (the most flat),
/// The last element takes up the least space horizontally (but most horizontal space).
variants: Box<[Box<[FormatElement]>]>,
}

impl BestFitting {
impl BestFittingElement {
/// Creates a new best fitting IR with the given variants. The method itself isn't unsafe
/// but it is to discourage people from using it because the printer will panic if
/// the slice doesn't contain at least the least and most expanded variants.
Expand Down Expand Up @@ -326,7 +326,7 @@ impl BestFitting {
}
}

impl std::fmt::Debug for BestFitting {
impl std::fmt::Debug for BestFittingElement {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_list().entries(&*self.variants).finish()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_formatter/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ macro_rules! format {
///
/// [`Flat`]: crate::format_element::PrintMode::Flat
/// [`Expanded`]: crate::format_element::PrintMode::Expanded
/// [`MostExpanded`]: crate::format_element::BestFitting::most_expanded
/// [`MostExpanded`]: crate::format_element::BestFittingElement::most_expanded
#[macro_export]
macro_rules! best_fitting {
($least_expanded:expr, $($tail:expr),+ $(,)?) => {{
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_formatter/src/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod stack;

pub use printer_options::*;

use crate::format_element::{BestFitting, LineMode, PrintMode};
use crate::format_element::{BestFittingElement, LineMode, PrintMode};
use crate::{
ActualStart, FormatElement, GroupId, IndentStyle, InvalidDocumentError, PrintError,
PrintResult, Printed, SourceMarker, TextRange,
Expand Down Expand Up @@ -380,7 +380,7 @@ impl<'a> Printer<'a> {

fn print_best_fitting(
&mut self,
best_fitting: &'a BestFitting,
best_fitting: &'a BestFittingElement,
queue: &mut PrintQueue<'a>,
stack: &mut PrintCallStack,
) -> PrintResult<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ fn write_grouped_arguments(
// ... and best fitting only requires the most flat/and expanded.
unsafe {
f.write_element(FormatElement::BestFitting(
format_element::BestFitting::from_vec_unchecked(vec![
format_element::BestFittingElement::from_vec_unchecked(vec![
most_flat,
middle_variant,
most_expanded.into_boxed_slice(),
Expand Down
208 changes: 104 additions & 104 deletions crates/rome_js_formatter/src/utils/member_chain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,107 +1,107 @@
///! Utility function that applies some heuristic to format chain member expressions and call expressions
///!
///! We want to transform code that looks like this:
///!
///! ```js
///! something.execute().then().then().catch()
///! ```
///!
///! To something like this:
///!
///! ```js
///! something
///! .execute()
///! .then()
///! .then()
///! .catch()
///! ```
///!
///! In order to achieve that we use the same heuristic that [Prettier applies](https://github.com/prettier/prettier/blob/main/src/language-js/print/member-chain.js).
///!
///! The process is the following:
///!
///! ### Flattening the AST
///! We flatten the AST. See, the code above is actually nested, where the first member expression (`something`)
///! that we see is actually the last one. This is a oversimplified version of the AST:
///!
///! ```block
///! [
///! .catch() [
///! .then() [
///! .then() [
///! .execute() [
///! something
///! ]
///! ]
///! ]
///! ]
///! ]
///! ```
///! So we need to navigate the AST and make sure that `something` is actually
///! the first one. In a sense, we have to revert the chain of children. We will do that using a recursion.
///!
///! While we navigate the AST and we found particular nodes that we want to track, we also
///! format them. The format of these nodes is different from the standard version.
///!
///! Our formatter makes sure that we don't format twice the same nodes. Let's say for example that
///! we find a `something().execute()`, its AST is like this:
///!
///! ```block
///! JsCallExpression {
///! callee: JsStaticMember {
///! object: JsCallExpression {
///! callee: Reference {
///! execute
///! }
///! }
///! }
///! }
///! ```
///!
///! When we track the first [rome_js_syntax::JsCallExpression], we hold basically all the children,
///! that applies for the rest of the nodes. If we decided to format all the children of each node,
///! we will risk to format the last node, the `Reference`, four times.
///!
///! To avoid this, when we encounter particular nodes, we don't format all of its children, but defer
///! the formatting to the child itself.
///!
///! The end result of the flattening, will create an array of something like this:
///!
///! ```block
///! [ Identifier, JsCallExpression, JsStaticMember, JsCallExpression ]
///! ```
///!
///! ### Grouping
///!
///! After the flattening, we start the grouping. We want to group nodes in a way that will help us
///! to apply a deterministic formatting.
///! - first group will be the identifier
///! - the rest of the groups will be will start StaticMemberExpression followed by the rest of the nodes,
///! right before the end of the next StaticMemberExpression
///!
///! The first group is special, because it holds the reference; it has its own heuristic.
///! Inside the first group we store the first element of the flattened array, then:
///!
///! 1. as many as [rome_js_syntax::JsCallExpression] we can find, this cover cases like
///! `something()()().then()`;
///! 2. as many as [rome_js_syntax::JsComputedMemberExpression] we can find, this cover cases like
///! `something()()[1][3].then()`;
///! 3. as many as consecutive [rome_js_syntax::JsStaticMemberExpression] or [rome_js_syntax::JsComputedMemberExpression], this cover cases like
///! `this.items[0].then()`
///!
///! The rest of the groups are essentially a sequence of `[StaticMemberExpression , CallExpression]`.
///! In order to achieve that, we simply start looping through the rest of the flatten items that we haven't seen.
///!
///! Eventually, we should have something like this:
///!
///! ```block
///! [
///! [ReferenceIdentifier, CallExpression], // with possible computed expressions in the middle
///! [StaticMemberExpression, StaticMemberExpression, CallExpression],
///! [StaticMemberExpression, CallExpression],
///! [StaticMemberExpression],
///! ]
///! ```
//! Utility function that applies some heuristic to format chain member expressions and call expressions
//!
//! We want to transform code that looks like this:
//!
//! ```js
//! something.execute().then().then().catch()
//! ```
//!
//! To something like this:
//!
//! ```js
//! something
//! .execute()
//! .then()
//! .then()
//! .catch()
//! ```
//!
//! In order to achieve that we use the same heuristic that [Prettier applies](https://github.com/prettier/prettier/blob/main/src/language-js/print/member-chain.js).
//!
//! The process is the following:
//!
//! ### Flattening the AST
//! We flatten the AST. See, the code above is actually nested, where the first member expression (`something`)
//! that we see is actually the last one. This is a oversimplified version of the AST:
//!
//! ```block
//! [
//! .catch() [
//! .then() [
//! .then() [
//! .execute() [
//! something
//! ]
//! ]
//! ]
//! ]
//! ]
//! ```
//! So we need to navigate the AST and make sure that `something` is actually
//! the first one. In a sense, we have to revert the chain of children. We will do that using a recursion.
//!
//! While we navigate the AST and we found particular nodes that we want to track, we also
//! format them. The format of these nodes is different from the standard version.
//!
//! Our formatter makes sure that we don't format twice the same nodes. Let's say for example that
//! we find a `something().execute()`, its AST is like this:
//!
//! ```block
//! JsCallExpression {
//! callee: JsStaticMember {
//! object: JsCallExpression {
//! callee: Reference {
//! execute
//! }
//! }
//! }
//! }
//! ```
//!
//! When we track the first [rome_js_syntax::JsCallExpression], we hold basically all the children,
//! that applies for the rest of the nodes. If we decided to format all the children of each node,
//! we will risk to format the last node, the `Reference`, four times.
//!
//! To avoid this, when we encounter particular nodes, we don't format all of its children, but defer
//! the formatting to the child itself.
//!
//! The end result of the flattening, will create an array of something like this:
//!
//! ```block
//! [ Identifier, JsCallExpression, JsStaticMember, JsCallExpression ]
//! ```
//!
//! ### Grouping
//!
//! After the flattening, we start the grouping. We want to group nodes in a way that will help us
//! to apply a deterministic formatting.
//! - first group will be the identifier
//! - the rest of the groups will be will start StaticMemberExpression followed by the rest of the nodes,
//! right before the end of the next StaticMemberExpression
//!
//! The first group is special, because it holds the reference; it has its own heuristic.
//! Inside the first group we store the first element of the flattened array, then:
//!
//! 1. as many as [rome_js_syntax::JsCallExpression] we can find, this cover cases like
//! `something()()().then()`;
//! 2. as many as [rome_js_syntax::JsComputedMemberExpression] we can find, this cover cases like
//! `something()()[1][3].then()`;
//! 3. as many as consecutive [rome_js_syntax::JsStaticMemberExpression] or [rome_js_syntax::JsComputedMemberExpression], this cover cases like
//! `this.items[0].then()`
//!
//! The rest of the groups are essentially a sequence of `[StaticMemberExpression , CallExpression]`.
//! In order to achieve that, we simply start looping through the rest of the flatten items that we haven't seen.
//!
//! Eventually, we should have something like this:
//!
//! ```block
//! [
//! [ReferenceIdentifier, CallExpression], // with possible computed expressions in the middle
//! [StaticMemberExpression, StaticMemberExpression, CallExpression],
//! [StaticMemberExpression, CallExpression],
//! [StaticMemberExpression],
//! ]
//! ```
mod chain_member;
mod groups;
mod simple_argument;
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_js_parser/src/syntax/js_parse_error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Provides factory function to create common diagnostics for the JavaScript syntax

use crate::prelude::*;
use crate::span::Span;
use crate::JsParser;
use crate::JsSyntaxFeature::TypeScript;
use rome_js_syntax::TextRange;
use rome_parser::diagnostic::{expected_any, expected_node};

///! Provides factory function to create common diagnostics for the JavaScript syntax

pub(crate) fn expected_function_body(p: &JsParser, range: TextRange) -> ParseDiagnostic {
expected_node("function body", range).into_diagnostic(p)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_js_parser/src/syntax/module.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Implements the parsing logic for ES Module syntax

use crate::lexer::TextSize;
use crate::prelude::*;
use crate::state::{EnterAmbientContext, ExportDefaultItem, ExportDefaultItemKind};
Expand Down Expand Up @@ -38,8 +40,6 @@ use std::collections::HashMap;

use super::auxiliary::{is_nth_at_declaration_clause, parse_declaration_clause};

///! Implements the parsing logic for ES Module syntax

// test module
// import a from "b";
// export { a };
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_js_parser/src/syntax/pattern.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
///! Provides traits for parsing pattern like nodes
//! Provides traits for parsing pattern like nodes
use crate::prelude::*;
use crate::syntax::expr::{parse_assignment_expression_or_higher, ExpressionContext};
use crate::syntax::js_parse_error;
Expand Down
3 changes: 2 additions & 1 deletion crates/rome_parser/src/parse_lists.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! A set of traits useful to parse various types of lists

use crate::parse_recovery::RecoveryResult;
///! A set of traits useful to parse various types of lists
use crate::prelude::*;
use crate::ParserProgress;
use rome_rowan::SyntaxKind;
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_rowan/src/raw_language.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Provides a sample language implementation that is useful in API explanation or tests
use crate::raw_language::RawLanguageKind::{COMMA_TOKEN, LITERAL_EXPRESSION, ROOT};
///! Provides a sample language implementation that is useful in API explanation or tests
use crate::{
AstNode, AstSeparatedList, Language, ParsedChildren, RawNodeSlots, RawSyntaxKind,
RawSyntaxNode, SyntaxFactory, SyntaxKind, SyntaxKindSet, SyntaxList, SyntaxNode, TreeBuilder,
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# The default profile includes rustc, rust-std, cargo, rust-docs, rustfmt and clippy.
# https://rust-lang.github.io/rustup/concepts/profiles.html
profile = "default"
channel = "1.69.0"
channel = "1.70.0"
2 changes: 1 addition & 1 deletion website/build-netlify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if ! command -v wasm-pack &> /dev/null; then
fi

if [ "$1" == "preview" ]; then
pnpm build:wasm-dev
pnpm build:wasm
else
pnpm build:wasm
fi
Expand Down

0 comments on commit 36311b0

Please sign in to comment.