Skip to content

function imports are strange #71

Description

@smcjones

I wrote a test:

    printBeforeAndAfter(
      `import {foo} from './another_place';

foo()`,
    );

Here's the output:

# testImport
v--TS--v
import {foo} from './another_place';

foo()
---
// Compiled using ts2gas 4.2.0 (TypeScript 4.9.3)
var exports = exports || {};
var module = module || { exports: exports };
//import {foo} from './another_place';
(0, another_place_1.foo)();
^--GS--^

Expected output:

# testImport
v--TS--v
import {foo} from './another_place';

foo()
---
// Compiled using ts2gas 4.2.0 (TypeScript 4.9.3)
var exports = exports || {};
var module = module || { exports: exports };
//import {foo} from './another_place';
foo();
^--GS--^

Alternatively, if another_place.ts exports files, a different expectation would be for another_place.ts to define another_place_1 as its export variable:

var another_place_1 = another_place_1 || {};
var exports = exports || {};

// ...

exports.foo = another_place_1.foo = 'foo';

Or a namespace...

another_place.ts

namespace another_place_1 {
    export function foo() {}
}

main.ts

// import {foo} from './another_place';
const {foo} = another_place_1;

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