Skip to content

Commit 2730ccb

Browse files
PillowPillowjoshwiens
authored andcommitted
feat: allow charset in inline-source-map support (#21)
* add support for inline source map with charset update regexDataUrl * add unit test for inline source map with charset
1 parent 31b26bc commit 2730ccb

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var baseRegex = "\\s*[@#]\\s*sourceMappingURL\\s*=\\s*([^\\s]*)",
1414
// Matches // .... comments
1515
regex2 = new RegExp("//"+baseRegex+"($|\n|\r\n?)"),
1616
// Matches DataUrls
17-
regexDataUrl = /data:[^;\n]+;base64,(.*)/;
17+
regexDataUrl = /data:[^;\n]+(?:;charset=[^;\n]+)?;base64,(.*)/;
1818

1919
module.exports = function(input, inputMap) {
2020
this.cacheable && this.cacheable();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
with SourceMap
2+
// @ sourceMappingURL = data:application/source-map;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hhcnNldC1pbmxpbmUtc291cmNlLW1hcC5qcyIsInNvdXJjZXMiOlsiY2hhcnNldC1pbmxpbmUtc291cmNlLW1hcC50eHQiXSwic291cmNlc0NvbnRlbnQiOlsid2l0aCBTb3VyY2VNYXAiXSwibWFwcGluZ3MiOiJBQUFBIn0=
3+
// comment

test/index.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,23 @@ describe("source-map-loader", function() {
141141
done();
142142
});
143143
});
144+
145+
it("should process inlined SourceMaps with charset", function(done) {
146+
execLoader(path.join(__dirname, "fixtures", "charset-inline-source-map.js"), function(err, res, map, deps, warns) {
147+
should.equal(err, null);
148+
warns.should.be.eql([]);
149+
should.equal(res, "with SourceMap\n\n// comment"),
150+
map.should.be.eql({
151+
"version":3,
152+
"file":"charset-inline-source-map.js",
153+
"sources":[
154+
"charset-inline-source-map.txt"
155+
],
156+
"sourcesContent":["with SourceMap"],
157+
"mappings":"AAAA"
158+
});
159+
deps.should.be.eql([]);
160+
done();
161+
});
162+
});
144163
});

0 commit comments

Comments
 (0)