@@ -8,7 +8,6 @@ const keys = require('lodash/keys');
88const union = require ( 'lodash/union' ) ;
99const pick = require ( 'lodash/pick' ) ;
1010const difference = require ( 'lodash/difference' ) ;
11- const each = require ( 'lodash/each' ) ;
1211const has = require ( 'lodash/has' ) ;
1312const extend = require ( 'lodash/extend' ) ;
1413const isString = require ( 'lodash/isString' ) ;
@@ -52,15 +51,16 @@ module.exports = (currentNode, attributes, props, options, aware) => {
5251
5352 // Merge or override elementAttributes from options provided
5453 if ( ! isEmpty ( options . elementAttributes ) ) {
55- each ( options . elementAttributes , ( modifier , tagName ) => {
54+ for ( const tagName in options . elementAttributes ) {
55+ const modifier = options . elementAttributes [ tagName ] ;
5656 if ( typeof modifier === 'function' && isString ( tagName ) ) {
57- tagName = tagName . toUpperCase ( ) ;
58- const attributes = modifier ( validAttributes . elementAttributes [ tagName ] ) ;
57+ const upperTagName = tagName . toUpperCase ( ) ;
58+ const attributes = modifier ( validAttributes . elementAttributes [ upperTagName ] ) ;
5959 if ( Array . isArray ( attributes ) ) {
60- validAttributes . elementAttributes [ tagName ] = attributes ;
60+ validAttributes . elementAttributes [ upperTagName ] = attributes ;
6161 }
6262 }
63- } ) ;
63+ }
6464 }
6565
6666 // Attributes to be excluded
@@ -76,15 +76,18 @@ module.exports = (currentNode, attributes, props, options, aware) => {
7676 const mainNodeAttributes = pick ( attributes , validElementAttributes ) ;
7777
7878 // Get additional specified attributes
79- each ( attributes , ( value , attr ) => {
80- each ( validAttributes . safelistAttributes , additionalAttr => {
81- if ( additionalAttr === attr || ( additionalAttr . endsWith ( '*' ) && attr . startsWith ( additionalAttr . replace ( '*' , '' ) ) ) ) {
82- mainNodeAttributes [ attr ] = value ;
79+ for ( const attr in attributes ) {
80+ for ( const additionalAttr of validAttributes . safelistAttributes ) {
81+ if (
82+ additionalAttr === attr
83+ || ( additionalAttr . endsWith ( '*' ) && attr . startsWith ( additionalAttr . replace ( '*' , '' ) ) )
84+ ) {
85+ mainNodeAttributes [ attr ] = attributes [ attr ] ;
8386 }
84- } ) ;
85- } ) ;
87+ }
88+ }
8689
87- each ( mainNodeAttributes , ( value , key ) => {
90+ for ( const key in mainNodeAttributes ) {
8891 if ( [ 'class' , 'style' ] . includes ( key ) ) {
8992 if ( ! has ( nodeAttrs , key ) ) {
9093 nodeAttrs [ key ] = key === 'class' ? [ ] : { } ;
@@ -100,16 +103,16 @@ module.exports = (currentNode, attributes, props, options, aware) => {
100103 }
101104
102105 delete attributes [ key ] ;
103- } ) ;
106+ }
104107
105108 // The plugin posthtml-attrs-parser compose() method expects a string,
106109 // but since we are JSON parsing, values like "-1" become number -1.
107110 // So below we convert non string values to string.
108- each ( nodeAttrs , ( value , key ) => {
111+ for ( const key in nodeAttrs ) {
109112 if ( key !== 'compose' && ! isObject ( nodeAttrs [ key ] ) && ! isString ( nodeAttrs [ key ] ) ) {
110113 nodeAttrs [ key ] = nodeAttrs [ key ] . toString ( ) ;
111114 }
112- } ) ;
115+ }
113116
114117 mainNode . attrs = nodeAttrs . compose ( ) ;
115118} ;
0 commit comments