react-imported-component
Version: 
I will import your component, and help to handle it
19 lines (18 loc) • 583 B
JavaScript
import { __assign } from "tslib";
import vm from 'vm';
import { CLIENT_SIDE_ONLY } from '../configuration/constants';
var parseMagicComments = function (str) {
    if (str.trim() === CLIENT_SIDE_ONLY) {
        return {};
    }
    try {
        var values = vm.runInNewContext("(function(){return {" + str + "};})()");
        return values;
    }
    catch (e) {
        return {};
    }
};
export var commentsToConfiguration = function (comments) {
    return comments.reduce(function (acc, comment) { return (__assign(__assign({}, acc), parseMagicComments(comment))); }, {});
};