Socket
Socket
Sign inDemoInstall

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 7.0.0 to 8.0.0

renovate.json

1

lib/NodeType.js

@@ -7,2 +7,3 @@ 'use strict';

UNION: 'UNION',
INTERSECTION: 'INTERSECTION',
VARIADIC: 'VARIADIC',

@@ -9,0 +10,0 @@ RECORD: 'RECORD',

12

lib/parsing.js

@@ -7,2 +7,3 @@ 'use strict';

* @property {'none'|'single'|'double'} [quoteStyle]
* @property {boolean} [readonly]
* @property {string} [key]

@@ -78,2 +79,3 @@ * @property {string} [name]

* @property {"permissive"|"jsdoc"|"closure"|"typescript"} [mode='permissive']
* @property {"TopTypeExpr"|"BroadNamepathExpr"|"NamepathExpr"|"ExternalNameExpr"|"ModuleNameExpr"} [startRule="TopTypeExpr"]
*/

@@ -87,12 +89,12 @@

*/
parse (typeExprStr, {mode = 'permissive'} = {}) {
parse (typeExprStr, {mode = 'permissive', startRule = 'TopTypeExpr'} = {}) {
switch (mode) {
case 'jsdoc':
return parseJsdoc(typeExprStr);
return parseJsdoc(typeExprStr, {startRule});
case 'closure':
return parseClosure(typeExprStr);
return parseClosure(typeExprStr, {startRule});
case 'typescript':
return parseTypeScript(typeExprStr);
return parseTypeScript(typeExprStr, {startRule});
case 'permissive':
return parse(typeExprStr);
return parse(typeExprStr, {startRule});
default:

@@ -99,0 +101,0 @@ throw new TypeError('Unrecognized mode: ' + inspect(mode));

'use strict';
const {OPTIONAL} = require('./NodeType');
const {OPTIONAL, PARENTHESIS} = require('./NodeType');
const {OptionalTypeSyntax, VariadicTypeSyntax} = require('./SyntaxType');

@@ -61,5 +61,9 @@ const {format} = require('util');

UNION (unionNode, concretePublish) {
return format('%s|%s', concretePublish(unionNode.left),
return format('%s | %s', concretePublish(unionNode.left),
concretePublish(unionNode.right));
},
INTERSECTION (unionNode, concretePublish) {
return format('%s & %s', concretePublish(unionNode.left),
concretePublish(unionNode.right));
},
VARIADIC (variadicNode, concretePublish) {

@@ -76,10 +80,12 @@ if (variadicNode.meta.syntax === VariadicTypeSyntax.ONLY_DOTS) {

RECORD_ENTRY (entryNode, concretePublish) {
if (!entryNode.value) return addQuotesForName(entryNode.key, entryNode.quoteStyle);
const {readonly, value, key, quoteStyle} = entryNode;
const readonlyString = readonly ? 'readonly ' : '';
if (!value) return readonlyString + addQuotesForName(key, quoteStyle);
const keySuffix = (
entryNode.value.type === OPTIONAL &&
entryNode.value.meta.syntax === OptionalTypeSyntax.SUFFIX_KEY_QUESTION_MARK
value.type === OPTIONAL &&
value.meta.syntax === OptionalTypeSyntax.SUFFIX_KEY_QUESTION_MARK
)
? '?'
: '';
return format('%s%s: %s', addQuotesForName(entryNode.key, entryNode.quoteStyle), keySuffix, concretePublish(entryNode.value));
return format('%s%s%s: %s', readonlyString, addQuotesForName(key, quoteStyle), keySuffix, concretePublish(value));
},

@@ -180,2 +186,5 @@ TUPLE (tupleNode, concretePublish) {

KEY_QUERY (keyQueryNode, concretePublish) {
if (keyQueryNode.value.type === PARENTHESIS) {
return format('keyof%s', concretePublish(keyQueryNode.value));
}
return format('keyof %s', concretePublish(keyQueryNode.value));

@@ -182,0 +191,0 @@ },

@@ -21,3 +21,3 @@ 'use strict';

/**
* From JSDoc and JSDuck.
* From JSDoc.
* Example: {@code String[]}

@@ -28,21 +28,2 @@ */

/**
* Syntax types for union types.
* @enum {string}
*/
const UnionTypeSyntax = {
/**
* From Closure Library.
* Example: {@code Left|Right}
*/
PIPE: 'PIPE',
/**
* From JSDuck.
* Example: {@code Left/Right}
*/
SLASH: 'SLASH',
};
const VariadicTypeSyntax = {

@@ -86,3 +67,2 @@ /**

GenericTypeSyntax,
UnionTypeSyntax,
VariadicTypeSyntax,

@@ -89,0 +69,0 @@ OptionalTypeSyntax,

@@ -63,2 +63,6 @@ 'use strict';

},
INTERSECTION: {
left: _PropertyAccessor.NODE,
right: _PropertyAccessor.NODE,
},
VARIADIC: {

@@ -65,0 +69,0 @@ value: _PropertyAccessor.NODE,

{
"name": "jsdoctypeparser",
"description": "Strict JsDoc type expression parser.",
"version": "7.0.0",
"version": "8.0.0",
"author": "Kuniwak <orga.chem.job@gmail.com>",

@@ -55,6 +55,6 @@ "contributors": [

"prebuild": "npm-run-all clean",
"build:jsdoc": "frs-replace '^.*// [^/]*?no-jsdoc(?!-)[^/]*?$' '' -f gm -i './peg_src/jsdoctype.pegjs' --stdout | frs-replace '^.*// [^/]*?no-jsdoc-begin[\\s\\S]*?no-jsdoc-end.*?$' '' -f gm | pegjs --cache -o ./peg_lib/jsdoctype-jsdoc.js",
"build:typescript": "frs-replace '^.*// [^/]*?no-typescript(?!-)[^/]*?$' '' -f gm -i './peg_src/jsdoctype.pegjs' --stdout | frs-replace '^.*// [^/]*?no-typescript-begin[\\s\\S]*?no-typescript-end.*?$' '' -f gm | pegjs --cache -o ./peg_lib/jsdoctype-typescript.js",
"build:closure": "frs-replace '^.*// [^/]*?no-closure(?!-)[^/]*?$' '' -f gm -i './peg_src/jsdoctype.pegjs' --stdout | frs-replace '^.*// [^/]*?no-closure-begin[\\s\\S]*?no-closure-end.*?$' '' -f gm| pegjs --cache -o ./peg_lib/jsdoctype-closure.js",
"build:permissive": "pegjs --cache -o ./peg_lib/jsdoctype-permissive.js ./peg_src/jsdoctype.pegjs",
"build:jsdoc": "frs-replace '^.*// [^/]*?no-jsdoc(?!-)[^/]*?$' '' -f gm -i './peg_src/jsdoctype.pegjs' --stdout | frs-replace '^.*// [^/]*?no-jsdoc-begin[\\s\\S]*?no-jsdoc-end.*?$' '' -f gm | pegjs --allowed-start-rules TopTypeExpr,NamepathExpr,BroadNamepathExpr,ExternalNameExpr,ModuleNameExpr --cache -o ./peg_lib/jsdoctype-jsdoc.js",
"build:typescript": "frs-replace '^.*// [^/]*?no-typescript(?!-)[^/]*?$' '' -f gm -i './peg_src/jsdoctype.pegjs' --stdout | frs-replace '^.*// [^/]*?no-typescript-begin[\\s\\S]*?no-typescript-end.*?$' '' -f gm | pegjs --allowed-start-rules TopTypeExpr,NamepathExpr,BroadNamepathExpr --cache -o ./peg_lib/jsdoctype-typescript.js",
"build:closure": "frs-replace '^.*// [^/]*?no-closure(?!-)[^/]*?$' '' -f gm -i './peg_src/jsdoctype.pegjs' --stdout | frs-replace '^.*// [^/]*?no-closure-begin[\\s\\S]*?no-closure-end.*?$' '' -f gm| pegjs --allowed-start-rules TopTypeExpr,NamepathExpr,BroadNamepathExpr,ExternalNameExpr,ModuleNameExpr --cache -o ./peg_lib/jsdoctype-closure.js",
"build:permissive": "pegjs --allowed-start-rules TopTypeExpr,NamepathExpr,BroadNamepathExpr,ExternalNameExpr,ModuleNameExpr --cache -o ./peg_lib/jsdoctype-permissive.js ./peg_src/jsdoctype.pegjs",
"build": "npm run build:jsdoc && npm run build:typescript && npm run build:closure && npm run build:permissive"

@@ -69,6 +69,7 @@ },

"devDependencies": {
"@exe-boss/renovate-config": "^0.1.0",
"@frsource/frs-replace": "^2.1.1",
"@types/node": "^14.0.13",
"chai": "^4.2.0",
"eslint": "^7.2.0",
"@frsource/frs-replace": "^2.1.1",
"eslint": "^7.3.1",
"husky": "^4.2.5",

@@ -75,0 +76,0 @@ "mkdirp": "^1.0.4",

@@ -12,4 +12,2 @@ # jsdoctypeparser

* `Array<string>`, `function(arg1, arg2): ret`
* [JSDuck type definitions](https://github.com/senchalabs/jsduck/wiki/Type-Definitions)
* `Boolean/"top"/"bottom"`
* [some Typescript types](https://github.com/Microsoft/TypeScript)

@@ -255,3 +253,2 @@ * `(x: number) => string`, `typeof x`, `import("./some-module")`

* @type {(left|right)}
* @type {left/right}
*/

@@ -266,9 +263,27 @@ ```

"left": node,
"right": node,
"meta": {
"syntax": ("PIPE" or "SLASH")
}
"right": node
}
```
### `INTERSECTION`
Example:
```javascript
/**
* @type {left&right}
* @type {(left&right)}
*/
```
Structure:
```javascript
{
"type": "INTERSECTION",
"left": node,
"right": node
}
```
### `RECORD`

@@ -275,0 +290,0 @@

@@ -7,2 +7,3 @@ {

"UNION",
"INTERSECTION",
"VARIADIC",

@@ -9,0 +10,0 @@ "RECORD",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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