Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/gentle-gorillas-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: minor
swc_ecma_parser: minor
---

feat(es/parser): expose Token API with unstable feature flag
1 change: 1 addition & 0 deletions crates/swc_ecma_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ debug = ["tracing-spans"]
default = ["typescript", "stacker"]
tracing-spans = []
typescript = []
unstable = []
verify = ["swc_ecma_visit", "swc_ecma_lexer/verify"]

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{

mod state;
mod table;
mod token;
pub(crate) mod token;

pub(crate) use token::{NextTokenAndSpan, Token, TokenAndSpan, TokenValue};

Expand Down
28 changes: 23 additions & 5 deletions crates/swc_ecma_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,33 @@
#![allow(clippy::wrong_self_convention)]
#![allow(clippy::match_like_matches_macro)]

#[cfg(feature = "unstable")]
pub mod unstable {
//! This module expose tokens related to the `swc_ecma_parser::lexer`.
//!
//! Unlike the tokens re-exported from `swc_ecma_lexer`, the token kinds
//! defined in the `swc_ecma_parser` here are non-strict for higher
//! performance.
//!
//! Although it's marked as unstable, we can ensure that we will not
//! introduce too many breaking changes. And we also encourage the
//! applications to migrate to the lexer and tokens in the respect to
//! the performance.
//!
//! Also see the dicussion https://github.com/swc-project/swc/discussions/10683
pub use swc_ecma_lexer::common::lexer::token::TokenFactory;

pub use crate::lexer::token::{NextTokenAndSpan, Token, TokenAndSpan, TokenValue};
}

pub mod lexer;
mod parser;

pub use lexer::Lexer;
pub use swc_common::input::{Input, StringInput};
use swc_common::{comments::Comments, input::SourceFileInput, SourceFile};
use swc_ecma_ast::*;
use swc_ecma_lexer::{common::parser::Parser as ParserTrait, error::Error};
pub mod lexer;

pub use lexer::Lexer;
pub use swc_ecma_lexer::{
common::{
context::Context,
Expand All @@ -142,8 +162,6 @@ pub use swc_ecma_lexer::{

pub use self::parser::*;

mod parser;

#[cfg(test)]
fn with_test_sess<F, Ret>(src: &str, f: F) -> Result<Ret, ::testing::StdErr>
where
Expand Down
Loading