Skip to content

Commit 3219168

Browse files
authored
Typescript now reads type information without error. glayzzle#968 (glayzzle#980)
* docs: Modified jsdoc to be as per current types.d.ts. * A little processing has been added so that TokenNames are defined as constants. * NullSafePropertyLookup has renamed its constructor. * docs: npm run build-types * docs: fix typo, and define type. * chore: add type check in github actions. * chore: npm run test -- --updateSnapshot * chore: add diff check for types.d.ts. * docs: fix style.
1 parent e2b7453 commit 3219168

39 files changed

+363
-345
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ jobs:
2424
yarn
2525
yarn test
2626
27+
- name: type check
28+
run: |
29+
npm i -g typescript
30+
yarn build-types
31+
[ $(git diff types.d.ts | wc -l) -gt 0 ] && echo 'Diff exists in types.d.ts. Please change jsdoc.' && exit 1
32+
tsc --noEmit types.d.ts
33+
2734
- name: install valgrind
2835
run: sudo apt-get install -y valgrind
2936

src/ast/array.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const KIND = "array";
3131
* ]
3232
* }
3333
* @extends {Expression}
34-
* @property {Entry|Expression|Variable} items List of array items
34+
* @property {Array<Entry|Expression|Variable>} items List of array items
3535
* @property {boolean} shortForm Indicate if the short array syntax is used, ex `[]` instead `array()`
3636
*/
3737
module.exports = Expr.extends(

src/ast/attrgroup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const KIND = "attrgroup";
1010

1111
/**
1212
* Attribute group
13+
* @memberOf module:php-parser
1314
* @constructor AttrGroup
1415
* @extends {Node}
1516
* @property {Attribute[]} attrs

src/ast/attribute.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const KIND = "attribute";
1010

1111
/**
1212
* Attribute Value
13+
* @memberOf module:php-parser
1314
* @constructor Attribute
1415
* @extends {Node}
1516
* @property {String} name

src/ast/boolean.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const KIND = "boolean";
1313
* @constructor Boolean
1414
* @memberOf module:php-parser
1515
* @extends {Literal}
16+
* @property {boolean} value
1617
*/
1718
module.exports = Literal.extends(
1819
KIND,

src/ast/call.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const KIND = "call";
1414
* @memberOf module:php-parser
1515
* @extends {Expression}
1616
* @property {Identifier|Variable} what
17-
* @property {Variable[]} arguments
17+
* @property {Expression[]} arguments
1818
*/
1919
module.exports = Expression.extends(
2020
KIND,

src/ast/catch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const KIND = "catch";
1313
* @constructor Catch
1414
* @memberOf module:php-parser
1515
* @extends {Statement}
16-
* @property {Identifier[]} what
17-
* @property {Variable|null} variable
18-
* @property {Statement} body
16+
* @property {Name[]} what
17+
* @property {Variable} variable
18+
* @property {Block} body
1919
* @see http://php.net/manual/en/language.exceptions.php
2020
*/
2121
module.exports = Statement.extends(

src/ast/class.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const KIND = "class";
1414
* @memberOf module:php-parser
1515
* @extends {Declaration}
1616
* @property {Identifier|null} extends
17-
* @property {Identifier[]} implements
17+
* @property {Identifier[]|null} implements
1818
* @property {Declaration[]} body
19-
* @property {AttrGroup[]} attrGroups
2019
* @property {boolean} isAnonymous
2120
* @property {boolean} isAbstract
2221
* @property {boolean} isFinal
22+
* @property {AttrGroup[]} attrGroups
2323
*/
2424
module.exports = Declaration.extends(
2525
KIND,

src/ast/declare.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const KIND = "declare";
1313
* @constructor Declare
1414
* @memberOf module:php-parser
1515
* @extends {Block}
16-
* @property {Array[]} directives
17-
* @property {String} mode
16+
* @property {DeclareDirective[]} directives
17+
* @property {string} mode
1818
* @see http://php.net/manual/en/control-structures.declare.php
1919
*/
2020
const Declare = Block.extends(

src/ast/declaredirective.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const KIND = "declaredirective";
1313
* @constructor DeclareDirective
1414
* @memberOf module:php-parser
1515
* @extends {Node}
16-
* @property {Identifier} name
16+
* @property {Identifier} key
1717
* @property {Node|string|number|boolean|null} value
1818
*/
1919
module.exports = Node.extends(

src/ast/do.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const KIND = "do";
1414
* @memberOf module:php-parser
1515
* @extends {Statement}
1616
* @property {Expression} test
17-
* @property {Statement} body
17+
* @property {Block | null} body
1818
*/
1919
module.exports = Statement.extends(
2020
KIND,

src/ast/echo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const KIND = "echo";
1313
* @constructor Echo
1414
* @memberOf module:php-parser
1515
* @property {boolean} shortForm
16+
* @property {Expression[]} expressions
1617
* @extends {Statement}
1718
*/
1819
module.exports = Statement.extends(

src/ast/encapsed.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const KIND = "encapsed";
1515
* @extends {Literal}
1616
* @property {String} type - Defines the type of encapsed string (shell, heredoc, string)
1717
* @property {String|Null} label - The heredoc label, defined only when the type is heredoc
18+
* @property {EncapsedPart[]} value
1819
*/
1920
const Encapsed = Literal.extends(
2021
KIND,

src/ast/entry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const KIND = "entry";
1010

1111
/**
1212
* An array entry - see [Array](#array)
13-
* @constructor Entry
1413
* @memberOf module:php-parser
14+
* @constructor Entry
1515
* @extends {Expression}
1616
* @property {Node|null} key The entry key/offset
1717
* @property {Node} value The entry value

src/ast/for.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const KIND = "for";
1616
* @property {Expression[]} init
1717
* @property {Expression[]} test
1818
* @property {Expression[]} increment
19-
* @property {Statement} body
19+
* @property {Block | null} body
2020
* @property {boolean} shortForm
2121
* @see http://php.net/manual/en/control-structures.for.php
2222
*/

src/ast/foreach.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const KIND = "foreach";
1616
* @property {Expression} source
1717
* @property {Expression|null} key
1818
* @property {Expression} value
19-
* @property {Statement} body
19+
* @property {Block | null} body
2020
* @property {boolean} shortForm
2121
* @see http://php.net/manual/en/control-structures.foreach.php
2222
*/

src/ast/function.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const KIND = "function";
1818
* @property {boolean} byref
1919
* @property {boolean} nullable
2020
* @property {Block|null} body
21-
* @property {AttrGroups[]} attrGroups
21+
* @property {AttrGroup[]} attrGroups
2222
*/
2323
module.exports = Declaration.extends(
2424
KIND,

src/ast/inline.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const KIND = "inline";
1313
* @constructor Inline
1414
* @memberOf module:php-parser
1515
* @extends {Literal}
16+
* @property {string} value
1617
*/
1718
module.exports = Literal.extends(
1819
KIND,

src/ast/intersectiontype.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const KIND = "intersectiontype";
1010

1111
/**
1212
* A union of types
13+
* @memberOf module:php-parser
1314
* @constructor IntersectionType
1415
* @extends {Declaration}
1516
* @property {TypeReference[]} types

src/ast/list.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const KIND = "list";
1414
* @memberOf module:php-parser
1515
* @extends {Expression}
1616
* @property {boolean} shortForm
17+
* @property {Entry[]} items
1718
*/
1819
module.exports = Expression.extends(
1920
KIND,

src/ast/literal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const KIND = "literal";
1414
* @memberOf module:php-parser
1515
* @extends {Expression}
1616
* @property {string} raw
17-
* @property {Node|string|number|boolean|null} value
17+
* @property {EncapsedPart[]|Node|string|number|boolean|null} value
1818
*/
1919
module.exports = Expression.extends(
2020
KIND,

src/ast/match.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const KIND = "match";
1010

1111
/**
1212
* Defines a match expression
13+
* @memberOf module:php-parser
1314
* @constructor Match
1415
* @extends {Expression}
1516
* @property {Expression} cond Condition expression to match against

src/ast/matcharm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const KIND = "matcharm";
1010

1111
/**
1212
* An array entry - see [Array](#array)
13-
* @constructor Entry
13+
* @memberOf module:php-parser
14+
* @constructor MatchArm
1415
* @extends {Expression}
1516
* @property {Expression[]|null} conds The match condition expression list - null indicates default arm
1617
* @property {Expression} body The return value expression

src/ast/namedargument.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const KIND = "namedargument";
1010

1111
/**
1212
* Named arguments.
13+
* @memberOf module:php-parser
1314
* @constructor namedargument
1415
* @extends {Expression}
1516
* @property {String} name

src/ast/nowdoc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const KIND = "nowdoc";
1515
* @extends {Literal}
1616
* @property {string} label
1717
* @property {string} raw
18+
* @property {string} value
1819
*/
1920
module.exports = Literal.extends(
2021
KIND,

src/ast/nullsafepropertylookup.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ const KIND = "nullsafepropertylookup";
1010

1111
/**
1212
* Lookup to an object property
13-
* @constructor PropertyLookup
13+
* @memberOf module:php-parser
14+
* @constructor NullSafePropertyLookup
1415
* @extends {Lookup}
1516
*/
1617
module.exports = Lookup.extends(
1718
KIND,
18-
function PropertyLookup(what, offset, docs, location) {
19+
function NullSafePropertyLookup(what, offset, docs, location) {
1920
Lookup.apply(this, [KIND, what, offset, docs, location]);
2021
}
2122
);

src/ast/number.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const KIND = "number";
1313
* @constructor Number
1414
* @memberOf module:php-parser
1515
* @extends {Literal}
16+
* @property {number} value
1617
*/
1718
module.exports = Literal.extends(
1819
KIND,

src/ast/parameter.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
const Declaration = require("./declaration");
99
const KIND = "parameter";
1010

11-
// eslint-disable-next-line no-unused-vars
12-
const MODIFIER_PUBLIC = 1;
13-
// eslint-disable-next-line no-unused-vars
14-
const MODIFIER_PROTECTED = 2;
15-
// eslint-disable-next-line no-unused-vars
16-
const MODIFIER_PRIVATE = 4;
17-
11+
/**
12+
* @memberOf module:php-parser
13+
* @typedef {1} MODIFIER_PUBLIC
14+
**/
15+
/**
16+
* @memberOf module:php-parser
17+
* @typedef {2} MODIFIER_PROTECTED
18+
**/
19+
/**
20+
* @memberOf module:php-parser
21+
* @typedef {4} MODIFIER_PRIVATE
22+
**/
1823
/**
1924
* Defines a function parameter
2025
* @constructor Parameter
@@ -26,7 +31,7 @@ const MODIFIER_PRIVATE = 4;
2631
* @property {boolean} variadic
2732
* @property {boolean} readonly
2833
* @property {boolean} nullable
29-
* @property {AttrGroups[]} attrGroups
34+
* @property {AttrGroup[]} attrGroups
3035
* @property {MODIFIER_PUBLIC|MODIFIER_PROTECTED|MODIFIER_PRIVATE} flags
3136
*/
3237
module.exports = Declaration.extends(

src/ast/propertylookup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const KIND = "propertylookup";
1010

1111
/**
1212
* Lookup to an object property
13-
* @constructor PropertyLookup
1413
* @memberOf module:php-parser
14+
* @constructor PropertyLookup
1515
* @extends {Lookup}
1616
*/
1717
module.exports = Lookup.extends(

src/ast/propertystatement.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const IS_PRIVATE = "private";
1919
* @memberOf module:php-parser
2020
* @extends {Statement}
2121
* @property {Property[]} properties
22+
* @property {string|null} visibility
23+
* @property {boolean} isStatic
2224
*/
2325
const PropertyStatement = Statement.extends(
2426
KIND,

src/ast/string.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const KIND = "string";
1616
* @property {boolean} unicode
1717
* @property {boolean} isDoubleQuote
1818
* @see {Encapsed}
19+
* @property {string} value
1920
*/
2021
module.exports = Literal.extends(
2122
KIND,

src/ast/uniontype.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const KIND = "uniontype";
1010

1111
/**
1212
* A union of types
13+
* @memberOf module:php-parser
1314
* @constructor UnionType
1415
* @extends {Declaration}
1516
* @property {TypeReference[]} types

src/ast/while.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const KIND = "while";
1414
* @memberOf module:php-parser
1515
* @extends {Statement}
1616
* @property {Expression} test
17-
* @property {Statement} body
17+
* @property {Block | null} body
1818
* @property {boolean} shortForm
1919
*/
2020
module.exports = Statement.extends(

src/parser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ Parser.prototype.error = function (expect) {
400400
/**
401401
* Create a position node from the lexers position
402402
*
403+
* @function Parser#position
404+
* @memberOf module:php-parser
403405
* @return {Position}
404406
*/
405407
Parser.prototype.position = function () {
@@ -633,7 +635,9 @@ Parser.prototype.next = function () {
633635

634636
/**
635637
* Peek at the next token.
636-
* @returns string|number Next Token
638+
* @function Parser#peek
639+
* @memberOf module:php-parser
640+
* @returns {string|number} Next Token
637641
*/
638642
Parser.prototype.peek = function () {
639643
const lexerState = this.lexer.getState();

0 commit comments

Comments
 (0)