Closed redappleorigin closed 4 years ago
The interface referencing the imported class is fine and does not throw an error. It seems that trying to instantiate my ExampleModel class anywhere in the machine file will cause that SyntaxError.
I'm using node v14.2.0 on a windows 10 machine.
@redappleorigin I'm off on holiday today, so this fix might have to wait a few days. @Andarist would you know a reason why importing a class might mess with the extractMachines rollup config?
@redappleorigin Do you have a local babel config in the dir where you're running the codegen tool?
@mattpocock no sir
Not sure why this wouldn't be working - Rollup should handle your model file and transpile it down to CJS. I'm rewriting the extraction from the current Babel+Rollup+execute setup to a pure TS-based one, so I don't think it's worth looking into it now as it should just get solved soon-ish anyway.
Did the example I provided have the same issue for you?
Just curious if maybe it is my machine somehow.
I'm running into this issue as well
@Andarist I don't suppose you have a bleeding edge branch I could work off, would you?
@redappleorigin back from hols, so will have a look at your example tomorrow. Agree with @Andarist that this is odd.
In my case it has to do with an import enum
. As soon as I import it from another file rather than declare it in the same module where it is being used the SyntaxError: Unexpected token 'export'
error shows up.
Edit: Removing enum usage from the imported file doesn't resolve the issue either though.
It's because the configuration for external
that is passed to rollup in extractMachines.ts isn't working correctly. It's marking files that start with a forward slash (/
) as external when they're not.
(Relative paths are being converted to absolute paths and those absolute paths are marked as external)
@rjdestigter would this work?
// Tests for '.' or '/' at the start of a string
const internalRegex = /^(\.|\/)/;
external: (id) => !internalRegex.test(id),
@mattpocock in my case I am on windows, so a slight change was required:
// Tests for '.', '/', or some drive letter followed immediately by a ':' at the start of a string
const internalRegex = /^(\.|\/|\w:)/.test(id);
external: (id) => !internalRegex.test(id),
Released under 0.1.0-next.8
I have an example branch here: https://github.com/redappleorigin/xstate-codegen/tree/imported-class-syntax-error
It is forked off of xstate-codegen@0.1.0-next.7
I added a new folder and file to examples 'models/example.model.ts' and modified fetchMachine.machine.ts so that it specifies an initialContext with one of the properties being
new ExampleModel()
. This causes aSyntaxError: Unexpected token 'export'