ASI edits

Isiah Meadows isiahmeadows at gmail.com
Fri Jan 12 21:09:10 UTC 2018


I know this is probably bad timing (considering [this PR][1] and the
fallout that followed), but I was thinking that it'd be nice if we
could insert a `[no LineTerminator here]` clause in a few places, to
remove some of the ASI hazards for those going semicolon-free, along
with some extras for consistency:

- Before the `[` in the second rule of [`MemberExpression`][2] and the
fourth rule of [`CallExpression`][3]
- Before `Arguments` in the last rule of [`MemberExpression`][2], the
third and sixth rule of [`CallExpression`][3], and
[`CoverCallExpressionAndAsyncArrowHead`][4]
- Before the `(` in [`FunctionDeclaration`][5],
[`FunctionExpression`][6], the first, fourth, and fifth rule of
[`MethodDefinition`][7], [`GeneratorMethod`][8], both rules in
[`GeneratorDeclaration`][9], and [`GeneratorFunction`][10]

One of the practical effects would be this: this source (taken from the spec):

```js
a = b + c
(d + e).print()
```

is currently interpreted as:

```js
a = b + c(d + e).print();
```

but would, with this proposal, be interpreted as this, which is a
*lot* more intuitive with what people would expect:

```js
a = b + c;
(d + e).print();
```

I know there's risk of web compat concerns, but I doubt they'd be
significant for anything that's not minified via the Closure Compiler
(which limits line length by default for reasons of old IE). Also, for
most non-ASI people, they probably just forgot a semicolon anyways,
and [here][11] is a concrete example of this, where ESLint was fixing
a linter violation incorrectly because it wasn't reading it as you'd
expect.

[1]: https://github.com/tc39/ecma262/pull/1062
[2]: https://tc39.github.io/ecma262/#prod-MemberExpression
[3]: https://tc39.github.io/ecma262/#prod-CallExpression
[4]: https://tc39.github.io/ecma262/#prod-CoverCallExpressionAndAsyncArrowHead
[5]: https://tc39.github.io/ecma262/#prod-FunctionDeclaration
[6]: https://tc39.github.io/ecma262/#prod-FunctionExpression
[7]: https://tc39.github.io/ecma262/#prod-MethodDefinition
[8]: https://tc39.github.io/ecma262/#prod-GeneratorMethod
[9]: https://tc39.github.io/ecma262/#prod-GeneratorDeclaration
[10]: https://tc39.github.io/ecma262/#prod-GeneratorExpression
[11]: https://github.com/eslint/eslint/issues/7787

-----

Isiah Meadows
me at isiahmeadows.com

Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com


More information about the es-discuss mailing list