-
Notifications
You must be signed in to change notification settings - Fork 13
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
Compiler: add default export even if there's an export already in the code (strict check for default export, not just /export/) #831
Comments
I don't even think that export there should be allowed. It's on the same level as some-job.js console.log("here") because the export doesn't consume state and return state. |
Hiya @doc-han The default export is the basic contract between the a job and the runtime. I suppose you can look at it like this: the runtime will load a JS module that exports an array of functions as its default export. And then it'll execute those functions in series. It's a nice clean interface between a job and the rumtime. There's no need for a job expression to export anything today. Saying that, I would like it to support named exports so that we can unit test job code later on. You're absolutely right - we should be doing a stricter check for But this isn't an issue I'm looking to fix in the short-medium term. We've got way more interesting problems to fix. |
I'll rename this issue so that we can keep it in the backlog |
@doc-han why do you want to add an export anyway? |
I actually don't want to.
|
@doc-han Got it - eagle eyes you have there 🦅 |
Description.
Runtime seems to always require a compiled job to have a default export of an array. Hence, those without a default export break the runtime.
Because
kit/packages/runtime/src/execute/expression.ts
Line 146 in 4376f7b
kit/packages/runtime/src/execute/expression.ts
Line 53 in 4376f7b
Currently,
We create a default export and then put all top-level-expressions in it. If there's no top-level-expression and empty array is exported to make the runtime happy.
But,
when there's an export (either named or not) that isn't a default export, we ignore the creation of the default export which makes the runtime sad.
eg.
Is there a reason we don't accommodate this? @josephjclark
I feel we can have other exports and still generate our default export. Also, if the user provides a default export(which isn't encouraged) we can also check if it exports an Array.
Here we do a regex match.
kit/packages/compiler/src/transforms/ensure-exports.ts
Line 15 in 4376f7b
For the concern of having several types of export nodes. A default export seems to always have only one type of Node representation. The name of the node only changes across ast-generator.
Proposed solution.
The text was updated successfully, but these errors were encountered: