Title: [parser] Flow types and syntax errors in function bodies · Issue #38 · lightscript/lightscript · GitHub
Open Graph Title: [parser] Flow types and syntax errors in function bodies · Issue #38 · lightscript/lightscript
X Title: [parser] Flow types and syntax errors in function bodies · Issue #38 · lightscript/lightscript
Description: lightscript@0.5.9: a(b?: T1): T2 -> switch unknown: Unexpected token (1:4) > 1 | a(b?: T1): T2 -> | ^ 2 | switch 3 | The parser is misattributing the syntax error to the function arg list, rather than the body. Removing the return type a...
Open Graph Description: lightscript@0.5.9: a(b?: T1): T2 -> switch unknown: Unexpected token (1:4) > 1 | a(b?: T1): T2 -> | ^ 2 | switch 3 | The parser is misattributing the syntax error to the function arg list, rather t...
X Description: lightscript@0.5.9: a(b?: T1): T2 -> switch unknown: Unexpected token (1:4) > 1 | a(b?: T1): T2 -> | ^ 2 | switch 3 | The parser is misattributing the syntax error to the function arg list,...
Opengraph URL: https://github.com/lightscript/lightscript/issues/38
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[parser] Flow types and syntax errors in function bodies","articleBody":"`lightscript@0.5.9`:\r\n```js\r\na(b?: T1): T2 -\u003e\r\n switch\r\n```\r\n```js\r\nunknown: Unexpected token (1:4)\r\n\u003e 1 | a(b?: T1): T2 -\u003e\r\n | ^\r\n 2 | switch\r\n 3 | \r\n```\r\nThe parser is misattributing the syntax error to the function arg list, rather than the body. Removing the return type annotation fixes this and gives the proper syntax error:\r\n```js\r\na(b?: T1) -\u003e\r\n switch\r\n```\r\n```js\r\nunknown: Illegal newline. (2:8)\r\n 1 | a(b?: T1) -\u003e\r\n\u003e 2 | switch\r\n | ^\r\n 3 | \r\n```\r\nI have traced the problem to this area:\r\nhttps://github.com/lightscript/babylon-lightscript/blob/master/src/parser/expression.js#L477\r\n\r\nI think the preceding code, when it tries to speculatively parse a function with a flowtype, is encountering an error in the body and eating it/resetting the state. Then because the `refShorthandDefaultPos` is set, the error appears outside the function body.\r\n\r\nNo suggested fix yet but I am looking into it.","author":{"url":"https://github.com/wcjohnson","@type":"Person","name":"wcjohnson"},"datePublished":"2017-06-20T21:47:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/38/lightscript/issues/38"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:154ca8ef-0b21-032e-fe5d-5d133e910d8a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9B8A:25305:10270A0:172E2DE:6A4E561B |
| html-safe-nonce | ac844043b296159539c9ce58a067b27797f59895c29ccc27ae5335cf6fbd93cf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QjhBOjI1MzA1OjEwMjcwQTA6MTcyRTJERTo2QTRFNTYxQiIsInZpc2l0b3JfaWQiOiIxOTE0NzI1NDkwNjc4OTc4MDc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 64cca3b663968ce17308def38c3c2892554ea16bdf49975cf6e650da13f9ac53 |
| hovercard-subject-tag | issue:237355117 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/lightscript/lightscript/38/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ba58389ad399ca7b1b6d131c6a22c8b3c7c7b950ecf3dedc34dfa80b03244aee/lightscript/lightscript/issues/38 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ba58389ad399ca7b1b6d131c6a22c8b3c7c7b950ecf3dedc34dfa80b03244aee/lightscript/lightscript/issues/38 |
| og:image:alt | lightscript@0.5.9: a(b?: T1): T2 -> switch unknown: Unexpected token (1:4) > 1 | a(b?: T1): T2 -> | ^ 2 | switch 3 | The parser is misattributing the syntax error to the function arg list, rather t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wcjohnson |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/lightscript/lightscript git https://github.com/lightscript/lightscript.git |
| octolytics-dimension-user_id | 20427295 |
| octolytics-dimension-user_login | lightscript |
| octolytics-dimension-repository_id | 63191213 |
| octolytics-dimension-repository_nwo | lightscript/lightscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63191213 |
| octolytics-dimension-repository_network_root_nwo | lightscript/lightscript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f344f1eab54fc7dfc02d0d018cda7e158c3db65c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width