Socket
Socket
Sign inDemoInstall

doctrine-temporary-fork

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-alpha-allowarrayindex to 2.0.1

38

CHANGELOG.md

@@ -0,1 +1,39 @@

# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="2.0.1"></a>
## [2.0.1](https://github.com/eslint/doctrine/compare/v2.0.0...v2.0.1) (2018-04-11)
### Bug Fixes
* Allow array indexes in names ([#193](https://github.com/eslint/doctrine/issues/193)) ([4f028d8](https://github.com/eslint/doctrine/commit/4f028d8))
* support type expression for [@this](https://github.com/this) tag (fixes [#181](https://github.com/eslint/doctrine/issues/181)) ([#182](https://github.com/eslint/doctrine/issues/182)) ([07f4751](https://github.com/eslint/doctrine/commit/07f4751))
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
v2.1.0 - January 6, 2018
* 827f314 Update: support node ranges (fixes #89) (#190) (Teddy Katz)
v2.0.2 - November 25, 2017
* 5049ee3 Fix: Remove redundant LICENSE/README names from files (#203) (Kevin Partington)
v2.0.1 - November 10, 2017
* 009f33d Fix: Making sure union type stringification respects compact flag (#199) (Mitermayer Reis)
* 19da935 Use native String.prototype.trim instead of a custom implementation. (#201) (Rouven Weßling)
* e3a011b chore: add mocha.opts to restore custom mocha config (Jason Kurian)
* d888200 chore: adds nyc and a newer version of mocha to accurately report coverage (Jason Kurian)
* 6b210a8 fix: support type expression for @this tag (fixes #181) (#182) (Frédéric Junod)
* 1c4a4c7 fix: Allow array indexes in names (#193) (Tom MacWright)
* 9aed54d Fix incorrect behavior when arrow functions are used as default values (#189) (Gaurab Paul)
* 9efb6ca Upgrade: Use Array.isArray instead of isarray package (#195) (medanat)
v2.0.0 - November 15, 2016

@@ -2,0 +40,0 @@

146

lib/doctrine.js

@@ -13,3 +13,2 @@ /*

utility,
isArray,
jsdoc,

@@ -20,3 +19,2 @@ esutils,

esutils = require('esutils');
isArray = require('isarray');
typed = require('./typed');

@@ -97,6 +95,7 @@ utility = require('./utility');

function trim(str) {
return str.replace(/^\s+/, '').replace(/\s+$/, '');
}
// A regex character class that contains all whitespace except linebreak characters (\r, \n, \u2028, \u2029)
var WHITESPACE = '[ \\f\\t\\v\\u00a0\\u1680\\u180e\\u2000-\\u200a\\u202f\\u205f\\u3000\\ufeff]';
var STAR_MATCHER = '(' + WHITESPACE + '*(?:\\*' + WHITESPACE + '?)?)(.+|[\r\n\u2028\u2029])';
function unwrapComment(doc) {

@@ -107,50 +106,35 @@ // JSDoc comment is following form

// */
// remove /**, */ and *
var BEFORE_STAR = 0,
STAR = 1,
AFTER_STAR = 2,
index,
len,
mode,
result,
ch;
doc = doc.replace(/^\/\*\*?/, '').replace(/\*\/$/, '');
index = 0;
len = doc.length;
mode = BEFORE_STAR;
result = '';
return doc.
// remove /**
replace(/^\/\*\*?/, '').
// remove */
replace(/\*\/$/, '').
// remove ' * ' at the beginning of a line
replace(new RegExp(STAR_MATCHER, 'g'), '$2').
// remove trailing whitespace
replace(/\s*$/, '');
}
while (index < len) {
ch = doc.charCodeAt(index);
switch (mode) {
case BEFORE_STAR:
if (esutils.code.isLineTerminator(ch)) {
result += String.fromCharCode(ch);
} else if (ch === 0x2A /* '*' */) {
mode = STAR;
} else if (!esutils.code.isWhiteSpace(ch)) {
result += String.fromCharCode(ch);
mode = AFTER_STAR;
}
break;
/**
* Converts an index in an "unwrapped" JSDoc comment to the corresponding index in the original "wrapped" version
* @param {string} originalSource The original wrapped comment
* @param {number} unwrappedIndex The index of a character in the unwrapped string
* @returns {number} The index of the corresponding character in the original wrapped string
*/
function convertUnwrappedCommentIndex(originalSource, unwrappedIndex) {
var replacedSource = originalSource.replace(/^\/\*\*?/, '');
var numSkippedChars = 0;
var matcher = new RegExp(STAR_MATCHER, 'g');
var match;
case STAR:
if (!esutils.code.isWhiteSpace(ch)) {
result += String.fromCharCode(ch);
}
mode = esutils.code.isLineTerminator(ch) ? BEFORE_STAR : AFTER_STAR;
break;
while ((match = matcher.exec(replacedSource))) {
numSkippedChars += match[1].length;
case AFTER_STAR:
result += String.fromCharCode(ch);
if (esutils.code.isLineTerminator(ch)) {
mode = BEFORE_STAR;
}
break;
if (match.index + match[0].length > unwrappedIndex + numSkippedChars) {
return unwrappedIndex + numSkippedChars + originalSource.length - replacedSource.length;
}
index += 1;
}
return result.replace(/\s+$/, '');
return originalSource.replace(/\*\/$/, '').replace(/\s*$/, '').length;
}

@@ -166,2 +150,3 @@

source,
originalSource,
recoverable,

@@ -201,2 +186,6 @@ sloppy,

} else if (waiting) {
// '\@'
if (ch === 0x5c /* '\' */ && source.charCodeAt(last + 1) === 0x40 /* '@' */) {
source = source.substring(0, last) + source.substring(last + 1);
}
if (ch === 0x40 /* '@' */) {

@@ -218,4 +207,4 @@ break;

// therefore, scanning type expression with balancing braces.
function parseType(title, last) {
var ch, brace, type, direct = false;
function parseType(title, last, addRange) {
var ch, brace, type, startIndex, direct = false;

@@ -260,2 +249,5 @@

}
if (type === '') {
startIndex = index;
}
type += advance();

@@ -271,6 +263,6 @@ }

if (isAllowedOptional(title)) {
return typed.parseParamType(type);
return typed.parseParamType(type, {startIndex: convertIndex(startIndex), range: addRange});
}
return typed.parseType(type);
return typed.parseType(type, {startIndex: convertIndex(startIndex), range: addRange});
}

@@ -420,2 +412,9 @@

function convertIndex(rangeIndex) {
if (source === originalSource) {
return rangeIndex;
}
return convertUnwrappedCommentIndex(originalSource, rangeIndex);
}
function TagParser(options, title) {

@@ -431,2 +430,3 @@ this._options = options;

}
this._first = index - title.length - 1;
this._last = 0;

@@ -462,3 +462,3 @@ // space to save special information for title parsers.

try {
this._tag.type = parseType(this._title, this._last);
this._tag.type = parseType(this._title, this._last, this._options.range);
if (!this._tag.type) {

@@ -480,3 +480,3 @@ if (!isParamTitle(this._title) && !isReturnTitle(this._title)) {

try {
this._tag.type = parseType(this._title, this._last);
this._tag.type = parseType(this._title, this._last, this._options.range);
} catch (e) {

@@ -541,4 +541,4 @@ //For optional types, lets drop the thrown error when we hit the end of the file

assign = name.substring(1, name.length - 1).split('=');
if (assign[1]) {
this._tag['default'] = assign[1];
if (assign.length > 1) {
this._tag['default'] = assign.slice(1).join('=');
}

@@ -563,3 +563,3 @@ this._tag.name = assign[0];

TagParser.prototype.parseDescription = function parseDescription() {
var description = trim(sliceSource(source, index, this._last));
var description = sliceSource(source, index, this._last).trim();
if (description) {

@@ -575,3 +575,3 @@ if ((/^-\s+/).test(description)) {

TagParser.prototype.parseCaption = function parseDescription() {
var description = trim(sliceSource(source, index, this._last));
var description = sliceSource(source, index, this._last).trim();
var captionStartTag = '<caption>';

@@ -582,5 +582,5 @@ var captionEndTag = '</caption>';

if (captionStart >= 0 && captionEnd >= 0) {
this._tag.caption = trim(description.substring(
captionStart + captionStartTag.length, captionEnd));
this._tag.description = trim(description.substring(captionEnd + captionEndTag.length));
this._tag.caption = description.substring(
captionStart + captionStartTag.length, captionEnd).trim();
this._tag.description = description.substring(captionEnd + captionEndTag.length).trim();
} else {

@@ -607,3 +607,3 @@ this._tag.description = description;

};
kind = trim(sliceSource(source, index, this._last));
kind = sliceSource(source, index, this._last).trim();
this._tag.kind = kind;

@@ -620,3 +620,3 @@ if (!hasOwnProperty(kinds, kind)) {

var access;
access = trim(sliceSource(source, index, this._last));
access = sliceSource(source, index, this._last).trim();
this._tag.access = access;

@@ -631,9 +631,9 @@ if (access !== 'private' && access !== 'protected' && access !== 'public') {

TagParser.prototype.parseThis = function parseAccess() {
// this name may be a name expression (e.g. {foo.bar})
// or a name path (e.g. foo.bar)
var value = trim(sliceSource(source, index, this._last));
TagParser.prototype.parseThis = function parseThis() {
// this name may be a name expression (e.g. {foo.bar}),
// an union (e.g. {foo.bar|foo.baz}) or a name path (e.g. foo.bar)
var value = sliceSource(source, index, this._last).trim();
if (value && value.charAt(0) === '{') {
var gotType = this.parseType();
if (gotType && this._tag.type.type === 'NameExpression') {
if (gotType && this._tag.type.type === 'NameExpression' || this._tag.type.type === 'UnionType') {
this._tag.name = this._tag.type.name;

@@ -651,3 +651,3 @@ return true;

var variation, text;
text = trim(sliceSource(source, index, this._last));
text = sliceSource(source, index, this._last).trim();
variation = parseFloat(text, 10);

@@ -664,3 +664,3 @@ this._tag.variation = variation;

TagParser.prototype.ensureEnd = function () {
var shouldBeEmpty = trim(sliceSource(source, index, this._last));
var shouldBeEmpty = sliceSource(source, index, this._last).trim();
if (shouldBeEmpty) {

@@ -782,2 +782,6 @@ if (!this.addError('Unknown content \'%0\'', shouldBeEmpty)) {

if (this._options.range) {
this._tag.range = [this._first, source.slice(0, this._last).replace(/\s*$/, '').length].map(convertIndex);
}
if (hasOwnProperty(Rules, this._title)) {

@@ -847,3 +851,3 @@ sequences = Rules[this._title];

return preserveWhitespace ? description : trim(description);
return preserveWhitespace ? description : description.trim();
}

@@ -864,5 +868,7 @@

originalSource = comment;
// array of relevant tags
if (options.tags) {
if (isArray(options.tags)) {
if (Array.isArray(options.tags)) {
interestingTags = { };

@@ -869,0 +875,0 @@ for (i = 0, iz = options.tags.length; i < iz; i++) {

@@ -22,3 +22,5 @@ /*

esutils,
utility;
utility,
rangeOffset,
addRange;

@@ -98,2 +100,9 @@ esutils = require('esutils');

function maybeAddRange(node, range) {
if (addRange) {
node.range = [range[0] + rangeOffset, range[1] + rangeOffset];
}
return node;
}
function advance() {

@@ -513,3 +522,3 @@ var ch = source.charAt(index);

function parseUnionType() {
var elements;
var elements, startIndex = index - 1;
consume(Token.LPAREN, 'UnionType should start with (');

@@ -527,6 +536,6 @@ elements = [];

consume(Token.RPAREN, 'UnionType should end with )');
return {
return maybeAddRange({
type: Syntax.UnionType,
elements: elements
};
}, [startIndex, previous]);
}

@@ -542,3 +551,3 @@

function parseArrayType() {
var elements;
var elements, startIndex = index - 1, restStartIndex;
consume(Token.LBRACK, 'ArrayType should start with [');

@@ -548,7 +557,8 @@ elements = [];

if (token === Token.REST) {
restStartIndex = index - 3;
consume(Token.REST);
elements.push({
elements.push(maybeAddRange({
type: Syntax.RestType,
expression: parseTypeExpression()
});
}, [restStartIndex, previous]));
break;

@@ -563,6 +573,6 @@ } else {

expect(Token.RBRACK);
return {
return maybeAddRange({
type: Syntax.ArrayType,
elements: elements
};
}, [startIndex, previous]);
}

@@ -595,3 +605,3 @@

function parseFieldType() {
var key;
var key, rangeStart = previous;

@@ -601,13 +611,13 @@ key = parseFieldName();

consume(Token.COLON);
return {
return maybeAddRange({
type: Syntax.FieldType,
key: key,
value: parseTypeExpression()
};
}, [rangeStart, previous]);
}
return {
return maybeAddRange({
type: Syntax.FieldType,
key: key,
value: null
};
}, [rangeStart, previous]);
}

@@ -622,3 +632,3 @@

function parseRecordType() {
var fields;
var fields, rangeStart = index - 1, rangeEnd;

@@ -637,7 +647,8 @@ consume(Token.LBRACE, 'RecordType should start with {');

}
rangeEnd = index;
expect(Token.RBRACE);
return {
return maybeAddRange({
type: Syntax.RecordType,
fields: fields
};
}, [rangeStart, rangeEnd]);
}

@@ -653,3 +664,3 @@

function parseNameExpression() {
var name = value;
var name = value, rangeStart = index - name.length;
expect(Token.NAME);

@@ -666,6 +677,6 @@

return {
return maybeAddRange({
type: Syntax.NameExpression,
name: name
};
}, [rangeStart, previous]);
}

@@ -695,3 +706,3 @@

function parseTypeName() {
var expr, applications;
var expr, applications, startIndex = index - value.length;

@@ -703,7 +714,7 @@ expr = parseNameExpression();

expect(Token.GT);
return {
return maybeAddRange({
type: Syntax.TypeApplication,
expression: expr,
applications: applications
};
}, [startIndex, previous]);
}

@@ -755,3 +766,3 @@ return expr;

function parseParametersType() {
var params = [], optionalSequence = false, expr, rest = false;
var params = [], optionalSequence = false, expr, rest = false, startIndex, restStartIndex = index - 3, nameStartIndex;

@@ -765,18 +776,21 @@ while (token !== Token.RPAREN) {

startIndex = previous;
expr = parseTypeExpression();
if (expr.type === Syntax.NameExpression && token === Token.COLON) {
nameStartIndex = previous - expr.name.length;
// Identifier ':' TypeExpression
consume(Token.COLON);
expr = {
expr = maybeAddRange({
type: Syntax.ParameterType,
name: expr.name,
expression: parseTypeExpression()
};
}, [nameStartIndex, previous]);
}
if (token === Token.EQUAL) {
consume(Token.EQUAL);
expr = {
expr = maybeAddRange({
type: Syntax.OptionalType,
expression: expr
};
}, [startIndex, previous]);
optionalSequence = true;

@@ -789,6 +803,6 @@ } else {

if (rest) {
expr = {
expr = maybeAddRange({
type: Syntax.RestType,
expression: expr
};
}, [restStartIndex, previous]);
}

@@ -811,3 +825,3 @@ params.push(expr);

function parseFunctionType() {
var isNew, thisBinding, params, result, fnType;
var isNew, thisBinding, params, result, fnType, startIndex = index - value.length;
utility.assert(token === Token.NAME && value === 'function', 'FunctionType should start with \'function\'');

@@ -849,7 +863,7 @@ consume(Token.NAME);

fnType = {
fnType = maybeAddRange({
type: Syntax.FunctionType,
params: params,
result: result
};
}, [startIndex, previous]);
if (thisBinding) {

@@ -875,9 +889,9 @@ // avoid adding null 'new' and 'this' properties

function parseBasicTypeExpression() {
var context;
var context, startIndex;
switch (token) {
case Token.STAR:
consume(Token.STAR);
return {
return maybeAddRange({
type: Syntax.AllLiteral
};
}, [previous - 1, previous]);

@@ -894,7 +908,9 @@ case Token.LPAREN:

case Token.NAME:
startIndex = index - value.length;
if (value === 'null') {
consume(Token.NAME);
return {
return maybeAddRange({
type: Syntax.NullLiteral
};
}, [startIndex, previous]);
}

@@ -904,5 +920,5 @@

consume(Token.NAME);
return {
return maybeAddRange({
type: Syntax.UndefinedLiteral
};
}, [startIndex, previous]);
}

@@ -912,6 +928,6 @@

consume(Token.NAME);
return {
return maybeAddRange({
type: Syntax.BooleanLiteralType,
value: value === 'true'
};
}, [startIndex, previous]);
}

@@ -932,13 +948,13 @@

next();
return {
return maybeAddRange({
type: Syntax.StringLiteralType,
value: value
};
}, [previous - value.length - 2, previous]);
case Token.NUMBER:
next();
return {
return maybeAddRange({
type: Syntax.NumericLiteralType,
value: value
};
}, [previous - String(value).length, previous]);

@@ -959,5 +975,6 @@ default:

function parseTypeExpression() {
var expr;
var expr, rangeStart;
if (token === Token.QUESTION) {
rangeStart = index - 1;
consume(Token.QUESTION);

@@ -967,20 +984,21 @@ if (token === Token.COMMA || token === Token.EQUAL || token === Token.RBRACE ||

token === Token.RBRACK || token === Token.GT) {
return {
return maybeAddRange({
type: Syntax.NullableLiteral
};
}, [rangeStart, previous]);
}
return {
return maybeAddRange({
type: Syntax.NullableType,
expression: parseBasicTypeExpression(),
prefix: true
};
}
if (token === Token.BANG) {
}, [rangeStart, previous]);
} else if (token === Token.BANG) {
rangeStart = index - 1;
consume(Token.BANG);
return {
return maybeAddRange({
type: Syntax.NonNullableType,
expression: parseBasicTypeExpression(),
prefix: true
};
}, [rangeStart, previous]);
} else {
rangeStart = previous;
}

@@ -991,7 +1009,7 @@

consume(Token.BANG);
return {
return maybeAddRange({
type: Syntax.NonNullableType,
expression: expr,
prefix: false
};
}, [rangeStart, previous]);
}

@@ -1001,7 +1019,7 @@

consume(Token.QUESTION);
return {
return maybeAddRange({
type: Syntax.NullableType,
expression: expr,
prefix: false
};
}, [rangeStart, previous]);
}

@@ -1012,10 +1030,10 @@

expect(Token.RBRACK, 'expected an array-style type declaration (' + value + '[])');
return {
return maybeAddRange({
type: Syntax.TypeApplication,
expression: {
expression: maybeAddRange({
type: Syntax.NameExpression,
name: 'Array'
},
}, [rangeStart, previous]),
applications: [expr]
};
}, [rangeStart, previous]);
}

@@ -1053,6 +1071,6 @@

return {
return maybeAddRange({
type: Syntax.UnionType,
elements: elements
};
}, [0, index]);
}

@@ -1065,6 +1083,6 @@

consume(Token.REST);
return {
return maybeAddRange({
type: Syntax.RestType,
expression: parseTop()
};
}, [0, index]);
}

@@ -1075,6 +1093,6 @@

consume(Token.EQUAL);
return {
return maybeAddRange({
type: Syntax.OptionalType,
expression: expr
};
}, [0, index]);
}

@@ -1092,2 +1110,4 @@

previous = 0;
addRange = opt && opt.range;
rangeOffset = opt && opt.startIndex || 0;

@@ -1118,2 +1138,4 @@ next();

previous = 0;
addRange = opt && opt.range;
rangeOffset = opt && opt.startIndex || 0;

@@ -1171,3 +1193,3 @@ next();

if ((i + 1) !== iz) {
result += '|';
result += compact ? '|' : ' | ';
}

@@ -1174,0 +1196,0 @@ }

@@ -6,3 +6,3 @@ {

"main": "lib/doctrine.js",
"version": "2.0.0-alpha-allowarrayindex",
"version": "2.0.1",
"engines": {

@@ -15,7 +15,3 @@ "node": ">=0.10.0"

"files": [
"lib",
"LICENSE.BSD",
"LICENSE.closure-compiler",
"LICENSE.esprima",
"README.md"
"lib"
],

@@ -40,16 +36,19 @@ "maintainers": [

"eslint-release": "^0.10.0",
"istanbul": "^0.4.1",
"linefix": "^0.1.1",
"mocha": "^2.3.3",
"mocha": "^3.4.2",
"npm-license": "^0.3.1",
"nyc": "^10.3.2",
"semver": "^5.0.3",
"shelljs": "^0.5.3",
"shelljs-nodecli": "^0.1.1",
"should": "^5.0.1"
"should": "^5.0.1",
"standard-version": "^4.3.0"
},
"license": "Apache-2.0",
"scripts": {
"test": "npm run lint && node Makefile.js test",
"pretest": "npm run lint",
"test": "nyc mocha",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"lint": "eslint lib/",
"release": "eslint-release",
"release": "standard-version",
"ci-release": "eslint-ci-release",

@@ -60,5 +59,4 @@ "alpharelease": "eslint-prerelease alpha",

"dependencies": {
"esutils": "^2.0.2",
"isarray": "^1.0.0"
"esutils": "^2.0.2"
}
}

@@ -38,2 +38,3 @@ [![NPM version][npm-image]][npm-url]

* `lineNumbers` - set to `true` to add `lineNumber` to each node, specifying the line on which the node is found in the source. Default: `false`.
* `range` - set to `true` to add `range` to each node, specifying the start and end index of the node in the original comment. Default: `false`.

@@ -40,0 +41,0 @@ Here's a simple example:

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc