Skip to content

Commit 52ff5ff

Browse files
authored
upgrade: swc_ecma_parser 0.29.0 (#31)
1 parent 38989c4 commit 52ff5ff

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "dprint-plugin-typescript"
33
description = "TypeScript code formatting plugin for Dprint."
44
keywords = ["formatting", "formatter", "typescript"]
5-
version = "0.21.0"
5+
version = "0.22.0"
66
authors = ["David Sherret <[email protected]>"]
77
edition = "2018"
88
license = "MIT"
@@ -24,7 +24,7 @@ panic = "abort"
2424
dprint-core = "0.24.1"
2525
swc_common = "=0.7.0"
2626
swc_ecma_ast = "=0.24.0"
27-
swc_ecma_parser = "=0.28.0"
27+
swc_ecma_parser = "=0.29.0"
2828
serde = { version = "1.0.88", features = ["derive"] }
2929
serde_json = "1.0"
3030

src/swc/parse_swc_ast.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use swc_common::{
55
FileName, comments::{Comment, Comments, CommentMap}, SourceFile, BytePos
66
};
77
use swc_ecma_ast::{Module};
8-
use swc_ecma_parser::{Parser, Session, SourceFileInput, Syntax, lexer::Lexer, Capturing, JscTarget, token::{TokenAndSpan}};
8+
use swc_ecma_parser::{Parser, SourceFileInput, Syntax, lexer::Lexer, Capturing, JscTarget, token::{TokenAndSpan}};
99

1010
pub struct ParsedSourceFile<'a> {
1111
pub module: Module,
@@ -36,8 +36,7 @@ pub fn parse_swc_ast<'a>(file_path: &PathBuf, file_text: &'a str) -> Result<Pars
3636

3737
fn parse_inner<'a>(file_path: &PathBuf, file_text: &'a str) -> Result<ParsedSourceFile<'a>, String> {
3838
let handler = Handler::with_emitter(false, false, Box::new(EmptyEmitter {}));
39-
let session = Session { handler: &handler };
40-
39+
4140
let file_bytes = file_text.as_bytes();
4241
let source_file = SourceFile::new(
4342
FileName::Custom(file_path.to_string_lossy().into()),
@@ -54,23 +53,23 @@ fn parse_inner<'a>(file_path: &PathBuf, file_text: &'a str) -> Result<ParsedSour
5453
ts_config.dynamic_import = true;
5554
ts_config.decorators = true;
5655
let lexer = Lexer::new(
57-
session,
5856
Syntax::Typescript(ts_config),
5957
JscTarget::Es2019,
6058
SourceFileInput::from(&source_file),
6159
Some(&comments)
6260
);
6361
let lexer = Capturing::new(lexer);
64-
let mut parser = Parser::new_from(session, lexer);
62+
let mut parser = Parser::new_from(lexer);
6563
let parse_module_result = parser.parse_module();
6664
let tokens = parser.input().take();
6765

6866
match parse_module_result {
69-
Err(mut error) => {
67+
Err(error) => {
7068
// mark the diagnostic as being handled (otherwise it will panic in its drop)
71-
error.cancel();
69+
let mut diagnostic = error.into_diagnostic(&handler);
70+
diagnostic.cancel();
7271
// return the formatted diagnostic string
73-
Err(format_diagnostic(&error, file_text))
72+
Err(format_diagnostic(&diagnostic, file_text))
7473
},
7574
Ok(module) => Ok((module, tokens))
7675
}

0 commit comments

Comments
 (0)