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

Code before:

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

                                return Ok(ImportSpecifier::Named(ImportNamedSpecifier {
                                    span: self.span(start),
                                    local: possibly_orig_name,
                                    imported: None,
                                    is_type_only: true,
                                }));
                            }

                            let maybe_as: Ident = self.parse_binding_ident(false)?.into();
                            if maybe_as.sym == "as" {
                                if self.input().cur().is_word() {
                                    // `import { type as as as } from 'mod'`
                                    // `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'`

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

Code after:

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

                                return Ok(ImportSpecifier::Named(ImportNamedSpecifier {
                                    span: self.span(start),
                                    local: possibly_orig_name,
                                    imported: None,
                                    is_type_only: true,
                                }));
                            }

                            let maybe_as: Ident = self.parse_binding_ident(false)?.into();
                            if maybe_as.sym == "as" {
                                if self.input().cur().is_word() {
                                    // `import { type as as as } from 'mod'`
                                    // `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'`