51 Commits

Author SHA1 Message Date
Ron Buckton
2c08affa0d
Merge pull request #39264 from microsoft/migrateMapsAndSets
Migrate maps and sets
2020-07-13 10:38:30 -07:00
Sheetal Nandi
8002473ea6
Add ClassExpression, FunctionExpression and ArrowFunction to check for cancellation token from classifier (#39557)
Fixes #35364
2020-07-10 13:39:09 -07:00
Ron Buckton
611b77f2e6 Migrate more places to use Map/Set 2020-06-26 10:15:53 -07:00
Ron Buckton
eb3645f16b
Refactor node factory API, use node factory in parser (#35282)
* Refactor node factory API, use node factory in parser

* Move UnparsedSource nodes to factory

* Make most Node properties read-only

* Make pos/end/parent and JSDoc 'comment' read-only

* Update function/constructor-type factories

* Remove treeStateObserver

* Simplify Debug.deprecate

* Remove unused factory methods, simplify lazy factory methods

* Fix base factory used for source file updates

* Update test baseline due to merge from master

* Rename factory methods to be more consistent (#39058)
2020-06-16 16:55:03 -07:00
kingwl
1d93db81cc Add logical assignment operator 2020-05-16 08:09:32 +08:00
Wenlu Wang
70399e146e
add support for Lift Template Literal Restriction (#23801)
* add support for Lift Template Literal Restriction

* rename file and improve comment and tests

* fix NoSubstitutionTemplateLiteral support

* extract tagged template and add more test

* avoid useless parameter

* fix incorrect return node if cannot transform

* accept baseline

* correctly baseline

* accept baseline

* fix merge break

* fix merge break

* inline rescan template head or no subsititution template

* update scan error

* add comment and fix lint

* refactor and fix lint

* avoid blank

* fix merge conflict

* fix again

* fix again

* use multiple target

* fix space lint

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-02-05 08:59:51 -08:00
Ben Lichtman
65561a89dd fix assertion condition 2019-10-18 09:18:16 -07:00
Ben Lichtman
fcdd5bd782 Add assertion when classification has unexpected length 2019-10-10 16:28:41 -07:00
Andrew Casey
87c905f423 Handle string literals in merge conflict regions
Check for undefined, like the other code paths in the same function.
2019-10-09 14:46:19 -07:00
Wenlu Wang
7c50bccec2 nullish coalescing commit (#32883)
* migrate nullish coalescing commit

* add more test case

* add branch type check test

* add more tests

* fix nullish precedence

* update public api

* add rescan question question token to fix regression

* update public api baseline

* Added tests that emit for nullish coalescing operator conforming with grammar restrictions when assertions are used.

* Fixed emit to hoist temporary variables (they previously went undeclared).
Added tests to ensure calls and property accesses are only called once.

* use not equal to null

* rename factory

* add grammar check

* fix more cases

* Fix handling of nullish coalescing oprator in expando objects.

* Fixed classifier to support ?? operator.

* update baseline

* accept baseline

* fix review

* update emitter and more testcase

* update control flow

* make linter happy

* update libs

* avoid unnecessary assert

* fix typooo

* Fixes for control-flow analysis
2019-09-30 15:33:50 -07:00
Alexander T
a98798fad6 fix eslint errors 2019-08-27 09:32:36 +03:00
Andrew Casey
e3690c3a07 Use the in operator 2019-08-23 13:10:32 -07:00
Andrew Casey
00d37268e8 Make triple-slash comment classification more restrictive
It was overly permissive and ended up making a mess of C#-style
comments:

`/// <summary>Text</summary>`

Now it checks the element name.  Attribute names remain unchecked.
2019-08-23 12:55:10 -07:00
Orta Therox
487e2ffe2a Merge master 2019-08-06 15:34:06 -04:00
Orta Therox
30aad9db8d Support more terminators for parsing jsdoc filepaths 2019-07-29 09:46:42 -04:00
Andrew Casey
9647506d8c Support classification of triple-slash references
Note: not restricted to the element and attribute names that actually
bind
2019-07-25 15:59:17 -07:00
Andy
772f6cdf48
Remove JSDocTag#atToken (#28376) 2018-11-06 09:54:23 -08:00
Caleb Sander
28e9ec497c Address review comments 2018-11-05 11:36:32 -08:00
Andy
e53e56cf82
Enable '--strictNullChecks' (#22088)
* Enable '--strictNullChecks'

* Fix API baselines

* Make sys.getEnvironmentVariable non-nullable

* make properties optional instead of using `| undefined` in thier type

* reportDiagnostics should be required

* Declare firstAccessor as non-nullable

* Make `some` a type guard

* Fix `getEnvironmentVariable` definition in tests

* Pretend transformFlags are always defined

* Fix one more use of sys.getEnvironmentVariable

* `requiredResponse` accepts undefined, remove assertions

* Mark optional properties as optional instead of using `| undefined`

* Mark optional properties as optional instead of using ` | undefined`

* Remove unnecessary null assertions

* Put the bang on the declaration instead of every use

* Make `createMapFromTemplate` require a parameter

* Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional

* Plumb through undefined in emitLsit and EmitExpressionList

* `ElementAccessExpression.argumentExpression` can not be `undefined`

* Add overloads for `writeTokenText`

* Make `shouldWriteSeparatingLineTerminator` argument non-nullable

* Make `synthesizedNodeStartsOnNewLine` argument required

* `PropertyAssignment.initializer` cannot be undefined

* Use one `!` at declaration site instead of on every use site

* Capture host in a constant and avoid null assertions

* Remove few more unused assertions

* Update baselines

* Use parameter defaults

* Update baselines

* Fix lint

* Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions

* Make Node#symbol and Type#symbol non-optional to reduce assertions

* Make `flags` non-nullable to reduce assertions

* Convert some asserts to type guards

* Make `isNonLocalAlias` a type guard

* Add overload for `getSymbolOfNode` for `Declaration`

* Some more `getSymbolOfNode` changes

* Push undefined suppression into `typeToTypeNodeHelper`

* `NodeBuilderContext.tracker` is never `undefined`

* use `Debug.assertDefined`

* Remove unnecessary tag

* Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 14:46:57 -07:00
Wesley Wigham
d82d35c7f5
Set startPos at EOF in jsdoc token scanner so node end positions for nodes terminated at EoF are right (#24184)
* Set startPos at EOF in jsdoc token scanner to node end positions for nodes terminated at EoF are right

* More complete nonwhitespace token check, fix syntactica jsdoc classifier

* Use loop and no nested lookahead

* Do thigns unrelated to the bug in the test

* Fix typo move return

* Patch up typedef end pos

* Fix indentation, make end pos target more obvious
2018-05-17 15:16:18 -07:00
Andy
ba8879d005
Prefer 'return Debug.fail()' over 'throw Debug.fail()' (#22092) 2018-03-02 10:44:06 -08:00
Andy
a564912d9a
Apply 'no-unnecessary-qualifier' lint rule (#22009) 2018-03-01 14:20:18 -08:00
Andy
dffa8b1329
Add a TriviaKind type to allow more specific types (#21237) 2018-01-18 09:44:30 -08:00
Andy
6f2ba15446
Start linting for double spaces (#20820)
* Start linting for double spaces

* Code review

* Fix cases that were excluded by countDoubleSpaces

* Remove extraneous closing parenthesis
2018-01-08 08:52:13 -08:00
Andy
53796eed59
Clean up lexical classifier (#20123) 2017-11-20 16:25:51 -08:00
Andy
74a44e09a7
Support semantic classification of alias (#20012) 2017-11-17 08:04:51 -08:00
Wesley Wigham
c1f2afd645 Add typedef declaration space, unify typedef name gathering (#18172)
* Add typedef declaration space, unify typedef name gathering, strengthen errorUnusedLocal

* Bonus round: make jsdoc presence way mroe typesafe

* Be exhaustive in nameForNamelessJSDocTypedef

* Remove nonrequired casts

* Replace more casts with guards

* Cannot be internal

* Debug.fail returns never, assert never no longer needs unreachable throw to satisfy checker

* Rename type

* Add replacement message as in 18287
2017-09-07 10:28:58 -07:00
Andy
ceae613e4c Add lint rule to check that Debug.assert calls do not eagerly interpolate strings (#17125)
* And lint rule to check that `Debug.assert` calls do not eagerly interpolate strings

* Use more specific 'assert' functions to avoid callbacks

* Respond to PR feedback
2017-08-08 07:56:14 -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
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
Andy
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
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
Andy
17578e8a5d Use Map<true> for sets (#16972) 2017-07-07 10:34:36 -07:00
Wesley Wigham
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
Andy
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
Andy
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
Kate Miháliková
e3e81b8673
Add support for diff3-style conflict 2017-05-30 08:03:58 +02:00
Andy Hanson
f94818da36 Also convert ClassificationTypeNames and CommandTypes/CommandNames 2017-05-22 10:40:59 -07:00
Andy Hanson
1cf765d664 Lint for fallthrough in switch 2017-03-27 15:09:00 -07:00
Andy Hanson
9e33585a80 Merge branch 'master' into map5 2016-12-27 12:56:05 -08:00
Kagami Sascha Rosylight
1f79741732 needless newline 2016-12-20 03:14:50 +09:00
Kagami Sascha Rosylight
2a941a7222 inline length 2016-12-20 03:12:35 +09:00
Kagami Sascha Rosylight
27a60e4580 fix linting errors 2016-12-18 15:44:54 +09:00
Andy Hanson
6b1cc8972d Use native maps when they're available 2016-12-08 06:40:31 -08:00
Andy Hanson
12f6dcefa1 Revert "Merge pull request #11354 from Microsoft/map4"
This reverts commit adfdae0dc47db5ad8248d26929a7b31cb895a539, reversing
changes made to aad663cebf6a89f7029af57d8cb6a0a011854978.
2016-10-27 15:50:21 -07:00
Andy Hanson
aadcbcc083 Use native maps when they're available 2016-10-06 13:29:18 -07:00
Andy Hanson
1879e28fd3 Add helper functions for detecting 'this' identifiers 2016-10-05 08:54:20 -07:00
Nathan Shively-Sanders
f8f244f68a Merge branch 'master' into new-jsdoc-parser 2016-09-15 11:53:04 -07:00
Ron Buckton
b90e3eec3c Fix classifier as well. 2016-09-08 16:20:18 -07:00
Andy Hanson
c3e63ee1f1 Move allocators.ts to services.ts, meaning.ts to utilities.ts, and transpile functions to a new file transpile.ts 2016-09-07 14:28:08 -07:00