Skip to content

Commit bb610cd

Browse files
committed
fix(tokenize): support reserved "constructor" token
1 parent f32fb72 commit bb610cd

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

prototype/tokenize.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ function _groups(tokens, phrases) {
8484
// key is a single word token (the first word in
8585
// the phrase) and the values is an array of
8686
// phrases which contain that word.
87-
const index = {};
87+
const index = Object.create(null);
8888
phrases.forEach( phrase => {
8989
const words = phrase.split(/\s+/);
9090
const firstWord = words[0];
91-
if( !index.hasOwnProperty( firstWord ) ){
91+
if( !index[ firstWord ] ){
9292
index[ firstWord ] = [];
9393
}
9494
index[ firstWord ].push( words );

test/prototype/tokenize.js

+11
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ module.exports._groups = function(test, common) {
177177
t.deepEqual(tokenize._groups(tokens, phrases), expected);
178178
t.end();
179179
});
180+
181+
// https://github.com/pelias/placeholder/issues/231
182+
test('_groups "constructor"', function(t) {
183+
184+
const tokens = ['constructor'];
185+
const phrases = [];
186+
const expected = [];
187+
188+
t.deepEqual(tokenize._groups(tokens, phrases), expected);
189+
t.end();
190+
});
180191
};
181192

182193
//

0 commit comments

Comments
 (0)