jsoverson / preprocess

Preprocess HTML, JavaScript, and other files with directives based off custom or ENV configuration
Other
366 stars 80 forks source link

Fix: End of JavaScript comments are not parsed #83

Open anseki opened 9 years ago

anseki commented 9 years ago

Issue: https://github.com/jsoverson/preprocess/issues/77#issuecomment-120682188

In JavaScript code, that regexp stops reading immediately it found * without checking */ or end of line, etc.. Because that regexp accepts these as the end of the directive:

  1. **
  2. */
  3. Nothing

That regexp accepts "Nothing". And * as the parameters is not accepted.

For example:

console.log(
  require('preprocess').preprocess(
    'foo/* @if SIZE * 1024 > MEM */ BIG/* @endif */ bar',
    {SIZE: 2, MEM: 1024},
    {type: 'js'}
  )
);

Result:

foo* 1024 > MEM */ BIG bar

This PR fixes this bug, and puts common patterns into the variables.

anseki commented 9 years ago

I renamed vars because those are not good naming. If I should do it, I do rebase to a one commit.