handle object literals whose property names must be escaped in a regexp (#775)

This commit is contained in:
Jeff Williams 2014-10-05 21:35:45 -07:00
parent 765abd9a10
commit 4eb86a13a2
3 changed files with 33 additions and 1 deletions

View File

@ -74,7 +74,7 @@ var REGEXP_LEADING_SCOPE = new RegExp('^(' + REGEXP_SCOPE_PUNC + ')');
var REGEXP_TRAILING_SCOPE = new RegExp('(' + REGEXP_SCOPE_PUNC + ')$');
function nameIsLongname(name, memberof) {
var regexp = new RegExp('^' + memberof + REGEXP_SCOPE_PUNC);
var regexp = new RegExp('^' + escape(memberof) + REGEXP_SCOPE_PUNC);
return regexp.test(name);
}

10
test/fixtures/objectlit3.js vendored Normal file
View File

@ -0,0 +1,10 @@
/** Tokens that can appear in the stream. */
var tokens = {
/** Open parenthesis. */
'(': {
/** Executed before the token is processed. */
before: function(token) {},
/** Executed after the token is processed. */
after: function(token) {}
}
};

View File

@ -42,4 +42,26 @@ describe('object literals', function() {
expect(found[0].scope).toBe('static');
});
});
describe('When an object literal\'s property names must be escaped in a regexp', function() {
var docSet;
var found;
function loadDocSet() {
docSet = jasmine.getDocSetFromFile('test/fixtures/objectlit3.js');
found = docSet.getByLongname('tokens.(.before');
}
it('should not throw an error when creating a doclet', function() {
expect(loadDocSet).not.toThrow();
});
it('should have a doclet with the correct name', function() {
expect(found[0].name).toBe('before');
});
it('should have a doclet with the correct memberof', function() {
expect(found[0].memberof).toBe('tokens.(');
});
});
});