Skip to content

Commit

Permalink
[chore] fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
Siubaak committed Jan 29, 2024
1 parent c830463 commit 14d9cfd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A JavaScript interpreter writen in JavaScript, based on parser [Acorn](https://github.com/acornjs/acorn).

- **Running on ES5, supporting ES5~10 full features**
- **Running on ES5, supporting ES latest features**
- **Both invasived and sandbox modes available**

It's useful to evaluate the code of higher ECMAScript editions, or for the environment with disabled `eval`, `setTimeout` and `new Function`.
Expand Down
4 changes: 2 additions & 2 deletions src/evaluate/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,12 @@ export function* ChainExpression(node: estree.ChainExpression, scope: Scope) {
}

/*<remove>*/
export function* YieldExpression(node: estree.YieldExpression, scope: Scope) {
export function* YieldExpression(node: estree.YieldExpression, scope: Scope): any {
const res = yield* evaluate(node.argument, scope)
return node.delegate ? yield* res : yield res
}

export function* AwaitExpression(node: estree.AwaitExpression, scope: Scope) {
export function* AwaitExpression(node: estree.AwaitExpression, scope: Scope): any {
AWAIT.RES = yield* evaluate(node.argument, scope)
return yield AWAIT
}
Expand Down
2 changes: 1 addition & 1 deletion src/evaluate/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function* ForInStatement(node: estree.ForInStatement, scope: Scope) {
}
}

export function* ForOfStatement(node: estree.ForOfStatement, scope: Scope) {
export function* ForOfStatement(node: estree.ForOfStatement, scope: Scope): any {
const right = yield* evaluate(node.right, scope)
/*<remove>*/
if (node.await) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Sval {

parse(code: string, parser?: (code: string, options: SvalOptions) => Node) {
if (typeof parser === 'function') {
return parser(code, assign({}, this.options))
return parser(code, assign({} as SvalOptions, this.options))
}
return parse(code, this.options)
}
Expand Down
15 changes: 10 additions & 5 deletions tests/bootstrap.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFileSync, existsSync } from 'fs'
import Sval, { SvalOptions } from '../src'
import { ecmaVersion } from 'acorn'
import { resolve } from 'path'
import Sval from '../src'

let code: string

Expand Down Expand Up @@ -54,9 +55,13 @@ describe('testing src/index.ts', () => {
expect((window as any).y2).toBeUndefined()
})

it('should support ecma version 3, 5, 6, 7, 8, 9, 10', () => {
const versions = [3, 5, 6, 7, 8, 9, 10, 2015, 2016, 2017, 2018, 2019]
versions.forEach((v: SvalOptions['ecmaVer']) => new Sval({ ecmaVer: v }))
it('should support all ecma versions', () => {
const versions: ecmaVersion[] = [
3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024,
'latest'
]
versions.forEach((v) => new Sval({ ecmaVer: v }))

try {
new Sval({ ecmaVer: 4 as any })
Expand Down Expand Up @@ -101,7 +106,7 @@ describe('testing src/index.ts', () => {

// other than string / object, other types are not supported
interpreter.import(2 as any)
interpreter.import(undefined)
interpreter.import(undefined as any)
interpreter.import(function() {})
interpreter.import(true as any)
interpreter.import(Symbol('hello') as any)
Expand Down

0 comments on commit 14d9cfd

Please sign in to comment.