Skip to content

Commit

Permalink
Fix import url parsing when from is a filter
Browse files Browse the repository at this point in the history
The `from` keyword could be used as a node import filter, in such cases
and if whitespace is added around filters, extracting filters was not
working correctly.

Fixes #159
  • Loading branch information
maoberlehner committed Dec 14, 2017
1 parent a218d45 commit 4f802c2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ describe(`parseNodeFilters()`, () => {
expect(nodeFilters).toEqual(expectedResult);
});

test(`It should handle spaces in node filters.`, () => {
const parseNodeFilters = parseNodeFiltersFactory();
const urlWithFilters = `[ at-rules, mixins, from ] from style.scss`;

const nodeFilters = parseNodeFilters(urlWithFilters);
const expectedResult = [
`at-rules`,
`mixins`,
`from`,
];

expect(nodeFilters).toEqual(expectedResult);
});

test(`It should trim empty filter from multi line URL.`, () => {
const parseNodeFilters = parseNodeFiltersFactory();
const urlWithFilters = `[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IFilterParser } from '../interfaces/IFilterParser';

export function parseNodeFiltersFactory(): IFilterParser {
return (url: string) => {
const filterDivider = /[\s]+from[\s]+/;
const filterDivider = /[\s]+from[\s]+(?!.*from)/;

if (!filterDivider.test(url)) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function parseSelectorFiltersFactory(
splitSelectorFilter: ISplitSelectorFilter,
): IParseSelectorFilters {
return (url: string) => {
const filterDivider = /[\s]+from[\s]+/;
const filterDivider = /[\s]+from[\s]+(?!.*from)/;

if (!filterDivider.test(url)) {
return [];
Expand Down

0 comments on commit 4f802c2

Please sign in to comment.