Commit Graph
1361 Commits
Author SHA1 Message Date
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
AndyandGitHub 0d36d0e39f Support completions for qualified names in JSDoc (#16380)
* Support completions for qualified names in JSDoc

* Fix typo
2017-06-08 17:21:36 -07:00
Daniel Rosenwasser 86e54ac787 Correct pluralization of 'Contain' to 'Contains', made the nodeflag internal. 2017-06-08 16:00:38 -07:00
Kanchalai Tanglertsampan 58aa0f3f76 Copy PossiblyContainDynamicImport from old source file to new one 2017-06-08 14:30:56 -07:00
AndyandGitHub abb9681248 Support completions for JSDoc @param tag names (#16299)
* Support completions for JSDoc @param tag names

* Undo change to finishNode

* Don't include trailing whitespace in @param range; instead, specialize getJsDocTagAtPosition
2017-06-07 12:28:52 -07:00
Ron Buckton 8cb5333791 Verify JS function is constructor 2017-06-06 13:33:19 -07:00
Sheetal Nandi 48189c883f Merge branch 'master' into ownJsonParsing 2017-06-06 11:03:21 -07:00
Yui T fe4fec5220 Fix breaking tests 2017-06-05 17:23:33 -07:00
Yui T b9017795a0 Revert "Revert "[Master] wip-dynamic import" (#16264)"
This reverts commit ccc60c8b3b.
2017-06-05 17:16:29 -07:00
Sheetal Nandi c4ad151a46 Merge branch 'master' into ownJsonParsing 2017-06-05 17:01:09 -07:00
Mohamed HegazyandGitHub ccc60c8b3b Revert "[Master] wip-dynamic import" (#16264) 2017-06-05 10:49:20 -07:00
Sheetal Nandi d680720f6d Merge branch 'master' into ownJsonParsing 2017-06-05 10:28:23 -07:00
Yui T 2f476bf22f Merge branch 'master' into master-dynamicImport 2017-06-02 09:10:20 -07:00
Yui T e6d7327c3f Address PR: error message, fix capitalization, only allow functionLikeDeclaration and ImportCall for create Promise, use fall through comment 2017-06-01 23:21:59 -07:00
Charles Pierce 556e268bd0 #15943 #15981 Update special cases for await / yield parsing 2017-06-01 20:37:52 -07:00
Sheetal Nandi 8f4f6c565e Merge branch 'master' into ownJsonParsing 2017-06-01 10:43:41 -07:00
Nathan Shively-SandersandGitHub 928da675ac Merge pull request #16156 from Microsoft/report-jsdoc-syntax-errors
Report JSDoc syntax errors
2017-05-31 16:21:32 -07:00
Nathan Shively-Sanders 2dd6627022 Report jsdoc syntax errors when checkJs is on 2017-05-30 13:32:46 -07:00
Sheetal Nandi 8d771ca044 Merge branch 'master' into ownJsonParsing 2017-05-30 13:03:23 -07:00
Kanchalai Tanglertsampan 27078f995e Merge branch 'master' into master-fix16092 2017-05-30 08:25:53 -07:00
YuiandGitHub f938caf8c8 Merge pull request #16134 from Microsoft/master-fix15250
[Master] Fix 15250 - treat "object" and "Object" the same in JSDoc type def
2017-05-30 08:07:39 -07:00
Yui T 10eae61aca Handle "object" as "Object" in JSDoc type expression 2017-05-29 21:47:39 -07:00
Yui T 4838eff2d7 "function" without followed by "(" should be considered as Global function type 2017-05-29 20:37:01 -07:00
Yui T fe838bab2d Parse ts-style property tag 2017-05-27 19:10:53 -07:00
Yui T 9c102461d9 Rename parameterName to name 2017-05-26 19:08:08 -07:00
Yui T d68038ad28 Support bracket for optional property 2017-05-25 22:34:48 -07:00