Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsdoctypeparser

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsdoctypeparser - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

65

lib/index.js

@@ -8,19 +8,52 @@ // This script licensed under the MIT.

/**
* Namespace for jsdoctypeparser.
* @namespace
* @exports jsdoctypeparser
*/
module.exports = {
get Parser(){
defineProp(this, 'Parser', {value:require('./TypeParser.js')});
return this.Parser;
},
get Lexer(){
defineProp(this, 'Lexer', {value:require('./TypeLexer.js')});
return this.Lexer;
},
get Builder(){
defineProp(this, 'Builder', {value:require('./TypeBuilder.js')});
return this.Builder;
},
get Dictionary(){
defineProp(this, 'Dictionary', {value:require('./TypeDictionary.js')});
return this.Dictionary;
}
/**
* An alias for type expression parsers.
* @type {module:lib/TypeParser}
* @see module:lib/TypeParser
*/
get Parser() {
defineProp(this, 'Parser', { value: require('./TypeParser.js') });
return this.Parser;
},
/**
* An alias for type expression lexers.
* @type {module:lib/TypeLexer}
* @see module:lib/TypeLexer
*/
get Lexer() {
defineProp(this, 'Lexer', { value: require('./TypeLexer.js') });
return this.Lexer;
},
/**
* An alias for type expression object builders.
* @type {module:lib/TypeBuilder}
* @see module:lib/TypeBuilder
*/
get Builder() {
defineProp(this, 'Builder', { value: require('./TypeBuilder.js') });
return this.Builder;
},
/**
* An alias for type name dictionaries.
* @type {module:lib/TypeDictionary}
* @see module:lib/TypeDictionary
*/
get Dictionary() {
defineProp(this, 'Dictionary', { value: require('./TypeDictionary.js') });
return this.Dictionary;
}
};
// This script licensed under the MIT.
// http://orgachem.mit-license.org
/**
* @fileoverview A class for Jsdoc type object builders.
* @author orga.chem.job@gmail.com (OrgaChem)
*/
var util = require('./util.js');

@@ -13,4 +18,5 @@ var TypeLexer = require('./TypeLexer.js');

/**
* A class for type object builders.
* A class for Jsdoc type object builders.
* @constructor
* @exports lib/TypeBuilder
*/

