-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add failing test for nested consumer usage
- Loading branch information
David Sheldrick
committed
Apr 21, 2018
1 parent
c1e2ec8
commit b93aadb
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const {SourceMapConsumer, SourceMapGenerator} = require('../') | ||
|
||
const tsMap = { | ||
version: 3, | ||
file: "blah.js", | ||
sourceRoot: "", | ||
sources: ["blah.tsx"], | ||
names: [], | ||
mappings: | ||
";;AAKA;IACE,MAAM,CAAC,EAAC,MAAM,EAAE,SAAS,EAAC,CAAC;AAC7B,CAAC;AAFD,yBAEC", | ||
sourcesContent: [ | ||
"\ntype Cheese = {\n readonly cheese: string\n}\n\nexport default function Cheese(): Cheese {\n return {cheese: 'stilton'};\n}\n" | ||
] | ||
}; | ||
|
||
const babelMap = { | ||
version: 3, | ||
sources: ["blah.tsx"], | ||
names: [ | ||
"Object", | ||
"defineProperty", | ||
"exports", | ||
"value", | ||
"Cheese", | ||
"cheese", | ||
"default" | ||
], | ||
mappings: | ||
"AAAA;;AACAA,OAAOC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C,EAAEC,OAAO,IAAT,EAA7C;AACA,SAASC,MAAT,GAAkB;AACd,WAAO,EAAEC,QAAQ,SAAV,EAAP;AACH;AACDH,QAAQI,OAAR,GAAkBF,MAAlB", | ||
sourcesContent: [ | ||
'"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\nfunction Cheese() {\n return { cheese: \'stilton\' };\n}\nexports.default = Cheese;\n//# sourceMappingURL=blah.js.map' | ||
] | ||
}; | ||
|
||
|
||
async function composeSourceMaps( | ||
tsMap, | ||
babelMap, | ||
tsFileName, | ||
) { | ||
const tsConsumer = await new SourceMapConsumer(tsMap) | ||
const babelConsumer = await new SourceMapConsumer(babelMap) | ||
const map = new SourceMapGenerator() | ||
babelConsumer.eachMapping( | ||
({ | ||
source, | ||
generatedLine, | ||
generatedColumn, | ||
originalLine, | ||
originalColumn, | ||
name, | ||
}) => { | ||
if (originalLine) { | ||
const original = tsConsumer.originalPositionFor({ | ||
line: originalLine, | ||
column: originalColumn, | ||
}) | ||
if (original.line) { | ||
map.addMapping({ | ||
generated: { | ||
line: generatedLine, | ||
column: generatedColumn, | ||
}, | ||
original: { | ||
line: original.line, | ||
column: original.column, | ||
}, | ||
source: tsFileName, | ||
name: name, | ||
}) | ||
} | ||
} | ||
} | ||
) | ||
return map.toJSON() | ||
} | ||
|
||
exports["test nested consumer usage"] = async function (assert) { | ||
await composeSourceMaps(tsMap, babelMap, 'blah.tsx') | ||
}; |