Commit Graph
1386 Commits
Author SHA1 Message Date
Nathan Shively-Sanders c81a941303 Refactor parsePostfixTypeOrHigher
Inline the switch, but extract the function that creates jsdoc nodes.
2017-09-07 13:45:59 -07:00
Nathan Shively-Sanders 68ea88402a Make getPostfixSyntaxKind easier to read 2017-09-01 10:52:48 -07:00
Nathan Shively-Sanders ffe49428d8 Parse postfix [] ! ? at the same precedence level
This combines parseArrayType and parseJSDocPostfixType into
parsePostfixType.
2017-08-30 08:39:28 -07:00
Nathan Shively-Sanders c746477d81 JSDoc:... binds tighter than *n* postfix jsdocs
1. Previously ...X? mistakenly parsed as ...(X?) instead of (...X)?
2. Previously X?!?!? mistakenly failed to parse the postfix tokens
   ? ! ? ! ? at the same level of precedence.

The fix is to
1. Make ... parsing call parseNonArrayType instead of parseType.
2. Make postfix jsdoc parsing parse in a loop instead of only parsing
one token.
2017-08-29 12:59:34 -07:00
Nathan Shively-Sanders 71c5b1b354 Parsing:Allow QuestionToken as start of type 2017-08-23 15:00:12 -07:00
AndyandGitHub b3f3f336ad Use hasModifier and hasModifiers helper functions (#17724) 2017-08-11 07:15:15 -07:00
AndyandGitHub 08fbcd8b80 Fix many no-object-literal-type-assertion lint errors (#17278)
* Fix many no-object-literal-type-assertion lint errors

* Simple fixes

* Use a union for FlowNode

* PR feedback and remove remaining `id()` uses

* Use a union for CodeBlock

* Discriminate CodeBlock by CodeBlockKind
2017-08-10 12:52:15 -07:00
Ron BucktonandGitHub 75c8ecb2f1 Merge pull request #17517 from tinganho/IgnoredCatchParameter
Ignored catch parameter
2017-08-08 16:15:18 -07:00
Wesley WighamandGitHub a453eff575 Restrict parsing of literals and their expressions a _lot_ more (#17628) 2017-08-07 09:16:12 -07:00
Wesley WighamandGitHub c06a30ae68 JSDoc Instantiation Fixes (#17553)
* Fix #17383 - issue an error when jsdoc attempts to instantiate a builtin as a generic

* Fix comment

* Fix #17377 - only get type parameters from reference target if the type is a reference

* Fix #17525 - Add SyntaxKind.AsteriskToken to isStartOfType
2017-08-02 13:55:14 -07:00
Daniel RosenwasserandGitHub 3da1a53d7e Amend comment about explicitly setting catch clause variables to 'undefined'. 2017-08-02 12:50:04 -07:00
Tingan Ho d5c24f3cd3 Addresses CR comment 2017-08-02 20:13:43 +02:00
Tingan Ho b917eb0225 Adds optional catch parameter into the compiler 2017-07-30 23:26:47 +02:00
AndyandGitHub 70e5c6b1e5 Add some missing | undefined in parser.ts (#17407) 2017-07-27 11:25:48 -07:00
AndyandGitHub 977d907417 createMissingNode: Only assign '.text' or '.escapedText' on nodes of the correct type (#17439)
* createMissingNode: Only assign '.text' or '.escapedText' on nodes of the correct type

* Revert to having only createMissingNode
2017-07-27 10:34:08 -07:00
Wesley WighamandGitHub b9fe9964d2 Change isStartOfParameter to be more general (#17431) 2017-07-26 15:21:21 -07:00
Nathan Shively-Sanders 9fd90e7e02 Merge branch 'master' into jsdoc-param-type-literals 2017-07-26 11:09:24 -07:00
Nathan Shively-Sanders fde4c188ac Address more PR comments 2017-07-26 10:57:29 -07:00
Wesley WighamandGitHub 5b77ef8b4d Fix infinite loop in jsdoc parsing (#17420)
* Test case

* Move parameter fix to apply to jsdoc (and all lists)

* Inline function, generalize comment
2017-07-26 10:12:59 -07:00
Nathan Shively-Sanders c55a043767 Address PR comments from Andy
I'll take a look at Wesley's next and see if those require any changes.
2017-07-25 14:14:12 -07:00
AndyandGitHub eadd084c82 Add 'name' property to Identifier (#17329)
* Add 'name' property to Identifier

* Rename to unescapedText

* Rename 'id.text' to 'id.escapedText'

* Rename 'id.unescapedText' to 'id.text'

* Make escapeIdentifier and unescapeIdentifier do nothing
2017-07-25 13:16:34 -07:00
Wesley Wigham 98d5830831 Use scanner position instead of node members 2017-07-24 17:51:35 -07:00
Wesley Wigham 06beee1cc8 Much simpler fix, rolls in really old fix, removed unused comment 2017-07-24 15:16:21 -07:00
Wesley Wigham e7bf44e820 Fix for loop which retains jsdoc behaviors 2017-07-21 17:20:56 -07:00
Nathan Shively-Sanders 59961394cb @param parsing:const enum to improve readability 2017-07-21 15:07:20 -07:00
Nathan Shively-Sanders 7ff91c1e1c Parse jsdoc type literals in params
Now Typescript supports the creation of anonymous types using successive
`@param` lines in JSDoc:

```js
/**
 * @param {object} o - has a string and a number
 * @param {string} o.s - the string
 * @param {number} o.n - the number
 */
function f(o) { return o.s.length + o.n; }
```

This is equivalent to the Typescript syntax `{ s: string, n: number }`,
but it allows per-property documentation, even for types that only need
to be used in one place. (`@typedef` can be used for reusable types.)

If the type of the initial `@param` is `{object[]}`, then the resulting
type is an array of the specified anonymous type:

```js
/**
 * @param {Object[]} os - has a string and a number
 * @param {string} os[].s - the string
 * @param {number} os[].n - the number
 */
function f(os) { return os[0].s; }
```

Finally, nested anonymous types can be created by nesting the pattern:

```js
/**
 * @param {Object[]} os - has a string and a number
 * @param {string} os[].s - the string
 * @param {object} os[].nested - it's nested because of the object type
 * @param {number} os[].nested.length - it's a number
 */
function f(os) { return os[0].nested.length; }
```

Implementation notes:

1. I refactored JSDocParameterTag and JSDocPropertyTag to
JSDocPropertyLikeTag and modified its parsing to be more succinct. These
changes make the overall change easier to read but are not strictly
required.
2. parseJSDocEntityName accepts postfix[] as in `os[].nested.length`,
but it doesn't check that usages are correct. Such checking would be
easy to add but tedious and low-value.
3. `@typedef` doesn't support nested `@property` tags, but does support
`object[]` types. This is mostly a practical decision, backed up by the
fact that usejsdoc.org doesn't document nested types for `@typedef`.
2017-07-21 14:04:14 -07:00
AndyandGitHub 194c2bc2ca Make NodeArray readonly (#17213)
* Make NodeArray readonly

* Fix bug: use emptyArray instead of undefined

* Fix bug: Don't expose MutableNodeArray

* Undo trailing whitespace changes
2017-07-18 10:38:21 -07:00
Wesley WighamandGitHub 8a1cd33451 Use jsdoc casts (#17251)
* Allow jsdoc casts of parenthesized expressions

* Feedback from #17211
2017-07-17 23:39:20 -07:00
Nathan Shively-Sanders 172db13306 Parse more types in JSDoc function() syntax
Also some cleanup from PR comments
2017-07-14 14:34:32 -07:00
Nathan Shively-Sanders bdc3f1f3f7 Address more PR comments 2017-07-14 13:29:44 -07:00
Nathan Shively-Sanders 40ae42221e Better JSDoc generic errors and faster isInJSDoc 2017-07-14 11:07:20 -07:00
Nathan Shively-Sanders 6e861fd3e6 Remove JSDocConstructor/ThisType and just use named parameters 2017-07-14 09:36:12 -07:00
Nathan Shively-Sanders bc69c7e6d1 Parse JSDoc types using the normal TS parser
This means that JSDoc types can include the full range of Typescript
types now. It also means that Typescript annotations can include JSDoc
types. This is disallowed with a new error, however. But Typescript can
still give the correct types to JSDoc that shows up in .ts files by
mistake. This can easily happen, for example with types like

```ts
var x: number? = null;
var y: ?string = null;
var z: function(string,string): string = (s,t) => s + t;

// less likely to show up, but still understood.
var ka: ? = 1;
```

In the future, I will add a quick fix to convert these into the correct
types.

Fixes #16550
2017-07-13 11:27:50 -07:00
Nathan Shively-Sanders 1b1f257dbf Rename SignatureFlags enum and improve its usage
As requested in the PR comments
2017-07-11 14:49:47 -07:00
Nathan Shively-Sanders 8856ddfd15 Make enum private and fix fillSignature predicate 2017-07-11 10:45:25 -07:00
Nathan Shively-Sanders b6ad43d4a5 Better error for wrong return (: vs =>) in types
It's very ambiguous in expression position, so impossible to give a
better message from the parser. For example:

let f = (x: number) => number => x + 1;
                    ~~
                    Should be ':'

But the parser doesn't know that 'number' isn't an expression now.
2017-07-11 10:08:42 -07:00
Nathan Shively-Sanders fcc9823ac7 Switch fillSignature boolean params to single enum 2017-07-11 09:51:18 -07:00
Anders HejlsbergandGitHub b866cd4969 Merge pull request #16952 from Microsoft/optimizeForEachChild
Optimize forEachChild function
2017-07-07 16:18:00 -10:00
Wesley WighamandGitHub 4e6b2f3c93 Created a branded type for identifier-escaped strings (#16915)
* Created a branded type for escaped strings

Then flowed it throughout the compiler, finding and fixing a handful of
bugs relating to underscore-prefixed identifiers in the process.
Includes a test for two cases noticed - diagnostics from conflicting
symbols from export *'s, and enum with underscore prefixed member emit.

* Correctly double underscores WRT mapped types

* Add fourslash tests for other fixed issues

* use function call over cast

* Update forEachEntry type accuracy

* Just use escaped names for ActiveLabel

* Remove casts from getPropertyNameForPropertyNameNode

* This pattern has occurred a few times, could use a helper function.

* Remove duplicated helper

* Remove unneeded check, use helper

* Identifiers list is no longer escaped strings

* Extract repeated string-getting code into helper

* Rename type and associated functions

* Make getName() return UnderscoreEscapedString, add getUnescapedName()

* Add list of internal symbol names to escaped string type to cut back on casting

* Remove outdated comments

* Reassign interned values to nodes, just in case

* Swap to string enum

* Add deprecated aliases to escapeIdentifier and unescapeIdentifier

* Add temp var

* Remove unsafe casts

* Rename escaped string type as per @sandersn's suggestion, fix string enum usages

* Reorganize double underscore tests

* Remove jfreeman from TODO

* Remove unneeded parenthesis
2017-07-06 14:45:50 -07:00
Anders Hejlsberg 24a6a087f5 Add early bail out for token nodes 2017-06-23 08:31:48 -10:00
Anders Hejlsberg fd1e5ab6ed Simplify forEachChild 2017-06-22 08:55:18 -10:00
YuiandGitHub 47c1563649 Merge pull request #16544 from Microsoft/master-fixIncrementalParsingWithDynamicImport
[Master] wip - fix incremental parsing with dynamic import
2017-06-19 16:44:47 -07:00
Sheetal Nandi 09f0b3471a Merge branch 'master' into ownJsonParsing 2017-06-15 09:59:37 -07:00
Daniel RosenwasserandGitHub 5b12a04965 Merge pull request #16213 from charlespierce/await_yield_literals
Update special cases for await / yield expression parsing
2017-06-15 00:39:57 -07:00
Yui T 1636fbc966 Wip-fix incremental parsing 2017-06-14 17:13:35 -07:00
TravCavandMohamed Hegazy 9611e58670 combined logic in parseParameterOrPropertyTag (#16481) 2017-06-13 16:30:36 -07:00
Nathan Shively-Sanders 6d3e15f0ee Add JSDoc to EOF token to catch missed @typedefs 2017-06-13 10:32:25 -07:00
AndyandMohamed Hegazy fbcddb61e2 Don't bind JSDoc namespace in a TS file (#16416) 2017-06-12 14:35:35 -07:00
AndyandGitHub 09321b3834 Convert Extension to a string enum (#16425) 2017-06-09 19:32:44 -07:00
Daniel RosenwasserandGitHub 025fa87b8c Merge pull request #16382 from Microsoft/ContainsMaster
[Master] Rename & internalize PossiblyContainsDynamicImport
2017-06-08 23:57:01 -07:00