New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@typedefs/parser

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typedefs/parser - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

types/externs.js

10

build/index.js

@@ -15,9 +15,9 @@ const { lex, parser } = require('./lib');

* @suppress {nonStandardJsDocs}
* @typedef {_typedefsParser.FunctionType} FunctionType The meta information about the function.
* @typedef {_typedefsParser.FunctionType} FunctionType `@record` The meta information about the function.
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {Object} _typedefsParser.FunctionType The meta information about the function.
* @typedef {Object} _typedefsParser.FunctionType `@record` The meta information about the function.
* @prop {!Array<!_typedefsParser.Type>} args The arguments of the function.
* @prop {?_typedefsParser.Type} return 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' }`.
* @prop {?_typedefsParser.Type} return The return type of the function. When the value is set to `null`, it means the function does not have a return. If the return was actually `null`, it would be specified as `return: { name: 'null' }`.
* @prop {!_typedefsParser.Type} [this] The type of the `this` argument specified as `function(this: Type)`.

@@ -29,7 +29,7 @@ * @prop {!_typedefsParser.Type} [new] The type of the `new` argument specified as `function(new: Type)`.

* @suppress {nonStandardJsDocs}
* @typedef {_typedefsParser.Type} Type The representation of a type.
* @typedef {_typedefsParser.Type} Type `@record` The representation of a type.
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {Object} _typedefsParser.Type The representation of a type.
* @typedef {Object} _typedefsParser.Type `@record` The representation of a type.
* @prop {boolean} [nullable] 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`.

@@ -36,0 +36,0 @@ * @prop {string} [name] The name of the type.

@@ -112,4 +112,9 @@ const { Fn, fn,

consume()
const type = parseType()
props[propName] = type
try {
const type = parseType()
props[propName] = type
} catch (err) {
err.message += `(when parsing ${propName} property)`
throw err
}
}

@@ -120,3 +125,5 @@ if(peek() == '}') {

}
if (peek() != ',') throw new Error('Expecting , for record')
if (peek() != ',') {
throw new Error(`Expecting , for record after ${propName}`)
}
consume()

@@ -140,3 +147,3 @@ }

token = peek()
if (token == '(') { // consider cases without ()
if (token == '(') { // union, consider cases without ()
consume()

@@ -149,3 +156,5 @@ type = {

consume()
return type
if (peek() != '|') {
return type
}
} else if (token == '{') {

@@ -162,4 +171,6 @@ consume()

type.name = peek()
consume()
if (peek() != '|') {
type.name = peek()
consume()
}
if (fn == token) {

@@ -166,0 +177,0 @@ type.function = parseFunction()

@@ -0,1 +1,7 @@

## 8 August 2019
### [1.3.3](https://github.com/artdecocode/parser/compare/v1.3.2...v1.3.3)
- [fix] Fix parsing of certain unions like `{ type: ((function(): string)|number) }`.
## 25 July 2019

@@ -2,0 +8,0 @@

{
"name": "@typedefs/parser",
"version": "1.3.2",
"version": "1.3.3",
"description": "The Parser For JSDoc Types.",

@@ -14,7 +14,7 @@ "main": "build/index.js",

"lint": "eslint .",
"doc": "NODE_DEBUG=doc doc -o README.md",
"doc": "NODE_DEBUG=doc doc -o README.md -n _typedefsParser",
"b": "alamode src -o build -s",
"d": "yarn-s d1 externs",
"d1": "typal src -c",
"externs": "typal externs.js -e",
"externs": "typal types/externs.js -e",
"build": "yarn-s d b doc",

@@ -26,5 +26,5 @@ "e": "alanode"

"src",
"externs.js"
"types/externs.js"
],
"externs": "externs.js",
"externs": "types/externs.js",
"repository": {

@@ -50,4 +50,4 @@ "type": "git",

"devDependencies": {
"alamode": "^2.3.4",
"documentary": "^1.27.7",
"alamode": "^2.4.0",
"documentary": "^1.31.0",
"eslint-config-artdeco": "1.0.1",

@@ -54,0 +54,0 @@ "yarn-s": "1.1.0",

@@ -5,4 +5,9 @@ # @typedefs/parser

`@typedefs/parser` is The Parser For JSDoc Types.
`@typedefs/parser` is The Parser For _JSDoc_ Types Written Using Google Closure Compiler Annotations (no _TypeScript_ support). Although most of the typing rules are the same, the main difference is for functions and arrays:
- ✅ `function(string): void`
- ⛔️ `(arg: string) => void`
- ✅ `!Array<string>`
- ⛔️ `string[]`
```sh

@@ -16,8 +21,10 @@ yarn add @typedefs/parser

