@@ -45,7 +45,7 @@ export class HtmlTemplate implements ElementUpdater {
4545 * @param strings the strings as passed to the `html` string tag
4646 * @param data the data arguments as passed to the `html` string tag
4747 */
48- constructor ( private readonly strings : TemplateStringsArray , public data : ReadonlyArray < any > ) { }
48+ constructor ( private readonly strings : TemplateStringsArray , public data : ReadonlyArray < unknown > ) { }
4949
5050 /**
5151 * Generates a string containing the HTML markup as described by the strings array
@@ -118,9 +118,9 @@ export class HtmlTemplate implements ElementUpdater {
118118 }
119119}
120120
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
124124
125125/**
126126 * Generates a HTML markup string from the given static string parts.
@@ -159,7 +159,7 @@ function generateHtml(strings: TemplateStringsArray): [string, Map<string, strin
159159 * into an element but the rendered content is modified by some external DOM
160160 * operations when applying the insert.
161161 */
162- const DomInconsistencyError = ` DOM inconsistency error`
162+ const DomInconsistencyError = " DOM inconsistency error"
163163
164164/**
165165 * A `Binding` defines how to apply a placeholder's value to the DOM.
@@ -185,7 +185,7 @@ interface Binding {
185185 *
186186 * @param data all placeholder values
187187 */
188- applyData ( data : ReadonlyArray < any > ) : void
188+ applyData ( data : ReadonlyArray < unknown > ) : void
189189}
190190
191191/**
@@ -233,7 +233,7 @@ abstract class BindingBase implements Binding {
233233 this . node = node
234234 }
235235
236- abstract applyData ( data : ReadonlyArray < any > ) : void
236+ abstract applyData ( data : ReadonlyArray < unknown > ) : void
237237}
238238
239239/**
@@ -242,7 +242,7 @@ abstract class BindingBase implements Binding {
242242 * only when data changes.
243243 */
244244abstract class SingleDataIndexBindingBase extends BindingBase {
245- protected boundData : any
245+ protected boundData : unknown
246246
247247 constructor ( nodeIndex : number , protected readonly dataIndex : number ) {
248248 super ( nodeIndex )
@@ -254,7 +254,7 @@ abstract class SingleDataIndexBindingBase extends BindingBase {
254254 * data updates.
255255 * @param data the data array
256256 */
257- applyData ( data : Array < any > ) : void {
257+ applyData ( data : Array < unknown > ) : void {
258258 const dataItem = data [ this . dataIndex ]
259259
260260 if ( this . boundData === dataItem ) {
@@ -270,7 +270,7 @@ abstract class SingleDataIndexBindingBase extends BindingBase {
270270 * Called by `applyData` when a change in data is detected.
271271 * @param dataItem the single element from the data array selected by data index
272272 */
273- protected abstract applyChangedData ( dataItem : any ) : void
273+ protected abstract applyChangedData ( dataItem : unknown ) : void
274274}
275275
276276/**
@@ -281,7 +281,7 @@ abstract class SingleDataIndexBindingBase extends BindingBase {
281281class NodeBinding extends BindingBase {
282282 private startMarker : Node | undefined
283283 private endMarker : Node | undefined
284- private boundData : any
284+ private boundData : unknown
285285
286286 constructor ( nodeIndex : number , protected readonly dataIndex : number ) {
287287 super ( nodeIndex )
@@ -300,14 +300,14 @@ class NodeBinding extends BindingBase {
300300 this . startMarker = node . parentNode . insertBefore ( createMarker ( ) , node )
301301 }
302302
303- applyData ( data : ReadonlyArray < any > ) : void {
303+ applyData ( data : ReadonlyArray < unknown > ) : void {
304304 const dataItem = data [ this . dataIndex ]
305305
306306 if ( this . boundData === dataItem ) {
307307 return
308308 }
309309
310- if ( typeof ( dataItem ) === "undefined" || dataItem === null ) {
310+ if ( typeof ( dataItem ) === "undefined" || dataItem === null ) {
311311 // undefined/null are special and should be rendered as no content.
312312 this . applyText ( "" )
313313 } else if ( typeof dataItem === "string" ) {
@@ -326,7 +326,7 @@ class NodeBinding extends BindingBase {
326326 }
327327 }
328328
329- private applyIterable ( dataItem : Iterable < any > ) {
329+ private applyIterable ( dataItem : Iterable < unknown > ) {
330330 const dataArray = Array . from ( dataItem )
331331
332332 if ( Array . isArray ( this . boundData ) ) {
@@ -363,12 +363,12 @@ class NodeBinding extends BindingBase {
363363 ( this . boundData as Array < Binding > ) . forEach ( b => b . applyData ( dataArray ) )
364364 }
365365
366- private createBindingsFromIterable ( dataArray : Array < any > , startIndex = 0 ) {
366+ private createBindingsFromIterable ( dataArray : Array < unknown > , startIndex = 0 ) {
367367 for ( let idx = startIndex ; idx < dataArray . length ; ++ idx ) {
368368 const endMarker = this . endMarker . parentNode . insertBefore ( createMarker ( ) , this . endMarker )
369369 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 )
372372 }
373373 }
374374
@@ -437,7 +437,10 @@ class AttributeBinding extends BindingBase {
437437 private element : Element
438438 private boundAttributeValue : string | undefined
439439
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 ) {
441444 super ( nodeIndex )
442445 }
443446
@@ -450,7 +453,7 @@ class AttributeBinding extends BindingBase {
450453 super . bindNode ( node )
451454 }
452455
453- applyData ( data : ReadonlyArray < any > ) : void {
456+ applyData ( data : ReadonlyArray < unknown > ) : void {
454457 let gotEmptyValue = false
455458 const attributeValue = this . valueInstructions . map ( vi => {
456459 if ( typeof vi === "string" ) {
@@ -461,8 +464,8 @@ class AttributeBinding extends BindingBase {
461464
462465 // Otherwise it must be a number and refers to a
463466 // data item.
464- let d = data [ vi ]
465-
467+ const d = data [ vi ]
468+
466469 if ( typeof d === "undefined" || d === null ) {
467470 // If the data item is undefined or null we
468471 // set the empty value flag.
@@ -517,8 +520,8 @@ class BooleanAttributeBinding extends SingleDataIndexBindingBase {
517520 super . bindNode ( node )
518521 }
519522
520- protected applyChangedData ( dataItem : any ) : void {
521- if ( ! ! dataItem ) {
523+ protected applyChangedData ( dataItem : unknown ) : void {
524+ if ( dataItem ) {
522525 this . element . setAttribute ( this . attributeName , this . attributeName )
523526 } else {
524527 this . element . removeAttribute ( this . attributeName )
@@ -545,7 +548,9 @@ class EventListenerAttributeBinding extends SingleDataIndexBindingBase {
545548 private element : Element
546549 private boundListener : EventListenerOrEventListenerObject
547550
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 ) {
549554 super ( nodeIndex , dataIndex )
550555 }
551556
@@ -558,12 +563,12 @@ class EventListenerAttributeBinding extends SingleDataIndexBindingBase {
558563 super . bindNode ( node )
559564 }
560565
561- protected applyChangedData ( dataItem : any ) : void {
566+ protected applyChangedData ( dataItem : unknown ) : void {
562567 if ( this . boundListener ) {
563568 this . element . removeEventListener ( this . eventName , this . boundListener )
564569 }
565570
566- this . boundListener = this . createListener ( dataItem )
571+ this . boundListener = this . createListener ( dataItem as EventListenerOrEventListenerObject )
567572
568573 this . element . addEventListener ( this . eventName , this . boundListener , this . directives )
569574 }
@@ -615,7 +620,8 @@ class PropertyBinding extends SingleDataIndexBindingBase {
615620 super . bindNode ( node )
616621 }
617622
618- protected applyChangedData ( dataItem : any ) : void {
623+ protected applyChangedData ( dataItem : unknown ) : void {
624+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
619625 ( this . element as any ) [ this . propertyName ] = dataItem
620626 }
621627}
@@ -625,7 +631,7 @@ class PropertyBinding extends SingleDataIndexBindingBase {
625631 * @param bindings the bindings
626632 * @param data the data
627633 */
628- export function applyData ( bindings : ReadonlyArray < Binding > , data : ReadonlyArray < any > ) : void {
634+ export function applyData ( bindings : ReadonlyArray < Binding > , data : ReadonlyArray < unknown > ) : void {
629635 bindings . forEach ( b => b . applyData ( data ) )
630636}
631637
@@ -640,7 +646,7 @@ export function bindBindings(bindings: ReadonlyArray<Binding>, root: Node) {
640646 let nodeIndex = - 1
641647 let node : Node
642648
643- while ( node = treeWalker . nextNode ( ) ) {
649+ while ( ( node = treeWalker . nextNode ( ) ) !== null ) {
644650 nodeIndex ++
645651 bindings . forEach ( b => b . bind ( node , nodeIndex ) )
646652 }
@@ -660,7 +666,7 @@ export function determineBindings(root: Node, template: HtmlTemplate): Array<Bin
660666 let nodeIndex = - 1
661667 let node : Node
662668
663- while ( node = treeWalker . nextNode ( ) ) {
669+ while ( ( node = treeWalker . nextNode ( ) ) !== null ) {
664670 // Walk the whole DOM subtree and detect nodes with a binding marker on it.
665671 // Use the nodeIndex as a pointer to this node
666672 nodeIndex ++
@@ -673,7 +679,7 @@ export function determineBindings(root: Node, template: HtmlTemplate): Array<Bin
673679
674680 } else if ( node . nodeType === Node . ELEMENT_NODE ) {
675681 const element = node as Element
676- for ( let name of element . getAttributeNames ( ) ) {
682+ for ( const name of element . getAttributeNames ( ) ) {
677683 const value = element . getAttribute ( name )
678684 const parts = splitAtPlaceholders ( value )
679685
@@ -796,7 +802,7 @@ export function determineBindings(root: Node, template: HtmlTemplate): Array<Bin
796802 default :
797803 console . warn ( `unrecognized attribute binding directive: "${ optName } "` )
798804 }
799- } )
805+ } )
800806
801807 // Finally, create the binding and append it to the list of bindings.
802808 bindings . push ( new AttributeBinding ( nodeIndex , attributeName , valueInstructions , directives ) )
@@ -824,5 +830,6 @@ function createMarker(): Node {
824830 */
825831function isIterable ( value : unknown ) : value is Iterable < unknown > {
826832 return Array . isArray ( value ) ||
833+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
827834 ! ! ( value && ( value as any ) [ Symbol . iterator ] )
828835}
0 commit comments