Open
Description
My arrow function macro is as follows:
(macro =>
(function ()
(= env this)
(= atoms ((. Array from) (. arguments 0 values)))
(= propertyIdentifiers
((. atoms map)
(function (atom) (return ((. env compile) atom)))))
(= properties ((. propertyIdentifiers map)
(function (identifier)
(return (object type "Property"
key identifier
value identifier
shorthand true)))))
(= estree (object
type "ArrowFunctionExpression"
generator false
async false
params properties
body ((. this compile) (. arguments 1))))
(return estree)))
I show the Ecmascript it produces with:
(macro showEcma
(lambda (expression)
(return `((. console log)
,((. this string)
((. this compileToJs)
((. this compile) expression)))))
(return null)))
And I show the AST representation with:
(macro showAST
(lambda (expression)
(return ((. console log)
((. this compile) expression)))))
When I run :
(showEcma (= var1
(=> (a b c)
(block ((. console log) a)
((. console log) b)
((. console log) c)))))
I get:
var1 = (a, b, c) => {
console.log(a);
console.log(b);
console.log(c);
};
When I showAST I get:
{
type: 'AssignmentExpression',
operator: '=',
left: {
type: 'Identifier',
name: 'var1',
loc: { start: [Object], end: [Object] }
},
right: {
type: 'ArrowFunctionExpression',
generator: false,
async: false,
params: [ [Object], [Object], [Object] ],
body: { type: 'BlockStatement', body: [Array], loc: [Object] },
loc: { start: [Object], end: [Object] }
},
loc: {
start: { offset: 22, line: 1, column: 22 },
end: { offset: 23, line: 1, column: 23 }
}
}
Looks good to me. But when I go live with it:
(= var1 (=> (a b c)
(block ((. console log) a)
((. console log) b)
((. console log) c))))
I get:
[Error] AssignmentExpression `right` member must be an expression node
At line 1, offset 1:
Any ideas?
Kevin
Metadata
Metadata
Assignees
Labels
No labels