new Class() replace to esm class syntax #7113
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
我用 PHP 脚本和正则表达式对源代码的
new Class()
结构进行了替换。这样做的好处有:
还有很多。
这种批量替换源代码的做法,我是有经验的,我自己有实际使用,就是用本项目的源代码实践的,可以成功运行,且有实际生产环境的游戏。并且我的做法更彻底更激进,
require()
这些都替换成了 import from,var 替换成 const 或者 let 等等。现在有个遗留问题,esm的语法要求调用
super()
之前不能访问this
。这个可能需要主力开发者手动修复一下。在
src/a.php
里有替换逻辑,可以checkout
出来查看。只有一个commit
是用了这脚本替换的,其他commit
是手动修改的。由于我的英文表达很差,这里就用中文代替了。
附上谷歌翻译
I used PHP scripts and regular expressions to replace the
new Class()
structure in the source code.The benefits of doing this are:
There are many more.
I have experience with this practice of batch replacing source code. I have actually used it myself, that is, I practiced it with the source code of this project, which can be successfully run and has a game in the actual production environment. And my approach is more thorough and radical.
require()
is replaced with import from, var is replaced with const or let, etc.Now there is a legacy issue. The esm syntax requires that
this
cannot be accessed before callingsuper()
. This may require the main developer to manually fix it.There is a replacement logic in
src/a.php
, which can be checked out. Only onecommit
is replaced by this script, and the othercommit
are manually modified.Since my English is poor, I will use Chinese instead.
Attached is Google Translate