Commit graph

208 commits

Author SHA1 Message Date
Ron Buckton 6c59dc34ac
More tests for super.method call chain, improve vary-by (#35013) 2019-11-18 18:03:37 -08:00
Klaus Meinhardt fce728e07f fix emit for delete on optional chain (#35090)
* fix emit for delete on optional chain

* Apply suggestions from code review

Co-Authored-By: Ron Buckton <ron.buckton@microsoft.com>
2019-11-18 16:34:47 -08:00
Klaus Meinhardt 8f40ac06cc optimize transform of optional chaining and nullish coalescing (#34951)
* optimize transform of optional chaining and nullish coalescing

* remove unnecessary condition

* typo

* fix lint

* prevent capturing of super

* swap branches again

* accept new baselines

* avoid temporary objects
2019-11-14 17:34:13 -08:00
Ron Buckton ba5e86f140
Propagate 'undefined' instead of the optional type marker at an optional chain boundary (#34588)
* Propagate 'undefined' instead of the optional type marker at an optional chain boundary

* Update src/compiler/types.ts

Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2019-11-01 11:36:22 -07:00
Anders Hejlsberg c404c08fde
Fix reachability analysis for ?? operator (#34702)
* Exclude ?? operator from true/false literal check in createFlowCondition

* Accept new API baselines

* Add tests

* Accept new baselines

* Address CR feedback

* Accept new API baselines
2019-10-24 15:57:14 -07:00
Klaus Meinhardt 45d0ef9441 factory: parenthesize for-of expression when necessary (#34229)
Fixes: #33856
2019-10-17 10:17:33 -07:00
Klaus Meinhardt 178417f431 factory: correctly parenthesize conditional head (#34227)
Fixes: #34109
2019-10-16 10:41:52 -07:00
Ron Buckton c774762723
Fix crash in transformations (#33768) 2019-10-02 16:13:32 -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
Ron Buckton fcd9334f57
Add support for Optional Chaining (#33294)
* Add support for Optional Chaining

* Add grammar error for invalid tagged template, more tests

* Prototype

* PR feedback

* Add errors for invalid assignments and a trailing '?.'

* Add additional signature help test, fix lint warnings

* Fix to insert text for completions

* Add initial control-flow analysis for optional chains

* PR Feedback and more tests

* Update to control flow

* Remove mangled smart quotes in comments

* Fix lint, PR feedback

* Updates to control flow

* Switch to FlowCondition for CFA of optional chains

* Fix ?. insertion for completions on type variables

* Accept API baseline change

* Clean up types

* improve control-flow debug output

* Revert Debug.formatControlFlowGraph helper
2019-09-30 12:33:28 -07:00
Andrew Branch 16bbb4d002
Merge pull request #32077 from andrewbranch/bug/31114
Fix incorrect noImplicitAny error on contextual union function signature
2019-07-03 10:10:10 -07:00
Klaus Meinhardt 392d775095 allow const-assertion on aliased enum symbol (#32110)
Fixes: #32087
2019-06-26 14:42:06 -07:00
Andrew Branch 252840ad40
Fix incorrect noImplicitAny error on contextual union function signature 2019-06-24 17:37:14 -07:00
Anders Hejlsberg 51712fb1ae Add tests 2019-06-17 16:18:13 -10:00
Anders Hejlsberg 9d2a2c9634 Add tests 2019-06-06 13:33:36 -07:00
Nathan Shively-Sanders b36c8a0690
Make anyArray.filter(Boolean) return any[], not unknown[] (#31515)
* Add this-parameter workaround to Array.filter

Allows anys.filter(Boolean) to once again return any[], not unknown[].

* Add any constraint to Boolean factory function

I want to test how well this works.

* Remove Boolean factory type guard

* Remove typeGuardBoolean test
2019-05-22 09:45:41 -07:00
Forbes Lindesay 3ce3cde493 Allow Boolean() to be used to perform a null check (#29955)
* Allow Boolean() to be used to perform a null check

* Add missing test case output
2019-04-30 08:09:31 -07:00
Andrew Branch 8576018af1
Add failing test for function calls that have at least one non-spread argument, a spread argument, and overall potentially too few arguments 2019-04-04 11:47:25 -07:00
Collins Abitekaniza 7b55d1846b Giving too many arguments should error on the first argument that exceeds arity (#27982)
* span on first arg that exceeds arity

* refactor baseline

* handle cases for spread arguments

* refactor + add coverage for tuple spread cases

* create diagnostic on NodeArray of exceeding args

* test function overloading
2019-03-12 15:57:12 -07:00
Nathan Shively-Sanders be2db9db12
Add globalThis (#29332)
* Restore original code from bind-toplevel-this

With one or two additional comments

* Working in JS, but the symbol is not right.

Still need to

1. Make it work in Typescript.
2. Add test (and make them work) for the other uses of GlobalThis:
window, globalThis, etc.

* Check in TS also; update some tests

Lots of tests still fail, but all but 1 change so far has been correct.

* Update baselines

A couple of tests still fail and need to be fixed.

* Handle type references to globalThis

The type reference must be `typeof globalThis`. Just `globalThis` will
be treated as a value reference in type position -- an error.

* Restore former behaviour of implicitThis errors

I left the noImplicitThis rule for captured use of global this in an
arrow function, even though technically it isn't `any` any more --
it's typeof globalThis.  However, you should still use some other method
to access globals inside an arrow, because captured-global-this is super
confusing there.

* Test values with type globalThis

I ran into a problem with intersecting `Window & typeof globalThis`:

1. This adds a new index signature to Window, which is probably not
desired. In fact, with noImplicitAny, it's not desired on globalThis
either I think.
2. Adding this type requires editing TSJS-lib-generator, not this repo.

So I added the test cases and will probably update them later, when
those two problems are fixed.

* Add esnext declaration for globalThis

* Switch to symbol-based approach

I decided I didn't like the import-type-based approach.

Update baselines to reflect the difference.

* Do not suggest globals for completions at toplevel

* Add tests of element and property access

* Look up globalThis using normal resolution

globalThis is no longer constructed lazily. Its synthetic Identifier
node is also now more realistic.

* Update fourslash tests

* Add missed fourslash test update

* Remove esnext.globalthis.d.ts too

* Add chained globalThis self-lookup test

* Attempt at making globalThis readonly

In progress, had to interrupt for other work.

* Add/update tests

* Addres PR comments:

1. Add parameter to tryGetThisTypeAt to exclude globalThis.
2. Use combined Module flag instead combining them in-place.
3. SymbolDisplay doesn't print 'module globalThis' for this expressions
anymore.
2019-02-27 14:14:34 -08:00
Anders Hejlsberg 08fe06f527 Merge branch 'master' into constContexts
# Conflicts:
#	src/compiler/checker.ts
2019-01-29 12:29:30 -08:00
Anders Hejlsberg 2e94f47602 Add tests 2019-01-19 10:34:38 -08:00
Jack Williams 5651789629 Fix #29457
Use allTypesAssignableToKind instead of isTypeAssignableToKind to
account for union types.
2019-01-17 20:03:46 +00:00
Jack Williams 342fda98d8 Allow trailing void arguments to be omitted 2018-10-03 19:35:05 +01:00
Andy 72886512a6
When --noImplicitAny is enabled, don't report errors suggesting that a 'void' function can be 'new'ed (#26579) 2018-08-21 10:02:02 -07:00
Matt McCutchen cc1c2ab6b2 Go back to the old narrowing algorithm (pre #26143) and avoid #26130 by
skipping narrowing if the old algorithm produces a type to which the
assigned type is not assignable.

This also means we'll no longer narrow for erroneous assignments where
the assigned type is not assignable to the declared type.  This is the
reason for the numericLiteralTypes3 baseline change.

Fixes #26405.
2018-08-17 21:35:03 -04:00
Matt McCutchen d45e422b46 Have getAssignmentReducedType use the comparable relation instead of
typeMaybeAssignableTo.

typeMaybeAssignableTo decomposed unions at the top level of the assigned
type but didn't properly handle other unions that arose during
assignability checking, e.g., in the constraint of a generic lookup
type.

Fixes #26130.
2018-08-01 23:26:17 -04:00
Anders Hejlsberg 6f2001fb23 Add tests 2018-06-02 17:43:37 -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
Ron Buckton f67afa098f Unpatch vfs resolver and default lib rename 2018-05-03 14:18:50 -07:00
Nathan Shively-Sanders 7dbea0e82d Merge branch 'master' into fix2-getConstraintOfIndexedAccess 2018-01-10 12:40:35 -08:00
Nathan Shively-Sanders 3a0ce3435e Test:in doesn't narrow types with string indexers 2017-12-07 10:56:33 -08:00
IdeaHunter 069f73d0f2 Change type narrowing for optional properties 2017-12-06 00:02:36 +03:00
IdeaHunter 9c3c2adfb0 Add initial support for 'in' typeguarding 2017-12-06 00:02:36 +03:00
Nathan Shively-Sanders dd0fa41de1 Merge branch 'master' into fix2-getConstraintOfIndexedAccess 2017-12-04 15:26:02 -08:00
Nathan Shively-Sanders 865f3281bc Update spread tests w/new excess arguments error 2017-11-16 09:39:31 -08:00
Anders Hejlsberg 14b7e755ef Add tests 2017-10-26 14:56:54 -07:00
Nathan Shively-Sanders d7d69a1622 Test:string enum in element access 2017-08-24 14:06:21 -07:00
Nathan Shively-Sanders ecae295c5a Test getConstraintOfIndexedAccess fixes and update baselines 2017-08-18 15:16:24 -07:00
Arthur Ozga 6b68da1185 Revert "Fix getConstraintOfIndexedAccess" 2017-08-18 11:32:53 -07:00
Nathan Shively-Sanders 1b4f90705f Test getConstraintOfIndexedAccess fixes and update baselines 2017-08-17 12:45:20 -07:00
Nathan Shively-Sanders 7809398ad4 Indexed-assignment readonly err is not unknownType
Now, in an assignment to an indexed access of a readonly property, the
resulting type is still the property's type. Previously it was
unknownType. This improves error reporting slightly by reporting some
errors that were previously missed.
2017-08-16 10:06:01 -07:00
gcnew 0654fa285c Added tests 2017-07-20 02:59:33 +03:00
Nathan Shively-Sanders cefcc668a8 Correct test argument in callwithSpread2 2017-05-15 10:55:58 -07:00
Nathan Shively-Sanders 4c80aa17b3 Clean up comments in tests 2017-05-15 10:38:51 -07:00
Nathan Shively-Sanders 9ba0668afa Test:spread array after required params 2017-05-15 10:20:28 -07:00
Anders Hejlsberg 9d1b325e09 Update another test 2017-03-01 06:31:34 -08:00
Anders Hejlsberg e512376b0c Update tests 2017-02-16 17:42:22 -08:00
Nathan Shively-Sanders 69e9bfef35 Add typeof test case and update baselines
Test that `typeof x === 'random' as string`:

1. Does not issue an error.
2. Does not narrow.
2017-01-31 10:28:32 -08:00
Ron Buckton 20249e5c4a More exhaustive needsDotDotForPropertyAccess 2017-01-24 13:42:05 -08:00