ArrowFunctionExpression VS CallExpression Ambiguity


I am creating new concurrent systems for JavaScript, and I’m using Acorn as part of a compiler pipeline. I’ve added a new keyword named “spawn” as a contextual keyword, but I’m running into a paradox in the Acorn parser which I have had difficulty overcoming. Specifically, consider the following two cases:

spawn ("hello") => {...};

The desired AST nodes would be CallExpression for the first line, and SpawnExpression (my own custom node) for the second line. I have found source code within Acorn which differentiates between these two lines, however I have found it quite difficult to implement in the specific area I’m adding code. I have found that my difficulty lies in the fact that my SpawnExpression wraps the righthand expression, using it as an argument, while a similarly functioning keyword named “async” only marks the righthand expression. Right now, “spawn” behaves much like “yield” except it does not have the benefit of being a reserved keyword (and thus un-callable), and I’d like to preserve existing source code which makes calls to functions named “spawn”.

If anyone could offer some insight into how I could differentiate between the two lines of code up there, I’d greatly appreciate it. I have poured a massive amount of effort into this project and I’d hate for a tiny issue like this to stop it now.

Here’s the “plugin” I’ve written so far: