Skip to content

Commit ff60520

Browse files
committed
Merge branch 'master' into referencesDogfood_1
2 parents f24d57f + abbb79f commit ff60520

File tree

63 files changed

+361
-985
lines changed

Some content is hidden

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

63 files changed

+361
-985
lines changed

src/compiler/core.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,12 +1311,13 @@ namespace ts {
13111311
* the same key with the given 'makeKey' function, then the element with the higher
13121312
* index in the array will be the one associated with the produced key.
13131313
*/
1314-
export function arrayToMap<T>(array: ReadonlyArray<T>, makeKey: (value: T) => string): Map<T>;
1315-
export function arrayToMap<T, U>(array: ReadonlyArray<T>, makeKey: (value: T) => string, makeValue: (value: T) => U): Map<U>;
1316-
export function arrayToMap<T, U>(array: ReadonlyArray<T>, makeKey: (value: T) => string, makeValue: (value: T) => T | U = identity): Map<T | U> {
1314+
export function arrayToMap<T>(array: ReadonlyArray<T>, makeKey: (value: T) => string | undefined): Map<T>;
1315+
export function arrayToMap<T, U>(array: ReadonlyArray<T>, makeKey: (value: T) => string | undefined, makeValue: (value: T) => U): Map<U>;
1316+
export function arrayToMap<T, U>(array: ReadonlyArray<T>, makeKey: (value: T) => string | undefined, makeValue: (value: T) => T | U = identity): Map<T | U> {
13171317
const result = createMap<T | U>();
13181318
for (const value of array) {
1319-
result.set(makeKey(value), makeValue(value));
1319+
const key = makeKey(value);
1320+
if (key !== undefined) result.set(key, makeValue(value));
13201321
}
13211322
return result;
13221323
}
@@ -1337,8 +1338,9 @@ namespace ts {
13371338
* @param array the array of input elements.
13381339
*/
13391340
export function arrayToSet(array: ReadonlyArray<string>): Map<true>;
1340-
export function arrayToSet<T>(array: ReadonlyArray<T>, makeKey: (value: T) => string): Map<true>;
1341-
export function arrayToSet(array: ReadonlyArray<any>, makeKey?: (value: any) => string): Map<true> {
1341+
export function arrayToSet<T>(array: ReadonlyArray<T>, makeKey: (value: T) => string | undefined): Map<true>;
1342+
export function arrayToSet<T>(array: ReadonlyArray<T>, makeKey: (value: T) => __String | undefined): UnderscoreEscapedMap<true>;
1343+
export function arrayToSet(array: ReadonlyArray<any>, makeKey?: (value: any) => string | __String | undefined): Map<true> | UnderscoreEscapedMap<true> {
13421344
return arrayToMap<any, true>(array, makeKey || (s => s), () => true);
13431345
}
13441346

src/compiler/utilities.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6323,4 +6323,9 @@ namespace ts {
63236323
export function isStringLiteralLike(node: Node): node is StringLiteralLike {
63246324
return node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NoSubstitutionTemplateLiteral;
63256325
}
6326+
6327+
/** @internal */
6328+
export function isNamedImportsOrExports(node: Node): node is NamedImportsOrExports {
6329+
return node.kind === SyntaxKind.NamedImports || node.kind === SyntaxKind.NamedExports;
6330+
}
63266331
}

src/harness/unittests/organizeImports.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,24 @@ import D from "lib";
247247
},
248248
libFile);
249249

250+
testOrganizeImports("Unused_false_positive_shorthand_assignment",
251+
{
252+
path: "/test.ts",
253+
content: `
254+
import { x } from "a";
255+
const o = { x };
256+
`
257+
});
258+
259+
testOrganizeImports("Unused_false_positive_export_shorthand",
260+
{
261+
path: "/test.ts",
262+
content: `
263+
import { x } from "a";
264+
export { x };
265+
`
266+
});
267+
250268
testOrganizeImports("MoveToTop",
251269
{
252270
path: "/test.ts",

0 commit comments

Comments
 (0)