Skip to content

Commit 3226c14

Browse files
committed
refactor(estree/tokens): shorten code
1 parent 28983f9 commit 3226c14

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

crates/oxc_estree_tokens/src/raw_transfer.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ impl<O: ESTreeTokenConfig> RawContext<'_, O> {
8080
unreachable!("Expected token at position {start}");
8181
}
8282

83+
/// Advance to the token at `start` and set its `Kind`.
84+
fn set_kind_at(&mut self, start: u32, kind: Kind) {
85+
let token = self.advance_to(start);
86+
token.set_kind(kind);
87+
}
88+
8389
/// Convert remaining token spans from UTF-8 byte offsets to UTF-16 offsets.
8490
fn finish(self) {
8591
if let Some(mut converter) = self.span_converter {
@@ -137,14 +143,12 @@ impl<O: ESTreeTokenConfig> Context for RawContext<'_, O> {
137143

138144
/// Set `Kind` of the token at `start` to `Identifier`.
139145
fn emit_this_identifier_at(&mut self, start: u32) {
140-
let token = self.advance_to(start);
141-
token.set_kind(Kind::Ident);
146+
self.set_kind_at(start, Kind::Ident);
142147
}
143148

144149
/// Set `Kind` of the token at `start` to `JSXIdentifier`.
145150
fn emit_jsx_identifier_at(&mut self, start: u32, _name: &str) {
146-
let token = self.advance_to(start);
147-
token.set_kind(Kind::JSXIdentifier);
151+
self.set_kind_at(start, Kind::JSXIdentifier);
148152
}
149153

150154
/// Handle `PrivateIdentifier` token (no-op).
@@ -163,8 +167,7 @@ impl<O: ESTreeTokenConfig> Context for RawContext<'_, O> {
163167

164168
/// Set `Kind` of the `StringLiteral` token to `JSXText`.
165169
fn emit_string_literal_as_jsx_text(&mut self, literal: &StringLiteral<'_>) {
166-
let token = self.advance_to(literal.span.start);
167-
token.set_kind(Kind::JSXText);
170+
self.set_kind_at(literal.span.start, Kind::JSXText);
168171
}
169172

170173
/// Handle `JSXText` token (no-op).

0 commit comments

Comments
 (0)