UNPKG

@adguard/agtree

Version:
47 lines (44 loc) 1.47 kB
/* * AGTree v4.1.1 (build date: Thu, 23 Apr 2026 09:15:37 GMT) * (c) 2026 Adguard Software Ltd. * Released under the MIT license * https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme */ import { SPACE, COMMA, EMPTY } from '../../utils/constants.js'; import { BaseGenerator } from '../base-generator.js'; import { ParameterListGenerator } from '../misc/parameter-list-generator.js'; /** * Converts inline configuration comment nodes to their string format. */ class ConfigCommentGenerator extends BaseGenerator { /** * Converts an inline configuration comment node to a string. * * @param node Inline configuration comment node. * * @returns Raw string. */ static generate(node) { let result = EMPTY; result += node.marker.value; result += SPACE; result += node.command.value; if (node.params) { result += SPACE; if (node.params.type === 'ParameterList') { result += ParameterListGenerator.generate(node.params, COMMA); } else { // Trim JSON boundaries result += JSON.stringify(node.params.value).slice(1, -1).trim(); } } // Add comment within the config comment if (node.comment) { result += SPACE; result += node.comment.value; } return result; } } export { ConfigCommentGenerator };