Skip to content

Commit 72e7b5a

Browse files
committed
chore: Rename variables of type ResolvedConfiguration.
1 parent 9cc7d55 commit 72e7b5a

19 files changed

+116
-116
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ export class AttrValue extends Style<AttrValue, Block, Attribute, never> {
7878
return this.parent.asSource(this.value);
7979
}
8080

81-
public cssClass(opts: ResolvedConfiguration): string {
82-
switch (opts.outputMode) {
81+
public cssClass(config: ResolvedConfiguration): string {
82+
switch (config.outputMode) {
8383
case OutputMode.BEM:
84-
return `${this.parent.cssClass(opts)}${ this.isPresenceRule ? "" : `-${this.value}`}`;
84+
return `${this.parent.cssClass(config)}${ this.isPresenceRule ? "" : `-${this.value}`}`;
8585
default:
86-
return assertNever(opts.outputMode);
86+
return assertNever(config.outputMode);
8787
}
8888
}
8989

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,16 @@ export class Attribute extends Inheritable<Attribute, Block, BlockClass, AttrVal
174174

175175
/**
176176
* Export as new class name.
177-
* @param opts Option hash configuring output mode.
177+
* @param config Option hash configuring output mode.
178178
* @returns String representing output class.
179179
*/
180-
cssClass(opts: ResolvedConfiguration) {
181-
switch (opts.outputMode) {
180+
cssClass(config: ResolvedConfiguration) {
181+
switch (config.outputMode) {
182182
case OutputMode.BEM:
183-
let cssClassName = this.blockClass.cssClass(opts);
183+
let cssClassName = this.blockClass.cssClass(config);
184184
return `${cssClassName}--${this.token.name}`;
185185
default:
186-
return assertNever(opts.outputMode);
186+
return assertNever(config.outputMode);
187187
}
188188
}
189189

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -367,28 +367,28 @@ export class Block
367367
return null;
368368
}
369369

370-
rewriteSelectorNodes(nodes: selectorParser.Node[], opts: ResolvedConfiguration): selectorParser.Node[] {
370+
rewriteSelectorNodes(nodes: selectorParser.Node[], config: ResolvedConfiguration): selectorParser.Node[] {
371371
let newNodes: selectorParser.Node[] = [];
372372
for (let i = 0; i < nodes.length; i++) {
373373
let node = nodes[i];
374374
let result = this.nodeAsStyle(node);
375375
if (result === null) {
376376
newNodes.push(node);
377377
} else {
378-
newNodes.push(selectorParser.className({ value: result[0].cssClass(opts) }));
378+
newNodes.push(selectorParser.className({ value: result[0].cssClass(config) }));
379379
i += result[1];
380380
}
381381
}
382382
return newNodes;
383383
}
384384

385-
rewriteSelectorToString(selector: ParsedSelector, opts: ResolvedConfiguration): string {
385+
rewriteSelectorToString(selector: ParsedSelector, config: ResolvedConfiguration): string {
386386
let firstNewSelector = new CompoundSelector();
387387
let newSelector = firstNewSelector;
388388
let newCurrentSelector = newSelector;
389389
let currentSelector: CompoundSelector | undefined = selector.selector;
390390
do {
391-
newCurrentSelector.nodes = this.rewriteSelectorNodes(currentSelector.nodes, opts);
391+
newCurrentSelector.nodes = this.rewriteSelectorNodes(currentSelector.nodes, config);
392392
newCurrentSelector.pseudoelement = currentSelector.pseudoelement;
393393
if (currentSelector.next !== undefined) {
394394
let tempSel = newCurrentSelector;
@@ -402,21 +402,21 @@ export class Block
402402
return firstNewSelector.toString();
403403
}
404404

405-
rewriteSelector(selector: ParsedSelector, opts: ResolvedConfiguration): ParsedSelector {
405+
rewriteSelector(selector: ParsedSelector, config: 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.
408-
let s = this.rewriteSelectorToString(selector, opts);
408+
let s = this.rewriteSelectorToString(selector, config);
409409
return parseSelector(s)[0];
410410
}
411411

412-
debug(opts: ResolvedConfiguration): string[] {
413-
let result: string[] = [`Source: ${this.identifier}`, this.rootClass.asDebug(opts)];
412+
debug(config: ResolvedConfiguration): string[] {
413+
let result: string[] = [`Source: ${this.identifier}`, this.rootClass.asDebug(config)];
414414
let sourceNames = new Set<string>(this.all().map(s => s.asSource()));
415415
let sortedNames = [...sourceNames].sort();
416416
for (let n of sortedNames) {
417417
if (n !== ROOT_CLASS) {
418418
let o = this.find(n) as Styles;
419-
result.push(o.asDebug(opts));
419+
result.push(o.asDebug(config));
420420
}
421421
}
422422
return result;

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,19 @@ export class BlockClass extends Style<BlockClass, Block, Block, Attribute> {
182182

183183
/**
184184
* Export as new class name.
185-
* @param opts Option hash configuring output mode.
185+
* @param config Option hash configuring output mode.
186186
* @returns String representing output class.
187187
*/
188-
public cssClass(opts: ResolvedConfiguration): string {
189-
switch (opts.outputMode) {
188+
public cssClass(config: ResolvedConfiguration): string {
189+
switch (config.outputMode) {
190190
case OutputMode.BEM:
191191
if (this.isRoot) {
192192
return `${this.block.name}`;
193193
} else {
194194
return `${this.block.name}__${this.name}`;
195195
}
196196
default:
197-
return assertNever(opts.outputMode);
197+
return assertNever(config.outputMode);
198198
}
199199
}
200200

@@ -220,10 +220,10 @@ export class BlockClass extends Style<BlockClass, Block, Block, Attribute> {
220220
* @param options Options to pass to BlockClass' asDebug method.
221221
* @return Array of debug strings for this BlockClass
222222
*/
223-
debug(opts: ResolvedConfiguration): string[] {
223+
debug(config: ResolvedConfiguration): string[] {
224224
let result: string[] = [];
225225
for (let style of this.all()) {
226-
result.push(style.asDebug(opts));
226+
result.push(style.asDebug(config));
227227
}
228228
return result;
229229
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ export abstract class Style<
3838

3939
/**
4040
* Return the css selector for this `Style`.
41-
* @param opts Option hash configuring output mode.
41+
* @param config Option hash configuring output mode.
4242
* @returns The CSS class.
4343
*/
44-
public abstract cssClass(opts: ResolvedConfiguration): string;
44+
public abstract cssClass(config: ResolvedConfiguration): string;
4545

4646
/**
4747
* Return the source selector this `Style` was read from.
@@ -59,10 +59,10 @@ export abstract class Style<
5959
* including inherited classes.
6060
* @returns this object's css class and all inherited classes.
6161
*/
62-
cssClasses(opts: ResolvedConfiguration): string[] {
62+
cssClasses(config: ResolvedConfiguration): string[] {
6363
let classes: string[] = [];
6464
for (let style of this.resolveStyles()) {
65-
classes.push(style.cssClass(opts));
65+
classes.push(style.cssClass(config));
6666
}
6767
return classes;
6868
}
@@ -107,11 +107,11 @@ export abstract class Style<
107107

108108
/**
109109
* Debug utility to help log Styles
110-
* @param opts Options for rendering cssClass.
110+
* @param config Options for rendering cssClass.
111111
* @returns A debug string.
112112
*/
113-
asDebug(opts: ResolvedConfiguration) {
114-
return `${this.asSource()} => ${this.cssClasses(opts).map(n => `.${n}`).join(" ")}`;
113+
asDebug(config: ResolvedConfiguration) {
114+
return `${this.asSource()} => ${this.cssClasses(config).map(n => `.${n}`).join(" ")}`;
115115
}
116116

117117
// TypeScript can't figure out that `this` is the `StyleType` so this private

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ function updateConflict(t1: ConflictType, t2: ConflictType): ConflictType {
6161
* resolves property values accordingly.
6262
*/
6363
export class ConflictResolver {
64-
readonly opts: ResolvedConfiguration;
64+
readonly config: ResolvedConfiguration;
6565

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

7070
/**
@@ -242,7 +242,7 @@ export class ConflictResolver {
242242
// we reverse the selectors because otherwise the insertion order causes them to be backwards from the
243243
// source order of the target selector
244244
resultSelectors.reverse().forEach((s) => {
245-
let newSelectors = this.mergeKeySelectors(other.block.rewriteSelector(s.parsedSelector, this.opts), cs);
245+
let newSelectors = this.mergeKeySelectors(other.block.rewriteSelector(s.parsedSelector, this.config), cs);
246246
if (newSelectors === null) return;
247247
let newSelStr = newSelectors.join(",\n");
248248
// avoid duplicate selector via permutation
@@ -416,7 +416,7 @@ export class ConflictResolver {
416416
return mergedSelectors.map(sel => new ParsedSelector(sel));
417417
}
418418
sourceLocation(block: Block, node: postcss.Node): SourceLocation | undefined {
419-
let blockPath = this.opts.importer.debugIdentifier(block.identifier, this.opts);
419+
let blockPath = this.config.importer.debugIdentifier(block.identifier, this.config);
420420
return sourceLocation(blockPath, node);
421421
}
422422
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ import { ConflictResolver } from "./ConflictResolver";
1818
* interface is `BlockParser.parse`.
1919
*/
2020
export class BlockCompiler {
21-
private opts: ResolvedConfiguration;
21+
private config: ResolvedConfiguration;
2222
private postcss: typeof postcss;
2323

2424
constructor(postcssImpl: typeof postcss, opts?: SparseOptions) {
25-
this.opts = normalizeOptions(opts);
25+
this.config = normalizeOptions(opts);
2626
this.postcss = postcssImpl;
2727
}
2828

2929
compile(block: Block, root: postcss.Root, analysis?: StyleAnalysis): postcss.Root {
3030
if (analysis) {
3131
// console.log("Got an analysis for compilation. I should use it probably.", analysis);
3232
}
33-
let resolver = new ConflictResolver(this.opts);
34-
let filename = this.opts.importer.debugIdentifier(block.identifier, this.opts);
33+
let resolver = new ConflictResolver(this.config);
34+
let filename = this.config.importer.debugIdentifier(block.identifier, this.config);
3535

3636
// Process all debug statements for this block.
3737
this.processDebugStatements(filename, root, block);
@@ -53,7 +53,7 @@ export class BlockCompiler {
5353
resolver.resolveInheritance(root, block);
5454
root.walkRules((rule) => {
5555
let parsedSelectors = block.getParsedSelectors(rule);
56-
rule.selector = parsedSelectors.map(s => block.rewriteSelectorToString(s, this.opts)).join(",\n");
56+
rule.selector = parsedSelectors.map(s => block.rewriteSelectorToString(s, this.config)).join(",\n");
5757
});
5858

5959
resolver.resolve(root, block);
@@ -71,7 +71,7 @@ export class BlockCompiler {
7171
root.walkAtRules(BLOCK_DEBUG, (atRule) => {
7272
let {block: ref, channel} = parseBlockDebug(atRule, sourceFile, block);
7373
if (channel === "comment") {
74-
let debugStr = ref.debug(this.opts);
74+
let debugStr = ref.debug(this.config);
7575
atRule.replaceWith(this.postcss.comment({text: debugStr.join("\n ")}));
7676
} else {
7777
// stderr/stdout are emitted during parse.

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

+16-16
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface ErrorWithErrNum {
3636
export class BlockFactory {
3737
postcssImpl: typeof postcss;
3838
importer: Importer;
39-
options: ResolvedConfiguration;
39+
configuration: ResolvedConfiguration;
4040
blockNames: ObjectDictionary<number>;
4141
parser: BlockParser;
4242
preprocessors: Preprocessors;
@@ -48,16 +48,16 @@ export class BlockFactory {
4848

4949
constructor(options: SparseOptions, postcssImpl = postcss) {
5050
this.postcssImpl = postcssImpl;
51-
this.options = normalizeOptions(options);
52-
this.importer = this.options.importer;
53-
this.preprocessors = this.options.preprocessors;
51+
this.configuration = normalizeOptions(options);
52+
this.importer = this.configuration.importer;
53+
this.preprocessors = this.configuration.preprocessors;
5454
this.parser = new BlockParser(options, this);
5555
this.blocks = {};
5656
this.blockNames = {};
5757
this.promises = {};
5858
this.paths = {};
59-
this.preprocessQueue = new PromiseQueue(this.options.maxConcurrentCompiles, (item: PreprocessJob) => {
60-
return item.preprocessor(item.filename, item.contents, this.options);
59+
this.preprocessQueue = new PromiseQueue(this.configuration.maxConcurrentCompiles, (item: PreprocessJob) => {
60+
return item.preprocessor(item.filename, item.contents, this.configuration);
6161
});
6262
}
6363

@@ -95,7 +95,7 @@ export class BlockFactory {
9595
let identifier: FileIdentifier | undefined = this.paths[filePath];
9696
if (identifier && this.promises[identifier]) { return this.promises[identifier]; }
9797

98-
identifier = identifier || this.importer.identifier(null, filePath, this.options);
98+
identifier = identifier || this.importer.identifier(null, filePath, this.configuration);
9999
return this._getBlockPromise(identifier);
100100
}
101101

@@ -106,13 +106,13 @@ export class BlockFactory {
106106

107107
_getBlockPromise(identifier: FileIdentifier): Promise<Block> {
108108

109-
return this.promises[identifier] = this.importer.import(identifier, this.options)
109+
return this.promises[identifier] = this.importer.import(identifier, this.configuration)
110110

111111
// Parse the file into a `Block`.
112112
.then(file => {
113113

114114
// If the file identifier maps back to a real filename, ensure it is actually unique.
115-
let realFilename = this.importer.filesystemPath(file.identifier, this.options);
115+
let realFilename = this.importer.filesystemPath(file.identifier, this.configuration);
116116
if (realFilename) {
117117
if (this.paths[realFilename] && this.paths[realFilename] !== file.identifier) {
118118
throw new Error(`The same block file was returned with different identifiers: ${this.paths[realFilename]} and ${file.identifier}`);
@@ -125,7 +125,7 @@ export class BlockFactory {
125125
if (this.blocks[file.identifier]) { return this.blocks[file.identifier]; }
126126

127127
// Preprocess the file.
128-
let filename: string = realFilename || this.importer.debugIdentifier(file.identifier, this.options);
128+
let filename: string = realFilename || this.importer.debugIdentifier(file.identifier, this.configuration);
129129
let preprocessor = this.preprocessor(file);
130130
return this.preprocessQueue.enqueue({
131131
preprocessor,
@@ -187,8 +187,8 @@ export class BlockFactory {
187187

188188
getBlockRelative(fromIdentifier: FileIdentifier, importPath: string): Promise<Block> {
189189
let importer = this.importer;
190-
let fromPath = importer.debugIdentifier(fromIdentifier, this.options);
191-
let identifier = importer.identifier(fromIdentifier, importPath, this.options);
190+
let fromPath = importer.debugIdentifier(fromIdentifier, this.configuration);
191+
let identifier = importer.identifier(fromIdentifier, importPath, this.configuration);
192192
return this.getBlock(identifier).catch((err: ErrorWithErrNum) => {
193193
if (err.code === "ENOENT") {
194194
err.message = `From ${fromPath}: ${err.message}`;
@@ -215,12 +215,12 @@ export class BlockFactory {
215215
let firstPreprocessor: Preprocessor | undefined = this.preprocessors[syntax];
216216
let preprocessor: Preprocessor | null = null;
217217
if (firstPreprocessor) {
218-
if (syntax !== Syntax.css && this.preprocessors.css && !this.options.disablePreprocessChaining) {
218+
if (syntax !== Syntax.css && this.preprocessors.css && !this.configuration.disablePreprocessChaining) {
219219
let cssProcessor = this.preprocessors.css;
220-
preprocessor = (fullPath: string, content: string, options: ResolvedConfiguration): Promise<ProcessedFile> => {
221-
return firstPreprocessor!(fullPath, content, options).then(result => {
220+
preprocessor = (fullPath: string, content: string, configuration: ResolvedConfiguration): Promise<ProcessedFile> => {
221+
return firstPreprocessor!(fullPath, content, configuration).then(result => {
222222
let content = result.content.toString();
223-
return cssProcessor(fullPath, content, options, sourceMapFromProcessedFile(result)).then(result2 => {
223+
return cssProcessor(fullPath, content, configuration, sourceMapFromProcessedFile(result)).then(result2 => {
224224
return {
225225
content: result2.content,
226226
sourceMap: sourceMapFromProcessedFile(result2),

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export interface ParsedSource {
3232
* interface is `BlockParser.parse`.
3333
*/
3434
export class BlockParser {
35-
private opts: ResolvedConfiguration;
35+
private config: ResolvedConfiguration;
3636
private factory: BlockFactory;
3737

3838
constructor(opts: SparseOptions, factory: BlockFactory) {
39-
this.opts = normalizeOptions(opts);
39+
this.config = normalizeOptions(opts);
4040
this.factory = factory;
4141
}
4242

@@ -60,9 +60,9 @@ export class BlockParser {
6060
* @param defaultName Name of block
6161
*/
6262
public async parse(root: postcss.Root, identifier: string, name: string): Promise<Block> {
63-
let importer = this.opts.importer;
64-
let debugIdent = importer.debugIdentifier(identifier, this.opts);
65-
let sourceFile = importer.filesystemPath(identifier, this.opts) || debugIdent;
63+
let importer = this.config.importer;
64+
let debugIdent = importer.debugIdentifier(identifier, this.config);
65+
let sourceFile = importer.filesystemPath(identifier, this.config) || debugIdent;
6666

6767
// Discover the block's preferred name.
6868
name = await discoverName(root, name, sourceFile);
@@ -86,7 +86,7 @@ export class BlockParser {
8686
// Validate that all required Styles are implemented.
8787
await implementBlock(root, block, debugIdent);
8888
// Log any debug statements discovered.
89-
await processDebugStatements(root, block, debugIdent, this.opts);
89+
await processDebugStatements(root, block, debugIdent, this.config);
9090

9191
// Return our fully constructed block.
9292
return block;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { ResolvedConfiguration } from "../../options";
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: ResolvedConfiguration) {
14+
export async function processDebugStatements(root: postcss.Root, block: Block, file: string, config: ResolvedConfiguration) {
1515
root.walkAtRules(BLOCK_DEBUG, (atRule) => {
1616
let { block: ref, channel } = parseBlockDebug(atRule, file, block);
17-
let debugStr = ref.debug(opts);
17+
let debugStr = ref.debug(config);
1818
if (channel !== "comment") {
1919
if (channel === "stderr") {
2020
console.warn(debugStr.join("\n"));

0 commit comments

Comments
 (0)