ast-types
ast-types copied to clipboard
expose parameter metadata for builder functions
Closes #84
var types = require('ast-types');
var assert = require('assert');
var b = types.builders;
var n = types.namedTypes;
assert.strictEqual(b.whileStatement.paramCount, 2);
assert.deepEqual(b.whileStatement[0], {
name: 'test',
body: n.Expression,
required: true
});
assert.deepEqual(b.whileStatement[1], {
name: 'body',
body: n.Statement,
required: true // false for parameters that have a default specified
});
- [ ] General Comment
-
<img border=0 src='https://avatars.githubusercontent.com/u/4082216?v=3' height=16 width=16'> Note that the discussion in #84 suggested a
length
property to determine the number of parameters, but that is already defined (and not configurable) for Functions. It would be possible to generate build functions with the correct arity, so that thelength
property would accurately reflect the number of parameters. Note: thelength
property will be configurable in es6, but is not in es5.
Note that the discussion in #84 suggested a length
property to determine the number of parameters, but that is already defined (and not configurable) for Functions.
It would be possible to generate build functions with the correct arity, so that the length
property would accurately reflect the number of parameters.
Note: the length
property will be configurable in es6, but is not in es5.
:+1: to the idea, although I think a better way to do this would be to add a parameters
array, which removes the need for a separate paramCount
property as parameters.length
can be used instead.