mirror of https://github.com/lukechilds/rollup.git
Rich-Harris
8 years ago
22 changed files with 221 additions and 78 deletions
@ -1,8 +1,26 @@ |
|||
import Node from '../Node.js'; |
|||
import { ARRAY } from '../values.js'; |
|||
import { ARRAY, unknown } from '../values.js'; |
|||
|
|||
class ArrayValue { |
|||
constructor ( node ) { |
|||
this.node = node; |
|||
this.values = node.elements.map( element => element.run() ); |
|||
} |
|||
|
|||
getProperty ( name ) { |
|||
return unknown; // TODO return values, or prototype methods etc
|
|||
} |
|||
setProperty ( name, value ) { |
|||
// TODO
|
|||
} |
|||
} |
|||
|
|||
export default class ArrayExpression extends Node { |
|||
gatherPossibleValues ( values ) { |
|||
values.add( ARRAY ); |
|||
} |
|||
|
|||
run () { |
|||
return new ArrayValue( this ); |
|||
} |
|||
} |
|||
|
@ -0,0 +1,65 @@ |
|||
import { blank } from '../../../utils/object.js'; |
|||
import { unknown } from '../../values.js'; |
|||
|
|||
class AsyncFunctionReturnValue { |
|||
constructor ( value ) { |
|||
this.value = value; |
|||
} |
|||
|
|||
getProperty () { |
|||
// TODO express promise semantics somehow?
|
|||
return unknown; |
|||
} |
|||
} |
|||
|
|||
export default class FunctionValue { |
|||
constructor ( node ) { |
|||
this.node = node; |
|||
this.values = blank(); |
|||
} |
|||
|
|||
call ( context, args ) { |
|||
if ( this.node.isCalling ) return; // recursive functions
|
|||
this.node.isCalling = true; |
|||
|
|||
let returnValue; |
|||
this.node.body.scope.initialise(); |
|||
|
|||
args.forEach( ( arg, i ) => { |
|||
const param = this.node.params[i]; |
|||
|
|||
if ( !param ) return; |
|||
|
|||
if ( param.type !== 'Identifier' ) { |
|||
throw new Error( 'TODO desctructuring' ); |
|||
} |
|||
|
|||
this.node.body.scope.setValue( param.name, arg ); |
|||
}); |
|||
|
|||
for ( const node of this.node.body.body ) { |
|||
node.run(); |
|||
if ( node.type === 'ReturnStatement' ) { |
|||
returnValue = node.argument ? node.argument.run() : undefined; // TODO represent undefined
|
|||
break; |
|||
} |
|||
} |
|||
|
|||
this.node.isCalling = false; |
|||
|
|||
return this.node.async ? new AsyncFunctionReturnValue( returnValue ) : returnValue; |
|||
} |
|||
|
|||
getProperty ( name ) { |
|||
return this.values[ name ]; // TODO .length etc
|
|||
} |
|||
|
|||
markReturnStatements () { |
|||
this.node.returnStatements.forEach( statement => statement.mark() ); |
|||
} |
|||
|
|||
setProperty ( name, value ) { |
|||
// TODO unknown names
|
|||
this.values[ name ] = value; |
|||
} |
|||
} |
@ -1,3 +1,4 @@ |
|||
module.exports = { |
|||
solo: true, |
|||
description: 'it does static lookup optimization of internal namespaces' |
|||
}; |
|||
|
Loading…
Reference in new issue