Skip to content
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

Lost semi-colon in Vue.js source code #1132

Closed
CCharlieLi opened this issue Aug 8, 2015 · 14 comments
Closed

Lost semi-colon in Vue.js source code #1132

CCharlieLi opened this issue Aug 8, 2015 · 14 comments

Comments

@CCharlieLi
Copy link

Hi 佑,
Thanks for your work, Vue is fantastic! But....
why not add a ";" to end each line of source code? when the code is compressed it appears to be a problem.

@OEvgeny
Copy link

OEvgeny commented Aug 8, 2015

Just look at Code style and No semicolons unless necessary.

I haven't issues with minimized Vue sources. How can we reproduce it?

@yyx990803
Copy link
Member

I don't write semicolons because they are not necessary.
https://github.com/yyx990803/semi#why

@CCharlieLi
Copy link
Author

Thanks for the sharing.
I'm using total.js with vue, and there is a built-in JS compressor in total.js, so there'll be a problem after webpack all code (including Vue), all the JS code in one line without semi-colon, and the browser will be blocked. It seems the compressor didn't insert semicolon at all.
After webpack vue code, I tried to use YUI compressor(and then tried uglify) to compress the generated code, but it still didn't work util I modified the source code of total.js to avoid using the built-in compressor.
For a better solution, I used the semi to add semicolon to vue, and everything came back to normal.
Cheers.

@mark-hahn
Copy link

It seems the compressor didn't insert semicolon at all.

I would consider that broken. It does not follow the javascript standard.
I would file an issue in the repo.

On Sat, Aug 8, 2015 at 7:58 PM, Charlie Li notifications@github.com wrote:

Thanks for the sharing.
I'm using total.js with vue, and there is a built-in JS compressor in
total.js, so there'll be a problem after webpack all code (including Vue),
all the JS code in one line without semi-colon, and the browser will be
blocked. It seems the compressor didn't insert semicolon at all.
After webpack vue code, I tried to use YUI compressor(and then tried
uglify) to compress the generated code, but it still didn't work util I
modified the source code of total.js to avoid using the built-in compressor.
For a better solution, I used the semi to add semicolon to vue, and
everything came back to normal.
Cheers.


Reply to this email directly or view it on GitHub
https://github.com/yyx990803/vue/issues/1132#issuecomment-129097549.

@pine3ree
Copy link

pine3ree commented Apr 20, 2016

I believe that semicolons makes the code more readable, especially for developers that are accustomed to other programming languages such php, java, c/c++;

Furtherless even when semicolons are not needed the engine use a feature called "semicolon insertion". So the engine recognizes that a semicolon is needed and automatically adds it. They are still needed in the final code, they are just automatically inserted when missing;
So why not just add them in the 1st place? :-) ;

From emca specs;

When, as a Script or Module is parsed from left to right, a token (called the _offending token) is encountered that is not allowed by any production of the grammar, then a semicolon is _automatically inserted before the offending token if one or more of the following conditions is true:;

it sounds to me like a missing semicolon is _corrected and automatically inserted_ and that a normal script _should_ have it, not that the semicolon is not needed; It is not written that unneeded semicolons are removed!!!;
;
I am sure this is due to my personal developer experience, but if i don't see a ";", even if i use daily project with no-semicolon style guideline, i still tend to look to the next line to see what's going on. :-) ;

....of course since the engine allows it anybody can use whichever style they prefer;

kind regards;

oh i forgot this... ;

@yyx990803
Copy link
Member

@pine3ree
Copy link

@yyx990803
Thanks i already read it, and of course many similar posts when people also like to insult each other :-)

i was only offering my POV on th matter and examining word by word emca specs.

The reason i tend to use semicolons is about (!about!) the same that i have for declaring variables at the beginning of a function. The engine will automatically hoist any declaration, but the code is more clear when putting them just there where they will "end up" before being interpreted :-).

  1. if a semicolon is needed it will be automatically inserted.
  2. if a var is declared its declaration will be automatically hoisted.

the final interpreted code will have missing ; in place and hoisted declarations

it's called ASI not ASR ("R"emoval of unnecessary ;)...so the valid final statement after ASI will have its ";", not the other way around.

For some reason some js developers will tell you (1) to put your var declarations at top to reflect the final code interpretation, but also tell you (!2) to avoid semicolons. So in one case they tell you to NOT rely of automation while in the other case they tell you to DO so.

