HoriSun / closure-compiler

Automatically exported from code.google.com/p/closure-compiler
0 stars 0 forks source link

Patch for /contrib/externs/w3c_midi.js #1272

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Marking properties as read-only (with a comment -- Closure Compiler has no 
annotation for that currently) instead of @const, because there might be 
optimizations that mess things up if the compiler believes these properties are 
truly constant.

See w3c_gamepad.js revision bdd1b61106dc for reference -- 
https://code.google.com/p/closure-compiler/source/detail?r=bdd1b61106dc54b611de1
dc10bfe912f392a886f

Changed @const to @type on line 151 because the annotation was incorrect.

Original issue reported on code.google.com by RetroModular on 7 Mar 2014 at 9:57

Attachments:

GoogleCodeExporter commented 9 years ago
I would think some of these would actually be constant, no? For example, the 
'version' of a MIDIPort won't change over time, will it? (I could be totally 
wrong, I haven't actually played with web midi at all.)

Original comment by tbreisac...@google.com on 7 Mar 2014 at 5:23

GoogleCodeExporter commented 9 years ago
Just a clarification.

If a variable or property in externs is marked as @const, the compiler cannot 
use that knowledge in optimizations, eg, to inline the value, because it 
doesn't know what that value is (it's set in some file invisible to the 
compiler). So, it can't break your code.

The only effect of an @const annotation in externs is that the compiler checks 
that you don't assign to that variable or property in your code. So, it's safe 
to have the annotation and you will have more type checking.

Original comment by dim...@google.com on 7 Mar 2014 at 6:04

GoogleCodeExporter commented 9 years ago
Turns out I was wrong here. The compiler can alias @consts in externs, which 
can break your code. So, yes, you shouldn't be using @const for readonly 
variables that can change in external code.

Original comment by dim...@google.com on 7 Mar 2014 at 6:22

GoogleCodeExporter commented 9 years ago
Issue tracking has been migrated to github. Please make any further comments on 
this issue through https://github.com/google/closure-compiler/issues

Original comment by blic...@google.com on 1 May 2014 at 6:31

GoogleCodeExporter commented 9 years ago

Original comment by blic...@google.com on 1 May 2014 at 6:34