Ignore <%= and <?php sections
Status: Beta
Brought to you by:
matthiasmiller
People are using this to include dynamic values in their ASP and PHP JavaScript, but they're causing syntax errors. I propose that these be preprocessed into comments.
This works nicely for things like:
<%= include path %>
However, it fails for code like:
var yr = <%= YEAR(Date()) %>;
This will be preprocessed into invalid JavaScript:
var yr = /* YEAR(Date()) */;
However, this can be corrected with something like:
var yr;
<%= "yr = " & YEAR(Date()) & ";" %>
(Or whatever the exact syntax might be.)
The setting can be called something like "ignore-server-side-code". It should be disabled by default.
The original approach will fail of the <?php block contains c-style comments. Better to preprocess into whitespace (whitespace required to preserve line numbers and column numbers).
This seems like a "toughie". There will probably be side effects for however you choose to handle this, but I'm thinking that ignoring statements that contain things like this might be a possibility... but a "smart" preprocessor that handles this may have to convert the ASP or PHP depending on the context in which it is used. Perhaps you could convert it to comments like you suggest, removing any "*/" in the comment so it works even if the comment contains c-style comments. .. but if the ASP or PHP is in an "=" context, handle it differently, like make it equal to some "dummy" value... like var yr = "dummy"; Anyway, some ideas but this looks like it could be complicated for JavaScript.