Skip to content

Commit

Permalink
More strict cleanupSource()
Browse files Browse the repository at this point in the history
  • Loading branch information
jfparadis committed Oct 1, 2019
1 parent 2d9cd98 commit f26d939
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export function assert(condition, message) {
// Remove code modifications.
export function cleanupSource(src) {
// Restore eval which is modified by esm module.
src = src.replace(/\(0,[^)]+\)/g, '(0, eval)');
// (0, eval) => (0, _<something>.e)
src = src.replace(/\(0, _[^.]+\.e\)/g, '(0, eval)');

// Restore Reflect which is modified by esm module.
// Reflect => _<something>.e.Reflect
src = src.replace(/_[^.]+\.g\.Reflect/g, 'Reflect');

// Remove code coverage which is injected by nyc module.
src = src.replace(/cov_[^+]+\+\+[;,]/g, '');
Expand Down
14 changes: 9 additions & 5 deletions test/module/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@ test('assert', t => {
});

test('cleanupSource', t => {
t.plan(2);
t.plan(3);

t.equal(
cleanupSource(`function() { return (0, _123.e)('true'); }`),
`function() { return (0, eval)('true'); }`
);
t.equals(
cleanupSource(`function() { const { apply } = _123.g.Reflect; }`),
`function() { const { apply } = Reflect; }`
);
t.equal(
cleanupSource(`function() { cov_2kmyol0g2w[0]++;return true; }`),
'function() { return true; }'
);
t.equals(
cleanupSource(`function() { return (0, _123)('true'); }`),
`function() { return (0, eval)('true'); }`
);
});

0 comments on commit f26d939

Please sign in to comment.