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

Crash with ArrowFunctionExpression as ExpressionStatement #38

Closed
Conduitry opened this issue Apr 3, 2020 · 1 comment · Fixed by #39 or sveltejs/svelte#5000
Closed

Crash with ArrowFunctionExpression as ExpressionStatement #38

Conduitry opened this issue Apr 3, 2020 · 1 comment · Fixed by #39 or sveltejs/svelte#5000
Labels
bug Something isn't working

Comments

@Conduitry
Copy link
Collaborator

cr.print(cr.b`() => {}`).code

throws

Uncaught TypeError: Cannot read property 'type' of undefined
    at ExpressionStatement (.../code-red/dist/code-red.js:341:49)
    at handle (.../code-red/dist/code-red.js:71:18)
    at .../code-red/dist/code-red.js:249:19
    at Array.map (<anonymous>)
    at handle_body (.../code-red/dist/code-red.js:248:22)
    at Program (.../code-red/dist/code-red.js:319:11)
    at handle (.../code-red/dist/code-red.js:71:18)
    at print (.../code-red/dist/code-red.js:1414:18)
    at Object.print (.../code-red/dist/code-red.js:1399:11)

There's apparently an extra situation that needs to be handled here now that ArrowFunctionExpression has precedence 3.

Ref. sveltejs/svelte#4617

@Conduitry
Copy link
Collaborator Author

Conduitry commented Apr 3, 2020

Looking at this quickly, there's no reason as far as I can tell to be checking for the precedence of the operator, rather than just checking for the type of the node. So I think we could instead do node.expression.type === 'AssignmentExpression' && node.expression.left.type === 'ObjectPattern'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant