@typedefs/parser
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -7,3 +7,3 @@ const { lex, parser } = require('./lib'); | ||
*/ | ||
function parse(type) { | ||
function parse(type) { | ||
const tokens = lex(type) | ||
@@ -10,0 +10,0 @@ return parser(tokens) |
@@ -10,3 +10,3 @@ const { Fn, fn, | ||
*/ | ||
const lex = (s) => { | ||
const lex = (s) => { | ||
const res = s.split(/([!?=*(),:.<>{}|\s+])/g) | ||
@@ -28,3 +28,3 @@ return res | ||
function parser(tokens) { | ||
function parser(tokens) { | ||
let c = 0 | ||
@@ -84,2 +84,5 @@ | ||
const ret = parseType() | ||
if (ret.name == undefined && ret.nullable) | ||
// special case | ||
ret.name = '' | ||
meta.return = ret | ||
@@ -86,0 +89,0 @@ } |
@@ -1,7 +0,7 @@ | ||
const Fn = 'Function' | ||
const fn = 'function' | ||
const nullable = 'nullable' | ||
const nonNullable = 'nonNullable' | ||
const optional = '=' | ||
const any = 'any' | ||
const Fn = 'Function' | ||
const fn = 'function' | ||
const nullable = 'nullable' | ||
const nonNullable = 'nonNullable' | ||
const optional = '=' | ||
const any = 'any' | ||
@@ -8,0 +8,0 @@ module.exports.Fn = Fn |
@@ -0,1 +1,7 @@ | ||
## 22 July 2019 | ||
### [1.3.1](https://github.com/artdecocode/parser/compare/v1.3.0...v1.3.1) | ||
- [fix] Parse `?` function return type _OK_. | ||
## 29 April 2019 | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "@typedefs/parser", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "The Parser For JSDoc Types.", | ||
@@ -48,8 +48,8 @@ "main": "build/index.js", | ||
"devDependencies": { | ||
"alamode": "^2.0.0", | ||
"documentary": "^1.26.1", | ||
"alamode": "^2.3.4", | ||
"documentary": "^1.27.7", | ||
"eslint-config-artdeco": "1.0.1", | ||
"yarn-s": "1.1.0", | ||
"zoroaster": "^3.13.0" | ||
"zoroaster": "^4.1.1-alpha" | ||
} | ||
} |
@@ -20,3 +20,3 @@ # @typedefs/parser | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/0.svg?sanitize=true"></a></p> | ||
<p align="center"><a href="#table-of-contents"><img src="/.documentary/section-breaks/0.svg?sanitize=true"></a></p> | ||
@@ -31,3 +31,3 @@ ## API | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/1.svg?sanitize=true"></a></p> | ||
<p align="center"><a href="#table-of-contents"><img src="/.documentary/section-breaks/1.svg?sanitize=true"></a></p> | ||
@@ -38,22 +38,23 @@ ## `parse(`<br/> `type: string,`<br/>`): Type` | ||
__<a name="type-_typedefsparserfunctiontype">`_typedefsParser.FunctionType`</a>__: The meta information about the function. | ||
<strong><a name="type-_typedefsparserfunctiontype">`_typedefsParser.FunctionType`</a></strong>: The meta information about the function. | ||
| Name | Type | Description | | ||
| ----------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| __args*__ | <em>!Array<[!_typedefsParser.Type](#type-_typedefsparsertype)></em> | The arguments of the function. | | ||
| __return*__ | <em>[_typedefsParser.Type](#type-_typedefsparsertype)</em> | The return type of the function. When the value is set to `null`, it menas the function does not have a return. If the return was actuall `null`, it would be specified as `return: { name: 'null' }`. | | ||
| this | <em>[!_typedefsParser.Type](#type-_typedefsparsertype)</em> | The type of the `this` argument specified as `function(this: Type)`. | | ||
| new | <em>[!_typedefsParser.Type](#type-_typedefsparsertype)</em> | The type of the `new` argument specified as `function(new: Type)`. | | ||
| Name | Type | Description | | ||
| ------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| __args*__ | <em>!Array<<a href="#type-_typedefsparsertype" title="The representation of a type.">!_typedefsParser.Type</a>></em> | The arguments of the function. | | ||
| __return*__ | <em><a href="#type-_typedefsparsertype" title="The representation of a type.">?_typedefsParser.Type</a></em> | The return type of the function. When the value is set to `null`, it menas the function does not have a return. If the return was actuall `null`, it would be specified as `return: { name: 'null' }`. | | ||
| this | <em><a href="#type-_typedefsparsertype" title="The representation of a type.">!_typedefsParser.Type</a></em> | The type of the `this` argument specified as `function(this: Type)`. | | ||
| new | <em><a href="#type-_typedefsparsertype" title="The representation of a type.">!_typedefsParser.Type</a></em> | The type of the `new` argument specified as `function(new: Type)`. | | ||
| variableArgs | <em><a href="#type-_typedefsparsertype" title="The representation of a type.">!_typedefsParser.Type</a></em> | The type of the variable arguments, e.g., `function(...Type)`. | | ||
__<a name="type-_typedefsparsertype">`_typedefsParser.Type`</a>__: The representation of a type. | ||
<strong><a name="type-_typedefsparsertype">`_typedefsParser.Type`</a></strong>: The representation of a type. | ||
| Name | Type | Description | | ||
| ----------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| nullable | <em>boolean</em> | Whether the type is nullable. This is defined by writing `?` before the type name to state nullability and `!` otherwise. The parser does not infer nullability from types being primitive and `Function/function`. | | ||
| name | <em>string</em> | The name of the type. | | ||
| union | <em>!Array<[!_typedefsParser.Type](#type-_typedefsparsertype)></em> | If the type is defined as a union, e.g., `(string\|number)`, contains the united types. Must include parenthesis. | | ||
| record | <em>!Object<string, [_typedefsParser.Type](#type-_typedefsparsertype)></em> | If the type is a record, contains its representation. If a property of the record does not have a type, it will be set to null. | | ||
| application | <em>!Array<[!_typedefsParser.Type](#type-_typedefsparsertype)></em> | The application of the type, e.g., the inner type of `Object<Application>`. | | ||
| function | <em>[!_typedefsParser.FunctionType](#type-_typedefsparserfunctiontype)</em> | The function info with args and return if the type is a function. | | ||
| optional | <em>boolean</em> | If the type is returned as an optional argument of a function (`function(string=)`), this will be set to true. | | ||
| Name | Type | Description | | ||
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| nullable | <em>boolean</em> | Whether the type is nullable. This is defined by writing `?` before the type name to state nullability and `!` otherwise. The parser does not infer nullability from types being primitive and `Function/function`. | | ||
| name | <em>string</em> | The name of the type. | | ||
| union | <em>!Array<<a href="#type-_typedefsparsertype" title="The representation of a type.">!_typedefsParser.Type</a>></em> | If the type is defined as a union, e.g., `(string\|number)`, contains the united types. Must include parenthesis. | | ||
| record | <em>!Object<string, <a href="#type-_typedefsparsertype" title="The representation of a type.">_typedefsParser.Type</a>></em> | If the type is a record, contains its representation. If a property of the record does not have a type, it will be set to null. | | ||
| application | <em>!Array<<a href="#type-_typedefsparsertype" title="The representation of a type.">!_typedefsParser.Type</a>></em> | The application of the type, e.g., the inner type of `Object<Application>`. | | ||
| function | <em><a href="#type-_typedefsparserfunctiontype" title="The meta information about the function.">!_typedefsParser.FunctionType</a></em> | The function info with args and return if the type is a function. | | ||
| optional | <em>boolean</em> | If the type is returned as an optional argument of a function (`function(string=)`), this will be set to true. | | ||
@@ -83,2 +84,5 @@ ```js | ||
): function(): null`)) | ||
// special case when name is nullable empty string '' | ||
log(parser(`function(): ?`)) | ||
``` | ||
@@ -140,5 +144,7 @@ ```js | ||
this: { name: 'Type' } } } | ||
{ name: 'function', | ||
function: { return: { nullable: true, name: '' }, args: [] } } | ||
``` | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/2.svg?sanitize=true"></a></p> | ||
<p align="center"><a href="#table-of-contents"><img src="/.documentary/section-breaks/2.svg?sanitize=true"></a></p> | ||
@@ -151,3 +157,4 @@ ## Copyright | ||
<a href="https://artd.eco"> | ||
<img src="https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png" alt="Art Deco" /> | ||
<img width="100" src="https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png" | ||
alt="Art Deco"> | ||
</a> | ||
@@ -158,4 +165,4 @@ </th> | ||
<a href="https://www.technation.sucks" title="Tech Nation Visa"> | ||
<img src="https://raw.githubusercontent.com/artdecoweb/www.technation.sucks/master/anim.gif" | ||
alt="Tech Nation Visa" /> | ||
<img width="100" src="https://raw.githubusercontent.com/idiocc/cookies/master/wiki/arch4.jpg" | ||
alt="Tech Nation Visa"> | ||
</a> | ||
@@ -167,2 +174,2 @@ </th> | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/-1.svg?sanitize=true"></a></p> | ||
<p align="center"><a href="#table-of-contents"><img src="/.documentary/section-breaks/-1.svg?sanitize=true"></a></p> |
@@ -82,2 +82,5 @@ import { Fn, fn, | ||
const ret = parseType() | ||
if (ret.name == undefined && ret.nullable) | ||
// special case | ||
ret.name = '' | ||
meta.return = ret | ||
@@ -84,0 +87,0 @@ } |
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
30497
484
167