Commit graph

1857 commits

Author SHA1 Message Date
王文璐 9767fbba09 allow access protected member in this parameter context 2018-06-04 15:16:59 +08:00
Anders Hejlsberg 6f2001fb23 Add tests 2018-06-02 17:43:37 -07:00
Nathan Shively-Sanders d187de2076
Better JS container binding (#24367)
* Static assignments to class expressions work

* Bind static properties of functions too

Also update SymbolLinks in getTypeOfFuncClassEnumModule so that the
type gets cached correctly.

* Remove initializer handling:obj literals+type lookup

Also include a couple of improved baselines

* Fix 1-nested js containers:binding+cross-file merge

* Consolidate check into one utility

The utility is horrible and needs to change, but at least it's in one
place.

Next step is to make the utility like getDeclarationOfAlias, except
getDeclarationOfJSAlias.

* Defaulted assignments now (mostly) work

* Default assignment definitely work, and IIFEs kind of do

* n-nested undeclared containers now seem to work

Merging even seems to work ok.

* Handle prototype+prototype property assignments

Perhaps in the wrong way. I have an idea how to simplify them.

* Remove prototype special-case

1. It's not completely removed; the checker code in
getJavascriptClassType needs to be fixed, among other places.
2. I didn't actually remove the code so that it will be easier to see
what used to be there on Monday.

Regardless, the code will be much simpler and seems to be mostly
improved with very little work so far.

* Allow more merges+accept baselines

* Update more baselines

* Fix js initializer check in bindPropertyAssignment

* Fix codefixes

* Rest of strictNullChecks cleanup + other cleanup

1. Remove a few TODOs
2. Remove extraneous SymbolFlag
3. Simplify isSameDefaultedName

* Binder cleanup

* Checker cleanup

* Almost done with utilities cleanup

* Utilities cleanup

* Require js initializer to be (1) JS (2) initializer

Change getDeclarationOfJSInitializer to require that the provided js
initializer be in a javascript file, and that it is the initializer of
the retrieved declaration.

* Use getSymbolOfNode instead of accessing symbol directly

* Ugh. Start over with just test cases

* Handle additional cases in getTypeOfVariableOrParameterOrProperty

These are cases in a really embarrassing check, in which we admit that
the symbol flags steered us wrong and switch to
getTypeOfFuncClassEnumModule instead (which never asserts).

* Add test case for #24111

* Address PR comments
2018-05-31 11:41:26 -07:00
Nathan Shively-Sanders cdfa63aa40
Fix exported type resolution in commonjs (#24495)
* Fix resolution of exported types in commonjs

It is fine to resolve the types of exported classes in ES6:

```js
export class C {
}
var c = new C()
```

But not for commonjs exported classes:

```js
module.exports.C = class {
}
var c = new C() // should error
```

Fixes #24492

* All jsdoc type aliases are available locally in commonjs modules

* Check that location isSourceFile before commonJsModuleIndicator
2018-05-30 14:12:38 -07:00
Anders Hejlsberg a8a31ed508
Merge pull request #24439 from Microsoft/unknownType
New 'unknown' top type
2018-05-30 10:22:02 -07:00
Nathan Shively-Sanders 22cdff59e4
Better fix for bogus duplicate identifier in module exports (#24491) 2018-05-30 09:59:14 -07:00
Anders Hejlsberg e22a9d6fc1 Merge branch 'master' into unknownType 2018-05-30 07:45:10 -07:00
Anders Hejlsberg 577662de42 Update tests 2018-05-29 17:55:57 -07:00
Nathan Shively-Sanders 36c580378f
Fix duplicate identifier error with module.exports (#24466)
A bug in checkSpecialAssignment added bogus duplicate identifier errors
when using module.exports assignment to export a class. This commit
fixes that.
2018-05-29 14:29:48 -07:00
Nathan Shively-Sanders 15bfaf1cf6
Skip IntrinsicAttributes elaboration in JSX errors (#24461)
* Skip IntrinsicAttributes elaboration in JSX errors

Do not issue an error message for a source type that comes from JSX
attributes and a target type that is an intersection containing
IntrinsicAttributes or IntrinsicClassAttributes. This will make error
messages simpler and less confusing.

Note:
1. There will always be elaboration under the skipped message, so this
won't elide errors completely.
2. Rarely (once in the tests) the intersection type will have more that
one non-Intrinsic* member. However, these additional members don't
provide useful information either, so it's fine to skip them.

* Add test of IntrinsicAttributes error

* Fix indentation in test
2018-05-29 14:00:26 -07:00
Anders Hejlsberg c694ffe7a5 Update tests 2018-05-29 12:54:12 -07:00
Anders Hejlsberg 31c73defa7 Update tests 2018-05-27 15:44:01 -07:00
Anders Hejlsberg 73af0adcf0 Add tests 2018-05-27 10:37:59 -07:00
Mohamed Hegazy a7a68d9591 Merge branch 'fix-es5-export-class-name-object' of https://github.com/Kingwl/TypeScript into Kingwl-fix-es5-export-class-name-object 2018-05-25 15:45:31 -07:00
Nathan Shively-Sanders e250942d6a
Disallow nested object param syntax in callback tag (#24392)
* Callback tag:Disallow nested-object-param syntax

Previously this caused a crash in parsing. If/when we want to support
this syntax, we will need to fix this crash.

* Update baselines
2018-05-24 15:11:33 -07:00
kingwl cb2be44d02 fix export class declare with name object targeting es5 (#17494) 2018-05-24 18:16:38 +08:00
Mohamed Hegazy 10ac8b47e5
Merge pull request #22022 from Kingwl/enum-eval-div-zero
disallow nan and infinity in enum member
2018-05-23 15:32:35 -07:00
Andy 982c8d0af9
Add suggestion diagnostics for unused label and unreachable code (#24261)
* Add suggestion diagnostics for unused label and unreachable code

* Always error on unused left hand side of comma
2018-05-22 07:56:29 -07:00
Anders Hejlsberg 9d4096f9c4 Add tests 2018-05-21 16:43:55 -07:00
Nathan Shively-Sanders 6450490844
Fix jsdoc type resolution [merge to master] (#24204)
* Fix JSDoc type resolution

Breaks type parameter resolution that is looked up through prototype
methods, though. I need to fix that still.

* Check for prototype method assignments first

* Undo dedupe changes to getJSDocTags

* JS Type aliases can't refer to host type params

Previously, js type aliases (@typedef and @callback) could refer to
type paremeters defined in @template tags in a *different* jsdoc tag, as
long as both tags were hosted on the same signature.

* Reduce dedupe changes+update baseline

The only reason I had undone them was to merge successfully with an
older state of master.
2018-05-17 10:46:10 -07:00
Nathan Shively-Sanders aa7e2b0f07
Add callback tag, with type parameters (#23947)
* Add initial tests

* Add types

* Half of parsing (builds but does not pass tests)

* Parsing done; types are uglier; doesn't crash but doesn't pass

* Bind callback tag

Builds but tests still don't pass

* Only bind param tags inside callback tags

* Fix binding switch to only handle param tags once

* Checking is 1/3 done or so.

Now I'm going to go rename some members to be more uniform. I hate
unnnecessary conditionals.

* Rename typeExpression to type (for some jsdoc)

(maybe I'll rename more later)

* Rename the rest of typeExpressions

Turns out there is a constraint in services such that they all need to
be named the same.

* Few more checker changes

* Revert "Rename the rest of typeExpressions"

This reverts commit f41a96b24d.

* Revert "Rename typeExpression to type (for some jsdoc)"

This reverts commit 7d2233a00e.

* Finish undoing typeExpression rename

* Rename and improve getTypeParametersForAliasSymbol

Plus some other small fixes

* Core checking works, but is flabbergastingly messy

I'm serious.

* Callback return types work now

* Fix crash in services

* Make github diff smaller

* Try to make github diff even smaller

* Fix rename for callback tag

* Fix nav bar for callback tag

Also clean up some now-redundant code there to find the name of typedefs.

* Handle ooorder callback tags

Also get rid of redundant typedef name code *in the binder*. It's
everywhere!

* Add ooorder callback tag test

* Parse comments for typedef/callback+display param comments

* Always export callbacks

This requires almost no new code since it is basically the same as
typedefs

* Update baselines

* Fix support for nested namespaced callbacks

And add test

* Callbacks support type parameters

1. Haven't run it with all tests
2. Haven't tested typedef tags yet
3. Still allows shared symbols when on function or class declarations.

* Template tags are now bound correctly

* Test oorder template tags

It works.

* Parser cleanup

* Cleanup types and utilities

As much as possible, and not as much as I would like.

* Handle callback more often in services

* Cleanup of binder and checker

* More checker cleanup

* Remove TODOs and one more cleanup

* Support parameter-less callback tags

* Remove extra bind call on template type parameters

* Bind template tag containers

Doesn't quite work with typedefs, but that's because it's now stricter,
without the typedef fixes. I'm going to merge with jsdoc/callback and
see how it goes.

* Fix fourslash failures

* Stop pre-binding js type aliases

Next up, stop pre-binding js type parameters

* Further cleanup of delayed js type alias binding

* Stop prebinding template tags too

This gets rid of prebinding entirely

* Remove TODO

* Fix lint

* Finish merge with use-jsdoc-aliases

* Update callback tag baselines

* Rename getTypeParametersForAliasSymbol

The real fix is *probably* to rename Type.aliasTypeArguments to
aliasTypeParameters, but I want to make sure and then put it in a
separate PR.
2018-05-17 09:28:11 -07:00
Nathan Shively-Sanders 0ba8998c82
Fix stack overflow in merge symbol (#24134)
* JS initializers use original valueDecl, not mutated

target's valueDeclaration is set to the source's if it is not present.
This makes it incorrect to use getJSInitializerSymbol because it relies
on the symbol's valueDeclaration.

This fix just saves the original valueDeclaration before mutating and
uses that.

* Compare merged targetInitializer to target

Instead of the unmerged one

* Add test of stack overflow
2018-05-15 12:49:54 -07:00
王文璐 ad5a4c7097 add prependRange and move more variable declaration 2018-05-10 15:54:51 +08:00
Anders Hejlsberg 238177657f Add regression test 2018-05-08 09:42:21 -07:00
王文璐 a20470e005 disallow nan and infinity in enum member 2018-05-04 10:28:59 +08:00
Ron Buckton f67afa098f Unpatch vfs resolver and default lib rename 2018-05-03 14:18:50 -07:00
Ron Buckton d62a11ffc0 Merge branch 'master' into vfs 2018-05-01 18:58:31 -07:00
Anders Hejlsberg 4c933aef9a Check that test cases produce expected types 2018-05-01 13:05:49 -07:00
Anders Hejlsberg 59355cbfdb Add regression tests 2018-05-01 12:44:46 -07:00
Nathan Shively-Sanders 5ea4d3b2bb
No error for require, module.exports or exports in Javascript (#23743)
* No error for require

Still errors for module and exports, and require's type is now
incorreclty 'any'; I broke module resolution somehow. Needs
investigation.

* module/exports symbols+update isCommonJsRequire

Everything passes the tests but the code can be improved

* Update baselines

* Cleanup

* Update baselines of new tests

* Get rid of exports symbol

It wasn't doing anything anyway.
2018-04-30 15:47:59 -07:00
Nathan Shively-Sanders 7cda045d52
Always export typedefs (#23723)
* Always export typedefs

This actually just required deleting a check in declareModuleMembers
and checking for external AND commonjs modules in a couple of places.

However, while experimenting with this feature, I discovered that even
previously-exported typedefs would only be exported if they came after a
commonjs export node. So I added a commonjs check to the pass in the
parser. It will not catch nested module.exports, but it will catch
top-level assignments.

The new test tests both changes.

* Post-bind typedef instead of pre-checking for commonjs

* Duplicate identifier errors

* Fix class type reference resolution+update baselines

* Move to a type-based check for duplicate identifiers
2018-04-30 14:55:26 -07:00
Anders Hejlsberg 936444ad7b Add tests 2018-04-29 07:55:23 -07:00
Anders Hejlsberg 25d5952096
Merge pull request #23751 from Microsoft/reduceIntersectionTypes
Remove redundant primitive types from intersections
2018-04-28 11:42:56 -07:00
Daniel Rosenwasser 443c1c7965
Merge pull request #23327 from Microsoft/importDotMeta
Support 'import.meta'
2018-04-27 20:52:28 -07:00
Daniel Rosenwasser 12a3e39dca Specify ESNext module in test. 2018-04-27 18:17:49 -07:00
Anders Hejlsberg 38d1f7f0d2 Add tests 2018-04-27 16:50:09 -07:00
Anders Hejlsberg 6c28da328e
Merge pull request #23672 from Microsoft/intersectionWithUnionConstraint
Type relationships for intersections with union constraints
2018-04-27 15:53:00 -07:00
Anders Hejlsberg 5ecd03e8c0
Merge pull request #23660 from Microsoft/fixIndexTypeTargetConstraint
Fix constraint of 'keyof T[K]' in target position
2018-04-27 15:52:21 -07:00
Nathan Shively-Sanders 3631af6486
Remove readonly from object rest properties (#23746)
* Remove readonly from object rest properties

Works the same as removing it from object spread properties

* Fix bug number in test
2018-04-27 14:54:59 -07:00
Ron Buckton 4863d55d01 Merge branch 'master' into vfs 2018-04-27 14:03:42 -07:00
Nathan Shively-Sanders 1595f7fe83
Add prettier user test and fix associated crash (#23715)
* Add prettier and fix crash bug

Name resolution would crash when resolving a type name inside a
typedef's property tag.

* Update tsconfig and thefore prettier baseline
2018-04-26 14:03:18 -07:00
Nathan Shively-Sanders 1541599ea0
Check base type for special property declarations (#23671)
If the base type has a property by that name, add it to the list
constructor types to make it as authoritative as special assignments
found in the constructor.
2018-04-26 08:14:22 -07:00
Daniel Rosenwasser 9672116d8c Merge remote-tracking branch 'origin/master' into importDotMeta 2018-04-25 22:21:56 -07:00
Nathan Shively-Sanders b2bfccfce4
Prototype-property assignment:fix name resolution crash (#23680) 2018-04-25 13:59:40 -07:00
Anders Hejlsberg 8442a45bb6 Add additional tests 2018-04-25 11:03:25 -07:00
Anders Hejlsberg 50c7ff79d0 Add tests 2018-04-24 15:57:17 -07:00
Anders Hejlsberg ad4f83a281 Merge branch 'master' into fixIndexTypeTargetConstraint
# Conflicts:
#	tests/baselines/reference/keyofAndIndexedAccess.js
#	tests/baselines/reference/keyofAndIndexedAccess.symbols
#	tests/baselines/reference/keyofAndIndexedAccess.types
#	tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts
2018-04-24 11:08:08 -07:00
Anders Hejlsberg 57ef618120 Add regression test 2018-04-24 10:02:47 -07:00
Ron Buckton bb26ab5556 Merge branch 'master' into vfs 2018-04-23 22:48:48 -07:00
Anders Hejlsberg 7befd35009 Add tests 2018-04-23 21:09:49 -07:00