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

Acorn crashed on TS types #36

Closed
jchatard opened this issue Dec 22, 2023 · 5 comments · Fixed by #214
Closed

Acorn crashed on TS types #36

jchatard opened this issue Dec 22, 2023 · 5 comments · Fixed by #214

Comments

@jchatard
Copy link

Hi,

I just tried Start beta with island support. I got an error during the build process:

Acorn crashed with this error:

vite v4.5.0 building SSR bundle for production...
✓ 32 modules transformed.
✓ built in 482ms
[vite-server-references] Unexpected token (104:83)
file: /Users/jchatard/Documents/xxx/src/lib/fetcher.ts:104:83

 ERROR  Unexpected token (104:83)                                                                                                                     09:15:35

  at pp$4.raise (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:3571:15)
  at p.raiseCommonCheck (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:101468)
  at p.raise (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:101622)
  at pp$9.unexpected (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:772:10)
  at pp$9.expect (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:766:28)
  at p.parseExprList (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:92278)
  at p.parseSubscript (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:94920)
  at pp$5.parseSubscripts (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:2734:26)
  at pp$5.parseExprSubscripts (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:2718:23)
  at pp$5.parseMaybeUnary (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:2681:19)
  at pp$5.parseExprOps (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:2608:21)
  at p.parseMaybeConditional (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:75991)
  at p.parseMaybeAssignOrigin (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:83453)
  at p.parseMaybeAssign (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:84543)
  at p.parseExprList (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:92499)
  at p.parseSubscript (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:94920)
  at pp$5.parseSubscripts (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:2734:26)
  at pp$5.parseExprSubscripts (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:2718:23)
  at pp$5.parseMaybeUnary (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:2681:19)
  at pp$5.parseExprOps (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:2608:21)
  at p.parseMaybeConditional (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:75991)
  at p.parseMaybeAssignOrigin (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:83453)
  at p.parseMaybeAssign (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:84543)
  at pp$8.parseVar (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:1321:26)
  at p.parseVarStatement (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:73986)
  at pp$8.parseStatement (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:927:19)
  at p.parseStatement (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:74981)
  at p.parseExportDeclaration (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:77126)
  at p.parseExport (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:70559)
  at pp$8.parseStatement (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:948:76)
  at p.parseStatement (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:74981)
  at pp$8.parseTopLevel (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:829:23)
  at e.parse (node_modules/.pnpm/acorn@8.11.2/node_modules/acorn/dist/acorn.js:601:17)
  at e.parse (node_modules/.pnpm/acorn-typescript@1.4.12_acorn@8.11.2/node_modules/acorn-typescript/lib/index.js:1:99339)
  at parseLoose (node_modules/.pnpm/@vinxi+plugin-directives@0.0.50_vinxi@0.0.54/node_modules/@vinxi/plugin-directives/parse.js:14:17)
  at Object.transform (node_modules/.pnpm/@vinxi+plugin-directives@0.0.50_vinxi@0.0.54/node_modules/@vinxi/plugin-directives/transform.js:595:42)
  at Object.transform (node_modules/.pnpm/@vinxi+plugin-directives@0.0.50_vinxi@0.0.54/node_modules/@vinxi/plugin-directives/plugin.js:49:34)



 ERROR  Unexpected token (104:83)                                                                                                                     09:15:35

 ELIFECYCLE  Command failed with exit code 1.

My code in src/lib/fetcher.ts was:

//... Note the return type 
export const getSettings = cache(async (): Promise<Settings> => {
  return getDataAtPath("settings");
}, "settings");

export const getMenuMain = cache(async (): Promise<MenuItem[]> => {
  return getDataAtPath("menu/main");
}, "menu/main");

export const getMenuFooter = cache(async (): Promise<MenuItem[]> => {
  return getDataAtPath("menu/footer");
}, "menu/footer");

When I remove return types like this:

export const getSettings = cache(async () => {
  return getDataAtPath("settings");
}, "settings");

export const getMenuMain = cache(async () => {
  return getDataAtPath("menu/main");
}, "menu/main");

export const getMenuFooter = cache(async () => {
  return getDataAtPath("menu/footer");
}, "menu/footer");

It works!

PS: thanks Nikhil for your amazing work on Vinxi and Solid :-)

@nksaraf
Copy link
Owner

nksaraf commented Dec 23, 2023

Hmm I remember things like this happening. Is this specifically where islands are involved? or even with islands disabled?

@jchatard
Copy link
Author

This only happens when Solid start config flag islands: true is set.

@nksaraf
Copy link
Owner

nksaraf commented Dec 26, 2023

Yup the islands plugin is also doing a parse and its apparently doing a bad non-typescript/jsx parse, which is probably when I first implemeted it, but I remember having to fix the same issue for server functions. So will use the same solution here for server components too.

@nksaraf
Copy link
Owner

nksaraf commented Dec 26, 2023

Can I get a full version of the file that's failing. I am trying with

import { cache } from "@solidjs/router";

type Settings = {};

function getDataAtPath(path) {
  "use server";

  return {};
}

export const getSettings = cache(async (): Promise<Settings> => {
  return getDataAtPath("settings");
}, "settings");

and it seems to work fine

@jchatard
Copy link
Author

Here's the package the file in question is in src/lib/fetcher.ts.

It's slightly changed but I confirm the same behavior.

front-solidjs.zip

nksaraf added a commit that referenced this issue Dec 27, 2023
(fix): decorate exports use parse-advanced, fixes #36
This was referenced Feb 28, 2024
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

Successfully merging a pull request may close this issue.

2 participants