tajo / ladle

đŸ¥„ Develop, test and document your React story components faster.
https://www.ladle.dev
MIT License
2.61k stars 87 forks source link

Allow exports in `export` block #554

Open i-am-the-slime opened 6 months ago

i-am-the-slime commented 6 months ago

Is your feature request related to a problem? Please describe. I'm using ladle with PureScript and it almost works. It's just that the compiler output looks like this:

var someStory = /* #__PURE__ */ // some JS component

export {
    someStory
};

This leads to the following error:

TypeError: Cannot read properties of null (reading 'type')
    at getNamedExports (/node_modules/@ladle/react/lib/cli/vite-plugin/parse/get-named-exports.js:31:30)

If I manually change this to say export var someStory =... and remove the export block it works fine.

Interestingly, it keeps working from there on out (so even when the file gets overwritten)

Describe the solution you'd like I'd love for this to simply work without me having to change the output of the compiler.

Describe alternatives you've considered If there was a way to hook into the reading of files, I could probably fix this with some regex or something more bespoke that traverses the AST, so that could be an alternative. If that's something I could do with vite out of the box I'd be happy about any pointers.

tajo commented 6 months ago

Valid request. We would need to add specifiers / ExportSpecifier here.

It's a different case from other ExportedNamedDeclarations.

Should be fairly straightforward if you want to open a PR.

woeps commented 5 months ago

Would it be (easily) possible to also support StoryDefault exported in export block like:

var storyDefault = {
  title: "Custom Title"
};

export {
  hello_world ,
  storyDefault as default,
}

If this is not yet covered by #556, would anybody have some pointers on what needs to be done to support it?

i-am-the-slime commented 5 months ago

@woeps have you tried my branch? There's a test you can probably modify and see if it works already

woeps commented 5 months ago

@i-am-the-slime I tried your branch locally and it seems StoryDefault in export block is not supported yet. I haven't tinkered with any tests: Do you mean the tests in packages/ladle/tests/parse/get-storyname-and-meta.test.ts?

i-am-the-slime commented 5 months ago

@woeps I mean this one on my fork/branch:

https://github.com/tajo/ladle/blob/e75b7615f1e6748f25d822d1c466d6a6bcac2469/packages/ladle/tests/parse/get-named-exports.test.ts#L287