"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.engineTransformer = void 0;
var ts = require("typescript");
// @ts-ignore
var common_1 = require("../../common/common");
exports.engineTransformer = function (context) {
    return function (rootNode) {
        function visit(node) {
            if (node.kind === ts.SyntaxKind.TaggedTemplateExpression) {
                var _a = node.getChildren(), tag = _a[0], template = _a[1];
                if (tag.getText() === 'MACRO_GL_COMPRESS') {
                    var text = template.getText().slice(1, -1);
                    text = common_1.stringAsClearedArray(text).map(function (it) { return it.trim(); }).filter(function (it) { return !!it; }).join('\n');
                    return ts.createStringLiteral(text);
                    // const expressions:ts.Expression[] = [];
                    // const literals:ts.TemplateLiteralLikeNode[] = [];
                    // const statements:ts.Node[] = [];
                    // ((node as ts.TaggedTemplateExpression)?.template as ts.TemplateExpression)?.templateSpans?.forEach(it=>{
                    //     if (it.expression) expressions.push(it.expression);
                    //     if (it.literal) literals.push(it.literal);
                    // });
                    // expressions.forEach((ex,i)=>{
                    //     statements.push(ex);
                    //     console.log(literals[i].text);
                    //     statements.push(ts.createLiteral(literals[i].text));
                    // });
                    // console.log('---------------------------------------',statements);
                    // return (tsquery(tstemplate.compile(
                    //     `var template = [<%=statements%>].join(<%=EMPTY_STR%>);`,
                    // )({statements,EMPTY_STR:''}),'*')[0] as any).statements[0].declarationList.declarations[0].initializer;
                }
            }
            return ts.visitEachChild(node, visit, context);
        }
        return ts.visitNode(rootNode, visit);
    };
};
