Skip to content

Commit

Permalink
fix(parser): tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JiLiZART committed Dec 26, 2023
1 parent 2a2dd91 commit 2e604c6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
Empty file removed benchmark/test.js
Empty file.
4 changes: 2 additions & 2 deletions packages/bbob-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export function iterate<Content, Iterable = ArrayLike<Content> | Content>(t: Ite
for (let idx = 0; idx < tree.length; idx++) {
tree[idx] = iterate(cb(tree[idx]), cb);
}
} else if (tree && isObj(tree) && 'content' in tree) {
iterate(tree.content, cb);
} else if (isObj(tree) && 'content' in tree) {
iterate(tree.content, cb);
}

return tree;
Expand Down
3 changes: 1 addition & 2 deletions packages/bbob-parser/src/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ class Token<TokenValue = string> {
}

isEmpty() {
// eslint-disable-next-line no-restricted-globals
return isNaN(this[TOKEN_TYPE_ID]);
return this[TOKEN_TYPE_ID] === 0 || isNaN(this[TOKEN_TYPE_ID]);
}

isText() {
Expand Down
27 changes: 8 additions & 19 deletions packages/bbob-parser/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,31 @@ export interface ParseOptions {
}

class NodeList<Value> {
private m: Map<number, Value>
private c: number
private n: Value[]

constructor() {
this.m = new Map<number, Value>()
this.c = 0
this.n = []
}

last() {
const node = this.m.get(this.c)

if (node) {
return node
if (Array.isArray(this.n) && this.n.length > 0 && typeof this.n[this.n.length - 1] !== 'undefined') {
return this.n[this.n.length - 1]
}

return null
}

flush() {
if (this.c > 0) {
const item = this.m.get(this.c)
this.m.delete(this.c)
this.c = this.c - 1
return item
}

return false
return this.n.length ? this.n.pop() : false
}

push(value: Value) {
this.c = this.c + 1;
this.m.set(this.c, value)
this.n.push(value)
}

toArray() {
return [...this.m.values()]
console.log('toArray', this.n);
return this.n
}
}

Expand Down

0 comments on commit 2e604c6

Please sign in to comment.