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 ); 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 () { 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 ) { 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; const propValue = this.computed ? this.property.run() : this.property.name;
if ( !objectValue ) { if ( !objectValue ) {
console.log( this.object ) console.log( `${this.object} does not contain a value` );
console.log( `${this}` )
} }
if ( !objectValue.setProperty ) { if ( !objectValue.setProperty ) {

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

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

3
src/ast/scopes/BundleScope.js

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

4
src/ast/scopes/Scope.js

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

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

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

Loading…
Cancel
Save