Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
cddd138
Remove dep of swc_ecma_lexer
CPunisher Oct 11, 2025
810e183
Fix token.rs
CPunisher Oct 11, 2025
41d9535
Fix syntax.rs
CPunisher Oct 11, 2025
2736749
Fix lexer/mod.rs
CPunisher Oct 11, 2025
d750526
Fix lexer/comments_buffer.rs
CPunisher Oct 11, 2025
9ea06e9
Fix lexer/table.rs
CPunisher Oct 11, 2025
a5257d7
Fix lexer/state.rs
CPunisher Oct 11, 2025
1747ef8
Fix parser/mod.rs
CPunisher Oct 11, 2025
fa3c14d
Fix parser/tpl.rs
CPunisher Oct 11, 2025
ef278bd
Fix lexer/input.rs
CPunisher Oct 11, 2025
d0196f7
Fix lexer/state.rs
CPunisher Oct 11, 2025
e70a74c
Fix lexer/capturing.rs
CPunisher Oct 11, 2025
72287a1
Fix lexer/token.rs
CPunisher Oct 11, 2025
325b2f3
Fix lexer/input.rs
CPunisher Oct 11, 2025
998c38b
Fix parser/state.rs
CPunisher Oct 11, 2025
1318f2a
Fix parser/typescript.rs
CPunisher Oct 11, 2025
101b363
Fix parser/input.rs and parser/token.rs
CPunisher Oct 13, 2025
dcc7dd1
Fix lexer/*.rs
CPunisher Oct 13, 2025
f84a6c2
Fix some parser/*.rs
CPunisher Oct 14, 2025
bdcb908
Fix parser/stmt.rs
CPunisher Oct 16, 2025
1c0233c
Fix parser/*.rs
CPunisher Oct 16, 2025
cb3c019
Fix parser/module_item.rs
CPunisher Oct 16, 2025
aff231d
Fix parser/stmt_like_parser.rs
CPunisher Oct 16, 2025
35a58f9
Fix parser/class_and_fn.rs
CPunisher Oct 17, 2025
4917bbe
Fix parser/typescript.rs
CPunisher Oct 17, 2025
2a447d0
Fix parser/expr.rs
CPunisher Oct 18, 2025
a9f45db
Fix parser/jsx.rs
CPunisher Oct 18, 2025
3f19e2b
Post fix all
CPunisher Oct 18, 2025
1065f9e
Fix parse_tpl_elements
CPunisher Oct 18, 2025
1c13c6b
Fix parse_tagged_tpl
CPunisher Oct 18, 2025
403b2a7
Fix stacker
CPunisher Oct 18, 2025
5ea8257
Remove Token::is_*
CPunisher Oct 18, 2025
f3cacb1
Gather util files
CPunisher Oct 18, 2025
ed22878
Restrict access modifiers of parser functions
CPunisher Oct 18, 2025
e11fd87
Fix swc_ts_fast_strip
CPunisher Oct 18, 2025
ce9c1e6
Align post_span and fixed_len_span
CPunisher Oct 19, 2025
e9e5365
Move lexer bench
CPunisher Oct 19, 2025
3b5d108
DEBUG: exchange cond in eat_general_semi
CPunisher Oct 19, 2025
9913212
Remove token ref
CPunisher Oct 19, 2025
ded07d1
Remove TokenAndSpan ref
CPunisher Oct 19, 2025
fbe7f45
Inline parse_primary_expr
CPunisher Oct 19, 2025
b1bae66
Inline parse_stmt_like
CPunisher Oct 19, 2025
9b09167
Introduce fast_slice to avoid unnecessary memory write
CPunisher Oct 21, 2025
57d62fd
Rename to slice_to_cur
CPunisher Oct 21, 2025
0a7aec3
Remove some #inline(never)
CPunisher Oct 21, 2025
486099b
Advance opt: opt parse_subscript
CPunisher Oct 21, 2025
d99c994
Fix cargo shear
CPunisher Oct 21, 2025
562f279
Fix swc_ast_unknown
CPunisher Oct 21, 2025
965b4d3
Inline read_number_no_dot_as_str
CPunisher Oct 21, 2025
f8c3bbb
Revert "Inline read_number_no_dot_as_str"
CPunisher Oct 21, 2025
b6a5ceb
More input_slice_to_cur
CPunisher Oct 21, 2025
80af665
Inline token check methods
CPunisher Oct 21, 2025
6b37c00
Inline generic read_token_mul_mod
CPunisher Oct 21, 2025
0b8850c
Advance opt parse_subscripts: detach Callee::Import
CPunisher Oct 22, 2025
79987d2
Advance opt parse_subscripts: detach Callee::Super
CPunisher Oct 22, 2025
50f0f47
Fix swc_ast_unknown
CPunisher Oct 22, 2025
10de1b5
Rename parse_subscript param name
CPunisher Oct 22, 2025
90bcd44
Remove useless IsDirective
CPunisher Oct 22, 2025
ff0527c
Modified swc_ecma_lexer for compatibility
CPunisher Oct 22, 2025
8ed6253
Update docs
CPunisher Oct 22, 2025
1180637
Move color.js
CPunisher Oct 22, 2025
4ca6c9b
Cargo shear
CPunisher Oct 22, 2025
034d6ad
Rebase wtf8
CPunisher Oct 27, 2025
49c5006
Rebase Lit
CPunisher Oct 27, 2025
e2cbe9b
Rebase Wtf8 2
CPunisher Oct 27, 2025
53be991
Rebase #11164
CPunisher Oct 27, 2025
fc2e4e5
Rebase #11163
CPunisher Oct 27, 2025
3d99a0e
Fix legacy
CPunisher Oct 27, 2025
1c3d18e
Enable bench
CPunisher Oct 27, 2025
a19c696
Fix binding_es_ast_viewer
CPunisher Oct 27, 2025
d92fc7f
Create funny-dragons-promise.md
kdy1 Oct 27, 2025
816ca9c
Remove useless comments
CPunisher Oct 27, 2025
3d13362
Merge branch '10-11-refactor/parser' of github.com:CPunisher/swc into…
CPunisher Oct 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/funny-dragons-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
swc_common: patch
swc_ecma_lexer: major
swc_ecma_parser: major
---

refactor(es/parser): detach `swc_ecma_parser` from `swc_emca_lexer`
12 changes: 7 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions bindings/binding_es_ast_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use swc_core::{
common::{errors::ColorConfig, FileName, Globals, Mark, SourceMap, GLOBALS},
ecma::{
ast::*,
parser::{
unstable::{Buffer, Capturing, ParserTrait},
EsSyntax, Lexer, Parser, StringInput, Syntax, TsSyntax,
},
parser::{unstable::Capturing, EsSyntax, Lexer, Parser, StringInput, Syntax, TsSyntax},
transforms::base::resolver,
visit::VisitMutWith,
},
Expand Down
29 changes: 29 additions & 0 deletions crates/swc_common/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ impl<'a> StringInput<'a> {
self.iter.as_str()
}

#[inline(always)]
/// Compared to [StringInput::slice], this function doesn't set
/// `self.last_pos = end` because in most cases this property has been
/// satisfied but the compiler cannot optimize it.
///
/// Caution: This function should only be used internally and will be
/// changed in the future.
///
/// # Safety
/// - start should be less than or equal to end.
/// - start and end should be in the valid range of input.
pub unsafe fn slice_to_cur(&mut self, start: BytePos) -> &'a str {
let end = self.last_pos;

debug_assert!(start <= end, "Cannot slice {start:?}..{end:?}");
let s = self.orig;

let start_idx = (start - self.orig_start).0 as usize;
let end_idx = (end - self.orig_start).0 as usize;

debug_assert!(end_idx <= s.len());

let ret = unsafe { s.get_unchecked(start_idx..end_idx) };

self.iter = unsafe { s.get_unchecked(end_idx..) }.chars();

ret
}

#[inline]
pub fn bump_bytes(&mut self, n: usize) {
unsafe {
Expand Down
16 changes: 5 additions & 11 deletions crates/swc_ecma_lexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,29 @@ verify = ["swc_ecma_visit"]
bitflags = { workspace = true }
either = { workspace = true }
num-bigint = { workspace = true }
phf = { workspace = true, features = ["macros"] }
rustc-hash = { workspace = true }
seq-macro = { workspace = true }
serde = { workspace = true, features = ["derive"] }
smallvec = { workspace = true }
smartstring = { workspace = true }
tracing = { workspace = true }

swc_atoms = { version = "7.0.0", path = "../swc_atoms" }
swc_common = { version = "15.0.0", path = "../swc_common" }
swc_ecma_ast = { version = "16.0.0", path = "../swc_ecma_ast" }
swc_ecma_visit = { version = "16.0.0", path = "../swc_ecma_visit", optional = true }
swc_atoms = { version = "7.0.0", path = "../swc_atoms" }
swc_common = { version = "15.0.0", path = "../swc_common" }
swc_ecma_ast = { version = "16.0.0", path = "../swc_ecma_ast" }
swc_ecma_parser = { version = "25.0.0", path = "../swc_ecma_parser" }
swc_ecma_visit = { version = "16.0.0", path = "../swc_ecma_visit", optional = true }

[target.'cfg(not(any(target_arch = "wasm32", target_arch = "arm")))'.dependencies]
stacker = { version = "0.1.15", optional = true }

[dev-dependencies]

codspeed-criterion-compat = { workspace = true }
swc_ecma_ast = { version = "16.0.0", path = "../swc_ecma_ast", features = [
"serde-impl",
] }
swc_ecma_visit = { version = "16.0.0", path = "../swc_ecma_visit" }
swc_malloc = { version = "1.2.4", path = "../swc_malloc" }
testing = { version = "16.0.0", path = "../testing" }

[[example]]
name = "lexer"

[[bench]]
harness = false
name = "lexer"
5 changes: 5 additions & 0 deletions crates/swc_ecma_lexer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# swc_ecma_lexer

This crate is no longer maintained and kept just for compatibility. Please use [swc_ecma_parser](https://github.com/swc-project/swc/tree/main/crates/swc_ecma_parser) instead, which provides higher performance.

See more details in https://github.com/swc-project/swc/pull/11148.
2 changes: 1 addition & 1 deletion crates/swc_ecma_lexer/src/common/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl From<UnicodeEscape> for CodePoint {
}
}

pub type LexResult<T> = Result<T, crate::error::Error>;
pub type LexResult<T> = swc_ecma_parser::lexer::LexResult<T>;

fn remove_underscore(s: &str, has_underscore: bool) -> Cow<'_, str> {
if has_underscore {
Expand Down
Loading
Loading