Skip to content

Transitive external imports can be overwritten by simple-name collisions #2

Description

@danfma

Summary

_externalImportMap is keyed by simple name and is overwritten while discovering [Import] declarations from referenced assemblies. This makes external import resolution non-deterministic when two libraries expose bindings under the same TS name.

Evidence

  • MetaSharp.Compiler.TypeScript/Transformation/TypeTransformer.cs:323 does _externalImportMap[type.Name] = entry.
  • MetaSharp.Compiler.TypeScript/Transformation/TypeTransformer.cs:327 does _externalImportMap[tsName] = entry.
  • The comment immediately above says this phase should only add entries and should not overwrite local ones, but the implementation overwrites unconditionally.

Risk

A transitive dependency can silently replace a local external import mapping. The result depends on Compilation.References ordering, which makes the behavior hard to predict and debug.

Recommendation

Replace simple-name indexing with symbol-qualified or origin-qualified resolution, or at minimum detect collisions and emit a diagnostic. Local entries should explicitly win over transitive ones.

Missing tests

  • Two referenced assemblies with [Import] for the same simple name.
  • One local assembly and one referenced assembly defining the same external name.
  • A collision involving AsDefault = true and a named import.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions