grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

[javascript] Field declaration should end with ';'

Open ris58h opened this issue 2 years ago • 2 comments

Code:

class Foo {
    bar baz;
}

The code isn't correct according to documentation https://tc39.es/ecma262/multipage/ecmascript-language-functions-and-classes.html#prod-ClassElement and parsing should fail.

ris58h avatar Jun 21 '23 13:06 ris58h

Yes, I just saw this last week while scraping the Spec. But, it turns out that Node, which is built on V8, accepts the field with or without the semi-colon. So, what is "JavaScript"? Is the ECMAScript Spec correct? How is javascript and ecmascript supposed to differ in this repo?

kaby76 avatar Jun 21 '23 15:06 kaby76

Good question. I've checked Firefox and it allows a field declaration without semicolon so the code below is OK

class Foo {
    bar
    baz
}

but

class Foo {
    bar baz
}

is not OK and throws

Uncaught SyntaxError: unexpected token: identifier debugger eval code:2:8

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_semicolon_before_statement

ris58h avatar Jun 21 '23 17:06 ris58h