From 367ac825f6bfab65cf8bcb21e68500daef8ad177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 28 Feb 2023 17:20:29 +0900 Subject: [PATCH] refactor(es/parser): Make lexer not generic over `Input` (#6993) **Description:** Currently, it uses `StringInput` as the input type, but I'll refactor it to use `String` or `Vec` directly to optimize it further. **Related issue:** - https://github.com/swc-project/swc/discussions/6991 --- crates/swc/tests/serde.rs | 3 +-- crates/swc_ecma_codegen/tests/sourcemap.rs | 4 ++-- crates/swc_ecma_codegen/tests/test262.rs | 4 ++-- crates/swc_ecma_dep_graph/src/lib.rs | 4 ++-- crates/swc_ecma_parser/src/lexer/jsx.rs | 2 +- crates/swc_ecma_parser/src/lexer/mod.rs | 16 ++++++++-------- crates/swc_ecma_parser/src/lexer/number.rs | 6 +++--- crates/swc_ecma_parser/src/lexer/state.rs | 6 +++--- crates/swc_ecma_parser/src/lexer/util.rs | 2 +- crates/swc_ecma_parser/src/lib.rs | 2 +- crates/swc_ecma_parser/src/parser/mod.rs | 12 ++++++------ crates/swc_ecma_parser/tests/errors.rs | 2 +- crates/swc_ecma_parser/tests/js.rs | 4 ++-- crates/swc_ecma_parser/tests/jsx.rs | 4 ++-- crates/swc_ecma_parser/tests/span.rs | 4 ++-- crates/swc_ecma_parser/tests/test262.rs | 4 ++-- crates/swc_ecma_parser/tests/typescript.rs | 4 ++-- crates/swc_ecma_quote_macros/src/ret_type.rs | 2 +- crates/swc_ecma_transforms_base/src/tests.rs | 2 +- .../tests/fixer_test262.rs | 6 +++--- crates/swc_ecma_transforms_testing/src/lib.rs | 2 +- .../tests/strip_correctness.rs | 6 +++--- 22 files changed, 50 insertions(+), 51 deletions(-) diff --git a/crates/swc/tests/serde.rs b/crates/swc/tests/serde.rs index 32b888f8678f..aacc8aa4ec4d 100644 --- a/crates/swc/tests/serde.rs +++ b/crates/swc/tests/serde.rs @@ -1,13 +1,12 @@ use std::path::Path; -use swc_common::input::StringInput; use swc_ecma_ast::Module; use swc_ecma_parser::{lexer::Lexer, PResult, Parser, Syntax}; use testing::NormalizedOutput; fn with_parser(file_name: &str, f: F) -> Result where - F: FnOnce(&mut Parser>) -> PResult, + F: FnOnce(&mut Parser) -> PResult, { ::testing::run_test(false, |cm, handler| { let fm = cm diff --git a/crates/swc_ecma_codegen/tests/sourcemap.rs b/crates/swc_ecma_codegen/tests/sourcemap.rs index dd5a0f0dd3b8..ce0513cb267b 100644 --- a/crates/swc_ecma_codegen/tests/sourcemap.rs +++ b/crates/swc_ecma_codegen/tests/sourcemap.rs @@ -7,7 +7,7 @@ use sourcemap::SourceMap; use swc_common::{comments::SingleThreadedComments, source_map::SourceMapGenConfig}; use swc_ecma_ast::EsVersion; use swc_ecma_codegen::{self, text_writer::WriteJs, Emitter}; -use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax}; +use swc_ecma_parser::{lexer::Lexer, Parser, Syntax}; use swc_ecma_testing::{exec_node_js, JsExecOptions}; static IGNORED_PASS_TESTS: &[&str] = &[ @@ -306,7 +306,7 @@ fn identity(entry: PathBuf) { (&*fm).into(), Some(&comments), ); - let mut parser: Parser> = Parser::new_from(lexer); + let mut parser: Parser = Parser::new_from(lexer); let mut src_map = vec![]; { diff --git a/crates/swc_ecma_codegen/tests/test262.rs b/crates/swc_ecma_codegen/tests/test262.rs index 29a10d7fca66..8e0b27028362 100644 --- a/crates/swc_ecma_codegen/tests/test262.rs +++ b/crates/swc_ecma_codegen/tests/test262.rs @@ -9,7 +9,7 @@ use std::{ use swc_common::comments::SingleThreadedComments; use swc_ecma_ast::EsVersion; use swc_ecma_codegen::{self, text_writer::WriteJs, Emitter}; -use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax}; +use swc_ecma_parser::{lexer::Lexer, Parser, Syntax}; use testing::NormalizedOutput; const IGNORED_PASS_TESTS: &[&str] = &[ @@ -121,7 +121,7 @@ fn do_test(entry: &Path, minify: bool) { (&*src).into(), Some(&comments), ); - let mut parser: Parser> = Parser::new_from(lexer); + let mut parser: Parser = Parser::new_from(lexer); { let mut wr = Box::new(swc_ecma_codegen::text_writer::JsWriter::new( diff --git a/crates/swc_ecma_dep_graph/src/lib.rs b/crates/swc_ecma_dep_graph/src/lib.rs index 62ff96fed604..2bba8a8ce523 100644 --- a/crates/swc_ecma_dep_graph/src/lib.rs +++ b/crates/swc_ecma_dep_graph/src/lib.rs @@ -380,7 +380,7 @@ mod tests { comments::{Comment, CommentKind, SingleThreadedComments}, BytePos, FileName, Span, SyntaxContext, }; - use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax, TsConfig}; + use swc_ecma_parser::{lexer::Lexer, Parser, Syntax, TsConfig}; use super::*; @@ -393,7 +393,7 @@ mod tests { cm.new_source_file(FileName::Custom(file_name.to_string()), source.to_string()); let comments = SingleThreadedComments::default(); - let lexer: Lexer> = Lexer::new( + let lexer: Lexer = Lexer::new( Syntax::Typescript(TsConfig { dts: file_name.ends_with(".d.ts"), tsx: file_name.contains("tsx"), diff --git a/crates/swc_ecma_parser/src/lexer/jsx.rs b/crates/swc_ecma_parser/src/lexer/jsx.rs index b53bd1479e56..aab1ae833d01 100644 --- a/crates/swc_ecma_parser/src/lexer/jsx.rs +++ b/crates/swc_ecma_parser/src/lexer/jsx.rs @@ -3,7 +3,7 @@ use swc_atoms::Atom; use super::*; -impl<'a, I: Input> Lexer<'a, I> { +impl<'a> Lexer<'a> { pub(super) fn read_jsx_token(&mut self) -> LexResult> { debug_assert!(self.syntax.jsx()); diff --git a/crates/swc_ecma_parser/src/lexer/mod.rs b/crates/swc_ecma_parser/src/lexer/mod.rs index 4d54641ec7bf..64afb59d1046 100644 --- a/crates/swc_ecma_parser/src/lexer/mod.rs +++ b/crates/swc_ecma_parser/src/lexer/mod.rs @@ -5,7 +5,7 @@ use std::{cell::RefCell, char, iter::FusedIterator, rc::Rc}; use either::Either::{Left, Right}; use smallvec::{smallvec, SmallVec}; use swc_atoms::{Atom, AtomGenerator}; -use swc_common::{comments::Comments, BytePos, Span}; +use swc_common::{comments::Comments, input::StringInput, BytePos, Span}; use swc_ecma_ast::{op, EsVersion}; use self::{comments_buffer::CommentsBuffer, state::State, util::*}; @@ -98,13 +98,13 @@ impl Iterator for CharIter { impl FusedIterator for CharIter {} #[derive(Clone)] -pub struct Lexer<'a, I: Input> { +pub struct Lexer<'a> { comments: Option<&'a dyn Comments>, /// [Some] if comment comment parsing is enabled. Otherwise [None] comments_buffer: Option, pub(crate) ctx: Context, - input: I, + input: StringInput<'a>, start_pos: BytePos, state: State, @@ -119,13 +119,13 @@ pub struct Lexer<'a, I: Input> { buf: Rc>, } -impl FusedIterator for Lexer<'_, I> {} +impl FusedIterator for Lexer<'_> {} -impl<'a, I: Input> Lexer<'a, I> { +impl<'a> Lexer<'a> { pub fn new( syntax: Syntax, target: EsVersion, - input: I, + input: StringInput<'a>, comments: Option<&'a dyn Comments>, ) -> Self { let start_pos = input.last_pos(); @@ -149,7 +149,7 @@ impl<'a, I: Input> Lexer<'a, I> { /// Utility method to reuse buffer. fn with_buf(&mut self, op: F) -> LexResult where - F: for<'any> FnOnce(&mut Lexer<'any, I>, &mut String) -> LexResult, + F: for<'any> FnOnce(&mut Lexer<'any>, &mut String) -> LexResult, { let b = self.buf.clone(); let mut buf = b.borrow_mut(); @@ -691,7 +691,7 @@ impl<'a, I: Input> Lexer<'a, I> { } } -impl<'a, I: Input> Lexer<'a, I> { +impl<'a> Lexer<'a> { #[inline(never)] fn read_slash(&mut self) -> LexResult> { debug_assert_eq!(self.cur(), Some('/')); diff --git a/crates/swc_ecma_parser/src/lexer/number.rs b/crates/swc_ecma_parser/src/lexer/number.rs index c999f73c1bee..bba333b03cfd 100644 --- a/crates/swc_ecma_parser/src/lexer/number.rs +++ b/crates/swc_ecma_parser/src/lexer/number.rs @@ -28,7 +28,7 @@ impl LazyBigInt { } } -impl<'a, I: Input> Lexer<'a, I> { +impl<'a> Lexer<'a> { /// Reads an integer, octal integer, or floating-point number pub(super) fn read_number( &mut self, @@ -531,12 +531,12 @@ impl<'a, I: Input> Lexer<'a, I> { mod tests { use std::{f64::INFINITY, panic}; - use super::{input::StringInput, *}; + use super::*; use crate::EsConfig; fn lex(s: &'static str, f: F) -> Ret where - F: FnOnce(&mut Lexer<'_, StringInput<'_>>) -> Ret, + F: FnOnce(&mut Lexer<'_>) -> Ret, { crate::with_test_sess(s, |_, input| { let mut l = Lexer::new( diff --git a/crates/swc_ecma_parser/src/lexer/state.rs b/crates/swc_ecma_parser/src/lexer/state.rs index 3f588eda7686..6ab4fd5c507c 100644 --- a/crates/swc_ecma_parser/src/lexer/state.rs +++ b/crates/swc_ecma_parser/src/lexer/state.rs @@ -120,7 +120,7 @@ impl<'a> From<&'a Token> for TokenType { } } -impl Tokens for Lexer<'_, I> { +impl Tokens for Lexer<'_> { #[inline] fn set_ctx(&mut self, ctx: Context) { if ctx.module && !self.module_errors.borrow().is_empty() { @@ -192,7 +192,7 @@ impl Tokens for Lexer<'_, I> { } } -impl<'a, I: Input> Iterator for Lexer<'a, I> { +impl<'a> Iterator for Lexer<'a> { type Item = TokenAndSpan; fn next(&mut self) -> Option { @@ -797,7 +797,7 @@ pub(crate) fn with_lexer( f: F, ) -> Result where - F: FnOnce(&mut Lexer<'_, crate::lexer::input::StringInput<'_>>) -> Result, + F: FnOnce(&mut Lexer<'_>) -> Result, { crate::with_test_sess(s, |_, fm| { let mut l = Lexer::new(syntax, target, fm, None); diff --git a/crates/swc_ecma_parser/src/lexer/util.rs b/crates/swc_ecma_parser/src/lexer/util.rs index f1c904627766..7241f15ac5fc 100644 --- a/crates/swc_ecma_parser/src/lexer/util.rs +++ b/crates/swc_ecma_parser/src/lexer/util.rs @@ -46,7 +46,7 @@ impl Raw { // pub const LINE_SEPARATOR: char = '\u{2028}'; // pub const PARAGRAPH_SEPARATOR: char = '\u{2029}'; -impl<'a, I: Input> Lexer<'a, I> { +impl<'a> Lexer<'a> { pub(super) fn span(&self, start: BytePos) -> Span { let end = self.last_pos(); if cfg!(debug_assertions) && start > end { diff --git a/crates/swc_ecma_parser/src/lib.rs b/crates/swc_ecma_parser/src/lib.rs index a26c1d0e255c..9d29d0a8147f 100644 --- a/crates/swc_ecma_parser/src/lib.rs +++ b/crates/swc_ecma_parser/src/lib.rs @@ -419,7 +419,7 @@ pub fn with_file_parser( target: EsVersion, comments: Option<&dyn Comments>, recovered_errors: &mut Vec, - op: impl for<'aa> FnOnce(&mut Parser>>) -> PResult, + op: impl for<'aa> FnOnce(&mut Parser) -> PResult, ) -> PResult { let lexer = Lexer::new(syntax, target, SourceFileInput::from(fm), comments); let mut p = Parser::new_from(lexer); diff --git a/crates/swc_ecma_parser/src/parser/mod.rs b/crates/swc_ecma_parser/src/parser/mod.rs index 4a697110c6dc..a0b4cdea0c9b 100644 --- a/crates/swc_ecma_parser/src/parser/mod.rs +++ b/crates/swc_ecma_parser/src/parser/mod.rs @@ -4,7 +4,7 @@ use std::ops::{Deref, DerefMut}; use swc_atoms::{Atom, JsWord}; -use swc_common::{collections::AHashMap, comments::Comments, input::Input, BytePos, Span}; +use swc_common::{collections::AHashMap, comments::Comments, input::StringInput, BytePos, Span}; use swc_ecma_ast::*; pub use self::input::{Capturing, Tokens, TokensInput}; @@ -58,8 +58,8 @@ struct State { trailing_commas: AHashMap, } -impl<'a, I: Input> Parser> { - pub fn new(syntax: Syntax, input: I, comments: Option<&'a dyn Comments>) -> Self { +impl<'a> Parser> { + pub fn new(syntax: Syntax, input: StringInput<'a>, comments: Option<&'a dyn Comments>) -> Self { Self::new_from(Lexer::new(syntax, Default::default(), input, comments)) } } @@ -250,7 +250,7 @@ impl Parser { #[cfg(test)] pub fn test_parser(s: &'static str, syntax: Syntax, f: F) -> Ret where - F: FnOnce(&mut Parser>>) -> Result, + F: FnOnce(&mut Parser) -> Result, { crate::with_test_sess(s, |handler, input| { let lexer = Lexer::new(syntax, EsVersion::Es2019, input, None); @@ -277,7 +277,7 @@ where #[cfg(test)] pub fn test_parser_comment(c: &dyn Comments, s: &'static str, syntax: Syntax, f: F) -> Ret where - F: FnOnce(&mut Parser>>) -> Result, + F: FnOnce(&mut Parser) -> Result, { crate::with_test_sess(s, |handler, input| { let lexer = Lexer::new(syntax, EsVersion::Es2019, input, Some(&c)); @@ -296,7 +296,7 @@ where #[cfg(test)] pub fn bench_parser(b: &mut Bencher, s: &'static str, syntax: Syntax, mut f: F) where - F: for<'a> FnMut(&'a mut Parser>>) -> PResult<()>, + F: for<'a> FnMut(&'a mut Parser>) -> PResult<()>, { b.bytes = s.len() as u64; diff --git a/crates/swc_ecma_parser/tests/errors.rs b/crates/swc_ecma_parser/tests/errors.rs index 052d736a04d1..8ec393141ac5 100644 --- a/crates/swc_ecma_parser/tests/errors.rs +++ b/crates/swc_ecma_parser/tests/errors.rs @@ -23,7 +23,7 @@ fn with_parser( f: F, ) -> Result where - F: FnOnce(&mut Parser>>) -> PResult, + F: FnOnce(&mut Parser) -> PResult, { let fm = cm .load_file(file_name) diff --git a/crates/swc_ecma_parser/tests/js.rs b/crates/swc_ecma_parser/tests/js.rs index 6bd767ecba95..74610a14ac67 100644 --- a/crates/swc_ecma_parser/tests/js.rs +++ b/crates/swc_ecma_parser/tests/js.rs @@ -8,7 +8,7 @@ use std::{ use swc_common::{comments::SingleThreadedComments, FileName}; use swc_ecma_ast::*; -use swc_ecma_parser::{lexer::Lexer, EsConfig, PResult, Parser, StringInput, Syntax}; +use swc_ecma_parser::{lexer::Lexer, EsConfig, PResult, Parser, Syntax}; use swc_ecma_visit::FoldWith; use testing::StdErr; @@ -76,7 +76,7 @@ fn with_parser( f: F, ) -> Result where - F: FnOnce(&mut Parser>>, &SingleThreadedComments) -> PResult, + F: FnOnce(&mut Parser, &SingleThreadedComments) -> PResult, { ::testing::run_test(treat_error_as_bug, |cm, handler| { if shift { diff --git a/crates/swc_ecma_parser/tests/jsx.rs b/crates/swc_ecma_parser/tests/jsx.rs index aadb1826fca2..5676742696da 100644 --- a/crates/swc_ecma_parser/tests/jsx.rs +++ b/crates/swc_ecma_parser/tests/jsx.rs @@ -6,7 +6,7 @@ use std::{ use pretty_assertions::assert_eq; use swc_common::{errors::Handler, sync::Lrc, SourceMap}; use swc_ecma_ast::*; -use swc_ecma_parser::{lexer::Lexer, PResult, Parser, StringInput}; +use swc_ecma_parser::{lexer::Lexer, PResult, Parser}; use swc_ecma_visit::{Fold, FoldWith}; use testing::{run_test, StdErr}; @@ -21,7 +21,7 @@ fn with_parser( f: F, ) -> Result where - F: FnOnce(&mut Parser>>) -> PResult, + F: FnOnce(&mut Parser) -> PResult, { let fm = cm .load_file(file_name) diff --git a/crates/swc_ecma_parser/tests/span.rs b/crates/swc_ecma_parser/tests/span.rs index ada4a2057fee..6e718f1be182 100644 --- a/crates/swc_ecma_parser/tests/span.rs +++ b/crates/swc_ecma_parser/tests/span.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use swc_common::{comments::SingleThreadedComments, errors::Handler, Spanned}; use swc_ecma_ast::*; -use swc_ecma_parser::{lexer::Lexer, EsConfig, Parser, StringInput, Syntax, TsConfig}; +use swc_ecma_parser::{lexer::Lexer, EsConfig, Parser, Syntax, TsConfig}; use swc_ecma_visit::{Visit, VisitWith}; #[testing::fixture("tests/span/**/*.js")] @@ -39,7 +39,7 @@ fn span(entry: PathBuf) { (&*src).into(), Some(&comments), ); - let mut parser: Parser> = Parser::new_from(lexer); + let mut parser: Parser = Parser::new_from(lexer); { let module = parser diff --git a/crates/swc_ecma_parser/tests/test262.rs b/crates/swc_ecma_parser/tests/test262.rs index a62b267a98fa..aa356ae6aa8c 100644 --- a/crates/swc_ecma_parser/tests/test262.rs +++ b/crates/swc_ecma_parser/tests/test262.rs @@ -11,7 +11,7 @@ use std::{ use common::Normalizer; use swc_ecma_ast::*; -use swc_ecma_parser::{lexer::Lexer, PResult, Parser, StringInput, Syntax}; +use swc_ecma_parser::{lexer::Lexer, PResult, Parser, Syntax}; use swc_ecma_visit::FoldWith; use test::{ test_main, DynTestFn, Options, ShouldPanic::No, TestDesc, TestDescAndFn, TestName, TestType, @@ -320,7 +320,7 @@ fn parse_module(file_name: &Path) -> Result { fn with_parser(file_name: &Path, f: F) -> Result where - F: FnOnce(&mut Parser>>) -> PResult, + F: FnOnce(&mut Parser) -> PResult, { ::testing::run_test(false, |cm, handler| { let fm = cm diff --git a/crates/swc_ecma_parser/tests/typescript.rs b/crates/swc_ecma_parser/tests/typescript.rs index 31e36e5249f2..e3ddae8beb2a 100644 --- a/crates/swc_ecma_parser/tests/typescript.rs +++ b/crates/swc_ecma_parser/tests/typescript.rs @@ -9,7 +9,7 @@ use std::{ use pretty_assertions::assert_eq; use swc_common::{comments::SingleThreadedComments, FileName}; use swc_ecma_ast::*; -use swc_ecma_parser::{lexer::Lexer, PResult, Parser, StringInput, Syntax, TsConfig}; +use swc_ecma_parser::{lexer::Lexer, PResult, Parser, Syntax, TsConfig}; use swc_ecma_visit::FoldWith; use testing::StdErr; @@ -221,7 +221,7 @@ fn with_parser( f: F, ) -> Result where - F: FnOnce(&mut Parser>>, &SingleThreadedComments) -> PResult, + F: FnOnce(&mut Parser, &SingleThreadedComments) -> PResult, { let fname = file_name.display().to_string(); diff --git a/crates/swc_ecma_quote_macros/src/ret_type.rs b/crates/swc_ecma_quote_macros/src/ret_type.rs index 3255f233f1e9..ad4b5ed3d7cd 100644 --- a/crates/swc_ecma_quote_macros/src/ret_type.rs +++ b/crates/swc_ecma_quote_macros/src/ret_type.rs @@ -50,7 +50,7 @@ pub(crate) fn parse_input_type(input_str: &str, ty: &Type) -> Result( input_str: &str, - op: &mut dyn FnMut(&mut Parser>) -> PResult, + op: &mut dyn FnMut(&mut Parser) -> PResult, ) -> Result where T: ToCode, diff --git a/crates/swc_ecma_transforms_base/src/tests.rs b/crates/swc_ecma_transforms_base/src/tests.rs index b03f316f1deb..1b7f6e68b83d 100644 --- a/crates/swc_ecma_transforms_base/src/tests.rs +++ b/crates/swc_ecma_transforms_base/src/tests.rs @@ -49,7 +49,7 @@ impl<'a> Tester<'a> { op: F, ) -> Result where - F: FnOnce(&mut Parser>) -> Result, + F: FnOnce(&mut Parser) -> Result, { let fm = self .cm diff --git a/crates/swc_ecma_transforms_base/tests/fixer_test262.rs b/crates/swc_ecma_transforms_base/tests/fixer_test262.rs index 6c3cb001f022..078d99f7c93c 100644 --- a/crates/swc_ecma_transforms_base/tests/fixer_test262.rs +++ b/crates/swc_ecma_transforms_base/tests/fixer_test262.rs @@ -11,7 +11,7 @@ use std::{ use swc_ecma_ast::*; use swc_ecma_codegen::{self, Emitter}; -use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax}; +use swc_ecma_parser::{lexer::Lexer, Parser, Syntax}; use swc_ecma_transforms_base::fixer::fixer; use swc_ecma_utils::DropSpan; use swc_ecma_visit::{Fold, FoldWith, VisitMutWith}; @@ -165,7 +165,7 @@ fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { let mut wr = Buf(Arc::new(RwLock::new(vec![]))); let mut wr2 = Buf(Arc::new(RwLock::new(vec![]))); - let mut parser: Parser> = + let mut parser: Parser = Parser::new(Syntax::default(), (&*src).into(), None); { @@ -197,7 +197,7 @@ fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { // Parse source - let mut e_parser: Parser> = + let mut e_parser: Parser = Parser::new(Syntax::default(), (&*expected).into(), None); if module { diff --git a/crates/swc_ecma_transforms_testing/src/lib.rs b/crates/swc_ecma_transforms_testing/src/lib.rs index b63aa6a52492..b53006c22bba 100644 --- a/crates/swc_ecma_transforms_testing/src/lib.rs +++ b/crates/swc_ecma_transforms_testing/src/lib.rs @@ -113,7 +113,7 @@ impl<'a> Tester<'a> { op: F, ) -> Result where - F: FnOnce(&mut Parser>) -> Result, + F: FnOnce(&mut Parser) -> Result, { let fm = self .cm diff --git a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs index 6841366b99b9..835f510ce8d3 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs @@ -7,7 +7,7 @@ use std::{ use swc_common::{FileName, Mark}; use swc_ecma_ast::*; use swc_ecma_codegen::{self, Emitter}; -use swc_ecma_parser::{lexer::Lexer, EsConfig, Parser, StringInput, Syntax, TsConfig}; +use swc_ecma_parser::{lexer::Lexer, EsConfig, Parser, Syntax, TsConfig}; use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene, resolver}; use swc_ecma_transforms_typescript::{strip, strip::strip_with_config}; use swc_ecma_visit::{Fold, FoldWith}; @@ -172,7 +172,7 @@ fn identity(entry: PathBuf) { let src = cm.load_file(&entry).expect("failed to load file"); println!("{}", src.src); - let mut parser: Parser> = Parser::new( + let mut parser: Parser = Parser::new( Syntax::Typescript(TsConfig { tsx: file_name.contains("tsx"), decorators: true, @@ -232,7 +232,7 @@ fn identity(entry: PathBuf) { let js_fm = cm.new_source_file(FileName::Anon, js_content.clone()); - let mut parser: Parser> = Parser::new( + let mut parser: Parser = Parser::new( Syntax::Es(EsConfig { jsx: file_name.contains("tsx"), decorators: true,