Skip to content

Commit c064607

Browse files
committed
simplify code a bit
1 parent 16bed54 commit c064607

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

src/unassert.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import unassertjs from 'unassert';
66
import convert from 'convert-source-map';
77
import {transfer} from 'multi-stage-sourcemap';
88

9-
// The following utility functions are adapted from
10-
// https://github.com/unassert-js/unassertify/blob/master/index.js
11-
// by Takuto Wada (which is under MIT license)
9+
// Adapted from https://github.com/unassert-js/unassertify/blob/master/index.js
10+
// by Takuto Wada (MIT-licensed)
1211

1312
function handleIncomingSourceMap(originalCode) {
1413
const commented = convert.fromSource(originalCode);
@@ -43,7 +42,6 @@ function mergeSourceMap(incomingSourceMap, outgoingSourceMap) {
4342
}
4443

4544
export default function unassert(options = {}) {
46-
4745
if (options.sourcemap === undefined) {
4846
options.sourcemap = true;
4947
}
@@ -58,35 +56,24 @@ export default function unassert(options = {}) {
5856
if (!filter(id)) { return null; }
5957

6058
return new Promise((resolve) => {
61-
62-
// The following piece of code is adapted from
63-
// https://github.com/unassert-js/unassertify/blob/master/index.js
64-
// by Takuto Wada (which is under MIT license)
6559
const ast = acorn.parse(code, {sourceType: 'module', locations: true});
66-
67-
const inMap = options.sourcemap && handleIncomingSourceMap(code);
6860
const unassertedAst = escodegen.generate(unassertjs(ast), {
6961
sourceMap: id,
7062
sourceContent: code,
7163
sourceMapWithCode: true
7264
});
73-
const outMap = convert.fromJSON(unassertedAst.map.toString());
7465

66+
const inMap = options.sourcemap && handleIncomingSourceMap(code);
67+
let outMap = convert.fromJSON(unassertedAst.map.toString());
7568
if (inMap) {
76-
const reMap = reconnectSourceMap(inMap, outMap);
77-
resolve({
78-
code: unassertedAst.code,
79-
map: reMap.toObject()
80-
});
81-
} else {
82-
resolve({
83-
code: unassertedAst.code,
84-
map: outMap.toObject()
85-
});
69+
outMap = reconnectSourceMap(inMap, outMap);
8670
}
8771

72+
resolve({
73+
code: unassertedAst.code,
74+
map: outMap.toObject()
75+
});
8876
});
89-
9077
}
9178
};
9279
}

0 commit comments

Comments
 (0)