- [API](#api)
- [`parse(type: string): Type`](#parsetype-string-type)
* [`_typedefsParser.FunctionType`](#type-_typedefsparserfunctiontype)
* [`_typedefsParser.Type`](#type-_typedefsparsertype)
- [`parse(type: string): !Type`](#parsetype-string-type)
* [`Type`](#type-type)
* [`FunctionType`](#type-functiontype)
- [Copyright](#copyright)
<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>

@@ -32,30 +39,35 @@ ## 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>
## `parse(`<br/>&nbsp;&nbsp;`type: string,`<br/>`): Type`
## <code><ins>parse</ins>(</code><sub><br/>&nbsp;&nbsp;`type: string,`<br/></sub><code>): <i>!Type</i></code>
Parses the type recursively. Obeys the JSDoc rules, but also supports [Google Closure Compiler annotations](https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System).
Parses a [Google Closure Compiler](https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System) type recursively.
<strong><a name="type-_typedefsparserfunctiontype">`_typedefsParser.FunctionType`</a></strong>: The meta information about the function.
__<a name="type-type">`Type`</a>__: The representation of a type.
| Name | Type | Description |
| ------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| __args*__ | <em>!Array&lt;<a href="#type-_typedefsparsertype" title="The representation of a type.">!_typedefsParser.Type</a>&gt;</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)`. |
<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&lt;<a href="#type-type" title="The representation of a type.">!Type</a>&gt;</em> | If the type is defined as a union, e.g., `(string\|number)`, contains the united types. Must include parenthesis. |
| record | <em>!Object&lt;string, <a href="#type-type" title="The representation of a type.">Type</a>&gt;</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&lt;<a href="#type-type" title="The representation of a type.">!Type</a>&gt;</em> | The application of the type, e.g., the inner type of `Object<Application>`. |
| function | <em><a href="#type-functiontype" title="The meta information about the function.">!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. |
| 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&lt;<a href="#type-_typedefsparsertype" title="The representation of a type.">!_typedefsParser.Type</a>&gt;</em> | If the type is defined as a union, e.g., `(string\|number)`, contains the united types. Must include parenthesis. |
| record | <em>!Object&lt;string, <a href="#type-_typedefsparsertype" title="The representation of a type.">_typedefsParser.Type</a>&gt;</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&lt;<a href="#type-_typedefsparsertype" title="The representation of a type.">!_typedefsParser.Type</a>&gt;</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. |
__<a name="type-functiontype">`FunctionType`</a>__: The meta information about the function.
| Name | Type | Description |
| ------------ | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| __args*__ | <em>!Array&lt;<a href="#type-type" title="The representation of a type.">!Type</a>&gt;</em> | The arguments of the function. |
| __return*__ | <em><a href="#type-type" title="The representation of a type.">?Type</a></em> | The return type of the function. When the value is set to `null`, it means the function does not have a return. If the return was actually `null`, it would be specified as `return: { name: 'null' }`. |
| this | <em><a href="#type-type" title="The representation of a type.">!Type</a></em> | The type of the `this` argument specified as `function(this: Type)`. |
| new | <em><a href="#type-type" title="The representation of a type.">!Type</a></em> | The type of the `new` argument specified as `function(new: Type)`. |
| variableArgs | <em><a href="#type-type" title="The representation of a type.">!Type</a></em> | The type of the variable arguments, e.g., `function(...Type)`. |
```js

@@ -147,3 +159,5 @@ import parser from '@typedefs/parser'

<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>

@@ -171,2 +185,4 @@ ## Copyright

<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>

@@ -15,9 +15,9 @@ import { lex, parser } from './lib'

* @suppress {nonStandardJsDocs}
* @typedef {_typedefsParser.FunctionType} FunctionType The meta information about the function.
* @typedef {_typedefsParser.FunctionType} FunctionType `@record` The meta information about the function.
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {Object} _typedefsParser.FunctionType The meta information about the function.
* @typedef {Object} _typedefsParser.FunctionType `@record` The meta information about the function.
* @prop {!Array<!_typedefsParser.Type>} args The arguments of the function.
* @prop {?_typedefsParser.Type} return 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' }`.
* @prop {?_typedefsParser.Type} return The return type of the function. When the value is set to `null`, it means the function does not have a return. If the return was actually `null`, it would be specified as `return: { name: 'null' }`.
* @prop {!_typedefsParser.Type} [this] The type of the `this` argument specified as `function(this: Type)`.

@@ -29,7 +29,7 @@ * @prop {!_typedefsParser.Type} [new] The type of the `new` argument specified as `function(new: Type)`.

* @suppress {nonStandardJsDocs}
* @typedef {_typedefsParser.Type} Type The representation of a type.
* @typedef {_typedefsParser.Type} Type `@record` The representation of a type.
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {Object} _typedefsParser.Type The representation of a type.
* @typedef {Object} _typedefsParser.Type `@record` The representation of a type.
* @prop {boolean} [nullable] 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`.

@@ -36,0 +36,0 @@ * @prop {string} [name] The name of the type.

@@ -112,4 +112,9 @@ import { Fn, fn,

consume()
const type = parseType()
props[propName] = type
try {
const type = parseType()
props[propName] = type
} catch (err) {
err.message += `(when parsing ${propName} property)`
throw err
}
}

@@ -120,3 +125,5 @@ if(peek() == '}') {

}
if (peek() != ',') throw new Error('Expecting , for record')
if (peek() != ',') {
throw new Error(`Expecting , for record after ${propName}`)
}
consume()

@@ -140,3 +147,3 @@ }

token = peek()
if (token == '(') { // consider cases without ()
if (token == '(') { // union, consider cases without ()
consume()

@@ -149,3 +156,5 @@ type = {

consume()
return type
if (peek() != '|') {
return type
}
} else if (token == '{') {

@@ -162,4 +171,6 @@ consume()

type.name = peek()
consume()
if (peek() != '|') {
type.name = peek()
consume()
}
if (fn == token) {

@@ -166,0 +177,0 @@ type.function = parseFunction()

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