@parcel/source-map
Advanced tools
Comparing version 2.0.0-alpha.1.1 to 2.0.0-alpha.2
@@ -26,2 +26,6 @@ "use strict"; | ||
function generateInlineMap(map) { | ||
return `data:application/json;charset=utf-8;base64,${new Buffer(map).toString('base64')}`; | ||
} | ||
class SourceMap { | ||
@@ -80,9 +84,14 @@ constructor(mappings = [], sources = {}) { | ||
async getConsumer(map) { | ||
getConsumer(map) { | ||
if (map instanceof _sourceMap.SourceMapConsumer) { | ||
return map; | ||
return Promise.resolve(map); | ||
} | ||
let sourcemap = typeof map === 'string' ? JSON.parse(map) : map; | ||
if (sourcemap.sourceRoot != null) delete sourcemap.sourceRoot; | ||
if (sourcemap.sourceRoot != null) { | ||
// $FlowFixMe | ||
delete sourcemap.sourceRoot; | ||
} | ||
return new _sourceMap.SourceMapConsumer(sourcemap); | ||
@@ -107,3 +116,3 @@ } | ||
async addMap(map, lineOffset = 0, columnOffset = 0) { | ||
addMap(map, lineOffset = 0, columnOffset = 0) { | ||
if (lineOffset === 0 && columnOffset === 0) { | ||
@@ -181,3 +190,3 @@ this.mappings.push(...map.mappings); | ||
async _extend(extension) { | ||
_extend(extension) { | ||
extension.eachMapping(mapping => { | ||
@@ -314,3 +323,4 @@ let originalMappingIndex = null; | ||
inlineSources, | ||
fs | ||
fs, | ||
inlineMap | ||
}) { | ||
@@ -344,3 +354,4 @@ let generator = new _sourceMap.SourceMapGenerator({ | ||
return generator.toString(); | ||
let stringifiedMap = generator.toString(); | ||
return inlineMap ? generateInlineMap(stringifiedMap) : stringifiedMap; | ||
} | ||
@@ -347,0 +358,0 @@ |
{ | ||
"name": "@parcel/source-map", | ||
"version": "2.0.0-alpha.1.1", | ||
"version": "2.0.0-alpha.2", | ||
"main": "./lib/SourceMap.js", | ||
@@ -8,6 +8,6 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">= 8.0.0" | ||
"node": ">= 10.0.0" | ||
}, | ||
"dependencies": { | ||
"@parcel/utils": "^2.0.0-alpha.1.1", | ||
"@parcel/utils": "^2.0.0-alpha.2", | ||
"nullthrows": "^1.1.1", | ||
@@ -19,3 +19,3 @@ "source-map": "^0.7.3" | ||
}, | ||
"gitHead": "8f9c49c1c53753b1139501cc4090cd4b1ab5ac0b", | ||
"gitHead": "aa2619af0a50fecbab024d30521391814560337f", | ||
"publishConfig": { | ||
@@ -22,0 +22,0 @@ "access": "public" |
@@ -17,3 +17,4 @@ // @flow strict-local | ||
column: number, | ||
name: string | null | ||
name: string | null, | ||
... | ||
}; | ||
@@ -25,11 +26,19 @@ | ||
column: null, | ||
name: null | ||
name: null, | ||
... | ||
}; | ||
type Sources = {[key: string]: string | null}; | ||
type Sources = {[key: string]: string | null, ...}; | ||
type SerializedSourceMap = { | ||
mappings: Array<Mapping>, | ||
sources: Sources | ||
sources: Sources, | ||
... | ||
}; | ||
function generateInlineMap(map: string): string { | ||
return `data:application/json;charset=utf-8;base64,${new Buffer(map).toString( | ||
'base64' | ||
)}`; | ||
} | ||
export default class SourceMap { | ||
@@ -86,5 +95,5 @@ mappings: Array<Mapping>; | ||
async getConsumer(map: RawMapInput): Promise<SourceMapConsumer> { | ||
getConsumer(map: RawMapInput): Promise<SourceMapConsumer> { | ||
if (map instanceof SourceMapConsumer) { | ||
return map; | ||
return Promise.resolve(map); | ||
} | ||
@@ -94,3 +103,6 @@ | ||
typeof map === 'string' ? JSON.parse(map) : map; | ||
if (sourcemap.sourceRoot != null) delete sourcemap.sourceRoot; | ||
if (sourcemap.sourceRoot != null) { | ||
// $FlowFixMe | ||
delete sourcemap.sourceRoot; | ||
} | ||
return new SourceMapConsumer(sourcemap); | ||
@@ -125,7 +137,3 @@ } | ||
async addMap( | ||
map: SourceMap, | ||
lineOffset: number = 0, | ||
columnOffset: number = 0 | ||
) { | ||
addMap(map: SourceMap, lineOffset: number = 0, columnOffset: number = 0) { | ||
if (lineOffset === 0 && columnOffset === 0) { | ||
@@ -215,3 +223,3 @@ this.mappings.push(...map.mappings); | ||
async _extend(extension: SourceMap) { | ||
_extend(extension: SourceMap) { | ||
extension.eachMapping(mapping => { | ||
@@ -331,3 +339,4 @@ let originalMappingIndex = null; | ||
line: number, | ||
column: number | ||
column: number, | ||
... | ||
} = { | ||
@@ -374,3 +383,4 @@ source: mapping.source, | ||
inlineSources, | ||
fs | ||
fs, | ||
inlineMap | ||
}: {| | ||
@@ -381,4 +391,5 @@ file?: string, // Filename of the bundle/file sourcemap applies to | ||
inlineSources?: boolean, // true = inline everything, false = inline nothing | ||
fs?: FileSystem | ||
|}) { | ||
fs?: FileSystem, | ||
inlineMap?: boolean | ||
|}): Promise<string> { | ||
let generator = new SourceMapGenerator({file, sourceRoot}); | ||
@@ -401,2 +412,3 @@ | ||
); | ||
if (content) { | ||
@@ -412,3 +424,5 @@ generator.setSourceContent(sourceName, content); | ||
return generator.toString(); | ||
let stringifiedMap = generator.toString(); | ||
return inlineMap ? generateInlineMap(stringifiedMap) : stringifiedMap; | ||
} | ||
@@ -415,0 +429,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31143
1052
Updated@parcel/utils@^2.0.0-alpha.2