mirror of https://github.com/lukechilds/rollup.git
committed by
GitHub
20 changed files with 185 additions and 35 deletions
@ -1,11 +1,22 @@ |
|||||
import Statement from './shared/Statement.js'; |
import Statement from './shared/Statement.js'; |
||||
import assignTo from './shared/assignTo.js'; |
import assignTo from './shared/assignTo.js'; |
||||
|
import Scope from '../scopes/Scope.js'; |
||||
import { STRING } from '../values.js'; |
import { STRING } from '../values.js'; |
||||
|
|
||||
export default class ForInStatement extends Statement { |
export default class ForInStatement extends Statement { |
||||
initialise ( scope ) { |
initialise ( scope ) { |
||||
this.body.createScope( scope ); |
if ( this.body.type === 'BlockStatement' ) { |
||||
super.initialise( this.body.scope ); |
this.body.createScope( scope ); |
||||
assignTo( this.left, this.body.scope, STRING ); |
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 Statement from './shared/Statement.js'; |
||||
import assignTo from './shared/assignTo.js'; |
import assignTo from './shared/assignTo.js'; |
||||
|
import Scope from '../scopes/Scope.js'; |
||||
import { UNKNOWN } from '../values.js'; |
import { UNKNOWN } from '../values.js'; |
||||
|
|
||||
export default class ForOfStatement extends Statement { |
export default class ForOfStatement extends Statement { |
||||
initialise ( scope ) { |
initialise ( scope ) { |
||||
this.body.createScope( scope ); |
if ( this.body.type === 'BlockStatement' ) { |
||||
super.initialise( this.body.scope ); |
this.body.createScope( scope ); |
||||
assignTo( this.left, this.body.scope, UNKNOWN ); |
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,31 +1,23 @@ |
|||||
import Statement from './shared/Statement.js'; |
import Statement from './shared/Statement.js'; |
||||
|
import Scope from '../scopes/Scope.js'; |
||||
|
|
||||
export default class ForStatement extends Statement { |
export default class ForStatement extends Statement { |
||||
bind () { |
|
||||
const scope = this.body.scope; |
|
||||
|
|
||||
this.init.bind( scope ); |
|
||||
this.test.bind( scope ); |
|
||||
this.update.bind( scope ); |
|
||||
this.body.bind( scope ); |
|
||||
} |
|
||||
|
|
||||
hasEffects () { |
|
||||
return super.hasEffects( this.body.scope ); |
|
||||
} |
|
||||
|
|
||||
initialise ( scope ) { |
initialise ( scope ) { |
||||
this.body.createScope( scope ); |
if ( this.body.type === 'BlockStatement' ) { |
||||
scope = this.body.scope; |
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
|
// can't use super, because we need to control the order
|
||||
this.init.initialise( scope ); |
if ( this.init ) this.init.initialise( this.scope ); |
||||
this.test.initialise( scope ); |
if ( this.test ) this.test.initialise( this.scope ); |
||||
this.update.initialise( scope ); |
if ( this.update ) this.update.initialise( this.scope ); |
||||
this.body.initialise( scope ); |
this.body.initialise( this.scope ); |
||||
} |
|
||||
|
|
||||
run ( scope ) { |
|
||||
super.run( 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 ); |
@ -0,0 +1,3 @@ |
|||||
|
module.exports = { |
||||
|
description: 'handles for loop with empty head' |
||||
|
}; |
@ -0,0 +1,7 @@ |
|||||
|
define(function () { 'use strict'; |
||||
|
|
||||
|
for ( ; ; ) { |
||||
|
console.log( 42 ); |
||||
|
} |
||||
|
|
||||
|
}); |
@ -0,0 +1,5 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
for ( ; ; ) { |
||||
|
console.log( 42 ); |
||||
|
} |
@ -0,0 +1,3 @@ |
|||||
|
for ( ; ; ) { |
||||
|
console.log( 42 ); |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
(function () { |
||||
|
'use strict'; |
||||
|
|
||||
|
for ( ; ; ) { |
||||
|
console.log( 42 ); |
||||
|
} |
||||
|
|
||||
|
}()); |
@ -0,0 +1,11 @@ |
|||||
|
(function (global, factory) { |
||||
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
||||
|
typeof define === 'function' && define.amd ? define(factory) : |
||||
|
(factory()); |
||||
|
}(this, (function () { 'use strict'; |
||||
|
|
||||
|
for ( ; ; ) { |
||||
|
console.log( 42 ); |
||||
|
} |
||||
|
|
||||
|
}))); |
@ -0,0 +1,3 @@ |
|||||
|
for ( ; ; ) { |
||||
|
console.log( 42 ); |
||||
|
} |
Loading…
Reference in new issue