@syntest/analysis-javascript
Version:
SynTest CFG JavaScript is a library for generating control flow graphs for the JavaScript language
58 lines • 2.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConstantVisitor = void 0;
const ast_visitor_javascript_1 = require("@syntest/ast-visitor-javascript");
class ConstantVisitor extends ast_visitor_javascript_1.AbstractSyntaxTreeVisitor {
get constantPool() {
return this._constantPool;
}
constructor(filePath, syntaxForgiving, constantPool) {
super(filePath, syntaxForgiving);
this.Literal = (path) => {
switch (path.node.type) {
case "StringLiteral": {
this._constantPool.addString(path.node.value);
break;
}
case "NumericLiteral": {
if (Number.isInteger(path.node.value)) {
this._constantPool.addInteger(path.node.value);
}
else {
this._constantPool.addNumeric(path.node.value);
}
break;
}
case "NullLiteral": {
// Not useful for the constant pool
break;
}
case "BooleanLiteral": {
// Not useful for the constant pool
break;
}
case "RegExpLiteral": {
break;
}
case "TemplateLiteral": {
break;
}
case "BigIntLiteral": {
this._constantPool.addBigInt(BigInt(path.node.value));
break;
}
case "DecimalLiteral": {
this._constantPool.addNumeric(Number(path.node.value));
break;
}
default: {
// should never occur
throw new Error(`Unknown literal type`);
}
}
};
this._constantPool = constantPool;
}
}
exports.ConstantVisitor = ConstantVisitor;
//# sourceMappingURL=ConstantVisitor.js.map