This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 262449 - Javascript "Automatic Semicolon Insertion"
Summary: Javascript "Automatic Semicolon Insertion"
Status: RESOLVED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Petr Hejl
URL:
Keywords:
: 262415 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-06-15 19:24 UTC by dusty
Modified: 2016-08-16 14:22 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dusty 2016-06-15 19:24:18 UTC
According to ES6 specs, there are rules for "Automatic Semicolon Insertion" and the parser should use them to avoid signaling errors and warnings.

The reference is http://www.ecma-international.org/ecma-262/6.0/#sec-automatic-semicolon-insertion

As an example, if a source has these two lines, NB marks the second as error since the first one is not semicolon terminated:

import {LooseParser} from "./state"
import {isDummy} from "./parseutil"
Comment 1 Petr Hejl 2016-06-20 09:07:07 UTC
Those warnings should be hints. You can enable/disable them.

In your ES6 sample, the semicolons has to be there as (whenever there is import/export) it is module and module is always in strict mode.
Comment 2 Petr Hejl 2016-06-20 09:09:36 UTC
*** Bug 262415 has been marked as a duplicate of this bug. ***
Comment 3 dusty 2016-06-20 09:21:31 UTC
It's not a module definition but a simple usage on a node application: the code showed is taken from some random library in npm (it's not my own), and works fine on node.

ES6 has no strict mode and semicolon are optional, that's why there is a specification to know how and when automatically apply it when not present.

Pietr Pisl is working on updating the parser to better implement the specification so I think this bug should be left open until the new parser is complete.
Comment 4 Petr Pisl 2016-06-20 09:49:41 UTC
I'm not working on new parser. I want to try changed the source code before parsing to pass it according ECMA6 spec. So we can replace the new line with semicolon before the parsing in these cases. 

I also agree with Petr Hejl that the code doesn't pass the ECMA6 spec, because module is in strict mode. Unfortunately the node js parser doesn't follow fully the spec .
Comment 5 Petr Hejl 2016-06-20 09:52:14 UTC
(In reply to dusty from comment #3)
> It's not a module definition but a simple usage on a node application: the
> code showed is taken from some random library in npm (it's not my own), and
> works fine on node.
> 
> ES6 has no strict mode and semicolon are optional, that's why there is a
> specification to know how and when automatically apply it when not present.
http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code
"Module code is always strict mode code."

And note that import and export keyword may be only present in module.
http://www.ecma-international.org/ecma-262/6.0/#sec-modules

> 
> Pietr Pisl is working on updating the parser to better implement the
> specification so I think this bug should be left open until the new parser
> is complete.
It won't be actually implemeting the spec; technically it would be violating it - it's nice that npm is handling such code and we'll try to do it during code sanitization but it's not ES6 source :(
Comment 6 dusty 2016-06-20 10:12:06 UTC
Where may I see that ES6 strict mode requires semicolon?
Comment 7 dusty 2016-06-20 10:21:26 UTC
In particular I can't find any rules about mandatory semicolons in the section:
http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-of-ecmascript

Also, in the Lexical Grammar:
http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-lexical-grammar

I read:
> The source text of an ECMAScript Script or Module is first converted into a sequence of input elements,

and subsequently:
> The use of multiple lexical goals ensures that there are no lexical ambiguities that would affect automatic semicolon insertion.

So, according to specs, it is my understanding that semicolons are not mandatory in ES6 strict mode while, in fact, automatic semicolon insertion must be implemented.

Please correct me if I misread the official documentation, thanks!
Comment 8 Petr Hejl 2016-06-20 10:30:48 UTC
(In reply to dusty from comment #7)
> In particular I can't find any rules about mandatory semicolons in the
> section:
> http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-of-ecmascript
> 
> Also, in the Lexical Grammar:
> http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-
> lexical-grammar
> 
> I read:
> > The source text of an ECMAScript Script or Module is first converted into a sequence of input elements,
> 
> and subsequently:
> > The use of multiple lexical goals ensures that there are no lexical ambiguities that would affect automatic semicolon insertion.
> 
> So, according to specs, it is my understanding that semicolons are not
> mandatory in ES6 strict mode while, in fact, automatic semicolon insertion
> must be implemented.
> 
> Please correct me if I misread the official documentation, thanks!

I'll look into that. I guess I overestimated ES6 strictness ;)
That would possibly mean bug in parser we are using.
Comment 9 Petr Pisl 2016-06-20 10:58:37 UTC
If it's a bug in the parser, we can possible fix it and provide the patch back to the parser project.
Comment 10 Petr Hejl 2016-06-20 21:08:38 UTC
Fixed in web-main f9c9ce85e20c.
Comment 11 dusty 2016-08-16 14:15:15 UTC
I'm using netbeans-trunk-nightly-201608150002 but the warning is still present.

I need to manually disable warnings in the editor preferences to avoid it, but that should be automatic if ECMA6 or ECMA7 features are enabled.
Comment 12 Petr Hejl 2016-08-16 14:22:30 UTC
(In reply to dusty from comment #11)
> I'm using netbeans-trunk-nightly-201608150002 but the warning is still
> present.
> 
> I need to manually disable warnings in the editor preferences to avoid it,
> but that should be automatic if ECMA6 or ECMA7 features are enabled.

I'm not seeing hints for your original report. You should report the particular case for which you do see these. Thanks.