@algebraic/ast
Advanced tools
Comparing version 1.0.0-alpha.13 to 1.0.0-alpha.14
@@ -10,3 +10,6 @@ const { is, data, nullable, array, or } = require("@algebraic/type"); | ||
exports.AssignmentExpression = Node `AssignmentExpression` ( | ||
left => Node.RootPattern, | ||
left => or (Node.IdentifierExpression, | ||
Node.MemberExpression, | ||
Node.ArrayPattern, | ||
Node.ObjectPattern), | ||
right => Node.Expression, | ||
@@ -117,2 +120,6 @@ operator => string, | ||
exports.MemberExpression = union2 `MemberExpression` ( | ||
is => Node.StaticMemberExpression, | ||
or => Node.ComputedMemberExpression ); | ||
exports.NewExpression = Node `NewExpression` ( | ||
@@ -119,0 +126,0 @@ callee => Node.Expression, |
@@ -87,5 +87,2 @@ const Comment = require("./comment"); | ||
}))(); | ||
const Assignment = type => | ||
({ left, ...mappedFields }) => | ||
type({ left: toPattern(left), ...mappedFields }); | ||
const toPatternFields = (keys, type) => mappedFields => | ||
@@ -105,4 +102,2 @@ type({ ...mappedFields, ...Object.fromEntries(keys | ||
AssignmentExpression: Assignment(Node.AssignmentExpression, false), | ||
MemberExpression: (mappedFields, { computed, property }) => | ||
@@ -113,2 +108,3 @@ Node.MemberExpression(computed ? | ||
CatchClause: toPatternFields(["param"], Node.CatchClause), | ||
VariableDeclarator: toPatternFields(["id"], Node.VariableDeclarator), | ||
@@ -127,3 +123,4 @@ | ||
AssignmentPattern: Assignment(Node.AssignmentPattern, true), | ||
AssignmentPattern: ({ left, ...mappedFields }) => | ||
type({ left: toPattern(left), ...mappedFields }), | ||
@@ -182,76 +179,1 @@ ArrayPattern: mappedFields => | ||
/* | ||
const Node = require("./node"); | ||
const { NODE_FIELDS } = require("@babel/types"); | ||
const undeprecated = require("./babel/undeprecated-types"); | ||
const trivialMappings = Object | ||
.key(undeprecated) | ||
.map(name => [name, ] | ||
function trivial(name) | ||
{ | ||
const fields = NODE_FIELDS[name]; | ||
const type = Node[name]; | ||
return function (babelNode) | ||
{ | ||
const entries = fields | ||
.map(field => [field, fromBabel(babelNode[field])]); | ||
return type({ ...babelNode, }); | ||
babelNode | ||
NODE_FIELDS | ||
t[name] | ||
} | ||
} | ||
const fromJS = (type, object) => | ||
type((fields => Object.fromEntries(Object | ||
.keys(object) | ||
.map(key => [key, fields[key]]) | ||
.map(([key, type]) => !type || is(primitive, type) ? | ||
object[key] : fromJS(type, object[key])))) | ||
(Object.fromEntries(data.fields(type)))); | ||
.map() | ||
function mapCommonFields(node) => | ||
({ | ||
leadingComments: (node || []).map(comment => Comment) | ||
}) | ||
{ | ||
return { | ||
leadingComments => [nullable(Array), null], | ||
innerComments => [nullable(Array), null], | ||
trailingComment => [nullable(Array), null], | ||
start => [nullable(number), null], | ||
end => [nullable(number), null], | ||
loc => [nullable(SourceLocation), null] | ||
} | ||
module.exports = function fromBabel(node) | ||
{ | ||
return node; | ||
} | ||
/* | ||
const fromJS = (type, object) => | ||
type((fields => Object.fromEntries(Object | ||
.keys(object) | ||
.map(key => [key, fields[key]]) | ||
.map(([key, type]) => [key, | ||
!type || typeof object[key] !== "object" ? | ||
object[key] : fromJS(type, object[key])]))) | ||
(Object.fromEntries(data.fields(type)))); | ||
*/ |
{ | ||
"name": "@algebraic/ast", | ||
"version": "1.0.0-alpha.13", | ||
"version": "1.0.0-alpha.14", | ||
"description": "", | ||
@@ -18,5 +18,5 @@ "main": "node.js", | ||
"peerDependencies": { | ||
"@algebraic/type": "1.0.0-alpha.13", | ||
"@algebraic/collectoons": "1.0.0-alpha.13" | ||
"@algebraic/type": "1.0.0-alpha.14", | ||
"@algebraic/collectoons": "1.0.0-alpha.14" | ||
} | ||
} |
48013
909