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

[Typescript Error]: Function declaration must have a name in this context #105

Closed
felipelealdefaria opened this issue Jul 4, 2021 · 2 comments

Comments

@felipelealdefaria
Copy link

Hi, I'm working on a project where I need to convert snippets of code to AST. I have two simple examples of functions using Typescript:

export const arrowFunction = (value: any): string => {
  const { type } = value
  return type
}

export function regularFunction (value: any): string {
  // this is a regular function
  const { type } = value
  return type
}

For the case of regularFunction I don't have any problem, but when I use the parse function in arrowFunction I get the error below:

<rootDir>/node_modules/meriyah/dist/meriyah.cjs:187
    throw new ParseError(parser.index, parser.line, parser.column, type, ...params);
    ^

ParseError [SyntaxError]: [1:10]: Function declaration must have a name in this context
    at report (<rootDir>/node_modules/meriyah/dist/meriyah.cjs:187:11)
    at parseFunctionDeclaration (<rootDir>/node_modules/meriyah/dist/meriyah.cjs:6592:13)
    at parseStatementListItem (<rootDir>/node_modules/meriyah/dist/meriyah.cjs:4853:20)
    at parseModuleItem (<rootDir>/node_modules/meriyah/dist/meriyah.cjs:4840:26)
    at parseModuleItemList (<rootDir>/node_modules/meriyah/dist/meriyah.cjs:4825:25)
    at parseSource (<rootDir>/node_modules/meriyah/dist/meriyah.cjs:4769:16)
    at Object.parseModule (<rootDir>/node_modules/meriyah/dist/meriyah.cjs:8780:12)
    at parse (<rootDir>/node_modules/abstract-syntax-tree/src/parse.js:4:18)
    at parse (<rootDir>/node_modules/abstract-syntax-tree/index.js:75:12)
    at Object.<anonymous> (<rootDir>/dist/clones/arrow-and-regular/index.js:10:43) {
  index: 10,
  line: 1,
  column: 10,
  description: '[1:10]: Function declaration must have a name in this context',
  loc: { line: 1, column: 10 }
}

I realized that it can be related to the newer syntaxes of the language and remembering that I only have this error when using Typescript.

Library Version
abstract-syntax-tree 2.19.1
typescript ^4.2.3
@emilos
Copy link
Contributor

emilos commented Jul 5, 2021

hey @felipelealdefaria, thanks for using the library. Are you trying to parse the output that's compiled via typescript? How does the compiled output look like?

@felipelealdefaria
Copy link
Author

felipelealdefaria commented Jul 5, 2021

Hi @emilos, thanks for answering!

I was trying to parse the typescript code directly. However, today I got the answer that the library meriyah doesn't understand Typescript syntax, only Javascript.

Sorry for the misunderstanding, I will follow the project using only Javascript :)

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

No branches or pull requests

2 participants