Skip to content

Commit 8898eca

Browse files
author
Eric MORAND
authored
Merge pull request #6 from ericmorand/issue_5
Fix issue #5
2 parents b1e4b35 + 8fab8fa commit 8898eca

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/index.js

+23-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ class Rebaser extends Transform {
2323
syntax: 'css'
2424
});
2525

26+
let shouldBeRebased = function(uri) {
27+
if (path.isAbsolute(uri)) {
28+
return false;
29+
}
30+
31+
let url = Url.parse(uri);
32+
33+
// if the url consists of only a hash, it is a reference to an id
34+
if (url.hash) {
35+
if (!url.path) {
36+
return false;
37+
}
38+
}
39+
40+
// if the url host is set, it is a remote uri
41+
if (url.host) {
42+
return false;
43+
}
44+
45+
return true;
46+
};
47+
2648
if (self.map) {
2749
let sourceMapConsumer = new SourceMapConsumer(self.map);
2850

@@ -44,9 +66,7 @@ class Rebaser extends Transform {
4466
});
4567

4668
if (sourceMapNode && sourceMapNode.source) {
47-
let url = Url.parse(contentNodeContent);
48-
49-
if (!url.host && !path.isAbsolute(contentNodeContent)) {
69+
if (shouldBeRebased(contentNodeContent)) {
5070
contentNode.content = path.join(path.dirname(sourceMapNode.source), contentNodeContent);
5171

5272
self.emit('rebase', contentNode.content);

test/fixtures/remote-and-absolute/index.scss

+4
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88

99
.foo-bar {
1010
background: url('http://foo/bar');
11+
}
12+
13+
.svg-id {
14+
fill: url(#foo);
1115
}

test/fixtures/remote-and-absolute/wanted.css

+4
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88

99
.foo-bar {
1010
background: url('http://foo/bar');
11+
}
12+
13+
.svg-id {
14+
fill: url(#foo);
1115
}

0 commit comments

Comments
 (0)