mirror of https://github.com/lukechilds/rollup.git
Rich-Harris
8 years ago
12 changed files with 144 additions and 25 deletions
@ -1,11 +1,22 @@ |
|||
import Statement from './shared/Statement.js'; |
|||
import assignTo from './shared/assignTo.js'; |
|||
import Scope from '../scopes/Scope.js'; |
|||
import { STRING } from '../values.js'; |
|||
|
|||
export default class ForInStatement extends Statement { |
|||
initialise ( scope ) { |
|||
this.body.createScope( scope ); |
|||
super.initialise( this.body.scope ); |
|||
assignTo( this.left, this.body.scope, STRING ); |
|||
if ( this.body.type === 'BlockStatement' ) { |
|||
this.body.createScope( scope ); |
|||
this.scope = this.body.scope; |
|||
} else { |
|||
this.scope = new Scope({ |
|||
parent: scope, |
|||
isBlockScope: true, |
|||
isLexicalBoundary: false |
|||
}); |
|||
} |
|||
|
|||
super.initialise( this.scope ); |
|||
assignTo( this.left, this.scope, STRING ); |
|||
} |
|||
} |
|||
|
@ -1,11 +1,22 @@ |
|||
import Statement from './shared/Statement.js'; |
|||
import assignTo from './shared/assignTo.js'; |
|||
import Scope from '../scopes/Scope.js'; |
|||
import { UNKNOWN } from '../values.js'; |
|||
|
|||
export default class ForOfStatement extends Statement { |
|||
initialise ( scope ) { |
|||
this.body.createScope( scope ); |
|||
super.initialise( this.body.scope ); |
|||
assignTo( this.left, this.body.scope, UNKNOWN ); |
|||
if ( this.body.type === 'BlockStatement' ) { |
|||
this.body.createScope( scope ); |
|||
this.scope = this.body.scope; |
|||
} else { |
|||
this.scope = new Scope({ |
|||
parent: scope, |
|||
isBlockScope: true, |
|||
isLexicalBoundary: false |
|||
}); |
|||
} |
|||
|
|||
super.initialise( this.scope ); |
|||
assignTo( this.left, this.scope, UNKNOWN ); |
|||
} |
|||
} |
|||
|
@ -1,22 +1,23 @@ |
|||
import Statement from './shared/Statement.js'; |
|||
import Scope from '../scopes/Scope.js'; |
|||
|
|||
export default class ForStatement extends Statement { |
|||
hasEffects () { |
|||
return super.hasEffects( this.body.scope ); |
|||
} |
|||
|
|||
initialise ( scope ) { |
|||
this.body.createScope( scope ); |
|||
scope = this.body.scope; |
|||
if ( this.body.type === 'BlockStatement' ) { |
|||
this.body.createScope( scope ); |
|||
this.scope = this.body.scope; |
|||
} else { |
|||
this.scope = new Scope({ |
|||
parent: scope, |
|||
isBlockScope: true, |
|||
isLexicalBoundary: false |
|||
}); |
|||
} |
|||
|
|||
// can't use super, because we need to control the order
|
|||
if ( this.init ) this.init.initialise( scope ); |
|||
if ( this.test ) this.test.initialise( scope ); |
|||
if ( this.update ) this.update.initialise( scope ); |
|||
this.body.initialise( scope ); |
|||
} |
|||
|
|||
run ( scope ) { |
|||
super.run( scope ); |
|||
if ( this.init ) this.init.initialise( this.scope ); |
|||
if ( this.test ) this.test.initialise( this.scope ); |
|||
if ( this.update ) this.update.initialise( this.scope ); |
|||
this.body.initialise( this.scope ); |
|||
} |
|||
} |
|||
|
@ -0,0 +1,3 @@ |
|||
module.exports = { |
|||
description: 'supports body-less for loops' |
|||
}; |
@ -0,0 +1,16 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
for ( let i = 0; i < 10; i += 1 ) console.log( i ); |
|||
for ( const letter of array ) console.log( letter ); |
|||
for ( const index in array ) console.log( index ); |
|||
|
|||
let i; |
|||
for ( i = 0; i < 10; i += 1 ) console.log( i ); |
|||
|
|||
let letter; |
|||
for ( letter of array ) console.log( letter ); |
|||
|
|||
let index; |
|||
for ( index in array ) console.log( index ); |
|||
|
|||
}); |
@ -0,0 +1,14 @@ |
|||
'use strict'; |
|||
|
|||
for ( let i = 0; i < 10; i += 1 ) console.log( i ); |
|||
for ( const letter of array ) console.log( letter ); |
|||
for ( const index in array ) console.log( index ); |
|||
|
|||
let i; |
|||
for ( i = 0; i < 10; i += 1 ) console.log( i ); |
|||
|
|||
let letter; |
|||
for ( letter of array ) console.log( letter ); |
|||
|
|||
let index; |
|||
for ( index in array ) console.log( index ); |
@ -0,0 +1,12 @@ |
|||
for ( let i = 0; i < 10; i += 1 ) console.log( i ); |
|||
for ( const letter of array ) console.log( letter ); |
|||
for ( const index in array ) console.log( index ); |
|||
|
|||
let i; |
|||
for ( i = 0; i < 10; i += 1 ) console.log( i ); |
|||
|
|||
let letter; |
|||
for ( letter of array ) console.log( letter ); |
|||
|
|||
let index; |
|||
for ( index in array ) console.log( index ); |
@ -0,0 +1,17 @@ |
|||
(function () { |
|||
'use strict'; |
|||
|
|||
for ( let i = 0; i < 10; i += 1 ) console.log( i ); |
|||
for ( const letter of array ) console.log( letter ); |
|||
for ( const index in array ) console.log( index ); |
|||
|
|||
let i; |
|||
for ( i = 0; i < 10; i += 1 ) console.log( i ); |
|||
|
|||
let letter; |
|||
for ( letter of array ) console.log( letter ); |
|||
|
|||
let index; |
|||
for ( index in array ) console.log( index ); |
|||
|
|||
}()); |
@ -0,0 +1,20 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
(factory()); |
|||
}(this, (function () { 'use strict'; |
|||
|
|||
for ( let i = 0; i < 10; i += 1 ) console.log( i ); |
|||
for ( const letter of array ) console.log( letter ); |
|||
for ( const index in array ) console.log( index ); |
|||
|
|||
let i; |
|||
for ( i = 0; i < 10; i += 1 ) console.log( i ); |
|||
|
|||
let letter; |
|||
for ( letter of array ) console.log( letter ); |
|||
|
|||
let index; |
|||
for ( index in array ) console.log( index ); |
|||
|
|||
}))); |
@ -0,0 +1,12 @@ |
|||
for ( let i = 0; i < 10; i += 1 ) console.log( i ); |
|||
for ( const letter of array ) console.log( letter ); |
|||
for ( const index in array ) console.log( index ); |
|||
|
|||
let i; |
|||
for ( i = 0; i < 10; i += 1 ) console.log( i ); |
|||
|
|||
let letter; |
|||
for ( letter of array ) console.log( letter ); |
|||
|
|||
let index; |
|||
for ( index in array ) console.log( index ); |
Loading…
Reference in new issue