Menu

#31 Ignore <%= and <?php sections

open
nobody
None
5
2015-02-19
2009-10-22
No

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.)

Discussion

  • Matthias Miller

    Matthias Miller - 2009-10-22

    The setting can be called something like "ignore-server-side-code". It should be disabled by default.

     
  • Matthias Miller

    Matthias Miller - 2009-10-22

    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).

     
  • AlbertW

    AlbertW - 2009-10-22

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.