77 */
88
99import { CUSTOM_ELEMENTS_SCHEMA , NO_ERRORS_SCHEMA , SchemaMetadata , SecurityContext } from '../core' ;
10-
1110import { isNgContainer , isNgContent } from '../ml_parser/tags' ;
1211import { dashCaseToCamelCase } from '../util' ;
1312
@@ -232,46 +231,46 @@ const SCHEMA: string[] = [
232231 ':svg:cursor^:svg:|' ,
233232] ;
234233
235- const _ATTR_TO_PROP : { [ name : string ] : string } = {
234+ const _ATTR_TO_PROP = new Map ( Object . entries ( {
236235 'class' : 'className' ,
237236 'for' : 'htmlFor' ,
238237 'formaction' : 'formAction' ,
239238 'innerHtml' : 'innerHTML' ,
240239 'readonly' : 'readOnly' ,
241240 'tabindex' : 'tabIndex' ,
242- } ;
241+ } ) ) ;
243242
244243// 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 ) ;
248247 return inverted ;
249- } , { } as { [ prop : string ] : string } ) ;
248+ } , new Map < string , string > ( ) ) ;
250249
251250export class DomElementSchemaRegistry extends ElementSchemaRegistry {
252- private _schema : { [ element : string ] : { [ property : string ] : string } } = { } ;
251+ private _schema = new Map < string , Map < string , string > > ( ) ;
253252 // We don't allow binding to events for security reasons. Allowing event bindings would almost
254253 // 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 > > ;
256255
257256 constructor ( ) {
258257 super ( ) ;
259258 SCHEMA . forEach ( encodedType => {
260- const type : { [ property : string ] : string } = { } ;
259+ const type = new Map < string , string > ( ) ;
261260 const events : Set < string > = new Set ( ) ;
262261 const [ strType , strProperties ] = encodedType . split ( '|' ) ;
263262 const properties = strProperties . split ( ',' ) ;
264263 const [ typeNames , superName ] = strType . split ( '^' ) ;
265264 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 ) ;
268267 } ) ;
269- const superType = superName && this . _schema [ superName . toLowerCase ( ) ] ;
268+ const superType = superName && this . _schema . get ( superName . toLowerCase ( ) ) ;
270269 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 ( ) ) ! ) {
275274 events . add ( superEvent ) ;
276275 }
277276 }
@@ -282,16 +281,16 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
282281 events . add ( property . substring ( 1 ) ) ;
283282 break ;
284283 case '!' :
285- type [ property . substring ( 1 ) ] = BOOLEAN ;
284+ type . set ( property . substring ( 1 ) , BOOLEAN ) ;
286285 break ;
287286 case '#' :
288- type [ property . substring ( 1 ) ] = NUMBER ;
287+ type . set ( property . substring ( 1 ) , NUMBER ) ;
289288 break ;
290289 case '%' :
291- type [ property . substring ( 1 ) ] = OBJECT ;
290+ type . set ( property . substring ( 1 ) , OBJECT ) ;
292291 break ;
293292 default :
294- type [ property ] = STRING ;
293+ type . set ( property , STRING ) ;
295294 }
296295 }
297296 } ) ;
@@ -315,8 +314,9 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
315314 }
316315 }
317316
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 ) ;
320320 }
321321
322322 override hasElement ( tagName : string , schemaMetas : SchemaMetadata [ ] ) : boolean {
@@ -335,7 +335,7 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
335335 }
336336 }
337337
338- return ! ! this . _schema [ tagName . toLowerCase ( ) ] ;
338+ return this . _schema . has ( tagName . toLowerCase ( ) ) ;
339339 }
340340
341341 /**
@@ -368,7 +368,7 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
368368 }
369369
370370 override getMappedPropName ( propName : string ) : string {
371- return _ATTR_TO_PROP [ propName ] || propName ;
371+ return _ATTR_TO_PROP . get ( propName ) ?? propName ;
372372 }
373373
374374 override getDefaultComponentElementName ( ) : string {
@@ -398,17 +398,18 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
398398 }
399399
400400 override allKnownElementNames ( ) : string [ ] {
401- return Object . keys ( this . _schema ) ;
401+ return Array . from ( this . _schema . keys ( ) ) ;
402402 }
403403
404404 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' ) ! ;
406407 // 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 ) ;
408409 }
409410
410411 allKnownEventsOfElement ( tagName : string ) : string [ ] {
411- return Array . from ( this . _eventSchema [ tagName . toLowerCase ( ) ] ?? [ ] ) ;
412+ return Array . from ( this . _eventSchema . get ( tagName . toLowerCase ( ) ) ?? [ ] ) ;
412413 }
413414
414415 override normalizeAnimationStyleProperty ( propName : string ) : string {
0 commit comments