-
-
Notifications
You must be signed in to change notification settings - Fork 673
Improve arrow function parsing #256
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
Improve arrow function parsing #256
Conversation
24d6822
to
2cff7e0
Compare
src/parser.ts
Outdated
@@ -1420,6 +1420,11 @@ export class Parser extends DiagnosticEmitter { | |||
return Node.createFunctionExpression(declaration); | |||
} | |||
|
|||
private parseArrowFunctionBody(tn: Tokenizer): Statement | null { | |||
// TODO: should parse an expression unless the next token is `{`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tn.peek()
can check the next token, would that help?
src/compiler.ts
Outdated
@@ -5445,7 +5444,9 @@ export class Compiler extends DiagnosticEmitter { | |||
} | |||
} | |||
} else { | |||
body.push(this.compileStatement(bodyStatement)); | |||
body.push(bodyStatement instanceof Expression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be bodyStatement.kind != NodeKind.BLOCK
, as instanceof
isn't supported (yet, without a GC).
Quite similar to #256 and also uses its test, but also fixes the serializer and doesn't try to parse an untyped 'x => x'.
The commit above does something very similar with a somewhat reduced refactoring footprint. Also fixes related serializer issues but doesn't tackle |
Closing in favor of referenced commit. |
Fixes parsing for #255. Does not fix the issue since a conditional expression is still unsupported in the resolver.
Previously at
(a ? b : c)()
, we would assume thata ? b : c
were the parameters of an arrow function because every token involved was a valid token to appear in a signature -- but that wasn't strict enough. Now we will verify that?
is always followed by:
,,
, or)
, none of which are legal in expressions.Also correctly parses
x => x
now, though it still won't compile.