12345678910111213141516171819202122232425 |
- import * as AST from '../ast';
- import Env, { EnvError } from '../env';
-
- export class Rule {
- public property: AST.Property;
- public value: AST.Value;
-
- public constructor(
- property: AST.Property,
- value: AST.Value
- ) {
- this.property = property;
- this.value = value;
- }
-
- public compile(env: Env, opts: AST.Opts): string | EnvError {
- const wordSpacer = opts.prettyPrint ? ' ' : '';
- const indentSpacer = opts.prettyPrint ? ' ' + Array(opts.depth).fill(' ').join('') : '';
- const property = this.property.compile(env, opts);
- if (property instanceof EnvError) return property;
- const value = this.value.compile(env, opts);
- if (value instanceof EnvError) return value;
- return `${indentSpacer}${property}:${wordSpacer}${value};`;
- }
- }
|