swc_ecma_fast_parser/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! High-performance ECMAScript/TypeScript parser
//!
//! This parser is designed for maximum performance and memory efficiency,
//! operating at the byte level for optimal throughput.

#![cfg_attr(feature = "nightly", allow(internal_features))]
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]

mod error;
mod lexer;
mod parser;
pub mod token;
mod util;

pub use error::{Error, ErrorKind, Result};
pub use lexer::Lexer;
pub use parser::Parser;

/// Target ECMAScript version
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum JscTarget {
    Es3,
    Es5,
    Es2015,
    Es2016,
    Es2017,
    Es2018,
    Es2019,
    Es2020,
    Es2021,
    Es2022,
    EsNext,
}

/// Syntax configuration for the parser
#[derive(Debug, Clone, Copy)]
pub struct Syntax {
    /// Enable parsing of JSX syntax
    pub jsx: bool,

    /// Enable parsing of TypeScript syntax
    pub typescript: bool,

    /// Enable parsing of decorators
    pub decorators: bool,

    /// Enable parsing of dynamic imports
    pub dynamic_import: bool,

    /// Enable parsing of private methods
    pub private_methods: bool,

    /// Enable parsing of private fields
    pub private_fields: bool,
}

impl Default for Syntax {
    fn default() -> Self {
        Self {
            jsx: false,
            typescript: false,
            decorators: false,
            dynamic_import: true,
            private_methods: true,
            private_fields: true,
        }
    }
}

/// Single-threaded source comments storage
#[derive(Debug, Default, Clone)]
pub struct SingleThreadedComments {
    // Comments implementation omitted for brevity
}