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

Commit

Permalink
fix: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Apr 11, 2023
1 parent 380bdfe commit 6209898
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 58 deletions.
11 changes: 5 additions & 6 deletions crates/rome_js_parser/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ pub fn parse_module(text: &str) -> Parse<JsModule> {
/// assert_eq!(parsed.diagnostics().len(), 0);
/// // parse source text with granular control
/// module = SourceType::default()
/// .with_version(LanguageVersion::ESNext)
/// .with_module_kind(ModuleKind::Module)
/// .with_variant(LanguageVariant::Jsx);
/// .with_version(LanguageVersion::ESNext)
/// .with_module_kind(ModuleKind::Module)
/// .with_variant(LanguageVariant::Jsx);
/// parsed = parse("foo[bar]", module);
/// assert_eq!(parsed.diagnostics().len(), 0);
/// ```
Expand All @@ -267,12 +267,11 @@ pub fn parse(text: &str, source_type: SourceType) -> Parse<AnyJsRoot> {
/// let mut source = "function f() { return 2 }";
///
/// let parsed = parse_js_with_cache(source, source_type, &mut cache);
/// assert_eq!(parsed.diagnostics().len(), 0);
/// assert_eq!(parsed.diagnostics().len(), 0);
///
/// source = "function bar() { return 3 }";
/// let parsed = parse_js_with_cache(source, source_type, &mut cache);
/// assert_eq!(parsed.diagnostics().len(), 0);
///
/// assert_eq!(parsed.diagnostics().len(), 0);
/// ```
pub fn parse_js_with_cache(
text: &str,
Expand Down
52 changes: 0 additions & 52 deletions crates/rome_js_parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,59 +212,7 @@ pub struct JsParserCheckpoint {
#[cfg(test)]
mod tests {
use crate::prelude::*;
use crate::JsLosslessTreeSink;
use rome_js_syntax::{JsSyntaxKind, SourceType};
use rome_rowan::AstNode;

#[test]
fn example() {
use crate::syntax::expr::parse_expression_snipped;
use crate::JsParser;
use rome_js_syntax::{AnyJsExpression, JsExpressionSnipped};

let source = "(void b)";

// File id is used for the labels inside parser errors to report them, the file id
// is used to look up a file's source code and path inside of a codespan `Files` implementation.
let mut parser = JsParser::new(source, SourceType::default());

// Use one of the syntax parsing functions to parse an expression.
// This adds node and token events to the parser which are then used to make a node.
// A completed marker marks the start and end indices in the events vec which signify
// the Start event, and the Finish event.
// Completed markers can be turned into an ast node with parse_marker on the parser
parse_expression_snipped(&mut parser).unwrap();

// Consume the parser and get its events, then apply them to a tree sink with `process`.
let (events, tokens, errors) = parser.finish();

// Make a new text tree sink, its job is assembling events into a rowan GreenNode.
// At each point (Start, Token, Finish, Error) it also consumes whitespace.
// Other abstractions can also yield lossy syntax nodes if whitespace is not wanted.
// Swap this for a LossyTreeSink for a lossy AST result.
let mut sink = JsLosslessTreeSink::new(source, &tokens);

rome_parser::event::process(&mut sink, events, errors);

let (untyped_node, errors) = sink.finish();

assert!(errors.is_empty());
assert!(JsExpressionSnipped::can_cast(untyped_node.kind()));

// Convert the untyped SyntaxNode into a typed AST node
let expression_snipped = JsExpressionSnipped::cast(untyped_node).unwrap();
let expression = expression_snipped.expression().unwrap();

match expression {
AnyJsExpression::JsParenthesizedExpression(parenthesized) => {
assert_eq!(
parenthesized.expression().unwrap().syntax().text(),
"void b"
);
}
_ => panic!("Expected parenthesized expression"),
}
}

#[test]
#[should_panic(
Expand Down

0 comments on commit 6209898

Please sign in to comment.