|
|
@ -1,36 +1,13 @@ |
|
|
|
import Node from '../Node.js'; |
|
|
|
import Scope from '../scopes/Scope.js'; |
|
|
|
import extractNames from '../utils/extractNames.js'; |
|
|
|
import FunctionValue from './shared/FunctionValue.js'; |
|
|
|
|
|
|
|
export default class ArrowFunctionExpression extends Node { |
|
|
|
bind ( scope ) { |
|
|
|
super.bind( this.scope || scope ); |
|
|
|
} |
|
|
|
|
|
|
|
call ( context, args ) { |
|
|
|
// TODO account for `this` and `arguments`
|
|
|
|
if ( this.isCalling ) return; // recursive functions
|
|
|
|
this.isCalling = true; |
|
|
|
|
|
|
|
this.body.scope.initialise(); |
|
|
|
|
|
|
|
args.forEach( ( arg, i ) => { |
|
|
|
const param = this.params[i]; |
|
|
|
|
|
|
|
if ( param.type !== 'Identifier' ) { |
|
|
|
throw new Error( 'TODO desctructuring' ); |
|
|
|
} |
|
|
|
|
|
|
|
throw new Error( 'TODO setValue' ); |
|
|
|
}); |
|
|
|
|
|
|
|
for ( const node of this.body.body ) { |
|
|
|
node.run(); |
|
|
|
} |
|
|
|
|
|
|
|
this.isCalling = false; |
|
|
|
} |
|
|
|
|
|
|
|
findScope ( functionScope ) { |
|
|
|
return this.scope || this.parent.findScope( functionScope ); |
|
|
|
} |
|
|
@ -62,8 +39,7 @@ export default class ArrowFunctionExpression extends Node { |
|
|
|
super.initialise( this.scope ); |
|
|
|
} |
|
|
|
|
|
|
|
markReturnStatements () { |
|
|
|
// TODO implicit returns
|
|
|
|
this.returnStatements.forEach( statement => statement.mark() ); |
|
|
|
run () { |
|
|
|
return new FunctionValue( this ); |
|
|
|
} |
|
|
|
} |
|
|
|