Skip to content

Commit a353aa3

Browse files
committed
get tests passing
1 parent d5a5231 commit a353aa3

24 files changed

Lines changed: 1344 additions & 422 deletions

Cargo.lock

Lines changed: 13 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ harness = false
3333
anyhow = "1.0.64"
3434
capacity_builder = "0.5.0"
3535
# oxc-port: use the local checkout for iteration. Final form:
36-
# deno_ast = { git = "https://github.com/nathanwhit/deno_ast", branch = "oxc-port" }
37-
deno_ast = { path = "../deno_ast" }
36+
deno_ast = { git = "https://github.com/nathanwhit/deno_ast", branch = "oxc-port" }
3837
dprint-core = { version = "0.67.4", features = ["formatting"] }
3938
dprint-core-macros = "0.1.0"
4039
percent-encoding = "2.3.1"

src/format_text.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ use std::path::Path;
22
use std::sync::Arc;
33

44
use anyhow::Result;
5-
use deno_ast::oxc::allocator::Allocator;
65
use deno_ast::ParsedSource;
6+
use deno_ast::oxc::allocator::Allocator;
77
use dprint_core::configuration::resolve_new_line_kind;
88
use dprint_core::formatting::*;
99

10-
use crate::swc::ensure_no_specific_syntax_errors;
10+
use crate::parse::ensure_no_specific_syntax_errors;
1111

1212
use super::configuration::Configuration;
13-
use super::generation::generate;
1413
pub use super::generation::ExternalFormatter;
15-
use super::swc::parse_swc_ast;
14+
use super::generation::generate;
15+
use super::parse::parse_ast;
1616

1717
pub struct FormatTextOptions<'a> {
1818
pub path: &'a Path,
@@ -70,7 +70,7 @@ pub fn format_text(options: FormatTextOptions) -> Result<Option<String>> {
7070
let file_text = if had_bom { file_text[3..].to_string() } else { file_text };
7171
let file_text: Arc<str> = file_text.into();
7272
let allocator = Allocator::default();
73-
let parsed_source = parse_swc_ast(&allocator, file_path, file_extension, file_text)?;
73+
let parsed_source = parse_ast(&allocator, file_path, file_extension, file_text)?;
7474
match inner_format(&parsed_source, config, external_formatter)? {
7575
Some(new_text) => Ok(Some(new_text)),
7676
None => {
@@ -85,7 +85,11 @@ pub fn format_text(options: FormatTextOptions) -> Result<Option<String>> {
8585
}
8686

8787
/// Formats an already parsed source. This is useful as a performance optimization.
88-
pub fn format_parsed_source<'a>(source: &'a ParsedSource<'a>, config: &Configuration, external_formatter: Option<&ExternalFormatter>) -> Result<Option<String>> {
88+
pub fn format_parsed_source<'a>(
89+
source: &'a ParsedSource<'a>,
90+
config: &Configuration,
91+
external_formatter: Option<&ExternalFormatter>,
92+
) -> Result<Option<String>> {
8993
if super::utils::file_text_has_ignore_comment(source.text(), &config.ignore_file_comment_text) {
9094
Ok(None)
9195
} else {
@@ -119,7 +123,7 @@ fn inner_format<'a>(parsed_source: &'a ParsedSource<'a>, config: &Configuration,
119123
#[cfg(feature = "tracing")]
120124
pub fn trace_file(file_path: &Path, file_text: &str, config: &Configuration) -> dprint_core::formatting::TracingResult {
121125
let allocator = Allocator::default();
122-
let parsed_source = parse_swc_ast(&allocator, file_path, None, file_text.into()).unwrap();
126+
let parsed_source = parse_ast(&allocator, file_path, None, file_text.into()).unwrap();
123127
ensure_no_specific_syntax_errors(&parsed_source).unwrap();
124128
dprint_core::formatting::trace_printing(|| generate(&parsed_source, config, None).unwrap(), config_to_print_options(file_text, config))
125129
}

src/generation/context.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use deno_ast::MediaType;
12
use deno_ast::oxc::ast::ast::Comment;
23
use deno_ast::oxc::parser::Token;
3-
use deno_ast::MediaType;
44
use dprint_core::formatting::ConditionReference;
55
use dprint_core::formatting::IndentLevel;
66
use dprint_core::formatting::IsStartOfLine;
@@ -9,14 +9,14 @@ use dprint_core::formatting::LineStartIndentLevel;
99
use rustc_hash::FxHashMap;
1010
use rustc_hash::FxHashSet;
1111

12+
use super::CommentTracker;
13+
use super::TokenFinder;
1214
use super::oxc_helpers::CommentExt;
1315
use super::oxc_helpers::Node;
1416
use super::oxc_helpers::ProgramInfo;
1517
use super::oxc_helpers::SourcePos;
1618
use super::oxc_helpers::SourceRange;
1719
use super::oxc_helpers::SourceRanged;
18-
use super::CommentTracker;
19-
use super::TokenFinder;
2020
use crate::configuration::*;
2121
use crate::utils::Stack;
2222

@@ -71,6 +71,7 @@ pub struct Context<'a> {
7171
stored_ln: FxHashMap<(SourcePos, SourcePos), LineNumber>,
7272
stored_il: FxHashMap<(SourcePos, SourcePos), IndentLevel>,
7373
pub skip_iife_body_indent: bool,
74+
pub suppress_synthetic_expr_parens: bool,
7475
pub end_statement_or_member_lns: Stack<LineNumber>,
7576
before_comments_start_info_stack: Stack<(SourceRange, LineNumber, IsStartOfLine)>,
7677
if_stmt_last_brace_condition_ref: Option<ConditionReference>,
@@ -106,6 +107,7 @@ impl<'a> Context<'a> {
106107
stored_ln: FxHashMap::default(),
107108
stored_il: FxHashMap::default(),
108109
skip_iife_body_indent: false,
110+
suppress_synthetic_expr_parens: false,
109111
end_statement_or_member_lns: Default::default(),
110112
before_comments_start_info_stack: Default::default(),
111113
if_stmt_last_brace_condition_ref: None,

0 commit comments

Comments
 (0)