aboutsummaryrefslogtreecommitdiff
path: root/node_modules/convert-source-map/index.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-04-20 03:09:25 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-04-24 16:14:29 +0200
commit82f2b76e25a4a67e01ec67e5ebe39d14ad771ea8 (patch)
tree965f6eb89b84d65a62b49008fd972c004832ccd1 /node_modules/convert-source-map/index.js
parente6e0cbc387c2a77b48e4065c229daa65bf1aa0fa (diff)
Reorganize module loading.
We now use webpack instead of SystemJS, effectively bundling modules into one file (plus commons chunks) for every entry point. This results in a much smaller extension size (almost half). Furthermore we use yarn/npm even for extension run-time dependencies. This relieves us from manually vendoring and building dependencies. It's also easier to understand for new developers familiar with node.
Diffstat (limited to 'node_modules/convert-source-map/index.js')
-rw-r--r--node_modules/convert-source-map/index.js67
1 files changed, 21 insertions, 46 deletions
diff --git a/node_modules/convert-source-map/index.js b/node_modules/convert-source-map/index.js
index 3e6fe2934..e171a673c 100644
--- a/node_modules/convert-source-map/index.js
+++ b/node_modules/convert-source-map/index.js
@@ -2,11 +2,20 @@
var fs = require('fs');
var path = require('path');
-var commentRx = /^\s*\/(?:\/|\*)[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+;)?base64,(.*)$/mg;
-var mapFileCommentRx =
- //Example (Extra space between slashes added to solve Safari bug. Exclude space in production):
- // / /# sourceMappingURL=foo.js.map /*# sourceMappingURL=foo.js.map */
- /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/){1}[ \t]*$)/mg
+Object.defineProperty(exports, 'commentRegex', {
+ get: function getCommentRegex () {
+ return /^\s*\/(?:\/|\*)[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/mg;
+ }
+});
+
+Object.defineProperty(exports, 'mapFileCommentRegex', {
+ get: function getMapFileCommentRegex () {
+ //Example (Extra space between slashes added to solve Safari bug. Exclude space in production):
+ // / /# sourceMappingURL=foo.js.map /*# sourceMappingURL=foo.js.map */
+ return /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/){1}[ \t]*$)/mg;
+ }
+});
+
function decodeBase64(base64) {
return new Buffer(base64, 'base64').toString();
@@ -19,8 +28,7 @@ function stripComment(sm) {
function readFromFileMap(sm, dir) {
// NOTE: this will only work on the server since it attempts to read the map file
- var r = mapFileCommentRx.exec(sm);
- mapFileCommentRx.lastIndex = 0;
+ var r = exports.mapFileCommentRegex.exec(sm);
// for some odd reason //# .. captures in 1 and /* .. */ in 2
var filename = r[1] || r[2];
@@ -44,16 +52,6 @@ function Converter (sm, opts) {
this.sourcemap = sm;
}
-function convertFromLargeSource(content){
- var lines = content.split('\n');
- var line;
- // find first line which contains a source map starting at end of content
- for (var i = lines.length - 1; i > 0; i--) {
- line = lines[i]
- if (~line.indexOf('sourceMappingURL=data:')) return exports.fromComment(line);
- }
-}
-
Converter.prototype.toJSON = function (space) {
return JSON.stringify(this.sourcemap, null, space);
};
@@ -65,7 +63,7 @@ Converter.prototype.toBase64 = function () {
Converter.prototype.toComment = function (options) {
var base64 = this.toBase64();
- var data = 'sourceMappingURL=data:application/json;base64,' + base64;
+ var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
return options && options.multiline ? '/*# ' + data + ' */' : '//# ' + data;
};
@@ -113,49 +111,26 @@ exports.fromMapFileComment = function (comment, dir) {
};
// Finds last sourcemap comment in file or returns null if none was found
-exports.fromSource = function (content, largeSource) {
- if (largeSource) {
- var res = convertFromLargeSource(content);
- return res ? res : null;
- }
-
- var m = content.match(commentRx);
- commentRx.lastIndex = 0;
+exports.fromSource = function (content) {
+ var m = content.match(exports.commentRegex);
return m ? exports.fromComment(m.pop()) : null;
};
// Finds last sourcemap comment in file or returns null if none was found
exports.fromMapFileSource = function (content, dir) {
- var m = content.match(mapFileCommentRx);
- mapFileCommentRx.lastIndex = 0;
+ var m = content.match(exports.mapFileCommentRegex);
return m ? exports.fromMapFileComment(m.pop(), dir) : null;
};
exports.removeComments = function (src) {
- commentRx.lastIndex = 0;
- return src.replace(commentRx, '');
+ return src.replace(exports.commentRegex, '');
};
exports.removeMapFileComments = function (src) {
- mapFileCommentRx.lastIndex = 0;
- return src.replace(mapFileCommentRx, '');
+ return src.replace(exports.mapFileCommentRegex, '');
};
exports.generateMapFileComment = function (file, options) {
var data = 'sourceMappingURL=' + file;
return options && options.multiline ? '/*# ' + data + ' */' : '//# ' + data;
};
-
-Object.defineProperty(exports, 'commentRegex', {
- get: function getCommentRegex () {
- commentRx.lastIndex = 0;
- return commentRx;
- }
-});
-
-Object.defineProperty(exports, 'mapFileCommentRegex', {
- get: function getMapFileCommentRegex () {
- mapFileCommentRx.lastIndex = 0;
- return mapFileCommentRx;
- }
-});