7
7
*/
8
8
9
9
import { CUSTOM_ELEMENTS_SCHEMA , NO_ERRORS_SCHEMA , SchemaMetadata , SecurityContext } from '../core' ;
10
-
11
10
import { isNgContainer , isNgContent } from '../ml_parser/tags' ;
12
11
import { dashCaseToCamelCase } from '../util' ;
13
12
@@ -232,46 +231,46 @@ const SCHEMA: string[] = [
232
231
':svg:cursor^:svg:|' ,
233
232
] ;
234
233
235
- const _ATTR_TO_PROP : { [ name : string ] : string } = {
234
+ const _ATTR_TO_PROP = new Map ( Object . entries ( {
236
235
'class' : 'className' ,
237
236
'for' : 'htmlFor' ,
238
237
'formaction' : 'formAction' ,
239
238
'innerHtml' : 'innerHTML' ,
240
239
'readonly' : 'readOnly' ,
241
240
'tabindex' : 'tabIndex' ,
242
- } ;
241
+ } ) ) ;
243
242
244
243
// Invert _ATTR_TO_PROP.
245
- const _PROP_TO_ATTR : { [ name : string ] : string } =
246
- Object . keys ( _ATTR_TO_PROP ) . reduce ( ( inverted , attr ) => {
247
- inverted [ _ATTR_TO_PROP [ attr ] ] = attr ;
244
+ const _PROP_TO_ATTR =
245
+ Array . from ( _ATTR_TO_PROP ) . reduce ( ( inverted , [ propertyName , attributeName ] ) => {
246
+ inverted . set ( propertyName , attributeName ) ;
248
247
return inverted ;
249
- } , { } as { [ prop : string ] : string } ) ;
248
+ } , new Map < string , string > ( ) ) ;
250
249
251
250
export class DomElementSchemaRegistry extends ElementSchemaRegistry {
252
- private _schema : { [ element : string ] : { [ property : string ] : string } } = { } ;
251
+ private _schema = new Map < string , Map < string , string > > ( ) ;
253
252
// We don't allow binding to events for security reasons. Allowing event bindings would almost
254
253
// certainly introduce bad XSS vulnerabilities. Instead, we store events in a separate schema.
255
- private _eventSchema : { [ element : string ] : Set < string > } = { } ;
254
+ private _eventSchema = new Map < string , Set < string > > ;
256
255
257
256
constructor ( ) {
258
257
super ( ) ;
259
258
SCHEMA . forEach ( encodedType => {
260
- const type : { [ property : string ] : string } = { } ;
259
+ const type = new Map < string , string > ( ) ;
261
260
const events : Set < string > = new Set ( ) ;
262
261
const [ strType , strProperties ] = encodedType . split ( '|' ) ;
263
262
const properties = strProperties . split ( ',' ) ;
264
263
const [ typeNames , superName ] = strType . split ( '^' ) ;
265
264
typeNames . split ( ',' ) . forEach ( tag => {
266
- this . _schema [ tag . toLowerCase ( ) ] = type ;
267
- this . _eventSchema [ tag . toLowerCase ( ) ] = events ;
265
+ this . _schema . set ( tag . toLowerCase ( ) , type ) ;
266
+ this . _eventSchema . set ( tag . toLowerCase ( ) , events ) ;
268
267
} ) ;
269
- const superType = superName &&
10000
; this . _schema [ superName . toLowerCase ( ) ] ;
268
+ const superType = superName && this . _schema . get ( superName . toLowerCase ( ) ) ;
270
269
if ( superType ) {
271
- Object . keys ( superType ) . forEach ( ( prop : string ) => {
272
- type [ prop ] = superType [ prop ] ;
273
- } ) ;
274
- for ( const superEvent of this . _eventSchema [ superName . toLowerCase ( ) ] ) {
270
+ for ( const [ prop , value ] of superType ) {
271
+ type . set ( prop , value ) ;
272
+ }
273
+ for ( const superEvent of this . _eventSchema . get ( superName . toLowerCase ( ) ) ! ) {
275
274
events . add ( superEvent ) ;
276
275
}
277
276
}
@@ -282,16 +281,16 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
282
281
events . add ( property . substring ( 1 ) ) ;
283
282
break ;
284
283
case '!' :
285
- type [ property . substring ( 1 ) ] = BOOLEAN ;
284
+ type . set ( property . substring ( 1 ) , BOOLEAN ) ;
286
285
break ;
287
286
case '#' :
288
- type [ property . substring ( 1 ) ] = NUMBER ;
287
+ type . set ( property . substring ( 1 ) , NUMBER ) ;
289
288
break ;
290
289
case '%' :
291
- type [ property . substring ( 1 ) ] = OBJECT ;
290
+ type . set ( property . substring ( 1 ) , OBJECT ) ;
292
291
break ;
293
292
default :
294
- type [ property ] = STRING ;
293
+ type . set ( property , STRING ) ;
295
294
}
296
295
}
297
296
} ) ;
@@ -315,8 +314,9 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
315
314
}
316
315
}
317
316
318
- const elementProperties = this . _schema [ tagName . toLowerCase ( ) ] || this . _schema [ 'unknown' ] ;
319
- return ! ! elementProperties [ propName ] ;
317
+ const elementProperties =
318
+ this . _schema . get ( tagName . toLowerCase ( ) ) || this . _schema . get ( 'unknown' ) ! ;
319
+ return elementProperties . has ( propName ) ;
320
320
}
321
321
322
322
override hasElement ( tagName : string , schemaMetas : SchemaMetadata [ ] ) : boolean {
@@ -335,7 +335,7 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
335
335
}
336
336
}
337
337
338
- return ! ! this . _schema [ tagName . toLowerCase ( ) ] ;
338
+ return this . _schema . has ( tagName . toLowerCase ( ) ) ;
339
339
}
340
340
341
341
/**
@@ -368,7 +368,7 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
368
368
}
369
369
370
370
override getMappedPropName ( propName : string ) : string {
371
- return _ATTR_TO_PROP [ propName ] || propName ;
371
+ return _ATTR_TO_PROP . get ( propName ) ?? propName ;
372
372
}
373
373
374
374
override getDefaultComponentElementName ( ) : string {
@@ -398,17 +398,18 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
398
398
}
399
399
400
400
override allKnownElementNames ( ) : string [ ] {
401
- return Object . keys ( this . _schema ) ;
401
+ return Array . from ( this . _schema . keys ( ) ) ;
402
402
}
403
403
404
404
allKnownAttributesOfElement ( tagName : string ) : string [ ] {
405
- const elementProperties = this . _schema [ tagName . toLowerCase ( ) ] || this . _schema [ 'unknown' ] ;
405
+ const elementProperties =
406
+ this . _schema . get ( tagName . toLowerCase ( ) ) || this . _schema . get ( 'unknown' ) ! ;
406
407
// Convert properties to attributes.
407
- return Object . keys ( elementProperties ) . map ( prop => _PROP_TO_ATTR [ prop ] ?? prop ) ;
408
+ return Array . from ( elementProperties . keys ( ) ) . map ( prop => _PROP_TO_ATTR . get ( prop ) ?? prop ) ;
408
409
}
409
410
410
411
allKnownEventsOfElement ( tagName : string ) : string [ ] {
411
- return Array . from ( this . _eventSchema [ tagName . toLowerCase ( ) ] ?? [ ] ) ;
412
+ return Array . from ( this . _eventSchema . get ( tagName . toLowerCase ( ) ) ?? [ ] ) ;
412
413
}
413
414
414
415
override normalizeAnimationStyleProperty ( propName : string ) : string {
0 commit comments