Skip to content

Commit

Permalink
Deprecate Lexer#has
Browse files Browse the repository at this point in the history
  • Loading branch information
tjvr committed Sep 16, 2018
1 parent 536985d commit 40dee4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
11 changes: 1 addition & 10 deletions moo.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,7 @@
}

Lexer.prototype.has = function(tokenType) {
for (var s in this.states) {
var state = this.states[s]
if (state.error && state.error.defaultType === tokenType) return true
var groups = state.groups
for (var i = 0; i < groups.length; i++) {
var group = groups[i]
if (group.defaultType === tokenType) return true
}
}
return false
return true
}


Expand Down
29 changes: 8 additions & 21 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,8 @@ describe('Lexer#has', () => {
expect(basicLexer.has('error')).toBe(true)
})

test('returns false for nonexistent junk', () => {
expect(basicLexer.has('random')).toBe(false)
})

test('returns false for stuff inherited from Object', () => {
expect(basicLexer.has('hasOwnProperty')).toBe(false)
test('returns true even for nonexistent junk', () => {
expect(basicLexer.has('random')).toBe(true)
})

const keywordLexer = compile({
Expand All @@ -580,9 +576,8 @@ describe('Lexer#has', () => {
},
})

test("doesn't work with keywords", () => {
expect(keywordLexer.has('identifier')).toBe(true)
expect(keywordLexer.has('kw-class')).toBe(false)
test("returns true even for keywords", () => {
expect(keywordLexer.has('kw-class')).toBe(true)
})

// Example from the readme.
Expand Down Expand Up @@ -613,20 +608,12 @@ describe('Lexer#has', () => {
expect(statefulLexer.has('interp')).toEqual(true)
})

test('works with error tokens - for first state', () => {
expect(statefulLexer.has('mainErr')).toEqual(true)
})

test('works with error tokens - for second state', () => {
expect(statefulLexer.has('litErr')).toEqual(true)
})

test('returns false for the state names themselves', () => {
expect(statefulLexer.has('main')).toEqual(false)
test('works with error tokens - for first state', () => {
expect(statefulLexer.has('mainErr')).toEqual(true)
})

test('returns false for stuff inherited from Object when using states', () => {
expect(statefulLexer.has('toString')).toEqual(false)
test('works with error tokens - for second state', () => {
expect(statefulLexer.has('litErr')).toEqual(true)
})

})
Expand Down

0 comments on commit 40dee4a

Please sign in to comment.