Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-env mocha */
'use strict'
const Syntax = require('doctrine').Syntax
const expect = require('chai').expect
const remark = require('remark')
const Utils = require('../lib/utils')
describe('utils', () => {
const u = new Utils({hljs: {highlightAuto: false}}, [])
describe('md', () => {
it('renders remark asts', () => {
expect(
u.md(
remark().parse(
'Converts from `Result` to `?Error`'
)
)
var t =
this.getExpressionAval(typeManager, subExpr, reason, innerType);
if (t) {
types.push(t);
}
}, this);
return typeManager.getUnionType(types);
case doctrine.Syntax.RestType:
// TODO: Expose varargs #20.
return this.getExpressionAval(
typeManager, typeExpr.expression, reason, innerType);
case doctrine.Syntax.RecordType:
case doctrine.Syntax.FieldType:
// TODO: Handle records #15.
return null;
case doctrine.Syntax.FunctionType:
// TODO: Handle functions #16.
return null;
case doctrine.Syntax.TypeApplication:
// TODO: Handle more exotic type applications?
// We support type applications for array and object values. In those
// cases, only the last applied type (the value type) is meaningful.
return this.getExpressionAval(typeManager, typeExpr.expression, reason,
this.getExpressionAval(typeManager,
typeExpr.applications[typeExpr.applications.length - 1],
reason, innerType));
case doctrine.Syntax.NullLiteral:
case doctrine.Syntax.UndefinedLiteral:
case doctrine.Syntax.NullableLiteral:
case doctrine.Syntax.AllLiteral:
case doctrine.Syntax.VoidLiteral:
// No type to apply.
var t =
this.getExpressionAval(typeManager, subExpr, reason, innerType);
if (t) {
types.push(t);
}
}, this);
return typeManager.getUnionType(types);
case doctrine.Syntax.RestType:
// TODO: Expose varargs #20.
return this.getExpressionAval(
typeManager, typeExpr.expression, reason, innerType);
case doctrine.Syntax.RecordType:
case doctrine.Syntax.FieldType:
// TODO: Handle records #15.
return null;
case doctrine.Syntax.FunctionType:
// TODO: Handle functions #16.
return null;
case doctrine.Syntax.TypeApplication:
// TODO: Handle more exotic type applications?
// We support type applications for array and object values. In those
// cases, only the last applied type (the value type) is meaningful.
return this.getExpressionAval(typeManager, typeExpr.expression, reason,
this.getExpressionAval(typeManager,
typeExpr.applications[typeExpr.applications.length - 1],
reason, innerType));
case doctrine.Syntax.NullLiteral:
case doctrine.Syntax.UndefinedLiteral:
case doctrine.Syntax.NullableLiteral:
case doctrine.Syntax.AllLiteral:
case doctrine.Syntax.VoidLiteral:
// No type to apply.
'use strict';
var formatMarkdown = require('./format_markdown');
var Syntax = require('doctrine').Syntax;
/**
* Format a parameter name. This is used in formatParameters
* and just needs to be careful about differentiating optional
* parameters
*
* @param {Object} param a param as a type spec
* @returns {string} formatted parameter representation.
*/
function formatParameter(param, short) {
if (short) {
return param.type.type == Syntax.OptionalType ? '[' + param.name + ']' : param.name;
} else {
return param.name + ': ' + formatMarkdown.type(param.type).replace(/\n/g, '');
}
}
var doctrine = require("doctrine");
var doctrineSyntax = doctrine.Syntax;
var codeBlock = require("indented-code-block");
var TYPE_MAPPING = {};
TYPE_MAPPING[doctrineSyntax.RecordType] = "Object";
var NAME_REGEX = /(\s|\[|^)(\w+((-+|\.)\w+)*)($|\s+?|\-|=|\]).*$/;
/**
* Get JSDoc type
*/
function getJSDocType(tag) {
var type = tag.type;
if (type) {
if (type.elements) {
'use strict';
var formatMarkdown = require('./format_markdown');
var Syntax = require('doctrine').Syntax;
/**
* Format a parameter name. This is used in formatParameters
* and just needs to be careful about differentiating optional
* parameters
*
* @param {Object} param a param as a type spec
* @returns {string} formatted parameter representation.
*/
function formatParameter(param, short) {
if (short) {
return param.type.type == Syntax.OptionalType ? '[' + param.name + ']' : param.name;
} else {
return param.name + ': ' + formatMarkdown.type(param.type).replace(/\n/g, '');
}
}