@@ -32,3 +38,3 @@ var TypeBuilder = function() {

* Returns an unknown type.
* @return {TypeBuilder.TypeUnion} Unknown union.
* @return {module:lib/TypeBuilder.TypeUnion} Unknown union.
*/

@@ -54,3 +60,3 @@ TypeBuilder.getUnknownType = function() {

* Builds a type objects.
* @return {TypeBuilder.TypeUnion} Builded objects.
* @return {module:lib/TypeBuilder.TypeUnion} Builded objects.
*/

@@ -81,3 +87,3 @@ TypeBuilder.prototype.build = function() {

* type lexer.
* @return {TypeLexer} Type lexer.
* @return {module:lib/TypeLexer} Type lexer.
* @protected

@@ -92,3 +98,3 @@ */

* Sets a mode.
* @param {TypeBuilder.Mode} mode Mode of the type builder.
* @param {module:lib/TypeBuilder.Mode} mode Mode of the type builder.
*/

@@ -109,2 +115,3 @@ TypeBuilder.prototype.setMode = function(mode) {

* @constructor
* @alias module:lib/TypeBuilder.Mode
*/

@@ -116,3 +123,3 @@ TypeBuilder.Mode = function() {};

* Next mode.
* @type {?TypeBuilder.Mode}
* @type {?module:lib/TypeBuilder.Mode}
* @private

@@ -125,3 +132,3 @@ */

* Builder has the mode.
* @type {?TypeBuilder}
* @type {?module:lib/TypeBuilder}
* @private

@@ -134,3 +141,3 @@ */

* Sets a builder has the mode.
* @param {TypeBuilder} builder Builder has the mode.
* @param {module:lib/TypeBuilder} builder Builder has the mode.
*/

@@ -144,3 +151,3 @@ TypeBuilder.Mode.prototype.setBuilder = function(builder) {

* Returns a builder has the mode.
* @return {TypeBuilder} Builder has the mode.
* @return {module:lib/TypeBuilder} Builder has the mode.
*/

@@ -154,3 +161,3 @@ TypeBuilder.Mode.prototype.getBuilder = function() {

* Sets a mode next to the mode.
* @param {TypeBuilder.Mode} next Next mode.
* @param {module:lib/TypeBuilder.Mode} next Next mode.
*/

@@ -164,3 +171,3 @@ TypeBuilder.Mode.prototype.setNext = function(next) {

* Returns a mode next to the mode.
* @return {TypeBuilder.Mode} Next mode.
* @return {module:lib/TypeBuilder.Mode} Next mode.
*/

@@ -257,3 +264,4 @@ TypeBuilder.Mode.prototype.getNext = function() {

* @constructor
* @extends {TypeBuilder.Mode}
* @extends {module:lib/TypeBuilder.Mode}
* @alias module:lib/TypeBuilder.BaseMode
*/

@@ -268,3 +276,3 @@ TypeBuilder.BaseMode = function() {

* Base type union.
* @type {?TypeBuilder.TypeUnion}
* @type {?module:lib/TypeBuilder.TypeUnion}
* @private

@@ -277,3 +285,3 @@ */

* Sets a type union at the root.
* @param {TypeBuilder.TypeUnion} union Type union to set.
* @param {module:lib/TypeBuilder.TypeUnion} union Type union to set.
*/

@@ -287,3 +295,3 @@ TypeBuilder.BaseMode.prototype.setTypeUnionToken = function(union) {

* Returns a type union at the root.
* @return {TypeBuilder.TypeUnion} Type union to set.
* @return {module:lib/TypeBuilder.TypeUnion} Type union to set.
*/

@@ -299,3 +307,4 @@ TypeBuilder.BaseMode.prototype.getTypeUnionToken = function() {

* @constructor
* @extends {TypeBuilder.Mode}
* @extends {module:lib/TypeBuilder.Mode}
* @alias module:lib/TypeBuilder.TypeUnionMode
*/

@@ -311,3 +320,3 @@ TypeBuilder.TypeUnionMode = function() {

* Target type union.
* @type {TypeBuilder.TypeUnion}
* @type {module:lib/TypeBuilder.TypeUnion}
* @private

@@ -393,4 +402,16 @@ */

/**
* Handles a module name token.
* @param {string} moduleName Module name.
*/
TypeBuilder.TypeUnionMode.prototype.handleModuleNameToken = function(
moduleName) {
var obj = new TypeBuilder.ModuleName();
obj.setModuleName(moduleName);
this.union_.addModuleName(obj);
};
/**
* Sets a generic type token.
* @param {TypeBuilder.GenericType} generic Generic type token to
* @param {module:lib/TypeBuilder.GenericType} generic Generic type token to
* set.

@@ -405,3 +426,3 @@ */

* Handles a function type token.
* @param {TypeBuilder.FunctionType} func Function type token to
* @param {module:lib/TypeBuilder.FunctionType} func Function type token to
* set.

@@ -416,3 +437,3 @@ */

* Handles a record type token.
* @param {TypeBuilder.RecordType} record Record type token to
* @param {module:lib/TypeBuilder.RecordType} record Record type token to
* set.

@@ -429,3 +450,4 @@ */

* @constructor
* @extends {TypeBuilder.Mode}
* @extends {module:lib/TypeBuilder.Mode}
* @alias module:lib/TypeBuilder.GenericTypeMode
*/

@@ -441,3 +463,3 @@ TypeBuilder.GenericTypeMode = function() {

* Target generic type.
* @type {TypeBuilder.GenericType}
* @type {module:lib/TypeBuilder.GenericType}
* @private

@@ -462,3 +484,3 @@ */

* Sets a type union at the root.
* @param {TypeBuilder.TypeUnion} union Type union to set.
* @param {module:lib/TypeBuilder.TypeUnion} union Type union to set.
*/

@@ -484,3 +506,4 @@ TypeBuilder.GenericTypeMode.prototype.setTypeUnionToken = function(union) {

* @constructor
* @extends {TypeBuilder.Mode}
* @extends {module:lib/TypeBuilder.Mode}
* @alias module:lib/TypeBuilder.FunctionTypeMode
*/

@@ -522,3 +545,3 @@ TypeBuilder.FunctionTypeMode = function() {

* State of the function type mode.
* @type {TypeBuilder.FunctionTypeMode.State}
* @type {module:lib/TypeBuilder.FunctionTypeMode.State}
* @private:

@@ -578,3 +601,3 @@ */

* the state.
* @param {TypeBuilder.TypeUnion} union Type union to set.
* @param {module:lib/TypeBuilder.TypeUnion} union Type union to set.
*/

@@ -616,3 +639,4 @@ TypeBuilder.FunctionTypeMode.prototype.setTypeUnionToken = function(union) {

* @constructor
* @extends {TypeBuilder.Mode}
* @extends {module:lib/TypeBuilder.Mode}
* @alias module:lib/TypeBuilder.RecordTypeMode
*/

@@ -628,3 +652,3 @@ TypeBuilder.RecordTypeMode = function() {

* Target record type.
* @type {TypeBuilder.RecordType}
* @type {module:lib/TypeBuilder.RecordType}
* @private

@@ -637,3 +661,3 @@ */

* Target entry.
* @type {?TypeBuilder.RecordType.Entry}
* @type {?module:lib/TypeBuilder.RecordType.Entry}
* @private

@@ -664,3 +688,3 @@ */

* Sets a type union at the root.
* @param {TypeBuilder.TypeUnion} union Type union to set.
* @param {module:lib/TypeBuilder.TypeUnion} union Type union to set.
*/

@@ -688,2 +712,3 @@ TypeBuilder.RecordTypeMode.prototype.setTypeUnionToken = function(union) {

* @constructor
* @alias module:lib/TypeBuilder.TypeName
*/

@@ -706,3 +731,3 @@ TypeBuilder.TypeName = function() {};

* </pre>
* @type {?{publish: function(TypeBuilder.TypeName): string}}
* @type {?{publish: function(module:lib/TypeBuilder.TypeName): string}}
*/

@@ -713,3 +738,4 @@ TypeBuilder.TypeName.publisher = null;

/**
* Returns a file url by a type name.
* Returns an encoded file url by a type name.
* For example, {@code foo.bar} ⇒ {@code foo.bar.html}.
* @param {string} typeName Type name string.

@@ -719,3 +745,3 @@ * @return {string} URL string.

TypeBuilder.TypeName.getUrlByTypeName = function(typeName) {
return typeName + '.html';
return encodeURIComponent(typeName) + '.html';
};

@@ -745,3 +771,3 @@

* @override
* @see TypeBuilder.TypeName.publisher
* @see module:lib/TypeBuilder.TypeName.publisher
*/

@@ -759,3 +785,9 @@ TypeBuilder.TypeName.prototype.toString = function() {

/**
* Returns a html.
* Returns a html string. A type name is wrapped in an anchor tag, if the type
* dictionary does not have the type name. Otherwise, a type name is wrapped in
* a code tag. For example:
* <ul>
* <li>string, Array, window are wrapped in a code tag
* <li>foo.bar is wrapped in an anchor tag
* </ul>
* @return {string} HTML string.

@@ -766,3 +798,3 @@ */

if (dict.has(this.name)) {
return this.name;
return '<code>' + this.name + '</code>';
}

@@ -780,2 +812,3 @@ else {

* @constructor
* @alias module:lib/TypeBuilder.TypeUnion
*/

@@ -790,4 +823,5 @@ TypeBuilder.TypeUnion = function() {

* Type objects.
* @type {Array.<TypeBuilder.TypeName|TypeBuilder.GenericType|TypeBuilder.
* RecordType|TypeBuilder.FunctionType>}
* @type {Array.<module:lib/TypeBuilder.TypeName|
* module:lib/TypeBuilder.GenericType|module:lib/TypeBuilder.RecordType|
* module:lib/TypeBuilder.FunctionType>}
*/

@@ -849,3 +883,3 @@ TypeBuilder.TypeUnion.prototype.types = null;

* Adds a type name string to the union.
* @param {TypeBuilder.TypeName} type Type name to add.
* @param {module:lib/TypeBuilder.TypeName} type Type name to add.
*/

@@ -858,4 +892,13 @@ TypeBuilder.TypeUnion.prototype.addTypeName = function(type) {

/**
* Adds a module name string to the union.
* @param {module:lib/TypeBuilder.ModuleName} type Module name to add.
*/
TypeBuilder.TypeUnion.prototype.addModuleName = function(type) {
this.types[this.count_++] = type;
};
/**
* Adds a generic type to the union.
* @param {TypeBuilder.GenericType} generic Generic type to add.
* @param {module:lib/TypeBuilder.GenericType} generic Generic type to add.
*/

@@ -869,3 +912,3 @@ TypeBuilder.TypeUnion.prototype.addGenericType = function(generic) {

* Adds a record type to the union.
* @param {TypeBuilder.RecordType} record Record type to add.
* @param {module:lib/TypeBuilder.RecordType} record Record type to add.
*/

@@ -879,3 +922,3 @@ TypeBuilder.TypeUnion.prototype.addRecordType = function(record) {

* Adds a function type to the union.
* @param {TypeBuilder.FunctionType} func Function type to add.
* @param {module:lib/TypeBuilder.FunctionType} func Function type to add.
*/

@@ -1017,2 +1060,3 @@ TypeBuilder.TypeUnion.prototype.addFunctionType = function(func) {

* @constructor
* @alias module:lib/TypeBuilder.GenericType
*/

@@ -1034,3 +1078,3 @@ TypeBuilder.GenericType = function() {

* Generic parameter type unions.
* @type {Array.<TypeBuilder.TypeUnion>}
* @type {Array.<module:lib/TypeBuilder.TypeUnion>}
*/

@@ -1050,3 +1094,3 @@ TypeBuilder.GenericType.prototype.parameterTypeUnions = null;

* Sets a generic type name.
* @param {TypeBuilder.TypeName} name Generic type name.
* @param {module:lib/TypeBuilder.TypeName} name Generic type name.
*/

@@ -1060,3 +1104,3 @@ TypeBuilder.GenericType.prototype.setGenericTypeName = function(name) {

* Adds a generic parameter type union.
* @param {TypeBuilder.TypeUnion} type Parameter type union to
* @param {module:lib/TypeBuilder.TypeUnion} type Parameter type union to
* add.

@@ -1084,3 +1128,3 @@ */

});
return this.genericTypeName + '.&lt;' + params.join(', ') + '&gt;';
return this.genericTypeName.toHtml() + '.&lt;' + params.join(', ') + '&gt;';
};

@@ -1093,2 +1137,3 @@

* @constructor
* @alias module:lib/TypeBuilder.FunctionType
*/

@@ -1111,3 +1156,3 @@ TypeBuilder.FunctionType = function() {

* Function parameter type unions.
* @type {Array.<TypeBuilder.TypeUnion>}
* @type {Array.<module:lib/TypeBuilder.TypeUnion>}
*/

@@ -1119,3 +1164,3 @@ TypeBuilder.FunctionType.prototype.parameterTypeUnions = null;

* Fuction return type union. Null if a function has nothing to return.
* @type {?TypeBuilder.TypeUnion}
* @type {?module:lib/TypeBuilder.TypeUnion}
*/

@@ -1128,3 +1173,3 @@ TypeBuilder.FunctionType.prototype.returnTypeUnion = null;

* not specified.
* @type {?TypeBuilder.TypeUnion}
* @type {?module:lib/TypeBuilder.TypeUnion}
*/

@@ -1145,3 +1190,3 @@ TypeBuilder.FunctionType.prototype.contextTypeUnion = null;

* Sets a context type union.
* @param {TypeBuilder.TypeUnion} union Context type union.
* @param {module:lib/TypeBuilder.TypeUnion} union Context type union.
*/

@@ -1155,3 +1200,3 @@ TypeBuilder.FunctionType.prototype.setContextTypeUnion = function(union) {

* Adds a parameter type union.
* @param {TypeBuilder.TypeUnion} param Parameter type union to
* @param {module:lib/TypeBuilder.TypeUnion} param Parameter type union to
* add.

@@ -1166,3 +1211,3 @@ */

* Sets a return type union.
* @param {TypeBuilder.TypeUnion} ret Return type union.
* @param {module:lib/TypeBuilder.TypeUnion} ret Return type union.
*/

@@ -1234,2 +1279,3 @@ TypeBuilder.FunctionType.prototype.setReturnTypeUnion = function(ret) {

* @constructor
* @alias module:lib/TypeBuilder.RecordType
*/

@@ -1244,3 +1290,3 @@ TypeBuilder.RecordType = function() {

* An array of entries.
* @type {Array.<TypeBuilder.RecordType.Entry>}
* @type {Array.<module:lib/TypeBuilder.RecordType.Entry>}
*/

@@ -1288,2 +1334,3 @@ TypeBuilder.RecordType.prototype.entries = null;

* @constructor
* @alias module:lib/TypeBuilder.RecordType.Entry
*/

@@ -1302,3 +1349,3 @@ TypeBuilder.RecordType.Entry = function() {};

* Entry value type union.
* @type {?TypeBuilder.TypeUnion}
* @type {?module:lib/TypeBuilder.TypeUnion}
*/

@@ -1319,3 +1366,3 @@ TypeBuilder.RecordType.Entry.prototype.typeUnion = null;

* Sets a value type union.
* @param {TypeBuilder.TypeUnion} type Value type union to set.
* @param {module:lib/TypeBuilder.TypeUnion} type Value type union to set.
*/

@@ -1339,3 +1386,84 @@ TypeBuilder.RecordType.Entry.prototype.setValueTypeUnion = function(type) {

/**
* A class for module names.
* @constructor
* @alias module:lib/TypeBuilder.ModuleName
*/
TypeBuilder.ModuleName = function() {};
/**
* Module name publisher. Set a publisher object if you want to get a link from
* a module name when {@code #toString} is called.
*
* This example is a simple HTML anchor publisher.
* <pre>
* MyPublisher = {
* publish: function(moduleNameObj) {
* return '&lt;a href=&quot;' + moduleNameObj.name + '.html&quot;&gt;' +
* moduleNameObj.name + '&lt;/a&gt;';
* }
* };
* </pre>
* @type {?{publish: function(module:lib/TypeBuilder.ModuleName): string}}
*/
TypeBuilder.ModuleName.publisher = null;
/**
* Returns an encoded file url by a module name.
* For example, {@code module:foo/bar} ⇒ {@code module%3Afoo%2Fbar.html}.
* @param {string} moduleName Module name string.
* @return {string} URL string.
*/
TypeBuilder.ModuleName.getUrlByModuleName = function(moduleName) {
return encodeURIComponent('module:' + moduleName) + '.html';
};
/**
* Type name string.
* @type {?string}
*/
TypeBuilder.ModuleName.prototype.name = null;
/**
* Sets a type name string.
* @param {string} name Type name string.
*/
TypeBuilder.ModuleName.prototype.setModuleName = function(name) {
this.name = name;
};
/**
* Returns a type name string. Set {@code TypeBuilder.ModuleName.publisher} if
* you want to convert to a link from the type name. In default, returns a
* raw type name.
* @override
* @see module:lib/TypeBuilder.ModuleName.publisher
*/
TypeBuilder.ModuleName.prototype.toString = function() {
if (TypeBuilder.ModuleName.publisher) {
return TypeBuilder.ModuleName.publisher.publish(this);
}
else {
return 'module:' + this.name;
}
};
/**
* Returns a html.
* @return {string} HTML string.
*/
TypeBuilder.ModuleName.prototype.toHtml = function() {
return 'module:<a href="' + TypeBuilder.ModuleName.getUrlByModuleName(this.name) +
'">' + this.name + '</a>';
};
// Exports the constructor.
module.exports = TypeBuilder;

@@ -29,2 +29,3 @@ // This script licensed under the MIT.

* @constructor
* @exports lib/TypeDictionary
*/

@@ -31,0 +32,0 @@ var TypeDictionary = function() {

// This script licensed under the MIT.
// http://orgachem.mit-license.org
/**
* @fileoverview A class for Jsdoc type lexers.
* @author orga.chem.job@gmail.com (OrgaChem)
*/
var util = require('./util.js');

@@ -10,3 +15,3 @@

/**
* A class for jsdoc type lexer. This lexer can analize JsDoc type expressions
* A class for Jsdoc type lexers. This lexer can analize JsDoc type expressions
* and ClosureCompiler type expressions. See

@@ -55,2 +60,5 @@ * {@link https://code.google.com/p/jsdoc-toolkit/wiki/TagParam} and

* {@code handleUnknownTypeOperatorToken()}</dd>
*
* <dt>Module token handlers</dt>
* <dd>{@code handleModuleNameToken(moduleName)}</dd>
* </dl>

@@ -60,2 +68,3 @@ *

* @constructor
* @exports lib/TypeLexer
*/

@@ -75,2 +84,3 @@ var TypeLexer = function(opt_map) {

* @extends {Error}
* @alias lib/TypeLexer.SyntaxError
*/

@@ -268,3 +278,3 @@ TypeLexer.SyntaxError = function(msg, org, index) {

if (!str) {
this.fail_('Empty type as a null string was found', this.org_.length);
this.fail_('Unexpected token: ""', this.org_.length);
}

@@ -301,8 +311,20 @@ else if (str.match(/^\*/)) {

}
else if (str.match(/^module:/)) {
// Support "module:" expression.
str = str.replace(/^module:\s*/, '');
tmp = str.match(/^[\w\s\.#\/$_]+/);
matched = tmp[0];
str = str.slice(matched.length);
matched = matched.replace(/\s+/g, '');
if (this.handlers_.handleModuleNameToken) {
this.handlers_.handleModuleNameToken(matched);
}
}
else {
tmp = str.match(/^[\w\s\.#\/$]+/);
tmp = str.match(/^[\w\s\.#$_]+/);
if (!tmp) {
// This is an empty type such as ',foobar' or '|foobar'.
this.fail_('Unexpected token', this.org_.length - str.length);
this.fail_('Unexpected token: ""', this.org_.length - str.length);
}

@@ -315,3 +337,3 @@

if (str.match(/^\[\s*\]/)) {
// Support an array generic type as JsDoc official such as String[].
// Support an array generic type as JsDoc official such as "String[]".
// String[] => Array.<String>

@@ -333,3 +355,4 @@ str = str.replace(/^\[\s*\]\s*/, '');

// This is an empty type that has only white spaces.
this.fail_('Empty type was found', this.org_.length - str.length);
this.fail_('Unexpected token: "' + str + '"', this.org_.length -
str.length);
}

@@ -336,0 +359,0 @@ }

@@ -53,2 +53,3 @@ // This script licensed under the MIT.

* @constructor
* @exports lib/TypeParser
*/

@@ -62,3 +63,3 @@ var TypeParser = function() {

* Type builder.
* @type {TypeBuilder}
* @type {module:lib/TypeBuilder}
* @private

@@ -72,3 +73,3 @@ */

* @param {string} typeExp Type expression string to parse.
* @return {TypeBuilder.TypeUnion} Type union object.
* @return {module:lib/TypeBuilder.TypeUnion} Type union object.
*/

@@ -75,0 +76,0 @@ TypeParser.prototype.parse = function(typeExp) {

@@ -8,2 +8,3 @@ // This script licensed under the MIT.

* @namespace
* @exports lib/util
*/

@@ -10,0 +11,0 @@ var util = {};

{
"name": "jsdoctypeparser",
"description": "Strict JsDoc type expression parser",
"version": "1.0.3",
"description": "Strict JsDoc type expression parser.",
"version": "1.1.0",
"author": "Orga Chem <orga.chem.job@gmail.com>",

@@ -6,0 +6,0 @@ "keywords": [

@@ -20,4 +20,5 @@ // This script licensed under the MIT.

union = builder.build();
test.equal(union.types.length, 1);
test.equal(union.types[0], 'boolean');
test.equal(union.types[0].name, 'boolean');
test.equal(union.optional, false);

@@ -31,3 +32,3 @@ test.equal(union.nullable, false);

test.equal(union.toString(), 'boolean');
test.equal(union.toHtml(), 'boolean');
test.equal(union.toHtml(), '<code>boolean</code>');
test.done();

@@ -38,4 +39,5 @@ },

union = builder.build();
test.equal(union.types.length, 1);
test.equal(union.types[0], 'Window');
test.equal(union.types[0].name, 'Window');
test.equal(union.optional, false);

@@ -49,3 +51,3 @@ test.equal(union.nullable, false);

test.equal(union.toString(), 'Window');
test.equal(union.toHtml(), 'Window');
test.equal(union.toHtml(), '<code>Window</code>');
test.done();

@@ -56,4 +58,5 @@ },

union = builder.build();
test.equal(union.types.length, 1);
test.equal(union.types[0], 'goog.ui.Menu');
test.equal(union.types[0].name, 'goog.ui.Menu');
test.equal(union.optional, false);

@@ -73,2 +76,3 @@ test.equal(union.nullable, false);

union = builder.build();
test.equal(union.types.length, 1);

@@ -97,3 +101,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'Array.<string>');
test.equal(union.toHtml(), 'Array.&lt;string&gt;');
test.equal(union.toHtml(), '<code>Array</code>.&lt;<code>string</code>&gt;');
test.done();

@@ -104,2 +108,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -119,3 +124,3 @@ test.equal(union.optional, false);

test.equal(paramUnion1.types.length, 1);
test.equal(paramUnion1.types[0], 'string');
test.equal(paramUnion1.types[0].name, 'string');
test.equal(paramUnion1.optional, false);

@@ -139,3 +144,3 @@ test.equal(paramUnion1.nullable, false);

test.equal(union.toString(), 'Object.<string, number>');
test.equal(union.toHtml(), 'Object.&lt;string, number&gt;');
test.equal(union.toHtml(), '<code>Object</code>.&lt;<code>string</code>, <code>number</code>&gt;');
test.done();

@@ -146,2 +151,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -170,3 +176,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'Array.<String>');
test.equal(union.toHtml(), 'Array.&lt;String&gt;');
test.equal(union.toHtml(), '<code>Array</code>.&lt;<code>String</code>&gt;');
test.done();

@@ -177,2 +183,3 @@ },

union = builder.build();
test.equal(union.types.length, 2);

@@ -203,3 +210,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'number|boolean');
test.equal(union.toHtml(), 'number|boolean');
test.equal(union.toHtml(), '<code>number</code>|<code>boolean</code>');
test.done();

@@ -210,2 +217,3 @@ },

union = builder.build();
test.equal(union.types.length, 2);

@@ -236,3 +244,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'number|boolean');
test.equal(union.toHtml(), 'number|boolean');
test.equal(union.toHtml(), '<code>number</code>|<code>boolean</code>');
test.done();

@@ -243,2 +251,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -268,3 +277,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), '{ myNum: * }');
test.equal(union.toHtml(), '{ myNum: * }');
test.equal(union.toHtml(), '{ myNum: <code>*</code> }');
test.done();

@@ -275,2 +284,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -313,3 +323,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), '{ myNum: number, myObject: * }');
test.equal(union.toHtml(), '{ myNum: number, myObject: * }');
test.equal(union.toHtml(), '{ myNum: <code>number</code>, myObject: <code>*</code> }');
test.done();

@@ -320,2 +330,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -331,6 +342,5 @@ test.equal(union.optional, false);

test.equal(generic.genericTypeName, 'Array');
test.equal(generic.parameterTypeUnions.length, 1);
var valUnion = generic.parameterTypeUnions[0];
test.equal(valUnion.types.length, 1);

@@ -360,3 +370,3 @@ test.equal(valUnion.optional, false);

test.equal(union.toString(), 'Array.<{ length: * }>');
test.equal(union.toHtml(), 'Array.&lt;{ length: * }&gt;');
test.equal(union.toHtml(), '<code>Array</code>.&lt;{ length: <code>*</code> }&gt;');
test.done();

@@ -367,2 +377,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -378,3 +389,3 @@ test.equal(union.types[0], 'number');

test.equal(union.toString(), 'number|null');
test.equal(union.toHtml(), 'number|null');
test.equal(union.toHtml(), '<code>number</code>|<code>null</code>');
test.done();

@@ -385,2 +396,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -396,3 +408,3 @@ test.equal(union.types[0], 'goog.ui.Component');

test.equal(union.toString(), 'goog.ui.Component|null');
test.equal(union.toHtml(), '<a href="goog.ui.Component.html">goog.ui.Component</a>|null');
test.equal(union.toHtml(), '<a href="goog.ui.Component.html">goog.ui.Component</a>|<code>null</code>');
test.done();

@@ -403,2 +415,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -414,3 +427,3 @@ test.equal(union.types[0], 'Object');

test.equal(union.toString(), '!Object');
test.equal(union.toHtml(), '!Object');
test.equal(union.toHtml(), '!<code>Object</code>');
test.done();

@@ -421,2 +434,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -432,3 +446,3 @@ test.equal(union.types[0], 'Object');

test.equal(union.toString(), '!Object');
test.equal(union.toHtml(), '!Object');
test.equal(union.toHtml(), '!<code>Object</code>');
test.done();

@@ -439,2 +453,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -450,3 +465,3 @@ test.equal(union.types[0], 'Function');

test.equal(union.toString(), 'Function');
test.equal(union.toHtml(), 'Function');
test.equal(union.toHtml(), '<code>Function</code>');
test.done();

@@ -457,2 +472,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -479,2 +495,3 @@ test.equal(union.optional, false);

union = builder.build();
test.equal(union.types.length, 1);

@@ -505,3 +522,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'function(string)');
test.equal(union.toHtml(), 'function(string)');
test.equal(union.toHtml(), 'function(<code>string</code>)');
test.done();

@@ -512,2 +529,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -548,3 +566,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'function(string, boolean)');
test.equal(union.toHtml(), 'function(string, boolean)');
test.equal(union.toHtml(), 'function(<code>string</code>, <code>boolean</code>)');
test.done();

@@ -555,2 +573,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -580,3 +599,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'function(): number');
test.equal(union.toHtml(), 'function(): number');
test.equal(union.toHtml(), 'function(): <code>number</code>');
test.done();

@@ -587,2 +606,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -622,3 +642,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'function(this: goog.ui.Menu, string)');
test.equal(union.toHtml(), 'function(this: <a href="goog.ui.Menu.html">goog.ui.Menu</a>, string)');
test.equal(union.toHtml(), 'function(this: <a href="goog.ui.Menu.html">goog.ui.Menu</a>, <code>string</code>)');
test.done();

@@ -629,2 +649,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -664,3 +685,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'function(new: goog.ui.Menu, string)');
test.equal(union.toHtml(), 'function(new: <a href="goog.ui.Menu.html">goog.ui.Menu</a>, string)');
test.equal(union.toHtml(), 'function(new: <a href="goog.ui.Menu.html">goog.ui.Menu</a>, <code>string</code>)');
test.done();

@@ -671,2 +692,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -716,3 +738,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'function(string, ...number): number');
test.equal(union.toHtml(), 'function(string, ...number): number');
test.equal(union.toHtml(), 'function(<code>string</code>, ...<code>number</code>): <code>number</code>');
test.done();

@@ -723,2 +745,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -759,3 +782,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'function(string|undefined|null, number|undefined)');
test.equal(union.toHtml(), 'function(string|undefined|null, number|undefined)');
test.equal(union.toHtml(), 'function(<code>string</code>|<code>undefined</code>|<code>null</code>, <code>number</code>|<code>undefined</code>)');
test.done();

@@ -766,2 +789,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -800,3 +824,3 @@ test.equal(union.optional, false);

test.equal(paramUnion2.types.length, 1);
test.equal(paramUnion2.types[0], 'number');
test.equal(paramUnion2.types[0].name, 'number');
test.equal(paramUnion2.optional, false);

@@ -819,3 +843,3 @@ test.equal(paramUnion2.nullable, false);

test.equal(union.toString(), 'function(this: T, ?, number): ?');
test.equal(union.toHtml(), 'function(this: <a href="T.html">T</a>, ?, number): ?');
test.equal(union.toHtml(), 'function(this: <a href="T.html">T</a>, <code>?</code>, <code>number</code>): <code>?</code>');
test.done();

@@ -826,2 +850,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -837,2 +862,3 @@ test.equal(union.types[0], 'number');

test.equal(union.toString(), '...number');
test.equal(union.toHtml(), '...<code>number</code>');
test.done();

@@ -843,2 +869,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -854,3 +881,3 @@ test.equal(union.types[0], 'number');

test.equal(union.toString(), 'number|undefined');
test.equal(union.toHtml(), 'number|undefined');
test.equal(union.toHtml(), '<code>number</code>|<code>undefined</code>');
test.done();

@@ -861,2 +888,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -872,3 +900,3 @@ test.equal(union.types[0], 'number');

test.equal(union.toString(), 'number|undefined');
test.equal(union.toHtml(), 'number|undefined');
test.equal(union.toHtml(), '<code>number</code>|<code>undefined</code>');
test.done();

@@ -879,2 +907,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -890,3 +919,3 @@ test.equal(union.types[0], 'Object');

test.equal(union.toString(), 'Object|undefined');
test.equal(union.toHtml(), 'Object|undefined');
test.equal(union.toHtml(), '<code>Object</code>|<code>undefined</code>');
test.done();

@@ -897,2 +926,3 @@ },

union = builder.build();
test.equal(union.types.length, 1);

@@ -908,3 +938,3 @@ test.equal(union.types[0], 'Object');

test.equal(union.toString(), 'Object|undefined');
test.equal(union.toHtml(), 'Object|undefined');
test.equal(union.toHtml(), '<code>Object</code>|<code>undefined</code>');
test.done();

@@ -915,2 +945,3 @@ },

union = builder.build();
test.equal(union.types.length, 0);

@@ -925,3 +956,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), '*');
test.equal(union.toHtml(), '*');
test.equal(union.toHtml(), '<code>*</code>');
test.done();

@@ -932,2 +963,3 @@ },

union = builder.build();
test.equal(union.types.length, 0);

@@ -942,3 +974,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), '?');
test.equal(union.toHtml(), '?');
test.equal(union.toHtml(), '<code>?</code>');
test.done();

@@ -949,2 +981,3 @@ },

union = builder.build();
test.equal(union.types.length, 0);

@@ -959,3 +992,3 @@ test.equal(union.optional, false);

test.equal(union.toString(), '?');
test.equal(union.toHtml(), '?');
test.equal(union.toHtml(), '<code>?</code>');
test.done();

@@ -966,2 +999,3 @@ },

union = builder.build();
test.equal(union.types.length, 0);

@@ -976,3 +1010,3 @@ test.equal(union.optional, true);

test.equal(union.toString(), 'undefined');
test.equal(union.toHtml(), 'undefined');
test.equal(union.toHtml(), '<code>undefined</code>');
test.done();

@@ -983,2 +1017,3 @@ },

union = builder.build();
test.equal(union.types.length, 0);

@@ -993,5 +1028,53 @@ test.equal(union.optional, false);

test.equal(union.toString(), 'null');
test.equal(union.toHtml(), 'null');
test.equal(union.toHtml(), '<code>null</code>');
test.done();
},
'Build a module type': function(test) {
builder.setTypeString('module:foo/bar');
union = builder.build();
test.equal(union.types.length, 1);
test.equal(union.optional, false);
test.equal(union.nullable, false);
test.equal(union.nonNullable, false);
test.equal(union.variable, false);
test.equal(union.all, false);
test.equal(union.unknown, false);
test.equal(union.toString(), 'module:foo/bar');
test.equal(union.toHtml(), 'module:<a href="module%3Afoo%2Fbar.html">foo/bar</a>');
test.done();
},
'Build a module type with a prefix nullable type operator': function(test) {
builder.setTypeString('?module:foo/bar');
union = builder.build();
test.equal(union.types.length, 1);
test.equal(union.optional, false);
test.equal(union.nullable, true);
test.equal(union.nonNullable, false);
test.equal(union.variable, false);
test.equal(union.all, false);
test.equal(union.unknown, false);
test.equal(union.toString(), 'module:foo/bar|null');
test.equal(union.toHtml(), 'module:<a href="module%3Afoo%2Fbar.html">foo/bar</a>|<code>null</code>');
test.done();
},
'Build a module type with a postfix nullable type operator': function(test) {
builder.setTypeString('module:foo/bar?');
union = builder.build();
test.equal(union.types.length, 1);
test.equal(union.optional, false);
test.equal(union.nullable, true);
test.equal(union.nonNullable, false);
test.equal(union.variable, false);
test.equal(union.all, false);
test.equal(union.unknown, false);
test.equal(union.toString(), 'module:foo/bar|null');
test.equal(union.toHtml(), 'module:<a href="module%3Afoo%2Fbar.html">foo/bar</a>|<code>null</code>');
test.done();
},
'Build an illegal generic type': function(test) {

@@ -998,0 +1081,0 @@ builder.setTypeString('Array.<a');

@@ -37,3 +37,4 @@ // This script licensed under the MIT.

handleAllTypeOperatorToken: function() {},
handleUnknownTypeOperatorToken: function() {}
handleUnknownTypeOperatorToken: function() {},
handleModuleNameToken: function(arg) {}
};

@@ -181,2 +182,10 @@

},
'Analize a module type': function(test) {
lexer.analize('module: foo/bar');
test.done();
},
'Analize a module type with a file extension': function(test) {
lexer.analize('module: foo/bar.js');
test.done();
},
'Analize an illegal generic type': function(test) {

@@ -183,0 +192,0 @@ test.throws(function() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc