Commit Graph

1532 Commits

Author SHA1 Message Date
Nathan Shively-Sanders
cc67ce1141 Property assignments in Typescript (#26368)
* Allow special property assignments in TS

But only for functions and constant variable declarations initialised with
functions.

This specifically excludes class declarations and class expressions,
which differs from Javascript. That's because Typescript supports
`static` properties, which are equivalent to property assignments to a
class.

* Improve contextual typing predicate

Don't think it's right yet, but probably closer?

* More fixes.

The code is still fantastically ugly, but everything works the way it
should.

Also update baselines, even where it is ill-advised.

* Cleanup

* Remove extra whitespace

* Some kind of fix to isAnyDeclarationName

It's not done yet.

Specifically, in TS:
Special property assignments are supposed to be declaration sites (but not all
top-level assignments), and I think I
got them to be. (But not sure).

In JS:
Special property assignments are supposed to be declaration sites (but not all
top-level assignments), and I'm pretty sure ALL top-level assignments
have been declaration sites for some time. This is incorrect, and
probably means the predicate needs to be the same for both dialects.

* Add fourslash and improve isAnyDeclarationName

Now JS behaves the same as TS.

* Cleanup from PR comments
2018-08-15 15:25:25 -07:00
Andy
62e6e6ae27 Remove special handling for JSDocPropertyLikeTag in getJSSpecialType (#26432)
* Remove special handling for JSDocPropertyLikeTag in getJSSpecialType

* Reduce nesting
2018-08-14 13:48:17 -07:00
Andy
cea4838972 Set rootDir in tsconfig-base.json (#26415) 2018-08-13 15:19:27 -07:00
Andy
ad63468ed5 noUnusedLocals: f(x = 1) does not use x (#26366) 2018-08-13 11:14:52 -07:00
Sheetal Nandi
c5b74db78b Merge pull request #26200 from Microsoft/watchWithStrict
Refresh semantic diagnostics when compiler options affecting semantic diagnostics generation changes
2018-08-10 16:15:37 -07:00
Andy
08f5edbd03 Treat NoSubstitutionTemplateLiteral like StringLiteral in more places (#26330)
* Treat NoSubstitutionTemplateLiteral like StringLiteral in more places

* Move isStringOrNumericLiteral closer to its only use
2018-08-10 16:00:08 -07:00
Andrew Casey
8ef7ceda6d Merge pull request #26289 from amcasey/LibSuggestions
Don't compute suggestion diagnostics for lib files
2018-08-10 15:59:40 -07:00
Sheetal Nandi
796302294f Review feedback 2018-08-10 14:44:44 -07:00
Andy
a73161e9d5 Don't store @template constraint in a TypeParameterDeclaration node (#26283)
* Don't store @template constraint in a TypeParameterDeclaration node

* Code review

* Update API
2018-08-09 17:39:15 -07:00
Wesley Wigham
fce3d9f34d Check the ambientness of a symbol name before attempting to trim it (#26312)
* Check the ambientness of a symbol name before attempting to trim it

* Use find instead of forEach, remember to also exclude global augmentations
2018-08-09 13:20:37 -07:00
Andrew Casey
daccc978a8 Don't compute suggestion diagnostics for lib files
The check applied to semantic diagnostics (and `checkSourceFile`) should
also apply to suggestion diagnostics.  Fixes assert.
2018-08-07 17:58:35 -07:00
Sheetal Nandi
4475d81b9c Add flags on commandLineOption to indicate strictFlag or option affecting semanticDiagnostics 2018-08-06 14:54:57 -07:00
Anders Hejlsberg
6a17f4d162 Merge branch 'master' into fixCircularReturnType
# Conflicts:
#	tests/baselines/reference/recursiveResolveDeclaredMembers.types
#	tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.types
2018-08-06 10:42:35 -07:00
Sheetal Nandi
d419968c0d Refresh semantic diagnostics when compiler options affecting semantic diagnostics generation changes
Fixes #26195
2018-08-03 16:27:25 -07:00
Anders Hejlsberg
e4443bb993 Properly catch and error on circular function return types 2018-08-03 14:03:30 -07:00
Andy
9c9f3e3cf9 importFixes: When one file redirects to another, consider both for global import specifiers (#25834)
* importFixes: When one file redirects to another, consider both for global import specifiers

* Add test for #26044

* Avoid a symlinked package globally importing itself (fixes another case of #26044)

* Compare to node_modules with getCanonicalFileName
2018-07-31 17:28:56 -07:00
Wesley Wigham
2edc47bc67 Fix decorated accessor emit (#26016) 2018-07-31 13:53:28 -07:00
Mohamed Hegazy
9e740deee8 Merge pull request #25965 from ajafff/expose-escapeleadingunderscores
expose escapeLeadingUnderscores
2018-07-30 12:05:33 -07:00
Nathan Shively-Sanders
25fb5419c0 Support the JSDoc @enum tag (#26021)
* Support the JSDoc @enum tag

`@enum` is used on a variable declaration with an object literal
initializer. It does a number of things:

1. The object literal has a closed set of properties, unlike other
object literals in Javascript.
2. The variable's name is resolvable as a type, but it just has the
declared type of the enum tag.
3. Each property's type must be assignable to the enum tag's declared type,
which can be any type.

For example,

```js
/** @enum {string} */
const Target = {
  START: "START",
  END: "END",
  MISTAKE: 0, // error 'number' is not assignable to 'string' -- see (3)
}

Target.THIS_IS_AN_ERROR; // See (1)
/** @type {Target} See (2) */
var target = Target.START;
```

* Fix lint, add new test case, update API baselines
2018-07-28 07:53:08 -07:00
Andy
644ceab02f Document ObjectLiteralElementLike (#26024) 2018-07-27 17:33:42 -07:00
Andy
d40d54984e Support deleting all unused type parameters in a list, and deleting @template tag (#25748)
* Support deleting all unused type parameters in a list, and deleting @template tag

* Support type parameter in 'infer'
2018-07-27 11:55:31 -07:00
Klaus Meinhardt
b65bbfd42d correctly resolve Symbol of destructuring shorthand intializer
Fixes: #21046
2018-07-26 14:37:52 +02:00
Klaus Meinhardt
b057bf9f01 expose escapeLeadingUnderscores
Fixes: #25343
2018-07-26 14:20:48 +02:00
Andy
e4d4b0ae4b Handle PropertyAssignment in getCommentOwnerInfo (#25911) 2018-07-24 17:43:46 -07:00
Andy
93722c8942 findAllReferences/rename: Search in all open projects (#25648)
* findAllReferences/rename: Search in all open projects

* Avoid needing a dummy location when location is unused

* Remove Program#getDeclarationEmitPath

* Only iterate over enabled projects
2018-07-20 16:53:59 -07:00
Mohamed Hegazy
2d0d655fea Merge pull request #25561 from ajafff/multiple-prologue-directives
handle multiple prologue directives
2018-07-11 11:38:01 -07:00
Andy
19993a5408 When import("foo") has module resolution error, error span should be "foo" (#25569)
* When `import("foo")` has module resolution error, error span should be "foo"

* Update more tests
2018-07-11 10:06:08 -07:00
Klaus Meinhardt
2a960011d7 Merge branch 'master' of github.com:Microsoft/TypeScript into multiple-prologue-directives 2018-07-11 18:47:23 +02:00
Klaus Meinhardt
0de903ea17 rename function 2018-07-11 18:43:58 +02:00
Andy
990d445bb6 In services, when overload resolution fails, create a union signature (2) (#25100) 2018-07-11 08:54:47 -07:00
Klaus Meinhardt
f9eb976319 handle multiple prologue directives
Fixes: #24689
2018-07-10 22:42:21 +02:00
Andy
1fc1495863 Increase span of unreachable code error (#25388)
* Increase span of unreachable code error

* Add a new diagnostic for each range of unreachable statements

* Update baselines
2018-07-10 11:45:16 -07:00
Ryan Cavanaugh
1b1ffe952b Use getEmitDeclarations instead of .declarations 2018-07-09 14:51:40 -07:00
Wesley Wigham
831be5d078 Introduce truncation into node builder and symbol display part writer (#24258)
* Introduce truncation into node builder and symbol display part writer

* Change default maxa truncation length to 240

* Fancy truncation + higher hard limit
2018-07-06 14:58:46 -07:00
Nathan Shively-Sanders
6589e867fe getJSDocReturnType gets return type from @type tags (#25486)
* get return type from `@type` tags

Previously, getJSDocReturnType did not check the `@type` tag for a type
node that has a return type. Now it does.

* Improve doc comment of getJSDocReturnType

* More type predicates in type guards!

* Update API baselines with new documentation (?!)
2018-07-06 10:46:43 -07:00
Nathan Shively-Sanders
1785041b8c make getEffectiveTypeParameterDeclarations public (#25472) 2018-07-06 10:26:53 -07:00
Mohamed Hegazy
8911c19f4f Merge pull request #25313 from github-john-doe/typo
Typo
2018-07-05 11:43:12 -07:00
Andy
064ecd449e Support code-fix-all for importFixes (#25137)
* Support code-fix-all for importFixes

* Change description

* Update API (#25283)
2018-07-03 15:19:15 -07:00
Andy
efc1b7df08 More thoroughly test navigateTo (#25239)
* More thoroughly test navigateTo

* Fix #25233 and #25237

* Update API (#24966)
2018-07-02 19:25:27 -07:00
Wesley Wigham
7084e6cf47 Adds related spans and error grouping for duplicate identifier errors (#25328)
* Adds related spans and error grouping for duplicate identifier errors

* Trim trailing whitespace

* Record related info in error baselines

* Make error more whimsical
2018-07-02 10:47:52 -07:00
Wesley Wigham
656f356495 Remove deprecated escapeidentifier and unescapeidentifier functions (#25333) 2018-07-02 10:47:24 -07:00
Andy
a1746d4cfe Use helper functions in a few more places (#21308)
* Use helper functions in a few more places

* Fix typo

* Update API (#24966)
2018-06-29 20:07:42 -07:00
Andy
48d31eddc8 Split isConst into isVarConst and isEnumConst (#25312) 2018-06-29 16:47:11 -07:00
John Doe
6d01001125 Assignement -> Assignment 2018-06-28 19:03:58 -07:00
Nathan Shively-Sanders
5c2eeb20b1 Destructuring declaration prefers type annotation type (#25282)
* Destructuring declaration prefers type annotation type

Previously, getTypeForBindingElement would always union the declarations type and
the type of the default initializer. Now, if the declaration has a type
annotation, it does not union with the initializer type. The type
annotation's type is the one used.

* Small cleanup in parentDeclarationHasTypeAnnotation

* Refactoring based on PR comments

* Combine getCombined*Flags into a single helper function

Retain the individual functions since they are used a lot.

* Remove unneeded temp
2018-06-28 10:41:38 -07:00
Andy
fd8b7f3da5 Remove redundant checks in getNameOfDeclaration (#25244) 2018-06-27 13:56:31 -07:00
Andy
e8e80d2bbd Don't crash on property access with type (#25170)
* Don't crash on property access with type

* Move test
2018-06-25 11:25:52 -07:00
Andy
806a661be3 Add refactor to convert named to default export and back (#24878)
* Add refactor to convert named to default export and back

* Support ambient module

* Handle declaration kinds that can't be default-exported

* Update API (#24966)
2018-06-25 10:34:24 -07:00
Andy
e3e4c5dd2e getEditsForFileRename: For directory rename, preserve casing of suffix (#24975) 2018-06-21 11:46:13 -07:00
Nathan Shively-Sanders
43d0794ba3 Fix crash when binding jsdoc-style inner namepaths (#25106)
* getDeclarationIdentifier handles undefined name

getNameOfDeclaration actually doesn't handle all declarations, only
those that produce names that could be reasonably used as an identifier.
Until now, getDeclarationIdentifier assumed that getNameOfDeclaration
always returned a name. This caused crashes whenever we tried to get the
name of something like a Constructor.

* Add test and baselines

* getNameOfDeclaration can return undefined

This requires all callers to handle it, which turns out now to be too
disruptive.

* Fix lint
2018-06-21 10:01:39 -07:00