"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.processScriptAndStyleTag = processScriptAndStyleTag;
const cheerio_1 = __importDefault(require("cheerio"));
/**
 * Removes every script and style node (written by the user) encountered in the main app,
 * and records all these script nodes in an array so that they can be hoisted to after
 * <body> tag at a later stage.
 *
 * This is to prevent Vue compilation of script/style tags (as they are not meant to be compiled).
 *
 * @param node from the dom traversal
 * @param userScriptsAndStyles to store scripts and style tags for hoisting
 */
function processScriptAndStyleTag(node, userScriptsAndStyles) {
    var _a, _b;
    // Do not process script/style tags that are meant to be inserted in head/bottom of HTML
    const isHeadOrBottom = node.parent && (node.parent.name === 'head-top'
        || node.parent.name === 'head-bottom' || node.parent.name === 'script-bottom');
    if (isHeadOrBottom) {
        return;
    }
    const nodeSiblings = (_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : [node];
    nodeSiblings.splice(nodeSiblings.indexOf(node), 1);
    node.parent = undefined;
    userScriptsAndStyles.push(cheerio_1.default.html(node));
}
//# sourceMappingURL=scriptAndStyleTagProcessor.js.map