Skip to content

Commit

Permalink
Prevent mangling of variables.
Browse files Browse the repository at this point in the history
#60
Changes:
- Keep cleanupSource for builds.
- Use minimized UMD in demo.
  • Loading branch information
jfparadis committed Oct 1, 2019
1 parent fc3b394 commit 6c899e0
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/simple.html
@@ -1,6 +1,6 @@
<html>
<header>
<script src="../dist/realms-shim.umd.js"></script>
<script src="../dist/realms-shim.umd.min.js"></script>
</header>
<body>
<h1>Realm Shim</h1>
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -50,7 +50,6 @@
"prettier": "^1.18.2",
"rollup": "^1.21.4",
"rollup-plugin-babel-minify": "^9.1.0",
"rollup-plugin-strip-code": "^0.2.7",
"sinon": "^7.5.0",
"tape": "^4.11.0"
},
Expand Down
10 changes: 2 additions & 8 deletions rollup.config.js
@@ -1,5 +1,4 @@
import minify from 'rollup-plugin-babel-minify';
import stripCode from 'rollup-plugin-strip-code';

export default () => {
const isProduction = process.env.NODE_ENV === 'production';
Expand All @@ -19,12 +18,7 @@ export default () => {
}
];

const plugins = [
stripCode({
start_comment: 'START_TESTS_ONLY',
end_comment: 'END_TESTS_ONLY'
})
];
const plugins = [];

if (isProduction) {
plugins.push(
Expand All @@ -45,4 +39,4 @@ export default () => {
output,
plugins
};
}
};
3 changes: 1 addition & 2 deletions src/repair/functions.js
Expand Up @@ -18,7 +18,6 @@
*/

// todo: this file should be moved out to a separate repo and npm module.
const globalEval = eval;
export function repairFunctions() {
const { defineProperties, getPrototypeOf, setPrototypeOf } = Object;

Expand All @@ -35,7 +34,7 @@ export function repairFunctions() {
let FunctionInstance;
try {
// eslint-disable-next-line no-new-func
FunctionInstance = globalEval(declaration);
FunctionInstance = (0, eval)(declaration);
} catch (e) {
if (e instanceof SyntaxError) {
// Prevent failure on platforms where async and/or generators
Expand Down
2 changes: 1 addition & 1 deletion src/unsafeRec.js
Expand Up @@ -94,7 +94,7 @@ const repairAccessorsShim = cleanupSource(
`"use strict"; (${repairAccessors})();`
);
const repairFunctionsShim = cleanupSource(
`"use strict"; const globalEval = eval; (${repairFunctions})();`
`"use strict"; (${repairFunctions})();`
);

// Create a new unsafeRec from a brand new context, with new intrinsics and a
Expand Down
3 changes: 0 additions & 3 deletions src/utilities.js
Expand Up @@ -29,14 +29,11 @@ export function assert(condition, message) {

// Remove code modifications.
export function cleanupSource(src) {
/* START_TESTS_ONLY */

// Restore eval which is modified by esm module.
src = src.replace(/\(0,[^)]+\)/g, '(0, eval)');

// Remove code coverage which is injected by nyc module.
src = src.replace(/cov_[^+]+\+\+[;,]/g, '');

/* END_TESTS_ONLY */
return src;
}

0 comments on commit 6c899e0

Please sign in to comment.