@algebraic/ast
Advanced tools
Comparing version 1.0.0-alpha.17 to 1.0.0-alpha.18
{ | ||
"name": "@algebraic/ast", | ||
"version": "1.0.0-alpha.17", | ||
"version": "1.0.0-alpha.18", | ||
"description": "", | ||
@@ -18,5 +18,5 @@ "main": "node.js", | ||
"peerDependencies": { | ||
"@algebraic/type": "1.0.0-alpha.17", | ||
"@algebraic/collectoons": "1.0.0-alpha.17" | ||
"@algebraic/type": "1.0.0-alpha.18", | ||
"@algebraic/collectoons": "1.0.0-alpha.18" | ||
} | ||
} |
@@ -7,6 +7,16 @@ const { is } = require("@algebraic/type"); | ||
const Negative = argument => Node.UnaryExpression({ operator: "-", argument }); | ||
const ZeroLiteral = Node.NumericLiteral({ value: 0 }); | ||
const NegativeZeroLiteral = | ||
Node.UnaryExpression({ operator: "-", argument: ZeroLiteral }); | ||
const NegativeZeroLiteral = Negative(ZeroLiteral); | ||
const OneLiteral = Node.NumericLiteral({ value: 1 }); | ||
const NegativeOneLiteral = Negative(OneLiteral); | ||
const Divide = (left, right) => | ||
Node.BinaryExpression({ operator: "/", left, right }); | ||
const NaNLiteral = Divide(ZeroLiteral, ZeroLiteral); | ||
const InfinityLiteral = Divide(OneLiteral, ZeroLiteral); | ||
const NegativeInfinityLiteral = Divide(NegativeOneLiteral, ZeroLiteral); | ||
const TrueLiteral = Node.BooleanLiteral({ value: true }); | ||
@@ -34,10 +44,12 @@ const FalseLiteral = Node.BooleanLiteral({ value: false }); | ||
if (Object.is(0, value)) | ||
return ZeroLiteral; | ||
if (Object.is(-0, value)) | ||
return NegativeZeroLiteral; | ||
if (typeof value === "number") | ||
return Node.NumericLiteral({ value }); | ||
return isNaN(value) ? NaNLiteral : | ||
value === Infinity ? InfinityLiteral : | ||
value === -Infinity ? NegativeInfinityLiteral : | ||
Object.is(-0, value) ? NegativeZeroLiteral : | ||
value === 0 ? ZeroLiteral : | ||
value === 1 ? OneLiteral : | ||
value === -1 ? NegativeOneLiteral : | ||
value > 0 ? Node.NumericLiteral({ value }) : | ||
Negative(Node.NumericLiteral({ value: -value })); | ||
@@ -44,0 +56,0 @@ if (typeof value === "string") |
53100
1033