jsdoctypeparser
Advanced tools
Comparing version 2.0.0-alpha-6 to 2.0.0-alpha-7
{ | ||
"name": "jsdoctypeparser", | ||
"description": "Strict JsDoc type expression parser.", | ||
"version": "2.0.0-alpha-6", | ||
"version": "2.0.0-alpha-7", | ||
"author": "Kuniwak <orga.chem.job@gmail.com>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -100,15 +100,12 @@ jsdoctypeparser | ||
```javascript | ||
const {publish, createDefaultPublisher} = require('jsdoctypeparser').publish; | ||
const {publish, createDefaultPublisher} = require('jsdoctypeparser'); | ||
const ast = { | ||
type: 'NAME', | ||
name: 'MyClass' | ||
name: 'MyClass', | ||
}; | ||
const defaultPublisher = createDefaultPublisher(); | ||
const customPublisher = Object.create(defaultPublisher, { | ||
NAME: (node, pub) => { | ||
return `<a href="./types/${node.name}.html">${node.name}</a>`; | ||
}, | ||
}); | ||
const customPublisher = createDefaultPublisher(); | ||
customPublisher.NAME = (node, pub) => | ||
`<a href="./types/${node.name}.html">${node.name}</a>`; | ||
@@ -115,0 +112,0 @@ const string = publish(ast, customPublisher); |
@@ -6,7 +6,9 @@ 'use strict'; | ||
var parse = require('../lib/parsing.js').parse; | ||
var publish = require('../lib/publishing.js').publish; | ||
var Publishing = require('../lib/publishing.js'); | ||
var publish = Publishing.publish; | ||
var createDefaultPublisher = Publishing.createDefaultPublisher; | ||
describe('publish', function() { | ||
it('Build a primitive type name', function() { | ||
it('should return a primitive type name', function() { | ||
var node = parse('boolean'); | ||
@@ -17,3 +19,3 @@ expect(publish(node)).to.equal('boolean'); | ||
it('Build a global type name', function() { | ||
it('should return a global type name', function() { | ||
var node = parse('Window'); | ||
@@ -24,3 +26,3 @@ expect(publish(node)).to.equal('Window'); | ||
it('Build an user-defined type name', function() { | ||
it('should return an user-defined type name', function() { | ||
var node = parse('goog.ui.Menu'); | ||
@@ -31,3 +33,3 @@ expect(publish(node)).to.equal('goog.ui.Menu'); | ||
it('Build a generic type has a parameter', function() { | ||
it('should return a generic type has a parameter', function() { | ||
var node = parse('Array.<string>'); | ||
@@ -38,3 +40,3 @@ expect(publish(node)).to.equal('Array<string>'); | ||
it('Build a generic type has 2 parameters', function() { | ||
it('should return a generic type has 2 parameters', function() { | ||
var node = parse('Object.<string, number>'); | ||
@@ -45,3 +47,3 @@ expect(publish(node)).to.equal('Object<string, number>'); | ||
it('Build a JsDoc-formal generic type', function() { | ||
it('should return a JsDoc-formal generic type', function() { | ||
var node = parse('String[]'); | ||
@@ -52,3 +54,3 @@ expect(publish(node)).to.equal('Array<String>'); | ||
it('Build a formal type union', function() { | ||
it('should return a formal type union', function() { | ||
var node = parse('(number|boolean)'); | ||
@@ -59,3 +61,3 @@ expect(publish(node)).to.equal('(number|boolean)'); | ||
it('Build a informal type union', function() { | ||
it('should return a informal type union', function() { | ||
var node = parse('number|boolean'); | ||
@@ -66,3 +68,3 @@ expect(publish(node)).to.equal('number|boolean'); | ||
it('Build a record type with an entry', function() { | ||
it('should return a record type with an entry', function() { | ||
var node = parse('{myNum}'); | ||
@@ -73,3 +75,3 @@ expect(publish(node)).to.equal('{myNum}'); | ||
it('Build a record type with 2 entries', function() { | ||
it('should return a record type with 2 entries', function() { | ||
var node = parse('{myNum: number, myObject}'); | ||
@@ -80,3 +82,3 @@ expect(publish(node)).to.equal('{myNum: number, myObject}'); | ||
it('Build a generic type has a parameter as a record type', function() { | ||
it('should return a generic type has a parameter as a record type', function() { | ||
var node = parse('Array<{length}>'); | ||
@@ -87,3 +89,3 @@ expect(publish(node)).to.equal('Array<{length}>'); | ||
it('Build a nullable type has a nullable type operator on the head', function() { | ||
it('should return a nullable type has a nullable type operator on the head', function() { | ||
var node = parse('?number'); | ||
@@ -94,3 +96,3 @@ expect(publish(node)).to.equal('?number'); | ||
it('Build a nullable type has a nullable type operator on the tail', function() { | ||
it('should return a nullable type has a nullable type operator on the tail', function() { | ||
var node = parse('goog.ui.Component?'); | ||
@@ -101,3 +103,3 @@ expect(publish(node)).to.equal('?goog.ui.Component'); | ||
it('Build a non-nullable type has a nullable type operator on the head', function() { | ||
it('should return a non-nullable type has a nullable type operator on the head', function() { | ||
var node = parse('!Object'); | ||
@@ -108,3 +110,3 @@ expect(publish(node)).to.equal('!Object'); | ||
it('Build a non-nullable type has a nullable type operator on the tail', function() { | ||
it('should return a non-nullable type has a nullable type operator on the tail', function() { | ||
var node = parse('Object!'); | ||
@@ -115,3 +117,3 @@ expect(publish(node)).to.equal('!Object'); | ||
it('Build a function type', function() { | ||
it('should return a function type', function() { | ||
var node = parse('Function'); | ||
@@ -122,3 +124,3 @@ expect(publish(node)).to.equal('Function'); | ||
it('Build a function type has no parameters', function() { | ||
it('should return a function type has no parameters', function() { | ||
var node = parse('function()'); | ||
@@ -129,3 +131,3 @@ expect(publish(node)).to.equal('function()'); | ||
it('Build a function type has a parameter', function() { | ||
it('should return a function type has a parameter', function() { | ||
var node = parse('function(string)'); | ||
@@ -136,3 +138,3 @@ expect(publish(node)).to.equal('function(string)'); | ||
it('Build a function type has 2 parameters', function() { | ||
it('should return a function type has 2 parameters', function() { | ||
var node = parse('function(string, boolean)'); | ||
@@ -143,3 +145,3 @@ expect(publish(node)).to.equal('function(string, boolean)'); | ||
it('Build a function type has a return', function() { | ||
it('should return a function type has a return', function() { | ||
var node = parse('function(): number'); | ||
@@ -150,3 +152,3 @@ expect(publish(node)).to.equal('function(): number'); | ||
it('Build a function type has a context', function() { | ||
it('should return a function type has a context', function() { | ||
var node = parse('function(this:goog.ui.Menu, string)'); | ||
@@ -157,3 +159,3 @@ expect(publish(node)).to.equal('function(this: goog.ui.Menu, string)'); | ||
it('Build a constructor type', function() { | ||
it('should return a constructor type', function() { | ||
var node = parse('function(new:goog.ui.Menu, string)'); | ||
@@ -164,3 +166,3 @@ expect(publish(node)).to.equal('function(new: goog.ui.Menu, string)'); | ||
it('Build a function type has a variable parameter', function() { | ||
it('should return a function type has a variable parameter', function() { | ||
var node = parse('function(string, ...number): number'); | ||
@@ -171,3 +173,3 @@ expect(publish(node)).to.equal('function(string, ...number): number'); | ||
it('Build a function type has parameters have some type operators', function() { | ||
it('should return a function type has parameters have some type operators', function() { | ||
var node = parse('function(?string=, number=)'); | ||
@@ -178,3 +180,3 @@ expect(publish(node)).to.equal('function(?string=, number=)'); | ||
it('Build a goog.ui.Component#forEachChild', function() { | ||
it('should return a goog.ui.Component#forEachChild', function() { | ||
var node = parse('function(this:T,?,number):?'); | ||
@@ -185,3 +187,3 @@ expect(publish(node)).to.equal('function(this: T, ?, number): ?'); | ||
it('Build a variable type', function() { | ||
it('should return a variable type', function() { | ||
var node = parse('...number'); | ||
@@ -192,3 +194,3 @@ expect(publish(node)).to.equal('...number'); | ||
it('Build an optional type has an optional type operator on the head', function() { | ||
it('should return an optional type has an optional type operator on the head', function() { | ||
var node = parse('=number'); | ||
@@ -199,3 +201,3 @@ expect(publish(node)).to.equal('number='); | ||
it('Build an optional type has an optional type operator on the tail', function() { | ||
it('should return an optional type has an optional type operator on the tail', function() { | ||
var node = parse('number='); | ||
@@ -206,3 +208,3 @@ expect(publish(node)).to.equal('number='); | ||
it('Build an all type', function() { | ||
it('should return an all type', function() { | ||
var node = parse('*'); | ||
@@ -213,3 +215,3 @@ expect(publish(node)).to.equal('*'); | ||
it('Build an unknown type', function() { | ||
it('should return an unknown type', function() { | ||
var node = parse('?'); | ||
@@ -220,3 +222,3 @@ expect(publish(node)).to.equal('?'); | ||
it('Build an undefined type with an "undefined" keyword', function() { | ||
it('should return an undefined type with an "undefined" keyword', function() { | ||
var node = parse('undefined'); | ||
@@ -227,3 +229,3 @@ expect(publish(node)).to.equal('undefined'); | ||
it('Build a null type with an "null" keyword', function() { | ||
it('should return a null type with an "null" keyword', function() { | ||
var node = parse('null'); | ||
@@ -234,3 +236,3 @@ expect(publish(node)).to.equal('null'); | ||
it('Build a module type', function() { | ||
it('should return a module type', function() { | ||
var node = parse('module:foo/bar'); | ||
@@ -241,3 +243,3 @@ expect(publish(node)).to.equal('module:foo/bar'); | ||
it('Build a module type with a prefix nullable type operator', function() { | ||
it('should return a module type with a prefix nullable type operator', function() { | ||
var node = parse('?module:foo/bar'); | ||
@@ -248,3 +250,3 @@ expect(publish(node)).to.equal('?module:foo/bar'); | ||
it('Build a module type with a postfix nullable type operator', function() { | ||
it('should return a module type with a postfix nullable type operator', function() { | ||
var node = parse('module:foo/bar?'); | ||
@@ -255,3 +257,3 @@ expect(publish(node)).to.equal('?module:foo/bar'); | ||
it('Build a string value type', function() { | ||
it('should return a string value type', function() { | ||
var node = parse('"stringValue"'); | ||
@@ -262,3 +264,3 @@ expect(publish(node)).to.equal('"stringValue"'); | ||
it('Build a number value type', function() { | ||
it('should return a number value type', function() { | ||
var node = parse('0123456789'); | ||
@@ -269,3 +271,3 @@ expect(publish(node)).to.equal('0123456789'); | ||
it('Build a bin number value type', function() { | ||
it('should return a bin number value type', function() { | ||
var node = parse('0b01'); | ||
@@ -276,3 +278,3 @@ expect(publish(node)).to.equal('0b01'); | ||
it('Build an oct number value type', function() { | ||
it('should return an oct number value type', function() { | ||
var node = parse('0o01234567'); | ||
@@ -283,3 +285,3 @@ expect(publish(node)).to.equal('0o01234567'); | ||
it('Build a hex number value type', function() { | ||
it('should return a hex number value type', function() { | ||
var node = parse('0x0123456789abcdef'); | ||
@@ -290,3 +292,3 @@ expect(publish(node)).to.equal('0x0123456789abcdef'); | ||
it('Build an external node type', function() { | ||
it('should return an external node type', function() { | ||
var node = parse('external:string'); | ||
@@ -297,3 +299,3 @@ expect(publish(node)).to.equal('external:string'); | ||
it('Build a module type with a generic type operator', function() { | ||
it('should return a module type with a generic type operator', function() { | ||
// Because the new generic type syntax was arrived, the old type generic | ||
@@ -308,2 +310,18 @@ // with the module keyword is not equivalent to the legacy behavior. | ||
}); | ||
it('should can take a custom publisher by the 2nd argument', function() { | ||
var ast = { | ||
type: 'NAME', | ||
name: 'MyClass', | ||
}; | ||
var customPublisher = createDefaultPublisher(); | ||
customPublisher.NAME = function(node) { | ||
return '<a href="./types/' + node.name + '.html">' + node.name + '</a>'; | ||
}; | ||
var string = publish(ast, customPublisher); | ||
expect(string).to.equal('<a href="./types/MyClass.html">MyClass</a>'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
338910
6847
0
649