forked from babel/sandboxes
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
78 lines (69 loc) · 1.81 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from "react";
import { render } from "react-dom";
import { App } from "./components/App";
import { extractID, isShareLink, REPLState } from "./state";
import * as Babel from "@babel/standalone";
import { addDefaultPlugins, loadPlugin, loadPreset } from "./plugins";
// css
import "semantic-ui-less/semantic.less";
window.babel = Babel;
// If we want to be able to easily replace a codesandbox template via Define API later...
// const BABEL_CONFIG = require("!raw-loader!../config.json");
// const BABEL_CONFIG2 = require("!raw-loader!../config2.json");
// const SOURCE = require("!raw-loader!../source.js");
// const PLUGIN = require("!raw-loader!../plugin.js");
const SOURCE = `Promise.allSettled([p1, p2]).finally(() => {
console.log("Done!");
});
`;
const CONFIG = [
{
plugins: [
],
presets: [
],
},
// {},
];
const PLUGIN = `export default function customPlugin(babel) {
return {
visitor: {
Identifier(path) {
// console.log(path.node.name);
}
}
};
}
`;
const defaultState = new REPLState(
SOURCE,
PLUGIN,
CONFIG.map(conf => JSON.stringify(conf))
);
/**
* @returns {Promise<REPLState>}
*/
async function getState() {
if (!isShareLink()) {
return defaultState;
}
const id = extractID();
const state = await REPLState.FromID(id);
return state === null ? defaultState : state;
}
(async () => {
addDefaultPlugins();
const state = await getState();
state.PluginList().forEach(plugin => loadPlugin(plugin));
state.PresetList().forEach(preset => loadPreset(preset));
render(
<App
defaultConfig={state.configs.map(conf => JSON.parse(conf))}
defaultSource={state.jsSource}
defCustomPlugin={state.pluginSource}
defaultId={state.id}
defaultForks={state.forks}
/>,
document.getElementById("root")
);
})();