1234567891011121314151617181920212223242526272829 |
- import * as AST from '../ast';
- import Env, { EnvError } from '../env';
-
- export class Rule {
- public property: AST.Property;
- public values: AST.Value[];
-
- public constructor(
- property: AST.Property,
- values: AST.Value[]
- ) {
- this.property = property;
- this.values = values;
- }
-
- 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 values: string[] = [];
- for (const value of this.values) {
- const compiledValue = value.compile(env, opts);
- if (compiledValue instanceof EnvError) return compiledValue;
- values.push(compiledValue);
- }
- return `${indentSpacer}${property}:${wordSpacer}${values.join(',')};`;
- }
- }
|