Skip to content

Commit

Permalink
fix(tokenize): support reserved "constructor" token
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink committed Aug 12, 2024
1 parent f32fb72 commit c039ce2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions prototype/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ function _groups(tokens, phrases) {
// key is a single word token (the first word in
// the phrase) and the values is an array of
// phrases which contain that word.
const index = {};
const index = Object.create(null);
phrases.forEach( phrase => {
const words = phrase.split(/\s+/);
const firstWord = words[0];
if( !index.hasOwnProperty( firstWord ) ){
if( !index[ firstWord ] ){
index[ firstWord ] = [];
}
index[ firstWord ].push( words );
Expand Down
11 changes: 11 additions & 0 deletions test/prototype/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ module.exports._groups = function(test, common) {
t.deepEqual(tokenize._groups(tokens, phrases), expected);
t.end();
});

// https://github.com/pelias/placeholder/issues/231
test('_groups "constructor"', function(t) {

const tokens = ['constructor'];
const phrases = [];
const expected = [];

t.deepEqual(tokenize._groups(tokens, phrases), expected);
t.end();
});
};

//
Expand Down

0 comments on commit c039ce2

Please sign in to comment.