mattpocock / xstate-codegen

A codegen tool for 100% TS type-safety in XState
MIT License
245 stars 12 forks source link

Unexpected token after somehow removing `export` #3

Closed FokkeZB closed 4 years ago

FokkeZB commented 4 years ago

I see:

SyntaxError: Controller.machine.ts: Unexpected token (137:0)

  135 | );
  136 |
> 137 | default myMachine;
      | ^
  138 |

Although my code ends with:

);

export default myMachine;

This is because of:

https://github.com/mattpocock/xstate-codegen/blob/9dee84b1b3b3806de1cb215559397252f5ecf607/packages/xstate-compiled/src/getMachine.ts#L26

I guess it should also remove default following export.

mattpocock commented 4 years ago

@FokkeZB Could you paste in the entire file your machine is in so I can check it out? You're very likely right.

FokkeZB commented 4 years ago

It's something like:

const myMachine = Machine<Context, StateSchema>({ ... }, {...});

export default myMachine;

When I drop the last line it works fine.

mattpocock commented 4 years ago

@FokkeZB If you export it via a export const, it'll work. Although you'll of course have to change your imports elsewhere.

We're going to be releasing a new version of the tool quite soon (before the end of August) which will have improved the process by which we fetch machines from code. This will change things in a few ways (we'll be closer to number 4 here)

I'll make sure we include this fix in that version. Is it a blocker to change your export default to export const?

FokkeZB commented 4 years ago

@mattpocock awesome - I'll keep an eye on it and just refrain from export default for now.

mattpocock commented 4 years ago

Much obliged. I'll keep this issue open to make sure we remember it.

mattpocock commented 4 years ago

@FokkeZB Could you try testing this on the 'next' branch on npm? Confident that what we've shipped there will fix this.

FokkeZB commented 4 years ago

@mattpocock - confirmed! I get no more errors.