Description
TypeScript Version: 3.9.2
Search Terms: organizeImports, imports, undefined
Code
import {
stat,
statSync,
} from "fs";
export function fakeFn() {
stat;
statSync;
}
Run through ts.organizeImports
.
Expected behavior:
import { stat, statSync } from "fs";
export function fakeFn() {
stat;
statSync;
}
Actual behavior:
import { undefinedstat, statSyncundefined } from "fs";
export function fakeFn() {
stat;
statSync;
}
Doesn't happen if there's only one import:
import { stat } from "fs";
export function fakeFn() {
stat;
}
Only happens at the start and end of the block:
import {
lstatSync,
stat,
statSync,
} from "fs";
export function fakeFn() {
lstatSync;
stat;
statSync;
}
will yield:
import { undefinedlstatSync, stat, statSyncundefined } from "fs";
export function fakeFn() {
lstatSync;
stat;
statSync;
}
Don't think it can run the programmatic API.
Doesn't have TS 3.9 yet.
I setup a demo repo with both TS 3.8.7 and TS 3.9.2 here:
https://github.com/mathieumg/organize-imports/blob/v3.8.3/index.js yields:
TypeScript 3.8.3
Text Changes [
{
span: { start: 0, length: 55 },
newText: 'import { lstatSync,stat,statSync } from "fs";\r\n'
}
]
Failure? NO
and https://github.com/mathieumg/organize-imports/blob/v3.9.2/index.js yields:
TypeScript 3.9.2
Text Changes [
{
span: { start: 0, length: 55 },
newText: 'import {undefinedlstatSync,\r\nstat,\r\nstatSyncundefined} from "fs";\r\n'
}
]
Failure? YES
It's a simplified version of https://github.com/simonhaenisch/prettier-plugin-organize-imports/blob/f590b06c382aeeeeb3dadd9191c31aab9284d68c/index.js (which my use case emanates from), so it's not impossible they could be misusing the Language Service API. (but I wouldn't know) I imagine it could also be there was an undocumented breaking change there.
Possibly Related Issues: #38507