A Babel 6 transform which finds mandatory()
calls which are the default expression for named function parameters and inserts parameter index and name information.
Based on this discussion on Twitter
Try it out in AST Explorer by selecting Transform → babelv6 from the top menu.
Sample code:
function mandatory(argPosition, name) {
throw new Error(`argument at ${argPosition} called ${name} is mandatory`)
}
function foo(mustBeProvided = mandatory()) {
return mustBeProvided
}