Repository: swc-project/swc
File: crates/swc_ecma_parser/src/lexer/state.rs (Rust)

Code before:
                            self.input_slice_str(start, self.cur_pos())
                        };

                        let value = self.atom(s);
                        self.state.set_token_value(TokenValue::JsxText(value));
                        return Ok(Token::JSXText);
                    },
                };

                let s = unsafe {
                    // Safety: start and end are valid position because we got them from
                    // `self.input`
                    self.input_slice_str(start, self.cur_pos())
                };

                let value = self.atom(s);
                self.state.set_token_value(TokenValue::JsxText(value));
                Ok(Token::JSXText)
            }
            None => Ok(Token::Eof),
        }
    }

    #[cold]
    /// Slow path: we encountered `&` in the jsx child, so we need to scan and
    /// resolve the jsx entity, which requires a dedicate string allocation.
    fn scan_jsx_token_with_jsx_entity(&mut self) -> LexResult<Token> {
        let mut value = String::new();
        let mut chunk_start = self.input.cur_pos();

        while let Some(byte) = self.input.cur_as_char() {
            match byte {
                '>' => {
                    self.bump(1);
                    self.emit_error(
                        self.input().cur_pos(),
                        SyntaxError::UnexpectedTokenWithSuggestions {
                            candidate_list: vec!["`{'>'}`", "`&gt;`"],
                        },
                    );
                }
                '}' => {
                    self.bump(1);
                    self.emit_error(
                        self.input().cur_pos(),
                        SyntaxError::UnexpectedTokenWithSuggestions {
                            candidate_list: vec!["`{'}'}`", "`&rbrace;`"],
                        },
                    );
                }
                '&' => {

Review comment (suggestion):
The word "dedicate" should be "dedicated" to correctly describe the string allocation.
```suggestion
    /// resolve the jsx entity, which requires a dedicated string allocation.
```

Code after:
                            self.input_slice_str(start, self.cur_pos())
                        };

                        let value = self.atom(s);
                        self.state.set_token_value(TokenValue::JsxText(value));
                        return Ok(Token::JSXText);
                    },
                };

                let s = unsafe {
                    // Safety: start and end are valid position because we got them from
                    // `self.input`
                    self.input_slice_str(start, self.cur_pos())
                };

                let value = self.atom(s);
                self.state.set_token_value(TokenValue::JsxText(value));
                Ok(Token::JSXText)
            }
            None => Ok(Token::Eof),
        }
    }

    #[cold]
    /// Slow path: we encountered `&` in the jsx child, so we need to scan and
    /// resolve the jsx entity, which requires a dedicated string allocation.
    fn scan_jsx_token_with_jsx_entity(&mut self) -> LexResult<Token> {
        let mut value = String::new();
        let mut chunk_start = self.input.cur_pos();

        while let Some(ch) = self.input.cur_as_char() {
            match ch {
                '>' => {
                    let error_pos = self.input().cur_pos();
                    self.bump(1);
                    self.emit_error(
                        error_pos,
                        SyntaxError::UnexpectedTokenWithSuggestions {
                            candidate_list: vec!["`{'>'}`", "`&gt;`"],
                        },
                    );
                }
                '}' => {
                    let error_pos = self.input().cur_pos();
                    self.bump(1);
                    self.emit_error(
                        error_pos,
                        SyntaxError::UnexpectedTokenWithSuggestions {
                            candidate_list: vec!["`{'}'}`", "`&rbrace;`"],
                        },
                    );