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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 8 additions & 0 deletions
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;
Lines changed: 6 additions & 0 deletions
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+
Lines changed: 7 additions & 0 deletions
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+
Lines changed: 9 additions & 0 deletions
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;
Lines changed: 6 additions & 0 deletions
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+
Lines changed: 7 additions & 0 deletions
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+

0 commit comments

Comments
 (0)