Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Ignore @import statements which are not followed by url(..) #510

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/concat-style-loader/concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ function getImportStatements(content, ignoreComments = true) {
const matches = [];
let match;
while ((match = regex.exec(content))) {
// If import statement is not followed by a `url(...)`
if (typeof match[1] === 'undefined') {
continue;
}

match.endIndex = match.index + match[1].length;

if (matchIsInComment(content, match) && ignoreComments) {
Expand Down
13 changes: 12 additions & 1 deletion packages/concat-style-loader/test/concat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,24 @@ describe('getImportStatements()', () => {
const {getImportStatements} = require('../concat');
const contents = `
@import url('./other.css.liquid');
/* @import url('./another.css.liquid'); */
/* @import url('./anotherOne.css.liquid'); */
// @import url('./something.css.liquid');
@import url('./another.css.liquid');`;
const imports = getImportStatements(contents);

expect(imports.length).toBe(2);
});

test('ignores @import statements which are not followed by a url(...) statement', () => {
const {getImportStatements} = require('../concat');
const contents = `
@import './something.css.liquid';
@import url('./another.css.liquid');`;
const imports = getImportStatements(contents);

expect(imports.length).toBe(1);
});

test('can include @import statements inside comments', () => {
const {getImportStatements} = require('../concat');
const contents = `
Expand Down