Skip to content

Commit b93aadb

Browse files
author
David Sheldrick
committed
add failing test for nested consumer usage
1 parent c1e2ec8 commit b93aadb

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

test/test-nested-consumer-usage.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const {SourceMapConsumer, SourceMapGenerator} = require('../')
2+
3+
const tsMap = {
4+
version: 3,
5+
file: "blah.js",
6+
sourceRoot: "",
7+
sources: ["blah.tsx"],
8+
names: [],
9+
mappings:
10+
";;AAKA;IACE,MAAM,CAAC,EAAC,MAAM,EAAE,SAAS,EAAC,CAAC;AAC7B,CAAC;AAFD,yBAEC",
11+
sourcesContent: [
12+
"\ntype Cheese = {\n readonly cheese: string\n}\n\nexport default function Cheese(): Cheese {\n return {cheese: 'stilton'};\n}\n"
13+
]
14+
};
15+
16+
const babelMap = {
17+
version: 3,
18+
sources: ["blah.tsx"],
19+
names: [
20+
"Object",
21+
"defineProperty",
22+
"exports",
23+
"value",
24+
"Cheese",
25+
"cheese",
26+
"default"
27+
],
28+
mappings:
29+
"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",
30+
sourcesContent: [
31+
'"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\nfunction Cheese() {\n return { cheese: \'stilton\' };\n}\nexports.default = Cheese;\n//# sourceMappingURL=blah.js.map'
32+
]
33+
};
34+
35+
36+
async function composeSourceMaps(
37+
tsMap,
38+
babelMap,
39+
tsFileName,
40+
) {
41+
const tsConsumer = await new SourceMapConsumer(tsMap)
42+
const babelConsumer = await new SourceMapConsumer(babelMap)
43+
const map = new SourceMapGenerator()
44+
babelConsumer.eachMapping(
45+
({
46+
source,
47+
generatedLine,
48+
generatedColumn,
49+
originalLine,
50+
originalColumn,
51+
name,
52+
}) => {
53+
if (originalLine) {
54+
const original = tsConsumer.originalPositionFor({
55+
line: originalLine,
56+
column: originalColumn,
57+
})
58+
if (original.line) {
59+
map.addMapping({
60+
generated: {
61+
line: generatedLine,
62+
column: generatedColumn,
63+
},
64+
original: {
65+
line: original.line,
66+
column: original.column,
67+
},
68+
source: tsFileName,
69+
name: name,
70+
})
71+
}
72+
}
73+
}
74+
)
75+
return map.toJSON()
76+
}
77+
78+
exports["test nested consumer usage"] = async function (assert) {
79+
await composeSourceMaps(tsMap, babelMap, 'blah.tsx')
80+
};

0 commit comments

Comments
 (0)