Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Multiple conditions in one line and/or nested conditions #4

Closed
kschzt opened this Issue Jan 22, 2013 · 8 comments

Comments

Projects
None yet
7 participants

kschzt commented Jan 22, 2013

Hi,

Here's an amended ifdef test that fails with multiple conditions on one line, and with nested conditions. HTH.

  'ifdef': function(test) {
    test.expect(6);

    var input,expected,settings;

    input = "a<!-- @ifdef NONEXISTANT -->b<!-- @endif -->c";
    expected = "ac";
    test.equal(pp.preprocess(input, { }), expected, 'Fail case, should not be included');

    input = "a<!-- @ifdef NODE_ENV -->b<!-- @endif -->c";
    expected = "abc";
    test.equal(pp.preprocess(input, { NODE_ENV: 'dev'}), expected, 'Success case, should be included');

    input = "a/* @ifdef NONEXISTANT */b/* @endif */c";
    expected = "ac";
    test.equal(pp.preprocess(input, { },'js'), expected, 'Fail case, should not be included');

    input = "a/* @ifdef DEFA && DEFB */b/* @endif */c";
    expected = "abc";
    test.equal(pp.preprocess(input, { DEFA: true, DEFB: true },'js'), expected, 'Fail case, should not be included');

    input = "a\n// @ifdef DEFA \nb\n// @ifdef DEFB\nc\n// @endif\n// @endif\nd";
    expected = "abcd";
    test.equal(pp.preprocess(input, { DEFA: true, DEFB: true },'js'), expected, 'Fail case, should not be included');

    input = "a/* @ifdef NODE_ENV */b/* @endif */c";
    expected = "abc";
    test.equal(pp.preprocess(input, { NODE_ENV: 'dev'},'js'), expected, 'Success case, should be included');

    test.done();
  },
Owner

jsoverson commented Jan 24, 2013

Thanks for the reminder. I'll try to get this taken care of soon.

Owner

jsoverson commented Feb 13, 2013

Multiple sequential conditions should be fixed. Nested inclusions will have to wait until this library gets more advanced tokenization in place (in progress, but no serious issues pressing faster development)

Would nested inclusions work if the preprocess method was recursive? It may also help to reorder the matches to if, ifdef, ifndef, exclude, include, and echo. This way dropped blocks won't recurse if they don't need to.

I just saw that include is indeed recursive cc5bf59#L2R60 and you made this change a month after this pull issue. Well the question still stands on the order thing though.

JonDum commented Jul 30, 2013

+1 for nested conditions. I had just assumed nested conditions would work and had to learn the hard way that they do not. :(

drasive commented Jan 26, 2015

+1, this would be really useful

I've just written a patch which should do one line multiples for ifdef and ifndef

Collaborator

BendingBender commented Jun 16, 2015

Nested directive support was implemented in #61.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment