Repository: swc-project/swc
File: crates/swc_ecma_parser/src/parser/typescript.rs (Rust)

Code before:

            let cur = p.input().cur();
            if matches!(cur, Token::Const | Token::Var | Token::Let) {
                return p
                    .parse_var_stmt(false)
                    .map(|decl| VarDecl {
                        declare: true,
                        span: Span {
                            lo: declare_start,
                            ..decl.span
                        },
                        ..*decl
                    })
                    .map(Box::new)
                    .map(From::from)
                    .map(Some);
            }

            if p.input().is(Token::Global) {
                return p
                    .parse_ts_ambient_external_module_decl(start)
                    .map(Decl::from)
                    .map(make_decl_declare)
                    .map(Some);
            } else if p.input().cur().is_word() {
                let value = p.input_mut().cur().take_word(&p.input);
                return p
                    .parse_ts_decl(start, decorators, value, /* next */ true)
                    .map(|v| v.map(make_decl_declare));
            }

            Ok(None)
        })
    }

    /// `tsTryParseExportDeclaration`
    ///
    /// Note: this won't be called unless the keyword is allowed in
    /// `shouldParseExportDeclaration`.
    pub(crate) fn try_parse_ts_export_decl(
        &mut self,
        decorators: Vec<Decorator>,
        value: Atom,
    ) -> Option<Decl> {
        if !cfg!(feature = "typescript") {
            return None;
        }

        self.try_parse_ts(|p| {
            let start = p.cur_pos();
            let opt = p.parse_ts_decl(start, decorators, value, true)?;

Review comment (suggestion):
The call to `input_mut()` is unnecessary here since `take_word()` now accepts an immutable reference. Consider using `p.input().cur().take_word(&p.input)` for consistency and to avoid unnecessary mutable borrowing.
```suggestion
                let value = p.input().cur().take_word(&p.input);
```

Code after:

            let cur = p.input().cur();
            if matches!(cur, Token::Const | Token::Var | Token::Let) {
                return p
                    .parse_var_stmt(false)
                    .map(|decl| VarDecl {
                        declare: true,
                        span: Span {
                            lo: declare_start,
                            ..decl.span
                        },
                        ..*decl
                    })
                    .map(Box::new)
                    .map(From::from)
                    .map(Some);
            }

            if p.input().is(Token::Global) {
                return p
                    .parse_ts_ambient_external_module_decl(start)
                    .map(Decl::from)
                    .map(make_decl_declare)
                    .map(Some);
            } else if p.input().cur().is_word() {
                let value = p.input().cur().take_word(&p.input);
                return p
                    .parse_ts_decl(start, decorators, value, /* next */ true)
                    .map(|v| v.map(make_decl_declare));
            }

            Ok(None)
        })
    }

    /// `tsTryParseExportDeclaration`
    ///
    /// Note: this won't be called unless the keyword is allowed in
    /// `shouldParseExportDeclaration`.
    pub(crate) fn try_parse_ts_export_decl(
        &mut self,
        decorators: Vec<Decorator>,
        value: Atom,
    ) -> Option<Decl> {
        if !cfg!(feature = "typescript") {
            return None;
        }

        self.try_parse_ts(|p| {
            let start = p.cur_pos();
            let opt = p.parse_ts_decl(start, decorators, value, true)?;