-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
oxc-parser.patch
136 lines (129 loc) · 4.7 KB
/
oxc-parser.patch
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
diff --git a/crates/oxc_parser/src/js/binding.rs b/crates/oxc_parser/src/js/binding.rs
index 450097676..1d52aa8db 100644
--- a/crates/oxc_parser/src/js/binding.rs
+++ b/crates/oxc_parser/src/js/binding.rs
@@ -8,7 +8,7 @@ impl<'a> ParserImpl<'a> {
/// `BindingElement`
/// `SingleNameBinding`
/// `BindingPattern`[?Yield, ?Await] `Initializer`[+In, ?Yield, ?Await]opt
- pub(super) fn parse_binding_pattern_with_initializer(&mut self) -> Result<BindingPattern<'a>> {
+ pub(crate) fn parse_binding_pattern_with_initializer(&mut self) -> Result<BindingPattern<'a>> {
let span = self.start_span();
let pattern = self.parse_binding_pattern(true)?;
self.context(Context::In, Context::empty(), |p| p.parse_initializer(span, pattern))
diff --git a/crates/oxc_parser/src/js/declaration.rs b/crates/oxc_parser/src/js/declaration.rs
index a7ab890d4..56315eb58 100644
--- a/crates/oxc_parser/src/js/declaration.rs
+++ b/crates/oxc_parser/src/js/declaration.rs
@@ -86,7 +86,7 @@ impl<'a> ParserImpl<'a> {
))
}
- fn parse_variable_declarator(
+ pub(crate) fn parse_variable_declarator(
&mut self,
decl_ctx: VariableDeclarationContext,
kind: VariableDeclarationKind,
diff --git a/crates/oxc_parser/src/js/mod.rs b/crates/oxc_parser/src/js/mod.rs
index 41133dab4..6b3a7e898 100644
--- a/crates/oxc_parser/src/js/mod.rs
+++ b/crates/oxc_parser/src/js/mod.rs
@@ -43,7 +43,7 @@ pub struct VariableDeclarationContext {
}
impl VariableDeclarationContext {
- pub(crate) fn new(parent: VariableDeclarationParent) -> Self {
+ pub fn new(parent: VariableDeclarationParent) -> Self {
Self { parent }
}
}
diff --git a/crates/oxc_parser/src/lib.rs b/crates/oxc_parser/src/lib.rs
index 531a38fa3..b2d97dc16 100644
--- a/crates/oxc_parser/src/lib.rs
+++ b/crates/oxc_parser/src/lib.rs
@@ -60,6 +60,8 @@
//! See [full linter example](https://github.com/Boshen/oxc/blob/ab2ef4f89ba3ca50c68abb2ca43e36b7793f3673/crates/oxc_linter/examples/linter.rs#L38-L39)
#![allow(clippy::wildcard_imports)] // allow for use `oxc_ast::ast::*`
+#![allow(rustdoc::bare_urls)]
+#![allow(clippy::doc_lazy_continuation)]
mod context;
mod cursor;
@@ -88,6 +90,7 @@ use oxc_ast::{
use oxc_diagnostics::{OxcDiagnostic, Result};
use oxc_span::{ModuleKind, SourceType, Span};
+pub use self::js::{VariableDeclarationContext, VariableDeclarationParent};
pub use crate::lexer::Kind; // re-export for codegen
use crate::{
lexer::{Lexer, Token},
@@ -179,6 +182,10 @@ impl<'a> Parser<'a> {
}
mod parser_parse {
+ use oxc_ast::ast::{
+ BindingPattern, IdentifierReference, VariableDeclarationKind, VariableDeclarator,
+ };
+
use super::*;
/// `UniquePromise` is a way to use the type system to enforce the invariant that only
@@ -247,6 +254,64 @@ mod parser_parse {
);
parser.parse_expression()
}
+
+ /// Parse `IdentifierReference`
+ ///
+ /// # Errors
+ ///
+ /// * Syntax Error
+ pub fn parse_identifier_reference(self) -> Result<IdentifierReference<'a>> {
+ let unique = UniquePromise::new();
+ let mut parser = ParserImpl::new(
+ self.allocator,
+ self.source_text,
+ self.source_type,
+ self.options,
+ unique,
+ );
+ parser.bump_any();
+ parser.parse_identifier_reference()
+ }
+
+ /// Parse `VariableDeclarator`
+ ///
+ /// # Errors
+ ///
+ /// * Syntax Error
+ pub fn parse_variable_declarator(
+ self,
+ decl_ctx: VariableDeclarationContext,
+ kind: VariableDeclarationKind,
+ ) -> Result<VariableDeclarator<'a>> {
+ let unique = UniquePromise::new();
+ let mut parser = ParserImpl::new(
+ self.allocator,
+ self.source_text,
+ self.source_type,
+ self.options,
+ unique,
+ );
+ parser.bump_any();
+ parser.parse_variable_declarator(decl_ctx, kind)
+ }
+
+ /// Parse `BindingPattern`
+ ///
+ /// # Errors
+ ///
+ /// * Syntax Error
+ pub fn parse_binding_pattern(self) -> Result<BindingPattern<'a>> {
+ let unique = UniquePromise::new();
+ let mut parser = ParserImpl::new(
+ self.allocator,
+ self.source_text,
+ self.source_type,
+ self.options,
+ unique,
+ );
+ parser.bump_any();
+ parser.parse_binding_pattern_with_initializer()
+ }
}
}
use parser_parse::UniquePromise;