nippur72 / ifdef-loader

Webpack loader for JavaScript/TypeScript conditional compilation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regular expression not working well in some cases

TanukiSharp opened this issue · comments

Hi,

Pretty cool loader, but I ran into a problem. When I set the --host property of the webpack-dev-server, the ifdef-loader doesn't work anymore. The dude at webpack-dev-server didn't really seem to be open to the conversation so I don't really know why.

Here are the details: webpack/webpack-dev-server#2623

You can find a complete repro here: https://github.com/TanukiSharp/webpack-dev-server-host-ifdef-loader

Would you accept a PR to get rid off the regular expressions ? Or at least to make their use optional with a traditional parsing fallback method ?

I really don't get the reason why the server refuses to execute a loader containing a regex... it's a dev server! At least they should document it, explaining the reason why it's "insecure" (I could not find any reference in the docs).

If you want to make a PR for it make the fallback method optional e.g. "--noregex".

BTW, have you already tried the option disableHostCheck: true ? I am also curious where in the dev-server code the regex is blocked (in order to see if it's possible to circumvent it).

I agree with you I don't see any reason why it would do so. I think it's more a side effect than an intentional action, but still it sounds strange.

Yes I tried the disableHostCheck option, but nothing changed.

I'll try to make a PR to get an optional fallback support.

I have a few questions:

  1. Running npm test produces strange output. In the test script of package.json, did you mean && instead a single & to chain commands ?

  2. The regular expression to match #if and #elif has [\s\S]+, which means currently it matches expression like /// #iflol. I think it should be \s+[\s\S]+, right ?

  3. When you said --noregex, did you mean something like that ?

    const opts = {
        DEBUG: true,
        version: 3,
        "ifdef-noregex": true       // Does not use regular expressions.
    };

Thanks.

Implementation is done, unit tests passing. It doubled the amount of unit tests by the way.
Just waiting for answers to my above questions to finalize the PR.

Thanks.

Fun fact, this morning I retried my bug repro in order to then test the no-regex implementation to make sure it really fixes the problem... and couldn't repro... I tried my real project and... couldn't repro...

All this shit may just have been a really nasty bug in webpack-dev-server persisting across process restarts ???

So all my work may just be completely useless, but maybe it can still be merged ?

if it's useless, why merge? Just keep it aside in case we need it in the future.

Sorry for the lost time and effort, I guess it's part of what they call "JavaScript fatigue".