marko
Version:
UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.
35 lines (33 loc) • 898 B
JavaScript
;exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
function _default(path) {
const { node } = path;
const isHTML = path.hub.file.markoOpts.output === "html";
switch (node.target) {
case "server":
if (!isHTML) {
replaceWithUndefinedIdentifiers(path);
return;
}
break;
case "client":
if (isHTML) {
replaceWithUndefinedIdentifiers(path);
return;
}
break;
}
path.replaceWithMultiple(node.body);
}
function replaceWithUndefinedIdentifiers(path) {
const keys = Object.keys(path.getOuterBindingIdentifiers());
if (keys.length) {
path.replaceWith(
_compiler.types.variableDeclaration(
"var",
keys.map((key) => _compiler.types.variableDeclarator(_compiler.types.identifier(key)))
)
);
} else {
path.remove();
}
}