Skip to content

Commit

Permalink
Merge pull request #312 from FormidableLabs/jp-remove-object-assign-p…
Browse files Browse the repository at this point in the history
…olyfill

remove Object.assign polyfill
  • Loading branch information
jpdriver committed Mar 31, 2022
2 parents 98925cc + 6c71dd6 commit c63fbfe
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"lint": "eslint --config .eslintrc \"./**/*.js\""
},
"dependencies": {
"core-js": "^3.14.0",
"prism-react-renderer": "^1.2.1",
"sucrase": "^3.20.3",
"use-editable": "^2.3.3"
Expand Down
9 changes: 1 addition & 8 deletions src/utils/transpile/evalCode.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import React from "react";
import assign from "core-js/features/object/assign";

export const _poly = { assign };

const evalCode = (code, scope) => {
const scopeKeys = Object.keys(scope);
const scopeValues = scopeKeys.map((key) => scope[key]);
// eslint-disable-next-line no-new-func
const res = new Function("_poly", "React", ...scopeKeys, code);
return res(_poly, React, ...scopeValues);
return new Function(...scopeKeys, code)(...scopeValues);
};

export default evalCode;
8 changes: 6 additions & 2 deletions src/utils/transpile/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from "react";
import transform from "./transform";
import errorBoundary from "./errorBoundary";
import evalCode from "./evalCode";
Expand All @@ -8,7 +9,10 @@ export const generateElement = ({ code = "", scope = {} }, errorCallback) => {

// NOTE: Workaround for classes and arrow functions.
const transformed = transform(`return (${codeTrimmed})`).trim();
return errorBoundary(evalCode(transformed, scope), errorCallback);
return errorBoundary(
evalCode(transformed, { React, ...scope }),
errorCallback
);
};

export const renderElementAsync = (
Expand All @@ -31,5 +35,5 @@ export const renderElementAsync = (
);
}

evalCode(transform(code), { ...scope, render });
evalCode(transform(code), { React, ...scope, render });
};
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4363,11 +4363,6 @@ core-js@^3.0.4, core-js@^3.6.5, core-js@^3.8.2:
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.16.0.tgz#1d46fb33720bc1fa7f90d20431f36a5540858986"
integrity sha512-5+5VxRFmSf97nM8Jr2wzOwLqRo6zphH2aX+7KsAUONObyzakDNq2G/bgbhinxB4PoV9L3aXQYhiDKyIKWd2c8g==

core-js@^3.14.0:
version "3.14.0"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.14.0.tgz#62322b98c71cc2018b027971a69419e2425c2a6c"
integrity sha512-3s+ed8er9ahK+zJpp9ZtuVcDoFzHNiZsPbNAAE4KXgrRHbjSqqNN6xGSXq6bq7TZIbKj4NLrLb6bJ5i+vSVjHA==

core-util-is@1.0.2, core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
Expand Down

0 comments on commit c63fbfe

Please sign in to comment.