Commit graph

2721 commits

Author SHA1 Message Date
Oleksandr T 3e25424652
fix(43408): emit nullable/optional types on getters (#43476) 2021-04-29 09:20:40 -07:00
Andrew Branch a14b22718a
Enforce keyword order of abstract and override (#43829)
* Enforce keyword order of abstract and override

* Update baselines

* Update existing test
2021-04-28 16:41:28 -07:00
Andrew Branch 791c747e06
Allow override as parameter property (#43831)
* Allow `override` as parameter property

* Update other baseline

* Add test for override on normal parameter

* Copy typo fix

* Update baselines

* Update API baseline
2021-04-28 16:41:09 -07:00
Nathan Shively-Sanders d5af89c552
Contextual typing checks property assignments for type annotation (#43598)
Property assignments can have a type annotation in JS. This PR adds a
check for it in contextual typing.

Fixes #43379
2021-04-26 09:19:24 -07:00
Armando Aguirre f67ee44379
Instantiate getter when infering setter parameter value (#43564)
* Instantiate getter when infering setter parameter value

* Use esnext on tests

* Instantiate for JsDoc and getter from body

* PR comments

* Updated baseline
2021-04-19 23:23:40 -07:00
Andrew Branch 06f25c0390
Enforce keyword order between override and static/async (#43660)
* Enforce keyword order between override and static/async

* Update old tests for new keyword order
2021-04-15 14:03:53 -07:00
Nathan Shively-Sanders 0987ee9e0e
Do not erase signatures in getSignatureOfTypeTag (#43688)
I don't see a reason for it, and it doesn't cause any tests to fail.
2021-04-15 10:53:23 -07:00
Nathan Shively-Sanders 3f93d420bf
Fix @typedef/@callback scope (#43682)
JSDoc typedefs don't actually have hosts, because they're not
semantically attached to a declaration. However, the parser still
attaches them to some declaration (or statement), but that declaration
is not related to the typedef.

Previously, delayedBindJSDocTypedefTag used getJSDocHost to walk past
the unrelated declaration, but #41858 correctly started categorising
typedefs as unattached, with no host, so the binder began falling
back to file scope.

The path to skip the unrelated declaration is always the same, though, so this
PR uses `typeAlias.parent.parent` instead of `getJSDocHost(typeAlias)`.
2021-04-14 16:56:37 -07:00
Oleksandr T e87a0be959
fix(43444): add support JSDoc function signatures on returned function expressions (#43607)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-04-13 16:11:58 -07:00
Nathan Shively-Sanders 6a3d68905c
Add jsdoc to all js statements (#43659)
* Add jsdoc to if statements

This should only happen in JS files, however, and there needs to be some
conditional handling of jsdoc on statements that can't have jsdoc in TS
files.

* Finish change

* Add test
2021-04-13 15:30:22 -07:00
Anders Hejlsberg 5977233fd1
Reinstate constraint check for template literal types (#43661)
* Add missing constraint check for template literal types

* Add regression test
2021-04-13 12:17:55 -10:00
Wenlu Wang b0c2860a68
ignore static and declared member if checking override (#43569)
* ignore static member if checking override

* Ignore declared member when check override

* Check static override too

* Add more tests
2021-04-09 10:43:33 -07:00
Josh Goldberg 905a1fea39
Corrected parsing for decorators on 'this' parameters (#43175)
* Corrected parsing for decorators on 'this' parameters

* Moved checking to parser and added a specific test

* Remove unrelated checker.ts blank line

* Missed some baseeline updates...
2021-04-07 11:21:28 -07:00
Titian Cernicova-Dragomir 2484210a00
Gh 41788 incorrect output for esprivate with nested class in esnext (#42663)
* If target:esnext,then useDefineForClassFields: true will now be the default.

* Added error if a private identifier is used in a static a initializer if target:ESNext and useDefineForClassFields:false.

* Added test for new useDefineForClassFields default and error message.

* Fixed tests after changing the default of useDefineForClassFields to true for target esnext

* Fixed code review suggestions.

* Updated error message.

* Added missing static check for the containing property. Fixed other code review issues.
2021-04-07 08:23:16 -07:00
Nathan Shively-Sanders 2bb54dc11a
Fix getTypeFromJSDocVariadicType in callback tag (#43562)
* Fix getTypeFromJSDocVariadicType in @callback

Variadics have never worked there, I think.

* add test + fix lint

* remove outdated comment
2021-04-07 08:12:05 -07:00
Nathan Shively-Sanders dd1ef88d01
Use control flow to type CommonJS exports (#42751)
* Allow redeclaring CommonJS alias with initial undefined

This allows us to read our own output, plus the times when people
manually write exactly the same pattern.

Fixes #40555

* Use control flow to type commonjs exports

1. Could probably use a *lot* more tests.
2. getTypeOfAlias redoes some work from resolveAlias because it needs to
not resolve the alias completely, just to its export.

* fix lint, improve jsdoc

* Add tests, improve+fix control flow

1. Update the module.exports test to match the exports ones.
2. Add a test of evolving commonjs type.
3. Add a test of assignment as last statement.

(1) exposed a bug that required a better synthetic reference. (3)
exposed a bug that was most easily fixed by giving source files a
`endFlowNode` like functions and setting it in the binder.

* fix lint
2021-04-06 17:07:35 -07:00
Oleksandr T 3a22b3e701
fix(43535): preserves 'override' modifier in JavaScript output (#43536) 2021-04-06 11:31:54 -07:00
Zen 3cf26e44ee
fix(43160): improve error location for functions without explicit return (#43367)
* fix(43160): improve error location for functions without explicit return

* handle functions returning never
2021-04-06 07:21:02 -07:00
Armando Aguirre 8f8a579eee
Added BindingElement to isSomeImportDeclaration (#43387)
* Added BindingElement to isSomeImportDeclaration

* Added tests

* Refactores to use getDeclarationOfAlias
2021-03-31 18:18:16 -07:00
Anders Hejlsberg 3dd68b878a
Fix template literal type relations (#43440)
* Fix template literal relationships

* Accept new baselines

* Add regression test
2021-03-30 12:53:15 -10:00
keerthana1212 555ef73da8
Adding Diagnostic message for missing ']' and ')' in Array literal and conditional statements (#40884)
* Adding Diagnostic message for missing ']' in Array literal

* revert change on parseArrayBindingPattern

* Adding diagnostic message for if, while, do and with statements

* Extract parseExpectMatchingBrackets

Co-authored-by: Keerthana Kanakaraju <kekanaka@microsoft.com>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-03-30 13:13:57 -07:00
Oleksandr T 6fd676b8ef
fix(43215): disallow using never as an interface name (#43217) 2021-03-29 17:22:41 -07:00
Josh Goldberg 57775ed405
Consider class field properties to redeclare parent definitions (#43194) 2021-03-29 17:20:25 -07:00
Anders Hejlsberg 4774666f23
Support relations and inference between template literal types (#43361)
* Support assignment and inference between template literal types

* Add tests

* Accept new baselines

* Add comments
2021-03-28 13:11:56 -07:00
Wenlu Wang 2f0c8b2bea
--noImplicitOverride (#39669)
* wip: add types

* wip

* Add cases

* Add some case

* Add more check

* accept baseline

* add abstract abd declare method

* add override in declaration

* accept baseline

* add property override

* Fix decalre modifier

* update baseline

* Add more cases

* make lint happy

* make lint happy

* Update description

* Add codefix

* simplify code

* accept baseline

* Update desc

* Accept baseline

* Add override completions

* filter out implements field in override context

* fix tests

* Add parameter property check

* Accept baseline

* acept baseline

* Add parameter property to declaration code action

* Add quickfix for override parameter property

* fix code style

* Add override with interface tests

* Add more cases about modifier position

* rename flag

* rename flags

* Added tests.

* Accepted baselines.

* Always issue errors for unnecessary 'override' modifiers.

* Accepted baselines.

* Override perf (#4)

* try cache check result

* pre check for override

* Do not issue error if implement abstract

* Add abstract-spec check

* Avoid override dead lock

* Add more case

* Add codefix for new error

* Fix error message

* Add jsdoc override tag (#6)

* Override jsdoc tag (#7)

* accept baseline

* Disallow codefix in js

* update baseline

* Omit override in d.ts

* Add more case in js

* Accept baseline

* fix override js test

* fix crlf

* Revert merge conflict changes

* Accept baseline

* Avoid space

* Fix CR issues

* Accept baseline

* Fix typo and add more check

* Fix error name

Co-authored-by: Daniel Rosenwasser <Daniel.Rosenwasser@microsoft.com>
2021-03-26 16:29:22 -07:00
Wenlu Wang 41dc625b0a
Add static index signature (#37797)
* Add static index

* fix lint

* make lint happy

* adjust test cases

* add more cases

* fix changes

* Add more case

* accept baseline

* fix error if extends others

* Update vfsUtil.ts

* use equal to empty array

* static signature of interface is an error

* Accept baseline

* Check index constraints for static signature

* Accpet baseline

* Fix crash

* fix crash

* Accept baseline

* Fix regression

* Fix crash

* always return new array
2021-03-26 15:30:09 -07:00
Anders Hejlsberg a26acf4540
Template literal types for contextually typed template literal expressions (#43376)
* Template literal types for contextually typed template literal expressions

* Accept new baselines

* Add regression test

* Add a few more tests
2021-03-26 10:32:05 -07:00
Titian Cernicova-Dragomir e638af7560
ES private class elements (#42458)
* Added support for private identifier methods.

* Added tests for private methods.

* Added check to only not allow private name method signatures in anything except classes.
Changes objects literal checking to not bail on first private name found in object literal.

* Added private accessors tests

* Transform private methods

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Rename shouldTransformPrivateFields

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Use a single WeakSet for brand-check

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add a test for using private methods in static field initializers

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add breaking checker test

Private methods inside class expressions should not error.

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add to instances once per-instance

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: evaluate receiver and rhs expressions before throwing on readonly assignment

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add a test for evaluating rhs before readonly assignment

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Transpile private accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: handle readonly/writeonly accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for private setter without a getter

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: getAllUnscopedEmitHelpers

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: better handling of duplicate names

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Fixed wrong error message for private methods in class expressions.

* change error message

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for async private methods with a higher target

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: setter assignment returns rhs value

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for setter assignment return value

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: handle duplicate accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add tests for duplicate accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* docs: add missing parameter docs

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Fixed failing test.

* baseline-accept: ordering changes

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: attach weakSetName to property declaration

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for nested private methods

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test with any

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Added support for static private fields accessors and methods.

* Added error message for private identifiers used with static decorators. There is no spec to go with this behavior as of yet.

* Fixed emit static bug that used private names outside of classes for initialization in esnext. Fixed issue where nested privates produce incorrect brand check.

* Added tests for private static fields methods and accessors.

* Fixed error messages and tests after merge.

* Accept new baseline.

* Improved duplicate identifier checks for static private class elements.

* Added error when using initializers with private static fields when useDefineForClassFields is not specified and target is esnext.

* Fixed code review issues.

* Removed semantically wrong emit on `useDefineForClassFields:true` with `target:esnext`

* Changed emit for uninitialized private static fields.

* Added runtime error in helper if a static private field is accessed before it was declared.

* Fixed code review comments for private identifier static class elements.

* add debug.assertNever for unknown node type (#53)

* Fixed code review issues.

* Fixed code review issues for private class elements.

* Fixes class shadowing when checking access to a private static class element.

* fix private methods/accessors in class expr inside a loop

* collapse switch case

* fix class name

* simplify getPrivateMethodsAndAccessors

* remove findPreviousAccessorInfo

* lazily create weakSetName identifier

* do not allocate a node if not needed in visitMehodDeclaration (#55)

* Removed all the emit helpers for private identifier methods accessors and modified the existing helpers for get and set fields to do the same job.

* Simplified emit for private identifier class elements.

* do not clone the receiver (#57)

* leave bad code in for #constructor and duplicate private names (#58)

* Added check for WeakSet collision.

* Added error for using a set only accessor.

* update keyof tests and ?? (#62)

* replace ?? with ||

* update keyof tests

* fix emit helpers comments

* produce an error if private field helpers are not up to date

* add tests

* fix setter-only compound assignment

* fix tests

* fix duplicated trailing comments (#64)

* clear receiver pos and setTextRange on helper calls

Co-authored-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
2021-03-24 18:15:50 -07:00
Nathan Shively-Sanders dcc27ebaf2
@link support, second try (#43312)
* Revert "Revert "Editor support for link tag (#41877)" (#43302)"

This reverts commit 451d4354b9.

* Fix parsing @link at end of comment

* Parse comments as string when no @link occurs

* fix lint
2021-03-22 16:39:35 -07:00
Wesley Wigham 9a256a1935
Adjust scanning of keywordy jsx namespace names, add grammar error for jsx dotted names containing namespace names (#43104) 2021-03-22 10:28:43 -07:00
Anders Hejlsberg 15fae38b39
Improve narrowing of generic types in control flow analysis (#43183)
* Narrow type variables with union constraints when merited by contextual type

* Narrow generics with union type constraints as indicated by contextual type

* Accept new baselines

* Add tests

* Fix circularity for JSX elements

* Remove unnecessary isConstraintPosition information from flow cache key

* Update comment

* Add additional tests

* Rename to getNarrowableTypeForReference, remove getConstraintForLocation

* Add comment

* Fix removal of undefined in destructurings with initializers

* Use getContextFreeTypeOfExpression in discriminateContextualTypeByObjectMembers

* In obj[x], use constraint of obj's type only when x's type is non-generic

* Add comment
2021-03-19 17:12:57 -07:00
Nathan Shively-Sanders 451d4354b9
Revert "Editor support for link tag (#41877)" (#43302)
This reverts commit ec77bff332.
2021-03-18 14:42:25 -07:00
Anders Hejlsberg a21f61f746
Fix narrowing of intersections of type variables and primitive types (#43131)
* Fix narrowing of intersections of type variables and primitive types

* Add tests
2021-03-18 08:55:50 -07:00
Nathan Shively-Sanders ec77bff332
Editor support for link tag (#41877)
* Initial scribbles

* Compiles but provides spans instead of location pairs

Probably need to fork the services/server types and provide a conversion
with Session.toFileSpan. Not sure where to put the conversion.

* Switch to DocumentSpan

In theory this is already better supported, but not sure practise bears
that out.

* Builds w/protocol types + conversions

* cleanup:better names and scrub TODOs

* fix test harness too

* Misc

1. Simplify protocol after talking to @mjbvz.
2. Add more tests.
3. Initial notes about where to add parsing.

* Parse and store links in the compiler

The text of the link is still stored in the comment text, but that's now
kept in an object instead of just a string. Each link has the parse for
the entity reference, if there is one.

Needs lots more tests -- this just makes all the existing jsdoc tests
pass.

* more tests and some fixes

* Fix other failing tests

* fix bad merge

* polish parser

* improve names and array types

* slight tweaks

* remove some done TODOs

* more tests + resulting fixes

* add+fix cross-module tests

* Support `@see {@link`

Plus find-all-refs support equivalent to @see's.

* add server test

* Make comments actually part of the AST

* Add span for link.name in language service/protocol

* Make checker optional in getJSDocTags

Also change to JSDocCommentText from JSDocCommentComment

* Use getTokenValue instead of getTokenText

Measure twice, slice once

* Add missing support for top-level links

The language service and protocol were missing support for top-level
links. This commit adds that plumbing.

* add string back to comment type in node constructors

* Full parse of link tags and jsdoc comment text

- Doesn't pass fourslash yet, I'm going to switch to baselines for
  failures there.
- Still needs some work on the protocol to convert file+offset to
  file+line+offset.

* fix lint

* Fix missing newlines in inferFromUsage codefix

* Parse jsdoc comments as text node/link array

And switch to line+character offsets in the protocol

* Fix fourslash tests

Mostly ones that can't be baselined, but I switched a couple more over
to baselines

* Improve types and documentation

* Test+fix @link emit, scrub other TODOs

* update API baselines

* test that goto-def works with @link

* Split link displaypart into 3

One for link prefix and suffix, one for link name, and one for link
text.

* update baselines

* Provide JSDocTagInfo.text: string to full clients by default

Instead of upgrading them to displayparts.

* Real server tests

* Disambiguate {@link} and @param x {type}

They are ambiguous; previously the parser preferred the type
interpretation, but will now look ahead and parse links instead when the
prefix is `{@link`.

* Add explanatory comment in test

* fix location in richResponse in protocol

* update API baseline

* Address PR comments

1. Add a cross-file goto-def test.
2. Switch from per-message args to UserPreference.

* use arraysEqual from core
2021-03-16 16:26:01 -07:00
Nathan Shively-Sanders 2ea2f4f9a0
Bigint constructor forbids object null undefined (#43204)
* Update es2020.bigint.d.ts

* Update es2020.bigint.d.ts

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* add a test

Co-authored-by: 龙腾道 <LongTengDao@LongTengDao.com>
Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2021-03-11 16:51:03 -08:00
Nathan Shively-Sanders b2d1f537f1
Bloomberg computed property name fix (#43197)
* Fix property name bindings for class expr in loops

* Fix block-scope capturing with prop initializers

Co-authored-by: Joey Watts <joey.watts.96@gmail.com>
2021-03-11 10:32:42 -08:00
Titian Cernicova-Dragomir 71661b932a
Fixed issue where non null assertion caused getFlowTypeOfReference to return the declared type if the type was already narrowed to never. (#35863)
This was caused by the fact that getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull) will return never both if resultType was already never and if resultType does not contain undefined or null. In the latter case returning the declaring type is correct, in the former case this causes something narrowed to never to still be typed as the original declared type.
2021-03-11 07:33:33 -08:00
Kagami Sascha Rosylight f4d0ea6539
Add target: ES2021 (#41239)
* Support `target: es2020`

* use CRLF

* update symbols

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-03-10 13:31:25 -08:00
Oleksandr T 9610c16cc8
fix(42380): include JSDoc comments in declarations for static/prototype methods (#42454) 2021-03-09 11:37:40 -08:00
Anders Hejlsberg f918bd9c76
Exclude enum/number compatibility rule from comparable relation (#42472)
* Exclude old number/enum literal compatibility rule from comparable relation

* Add tests

* Accept new baselines
2021-03-06 06:52:00 -08:00
Daniel Rosenwasser 9862b031b0
Relax requirements on index signatures to 'any' when a type also contains a string index signature to 'any' (#43065)
* Added test.

* Accepted baselines.

* Allow other index signatures to 'any' if there is a string index signature to 'any'.

* Accepted baselines.
2021-03-04 17:42:00 -08:00
Oleksandr T ca8d9e4402
fix(39836): allow type declaration/unknown type in catch arguments in JavaScript files (#42392) 2021-03-04 17:19:35 -08:00
Klaus Meinhardt 15e69acc20
capture thisArg of optionalChaining in parens (#35494)
Fixes: #35476
2021-03-03 19:35:17 -08:00
Andrew Branch 56cf2e68e8
Never-reducing intersections are not untyped function call targets (#42917)
* Never-reducing intersections are not untyped function call targets

* Don’t attempt to reduce union types
2021-02-23 17:22:41 -08:00
Eli Barzilay 67f55aabd7 Extend the MetaProperty check to work for new.target too 2021-02-22 19:33:01 -05:00
Eli Barzilay d495957065 Add missing MetaProperty stuffs
Add missing parts in the binder and the checker to enable CFA +
narrowing of `import.meta` values.

Fixes #41468
2021-02-22 19:33:01 -05:00
Oleksandr T e961916217
fix(42368): omit converting jsx spread attributes to Object.assign for ES2018 and up (#42554) 2021-02-18 17:06:08 -08:00
Titian Cernicova-Dragomir a2ed469022
Fix for crash when using ca call expression on private identifier coming from an any typed variable. (GH #42860) (#42861) 2021-02-18 13:54:10 -08:00
Nathan Shively-Sanders 3d7ec8aab2
Improve @template lookup and resilience (#42851)
* Improve @template lookup and resilience

1. @template parsing may produce a template tag with a type parameter
whose name is the missing identifier. These tags should be skipped
in the checker because they receive an error in the parser.
2. The fix in #37819 was incorrect; there's no such thing as a type
parameter declared on a variable declaration. Instead, there needs to be a type
parameter declared on a jsdoc comment, because that's the scope for tags
like `@return` and `@typedef`.

There are 3 tests because either fix (1) and (2) fix the first test's
failure, but both are required to fix the last two tests' failures.

* remove containsParseError call
2021-02-17 17:21:17 -08:00
Oleksandr T 475036950e
fix(42133): fix instantiated undefined type from JS initializer (#42662) 2021-02-11 17:07:14 -08:00
Eli Barzilay c7bac6f2e6 Avoid getting undefined callSignatures/constructSignatures in getPropertyOfType
e350c357 (#40228) introduced a subtle bug: it switched the flags to an
alias, dropping `SymbolFlags.Property` --- and that makes
`symbolIsValue()` get to the `resolveAlias(symbol)` call, which leads to
`getPropertyOfType()` with`resolved.callSignatures`+`constructSignatures`
being `undefined`.  So initialize them in `setStructuredTypeMembers`
before calling `getNamedMembers()`.

Fixes #42350
2021-02-11 18:56:47 -05:00
Orta Therox 8c5fa5cc91
Revert assignability cases in getNarrowedType (#42231)
* Revert subtype narrowing changes from readonly array PRs

* Adds a test for the change

* More baselines
2021-02-09 15:03:11 -08:00
Anders Hejlsberg e2318217fb
Strip nullable types from 'this' type in inference with optional chain calls (#42536)
* Properly strip nullable types from this type in optional chain calls

* Add regression test
2021-02-03 13:50:23 -10:00
Song Gao 3e28e29c51
fix 38503. (#39716)
* fix 38503.

* trigger test.

* trigger test.

* Move isCallChain

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-02-01 18:34:46 -08:00
Andrew Branch c15f40abfa
Fix discriminant property narrowing through optional chain with null (#42503)
* Fix discriminant property narrowing through optional chain with null

* Accept baselines

* Add tests from Anders
2021-01-29 12:03:42 -08:00
Nathan Shively-Sanders 9dbfaeef2d
Narrow QualifiedName inside typeof (#42540)
Previously this wasn't narrowed at all. Now there is control flow and
code in isMatchingReference.
2021-01-28 15:19:01 -08:00
Nathan Shively-Sanders d2443a5df1
@typedef: Improve error spans from declaration emit (#42501)
* @typedef: Improve error spans from declaration emit

This is a proof-of-concept fix. I think it could be expanded for all of
jsdoc, but I only set it up for jsdoc type aliases. It could use a lot
of polish too.

* track error node in isSymbolAccessible instead

* Switch to using enclosingDeclaration

Remove trueErrorNode

* add test of @callback and @enum

* Better error + fix @enum error

Since enums don't have a name property, you *have* to call
`getNameOfDeclaration` to go looking through the AST for one.
2021-01-28 08:35:05 -08:00
M.Yoshimura 701493fb80
Support top level "for await of" (#37424)
* Support Top Level "for await of".

* Add test cases for top level "for await of".

* Apply suggestions from code review

* add test cases

* remove redundant variables

* fix test baselines

* Update diagnostic message and tests

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-01-25 13:40:45 -08:00
Andrew Branch 89c173fddc
Narrow via discriminant property through optional chain (#42450)
* Naive attempt at narrowing via discriminant property through optional chain

* Clean up test
2021-01-25 09:29:51 -08:00
Oleksandr T 1ecf22884f
fix(42166): allow assertion signature for private identifiers (#42176) 2021-01-11 09:25:51 -08:00
Orta Therox 055f363fba
Reverts #39277 removing bundledPackageName (#41499)
* Reverts #39277

* Bring back modeyule resolution for the test runner
2021-01-08 10:55:34 +00:00
Ron Buckton 0d284e6c26
Add support for abstract constructor types (#36392)
* Add support for abstract constructor types

* Add backwards-compatible overloads for creating/updating constructor types

* Reverting use of 'abstract' in lib/es5.d.ts due to eslint issues

* Update baseline due to reverting lib

* Add error for failing to mark an mixin class as abstract

* Fix declaration/quick info for abstract construct signatures
2021-01-07 17:11:14 -08:00
Andrew Branch dbba8b358f
Make optional properties assignable to string index signatures (#41921) 2021-01-07 10:46:55 -08:00
Anders Hejlsberg 9b1718677a
Leading and middle rest elements in tuple types (#41544)
* Support starting and middle rest elements in tuples

* Accept new baselines

* Include all rest arguments in error span

* Accept new baselines

* Fix tests

* Add new tests

* Fix lint errors
2021-01-04 15:12:51 -10:00
Oleksandr T b405fdd2ab
fix(41420): forbid optional chain in extends/implements (#41481) 2021-01-04 15:38:54 -08:00
Ron Buckton 6fac3ddfd4
Fix module resolution for import call emit (#41390) 2021-01-04 15:08:57 -08:00
Oleksandr T 841b1a5bc7
fix(37791): fix incorrect private field access in a computed property name (#38135) 2021-01-04 14:01:54 -08:00
Oleksandr T e108257fb6
fix(41965): fix error in definite assignment assertion context (#41989) 2020-12-30 11:45:18 -08:00
Oleksandr T 303ed3a357
fix(42099): fix JSDoc optional properties declaration emit (#42116) 2020-12-28 13:34:55 -08:00
Oleksandr T a763600cc4
fix(41818): use last JSDoc comment related to host (#41858) 2020-12-18 13:24:58 -08:00
Ron Buckton 4239904517
Report implicit any error for 'yield' result with no contextual type (#41348) 2020-12-18 09:55:33 -08:00
Ron Buckton e789cb1356
Fix single-line comment disrupting return w/optional chain (#42026) 2020-12-17 18:55:09 -08:00
Anders Hejlsberg ee1f262698
Template literal types for template literal expressions (#41891)
* Infer template literal types for template literal expressions

* Update test

* Update another test

* Accept new baselines

* Minor fixes

* Add tests

* Accept new baselines

* Make new TypeFlags internal

* Accept new API baselines

* Ensure template literals assignable to String, Object, {}, etc.

* Add tests
2020-12-11 15:07:37 -10:00
Wesley Wigham 69143ecc5b
Reuse input nodes where possible when serializing jsdoc implements clauses (#41783)
* Reuse input nodes where possible when serializing jsdoc implements clauses

* Whitespace changes, per PR feedback
2020-12-08 12:13:37 -08:00
Wesley Wigham 360958e04c
JSDoc declaration emit should reuse input nodes where possible when serializing typedefs (#41760)
* JSDoc declaration emit should reuse input nodes where possible when serializing typedefs

* Style comments
2020-12-04 13:42:35 -08:00
Anders Hejlsberg cd37a327a7
Fix non-homomorphic mapped type constraint issues (#41807)
* Less aggressive wildcard check, 'keyof any' constraint for 'infer T' in mapped type constraint position

* Accept new baselines

* Add regression tests
2020-12-03 16:36:45 -10:00
Armando Aguirre 143d1104ab
Merge pull request #41703 from a-tarasyuk/fix/41653
fix(41653): Enum Keys in Destructure Prevents ES6 Function Convert with --target ES5
2020-12-03 16:10:51 -08:00
Ron Buckton 324f0469c0
Merge pull request #41791 from microsoft/fix40643
Reuse temp variable scope for converted loop body
2020-12-03 13:33:09 -08:00
Andrew Branch 69bc3f3b0c
Allow type-only imports on ImportEqualsDeclarations (#41573)
* Allow type-only ImportEqualsDeclarations

* Suppress CJS-in-ESM error when type-only

* Add grammar error on import type in import alias

* Update API baselines

* Fix importsNotUsedAsValues with ImportEqualsDeclarations

* Make bad error talk words more good for Daniel. Fixes #41603

* One more error message baseline update

* Update transformer and emitter
2020-12-03 13:27:15 -08:00
Ron Buckton 27dc177f29 Reuse temp variable scope for converted loop body 2020-12-02 18:11:45 -08:00
Wesley Wigham 9f9eed400c
Read the base construct signature from the static base type, not the instance base (#41767) 2020-12-02 13:30:46 -08:00
Anders Hejlsberg 4d6947ae14
Check nested conditional types for non-distributiveness in mapped types with 'as' clauses (#41713)
* Check nested conditional types for non-distributiveness

* Rename to maybeNonDistributiveNameType

* Add regression test
2020-12-01 12:07:47 -10:00
Anders Hejlsberg 4782c74b75
Propagate wildcard types in non-homomorphic mapped types (#41622)
* Propagate wildcard types in non-homomorphic mapped types

* Add regression test

* Accept new baselines

* Accept new baselines
2020-12-01 11:57:00 -10:00
Toan Nguyen 0c76803854
Fix typos in comments (#41307)
* Fix typo fuction -> function

* Fix typo assignement -> assignment
2020-11-30 15:02:07 -08:00
Oleksandr T 3a903b8a28 fix(41653): convert arrow function to function expression that used as destructure initializer 2020-11-26 21:19:15 +02:00
Anders Hejlsberg 411c6d04c6
Fix getTypeFacts for pattern template literal types (#41693)
* Normalize `${string}` to just string, fix getTypeFacts

* Add tests

* Accept new baselines
2020-11-26 06:55:01 -10:00
Nathan Shively-Sanders 9fb6acf1e1
Add missed resolveSymbol in commonjs import resolution (#41479)
Fixes resolution of export aliases in the postfix-property-access case
of commonjs require:

```js
const { x } = require('./foo').nested
x
```

This program would previously fail if `x` was an export alias.

Fixes #41422
2020-11-10 11:28:49 -08:00
Oleksandr T 45b698b3f6
fix(40632): skip emitting abstract members (#40699) 2020-11-04 16:02:17 -08:00
Thomas Williamson 8ed251d0c7
Support xml namespace prefix for JSX elements and attributes (#37421)
* Support xml namespace prefix for JSX elements and attributes

Just as with the `-` character, `:` is now also treated specially in JSX
element and attribute names, but is only allowed a single time, and not
at the beginning or end of the name, as is specified in the JSX spec.
All tests in jsxInvalidEsprimaTestSuite still fail, but for slightly
different reasons now. Two lines in jsxEsprimaFbTestSuite were
uncommented as they included elements with namespaces, and they now pass
without error.

* Add case for colons at ends of identifier

* Add case for jsx namepsace intrinsics

* Add cases with upcase idents for jsx namespaces

* Add case for jsx namespaces with react option

* Always consider jsx names with colon to be intrinsics

* Adjust comment about chars valid in jsx names but not js idents

* Fix minor typo in namespace prefix test case variable name

* Remove misleading comments on isUnhyphenatedJsxName
2020-11-02 15:34:36 -08:00
Wenlu Wang ce8d702586
Add support for pedantic property access (#40171)
* Add support for pedantic property access

* accept baseline

* Update diag message

* Avoid pedantic

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-11-02 15:19:00 -08:00
Ron Buckton f944afd053 Fix double alias of complex export/import/default/namespace combination 2020-10-29 18:42:36 -07:00
Ron Buckton bcbe1d7638
Merge pull request #41094 from microsoft/destructuringEvaluationOrder
Fix destructuring evaluation order for initializers
2020-10-29 17:12:18 -07:00
Ron Buckton 2b7e790732 Update control flow for nested binary exprs 2020-10-29 13:32:32 -07:00
Ron Buckton 8a15291541 Update control flow for correct destructuring evaluation order 2020-10-28 16:50:15 -07:00
Wesley Wigham ca8a15d37b
Merge pull request #41287 from weswigham/bind-exports-assigned-object-as-alias
Bind `module.export = {Thing}` with alias symbols
2020-10-28 13:14:20 -07:00
Oleksandr T af38ab90e2
feat(41249): allow import.meta with module: es2020 (#41274) 2020-10-27 17:26:15 -07:00
Anders Hejlsberg 40b81224f9
Remove string literals from unions with matching template literals (#41276)
* Remove string literals from unions with matching template literals

* Add tests

* Accept new baselines
2020-10-27 16:21:07 -07:00
Wesley Wigham d1bc6b1ba6
Bind module.export = {Thing} with alias symbols 2020-10-27 15:43:00 -07:00
Wesley Wigham 94b0e0e389
Merge pull request #41190 from weswigham/handle-binding-element-aliases
Handle the new js binding element alias symbols in JS declaration emit
2020-10-23 10:31:08 -07:00
Ron Buckton 0b303ff08a Fix some rest cases and handling of unused results 2020-10-22 18:58:21 -07:00