Skip to content

Commit d856923

Browse files
committed
Fix swc_ts_fast_strip
1 parent 97fdd12 commit d856923

File tree

6 files changed

+20
-26
lines changed

6 files changed

+20
-26
lines changed

Cargo.lock

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

crates/swc_ecma_parser/src/lexer/token.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl std::fmt::Debug for Token {
493493
}
494494

495495
impl Token {
496-
pub(crate) fn is_reserved(&self, ctx: Context) -> bool {
496+
pub fn is_reserved(&self, ctx: Context) -> bool {
497497
match self {
498498
Token::Let | Token::Static => ctx.contains(Context::Strict),
499499
Token::Await => {
@@ -558,7 +558,7 @@ impl Token {
558558
}
559559

560560
#[cold]
561-
pub(crate) fn to_string(self, value: Option<&TokenValue>) -> String {
561+
pub fn to_string(self, value: Option<&TokenValue>) -> String {
562562
match self {
563563
Token::LParen => "(",
564564
Token::RParen => ")",
@@ -778,7 +778,7 @@ impl Token {
778778
.to_string()
779779
}
780780

781-
pub(crate) fn as_keyword_atom(self) -> Option<Atom> {
781+
pub fn as_keyword_atom(self) -> Option<Atom> {
782782
let atom = match self {
783783
Token::Await => atom!("await"),
784784
Token::Break => atom!("break"),
@@ -821,12 +821,12 @@ impl Token {
821821
Some(atom)
822822
}
823823

824-
pub(crate) const fn is_keyword(self) -> bool {
824+
pub const fn is_keyword(self) -> bool {
825825
let t = self as u8;
826826
t >= Token::Await as u8 && t <= Token::Module as u8
827827
}
828828

829-
pub(crate) fn as_known_ident_atom(self) -> Option<Atom> {
829+
pub fn as_known_ident_atom(self) -> Option<Atom> {
830830
let atom = match self {
831831
Token::Abstract => atom!("abstract"),
832832
Token::Any => atom!("any"),
@@ -880,20 +880,20 @@ impl Token {
880880
}
881881

882882
#[inline(always)]
883-
pub(crate) const fn is_known_ident(self) -> bool {
883+
pub const fn is_known_ident(self) -> bool {
884884
let t = self as u8;
885885
t >= Token::Abstract as u8 && t <= Token::Target as u8
886886
}
887887

888-
pub(crate) const fn is_word(self) -> bool {
888+
pub const fn is_word(self) -> bool {
889889
matches!(
890890
self,
891891
Token::Null | Token::True | Token::False | Token::Ident
892892
) || self.is_known_ident()
893893
|| self.is_keyword()
894894
}
895895

896-
pub(crate) fn as_word_atom(self, value: Option<&TokenValue>) -> Option<Atom> {
896+
pub fn as_word_atom(self, value: Option<&TokenValue>) -> Option<Atom> {
897897
match self {
898898
Token::Null => Some(atom!("null")),
899899
Token::True => Some(atom!("true")),
@@ -911,13 +911,13 @@ impl Token {
911911
}
912912

913913
#[inline(always)]
914-
pub(crate) const fn is_bin_op(self) -> bool {
914+
pub const fn is_bin_op(self) -> bool {
915915
let t = self as u8;
916916
(t >= Token::EqEq as u8 && t <= Token::NullishCoalescing as u8)
917917
|| (t >= Token::Plus as u8 && t <= Token::Ampersand as u8)
918918
}
919919

920-
pub(crate) fn as_bin_op(self) -> Option<swc_ecma_ast::BinaryOp> {
920+
pub fn as_bin_op(self) -> Option<swc_ecma_ast::BinaryOp> {
921921
match self {
922922
Token::EqEq => Some(swc_ecma_ast::BinaryOp::EqEq),
923923
Token::NotEq => Some(swc_ecma_ast::BinaryOp::NotEq),
@@ -949,12 +949,12 @@ impl Token {
949949
}
950950

951951
#[inline(always)]
952-
pub(crate) const fn is_assign_op(self) -> bool {
952+
pub const fn is_assign_op(self) -> bool {
953953
let t = self as u8;
954954
matches!(self, Token::Eq) || (t >= Token::PlusEq as u8 && t <= Token::NullishEq as u8)
955955
}
956956

957-
pub(crate) fn as_assign_op(self) -> Option<swc_ecma_ast::AssignOp> {
957+
pub fn as_assign_op(self) -> Option<swc_ecma_ast::AssignOp> {
958958
match self {
959959
Self::Eq => Some(AssignOp::Assign),
960960
Self::PlusEq => Some(AssignOp::AddAssign),
@@ -977,7 +977,7 @@ impl Token {
977977
}
978978

979979
#[inline(always)]
980-
pub(crate) const fn before_expr(self) -> bool {
980+
pub const fn before_expr(self) -> bool {
981981
match self {
982982
Self::Await
983983
| Self::Case
@@ -1014,7 +1014,7 @@ impl Token {
10141014
}
10151015

10161016
#[inline(always)]
1017-
pub(crate) const fn starts_expr(self) -> bool {
1017+
pub const fn starts_expr(self) -> bool {
10181018
matches!(
10191019
self,
10201020
Self::Ident
@@ -1055,7 +1055,7 @@ impl Token {
10551055
) || self.is_known_ident()
10561056
}
10571057

1058-
pub(crate) fn follows_keyword_let(self) -> bool {
1058+
pub fn follows_keyword_let(self) -> bool {
10591059
match self {
10601060
Token::Let
10611061
| Token::LBrace
@@ -1068,7 +1068,7 @@ impl Token {
10681068
}
10691069
}
10701070

1071-
pub(crate) fn should_rescan_into_gt_in_jsx(self) -> bool {
1071+
pub fn should_rescan_into_gt_in_jsx(self) -> bool {
10721072
matches!(
10731073
self,
10741074
Token::GtEq

crates/swc_ecma_parser/src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ impl<I: Tokens> Parser<I> {
7171
// type TokenAndSpan = TokenAndSpan;
7272

7373
#[inline(always)]
74-
fn input(&self) -> &Buffer<I> {
74+
pub fn input(&self) -> &Buffer<I> {
7575
&self.input
7676
}
7777

7878
#[inline(always)]
79-
fn input_mut(&mut self) -> &mut Buffer<I> {
79+
pub fn input_mut(&mut self) -> &mut Buffer<I> {
8080
&mut self.input
8181
}
8282

crates/swc_ecma_parser/src/parser/util.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ impl ExprExt for Expr {
141141

142142
pub trait IsDirective {
143143
fn as_ref(&self) -> Option<&Stmt>;
144-
fn is_use_strict(&self) -> bool {
145-
self.as_ref().is_some_and(Stmt::is_use_strict)
146-
}
147144
}
148145

149146
impl<T> IsDirective for Box<T>

crates/swc_ts_fast_strip/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ swc_common = { version = "14.0.4", path = "../swc_common", features = [
2626
] }
2727
swc_ecma_ast = { version = "15.0.0", path = "../swc_ecma_ast" }
2828
swc_ecma_codegen = { version = "17.0.2", path = "../swc_ecma_codegen" }
29-
swc_ecma_lexer = { version = "23.0.2", path = "../swc_ecma_lexer" }
3029
swc_ecma_parser = { version = "24.0.3", path = "../swc_ecma_parser", default-features = false, features = [
3130
"typescript",
3231
"unstable",

crates/swc_ts_fast_strip/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ use swc_ecma_ast::{
2121
TsSatisfiesExpr, TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, TsTypeParamDecl,
2222
TsTypeParamInstantiation, VarDeclarator, WhileStmt, YieldExpr,
2323
};
24-
use swc_ecma_lexer::common::parser::{buffer::Buffer, Parser as _};
2524
use swc_ecma_parser::{
2625
lexer::Lexer,
27-
unstable::{Capturing, Token, TokenAndSpan, TokenFactory},
26+
unstable::{Capturing, Token, TokenAndSpan},
2827
Parser, StringInput, Syntax, TsSyntax,
2928
};
3029
use swc_ecma_transforms_base::{
@@ -732,7 +731,7 @@ impl TsStrip {
732731

733732
// see ts_next_token_can_follow_modifier
734733
// class { public public() {} }
735-
if !<Token as TokenFactory<'_, TokenAndSpan, Capturing<Lexer>>>::is_word(&next.token)
734+
if !next.token.is_word()
736735
&& !matches!(
737736
next.token,
738737
Token::LBracket

0 commit comments

Comments
 (0)