Skip to content

Commit

Permalink
Add integration test for original sourcesContent through transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Binns-Smith committed May 6, 2021
1 parent dad91eb commit e0abdbc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-react", "@babel/preset-flow"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @flow

import * as React from "react";
import * as ReactDOM from "react-dom";

type Props = {|
bar: string,
|};

function App(props: Props) {
return <div>{props.bar}</div>;
}

ReactDOM.render(<App bar="bar" />, document.getElementById("root"));
45 changes: 45 additions & 0 deletions packages/core/integration-tests/test/sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,4 +1286,49 @@ describe('sourcemaps', function() {
sourcePath,
});
});

it('carries sourcesContent from the original sources through multiple transformations (babel and swc)', async () => {
let b = await bundle(
path.join(
__dirname,
'integration/sourcemap-original-sourcecontents/index.js',
),
{
defaultTargetOptions: {
shouldScopeHoist: true,
},
},
);

let filename = b.getBundles()[0].filePath;
let raw = await outputFS.readFile(filename, 'utf8');

let mapUrlData = await loadSourceMapUrl(outputFS, filename, raw);
if (!mapUrlData) {
throw new Error('Could not load map');
}
let map = mapUrlData.map;

let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);
let sourceContent = map.sourcesContent[0];
let sourcePath = './index.js';

checkSourceMapping({
map: sourceMap,
source: sourceContent,
generated: raw,
str: 'bar="bar"' /* from jsx: <App bar="bar" /> */,
generatedStr: 'bar: "bar"',
sourcePath,
});

checkSourceMapping({
map: sourceMap,
source: sourceContent,
generated: raw,
str: 'document.getElementById(',
sourcePath,
});
});
});

0 comments on commit e0abdbc

Please sign in to comment.