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

default exports not working #73

Open
samparsky opened this issue Aug 30, 2019 · 3 comments
Open

default exports not working #73

samparsky opened this issue Aug 30, 2019 · 3 comments

Comments

@samparsky
Copy link

samparsky commented Aug 30, 2019

For example, the below code does not generate the correct typing definition

/**
 * @module test1
 */

class One {}
export default One
exports.tag = "one"

It generates the below type description which does not include the default export

declare module 'test1' {
    class One { };
    export var tag: string;
}

It's missing the default export

@wehrstedt
Copy link
Collaborator

In resolveNamespaceMember is some logic which handles the export-flag. My first assumption is that this could be moved to the handleFlags function. Otherwise we have to add this logic to resolveModuleMember, too.

Would you like to contribute to this?

@samparsky
Copy link
Author

I could work on it if you can explain further

@wehrstedt
Copy link
Collaborator

I think the easiest way is to checkout the project. run yarn install and add a test like this

it.only("should export 'default' classes, async () => {
     const data = await parseData(`<your jsdoc / javascript goes in here`);
     const parser = new JSDocTsdParser();

     // Step in here to check why the flag is not set
     parser.parse(data);

     // Get the transformed class
     const result = parser.resolveMembership();
     result.should.include.keys("One");
     const classDeclaration: dom.ClassDeclaration= result.get("One") as dom.ClassDeclaration;
     
      // Ensure that the flag is set correctly
      expect(classDeclaration.flags).to.equal(dom.DeclarationFlags.ExportDefault);

      // You don't have to do this in the test, but you can get the result dts with
      const dts = parser.generateTypeDefinition();
      console.log(dts);
});

You can debug the test with vs code config Mocha Current File. Take a look at the handleFlags-function which is called here. As you can see here there is no handling for "default export", I assume that is the responsible point.

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

No branches or pull requests

2 participants