@typedefs/parser
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -92,16 +92,3 @@ const { Fn, fn, | ||
} | ||
const parseUnion = () => { | ||
const types = [] | ||
while(peek() != ')') { | ||
const type = parseType() | ||
types.push(type) | ||
if (peek() == ')') { | ||
consume() | ||
break | ||
} | ||
if (peek() != '|') throw new Error('Expecting | for union') | ||
consume() | ||
} | ||
return types | ||
} | ||
const parseRecord = () => { | ||
@@ -130,3 +117,3 @@ const props = {} | ||
/** @type {!_typedefsParser.Type} */ | ||
const type = {} | ||
let type = {} | ||
let applicationWithDot | ||
@@ -144,3 +131,8 @@ /** @type {string} */ | ||
consume() | ||
type.union = parseUnion() | ||
type = { | ||
...parseType(), | ||
...type, // preserve nullable | ||
} | ||
if (peek() != ')') throw new Error('Expecting closing )') | ||
consume() | ||
return type | ||
@@ -158,3 +150,3 @@ } else if (token == '{') { | ||
type.name = token | ||
type.name = peek() | ||
consume() | ||
@@ -178,3 +170,13 @@ if ([fn, Fn].includes(token)) { | ||
} | ||
return type | ||
if (peek() != '|') return type | ||
const union = [type] | ||
while(peek() == '|') { | ||
consume() | ||
const nextType = parseType(true) | ||
const u = nextType.union ? nextType.union : [nextType] | ||
union.push(...u) | ||
} | ||
return { union } | ||
} | ||
@@ -181,0 +183,0 @@ |
@@ -0,1 +1,7 @@ | ||
## 27 April 2019 | ||
### [1.1.0](https://github.com/artdecocode/parser/compare/v1.0.3...v1.1.0) | ||
- [feature] Implement the union type without parenthesis. | ||
## 26 April 2019 | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "@typedefs/parser", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "The Parser For JSDoc Types.", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -103,4 +103,4 @@ # @typedefs/parser | ||
application: | ||
[ { nullable: true, | ||
union: [ { name: 'string' }, { name: 'symbol' } ] } ] } ] } | ||
[ { union: [ { name: 'string' }, { name: 'symbol' } ], | ||
nullable: true } ] } ] } | ||
@@ -107,0 +107,0 @@ Records: |
@@ -92,16 +92,3 @@ import { Fn, fn, | ||
} | ||
const parseUnion = () => { | ||
const types = [] | ||
while(peek() != ')') { | ||
const type = parseType() | ||
types.push(type) | ||
if (peek() == ')') { | ||
consume() | ||
break | ||
} | ||
if (peek() != '|') throw new Error('Expecting | for union') | ||
consume() | ||
} | ||
return types | ||
} | ||
const parseRecord = () => { | ||
@@ -130,3 +117,3 @@ const props = {} | ||
/** @type {!_typedefsParser.Type} */ | ||
const type = {} | ||
let type = {} | ||
let applicationWithDot | ||
@@ -144,3 +131,8 @@ /** @type {string} */ | ||
consume() | ||
type.union = parseUnion() | ||
type = { | ||
...parseType(), | ||
...type, // preserve nullable | ||
} | ||
if (peek() != ')') throw new Error('Expecting closing )') | ||
consume() | ||
return type | ||
@@ -158,3 +150,3 @@ } else if (token == '{') { | ||
type.name = token | ||
type.name = peek() | ||
consume() | ||
@@ -178,3 +170,13 @@ if ([fn, Fn].includes(token)) { | ||
} | ||
return type | ||
if (peek() != '|') return type | ||
const union = [type] | ||
while(peek() == '|') { | ||
consume() | ||
const nextType = parseType(true) | ||
const u = nextType.union ? nextType.union : [nextType] | ||
union.push(...u) | ||
} | ||
return { union } | ||
} | ||
@@ -181,0 +183,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
27017
448