Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'export type' being transpiled #26

Closed
lucasheim opened this issue Nov 19, 2019 · 1 comment · Fixed by #28
Closed

'export type' being transpiled #26

lucasheim opened this issue Nov 19, 2019 · 1 comment · Fixed by #28

Comments

@lucasheim
Copy link

When I write a typescript file like this:

export type testType = string | boolean;

export class testClass {
  public testMethod() {
    console.log("test");
  }
}

And run it using babel's typescript-preset, it transpiles to this:

export class testClass {
  testMethod() {
    console.log("test");
  }

}

As the type is something only important to Typescript, it shouldn't be transpiled. But, when I go through typescript-preset and then through transform-modules-ui5, this is the result:

sap.ui.define([], function () {
  class testClass {
    testMethod() {
      console.log("test");
    }

  }

  var __exports = {
    __esModule: true
  };
  __exports.testType = testType;
  __exports.testClass = testClass;
  return __exports;
});

The type ends up being transpiled: __exports.testType = testType;, even though it's not on Typescript's transpiling. Maybe there's a need to test the exports of a file before outputting them to JS, as testType ends up having no reference in the file and we get a runtime error.

I have an example on this repo: https://github.com/lucasheim/transform-ui5-playground

@Elberet
Copy link

Elberet commented Nov 20, 2019

I believe this issue is, by and large, caused by improper sequencing of the plugin's visitors (similar in spirit to the root cause of #23).

The module wrapper visits ExportNamedDeclaration nodes first and replaces them with their declaration part.

Then, much, much later, it builds the sap.ui.define wrapper based on the export declarations it has removed previously, even if another plugin has removed the remaining declaration in the meantime.

Testing whether the to-be-exported identifier still exists within the file's scope might be possible, but it's IMO a bandaid for a deeper design problem. The ExportNamedDeclaration handler and its siblings should be moved to a nested traverse call in the Program exit handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants