Commit graph

2558 commits

Author SHA1 Message Date
Wesley Wigham da86332120
Limit export= js declaration emit to only json source files (#40882) 2020-10-01 14:55:24 -07:00
Wesley Wigham 3ea81e652a
Ensure whitespace jsx elements are not counted when determining if a jsx child is the only child (#40839)
* Ensure whitespace jsx elements are not counted when determining if a jsx child is the only child

* Use filtered children count for deciding constructor used

* Accept updated baselines post-merge
2020-10-01 14:36:44 -07:00
Andrew Branch 5fbe9806db
Fix noUncheckedIndexedAccess with tuple rest types and generic index types (#40681)
* Fix noUncheckedIndexedAccess for tuple rest elements

* Defer inclusion of undefined for generic indexed access types

* Create separate IndexedAccessTypes depending on whether --noUncheckedIndexedAccess applies

* Undo accidental export

* Parenthesize for clearer precedence
2020-10-01 13:56:13 -07:00
Anders Hejlsberg 950dad9c29
Propagate wildcard types in template literal type construction (#40875)
* Propagate wildcard types in template literal type construction

* Add regression test

* Accept new baselines
2020-10-01 13:36:08 -07:00
Anders Hejlsberg 4538e7352f
Properly distribute over unions in keyof for mapped types with as clause (#40837)
* Properly distribute over unions in keyof mapped types with as clause

* Accept new baselines

* Add regression test

* Accept new baselines
2020-10-01 09:36:51 -07:00
Andrew Casey 35111231f7
Merge pull request #40755 from amcasey/SpreadLimit
Enforce a size limit in getSpreadType
2020-09-30 13:44:59 -07:00
Nathan Shively-Sanders f615e229d3
Fix default property assigned prototype (#40836)
* Fix default-property-assignment decls+prototype property decls

The check in getAssignedClassSymbol forgot to allow for default-property
assignment declarations, in part because it wasn't using a utility
function to do so.

* small cleanup

* make allowDeclaration parameter required
2020-09-30 08:36:52 -07:00
Wesley Wigham 2428ade1a9
Match suffix _after_ prefix when inferring literals out of templates (#40841) 2020-09-29 16:34:58 -07:00
Andrew Casey 6650496e85 Enforce a size limit in getSpreadType
When a union is spread into a union, the sizes are multiplied,
potentially resulting in an enormous union (especially if there are
repeated spreads).  This check detects cases that used to run out of
memory.

Fixes #40754
2020-09-24 14:52:42 -07:00
Wesley Wigham a960463cf3
Allow pattern literal types like http://${string} to exist and be reasoned about (#40598)
* Allow pattern literal types like `http://${string}` to exist and be reasoned about

* Allow bigint, number, null, and undefined in template holes

* Add test of the trivia case

* Handle `any` in template holes, add assignability rules for template -> template relations

* Explicitly test concatenated patterns

* PR Feedback
2020-09-23 01:08:58 -07:00
Wesley Wigham ad2a07440c
Fix crash on js declaration emit of export assigned default augmented function (#40596)
* Fix crash on js declaration emit of export assigned default augmented function

* {sp}
2020-09-23 00:50:12 -07:00
Anders Hejlsberg 5d6cce5ca7
Const contexts for template literals (#40707)
* Support const assertions with template literal expressions

* Add tests

* Accept new baselines
2020-09-22 13:11:17 -10:00
Alex T 0310b530d8
feat(40663/40664): improve error messages for assignment assertions '!' (#40669) 2020-09-21 11:20:01 -07:00
Anders Hejlsberg fbce4f6c98
Intrinsic string types (#40580)
* Introduce Uppercase<T> and Lowercase<T> intrinsic types

* Accept new API baselines

* Add Uppercase/Lowercase/Capitalize/Uncapitalize to lib.d.ts

* Update fourslash

* Add an 'intrinsic' keyword

* Update template literal type tests

* Accept new API baselines

* Minor fixes

* Switch Capitalize<T> and Uncapitalize<T> to intrinsic types

* Add tests

* Accept new baselines

* Accept new baselines

* Remove template literal type casing modifiers

* Update tests

* Accept new baselines

* Add more tests

* Normalize nested template literal types

* Add normalization tests

* Accept new baselines

* Update tests
2020-09-21 07:09:29 -10:00
Anders Hejlsberg ce3dbef5f7
Support properties of mapped types in assertion control flow analysis (#40482)
* Support properties of mapped types in assertion control flow analysis

* Add regression test

* Accept new baselines
2020-09-21 07:07:29 -10:00
Anders Hejlsberg 17c7c261d4
Properly preserve modifiers in homomorphic mapped types with 'as' clauses (#40633)
* Use original property name to fetch source property for modifiers

* Add regression test

* Accept new baselines
2020-09-19 06:12:39 -10:00
Hikari Hayashi f1ac8cd93f
Fix children prop for react-jsx and react-jsxdev (#40630)
* Fix children prop for `react-jsx` and `react-jsxdev`

* Add tests
2020-09-18 14:26:20 -07:00
Nathan Shively-Sanders ec36d73e7a
Fix error on duplicate commonjs exports (#40545)
* Fix error on duplicate commonjs exports

Previously, the code missed setting the parent pointer for the lhs
access expression.

Also add declaration emit of element access expressions, missed in my
previous PR.

* Switch to excludes=None, add test case

CommonJS exports have None excludes, but still have an error issued by
the checker. This is the previous behaviour even though it would be nice
to add some exclusions.
2020-09-14 13:12:51 -07:00
Anders Hejlsberg 57c8938d9e
Consistent inferences when inferring to template literal type (#40518)
* Consistently make inferences when inferring to template literal type

* Add tests

* Accept new baselines
2020-09-12 16:33:33 -10:00
Nathan Shively-Sanders 9c99870058
Support element access aliases: exports["x"] = x (#40514) 2020-09-11 18:05:47 -07:00
Anders Hejlsberg eee799fe0c
Properly check types in template literal placeholders (#40498)
* Properly check types in template literal placeholders

* Add regression test

* Update test

* Accept new baselines
2020-09-11 14:48:35 -10:00
Ryan Cavanaugh 3d235b42a0
--noUncheckedIndexedAccess (#39560)
* Initial implementation + tests

* linty

* Support destructuring declarations and assignments

* lint

* Fix destructuring assignment and element access into known properties

* Update baselines

* Rename flag to unUncheckedIndexedAccess

* Add test for unique symbol indexing

* Fix flag order in baselines

Co-authored-by: Andrew Branch <andrew@wheream.io>
2020-09-11 14:43:10 -07:00
Wesley Wigham a36f17c1f8
Add emit support for jsx/jsxs experimental jsx runtime api (#39199) 2020-09-11 10:44:52 -07:00
Andrew Branch 083129f005
A union including non-iterable types is not iterable (#40350)
* WIP

* If method type derives solely from the global iterator or generator type, use its type arguments

* Add test for problem fixed as side effect
2020-09-11 09:31:22 -07:00
Orta Therox cdafb7157b
Replaces the default module index resolver with '/index' instead of '' when handling internal routing for dts bundles (#39277)
* Adds support for declaring the bundled name of a dts module export

Co-authored-by: Wesley Wigham <wwigham@gmail.com>

* Adds baselines

* Update the tests

* Try to reduce the scope of the bundledPackageName error

* Use the flag in more baselines

* Get it green

* More tests

* Handle more feedback

* More test cleanup

* Set the moduleResolution for the tsconfigs

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
2020-09-11 08:12:07 -04:00
Nathan Shively-Sanders 0eb0fb6d72 Change baseline name to avoid case-only conflict
Windows hates this one weird trick! (And humans are mightily confused by
it)
2020-09-10 13:17:40 -07:00
Nathan Shively-Sanders b7c598ea39
Use ad-hoc code for nested destructuring in require (#40188)
* Use ad-hoc code for nested destructuring in require

Nested destructuring doesn't really map to ES imports:

```js
const { utils: { nub, intercalate } } = require('./monopackage')
```

Previously, isRequireVariableDeclaration walked up binding elements
until it reached a variable declaration. This change instead only walks
up one binding element and stops. Then it's not bound as an alias and
uses the checker-only code to produce types for the nested-imported
identifiers.

Fixes #40143

* revert binder formatting change
2020-09-10 13:07:58 -07:00
Nathan Shively-Sanders e350c357d2
Alias for module.exports.x = x (#40228)
* Alias for `module.exports.x = x`

This fixes #40155 in a surprisingly small amount of code.

* Treat any aliasable expression as an alias

* test internal references to exported class
2020-09-10 11:23:48 -07:00
Wesley Wigham 683979246f
Fix JS declaration emit for acessors in a class/interface merge (#40456) 2020-09-10 10:39:41 -07:00
Anders Hejlsberg 6f0c91c4cb
Template literal types and mapped type 'as' clauses (#40336)
* Initial implementation of string template types

* Accept new API baselines

* Accept new baselines

* Unified checking for large cross product union types

* Accept new baselines

* Ensure errors from union type resolution are reported

* Accept new baselines

* Compute constraints for string template types

* Support `as T` clause in mapped types

* Accept new API baselines

* Add missing semicolon

* Add checking of `as T` clauses

* Support casing modifiers in string template types

* Accept new baselines

* Bump keyword maximum length

* fix anders

* Revert "fix anders"

This reverts commit b3178d4618.

* Properly handle 'as T' clause with keyof for mapped type

* Fix lint error

* Single character inferences and anchored end span matching

* Fewer array copy operations in template literal type resolution

* Handle cases where 'as T' maps multiple properties onto one

* Fix lint error

* Store key type instead of type mapper in MappedSymbol

* No constraint on `in T` type when `as N` clause present

* Rename from TemplateType to TemplateLiteralType

* Accept new API baselines

* Add tests

* Accept new baselines

* Address CR feedback

* Accept new API baselines

Co-authored-by: Erich Gamma <egamma@microsoft.com>
2020-09-09 17:23:22 -10:00
Wenlu Wang ee5f51bc0f
Add see tag support (#39760)
* Add see tag parser

* add baseline

* fix symbol resolve

* add more case

* fix unittests

* improve tests and parser

* accept baseline

* Adopt package-lock.json and npm ci

* Add a workflow to update package-lock.json daily

* Git ignore package-lock.json and forcibly update in workflow

* Update bot email address

* Delete extra npm update

* Update package-lock.json

* Add compactDisplay and signDisplay to NumberFormatOptions (#40039)

* Fix typo in (Readonly)Set.keys comment (fixes #40164) (#40176)

* fix(26325): use a unique name for reserved words in 'constructor like' function name (#39684)

* fix(25770): add diagnostic message for the possible mapped type used as an index (#39973)

* fix(31046): add new diagnostic message for incompatible constructor signature (#40073)

* Update package-lock.json

* Update package-lock.json

* Add rename support

* Accpet baseline

* wip

* fix anders

* Revert "fix anders"

This reverts commit b3178d4618.

* Fix call hierarchy item serialization and server tests (#40348)

* Avoid error

* accept baseline

* Add more tests

* Add signature name resolve

Co-authored-by: Andrew Casey <andrew.casey@microsoft.com>
Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
Co-authored-by: Neil Kistner <neil.kistner@gmail.com>
Co-authored-by: cherryblossom000 <31467609+cherryblossom000@users.noreply.github.com>
Co-authored-by: Alexander T <alexander.tarasyuk@outlook.com>
Co-authored-by: Erich Gamma <egamma@microsoft.com>
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
2020-09-09 10:45:09 -07:00
Alex T 15084465b7
fix(40222): fix crash on using destructuring in a catch clause (#40240) 2020-09-08 11:49:45 -07:00
Orta Therox fa89ce6158
Remove assignability cases in getNarrowedType + an isArray improvement for readonly arrays (#39258)
* Explore using a different isArray declaration

* Add tests and the new isArray definition

* Baseline updates

* Upda the isArray type
2020-09-08 14:43:48 -04:00
Anders Hejlsberg cea1cfb82e
Consistently error when rest element isn't last in tuple type (#40254)
* Consistently error when rest element isn't last in tuple type

* Add regression test

* Accept new baselines

* Stricter circular recursion check in type inference

* Revert "Stricter circular recursion check in type inference"

This reverts commit 80e6df6230.

* Revert "Accept new baselines"

This reverts commit 355706dadc.

* Accept new baselines
2020-09-08 07:14:16 -10:00
Wesley Wigham 155610e114
Better support class instances assigned to the module object for JS declarations (#40037)
* Better support class instances assigned to the module object for JS declarations

* Extract constant
2020-09-05 02:23:12 -07:00
Alexander T 09d68efae1
fix(28516): forbid using async modifier with the abstract modifier (#39963) 2020-09-04 14:59:53 -07:00
Nathan Shively-Sanders b0011feee1
Checkjs implies allowjs (#40275)
* Passing --checkJs always sets --allowJS

Even if you have `"allowJs": false`. This is not a useful combination.

Changing this makes the compiler more friendly and easier to describe.

* only set allowjs if not explicitly set

* remove stray newline

* restore bad config error

* use an accessor function instead
2020-09-01 10:16:08 -07:00
Nathan Shively-Sanders d572dcb272
Fix crash intersecting dynamic import w/esModuleInterop (#40249)
* Fix crash intersecting dynamic import w/esModuleInterop

The dynamic import shim creates a symbol without some properties that
the intersection-creating code assumes are present as of #38673.

This PR adds the smallest possible set of properties to avoid the crash.
I'm not sure what others would be good to add.

* Use symbol's declarations instead

* Fix getResolvedMembersOrExportsOfSymbol instead

* comment from code review
2020-09-01 09:10:36 -07:00
Nathan Shively-Sanders 378083fcec
Nested assignment to a require alias isn't a declaration (#40186)
This is not something we can type correctly, and doesn't work in
Typescript either. Better to ignore it in JS.
2020-09-01 08:20:56 -07:00
Ron Buckton 10fb9c9381
Treat trailing 'void' as optional for assignability (#40231) 2020-08-28 09:12:09 -07:00
Kyℓe Hensel c5446d1a47
don't emit "unused @ts-expect-error" in unchecked js files (#40046)
* don't emit unused ts-expect-error in unchecked js files

* simplify code
2020-08-25 11:04:23 -07:00
Nathan Shively-Sanders 4aadd5af41
Fix commonjs require of ES export (#40221)
The commonjs-specific code for resolving access expressions on `require`
assumes a fake commonjs export. For real exports, it needs to call
resolveSymbol since it's outside the normal alias-resolving
infrastructure.
2020-08-24 12:37:25 -07:00
Ron Buckton 598e9b2e88
Allow trailing params of 'undefined', 'unknown', and 'any' to be optional in non-strictNullChecks JS (#40057) 2020-08-20 13:38:14 -07:00
Nathan Shively-Sanders 55ca5e91b9
Fixes crash on chained property access on require (#40135)
From the user tests:

```js
const x = require('y').z.ka
```

would cause the crash because I forgot to call
getLeftMmostPropertyAccessExpression in one place.

Note that this doesn't fix the alias, it just stops the crash.
2020-08-19 12:59:22 -07:00
Wesley Wigham 44d2350e5f
Fix tuple name homogeneity check (#40118) 2020-08-19 12:08:17 -07:00
Nathan Shively-Sanders c3d41bbb73
Alias for commonjs require in JS (#39770)
* First attempt at aliases for require

* test+initial support for const x=require

* 1st round of baseline improvements

* 2nd round of baseline updates

* support property access after require

* check @type tag on require

* forbid expando missing namespaces on aliases

taken from #39558 as soon as it was created

* accept error baselines that are good, actually

* Scribbling on d.ts emit code

* use getSpecifierForModuleSymbol

* hideous hack for module.exports of aliases

* Fix module.exports.x --> export list emit

* fix isLocalImport predicate

* require only creates aliases in JS

* re-handle json imports

* update fourslash baseline

* Cleanup in the checker

1. Simplify alias resolution.
2. Simplify variable-like checking.
3. Make binding skip require calls with type tags -- they fall back to
the old require-call code and then check from there.

I haven't started on the declaration emit code since I don't know what
is going on there nearly as well.

* Function for getting module name from require call

* First round of cleanup plus a new test

Found one missing feature, not sure it's worth adding.

* more small cleanup

* more cleanup, including lint

* use trackSymbol, not serializeTypeForDeclaration

* Code review comments, plus remove unneeded code

Ad-hoc type reference resolution for `require` isn't needed anymore.

* find all refs works

* remove old ad-hoc code

* make it clear that old behaviour is not that correct

* update api baselines

* remove outdated comment

* PR feedback

1. Fix indentation
2. Add comment for exported JSON emit
3. Add test case for nested-namespace exports.

* add a fail-case test (which passes!)
2020-08-17 14:00:37 -07:00
Eli Barzilay 620e260576 Avoid the double-symbol trick for enums
Nameless jsdoc typedefs have their exportedness controlled by the
exportedness of the location they pull their name from.

Fixes #33575.
2020-08-12 18:40:57 -04:00
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