Compressing JS code with regular PHP code using preg_replace (). Replacing the properties and methods of objects with their abbreviated names everywhere except in those parts of the code where a literal object is transferred to one of the methods of the animation object (the properties of the desired literal object cannot be replaced, since their values ​​are later transferred to the corresponding properties of the element's house) .

Conditional JS code fragment:

 App.func.animation.animateDomElement(document.getElementById("container"), { height: 0 }, 300, q); var newObj = { height: 120 }; 

In this example, in the substring " var newObj={height:0}; " the height property of the object must be replaced with the new name, and in the literal object that is passed by the parameter to the function, the property must remain "as is".

The second day I struggle with this task, I can’t think of anything.

PS: in the JS code prepared for regular processing, of course, there will be no extra spaces, no tabs, no line breaks.

  • Where to get the new name? Or is it not important? - lampa
  • Never mind. It is required to replace the occurrence of the word, if to the left of it, to the nearest semicolon, the word “animation” does not occur - xdmitry
  • @AlexWindHope anonymous not forgive! Even when comments end. And you advice - the troll is written with two "ll". Even the name of the profession do not really know. Oh. - lampa
  • Please clarify: the word that needs to be replaced can be in any place or only as in the question? For example, which of the words in this example should be replaced: word1 = word2; word3 = {word4: word5, word6: {word7: word13}}; word8.word10.word11 (word12); All word_N is either a variable or a method / property of an object, and not a symbol of something abstract. - ReinRaus

0