Commit graph

2511 commits

Author SHA1 Message Date
Nathan Shively-Sanders d371ae770d
No this-property assignments in TS (#40009)
* No this-property assignments in TS

Even when `this` is aliased, which I mistakenly allowed in #39908.

* remove errant file
2020-08-11 15:46:49 -07:00
Wenlu Wang a80f60c6d6
fix export * as default syntax (#39803)
* fix export * as default syntax

* update comments
2020-08-10 16:56:45 -07:00
Nathan Shively-Sanders 1ec71f0e0c
Bind alias ThisProperty assignment declarations (#39908)
* Bind alias ThisProperty assignment declarations

This is a quick prototype that does the wrong thing at the wrong time
with the wrong technique.

* Preliminary checker handling for aliases

Duplicative and untested, but I think I updated all the places that need
updating.

* new is error; old one should not have been removed

* I don't even know what's happening with this test

* cleanup and testing in the checker

* binder: use lookupSymbolForNameWorker instead of mutable

This should have about the same behaviour and is much easier to
understand.

Also refactor common code a bit.

* Shorter name of lookupSymbolForName

Once upon a time there was a parent/worker function, but now it's just a
single function again. No need for the -Worker suffix.

* remove oodate comment

* fix switch-case-break lint

* Refactor and move functions

* Rename and improve type of getContextualTypeForAssignmentDeclaration
2020-08-10 16:45:55 -07:00
Wesley Wigham 94989789df
In JS declaration emit, move imports painted in nested contexts to the root private context (#39818)
* In JS declaration emit, move imports painted in nested contexts to the root private context

* Add test for nathan
2020-07-31 18:25:37 -07:00
Ron Buckton 32934a9989
Merge pull request #39824 from microsoft/fix35484
Allow assignments to a narrowable reference to be considered narrowable
2020-07-30 15:27:34 -04:00
Andrew Branch 7119e2b74f
The iteration type of overloaded iterator signatures derives from the intersection of their return types (#39722) 2020-07-30 11:37:04 -07:00
Ron Buckton b9db6413bf Allow assignments to a narrowable reference to be considered narrowable 2020-07-29 16:37:25 -07:00
Nathan Shively-Sanders 9b2d487392
Fix this-parameter emit for JSDocFunction types (#39814)
* Fix this parameter emit for JSDocFunction types

Previously, parameters with names that were not `new` were treated like
rest parameters. This is incorrect: parameters with the name `this`
should emit a `this` parameter.

Fixes #38550

* ❤️ quote style
2020-07-29 14:11:59 -07:00
Andrew Branch 1f1521c2f1
Undo accidental change from #39772 (#39779)
* Undo accidental change

* Delete test
2020-07-27 16:55:59 -07:00
Andrew Branch 68ba670467
Add contextual type for generator return type (#39772)
* WIP

* Add contextual type for generator return type
2020-07-27 15:14:47 -07:00
Anders Hejlsberg c5d21e7987
Lower priority for speculative variadic tuple inferences (#39723)
* Inference to [...T, X?] has lower priority than inference to [...T, X]

* Update tests

* Accept new API baselines
2020-07-24 15:00:53 -07:00
Song 8a05707559
Fix 31995: make cached key more precise to avoid returning wrong cached value. (#39670)
* fix 31995

* revert useless change only for debug.

* add test
2020-07-22 12:26:17 -04:00
Anders Hejlsberg db79030410
Support variadic tuple inference from trailing optional to non-optional (#39614)
* Permit variadic tuple inference from trailing optional to non-optional

* Add tests
2020-07-15 17:46:48 -07:00
Andrew Branch dd2fc86f2b
Don’t give all instantiated signatures in JS strict arity (#39606) 2020-07-14 18:56:50 -07:00
Ron Buckton 5ad8532a11 Merge branch 'master' into fix37113
# Conflicts:
#	src/compiler/transformers/module/module.ts
2020-07-13 11:13:35 -07:00
Andrew Branch 583bd92bc4
Don’t create expando declarations on alias symbols (#39558)
* Don’t create expando declarations on alias symbols

* Update other baseline

* Fix brace nesting refactor mistake
2020-07-13 10:05:48 -07:00
Nathan Shively-Sanders 3b107fec3b
Fix @param type parameter lookup (#39532)
Previously, getObjectTypeInstantiation had special-case code to look up
type parameters for `@param` as if they were in the parameter location.

This should occur in the main lookup loop of `getOuterTypeParameters`,
however. The current code only runs once, which is not sufficient, and
it also jumps to the parameter for any type contained in a `@param`,
which skips type parameters that occur in the tag itself.
2020-07-10 08:42:25 -07:00
Wesley Wigham dd2b2447d0
Add regression test for #38834 (#39479) 2020-07-08 13:32:15 -07:00
Nathan Shively-Sanders 53a756ea63
Type this in more constructor functions (#39447)
* Type `this` in more constructor functions

Previously,  `this: this` in constructor functions only when there was
an explicit `@constructor` tag on the function. Now, `this: this` for
any function that's known to be a constructor function.

This improves completions inside constructor functions; also note that
previously the compiler *did* type `this: this` inside methods of constructor
functions, so this fix makes us more consistent. This is reflected in
the large number of baselines that improve.

The fix is a simple switch to `isJSConstructor`, which is the standard
way to detect constructor functions. I'm not sure why the original PR
didn't use this method.

I remember discussing this limitation in the original bug, #25979, and
I guess I decided that it made sense. But I was heavily primed by the bug's
framing of the problem in terms of `noImplicitThis`, which *should*
require an explicit `@constructor` tag.

With better typing comes better detection of `@readonly` assignment; I
had to fix the readonly detection code to use `isJSConstructor` as well.

* Remove `Add @class tag` fix for noImplicitThis.

The new rules mean that it never applies. It's possible that it should
apply to functions like

```js
function f() {
  this.init()
}
```

In which `init` is never defined, but I think this program is incomplete
enough that not offering the fix is fine.

* Fix precedence of `@this`

Previously, both `@class` and `@this` in a jsdoc would cause the `@this`
annotation to be ignored. This became a worse problem with this PR,
because `this` is correctly typed even without the annotation.

This commit makes sure that `@this` is checked first and used if
present.
2020-07-08 08:44:17 -07:00
Ron Buckton 5c5f180f8e Fix namespace import/export helper usage 2020-07-07 17:36:59 -07:00
Anders Hejlsberg 8c6b85835f
Properly handle rest parameters in function declarations with @type annotations (#39473)
* Properly handle rest parameters in function declarations with @type annotations

* Add tests
2020-07-07 16:35:37 -07:00
Wesley Wigham d2b32b422f
Ensure type/namespaceish statics are included in the list of namespace merge members (#38920)
* Ensure type/namespaceish statics are included in the list of namespace merge members

* Simplit into two lines

* Update baseline post-merge
2020-07-07 16:28:09 -07:00
Ron Buckton b100680a3e
Fix for relating covered discriminants in unions (#39393) 2020-07-07 13:11:55 -07:00
Nathan Shively-Sanders 9a65658b28
Parse *= separately in types (#39457)
* Parse *= separately in types

Previously, when the scanner produced `*=` as a single token, the type
parser ran special-case code to produce an "optional all type", which
only makes sense when the `=` really should be attached to the `*`. This
is often not the case.

The correct solution, which I missed when I first wrote this code, is to
have the scanner go back and produce a separate `=` token, which is what
this PR does.

* add test from #38551

* we ❤️ semicolons
2020-07-07 08:30:42 -07:00
Nathan Shively-Sanders 0d84f210b7
In JS, assignment to void 0 isn't a declaration (#39452)
Previously, property assignments with `void 0` initialisers were treated
like any other values. But this causes us to choke when checking our own
commonjs emit. This is something that happens by mistake a fair amount,
so this PR goes back to treating these assignments as normal
assignments.

This should allow us to check our own emit in loose cases without
harming other code bases, since `void 0` is rarely written by hand.

Note that other errors still happen: noImplicitAny forbids
accessing undeclared properties on object literals, and strictNullChecks
forbids assigning `undefined` to properties with a different type.
However, this change is enough to unblock compilation with
`strictNullChecks: false`.
2020-07-06 14:00:12 -07:00
Ron Buckton 652a1c5950
Emit fallback for decorator metadata for type only imports (#39337) 2020-07-02 11:39:27 -07:00
Ron Buckton 8eba362a01 Fix for relating covered discriminants in unions 2020-07-02 11:09:14 -07:00
Anders Hejlsberg 784396ce95
Infer implied arity before inferring from 'this' argument (#39328)
* Infer implied arity before inferring from 'this' argument

* Add regression test
2020-06-29 17:38:41 -07:00
Anders Hejlsberg b448540644
No speculative inferences for variadic tuples (#39281)
* No speculative inferences to types like [...T, U?]

* Add tests
2020-06-29 15:24:32 -07:00
Andrew Branch 58ed610ef1
Allow distinct string enum members with identical property names to form unions in mapped types (#39101) 2020-06-29 10:08:17 -07:00
Wenlu Wang 6b4d0bff40
Avoid effect of element access expression (#39174)
* Avoid effect of element access expression

* Avoid unnecessary copy

* Add more tests
2020-06-25 17:38:05 -07:00
Anders Hejlsberg ee4aee0531
Handle 'keyof' for generic tuple types (#39218)
* Handle keyof T where T is generic tuple type

* Add tests

* Accept new baselines

* Address CR feedback

* Accept new baselines
2020-06-25 13:49:20 -07:00
Anders Hejlsberg 8df85b5cae
Disable unsound T[K] rule in subtype relations (#39249)
* Disable unsound T[K] rule in subtype relations

* Add test
2020-06-25 10:22:48 -07:00
Ron Buckton 0b1d4a9c96
Leverage syntax cursor as part of reparse (#39216) 2020-06-23 17:32:58 -07:00
Anders Hejlsberg d4792062bf
Variadic tuple types (#39094)
* Initial implementation of variadic tuple types

* Accept new baselines

* Handle variadic elements in tuple type inference

* Special case inference between tuples with matching structure

* Restore check that rest element is last element

* Handle variadic tuples in relationship checking

* Accept new baselines

* Infer readonly constraints when inferring from readonly tuples

* Fix lint issues

* T assignable to readonly [...T] and [...T] assignable to T

* Consistent tuple normalization

* Create variadic tuple types from array literal expressions

* Accept new baselines

* Array literals have tuple types when contextual type is readonly

* Accept new baselines

* Optional elements before required elements become required elements

* Update logic for rest parameters and spread arguments

* Revert special case of contextual readonly array type

* Accept new baselines

* Fix lint issue

* Switch entirely to createTupleType based on element flags

* Don't infer readonly tuple types when inferring to variadic elements

* Handle mapped types applied to generic tuple types

* Handle constraint of indexed access type with generic tuple type

* Accept new baselines

* Address CR feedback

* Simplify indexed access types involving generic tuple types

* Propagate checkMode into getSpreadArgumentType

* Guard against missing globalArrayType

* Inference to [...T, ...U] based on implied arity of T

* Accept new baselines

* Add tests

* Emit .d.ts from tests

* Address CR feedback
2020-06-22 18:35:43 -07:00
Jack Williams fd0ad2985b
Minor fix for assertion predicates (#38710) 2020-06-20 18:27:51 -07:00
Ron Buckton fe33e61823
Reparse top level 'await' in modules (#39084)
* Reparse top-level 'await' in modules

* Add more tests and additional diagnostics

* One more incremental parse test
2020-06-18 23:43:18 -07:00
Noj Vek f697d26ca1
reset soft with master for single commit (#38720) 2020-06-18 00:22:32 -07:00
Nathan Shively-Sanders c3c6be6618
In JSDoc, parse postfix-? below conditional types/tuple types (#39123)
Outside of JSDoc comments, postfix-? is parsed at lower precedence than
the `?` of conditional types, and a postfix-? inside a tuple type
results in the type being marked optional.

This PR changes JSDoc parsing to behave the same way, which means that

1. Conditional types are allowed in JSDoc. Fixes #37166.
2. Tuple types' postfix-? syntax is interpreted correctly in JSDoc.
Fixes #38747.

The breaking change is that a postfix-? type followed by another postfix type,
like `[]` or `!`, is parsed as a conditional type. [Postfix-? is not
common](https://github.com/microsoft/TypeScript/issues/37166#issuecomment-612274456),
so this is an acceptable breaking change.

A postfix-? type `T?` is still parsed everywhere else and treated as `T | null`.
2020-06-17 14:06:39 -07:00
Wenlu Wang 6c11ceb8db
Assignment operator is definite assignment (#39087)
Co-authored-by: Orta Therox <orta.therox@gmail.com>
2020-06-16 16:44:01 -04:00
Nathan Shively-Sanders 9f872c01e1 Merge branch 'master' into fix-implements-tag-emit 2020-06-11 16:05:21 -07:00
Nathan Shively-Sanders a64166de14 isDynamicName skips parentheses for element access
Neither `x[0]` nor `x[(0)]` should be dynamic names. Previously, the
latter was because `isDynamicName` didn't skip parentheses.

Since the binder treats dynamic names in property assignments as
assignment declarations, this incorrectly tried to create a binding for
expressions like `x[(0)] = 1`.

This caused an assert because `x[(0)]` would not take the dynamic name
code path during binding (`hasDynamicName` returned false), but the
normal code path for static names.
2020-06-11 09:08:51 -07:00
Eli Barzilay ffa35d3272 Allow e: unknown in catch arguments
In addition, allow an explicit `any`; anything else throws an error.

Also adjust and reorganize existing tests.

Fixes #36775.
2020-06-10 18:24:20 -04:00
Wesley Wigham 08cb0b23e8
Serialize (noncontextual) keyword named namespace members with export declarations in both declaration emitters (#38982)
* fix(38750): create unique names for keywords and re-export them with original names

* Serialize (noncontextual) keyword named namespace members with export declarations in both declaration emitters

* Add exhaustive keyword emit test for js declaration emitter and fix it up

Co-authored-by: Alexander T <alexander.tarasyuk@outlook.com>
2020-06-10 14:42:49 -07:00
Wesley Wigham 2287dbc7e2
Handle missing return type nodes and nested type references missing type arguments in existing jsdoc node serialization (#39011)
* Handle missing return type nodes and nested type references missing type arguments in existing jsdoc node serialization

* Accept updated baselines
2020-06-10 12:42:38 -07:00
Daniel Rosenwasser e832e04fa7
Merge pull request #37727 from Kingwl/logical_assignment
Add logical assignment operator
2020-06-09 14:44:08 -07:00
Eli Barzilay 3151e2a365 Make hasCorrectArity handle tuples properly
This completes the work that started in PR #33069, and fixes #32835.

There are probably two additional related changes that are needed to
make this more complete:

* Fix the code that composes the error message (see the first two
  `FIXME`s in `callWithSpread3.ts`).

* Fix the code that checks the argument types (second two `FIXME`s).

* There is also an error in `genericRestParameters1.ts` which changed
  but should not be an error in the first place.  Added a `FIXME` there
  too.  (Probably will work if the previous iterm is done.)

In addition, `getEffectiveCallArguments` munges the arguments in case of
a spread in the last argument which might be better to avoid.  (I think
that there are cases where it wouldn't work anyway, such as a spread of
an array followed by a spread of an empty array.)
2020-06-04 23:46:56 -04:00
rchaser53 261386d48b fix error when use spread arguments twice 2020-06-04 23:46:56 -04:00
Jack Works 8e290e5aae
Improve error range for ts2657 (jsx expr must have parent element), add code fix for it (#37917)
* fix: range of ts2657 (jsx expr must have parent) and remove 2695 (LHS expr of comma has no side effects)

* feat: add code fix for 2657

* fix: resolve review

* chore: hoist a var

* chore: add test for skipTrivia

* fix: rebase error

* Update src/compiler/diagnosticMessages.json

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>

* Update src/services/codefixes/wrapJsxInFragment.ts

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>

Co-authored-by: Andrew Branch <andrew@wheream.io>
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
2020-06-01 12:22:44 -07:00
Nathan Shively-Sanders 9b4a83e8df Merge branch 'master' into fix-implements-tag-emit 2020-05-21 08:21:16 -07:00