Skip to content

-shared: an exported const from a module with a top-level statement can't be resolved by the importer #448

Closed

Description

@ASDAlexander77

With -shared, an importer can't resolve an exported const from a module that also has a top-level statement. This happens under every memory model.

export_k.ts:

export const k = 5;

print("module init");

import_k.ts:

import "./export_k";

function main() {
    print(k);
    print("done.");
}
test-runner -shared -mm=gc import_k.ts export_k.ts
import_k.ts:4:11: error: can't resolve name: k
    print(k);
          ^

The result is the same under -mm=rc.

Without the top-level print, the pair compiles and runs, but the importer warns 'let' does not have initializer, use undefined union type '<type> | undefined' at the import. That suggests the declaration the importer sees for k is a let with no initializer. With a top-level statement in the module, k seems to be treated as a local of the module's top-level code rather than a global, so it is not exported at all.

Related: #447 (the same module imported as source does not compile at all).

Found during -mm=own phase 6 (#445, spec §20.5).

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