简体   繁体   English

在Linux上用bash脚本或c ++脚本替换JavaScript函数

[英]Replace JavaScript function with bash script or c++ script on linux

Hi everybody, 大家好,

Is somebody can help me , I need to replace a bugged javascript function by a non bugged JavaScript function in all my javascript files with a bash script (it would be great) or with c/c++ script if it's not possible, I want to replace these lines of codes on my javascript file: 是否有人可以帮助我,我需要用bash脚本(这很好)或用c / c ++脚本替换我所有javascript文件中的错误bug的JavaScript函数,如果不可能的话,我想替换我的javascript文件中的以下代码行:

FormGroupDirective.prototype._updateDomValue = function () {

        var _this = this;

        this.directives.forEach(function (dir) {

            var /** @type {?} */ newCtrl = _this.form.get(dir.path);

            if (dir._control !== newCtrl) {

                cleanUpControl(dir._control, dir);



                if (newCtrl && newCtrl instanceof FormControl) {

                    setUpControl(newCtrl, dir);

                    dir._control = newCtrl;

                } else {

                    dir._control = null;

                }

            }

        });

        this.form._updateTreeValidity({ emitEvent: false });

    };

With these lines of codes : 使用以下代码行:

FormGroupDirective.prototype._updateDomValue = function () {

    var _this = this;

    this.directives.forEach(function (dir) {

        var /** @type {?} */ newCtrl = _this.form.get(dir.path);

        if (dir._control !== newCtrl) {

            cleanUpControl(dir._control, dir);



            if (newCtrl && newCtrl instanceof FormControl) {

                setUpControl(newCtrl, dir);

                dir._control = newCtrl;

            } else {

                dir._control = null;

            }

        }

    });

    this.form._updateTreeValidity({ emitEvent: false });

};

Thanks you 谢谢

I managed to do it. 我设法做到了。 So i wanted to replace : 所以我想替换:

  FormGroupDirective.prototype._updateDomValue = function () {
        var _this = this;
        this.directives.forEach(function (dir) {
            var /** @type {?} */ newCtrl = _this.form.get(dir.path);
            if (dir._control !== newCtrl) {
                cleanUpControl(dir._control, dir);

                if (newCtrl && newCtrl instanceof FormControl) {
                    setUpControl(newCtrl, dir);
                    dir._control = newCtrl;
                } else {
                    dir._control = null;
                }
            }
        });
        this.form._updateTreeValidity({ emitEvent: false });
    };

by 通过

 FormGroupDirective.prototype._updateDomValue = function () {
        var _this = this;
        this.directives.forEach(function (dir) {
            var newCtrl = _this.form.get(dir.path);
            if (dir._control !== newCtrl) {
                cleanUpControl(dir._control, dir,_this);

                if (newCtrl && newCtrl instanceof FormControl) {
                    setUpControl(newCtrl, dir,_this);
                    dir._control = newCtrl;
                } else {
                    dir._control = _this;
                }
            }
        });
        this.form._updateTreeValidity({ emitEvent: false });
    };

I made a script who replace lines between first word FormGroupDirective and the last word emitEvent: false . 我制作了一个脚本,该脚本替换了第一个单词FormGroupDirective和最后一个单词glowEvent之间的行:false

My script replace : 我的脚本替换:

  • cleanUpControl(dir._control, dir); cleanUpControl(dir._control,dir); by cleanUpControl(dir._control, dir,_this); 通过cleanUpControl(dir._control,dir,_this);
  • setUpControl(newCtrl, dir); setUpControl(newCtrl,dir); by setUpControl(newCtrl, dir,_this); 通过setUpControl(newCtrl,dir,_this);
  • dir._control = null; dir._control = null; by dir._control = _this; 通过dir._control = _this;

the follow script command check all js file and do the replace : 以下脚本命令检查所有js文件并进行替换:

find . -name '*.js'|xargs  sed -i '/FormGroupDirective/,/emitEvent: false/ {s/cleanUpControl(dir._control, dir);/cleanUpControl(dir._control, dir,_this);/;s/setUpControl(newCtrl, dir);/setUpControl(newCtrl, dir,_this);/; s/dir._control = null;/dir._control = _this;/ }'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM