Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
};
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;
};
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;
};
(function parseCode() {
ast = parser.parseEval(code, {
parser: {
extractDoc: true
}
});
}).should.not.throw(code);
this.obj.should.be.Object();
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;
};
obj.prototype.setCode = function(code) {
var ast = parser.parseEval(code);
this.ast[property] = ast.children;
return this;
};
fn.prototype.setArgs = function(args) {
var ast = parser.parseEval('function a('+args+') {}');
this.ast.arguments = ast.children[0].arguments;
return this;
};
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;
};