Skip to content

Commit 9cc7d55

Browse files
committed
feat: Rename ReadonlyOptions to ResolvedConfiguration.
BREAKING CHANGE: ReadonlyOptions is really the configuration after having been fully resolved and populated by defaults. So the name ResolvedConfiguration makes more sense. This is the second of several commits to rename the types for our options.
1 parent 23acac0 commit 9cc7d55

37 files changed

+140
-120
lines changed

Diff for: packages/css-blocks/src/Block/AttrValue.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { assertNever, assertNeverCalled } from "@opticss/util";
88

99
import { ATTR_PRESENT } from "../BlockSyntax";
1010
import { OutputMode } from "../OutputMode";
11-
import { ReadonlyOptions } from "../options";
11+
import { ResolvedConfiguration } from "../options";
1212

1313
import { Attribute } from "./Attribute";
1414
import { Block } from "./Block";
@@ -78,7 +78,7 @@ export class AttrValue extends Style<AttrValue, Block, Attribute, never> {
7878
return this.parent.asSource(this.value);
7979
}
8080

81-
public cssClass(opts: ReadonlyOptions): string {
81+
public cssClass(opts: ResolvedConfiguration): string {
8282
switch (opts.outputMode) {
8383
case OutputMode.BEM:
8484
return `${this.parent.cssClass(opts)}${ this.isPresenceRule ? "" : `-${this.value}`}`;

Diff for: packages/css-blocks/src/Block/Attribute.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { assertNever, ObjectDictionary } from "@opticss/util";
1010

1111
import { ATTR_PRESENT, IAttrToken as AttrToken } from "../BlockSyntax";
1212
import { OutputMode } from "../OutputMode";
13-
import { ReadonlyOptions } from "../options";
13+
import { ResolvedConfiguration } from "../options";
1414

1515
import { AttrValue } from "./AttrValue";
1616
import { Block } from "./Block";
@@ -177,7 +177,7 @@ export class Attribute extends Inheritable<Attribute, Block, BlockClass, AttrVal
177177
* @param opts Option hash configuring output mode.
178178
* @returns String representing output class.
179179
*/
180-
cssClass(opts: ReadonlyOptions) {
180+
cssClass(opts: ResolvedConfiguration) {
181181
switch (opts.outputMode) {
182182
case OutputMode.BEM:
183183
let cssClassName = this.blockClass.cssClass(opts);

Diff for: packages/css-blocks/src/Block/Block.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { BlockPath, CLASS_NAME_IDENT, ROOT_CLASS } from "../BlockSyntax";
1919
import { SourceLocation } from "../SourceLocation";
2020
import { CssBlockError, InvalidBlockSyntax } from "../errors";
2121
import { FileIdentifier } from "../importing";
22-
import { ReadonlyOptions } from "../options";
22+
import { ResolvedConfiguration } from "../options";
2323

2424
import { BlockClass } from "./BlockClass";
2525
import { Inheritable } from "./Inheritable";
@@ -367,7 +367,7 @@ export class Block
367367
return null;
368368
}
369369

370-
rewriteSelectorNodes(nodes: selectorParser.Node[], opts: ReadonlyOptions): selectorParser.Node[] {
370+
rewriteSelectorNodes(nodes: selectorParser.Node[], opts: ResolvedConfiguration): selectorParser.Node[] {
371371
let newNodes: selectorParser.Node[] = [];
372372
for (let i = 0; i < nodes.length; i++) {
373373
let node = nodes[i];
@@ -382,7 +382,7 @@ export class Block
382382
return newNodes;
383383
}
384384

385-
rewriteSelectorToString(selector: ParsedSelector, opts: ReadonlyOptions): string {
385+
rewriteSelectorToString(selector: ParsedSelector, opts: ResolvedConfiguration): string {
386386
let firstNewSelector = new CompoundSelector();
387387
let newSelector = firstNewSelector;
388388
let newCurrentSelector = newSelector;
@@ -402,14 +402,14 @@ export class Block
402402
return firstNewSelector.toString();
403403
}
404404

405-
rewriteSelector(selector: ParsedSelector, opts: ReadonlyOptions): ParsedSelector {
405+
rewriteSelector(selector: ParsedSelector, opts: ResolvedConfiguration): ParsedSelector {
406406
// generating a string and re-parsing ensures the internal structure is consistent
407407
// otherwise the parent/next/prev relationships will be wonky with the new nodes.
408408
let s = this.rewriteSelectorToString(selector, opts);
409409
return parseSelector(s)[0];
410410
}
411411

412-
debug(opts: ReadonlyOptions): string[] {
412+
debug(opts: ResolvedConfiguration): string[] {
413413
let result: string[] = [`Source: ${this.identifier}`, this.rootClass.asDebug(opts)];
414414
let sourceNames = new Set<string>(this.all().map(s => s.asSource()));
415415
let sortedNames = [...sourceNames].sort();

Diff for: packages/css-blocks/src/Block/BlockClass.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Attribute as Attr, AttributeValue, attrValues } from "@opticss/element-analysis";
2+
import { assertNever } from "@opticss/util";
23
import { isString } from "util";
34

45
import { ATTR_PRESENT, IAttrToken as AttrToken, ROOT_CLASS } from "../BlockSyntax";
56
import { BlockPath } from "../BlockSyntax";
67
import { OutputMode } from "../OutputMode";
7-
import { ReadonlyOptions } from "../options";
8+
import { ResolvedConfiguration } from "../options";
89

910
import { AttrValue } from "./AttrValue";
1011
import { Attribute } from "./Attribute";
@@ -184,7 +185,7 @@ export class BlockClass extends Style<BlockClass, Block, Block, Attribute> {
184185
* @param opts Option hash configuring output mode.
185186
* @returns String representing output class.
186187
*/
187-
public cssClass(opts: ReadonlyOptions): string {
188+
public cssClass(opts: ResolvedConfiguration): string {
188189
switch (opts.outputMode) {
189190
case OutputMode.BEM:
190191
if (this.isRoot) {
@@ -193,7 +194,7 @@ export class BlockClass extends Style<BlockClass, Block, Block, Attribute> {
193194
return `${this.block.name}__${this.name}`;
194195
}
195196
default:
196-
throw new Error("this never happens");
197+
return assertNever(opts.outputMode);
197198
}
198199
}
199200

@@ -219,7 +220,7 @@ export class BlockClass extends Style<BlockClass, Block, Block, Attribute> {
219220
* @param options Options to pass to BlockClass' asDebug method.
220221
* @return Array of debug strings for this BlockClass
221222
*/
222-
debug(opts: ReadonlyOptions): string[] {
223+
debug(opts: ResolvedConfiguration): string[] {
223224
let result: string[] = [];
224225
for (let style of this.all()) {
225226
result.push(style.asDebug(opts));

Diff for: packages/css-blocks/src/Block/Style.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Attr } from "@opticss/element-analysis";
22

3-
import { ReadonlyOptions } from "../options";
3+
import { ResolvedConfiguration } from "../options";
44
import { unionInto } from "../util/unionInto";
55

66
import { AnyNode, Inheritable } from "./Inheritable";
@@ -41,7 +41,7 @@ export abstract class Style<
4141
* @param opts Option hash configuring output mode.
4242
* @returns The CSS class.
4343
*/
44-
public abstract cssClass(opts: ReadonlyOptions): string;
44+
public abstract cssClass(opts: ResolvedConfiguration): string;
4545

4646
/**
4747
* Return the source selector this `Style` was read from.
@@ -59,7 +59,7 @@ export abstract class Style<
5959
* including inherited classes.
6060
* @returns this object's css class and all inherited classes.
6161
*/
62-
cssClasses(opts: ReadonlyOptions): string[] {
62+
cssClasses(opts: ResolvedConfiguration): string[] {
6363
let classes: string[] = [];
6464
for (let style of this.resolveStyles()) {
6565
classes.push(style.cssClass(opts));
@@ -110,7 +110,7 @@ export abstract class Style<
110110
* @param opts Options for rendering cssClass.
111111
* @returns A debug string.
112112
*/
113-
asDebug(opts: ReadonlyOptions) {
113+
asDebug(opts: ResolvedConfiguration) {
114114
return `${this.asSource()} => ${this.cssClasses(opts).map(n => `.${n}`).join(" ")}`;
115115
}
116116

Diff for: packages/css-blocks/src/BlockCompiler/ConflictResolver.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getBlockNode } from "../BlockParser";
88
import { RESOLVE_RE } from "../BlockSyntax";
99
import { SourceLocation, sourceLocation } from "../SourceLocation";
1010
import * as errors from "../errors";
11-
import { ReadonlyOptions } from "../options";
11+
import { ResolvedConfiguration } from "../options";
1212
import { QueryKeySelector } from "../query";
1313

1414
import { Conflicts, detectConflicts } from "./conflictDetection";
@@ -61,9 +61,9 @@ function updateConflict(t1: ConflictType, t2: ConflictType): ConflictType {
6161
* resolves property values accordingly.
6262
*/
6363
export class ConflictResolver {
64-
readonly opts: ReadonlyOptions;
64+
readonly opts: ResolvedConfiguration;
6565

66-
constructor(opts: ReadonlyOptions) {
66+
constructor(opts: ResolvedConfiguration) {
6767
this.opts = opts;
6868
}
6969

Diff for: packages/css-blocks/src/BlockCompiler/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import {
1010
} from "../BlockSyntax";
1111
import { StyleAnalysis } from "../TemplateAnalysis/StyleAnalysis";
1212
import { normalizeOptions } from "../normalizeOptions";
13-
import { ReadonlyOptions, SparseOptions } from "../options";
13+
import { ResolvedConfiguration, SparseOptions } from "../options";
1414

1515
import { ConflictResolver } from "./ConflictResolver";
1616
/**
1717
* Compiler that, given a Block will return a transformed AST
1818
* interface is `BlockParser.parse`.
1919
*/
2020
export class BlockCompiler {
21-
private opts: ReadonlyOptions;
21+
private opts: ResolvedConfiguration;
2222
private postcss: typeof postcss;
2323

2424
constructor(postcssImpl: typeof postcss, opts?: SparseOptions) {

Diff for: packages/css-blocks/src/BlockParser/BlockFactory.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { RawSourceMap } from "source-map";
77
import { Block } from "../Block";
88
import { FileIdentifier, ImportedFile, Importer } from "../importing";
99
import { normalizeOptions } from "../normalizeOptions";
10-
import { ReadonlyOptions, SparseOptions } from "../options";
10+
import { ResolvedConfiguration, SparseOptions } from "../options";
1111
import { PromiseQueue } from "../util/PromiseQueue";
1212

1313
import { BlockParser, ParsedSource } from "./BlockParser";
@@ -36,7 +36,7 @@ interface ErrorWithErrNum {
3636
export class BlockFactory {
3737
postcssImpl: typeof postcss;
3838
importer: Importer;
39-
options: ReadonlyOptions;
39+
options: ResolvedConfiguration;
4040
blockNames: ObjectDictionary<number>;
4141
parser: BlockParser;
4242
preprocessors: Preprocessors;
@@ -217,7 +217,7 @@ export class BlockFactory {
217217
if (firstPreprocessor) {
218218
if (syntax !== Syntax.css && this.preprocessors.css && !this.options.disablePreprocessChaining) {
219219
let cssProcessor = this.preprocessors.css;
220-
preprocessor = (fullPath: string, content: string, options: ReadonlyOptions): Promise<ProcessedFile> => {
220+
preprocessor = (fullPath: string, content: string, options: ResolvedConfiguration): Promise<ProcessedFile> => {
221221
return firstPreprocessor!(fullPath, content, options).then(result => {
222222
let content = result.content.toString();
223223
return cssProcessor(fullPath, content, options, sourceMapFromProcessedFile(result)).then(result2 => {
@@ -235,7 +235,7 @@ export class BlockFactory {
235235
} else if (syntax !== Syntax.css) {
236236
throw new Error(`No preprocessor provided for ${syntaxName(syntax)}.`);
237237
} else {
238-
preprocessor = (_fullPath: string, content: string, _options: ReadonlyOptions): Promise<ProcessedFile> => {
238+
preprocessor = (_fullPath: string, content: string, _options: ResolvedConfiguration): Promise<ProcessedFile> => {
239239
return Promise.resolve({
240240
content: content,
241241
});

Diff for: packages/css-blocks/src/BlockParser/BlockParser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Block } from "../Block";
44
import * as errors from "../errors";
55
import { FileIdentifier } from "../importing";
66
import { normalizeOptions } from "../normalizeOptions";
7-
import { ReadonlyOptions, SparseOptions } from "../options";
7+
import { ResolvedConfiguration, SparseOptions } from "../options";
88

99
import { assertForeignGlobalAttribute } from "./features/assert-foreign-global-attribute";
1010
import { constructBlock } from "./features/construct-block";
@@ -32,7 +32,7 @@ export interface ParsedSource {
3232
* interface is `BlockParser.parse`.
3333
*/
3434
export class BlockParser {
35-
private opts: ReadonlyOptions;
35+
private opts: ResolvedConfiguration;
3636
private factory: BlockFactory;
3737

3838
constructor(opts: SparseOptions, factory: BlockFactory) {

Diff for: packages/css-blocks/src/BlockParser/features/process-debug-statements.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import * as postcss from "postcss";
33

44
import { Block } from "../../Block";
55
import { BLOCK_DEBUG, parseBlockDebug } from "../../BlockSyntax";
6-
import { ReadonlyOptions } from "../../options";
6+
import { ResolvedConfiguration } from "../../options";
77

88
/**
99
* Process all `@block-debug` statements, output debug statement to console or in comment as requested.
1010
* @param sourceFile File name of block in question.
1111
* @param root PostCSS Root for block.
1212
* @param block Block to resolve references for
1313
*/
14-
export async function processDebugStatements(root: postcss.Root, block: Block, file: string, opts: ReadonlyOptions) {
14+
export async function processDebugStatements(root: postcss.Root, block: Block, file: string, opts: ResolvedConfiguration) {
1515
root.walkAtRules(BLOCK_DEBUG, (atRule) => {
1616
let { block: ref, channel } = parseBlockDebug(atRule, file, block);
1717
let debugStr = ref.debug(opts);

Diff for: packages/css-blocks/src/BlockParser/preprocessing.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "source-map";
66

77
import {
8-
ReadonlyOptions,
8+
ResolvedConfiguration,
99
} from "../options";
1010

1111
export enum Syntax {
@@ -41,7 +41,7 @@ export interface ProcessedFile {
4141
}
4242

4343
// export type ContentPreprocessor = (content: string) => Promise<ProcessedFile>;
44-
export type Preprocessor = (fullPath: string, content: string, options: ReadonlyOptions, sourceMap?: RawSourceMap | string) => Promise<ProcessedFile>;
44+
export type Preprocessor = (fullPath: string, content: string, options: ResolvedConfiguration, sourceMap?: RawSourceMap | string) => Promise<ProcessedFile>;
4545

4646
/**
4747
* A map of supported syntaxes to the preprocessor function for that syntax.

Diff for: packages/css-blocks/src/Plugin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { BlockCompiler } from "./BlockCompiler";
44
import { BlockFactory } from "./BlockParser";
55
import * as errors from "./errors";
66
import { normalizeOptions } from "./normalizeOptions";
7-
import { ReadonlyOptions, SparseOptions } from "./options";
7+
import { ResolvedConfiguration, SparseOptions } from "./options";
88
export { SparseOptions } from "./options";
99

1010
/**
1111
* CSS Blocks PostCSS plugin.
1212
*/
1313
export class Plugin {
14-
private opts: ReadonlyOptions;
14+
private opts: ResolvedConfiguration;
1515
private postcss: typeof postcss;
1616

1717
/**

Diff for: packages/css-blocks/src/TemplateAnalysis/ElementAnalysis.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
Style,
3131
} from "../Block";
3232
import {
33-
ReadonlyOptions,
33+
ResolvedConfiguration,
3434
} from "../options";
3535
import {
3636
unionInto,
@@ -606,7 +606,7 @@ export class ElementAnalysis<BooleanExpression, StringExpression, TernaryExpress
606606
* assumed to be unique per Style across all blocks -- so these
607607
* maps can be merged safely.
608608
*/
609-
forOptimizer(options: ReadonlyOptions): [Element, Map<string, Style>] {
609+
forOptimizer(options: ResolvedConfiguration): [Element, Map<string, Style>] {
610610
this.assertSealed();
611611
let tagValue = this.tagName ? attrValues.constant(this.tagName) : attrValues.unknown();
612612
let tagName = new Tagname(tagValue);
@@ -770,7 +770,7 @@ function addToSet(
770770

771771
type ClassMapper = (style: Style) => ValueConstant | AttributeValueSet;
772772
function mapClasses(
773-
options: ReadonlyOptions,
773+
options: ResolvedConfiguration,
774774
map: Map<string, Style>,
775775
style: Style,
776776
): ValueConstant | AttributeValueSet {
@@ -790,7 +790,7 @@ function mapClasses(
790790

791791
type ChoiceMapper = (includeAbsent: boolean, ...styles: Style[]) => AttributeValueChoice;
792792
function mapChoiceClasses(
793-
options: ReadonlyOptions,
793+
options: ResolvedConfiguration,
794794
map: Map<string, Style>,
795795
includeAbsent: boolean,
796796
...styles: Style[],

Diff for: packages/css-blocks/src/TemplateAnalysis/MetaAnalysis.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { whatever } from "@opticss/util";
77
import * as debugGenerator from "debug";
88

99
import { Block, Style } from "../Block";
10-
import { ReadonlyOptions } from "../options";
10+
import { ResolvedConfiguration } from "../options";
1111

1212
import { StyleAnalysis } from "./StyleAnalysis";
1313
import { SerializedTemplateAnalysis, TemplateAnalysis } from "./index";
@@ -108,7 +108,7 @@ export class MetaTemplateAnalysis implements StyleAnalysis {
108108
return { analyses };
109109
}
110110

111-
forOptimizer(opts: ReadonlyOptions): Array<OptimizedTemplateAnalysis<keyof TemplateTypes>> {
111+
forOptimizer(opts: ResolvedConfiguration): Array<OptimizedTemplateAnalysis<keyof TemplateTypes>> {
112112
let analyses = new Array<OptimizedTemplateAnalysis<keyof TemplateTypes>>();
113113
this.eachAnalysis(a => {
114114
analyses.push(a.forOptimizer(opts));

Diff for: packages/css-blocks/src/TemplateAnalysis/TemplateAnalysis.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { IdentGenerator } from "opticss";
2121

2222
import { Block, Style } from "../Block";
2323
import { BlockFactory } from "../BlockParser";
24-
import { ReadonlyOptions } from "../options";
24+
import { ResolvedConfiguration } from "../options";
2525

2626
import { ElementAnalysis, SerializedElementAnalysis } from "./ElementAnalysis";
2727
import { StyleAnalysis } from "./StyleAnalysis";
@@ -368,7 +368,7 @@ export class TemplateAnalysis<K extends keyof TemplateTypes> implements StyleAna
368368
});
369369
}
370370

371-
forOptimizer(opts: ReadonlyOptions): OptimizationTemplateAnalysis<K> {
371+
forOptimizer(opts: ResolvedConfiguration): OptimizationTemplateAnalysis<K> {
372372
let optAnalysis = new OptimizationTemplateAnalysis<K>(this.template);
373373
for (let element of this.elements.values()) {
374374
let result = element.forOptimizer(opts);

Diff for: packages/css-blocks/src/TemplateRewriter/StyleMapping.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { StyleMapping as OptimizedMapping, TemplateTypes } from "@opticss/templa
33
import { Block, Style } from "../Block";
44
import { TemplateAnalysis } from "../TemplateAnalysis";
55
import { ElementAnalysis } from "../TemplateAnalysis/ElementAnalysis";
6-
import { ReadonlyOptions } from "../options";
6+
import { ResolvedConfiguration } from "../options";
77

88
import { IndexedClassRewrite } from "./ClassRewrite";
99
import { IndexedClassMapping, RewriteMapping } from "./RewriteMapping";
@@ -12,13 +12,13 @@ export class StyleMapping {
1212
analyses: Array<TemplateAnalysis<keyof TemplateTypes>> | undefined;
1313
/** The blocks that were used to create this mapping. */
1414
blocks: Set<Block>;
15-
private options: ReadonlyOptions;
15+
private options: ResolvedConfiguration;
1616
private optimizedMap: OptimizedMapping;
1717

1818
constructor(
1919
optimizedMap: OptimizedMapping,
2020
blocks: Iterable<Block>,
21-
options: ReadonlyOptions,
21+
options: ResolvedConfiguration,
2222
analyses?: Array<TemplateAnalysis<keyof TemplateTypes>>,
2323
) {
2424
this.options = options;

0 commit comments

Comments
 (0)