Skip to content

Commit

Permalink
fix: set negatedExtGlob also if it does not span the whole pattern
Browse files Browse the repository at this point in the history
This way micromatch can detect that this is a negation pattern.
  • Loading branch information
danez committed Apr 10, 2021
1 parent 4a510d7 commit 243f829
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/parse.js
Expand Up @@ -247,7 +247,7 @@ const parse = (input, options) => {
output = token.close = `)$))${extglobStar}`;
}

if (token.prev.type === 'bos' && eos()) {
if (token.prev.type === 'bos') {
state.negatedExtglob = true;
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/api.picomatch.js
Expand Up @@ -347,4 +347,19 @@ describe('picomatch', () => {
});
});
});

describe('state', () => {
describe('negatedExtglob', () => {
it('should return true', () => {
assert(picomatch('!(abc)', {}, true).state.negatedExtglob);
assert(picomatch('!(abc)**', {}, true).state.negatedExtglob);
assert(picomatch('!(abc)/**', {}, true).state.negatedExtglob);
});

it('should return false', () => {
assert(!picomatch('(!(abc))', {}, true).state.negatedExtglob);
assert(!picomatch('**!(abc)', {}, true).state.negatedExtglob);
});
});
});
});

0 comments on commit 243f829

Please sign in to comment.