Skip to content

Commit 6492786

Browse files
authored
refactor(es/parser): Extract parse_jsx_attrs (#10569)
1 parent 16e204d commit 6492786

File tree

1 file changed

+22
-13
lines changed
  • crates/swc_ecma_lexer/src/common/parser

1 file changed

+22
-13
lines changed

crates/swc_ecma_lexer/src/common/parser/jsx.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,27 @@ fn parse_jsx_opening_element_at<'a, P: Parser<'a>>(
242242
parse_jsx_opening_element_after_name(p, start, name).map(Either::Right)
243243
}
244244

245+
#[inline(always)]
246+
fn parse_jsx_attrs<'a, P: Parser<'a>>(p: &mut P) -> PResult<Vec<JSXAttrOrSpread>> {
247+
let mut attrs = Vec::with_capacity(8);
248+
249+
while cur!(p, false).is_ok() {
250+
trace_cur!(p, parse_jsx_opening__attrs_loop);
251+
252+
if p.input_mut()
253+
.cur()
254+
.is_some_and(|cur| cur.is_slash() || cur.is_jsx_tag_end())
255+
{
256+
break;
257+
}
258+
259+
let attr = parse_jsx_attr(p)?;
260+
attrs.push(attr);
261+
}
262+
263+
Ok(attrs)
264+
}
265+
245266
/// `jsxParseOpeningElementAfterName`
246267
fn parse_jsx_opening_element_after_name<'a, P: Parser<'a>>(
247268
p: &mut P,
@@ -256,20 +277,8 @@ fn parse_jsx_opening_element_after_name<'a, P: Parser<'a>>(
256277
None
257278
};
258279

259-
let mut attrs = Vec::new();
260-
while cur!(p, false).is_ok() {
261-
trace_cur!(p, parse_jsx_opening__attrs_loop);
262-
263-
if p.input_mut()
264-
.cur()
265-
.is_some_and(|cur| cur.is_slash() || cur.is_jsx_tag_end())
266-
{
267-
break;
268-
}
280+
let attrs = parse_jsx_attrs(p)?;
269281

270-
let attr = parse_jsx_attr(p)?;
271-
attrs.push(attr);
272-
}
273282
let self_closing = p.input_mut().eat(&P::Token::DIV);
274283
if !p.input_mut().eat(&P::Token::JSX_TAG_END)
275284
& !(p.ctx().contains(Context::InForcedJsxContext) && p.input_mut().eat(&P::Token::GREATER))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy