mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-29 14:56:36 +03:00
Extract constant.
This commit is contained in:
parent
a4b523c805
commit
51acc3263c
@ -344,6 +344,48 @@ async function compileCliApp(options) {
|
||||
);
|
||||
|
||||
const elmFileContent = await fsPromises.readFile(ELM_FILE_PATH, "utf-8");
|
||||
// Source: https://github.com/elm-explorations/test/blob/d5eb84809de0f8bbf50303efd26889092c800609/src/Elm/Kernel/HtmlAsJson.js
|
||||
const forceThunksSource = ` _HtmlAsJson_toJson(x)
|
||||
}
|
||||
|
||||
var virtualDomKernelConstants =
|
||||
{
|
||||
nodeTypeTagger: 4,
|
||||
nodeTypeThunk: 5,
|
||||
kids: "e",
|
||||
refs: "l",
|
||||
thunk: "m",
|
||||
node: "k",
|
||||
value: "a"
|
||||
}
|
||||
|
||||
function forceThunks(vNode) {
|
||||
if (typeof vNode !== "undefined" && vNode.$ === "#2") {
|
||||
// This is a tuple (the kids : List (String, Html) field of a Keyed node); recurse into the right side of the tuple
|
||||
vNode.b = forceThunks(vNode.b);
|
||||
}
|
||||
if (typeof vNode !== 'undefined' && vNode.$ === virtualDomKernelConstants.nodeTypeThunk && !vNode[virtualDomKernelConstants.node]) {
|
||||
// This is a lazy node; evaluate it
|
||||
var args = vNode[virtualDomKernelConstants.thunk];
|
||||
vNode[virtualDomKernelConstants.node] = vNode[virtualDomKernelConstants.thunk].apply(args);
|
||||
// And then recurse into the evaluated node
|
||||
vNode[virtualDomKernelConstants.node] = forceThunks(vNode[virtualDomKernelConstants.node]);
|
||||
}
|
||||
if (typeof vNode !== 'undefined' && vNode.$ === virtualDomKernelConstants.nodeTypeTagger) {
|
||||
// This is an Html.map; recurse into the node it is wrapping
|
||||
vNode[virtualDomKernelConstants.node] = forceThunks(vNode[virtualDomKernelConstants.node]);
|
||||
}
|
||||
if (typeof vNode !== 'undefined' && typeof vNode[virtualDomKernelConstants.kids] !== 'undefined') {
|
||||
// This is something with children (either a node with kids : List Html, or keyed with kids : List (String, Html));
|
||||
// recurse into the children
|
||||
vNode[virtualDomKernelConstants.kids] = vNode[virtualDomKernelConstants.kids].map(forceThunks);
|
||||
}
|
||||
return vNode;
|
||||
}
|
||||
|
||||
function _HtmlAsJson_toJson(html) {
|
||||
`;
|
||||
|
||||
await fsPromises.writeFile(
|
||||
ELM_FILE_PATH,
|
||||
elmFileContent
|
||||
@ -351,88 +393,11 @@ async function compileCliApp(options) {
|
||||
/return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_JSON_STRINGIFY.\)/g,
|
||||
"return " +
|
||||
(options.debug
|
||||
? // "_Json_wrap(x)"
|
||||
` _HtmlAsJson_toJson(x)
|
||||
}
|
||||
|
||||
var virtualDomKernelConstants =
|
||||
{
|
||||
nodeTypeTagger: 4,
|
||||
nodeTypeThunk: 5,
|
||||
kids: "e",
|
||||
refs: "l",
|
||||
thunk: "m",
|
||||
node: "k",
|
||||
value: "a"
|
||||
}
|
||||
|
||||
function forceThunks(vNode) {
|
||||
if (typeof vNode !== "undefined" && vNode.$ === "#2") {
|
||||
// This is a tuple (the kids : List (String, Html) field of a Keyed node); recurse into the right side of the tuple
|
||||
vNode.b = forceThunks(vNode.b);
|
||||
}
|
||||
if (typeof vNode !== 'undefined' && vNode.$ === virtualDomKernelConstants.nodeTypeThunk && !vNode[virtualDomKernelConstants.node]) {
|
||||
// This is a lazy node; evaluate it
|
||||
var args = vNode[virtualDomKernelConstants.thunk];
|
||||
vNode[virtualDomKernelConstants.node] = vNode[virtualDomKernelConstants.thunk].apply(args);
|
||||
// And then recurse into the evaluated node
|
||||
vNode[virtualDomKernelConstants.node] = forceThunks(vNode[virtualDomKernelConstants.node]);
|
||||
}
|
||||
if (typeof vNode !== 'undefined' && vNode.$ === virtualDomKernelConstants.nodeTypeTagger) {
|
||||
// This is an Html.map; recurse into the node it is wrapping
|
||||
vNode[virtualDomKernelConstants.node] = forceThunks(vNode[virtualDomKernelConstants.node]);
|
||||
}
|
||||
if (typeof vNode !== 'undefined' && typeof vNode[virtualDomKernelConstants.kids] !== 'undefined') {
|
||||
// This is something with children (either a node with kids : List Html, or keyed with kids : List (String, Html));
|
||||
// recurse into the children
|
||||
vNode[virtualDomKernelConstants.kids] = vNode[virtualDomKernelConstants.kids].map(forceThunks);
|
||||
}
|
||||
return vNode;
|
||||
}
|
||||
|
||||
function _HtmlAsJson_toJson(html) {
|
||||
? `${forceThunksSource}
|
||||
return _Json_wrap(forceThunks(html));
|
||||
`
|
||||
: ` _HtmlAsJson_toJson(x)
|
||||
}
|
||||
|
||||
var virtualDomKernelConstants =
|
||||
{
|
||||
nodeTypeTagger: 4,
|
||||
nodeTypeThunk: 5,
|
||||
kids: "e",
|
||||
refs: "l",
|
||||
thunk: "m",
|
||||
node: "k",
|
||||
value: "a"
|
||||
}
|
||||
|
||||
function forceThunks(vNode) {
|
||||
if (typeof vNode !== "undefined" && vNode.$ === "#2") {
|
||||
// This is a tuple (the kids : List (String, Html) field of a Keyed node); recurse into the right side of the tuple
|
||||
vNode.b = forceThunks(vNode.b);
|
||||
}
|
||||
if (typeof vNode !== 'undefined' && vNode.$ === virtualDomKernelConstants.nodeTypeThunk && !vNode[virtualDomKernelConstants.node]) {
|
||||
// This is a lazy node; evaluate it
|
||||
var args = vNode[virtualDomKernelConstants.thunk];
|
||||
vNode[virtualDomKernelConstants.node] = vNode[virtualDomKernelConstants.thunk].apply(args);
|
||||
// And then recurse into the evaluated node
|
||||
vNode[virtualDomKernelConstants.node] = forceThunks(vNode[virtualDomKernelConstants.node]);
|
||||
}
|
||||
if (typeof vNode !== 'undefined' && vNode.$ === virtualDomKernelConstants.nodeTypeTagger) {
|
||||
// This is an Html.map; recurse into the node it is wrapping
|
||||
vNode[virtualDomKernelConstants.node] = forceThunks(vNode[virtualDomKernelConstants.node]);
|
||||
}
|
||||
if (typeof vNode !== 'undefined' && typeof vNode[virtualDomKernelConstants.kids] !== 'undefined') {
|
||||
// This is something with children (either a node with kids : List Html, or keyed with kids : List (String, Html));
|
||||
// recurse into the children
|
||||
vNode[virtualDomKernelConstants.kids] = vNode[virtualDomKernelConstants.kids].map(forceThunks);
|
||||
}
|
||||
return vNode;
|
||||
}
|
||||
|
||||
function _HtmlAsJson_toJson(html) {
|
||||
return forceThunks(html);
|
||||
: `${forceThunksSource}
|
||||
return forceThunks(html);
|
||||
`)
|
||||
)
|
||||
.replace(
|
||||
|
Loading…
Reference in New Issue
Block a user