/
sheonn
/
ObjectScriptFormatter
Обзор
Документация
Войти
/
sheonn
/
ObjectScriptFormatter
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/conditions.ts
56 строк
1 KB
Sheonn
preliminary version
19 май 2026, 11:29
19 май 2026, 11:29
ae87253
Код
Авторство
О чём код?
import { Parser, Query, Language, Tree, Node } from 'web-tree-sitter'; export enum ConditionType { AppendSpace, PrependSpace, AppendIndent, PrependIndent, PrependAntispace, WrapParens } export class Condition { public readonly type: ConditionType; private readonly node: Node; constructor( type: ConditionType, node: Node ) { this.type = type; this.node = node; } } export class Conditions { private nodes: Map<number, Condition[]> = new Map(); public add(node: Node, condition: Condition) { if (this.nodes.has(node.id)) { this.nodes.get(node.id)!.push(condition); } else { this.nodes.set(node.id, [condition]); } } public remove(node: Node, condition: Condition) { if (this.nodes.has(node.id)) { const conditions = this.nodes.get(node.id)!; const index = conditions.indexOf(condition); if (index !== -1) { conditions.splice(index, 1); } } } public get(node: Node): Condition[] { if (this.nodes.has(node.id)) { return this.nodes.get(node.id)!; } else { return []; } } public has(node: Node): boolean { return this.nodes.has(node.id); } }