I'm currently working on a project, part of which is the conversion of old code to a new format. I'm using Java to do the conversion and the code that I'm converting is from an unknown language (possibly javascript) to javascript. The conversion is needed because the codebase is being rebuilt in a new framework so variable access, scope, etc has changed.
A simple example would be
this['something_92'].show()
would become
this.getById(92).setHidden(false)
or
this['irrelevant_5']['blabla_6'].disable()
would be
this.getById(6).setDisable(true)
or
this['asd_7']['abc_3'].setToVariable(this['Some_Thing'])
to
this.getById(3).set(this.some.thing)
There are also other scenarios but basically I'm wondering if there is some sort of open source library out there that lets you convert based on some form of semantics of the initial source being passed it. Something thats scope aware etc. I've got no idea what to even search for something like this if it at all exists.
If there's nothing like that, I was considering creating a sort of custom scope in the new project that I can call this old code it and have it convert on the fly to the modern version of the code. So maybe doing like a 'new Function('old code').bind(custom 'this' scope that has been built specifically in the old codes form).call() This approach isn't really ideal from a performance standpoint but it seems like it could be more flexible?
Currently I've been using a LOT of regex and other conditionals to split up, find, change, and reassemble everything. I've got it working but it feels horribly awkward, and I keep running into cases that I hadn't accounted for, and the complexity keeps growing. If its the only way of doing it so be it. Was just hoping someone may have had to do something similar at one point and may have some suggestions?
Aucun commentaire:
Enregistrer un commentaire