Skip to content

Commit d537b79

Browse files
authored
Merge release-2.1 into master (#12157)
* Update LKG * Update version * Update LKG * Skip overloads with too-short function parameters If the parameter of an overload is a function and the argument is also a function, skip the overload if the parameter has fewer arguments than the argument does. That overload cannot possibly apply, and should not participate in, for example, contextual typing. Example: ```ts interface I { (a: number): void; (b: string, c): void; } declare function f(i: I): void; f((x, y) => {}); ``` This code now skips the first overload instead of considering. This was a longstanding bug but was only uncovered now that more functions expressions are context sensitive. * Test skip overloads w/too-short function params 1. Update changed baseline. 2. Add a new test with baseline. * Minor style improvements * Ignore optionality when skipping overloads * Do not use contextual signatures with too few parameters * isAritySmaller runs later: getNonGenericSignature * rewrite void-returning statements in constructors that capture result of super call (#11868) * rewrite void-returning statements in constructors that capture result of super call * linter * Update LKG * Fix emit inferred type which is a generic type-alias both fully and partially fill type parameters * Add tests and baselines * Skip trying to use alias if there is target type * Update baselines * Add diagnostics to remind adding tsconfig file for certain external project (#11932) * Add diagnostics for certain external project * Show tsconfig suggestion * fix lint error * Address pr * fix comment * Update error message * Flag for not overwrite js files by default without generating errors (#11980) * WIP * Properly naming things * refactor * apply the option to all files and check out options * Fix typo * Update LKG * lockLinter * use local registry to check if typings package exist (#12014) (#12032) use local registry to check if typings package exist * Add test for #11980 (#12027) * add test for the fix for overwrite emitting error * cr feedback * enable sending telemetry events to tsserver client (#12034) (#12051) enable sending telemetry events * Update LKG * Reuse subtree transform flags for incrementally parsed nodes (#12088) * Update LKG * Update version * Update LKG * Do not emit "use strict" when targeting es6 or higher or module kind is es2015 and the file is external module * Add tests and baselines * [Release 2.1] fix11754 global augmentation (#12133) * Exclude global augmentation from module resolution logic * Address PR: check using string literal instead of NodeFlags.globalAugmentation * Remove comment
1 parent 4dc58dd commit d537b79

File tree

44 files changed

+549
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+549
-7
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11493,7 +11493,7 @@ namespace ts {
1149311493
function checkJsxOpeningLikeElement(node: JsxOpeningLikeElement) {
1149411494
checkGrammarJsxElement(node);
1149511495
checkJsxPreconditions(node);
11496-
// The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import.
11496+
// The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import.
1149711497
// And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error.
1149811498
const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
1149911499
const reactNamespace = getJsxNamespace();

src/compiler/program.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ namespace ts {
476476
return resolveModuleNamesWorker(moduleNames, containingFile);
477477
}
478478

479-
// at this point we know that either
479+
// at this point we know that either
480480
// - file has local declarations for ambient modules
481481
// OR
482482
// - old program state is available
@@ -670,7 +670,7 @@ namespace ts {
670670
}
671671

672672
const modifiedFilePaths = modifiedSourceFiles.map(f => f.newFile.path);
673-
// try to verify results of module resolution
673+
// try to verify results of module resolution
674674
for (const { oldFile: oldSourceFile, newFile: newSourceFile } of modifiedSourceFiles) {
675675
const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory);
676676
if (resolveModuleNamesWorker) {
@@ -1447,7 +1447,9 @@ namespace ts {
14471447
collectExternalModuleReferences(file);
14481448
if (file.imports.length || file.moduleAugmentations.length) {
14491449
file.resolvedModules = createMap<ResolvedModuleFull>();
1450-
const moduleNames = map(concatenate(file.imports, file.moduleAugmentations), getTextOfLiteral);
1450+
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
1451+
const nonGlobalAugmentation = filter(file.moduleAugmentations, (moduleAugmentation) => moduleAugmentation.kind === SyntaxKind.StringLiteral);
1452+
const moduleNames = map(concatenate(file.imports, nonGlobalAugmentation), getTextOfLiteral);
14511453
const resolutions = resolveModuleNamesReusingOldState(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory), file);
14521454
Debug.assert(resolutions.length === moduleNames.length);
14531455
for (let i = 0; i < moduleNames.length; i++) {

src/compiler/transformers/ts.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,11 @@ namespace ts {
471471
currentSourceFile = node;
472472

473473
// ensure "use strict" is emitted in all scenarios in alwaysStrict mode
474-
if (compilerOptions.alwaysStrict) {
474+
// There is no need to emit "use strict" in the following cases:
475+
// 1. The file is an external module and target is es2015 or higher
476+
// or 2. The file is an external module and module-kind is es6 or es2015 as such value is not allowed when targeting es5 or lower
477+
if (compilerOptions.alwaysStrict &&
478+
!(isExternalModule(node) && (compilerOptions.target >= ScriptTarget.ES2015 || compilerOptions.module === ModuleKind.ES2015))) {
475479
node = ensureUseStrict(node);
476480
}
477481

src/server/typingsInstaller/typingsInstaller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace ts.server.typingsInstaller {
6969
requestId: number;
7070
args: string[];
7171
cwd: string;
72-
onRequestCompleted: RequestCompletedAction
72+
onRequestCompleted: RequestCompletedAction;
7373
};
7474

7575
export abstract class TypingsInstaller {
@@ -380,7 +380,7 @@ namespace ts.server.typingsInstaller {
380380
compilerOptions: request.compilerOptions,
381381
typings,
382382
unresolvedImports: request.unresolvedImports,
383-
kind: server.ActionSet
383+
kind: ActionSet
384384
};
385385
}
386386

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [alwaysStrictModule3.ts]
2+
3+
// module ES2015
4+
export const a = 1;
5+
6+
//// [alwaysStrictModule3.js]
7+
// module ES2015
8+
export var a = 1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/alwaysStrictModule3.ts ===
2+
3+
// module ES2015
4+
export const a = 1;
5+
>a : Symbol(a, Decl(alwaysStrictModule3.ts, 2, 12))
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/alwaysStrictModule3.ts ===
2+
3+
// module ES2015
4+
export const a = 1;
5+
>a : 1
6+
>1 : 1
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [alwaysStrictModule4.ts]
2+
3+
// Module commonjs
4+
export const a = 1
5+
6+
//// [alwaysStrictModule4.js]
7+
"use strict";
8+
// Module commonjs
9+
exports.a = 1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/alwaysStrictModule4.ts ===
2+
3+
// Module commonjs
4+
export const a = 1
5+
>a : Symbol(a, Decl(alwaysStrictModule4.ts, 2, 12))
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/alwaysStrictModule4.ts ===
2+
3+
// Module commonjs
4+
export const a = 1
5+
>a : 1
6+
>1 : 1
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [alwaysStrictModule5.ts]
2+
3+
// Targeting ES6
4+
export const a = 1;
5+
6+
//// [alwaysStrictModule5.js]
7+
// Targeting ES6
8+
export const a = 1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/alwaysStrictModule5.ts ===
2+
3+
// Targeting ES6
4+
export const a = 1;
5+
>a : Symbol(a, Decl(alwaysStrictModule5.ts, 2, 12))
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/alwaysStrictModule5.ts ===
2+
3+
// Targeting ES6
4+
export const a = 1;
5+
>a : 1
6+
>1 : 1
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [alwaysStrictModule6.ts]
2+
3+
// Targeting ES5
4+
export const a = 1;
5+
6+
//// [alwaysStrictModule6.js]
7+
"use strict";
8+
// Targeting ES5
9+
exports.a = 1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/alwaysStrictModule6.ts ===
2+
3+
// Targeting ES5
4+
export const a = 1;
5+
>a : Symbol(a, Decl(alwaysStrictModule6.ts, 2, 12))
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/alwaysStrictModule6.ts ===
2+
3+
// Targeting ES5
4+
export const a = 1;
5+
>a : 1
6+
>1 : 1
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [declarationEmitTypeAliasWithTypeParameters2.ts]
2+
3+
export type Bar<X, Y, Z> = () => [X, Y, Z];
4+
export type Baz<M, N> = Bar<M, string, N>;
5+
export type Baa<Y> = Baz<boolean, Y>;
6+
export const y = (x: Baa<number>) => 1
7+
8+
//// [declarationEmitTypeAliasWithTypeParameters2.js]
9+
"use strict";
10+
exports.y = function (x) { return 1; };
11+
12+
13+
//// [declarationEmitTypeAliasWithTypeParameters2.d.ts]
14+
export declare type Bar<X, Y, Z> = () => [X, Y, Z];
15+
export declare type Baz<M, N> = Bar<M, string, N>;
16+
export declare type Baa<Y> = Baz<boolean, Y>;
17+
export declare const y: (x: Bar<boolean, string, number>) => number;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts ===
2+
3+
export type Bar<X, Y, Z> = () => [X, Y, Z];
4+
>Bar : Symbol(Bar, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 0, 0))
5+
>X : Symbol(X, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 16))
6+
>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 18))
7+
>Z : Symbol(Z, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 21))
8+
>X : Symbol(X, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 16))
9+
>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 18))
10+
>Z : Symbol(Z, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 21))
11+
12+
export type Baz<M, N> = Bar<M, string, N>;
13+
>Baz : Symbol(Baz, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 43))
14+
>M : Symbol(M, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 16))
15+
>N : Symbol(N, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 18))
16+
>Bar : Symbol(Bar, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 0, 0))
17+
>M : Symbol(M, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 16))
18+
>N : Symbol(N, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 18))
19+
20+
export type Baa<Y> = Baz<boolean, Y>;
21+
>Baa : Symbol(Baa, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 42))
22+
>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 3, 16))
23+
>Baz : Symbol(Baz, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 43))
24+
>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 3, 16))
25+
26+
export const y = (x: Baa<number>) => 1
27+
>y : Symbol(y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 4, 12))
28+
>x : Symbol(x, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 4, 18))
29+
>Baa : Symbol(Baa, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 42))
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts ===
2+
3+
export type Bar<X, Y, Z> = () => [X, Y, Z];
4+
>Bar : Bar<X, Y, Z>
5+
>X : X
6+
>Y : Y
7+
>Z : Z
8+
>X : X
9+
>Y : Y
10+
>Z : Z
11+
12+
export type Baz<M, N> = Bar<M, string, N>;
13+
>Baz : Bar<M, string, N>
14+
>M : M
15+
>N : N
16+
>Bar : Bar<X, Y, Z>
17+
>M : M
18+
>N : N
19+
20+
export type Baa<Y> = Baz<boolean, Y>;
21+
>Baa : Bar<boolean, string, Y>
22+
>Y : Y
23+
>Baz : Bar<M, string, N>
24+
>Y : Y
25+
26+
export const y = (x: Baa<number>) => 1
27+
>y : (x: Bar<boolean, string, number>) => number
28+
>(x: Baa<number>) => 1 : (x: Bar<boolean, string, number>) => number
29+
>x : Bar<boolean, string, number>
30+
>Baa : Bar<boolean, string, Y>
31+
>1 : 1
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [declarationEmitTypeAliasWithTypeParameters3.ts]
2+
3+
type Foo<T> = {
4+
foo<U>(): Foo<U>
5+
};
6+
function bar() {
7+
return {} as Foo<number>;
8+
}
9+
10+
11+
//// [declarationEmitTypeAliasWithTypeParameters3.js]
12+
function bar() {
13+
return {};
14+
}
15+
16+
17+
//// [declarationEmitTypeAliasWithTypeParameters3.d.ts]
18+
declare type Foo<T> = {
19+
foo<U>(): Foo<U>;
20+
};
21+
declare function bar(): Foo<number>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts ===
2+
3+
type Foo<T> = {
4+
>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 0, 0))
5+
>T : Symbol(T, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 1, 9))
6+
7+
foo<U>(): Foo<U>
8+
>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 1, 15))
9+
>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 2, 8))
10+
>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 0, 0))
11+
>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 2, 8))
12+
13+
};
14+
function bar() {
15+
>bar : Symbol(bar, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 3, 2))
16+
17+
return {} as Foo<number>;
18+
>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 0, 0))
19+
}
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts ===
2+
3+
type Foo<T> = {
4+
>Foo : Foo<T>
5+
>T : T
6+
7+
foo<U>(): Foo<U>
8+
>foo : <U>() => Foo<U>
9+
>U : U
10+
>Foo : Foo<T>
11+
>U : U
12+
13+
};
14+
function bar() {
15+
>bar : () => Foo<number>
16+
17+
return {} as Foo<number>;
18+
>{} as Foo<number> : Foo<number>
19+
>{} : {}
20+
>Foo : Foo<T>
21+
}
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [declarationEmitTypeAliasWithTypeParameters4.ts]
2+
3+
type Foo<T, Y> = {
4+
foo<U, J>(): Foo<U, J>
5+
};
6+
type SubFoo<R> = Foo<string, R>;
7+
8+
function foo() {
9+
return {} as SubFoo<number>;
10+
}
11+
12+
13+
//// [declarationEmitTypeAliasWithTypeParameters4.js]
14+
function foo() {
15+
return {};
16+
}
17+
18+
19+
//// [declarationEmitTypeAliasWithTypeParameters4.d.ts]
20+
declare type Foo<T, Y> = {
21+
foo<U, J>(): Foo<U, J>;
22+
};
23+
declare type SubFoo<R> = Foo<string, R>;
24+
declare function foo(): Foo<string, number>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts ===
2+
3+
type Foo<T, Y> = {
4+
>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 0, 0))
5+
>T : Symbol(T, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 1, 9))
6+
>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 1, 11))
7+
8+
foo<U, J>(): Foo<U, J>
9+
>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 1, 18))
10+
>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 8))
11+
>J : Symbol(J, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 10))
12+
>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 0, 0))
13+
>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 8))
14+
>J : Symbol(J, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 10))
15+
16+
};
17+
type SubFoo<R> = Foo<string, R>;
18+
>SubFoo : Symbol(SubFoo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 3, 2))
19+
>R : Symbol(R, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 4, 12))
20+
>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 0, 0))
21+
>R : Symbol(R, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 4, 12))
22+
23+
function foo() {
24+
>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 4, 32))
25+
26+
return {} as SubFoo<number>;
27+
>SubFoo : Symbol(SubFoo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 3, 2))
28+
}
29+

0 commit comments

Comments
 (0)