UNPKG

react-imported-component

Version:
19 lines (18 loc) 499 B
import vm from 'vm'; import { CLIENT_SIDE_ONLY } from '../configuration/constants'; const parseMagicComments = (str) => { if (str.trim() === CLIENT_SIDE_ONLY) { return {}; } try { const values = vm.runInNewContext(`(function(){return {${str}};})()`); return values; } catch (e) { return {}; } }; export const commentsToConfiguration = (comments) => comments.reduce((acc, comment) => ({ ...acc, ...parseMagicComments(comment), }), {});