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

export default let a = 42, not marked as error #209

Open
sguillia opened this issue Nov 26, 2021 · 2 comments
Open

export default let a = 42, not marked as error #209

sguillia opened this issue Nov 26, 2021 · 2 comments
Labels

Comments

@sguillia
Copy link

sguillia commented Nov 26, 2021

Hi!

The following piece of code is invalid but it is parsed correctly:

export default let a = 42

Here's a link to the TypeScript Playground showing that the snippet above is invalid JavaScript or TypeScript:
https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBAE2AMwIYFcA29PHquAXjgBYAmAbiA

The output of tree-sitter parse is the following:

(program [0, 0] - [1, 0]
  (export_statement [0, 0] - [0, 26]
    declaration: (lexical_declaration [0, 15] - [0, 26]
      (variable_declarator [0, 19] - [0, 25]
        name: (identifier [0, 19] - [0, 20])
        value: (number [0, 23] - [0, 25])))))

This issue was introduced in 0.20.0, the 0.19.0 grammar gave an ERROR node: 39b534f

I am not sure that declarations should be allowed in export default. I'd be happy if you can point me to the specification you're following when working on the grammar, so I can triple-check before opening issues


The parser not marking syntax errors as such is not a big problem, like in this kind of issues. The consuming code can assume it won't happen.

In this issue, the consuming code has to adapt to the new grammar, because export default function foo() { } contains a function_declaration instead of a function. I worked around like this:

switch (node.type):
	case "class-declaration":
	case "function-declaration":
		// valid because 'class' and 'function' node types exist

	case "variable-declaration":
	case "module-declaration":
	default:
		// syntax error
@sguillia sguillia added the bug label Nov 26, 2021
@mjambon
Copy link
Contributor

mjambon commented Nov 28, 2021

I think in general it's ok if the tree-sitter parser accepts more programs than it should. Maybe @maxbrunsfeld are more specific guidelines regarding this.

@maxbrunsfeld
Copy link
Contributor

If we can fix this in a way that simplifies the parser (reducing the state count), then that would be great. But if it would complicate the parser, then I'm inclined to leave it as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants