How to use the php-parser.parseEval function in php-parser

To help you get started, we’ve selected a few php-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github glayzzle / php-writer / src / trait.js View on Github external
Trait.prototype.setConstant = function(name, value) {
    var constant = this.getConstant(name);
    if (!constant) {
        // append the function
        var ast = parser.parseEval('class a { \n' +
            'const ' + name + (
                value ? ' = ' + value : ''
            ) + ';\n' +
        ' }');
        this.ast.body.unshift(
            ast.children[0].body[0]
        );
    } else {
        if (typeof value !== 'undefined') constant.setValue(value);
    }
    return this;
};
github glayzzle / php-writer / src / class.js View on Github external
Class.prototype.setMethod = function(name, args, body, flags) {
    var method = this.getMethod(name);
    if (!method) {
        // append the function
        var ast = parser.parseEval('class a { \n' +
            flags + ' function ' + name + '(' + args +  ') {\n' +
                body + '\n' +
            '}\n' +
        ' }');
        this.ast.body.push(
            ast.children[0].body[0]
        );
    } else {
        // update the function
        if (typeof flags !== 'undefined') method.setFlags(flags);
        if (typeof args !== 'undefined') method.setArgs(args);
        if (typeof body !== 'undefined') method.setCode(body);
    }
    return this;
};
github glayzzle / php-writer / src / interface.js View on Github external
Interface.prototype.setMethod = function(name, args, body, flags) {
    var method = this.getMethod(name);
    if (!method) {
        // append the function
        var ast = parser.parseEval('class a { \n' +
            flags + ' function ' + name + '(' + args +  ') {\n' +
                body + '\n' +
            '}\n' +
        ' }');
        this.ast.body.push(
            ast.children[0].body[0]
        );
    } else {
        // update the function
        if (typeof flags !== 'undefined') method.setFlags(flags);
        if (typeof args !== 'undefined') method.setArgs(args);
        if (typeof body !== 'undefined') method.setCode(body);
    }
    return this;
};
github glayzzle / php-writer / test / assert.js View on Github external
(function parseCode() {
      ast = parser.parseEval(code, {
        parser: {
          extractDoc: true
        }
      });
    }).should.not.throw(code);
    this.obj.should.be.Object();
github glayzzle / php-writer / src / constant.js View on Github external
Constant.prototype.setValue = function(value) {
    if (value) {
        var ast = parser.parseEval('return '+value+';');
        this.ast.value = ast.children[0].expr;
    } else {
        this.ast.value = null;
    }
    return this;
};
github glayzzle / php-writer / src / helpers / editor.js View on Github external
obj.prototype.setCode = function(code) {
    var ast = parser.parseEval(code);
    this.ast[property] = ast.children;
    return this;
  };
github glayzzle / php-writer / src / function.js View on Github external
fn.prototype.setArgs = function(args) {
    var ast = parser.parseEval('function a('+args+') {}');
    this.ast.arguments = ast.children[0].arguments;
    return this;
};
github glayzzle / php-writer / src / property.js View on Github external
Property.prototype.setValue = function(value) {
    if (value) {
        var ast = parser.parseEval('return '+value+';');
        this.ast.value = ast.children[0].expr;
    } else {
        this.ast.value = null;
    }
    return this;
};

php-parser

Parse PHP code from JS and returns its AST

BSD-3-Clause
Latest version published 11 months ago

Package Health Score

75 / 100
Full package analysis