since js allows both forms: having something like PSR for Javascript would be good, at least a for the eyes/brain not having to adjust coding style when switching form 1 project to another.

outside the scope of the discussion (and the fun of it :-) )
i believe that ASI leads to more uncertainty than not having it: i've always hated the return statement behaviour of js.....the developer should decide when the statement ends...but hey...that's the way it is...

...and....one final note....

;

just kidding...;

kind regards and thank you so much for VUE.JS

@yyx990803
Copy link
Member

The whole point is that readability is subjective and neither approach is technically superior or "more correct". There's simply no point in complaining about whether other people's code uses it or not.

@pine3ree
Copy link

I agree with you and i am not complaining! Maybe I wasn't clear (all the ; were just for fun). I was just expressing my point of view, the reason why i prefer not omitting semicolons and move all declarations on top and why a common style guideline among developers could be useful. PHP standard group has been very useful to te community. You can write php code in many ways but opening 10 different frameworks code and seeing the same style it's very helpful and saves you more than some time.

@posva
Copy link
Member

posva commented Apr 21, 2016

@pine3ree As for my personal experience, I liked using semi because I come from a C/C++ background but after trying the no semi style I found it faster to code with and more readable.

@pine3ree
Copy link

@posva same here, but i still prefer using it. As @yyx990803 says it's a matter of personal preference.
What i wanted to say it's that emca specs states that certain js statements must end with a semicolon. If you do not add it, the interpreter will add it for you before evaluation.
this:

var a = 1 + 2
++a

are not valid js statements, but you are allowed to write code in that way.

js ASI will transform them into a valid statements

var a = 1 + 2;
++a; 

the specs do not says that the ";" are removed from previous expressions because not needed, but that they are automatically added when missing.

quoting emca 11.9:

Certain ECMAScript statements MUST be terminated with semicolons (...). Such semicolons MAY always appear explicitly in the source text. For convenience, however, such semicolons MAY be omitted from the source text in certain situations. These situations are described by saying that semicolons are automatically inserted into the source code token stream in those situations.

so we MAY do things the way we are more comfortable :-)

quoting again:
In the circumstance that an assignment statement must begin with a left parenthesis, it is a good idea for the programmer to provide an explicit semicolon at the end of the preceding statement rather than to rely on automatic semicolon insertion.

just quoting the specs: ...at the end of the preciding statement...
again there is no must and many projects adds it at the beginning of next statement. It is fine!!! I've always use this technique when combining many scripts into one.

it's fine for me reading code relying on ASI, many big projects are using it, but It feels more natural to me to add it in my own code just because the other programming language i use do not provide ASI.
If i start omitting ; as a rule in js i am sure that sooner or later i will forget some in PHP/C++ or even in a multiple SQL query.

kind regards

@fnlctrl
Copy link
Member

fnlctrl commented Apr 21, 2016

@pine3ree I guess we should avoid using ++a (or a++) because Python doesn't support them. Well they're just philosophies and conventions enforced by language designers. C++/JS developers would prefer semicolons, and Python/JS developers would prefer no semicolons, since the specs allow both styles, it's just a matter of preference.

@pine3ree
Copy link

@fnlctrl
nope, again misunderstood. I am saying that you should do whatever you prefer. I just stated a few simple things.

  1. my personal preference (and some of the reasons behind it)
  2. quoting emca specs

Other than that I've never said to anyone what they should do....if you find me the line i will correct it because it's not what i intended.

They only thing i was complaining about (this is a general topic, it has nothing to do with this project's community) is the fact that some js developers tells you to put declaration on top because the engine put them there and so it's more clear to have them there but at the same time they tell you to avoid ; even if the engine adds them. I believe that you should either advice to use both, forbid both or allow people to choose for themselves. But not advice to use one and not to use the other, because the reason behind both is the same: writing code closer to how is interpreted.

Nobody should not feel sorry or more right than others for not using semicolons the same way nobody should feel sorry or more right for using them.

Pls let stop this! I don't want this silly thing to turn into a religious struggle or spaghetti vs fettuccine.
I just explained why i like fettuccine (well i like spaghetti as well). I am not telling you to eat fettuccine and to avoid spaghetti!

@vuejs vuejs locked and limited conversation to collaborators Apr 21, 2016
@yyx990803
Copy link
Member

I'm not interested in this conversation and I don't think it belongs here. Feel free to discuss semicolons elsewhere.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants