2025 Commits

Author SHA1 Message Date
Daniel Rosenwasser
0414deeaaf
Merge pull request #48954 from a-tarasyuk/fix/48948
fix(48948): constructor can't be the name of class accessors and generators
2022-05-13 12:20:45 -07:00
Jack Works
b689cd0aa9
feat: support error when comparing with object/array literals (#45978)
* feat: support error when comparing with object/array literals

* chore: include regexp, function and class literal

* chore: include regexp, function and class literal

* test: update baseline

* fix: baseline
2022-05-12 15:45:22 -07:00
Oleksandr T
c300fea325
fix(7410): allow using JSXElement as JSXAttributeValue (#47994) 2022-05-11 14:47:35 -07:00
Sheetal Nandi
6ee549075b
Identify when file name is matched by default include spec (#49040)
Fixes #43679
2022-05-10 10:34:03 -07:00
Ryan Cavanaugh
1a4643bdce
Flag resolution mode assertions in non-nightly builds (#49002)
* Flag resolution mode assertions in non-nightly builds

* Add checker check
2022-05-06 16:31:40 -07:00
Wesley Wigham
8e433cda3d
Allow export map entries to remap back to input files for a program (#47925)
* Allow export map entries to remap back to input files for a program

* Fix file casing issues on windows

* Implement abiguity error, doesnt quite work

* Refine selection logic in error case to use getCommonSourceDirectory, add more tests
2022-05-05 12:53:56 -07:00
Oleksandr T
538d6ce828 fix(48948): disallow constructor name in class accessors and generators 2022-05-04 21:04:23 +03:00
Daniel Rosenwasser
5f9c9a6ccf
Start Node ESM stable version at Node16 (#48879)
* Remove Node12, add Node16.

* Accepted baselines.

* Refactor checking for top-level await, give a better error message in CJS files.

* Accepted baselines.

* Stop erroring on JSON module imports in node ESM since they're no longer experimental.

* Accepted baselines.

* More refactoring, do the same checks for for-await loops.

* Accepted baselines.

* Adjust phrasing to permit for-await on CJS error.

* Accepted baselines.

* Accepted baselines.

* Fix lints.
2022-05-03 16:29:40 -07:00
Daniel Rosenwasser
3b8b2078a3
Temporarily revert unconstrained type parameter strictness in TS 4.7 (#48923)
* Revert a change around allowing unconstrained type parameters to '{}'.

* Accepted baselines.
2022-05-02 15:49:16 -07:00
Oleksandr T
99ffa394a8
fix(48759): throw an error on using import expression with type arguments (#48787) 2022-04-29 14:19:20 -07:00
Daniel Rosenwasser
18b08fc7c9
Use same error for iteration in <=ES5 (#48881)
* Use the same error for iterating over an Iterable in ES5 or lower.

* Accepted baselines.
2022-04-29 10:45:20 -07:00
Nicola Dardanis
d45012c5e2
Add JS-specific diagnostic message for resolve() in Promise where type argument can't be inferred (#48533)
* change error message on Promise

* fix(46570): Unhelpful Promise type argument hint in JS file

* refactor: Reword void Promise message for JSDoc type hint to provide better feedback

Co-authored-by: Osa <osaimola@gmail.com>
2022-04-27 11:55:35 -07:00
Anders Hejlsberg
8f6e626d1c
Permit type alias variance annotations only for certain object types (#48589)
* Permit type alias variance annotations only for certain object types

* Accept new baselines
2022-04-06 14:04:42 -07:00
Ron Buckton
7da80d79e2
Add 'extends' clause to 'infer' type (#48112)
* Add 'extends' clause to 'infer' type

* Revise parse for infer..extends, improve parenthesizer

* More aggressive parens to match existing DT tests

* tests 'infer' constraint using outer type parameter

* Adds a test showing 'infer' cannot reference other 'infer' in same 'extends'

* Emit extends clause for synthetic infer typesduring declaration emit
2022-04-05 12:35:28 -07:00
Adam Foxman
41aca7c337
Add a new compiler option moduleSuffixes to expand the node module resolver's search algorithm (#48189)
* Add moduleSuffixes compiler option and related tests. Update baselines for compiler options tests.

* Add a flag to the command-line parser which allows "list" params to preserve "falsy" values such as empty strings. Falsy values are normally stripped out.

* Add tests. Rework resolver logic to only run module-suffix code when needed.

* PR feedback

* Add test

* Remove unnecessary conditional.
2022-03-30 15:23:26 -07:00
Wesley Wigham
8cd4b7a5da
Make the unconstrained type parameter and {} assignability rule not apply under strictNullChecks (#48366)
* Make the unconstrained type parameter and {} assignability rule not apply under strictNullChecks

* Fix lint, PR feedback
2022-03-23 16:22:40 -07:00
Anders Hejlsberg
6cb58d382f
Optional variance annotations (#48240)
* Simplify getVariancesWorker and associated logic

* Accept new API baselines

* Add 'in' and 'out' modififers / add modifiers to type parameters

* Check variance annotations

* Update test runner

* Accept new API baselines

* Allow variance annotations only on certain type parameters

* Add deprecated implementation of createTypeParameterDeclaration

* Accept new API baselines

* Report variance markers as 'sub-XXX' and 'super-XXX'

* Add tests

* Accept new baselines
2022-03-22 11:31:08 -07:00
Pablo Sabater Jiménez
50a4b92bca
fix(48053) Description of tsBuildInfoFile is misleading in generated tsconfig.json (#48072)
* add check for path default value

* fix wrong tsBuildInfoFile description

* updated files to file
2022-03-22 10:35:47 -07:00
Andrew Branch
df1faa09b8
Add isolatedModules error for ambiguous imports referenced in decorator metadata (#42915)
* Add isolatedModules error for ambiguous imports referenced in decorator metadata

* Improve test and accept baselines

* Error only for es2015+

* Add namespace import to error message as workaround

* Add codefix

* Fix merge fallout
2022-03-17 12:00:23 -07:00
Jesse Trinity
111ca92646
Fix parser regression for bad related diagnostic on missing matching brackets (#44158)
* Revert "Revert #43460 and #40884 (#44175)"

This reverts commit 57704348914d046e6db8907f6e44e7937b3bcb5b.

* fix missing opening brace match error

* refactor parseExpectedMatchingBrackets

* use getNodePos

* accept baselines

* delete mistakenly added files

* Revert getNodePos addition

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2022-03-15 17:29:41 -07:00
Wesley Wigham
d1fa945261
Add moduleDetection compiler flag to allow for changing how modules are parsed (#47495)
* Add moduleDetection compiler flag to allow for changing how modules are parsed

The default setting is 'auto', where JSX containing files under react-jsx and react-jsxdev are
always parsed as modules, and esm-format files under module: node12+ are always parsed as modules,
in addition to the 'legacy' detection mode's conditions for other files. (Declaration files are exempt from
these new conditions)

The 'legacy' mode preserves TS's behavior prior to the introduction of this flag - a file is
parsed as a module if it contains an import, export, or import.meta expression.

In addition, there is a 'force' mode that forces all non-declaration files to be parsed as modules.
(Declaration files are still only modules if they contain a top-level import or export.)

This technically breaks the parser API, but it's kinda-sorta backwards compatible so long
as you don't need the functionality associated with more recent compiler flags.

* Fix post-merge lint

* Rename function

* Update default value documentation

* PR feedback

* Fix lint and typo
2022-03-11 10:36:00 -08:00
Jack Bates
94a7ec17e0
🤖 Sync option descriptions <- website (#46465)
* 🤖 Sync option descriptions <- jablko/TypeScript-Website@a9df5139f2

https://github.com/jablko/TypeScript-Website/actions/runs/1953829438

* Update Baselines and/or Applied Lint Fixes

Co-authored-by: jablko/TypeScript-Website:.github/workflows/sync-option-descriptions.yml <bot@typescriptlang.org>
Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2022-03-08 15:55:13 -08:00
Wesley Wigham
ea0db9e031
Add import assertions to type only imports and import types to force the resolution mode of the specifier (#47807)
* Add import assertions for type-only imports and import types to change resolver modes

* By popular request, only allow mode assertions on top-level type only imports

* Add specifier options parameter to specifier generation
2022-03-02 08:54:10 -08:00
Gabriela Araujo Britto
733eff2b10
Revert "Use related spans for "implement abstract class" errors" (#48029) 2022-02-24 16:15:31 -08:00
Gabriela Araujo Britto
4b395c6097 Merge branch 'related-spans-for-implement-abstract-class-error' of https://github.com/FlyingPumba/TypeScript into FlyingPumba-related-spans-for-implement-abstract-class-error 2022-02-24 16:11:03 -08:00
Josh Goldberg
92204983f4
Standardized aka.ms links for tsc and tsconfig (#47129)
* Standardized aka.ms links for tsc and tsconfig

* Three missed baselines

* Three last baselines

* Went back to aka.ms/tsconfig
2022-02-18 12:09:15 -08:00
Anders Hejlsberg
5afbfbcbd0
Instantiation expressions (#47607)
* Permit type arguments in references to generic functions

* Accept new baselines

* Delete pointless fourslash test

* Fix lint issue

* Finalize implementation

* Add tests

* Accept new baselines

* Properly handle instantiation of instantiation expression types

* Accept new API baselines

* Fix lint error

* Add more tests

* Properly handle unions/intersections of generic types

* Add more tests

* More permissive parsing of type arguments in member expressions

* Update tests

* Accept new baselines
2022-02-16 13:27:16 -08:00
Wesley Wigham
67172e41c2
Triple-slash reference type directives can override the import mode used for their resolution (#47732)
* Triple-slash reference type directives can override the import mode used for their resolution

They now use the file's default mode by default, rather than always using commonjs. The new arguments to the
reference directive look like:

```ts
///<reference types="pkg" resolution-mode="require" />
```

or

```ts
///<reference types="pkg" resolution-mode="import" />
```

* Omit redundant import modes in emitter

* Add test for #47806

* Add server test for triple-slash reference mode overrides

* Move FileReference mode into helper

* Update tests/cases/conformance/node/nodeModulesTripleSlashReferenceModeOverride3.ts

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2022-02-15 13:53:11 -08:00
Anders Hejlsberg
44e827bcc9
Eliminate redundant or meaningless elaborations in type relations (#47738)
* Eliminate redundant or meaningless elaborations in type relations

* Accept new baselines

* Add resetErrorInfo (though, oddly, shouldn't be necessary)

* Less aggressive reduction in second pass union/intersection checks

* Accept new baselines

* Restructure and back off a little bit more

* Only cache union/intersection relations once

* Accept new baselines

* Properly cache identity relations, clean up error reporting

* Move more logic to cached side of relation checks

* Optimize and remove more redundant elaborations

* Accept new baselines

* Remove unnecessary error state capture

* More optimizing

* Cache isWeakType computation

* Revert "Cache isWeakType computation"

This reverts commit 25a71c4de61f6366ffac080d19685dcb200f42b9.

* Address CR feedback

* Accept new baselines
2022-02-15 18:30:29 +00:00
Andrew Branch
0655f32e05
Add missing isolatedModules error for export import (#47838)
* Add missing isolatedModules error for `export import`

* Update existing baseline
2022-02-10 16:13:04 -08:00
Oleksandr T
b456702755
feat(11378): check param names in JSDoc (#47257) 2022-02-10 10:02:07 -08:00
islandryu
95c22d1750
fix(47076):Fix error term of declaration in modules (#47087)
* Fix error term of declaration in modules

* fix test

* change error code of "An import declaration can only be used at the top level of a module."

* Separate js and ts files for export errors in module.

* Change non-top-level error in namespace

* format

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2022-02-09 13:19:30 -08:00
Andrew Branch
9c3b41d3cc
Refactor named imports to default instead of namespace when esModuleInterop is on and module is an export= (#47744) 2022-02-04 17:11:25 -08:00
Ron Buckton
3328feb799
Use 'static {}' for static fields when available and useDefineForClassFields is false (#47707) 2022-02-04 12:34:29 -08:00
Andrew Branch
e9092f3723
Proposal: simplify auto import descriptions (#47631)
* Simplify import fix descriptions

* Update tests

* Fix new test
2022-01-27 10:21:08 -08:00
Andrew Branch
0d3ff0cce8
Add codefix and completions for promoting existing type-only imports to non-type-only (#47552)
* Import fix

* Wire up completions, add sorting to fix

* Fix overlapping changes when there’s only one import specifier

* Update API baseline

* Add sorting and filtering back to UMD fix
2022-01-26 15:07:41 -08:00
Wesley Wigham
bae0f50818
Fix import assertion occurrences crash and make import assertion parsing more generous (#47535) 2022-01-20 14:08:47 -08:00
mickey-stringer
9e2b7ad0d8
fix(47492): more detailed parseTryStatement error message (#47504)
* more detailed parseTryStatement error message

* move custom error to diagnosticMessages.json

* update error code

Co-authored-by: mickey-stringer <fcstring31@yahoo.com>
2022-01-19 15:32:47 -08:00
Orta Therox
113a681aee
Do not show the additional file/errors table when there's 1 file with many errors (#47345)
* Use relative paths for the end of compile report

* Have a tighter suffix for multiple errors in one file

* Review feedback

* Refactors, and adds color

* Update baselinies
2022-01-19 11:56:27 +00:00
Josh Goldberg
b7fee7f1ee
Allowed non-this, non-super code before super call in derived classes with property initializers (#29374)
* Allowed non-this, non-super code before super call in derived classes

Fixes #8277.

It feels wrong to put a new `forEachChild` loop in the checker, though in the vast majority of user files this will be a very quick one. Is there a better way to check for a reference to `super` or `this`?

* Used new isNewThisScope utility and dummy prop in baselines

* Accounted for parameters and get/set accessor bodies

* Accounted for class extensions

* (node|statement)RefersToSuperOrThis wasn't checking root level scope boundaries

```ts
function () {
    return this;
}
```

It was immediately going to `ts.forEachChild` so the statement itself wasn't being counted as a new `this` scope.

* Better 'references' name and comments; accounted for more method edge case

* Limited super calls to root-level statements in constructor bodies

As per discussion in the issue, it would be ideal to consider any block that always ends up calling to super() the equivalent of a root-level super() statement. This would be valid:

```ts
foo = 1;
constructor() {
    condition() ? super(1) : super(0);
    this.foo;
}
```

...as it would compile to the equivalent of:
```ts
function () {
    condition() ? super(1) : super(0);
    this.foo = 1;
    this.foo;
}

That change would a bit more intense and I'm very timid, so leaving it out of this PR. In the meantime the requirement is that the super() statement must itself be root-level.

* Fixed error number following 'master' merge

* Added decorator test cases

* Again allowed arrow functions

* Accepted new baselines

* Added allowance for (super())

* Reworked emitter transforms for ES this binding semantics

In trying to adjust to rbuckton's PR feedback, this orders derived class constructor bodies into five sections:

1. Pre-`super()` code
2. The `super()` call itself
3. Class properties with initializers
4. Parameter properties
5. The rest of the constructor

I've looked through the updated baselines and it looks like they're generally better than before. Within the existing test cases that result in semantic errors for `this` access before `super`, several previously resulted in a global `_this` being created; now, they correctly defer referring to `_this` until it's assigned to `_super.call(this) || this`.

* Used skipOuterExpressions when diving for super()s; fix prop ordering

* Allow direct var _this = super() when no pre-super() statements; lint fixes

* Always with the TSLint

* One last touchup: skipOuterExpressions in es2015 transformer

* Fixed new lint complaint in utilities.ts

* Again added a falls-through; it'd be swell if I could run linting locally

* This time I think I got it

* Well at least the error is a different one

* Undid irrelevant whitespace changes

* Mostly addressed private/field issues

* Accepted derivedClassSuperProperties baseline

* Lint fix, lovely

* Remove now-unnecesary comment

* First round of feedback

* Moved prologue statements to start of statements

* Added consideration for super statements in loops and the like

* Ordering and a _this_1 test

* Missed the one change I needed...

* First round of feedback corrections

* Feedback round two: statements

* Feedback: used more direct statements

* Fixed classFields emit to not duplicate temp variables

* Refactored es2015 helper to be less overloaded

* Accounted for parentheses

* Simpler feedback: -1, and emptyArray

* Next feedback: superStatementIndex

* Feedback: simplified to no longer create slice arrays

* Adjusted for default and rest parameters

* Added test case for commas

* Corrected comment ranges

* Handled comments after super, with tests

* Fixed Bad/Late super baselines

* Remove unused param and unnecessary baseline comments

Co-authored-by: Orta Therox <orta.therox@gmail.com>
Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2022-01-13 20:29:37 -08:00
Ryan Bargholz
7a12909ae3
fix(45713) Improve error report summaries (#45742)
* Improve error report summaries (#45713)

* fixup! Improve error report summaries (#45713)

* fixup! fixup! Improve error report summaries (#45713)

* Adds support for handling localization renaming the 'files' header due to localization

* fixup! Adds support for handling localization renaming the 'files' header due to localization

 - Fixed baseline error
 - Fixed linter error

Co-authored-by: Orta <git@orta.io>
Co-authored-by: Orta Therox <ortam@microsoft.com>
2021-12-07 10:50:44 +00:00
Yuki Osaki
1f275d705d
"No repeated property names" error in object literals is duplicated in strict mode (#46929)
* "No repeated property names" error in object literals is duplicated in strict mode

* fix indent
2021-12-06 10:22:28 -08:00
Oleksandr T
c5d9200ec6
feat(46986): offer QF for using await outside of async context (#46994) 2021-12-03 12:36:19 -08:00
Wesley Wigham
de23842e45
Allow import assertions on esm imports under module: nodenext (#46630)
* Allow import assertions on esm imports under module: nodenext

* Changes to copy

Co-authored-by: Andrew Branch <andrew@wheream.io>
2021-11-02 15:34:37 -07:00
Andrew Branch
eeaa595196
Enable auto imports in member snippet completions (#46592) 2021-10-29 14:43:32 -07:00
Wesley Wigham
28e3cd3a80
Add error on new module/moduleResolution modes when used in non-nightly TS (#46557)
* Add error on new module/moduleResolution modes when used in non-nightly TS

* Update diagnostic
2021-10-29 11:46:19 -07:00
Gabriela Araujo Britto
9cdbb7248b
Improve errors on module: node12 and extensionless relative imports (#46486)
* add new error + suggestions

* push down assert defined

* remove comment

* fix esm module import detection, update baselines

* add and update new tests

* fix review comments

* remove renamed baseline references

* update node modules test baselines

* fix error message, add new tests

* update old tests with new error message
2021-10-29 10:25:03 -07:00
Wesley Wigham
abfd537503
Support resolveJsonModule in new module modes (#46434)
* Support resolveJsonModule in new module modes

* Formatting feedback
2021-10-27 12:30:06 -07:00
Oleksandr T
ce676d0963
fix(46433): forbid using keywords as parameter names (#46459) 2021-10-22 09:58:01 -07:00
Nathan Shively-Sanders
8d715ff53e
Error on mapped type w/properties (#46346)
* Error on mapped types with properties

1. Error on properties of type literals with computed properties whose name is a
binary expression with `in`, because that's a good sign of a mapped
type.
2. Parse following properties on mapped types, and error on them.
3. Stop checking computed property names in (1) to avoid producing
errors based on misinterpreting mapped type syntax as an expression.

* add comment in types.ts

* Update API again

* Check interfaces and classes too

* Add missed check in updateMappedTypeNode
2021-10-18 09:00:00 -07:00