@@ -45,7 +45,7 @@ export class HtmlTemplate implements ElementUpdater {
45
45
* @param strings the strings as passed to the `html` string tag
46
46
* @param data the data arguments as passed to the `html` string tag
47
47
*/
48
- constructor ( private readonly strings : TemplateStringsArray , public data : ReadonlyArray < any > ) { }
48
+ constructor ( private readonly strings : TemplateStringsArray , public data : ReadonlyArray < unknown > ) { }
49
49
50
50
/**
51
51
* Generates a string containing the HTML markup as described by the strings array
@@ -118,9 +118,9 @@ export class HtmlTemplate implements ElementUpdater {
118
118
}
119
119
}
120
120
121
- const PlaceholderAttributeRegex = / ( [ . ? @ ] ? [ a - z 0 - 9 - _ @ ] + ) \s * = \s * $ / i;
122
- const PlaceholderSingleQuotedAttributeRegex = / ( [ . ? @ ] ? [ a - z 0 - 9 - _ @ ] + ) \s * = \s * ' [ ^ ' ] * $ / i;
123
- const PlaceholderDoubleQuotedAttributeRegex = / ( [ . ? @ ] ? [ a - z 0 - 9 - _ @ ] + ) \s * = \s * " [ ^ " ] * $ / i;
121
+ const PlaceholderAttributeRegex = / ( [ . ? @ ] ? [ a - z 0 - 9 - _ @ ] + ) \s * = \s * $ / i
122
+ const PlaceholderSingleQuotedAttributeRegex = / ( [ . ? @ ] ? [ a - z 0 - 9 - _ @ ] + ) \s * = \s * ' [ ^ ' ] * $ / i
123
+ const PlaceholderDoubleQuotedAttributeRegex = / ( [ . ? @ ] ? [ a - z 0 - 9 - _ @ ] + ) \s * = \s * " [ ^ " ] * $ / i
124
124
125
125
/**
126
126
* Generates a HTML markup string from the given static string parts.
@@ -159,7 +159,7 @@ function generateHtml(strings: TemplateStringsArray): [string, Map<string, strin
159
159
* into an element but the rendered content is modified by some external DOM
160
160
* operations when applying the insert.
161
161
*/
162
- const DomInconsistencyError = ` DOM inconsistency error`
162
+ const DomInconsistencyError = " DOM inconsistency error"
163
163
164
164
/**
165
165
* A `Binding` defines how to apply a placeholder's value to the DOM.
@@ -185,7 +185,7 @@ interface Binding {
185
185
*
186
186
* @param data all placeholder values
187
187
*/
188
- applyData ( data : ReadonlyArray < any > ) : void
188
+ applyData ( data : ReadonlyArray < unknown > ) : void
189
189
}
190
190
191
191
/**
@@ -233,7 +233,7 @@ abstract class BindingBase implements Binding {
233
233
this . node = node
234
234
}
235
235
236
- abstract applyData ( data : ReadonlyArray < any > ) : void
236
+ abstract applyData ( data : ReadonlyArray < unknown > ) : void
237
237
}
238
238
239
239
/**
@@ -242,7 +242,7 @@ abstract class BindingBase implements Binding {
242
242
* only when data changes.
243
243
*/
244
244
abstract class SingleDataIndexBindingBase extends BindingBase {
245
- protected boundData : any
245
+ protected boundData : unknown
246
246
247
247
constructor ( nodeIndex : number , protected readonly dataIndex : number ) {
248
248
super ( nodeIndex )
@@ -254,7 +254,7 @@ abstract class SingleDataIndexBindingBase extends BindingBase {
254
254
* data updates.
255
255
* @param data the data array
256
256
*/
257
- applyData ( data : Array < any > ) : void {
257
+ applyData ( data : Array < unknown > ) : void {
258
258
const dataItem = data [ this . dataIndex ]
259
259
260
260
if ( this . boundData === dataItem ) {
@@ -270,7 +270,7 @@ abstract class SingleDataIndexBindingBase extends BindingBase {
270
270
* Called by `applyData` when a change in data is detected.
271
271
* @param dataItem the single element from the data array selected by data index
272
272
*/
273
- protected abstract applyChangedData ( dataItem : any ) : void
273
+ protected abstract applyChangedData ( dataItem : unknown ) : void
274
274
}
275
275
276
276
/**
@@ -281,7 +281,7 @@ abstract class SingleDataIndexBindingBase extends BindingBase {
281
281
class NodeBinding extends BindingBase {
282
282
private startMarker : Node | undefined
283
283
private endMarker : Node | undefined
284
- private boundData : any
284
+ private boundData : unknown
285
285
286
286
constructor ( nodeIndex : number , protected readonly dataIndex : number ) {
287
287
super ( nodeIndex )
@@ -300,14 +300,14 @@ class NodeBinding extends BindingBase {
300
300
this . startMarker = node . parentNode . insertBefore ( createMarker ( ) , node )
301
301
}
302
302
303
- applyData ( data : ReadonlyArray < any > ) : void {
303
+ applyData ( data : ReadonlyArray < unknown > ) : void {
304
304
const dataItem = data [ this . dataIndex ]
305
305
306
306
if ( this . boundData === dataItem ) {
307
307
return
308
308
}
309
309
310
- if ( typeof ( dataItem ) === "undefined" || dataItem === null ) {
310
+ if ( typeof ( dataItem ) === "undefined" || dataItem === null ) {
311
311
// undefined/null are special and should be rendered as no content.
312
312
this . applyText ( "" )
313
313
} else if ( typeof dataItem === "string" ) {
@@ -326,7 +326,7 @@ class NodeBinding extends BindingBase {
326
326
}
327
327
}
328
328
329
- private applyIterable ( dataItem : Iterable < any > ) {
329
+ private applyIterable ( dataItem : Iterable < unknown > ) {
330
330
const dataArray = Array . from ( dataItem )
331
331
332
332
if ( Array . isArray ( this . boundData ) ) {
@@ -363,12 +363,12 @@ class NodeBinding extends BindingBase {
363
363
( this . boundData as Array < Binding > ) . forEach ( b => b . applyData ( dataArray ) )
364
364
}
365
365
366
- private createBindingsFromIterable ( dataArray : Array < any > , startIndex = 0 ) {
366
+ private createBindingsFromIterable ( dataArray : Array < unknown > , startIndex = 0 ) {
367
367
for ( let idx = startIndex ; idx < dataArray . length ; ++ idx ) {
368
368
const endMarker = this . endMarker . parentNode . insertBefore ( createMarker ( ) , this . endMarker )
369
369
const binding = new NodeBinding ( this . nodeIndex , idx )
370
- binding . bind ( endMarker , this . nodeIndex )
371
- this . boundData . push ( binding )
370
+ binding . bind ( endMarker , this . nodeIndex ) ;
371
+ ( this . boundData as Array < unknown > ) . push ( binding )
372
372
}
373
373
}
374
374
@@ -437,7 +437,10 @@ class AttributeBinding extends BindingBase {
437
437
private element : Element
438
438
private boundAttributeValue : string | undefined
439
439
440
- constructor ( nodeIndex : number , private readonly attributeName : string , private readonly valueInstructions : Array < string | number > , private readonly directives : AttributeBindingDirectives ) {
440
+ constructor ( nodeIndex : number ,
441
+ private readonly attributeName : string ,
442
+ private readonly valueInstructions : Array < string | number > ,
443
+ private readonly directives : AttributeBindingDirectives ) {
441
444
super ( nodeIndex )
442
445
}
443
446
@@ -450,7 +453,7 @@ class AttributeBinding extends BindingBase {
450
453
super . bindNode ( node )
451
454
}
452
455
453
- applyData ( data : ReadonlyArray < any > ) : void {
456
+ applyData ( data : ReadonlyArray < unknown > ) : void {
454
457
let gotEmptyValue = false
455
458
const attributeValue = this . valueInstructions . map ( vi => {
456
459
if ( typeof vi === "string" ) {
@@ -461,8 +464,8 @@ class AttributeBinding extends BindingBase {
461
464
462
465
// Otherwise it must be a number and refers to a
463
466
// data item.
464
- let d = data [ vi ]
465
-
467
+ const d = data [ vi ]
468
+
466
469
if ( typeof d === "undefined" || d === null ) {
467
470
// If the data item is undefined or null we
468
471
// set the empty value flag.
@@ -517,8 +520,8 @@ class BooleanAttributeBinding extends SingleDataIndexBindingBase {
517
520
super . bindNode ( node )
518
521
}
519
522
520
- protected applyChangedData ( dataItem : any ) : void {
521
- if ( ! ! dataItem ) {
523
+ protected applyChangedData ( dataItem : unknown ) : void {
524
+ if ( dataItem ) {
522
525
this . element . setAttribute ( this . attributeName , this . attributeName )
523
526
} else {
524
527
this . element . removeAttribute ( this . attributeName )
@@ -545,7 +548,9 @@ class EventListenerAttributeBinding extends SingleDataIndexBindingBase {
545
548
private element : Element
546
549
private boundListener : EventListenerOrEventListenerObject
547
550
548
- constructor ( nodeIndex : number , private readonly eventName : string , dataIndex : number , private readonly directives : EventListenerAttributeDirectives ) {
551
+ constructor ( nodeIndex : number ,
552
+ private readonly eventName : string , dataIndex : number ,
553
+ private readonly directives : EventListenerAttributeDirectives ) {
549
554
super ( nodeIndex , dataIndex )
550
555
}
551
556
@@ -558,12 +563,12 @@ class EventListenerAttributeBinding extends SingleDataIndexBindingBase {
558
563
super . bindNode ( node )
559
564
}
560
565
561
- protected applyChangedData ( dataItem : any ) : void {
566
+ protected applyChangedData ( dataItem : unknown ) : void {
562
567
if ( this . boundListener ) {
563
568
this . element . removeEventListener ( this . eventName , this . boundListener )
564
569
}
565
570
566
- this . boundListener = this . createListener ( dataItem )
571
+ this . boundListener = this . createListener ( dataItem as EventListenerOrEventListenerObject )
567
572
568
573
this . element . addEventListener ( this . eventName , this . boundListener , this . directives )
569
574
}
@@ -615,7 +620,8 @@ class PropertyBinding extends SingleDataIndexBindingBase {
615
620
super . bindNode ( node )
616
621
}
617
622
618
- protected applyChangedData ( dataItem : any ) : void {
623
+ protected applyChangedData ( dataItem : unknown ) : void {
624
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
619
625
( this . element as any ) [ this . propertyName ] = dataItem
620
626
}
621
627
}
@@ -625,7 +631,7 @@ class PropertyBinding extends SingleDataIndexBindingBase {
625
631
* @param bindings the bindings
626
632
* @param data the data
627
633
*/
628
- export function applyData ( bindings : ReadonlyArray < Binding > , data : ReadonlyArray < any > ) : void {
634
+ export function applyData ( bindings : ReadonlyArray < Binding > , data : ReadonlyArray < unknown > ) : void {
629
635
bindings . forEach ( b => b . applyData ( data ) )
630
636
}
631
637
@@ -640,7 +646,7 @@ export function bindBindings(bindings: ReadonlyArray<Binding>, root: Node) {
640
646
let nodeIndex = - 1
641
647
let node : Node
642
648
643
- while ( node = treeWalker . nextNode ( ) ) {
649
+ while ( ( node = treeWalker . nextNode ( ) ) !== null ) {
644
650
nodeIndex ++
645
651
bindings . forEach ( b => b . bind ( node , nodeIndex ) )
646
652
}
@@ -660,7 +666,7 @@ export function determineBindings(root: Node, template: HtmlTemplate): Array<Bin
660
666
let nodeIndex = - 1
661
667
let node : Node
662
668
663
- while ( node = treeWalker . nextNode ( ) ) {
669
+ while ( ( node = treeWalker . nextNode ( ) ) !== null ) {
664
670
// Walk the whole DOM subtree and detect nodes with a binding marker on it.
665
671
// Use the nodeIndex as a pointer to this node
666
672
nodeIndex ++
@@ -673,7 +679,7 @@ export function determineBindings(root: Node, template: HtmlTemplate): Array<Bin
673
679
674
680
} else if ( node . nodeType === Node . ELEMENT_NODE ) {
675
681
const element = node as Element
676
- for ( let name of element . getAttributeNames ( ) ) {
682
+ for ( const name of element . getAttributeNames ( ) ) {
677
683
const value = element . getAttribute ( name )
678
684
const parts = splitAtPlaceholders ( value )
679
685
@@ -796,7 +802,7 @@ export function determineBindings(root: Node, template: HtmlTemplate): Array<Bin
796
802
default :
797
803
console . warn ( `unrecognized attribute binding directive: "${ optName } "` )
798
804
}
799
- } )
805
+ } )
800
806
801
807
// Finally, create the binding and append it to the list of bindings.
802
808
bindings . push ( new AttributeBinding ( nodeIndex , attributeName , valueInstructions , directives ) )
@@ -824,5 +830,6 @@ function createMarker(): Node {
824
830
*/
825
831
function isIterable ( value : unknown ) : value is Iterable < unknown > {
826
832
return Array . isArray ( value ) ||
833
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
827
834
! ! ( value && ( value as any ) [ Symbol . iterator ] )
828
835
}
0 commit comments