@@ -23,10 +23,8 @@ import { FileIdentifier } from "../importing";
2323import { LocalScopedContext } from "../util/LocalScope" ;
2424
2525import { BlockClass } from "./BlockClass" ;
26- import { SourceContainer } from "./BlockTree" ;
27- import { State } from "./State" ;
28-
29- export type Style = BlockClass | State ;
26+ import { Inheritable } from "./Inheritable" ;
27+ import { Styles } from "./Styles" ;
3028
3129export const OBJ_REF_SPLITTER = ( s : string ) : [ string , string ] | undefined => {
3230 let index = s . indexOf ( "." ) ;
@@ -37,13 +35,13 @@ export const OBJ_REF_SPLITTER = (s: string): [string, string] | undefined => {
3735 return ;
3836} ;
3937
40- export class Block extends SourceContainer < Block , BlockClass > {
38+ export class Block extends Inheritable < Block , Block , never , BlockClass > {
4139 private _rootClass : BlockClass ;
4240 private _blockReferences : ObjectDictionary < Block > = { } ;
4341 private _blockReferencesReverseLookup : Map < Block , string > = new Map ( ) ;
4442 private _identifier : FileIdentifier ;
4543 private _implements : Block [ ] = [ ] ;
46- private _localScope : LocalScopedContext < Block , Style > ;
44+ private _localScope : LocalScopedContext < Block , Styles > ;
4745 private hasHadNameReset = false ;
4846 /**
4947 * array of paths that this block depends on and, if changed, would
@@ -59,12 +57,14 @@ export class Block extends SourceContainer<Block, BlockClass> {
5957 super ( name ) ;
6058 this . _identifier = identifier ;
6159 this . parsedRuleSelectors = new WeakMap ( ) ;
62- this . _localScope = new LocalScopedContext < Block , Style > ( OBJ_REF_SPLITTER , this ) ;
60+ this . _localScope = new LocalScopedContext < Block , Styles > ( OBJ_REF_SPLITTER , this ) ;
6361 this . _dependencies = new Set < string > ( ) ;
6462 this . _rootClass = new BlockClass ( ROOT_CLASS , this ) ;
6563 this . addClass ( this . _rootClass ) ;
6664 }
6765
66+ get block ( ) : Block { return this . root ; }
67+
6868 get name ( ) { return this . _name ; }
6969 set name ( name : string ) {
7070 if ( this . hasHadNameReset ) {
@@ -79,7 +79,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
7979 }
8080
8181 /// Start of methods to implement LocalScope<Block, Style>
82- subScope ( name : string ) : LocalScopedContext < Block , Style > | undefined {
82+ subScope ( name : string ) : LocalScopedContext < Block , Styles > | undefined {
8383 let block = this . _blockReferences [ name ] ;
8484 if ( block ) {
8585 return block . _localScope ;
@@ -88,7 +88,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
8888 }
8989 }
9090
91- lookupLocal ( name : string ) : Style | undefined {
91+ lookupLocal ( name : string ) : Styles | undefined {
9292 let blockRef = this . _blockReferences [ name ] ;
9393 if ( blockRef ) {
9494 return blockRef . rootClass ;
@@ -118,7 +118,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
118118 * A single dot by itself returns the current block.
119119 * @returns The Style referenced at the supplied path.
120120 */
121- public lookup ( path : string | BlockPath , errLoc ?: SourceLocation ) : Style | undefined {
121+ public lookup ( path : string | BlockPath , errLoc ?: SourceLocation ) : Styles | undefined {
122122 path = new BlockPath ( path ) ;
123123 let block = this . getReferencedBlock ( path . block ) ;
124124 if ( ! block ) {
@@ -183,8 +183,8 @@ export class Block extends SourceContainer<Block, BlockClass> {
183183 * @param b The block to check implementation against.
184184 * @returns The Styles from b that are missing in the block.
185185 */
186- checkImplementation ( b : Block ) : Style [ ] {
187- let missing : Style [ ] = [ ] ;
186+ checkImplementation ( b : Block ) : Styles [ ] {
187+ let missing : Styles [ ] = [ ] ;
188188 for ( let o of b . all ( ) ) {
189189 if ( ! this . find ( o . asSource ( ) ) ) {
190190 missing . push ( o ) ;
@@ -198,7 +198,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
198198 */
199199 checkImplementations ( ) : void {
200200 for ( let b of this . getImplementedBlocks ( ) ) {
201- let missing : Style [ ] = this . checkImplementation ( b ) ;
201+ let missing : Styles [ ] = this . checkImplementation ( b ) ;
202202 let paths = missing . map ( o => o . asSource ( ) ) . join ( ", " ) ;
203203 if ( missing . length > 0 ) {
204204 let s = missing . length > 1 ? "s" : "" ;
@@ -208,7 +208,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
208208 }
209209
210210 // This is a really dumb impl
211- find ( sourceName : string ) : Style | undefined {
211+ find ( sourceName : string ) : Styles | undefined {
212212 let blockRefName : string | undefined ;
213213 let md = sourceName . match ( CLASS_NAME_IDENT ) ;
214214 if ( md && md . index === 0 ) {
@@ -284,8 +284,8 @@ export class Block extends SourceContainer<Block, BlockClass> {
284284 * @param shallow Pass true to not include inherited objects.
285285 * @returns Array of Styles.
286286 */
287- all ( shallow ?: boolean ) : Style [ ] {
288- let result = new Array < Style > ( ) ;
287+ all ( shallow ?: boolean ) : Styles [ ] {
288+ let result = new Array < Styles > ( ) ;
289289 for ( let blockClass of this . classes ) {
290290 result . push ( ...blockClass . all ( ) ) ;
291291 }
@@ -295,8 +295,8 @@ export class Block extends SourceContainer<Block, BlockClass> {
295295 return result ;
296296 }
297297
298- merged ( ) : MultiMap < string , Style > {
299- let map = new MultiMap < string , Style > ( false ) ;
298+ merged ( ) : MultiMap < string , Styles > {
299+ let map = new MultiMap < string , Styles > ( false ) ;
300300 for ( let obj of this . all ( ) ) {
301301 map . set ( obj . asSource ( ) , obj ) ;
302302 }
@@ -307,7 +307,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
307307 * Fetch a the cached `Style` from `Block` given `NodeAndType`.
308308 * @param obj The `NodeAndType` object to use for `Style` lookup.
309309 */
310- nodeAndTypeToStyle ( obj : NodeAndType ) : Style | null {
310+ nodeAndTypeToStyle ( obj : NodeAndType ) : Styles | null {
311311 switch ( obj . blockType ) {
312312 case BlockType . root :
313313 return this . rootClass ;
@@ -327,7 +327,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
327327 }
328328 }
329329
330- nodeAsStyle ( node : selectorParser . Node ) : [ Style , number ] | null {
330+ nodeAsStyle ( node : selectorParser . Node ) : [ Styles , number ] | null {
331331 if ( node . type === selectorParser . CLASS && node . value === ROOT_CLASS ) {
332332 return [ this . rootClass , 0 ] ;
333333 } else if ( node . type === selectorParser . TAG ) {
@@ -444,7 +444,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
444444 let sortedNames = [ ...sourceNames ] . sort ( ) ;
445445 for ( let n of sortedNames ) {
446446 if ( n !== `.${ ROOT_CLASS } ` ) {
447- let o = this . find ( n ) as Style ;
447+ let o = this . find ( n ) as Styles ;
448448 result . push ( o . asDebug ( opts ) ) ;
449449 }
450450 }
0 commit comments