Skip to content

Invalid code generated with 'export module' declaration #713

Open
@theRobinator

Description

@theRobinator

Minimal reproduction follows:

test.ts

export module Foo {
    const notAnEmptyModule = 6;
}

Output: test.js

var Foo;
(function (Foo) {
    const /** @type {number} */ notAnEmptyModule = 6;
})(Foo = exports.Foo || (exports.Foo = {}));

Compiling with Closure Compiler v20180101 (the latest at the time of this writing) fails with this error:

vulcan/build/js/test.js:10: ERROR - Exports must be a statement at the top-level of a module
})(Foo = exports.Foo || (exports.Foo = {}));
                         ^^^^^^^^^^^^^^^^

As a workaround, doing the export on a separate line generates working code:

module Foo {
    const notAnEmptyModule = 6;
}
export {Foo};

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