Skip to content

TSImportType: read source with an argument fallback (forward-compat) #177

Description

@zloirock

The TSImportType printer reads node.argument. typescript-eslint 8 renamed the field to source and currently keeps argument only as a deprecated, non-enumerable alias - so printing still works there today, but any tree that ships only the canonical name crashes:

TypeError: Cannot read properties of undefined (reading 'type')

(oxc-parser already emits only source; typescript-eslint will drop the alias eventually.)

One-line future-proofing:

context.visit(node.source ?? node.argument);

Context: found by a parse -> print -> reparse structural gate over a ~8.5k-file TS/JS corpus while adopting esrap in core-js's build plugin, then re-verified in isolation. esrap 2.3.5; the ASTs below come from @typescript-eslint/typescript-estree 8.67 with loc/range enabled, so the repros are independent of our own (oxc-based) pipeline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions