Socket
Socket
Sign inDemoInstall

radspec

Package Overview
Dependencies
224
Maintainers
5
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.2 to 1.1.3

2

dist/evaluator/index.js

@@ -36,3 +36,3 @@ "use strict";/**

* @return {Promise<string>}
*/async evaluateNode(node){var _Mathceil=Math.ceil;if("ExpressionStatement"===node.type)return(await this.evaluateNodes(node.body)).join(" ");if("GroupedExpression"===node.type)return this.evaluateNode(node.body);if("MonologueStatement"===node.type)return new TypedValue("string",node.value);if("StringLiteral"===node.type)return new TypedValue("string",node.value);if("NumberLiteral"===node.type)return new TypedValue("int256",node.value);if("BytesLiteral"===node.type){const length=_Mathceil((node.value.length-2)/2);return 32<length&&this.panic("Byte literal represents more than 32 bytes"),new TypedValue(`bytes${length}`,node.value)}if("BinaryExpression"===node.type){const left=await this.evaluateNode(node.left),right=await this.evaluateNode(node.right);// String concatenation
*/async evaluateNode(node){var _Mathceil=Math.ceil;if("ExpressionStatement"===node.type)return(await this.evaluateNodes(node.body)).join(" ");if("GroupedExpression"===node.type)return this.evaluateNode(node.body);if("MonologueStatement"===node.type)return new TypedValue("string",node.value);if("StringLiteral"===node.type)return new TypedValue("string",node.value);if("NumberLiteral"===node.type)return new TypedValue("int256",node.value);if("BytesLiteral"===node.type){const length=_Mathceil((node.value.length-2)/2);return 32<length&&this.panic("Byte literal represents more than 32 bytes"),new TypedValue(`bytes${length}`,node.value)}if("BoolLiteral"===node.type)return new TypedValue("bool","true"===node.value);if("BinaryExpression"===node.type){const left=await this.evaluateNode(node.left),right=await this.evaluateNode(node.right);// String concatenation
if(("string"===left.type||"string"===right.type)&&"PLUS"===node.operator)return new TypedValue("string",left.value.toString()+right.value.toString());// TODO Additionally check that the type is signed if subtracting

@@ -39,0 +39,0 @@ switch(types.isInteger(left.type)&&types.isInteger(right.type)||this.panic(`Cannot evaluate binary expression "${node.operator}" for non-integer types "${left.type}" and "${right.type}"`),node.operator){case"PLUS":return new TypedValue("int256",left.value.add(right.value));case"MINUS":return new TypedValue("int256",left.value.sub(right.value));case"STAR":return new TypedValue("int256",left.value.mul(right.value));case"POWER":return new TypedValue("int256",left.value.pow(right.value));case"SLASH":return new TypedValue("int256",left.value.div(right.value));case"MODULO":return new TypedValue("int256",left.value.mod(right.value));default:this.panic(`Undefined binary operator "${node.operator}"`);}}if("ComparisonExpression"===node.type){const left=await this.evaluateNode(node.left),right=await this.evaluateNode(node.right);let leftValue=left.value,rightValue=right.value;const bothTypesAddress=(left,right)=>// isAddress is true if type is address or bytes with size less than 20

@@ -89,3 +89,3 @@ "use strict";/**

* @return {Node}
*/primary(){if(this.matches("NUMBER","STRING","HEXADECIMAL")){let type={NUMBER:"NumberLiteral",STRING:"StringLiteral",HEXADECIMAL:"BytesLiteral"}[this.previous().type];return{type,value:this.previous().value}}if(this.matches("LEFT_PAREN")){let expression;do// Keep munching expressions in the context of the current expression
*/primary(){if(this.matches("NUMBER","STRING","HEXADECIMAL","BOOLEAN")){let type={NUMBER:"NumberLiteral",STRING:"StringLiteral",HEXADECIMAL:"BytesLiteral",BOOLEAN:"BoolLiteral"}[this.previous().type];return{type,value:this.previous().value}}if(this.matches("LEFT_PAREN")){let expression;do// Keep munching expressions in the context of the current expression
expression=this.comparison(expression?[expression]:[]);while(!this.eof()&&!this.matches("RIGHT_PAREN"));return this.eof()&&this.report("Unterminated grouping"),{type:"GroupedExpression",body:expression}}this.report(`Unknown token "${this.consume().type}"`)}/**

@@ -92,0 +92,0 @@ * Try to parse a type.

@@ -29,3 +29,3 @@ "use strict";/**

default:const NUMBERS=/[0-9]/,HEX=/[0-9a-f]/i;if(NUMBERS.test(current)){let number=current,type="NUMBER";// Detect hexadecimals
if("0"===current&&"x"===this.peek())for(type="HEXADECIMAL",number+=this.consume();HEX.test(this.peek());)number+=this.consume();else for(;NUMBERS.test(this.peek());)number+=this.consume();this.emitToken(type,number);break}const IDENTIFIERS=/[_a-z0-9]/i;if(IDENTIFIERS.test(current)){let identifier=current;for(;IDENTIFIERS.test(this.peek());)identifier+=this.consume();types.isType(identifier)?this.emitToken("TYPE",identifier):this.emitToken("IDENTIFIER",identifier);break}if(`'`===current||`"`===current){let string="";for(;!this.matches(`'`)&&!this.matches(`"`);)string+=this.consume();this.emitToken("STRING",string);break}this.report(`Unexpected character "${current}"`);}}/**
if("0"===current&&"x"===this.peek())for(type="HEXADECIMAL",number+=this.consume();HEX.test(this.peek());)number+=this.consume();else for(;NUMBERS.test(this.peek());)number+=this.consume();this.emitToken(type,number);break}const IDENTIFIERS=/[_a-z0-9]/i;if(IDENTIFIERS.test(current)){let identifier=current;for(;IDENTIFIERS.test(this.peek());)identifier+=this.consume();if("true"===identifier||"false"===identifier){this.emitToken("BOOLEAN",identifier);break}types.isType(identifier)?this.emitToken("TYPE",identifier):this.emitToken("IDENTIFIER",identifier);break}if(`'`===current||`"`===current){let string="";for(;!this.matches(`'`)&&!this.matches(`"`);)string+=this.consume();this.emitToken("STRING",string);break}this.report(`Unexpected character "${current}"`);}}/**
* Push a token to `Scanner.tokens`

@@ -32,0 +32,0 @@ *

{
"name": "radspec",
"version": "1.1.2",
"version": "1.1.3",
"description": "Radspec is a safe alternative to Ethereum's natspec",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc