get-source
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -10,2 +10,3 @@ "use strict"; | ||
memoize = require ('lodash.memoize'), | ||
dataURIToBuffer = require ('data-uri-to-buffer'), | ||
lastOf = x => x[x.length - 1] | ||
@@ -58,2 +59,5 @@ | ||
else if (path.startsWith ('data:')) { | ||
this.text = dataURIToBuffer (path).toString () } | ||
else { | ||
@@ -85,11 +89,17 @@ try { | ||
try { | ||
if (this.sourceMap_ === undefined) { | ||
let url = this.text.match (/\u0023 sourceMappingURL=(.+\.map)/) // escape #, otherwise it will match this exact line.. %) | ||
if (url = (url && url[1])) { | ||
const [,url] = this.text.match (/\# sourceMappingURL=(.+)\n?/) || [undefined, undefined] | ||
if (url) { | ||
const sourceMap = new SourceMap (this.path, url) | ||
if (sourceMap.parsed) { | ||
this.sourceMap_ = sourceMap | ||
} | ||
} | ||
else { | ||
} else { | ||
this.sourceMap_ = null | ||
@@ -101,4 +111,5 @@ } | ||
catch (e) { | ||
this.sourceMap_ = null | ||
this.sourceMapError = e | ||
this.sourceMap_ = null } | ||
} | ||
@@ -105,0 +116,0 @@ return this.sourceMap_ |
{ | ||
"name": "get-source", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "Platform-agnostic source code inspection, with sourcemaps support", | ||
@@ -40,2 +40,3 @@ "main": "get-source", | ||
"dependencies": { | ||
"data-uri-to-buffer": "^1.0.0", | ||
"lodash.memoize": "^4.1.2", | ||
@@ -42,0 +43,0 @@ "source-map": "^0.5.6" |
@@ -12,3 +12,3 @@ # get-source | ||
- [x] Allows to read source code files in Node and browsers | ||
- [x] Full sourcemap support (path resolving, external/embedded linking and long chains) | ||
- [x] Full sourcemap support (path resolving, external/embedded/inline linking, and long chains) | ||
- [x] **Synchronous** API — which is good when you implement a debugging tool (e.g. [logging](https://github.com/xpl/ololog)) | ||
@@ -15,0 +15,0 @@ - [x] Built-in cache |
19
test.js
@@ -42,2 +42,9 @@ "use strict"; | ||
}) | ||
it ('works with data URIs', () => { | ||
path.relativeToFile ('/foo/bar.js', 'data:application/json;charset=utf-8;base64,eyJ2ZXJza==') | ||
.should.equal ( 'data:application/json;charset=utf-8;base64,eyJ2ZXJza==') | ||
}) | ||
}) | ||
@@ -122,3 +129,15 @@ | ||
it ('reads sources (sourcemapped, with inline base64 sourcemaps)', () => { | ||
const babeled = getSource ('./test_files/original.babeled.with.inline.sourcemap.js') | ||
babeled.sourceMap.should.not.equal (undefined) | ||
const resolved = babeled.resolve ({ line: 6, column: 1 }) | ||
resolved.line.should.equal (4) | ||
resolved.column.should.equal (1) | ||
resolved.sourceLine.should.equal ('\treturn \'hello world\' }') | ||
}) | ||
it ('supports even CHAINED sourcemaps!', () => { | ||
@@ -125,0 +144,0 @@ |
22436
18
322
3
+ Addeddata-uri-to-buffer@^1.0.0
+ Addeddata-uri-to-buffer@1.2.0(transitive)