Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('function type with name', () => {
let type = doctrine.parseType('function(a)');
assert.deepEqual(type, {
type: 'FunctionType',
params: [
{
type: 'NameExpression',
name: 'a'
}
],
result: null
});
});
it('function type with name and type', () => {
it('rest array type', () => {
let type = doctrine.parseType('[string,...string]');
assert.deepEqual(type, {
elements: [
{
name: 'string',
type: 'NameExpression'
},
{
expression: {
name: 'string',
type: 'NameExpression'
},
type: 'RestType'
}
],
type: 'ArrayType'
});
it('should parse record types', () => {
var fixture = '{ a: number, b: string }';
assert.deepEqual(parse(fixture), doctrine.parseType(fixture));
fixture = '{a: number, b: string}';
assert.deepEqual(parse(fixture), doctrine.parseType(fixture));
fixture = '{a: number, b: string, c}';
assert.deepEqual(parse(fixture), doctrine.parseType(fixture));
fixture = '{ a: number, b : string, c }';
assert.deepEqual(parse(fixture), doctrine.parseType(fixture));
fixture = '{ a : number, b : string, c }';
assert.deepEqual(parse(fixture), doctrine.parseType(fixture));
});
it('should parse a type in parens', () => {
assert.deepEqual(parse('(boolean)'), doctrine.parseType('(boolean)'));
assert.deepEqual(parse('(Window)'), doctrine.parseType('(Window)'));
});
it('boolean literal type', () => {
let type = doctrine.parseType('true');
assert.deepEqual(type, {
type: 'BooleanLiteralType',
value: true
});
type = doctrine.parseType('false');
assert.deepEqual(type, {
type: 'BooleanLiteralType',
value: false
});
});
assert.throws(() => doctrine.parseType('{0xd'), /unexpected token/);
assert.throws(() => doctrine.parseType('{0x2_:'), /unexpected token/);
assert.throws(() => doctrine.parseType('{0y'), /unexpected token/);
assert.throws(() => doctrine.parseType('{0'), /unexpected token/);
assert.throws(() => doctrine.parseType('{021:'), /unexpected token/);
assert.throws(() => doctrine.parseType('{021_:'), /unexpected token/);
assert.throws(() => doctrine.parseType('function(number=, string)'), /not reach to EOF/);
});
function jsDocParseType (typeString) {
var node;
try {
node = jsDocSimplifyNode(doctrineParser.parseType(typeString));
} catch (e) {
node = [];
node.invalid = true;
}
return node;
}