-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.9 Regression: organizeImports
prepends/appends "undefined" when there are 2+ named imports
#38548
Comments
organizeImports
prepends/appends "undefined" when there are 2+ named importsorganizeImports
prepends/appends "undefined" when there are 2+ named imports
I've been digging into this... import { foo,
bar, baz } from "foobar"; import {
foo,
bar, baz } from "foobar"; import {
foo,
bar, baz
} from "foobar"; These all work, but as soon as there's a new line between I could track it down to TypeScript/src/services/textChanges.ts Line 973 in c1f676d
returning an invalid set of changes, like { changes:
[ { span: { start: 8, length: 1 }, newText: undefined },
{ span: { start: 14, length: 4 }, newText: '' },
{ span: { start: 22, length: 1 }, newText: '' },
{ span: { start: 26, length: 1 }, newText: undefined } ] } I can confirm that those are the { changes:
[ { span: { start: 8, length: 1 }, newText: '\n' },
{ span: { start: 14, length: 4 }, newText: '' },
{ span: { start: 22, length: 1 }, newText: '' },
{ span: { start: 26, length: 1 }, newText: '\n' } ] } (The formatting options are passed into the However I'm not able to track it past this... I think the error happens somewhere in formatSpanWorker but that function is a beast. That file has last been edited by @andrewbranch and the commit message (237ea52) sounds like it might be related, which is why I'm tagging you here. |
The root bug is actually in Typescript: microsoft/TypeScript#38548
The root bug is actually in Typescript: microsoft/TypeScript#38548 Closes #5.
Thanks for tracking down the |
TypeScript Version: 3.9.2
Search Terms: organizeImports, imports, undefined
Code
Run through
ts.organizeImports
.Expected behavior:
Actual behavior:
Doesn't happen if there's only one import:
Only happens at the start and end of the block:
will yield:
Playground Link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=9&pc=1#code/JYWwDg9gTgLgBAbwFBzgZxgQxgGherGAZQE8A7AYzwF84AzKCEOAIjrRYG4kkBTAD0ix6AV0oxgEMvUwBrXgDEyACgCUifBmzdUW4uQrdqSIA
Don't think it can run the programmatic API.
https://ts-ast-viewer.com/#code/JYWwDg9gTgLgBAbwFBzgZxgQxgGherGAZQE8A7AYzwF84AzKCEOAIjrRYG4kkBTAD0ix6AV0oxgEMvUwBrXgDEyACgCUifBmzdUW4uQrdqSIA
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:
and https://github.com/mathieumg/organize-imports/blob/v3.9.2/index.js yields:
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
The text was updated successfully, but these errors were encountered: