@algebraic/ast
Advanced tools
Comparing version 1.0.0-alpha.16 to 1.0.0-alpha.17
const Comment = require("./comment"); | ||
const { Position, SourceLocation } = require("./source-location"); | ||
const { is } = require("@algebraic/type"); | ||
@@ -20,6 +21,5 @@ const isNullOrUndefined = | ||
trailingComments: mapComments(node.trailingComments), | ||
start: node.start, | ||
end: node.end, | ||
loc: mapSourceLocation(node.loc), | ||
extra: null | ||
start: node.start || null, | ||
end: node.end || null, | ||
loc: mapSourceLocation(node.loc) | ||
}); | ||
@@ -47,4 +47,5 @@ | ||
[name, toMapNodeFields(name, t.VISITOR_KEYS[name])])); | ||
const mapNode = node => Array.isArray(node) ? | ||
node.map(mapNode) : | ||
const mapNode = node => | ||
Array.isArray(node) ? node.map(mapNode) : | ||
is (Node, node) ? node : | ||
((name, fields) => | ||
@@ -61,3 +62,4 @@ (mappings[name] ? | ||
{ | ||
const { is, string } = require("@algebraic/type"); | ||
const { is, data, string, number, getTypename } = require("@algebraic/type"); | ||
const { parameterized: { parameters } } = require("@algebraic/type/parameterized"); | ||
@@ -168,3 +170,16 @@ const toObjectPropertyKey = ({ computed, key }) => | ||
Node.VarVariableDeclaration({ declarators, ...mappedFields }) : | ||
Node.BlockVariableDeclaration({ kind, declarators, ...mappedFields }) | ||
Node.BlockVariableDeclaration({ kind, declarators, ...mappedFields }), | ||
...Object.fromEntries([ | ||
Node.BigIntLiteral, | ||
Node.NumericLiteral, | ||
Node.RegExpLiteral, | ||
Node.StringLiteral, | ||
Node.DirectiveLiteral] | ||
.map(type => [type, | ||
parameters(parameters(data.fields(type) | ||
.find(field => field.name === "extra"))[0])[0]]) | ||
.map(([type, ExtraT]) => [getTypename(type), | ||
({ extra, ...mappedFields }) => | ||
type({ ...mappedFields, extra: extra ? ExtraT(extra) : null })])) | ||
}); | ||
@@ -171,0 +186,0 @@ })(); |
@@ -20,2 +20,3 @@ const { data, nullable, array } = require("@algebraic/type"); | ||
value => number, | ||
extra => [nullable(Extra(number)), null], | ||
([freeVariables]) => compute.empty (StringSet) ); | ||
@@ -22,0 +23,0 @@ |
15
node.js
const { IsSymbol } = require("@algebraic/type/declaration"); | ||
const { data, nullable, array, number, getTypename, or } = require("@algebraic/type"); | ||
const { of, data, nullable, array, number, getTypename, or } = require("@algebraic/type"); | ||
const tagged = require("@algebraic/type/tagged"); | ||
@@ -7,6 +7,7 @@ const SourceLocation = require("./source-location"); | ||
const ESTreeBridge = require("./estree-bridge"); | ||
const NodeSymbol = Symbol("Node"); | ||
const Node = tagged((name, ...fields) => | ||
ESTreeBridge ([name]) ( | ||
Object.assign(ESTreeBridge ([name]) ( | ||
...fields, | ||
@@ -18,8 +19,7 @@ leadingComments => [nullable(array(Comment)), null], | ||
end => [nullable(number), null], | ||
loc => [nullable(SourceLocation), null] ) ); | ||
loc => [nullable(SourceLocation), null] ), | ||
{ [NodeSymbol]: true }) ); | ||
Node[IsSymbol] = value => | ||
!!value && | ||
typeof value === "object" && | ||
typeof value.type === "string"; | ||
Node.Node = Node; | ||
Node[IsSymbol] = value => !!value && !!of(value) && of(value)[NodeSymbol]; | ||
@@ -49,2 +49,1 @@ module.exports = Node; | ||
}); | ||
{ | ||
"name": "@algebraic/ast", | ||
"version": "1.0.0-alpha.16", | ||
"version": "1.0.0-alpha.17", | ||
"description": "", | ||
@@ -18,5 +18,5 @@ "main": "node.js", | ||
"peerDependencies": { | ||
"@algebraic/type": "1.0.0-alpha.16", | ||
"@algebraic/collectoons": "1.0.0-alpha.16" | ||
"@algebraic/type": "1.0.0-alpha.17", | ||
"@algebraic/collectoons": "1.0.0-alpha.17" | ||
} | ||
} |
@@ -14,3 +14,4 @@ const { is, data, nullable, array, or } = require("@algebraic/type"); | ||
exports.DirectiveLiteral = Node `DirectiveLiteral` ( | ||
value => string ); | ||
value => string, | ||
extra => [nullable(Extra(string)), null] ); | ||
@@ -17,0 +18,0 @@ exports.InterpreterDirective = Node `InterpreterDirective` ( |
52366
18
1022