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

Code before:
                                    // `import { type as as foo } from 'mod'`
                                    let local: Ident = self.parse_binding_ident(false)?.into();

                                    if type_only {
                                        self.emit_err(orig_name.span, SyntaxError::TS2206);
                                    }

                                    return Ok(ImportSpecifier::Named(ImportNamedSpecifier {
                                        span: Span::new_with_checked(start, orig_name.span.hi()),
                                        local,
                                        imported: Some(ModuleExportName::Ident(possibly_orig_name)),
                                        is_type_only: true,
                                    }));
                                } else {
                                    // `import { type as as } from 'mod'`
                                    return Ok(ImportSpecifier::Named(ImportNamedSpecifier {
                                        span: Span::new_with_checked(start, maybe_as.span.hi()),
                                        local: maybe_as,
                                        imported: Some(ModuleExportName::Ident(orig_name)),
                                        is_type_only: false,
                                    }));
                                }
                            } else {
                                // `import { type as xxx } from 'mod'`
                                return Ok(ImportSpecifier::Named(ImportNamedSpecifier {
                                    span: Span::new_with_checked(start, orig_name.span.hi()),
                                    local: maybe_as,
                                    imported: Some(ModuleExportName::Ident(orig_name)),
                                    is_type_only: false,
                                }));
                            }
                        } else {
                            // `import { type xx } from 'mod'`
                            // `import { type xx as yy } from 'mod'`
                            if type_only {
                                self.emit_err(orig_name.span, SyntaxError::TS2206);
                            }

                            orig_name = possibly_orig_name;
                            is_type_only = true;
                        }
                    }
                }

                if self.input_mut().eat(Token::As) {
                    let local: Ident = self.parse_binding_ident(false)?.into();
                    return Ok(ImportSpecifier::Named(ImportNamedSpecifier {
                        span: Span::new_with_checked(start, local.span.hi()),
                        local,
                        imported: Some(ModuleExportName::Ident(orig_name)),
                        is_type_only,

Review comment (suggestion):
The span calculation uses `orig_name.span.hi()` but should use `maybe_as.span.hi()` since `maybe_as` is the local identifier and represents the actual end of this import specifier. For the case `import { type as xxx }`, the span should end at `xxx` (which is `maybe_as`), not at the `type` keyword (which is `orig_name`).
```suggestion
                                    span: Span::new_with_checked(start, maybe_as.span.hi()),
```

Code after:
                                    // `import { type as as foo } from 'mod'`
                                    let local: Ident = self.parse_binding_ident(false)?.into();

                                    if type_only {
                                        self.emit_err(orig_name.span, SyntaxError::TS2206);
                                    }

                                    return Ok(ImportSpecifier::Named(ImportNamedSpecifier {
                                        span: Span::new_with_checked(start, local.span.hi()),
                                        local,
                                        imported: Some(ModuleExportName::Ident(possibly_orig_name)),
                                        is_type_only: true,
                                    }));
                                } else {
                                    // `import { type as as } from 'mod'`
                                    return Ok(ImportSpecifier::Named(ImportNamedSpecifier {
                                        span: Span::new_with_checked(start, maybe_as.span.hi()),
                                        local: maybe_as,
                                        imported: Some(ModuleExportName::Ident(orig_name)),
                                        is_type_only: false,
                                    }));
                                }
                            } else {
                                // `import { type as xxx } from 'mod'`
                                return Ok(ImportSpecifier::Named(ImportNamedSpecifier {
                                    span: Span::new_with_checked(start, maybe_as.span.hi()),
                                    local: maybe_as,
                                    imported: Some(ModuleExportName::Ident(orig_name)),
                                    is_type_only: false,
                                }));
                            }
                        } else {
                            // `import { type xx } from 'mod'`
                            // `import { type xx as yy } from 'mod'`
                            if type_only {
                                self.emit_err(orig_name.span, SyntaxError::TS2206);
                            }

                            orig_name = possibly_orig_name;
                            is_type_only = true;
                        }
                    }
                }

                if self.input_mut().eat(Token::As) {
                    let local: Ident = self.parse_binding_ident(false)?.into();
                    return Ok(ImportSpecifier::Named(ImportNamedSpecifier {
                        span: Span::new_with_checked(start, local.span.hi()),
                        local,
                        imported: Some(ModuleExportName::Ident(orig_name)),
                        is_type_only,