Browse Source

more stuff

value-tracking
Rich Harris 8 years ago
parent
commit
ff32317811
  1. 5
      src/ast/nodes/BlockStatement.js
  2. 8
      src/ast/nodes/Identifier.js
  3. 3
      src/ast/nodes/MemberExpression.js
  4. 2
      src/ast/nodes/shared/FunctionValue.js
  5. 3
      src/ast/scopes/BundleScope.js
  6. 4
      src/ast/scopes/Scope.js
  7. 1
      test/form/side-effect-k/_config.js

5
src/ast/nodes/BlockStatement.js

@ -56,4 +56,9 @@ export default class BlockStatement extends Statement {
code.remove( this.start, this.next || this.end );
}
}
run () {
this.scope.initialise();
this.body.forEach( node => node.run() );
}
}

8
src/ast/nodes/Identifier.js

@ -91,7 +91,13 @@ export default class Identifier extends Node {
}
run () {
return this.scope.getValue( this.name );
const value = this.scope.getValue( this.name );
if ( !value ) {
console.log( this.name, this.scope.values )
}
return value;
}
setValue ( value ) {

3
src/ast/nodes/MemberExpression.js

@ -133,8 +133,7 @@ export default class MemberExpression extends Node {
const propValue = this.computed ? this.property.run() : this.property.name;
if ( !objectValue ) {
console.log( this.object )
console.log( `${this}` )
console.log( `${this.object} does not contain a value` );
}
if ( !objectValue.setProperty ) {

2
src/ast/nodes/shared/FunctionValue.js

@ -23,7 +23,7 @@ export default class FunctionValue {
this.node.isCalling = true;
let returnValue;
this.node.body.scope.initialise();
this.node.body.scope.initialise(); // TODO arrow functions...
args.forEach( ( arg, i ) => {
const param = this.node.params[i];

3
src/ast/scopes/BundleScope.js

@ -1,6 +1,7 @@
import Scope from './Scope.js';
import { unknown } from '../values';
// TODO represent things like Array, encodeURIComponent, Math, whatever
class SyntheticGlobalDeclaration {
constructor ( name ) {
this.name = name;
@ -21,7 +22,7 @@ class SyntheticGlobalDeclaration {
}
call ( args ) {
// TODO assume args can be called?
return unknown;
}
gatherPossibleValues ( values ) {

4
src/ast/scopes/Scope.js

@ -107,6 +107,10 @@ export default class Scope {
}
getValue ( name ) {
if ( name === 'x' ) {
console.log( `this.values`, this.values )
}
if ( name in this.values ) {
return this.values[ name ];
}

1
test/form/side-effect-k/_config.js

@ -1,4 +1,5 @@
module.exports = {
solo: true,
description: 'use of arguments is treated as a side-effect',
options: {
moduleName: 'myBundle'

Loading…
Cancel
Save