Skip to content

Commit

Permalink
[Bug] Fix #43
Browse files Browse the repository at this point in the history
  • Loading branch information
Siubaak committed Nov 12, 2019
1 parent e03e3e2 commit 722a65e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
16 changes: 13 additions & 3 deletions src/compile/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,23 @@ function hoistVar(statement: estree.Statement, state: State) {
hoistVarDclr(statement, state)
}
break
case 'WhileStatement':
case 'DoWhileStatement':
case 'ForStatement':
case 'ForInStatement':
case 'ForOfStatement':
if (statement.left.type === 'VariableDeclaration') {
hoistVar(statement.left, state)
}
case 'ForStatement':
if (statement.type === 'ForStatement' && statement.init.type === 'VariableDeclaration') {
hoistVar(statement.init, state)
}
case 'WhileStatement':
case 'DoWhileStatement':
hoistVar(statement.body, state)
break
case 'IfStatement':
hoistVar(statement.consequent, state)
hoistVar(statement.alternate, state)
break
case 'BlockStatement':
for (let i = 0; i < statement.body.length; i++) {
hoistVar(statement.body[i], state)
Expand Down
18 changes: 3 additions & 15 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,7 @@ import Sval from '.'

const interpreter = new Sval()
interpreter.run(`
class A {
get g() {
return this.k + 1
}
}
class B extends A { }
class C extends B {
constructor() {
super()
this.k = 1
exports.g = super.g
}
}
new C()
var start = Date.now()
for (var i = 0; i < 50000000; i++) {}
console.log((Date.now() - start) / 1000) // 3.45s now :D
`)
console.log(interpreter.exports.g)

0 comments on commit 722a65e

Please sign in to comment.