-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Add 'move to new file' refactor #23726
Changes from 1 commit
76871d2
2bb0760
8c46867
7f40d09
1884fe9
67c61ff
0f2b6b9
d8b5218
497343b
9900c4b
233640b
7051e32
886a937
19d7309
662e93c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
////import { a, b } from "./other"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [I'm sure this is clear from the product code, but I haven't read it in detail.] What happens if you extract an import statement. Is that disallowed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about a return statement? Can a return statement be moved to another file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we should allow this, though there's a bug if the moved import is still needed in the old file. #23968
Only top-level statements can be moved, and 'return' at top-level is an errorany way. |
||
////const p = 0; | ||
////[|const y = p + b;|] | ||
////y; | ||
////a; y; | ||
|
||
verify.moveToNewFile({ | ||
newFileContents: { | ||
|
@@ -13,7 +13,7 @@ verify.moveToNewFile({ | |
|
||
import { a } from "./other"; | ||
export const p = 0; | ||
y;`, | ||
a; y;`, | ||
|
||
"/y.ts": | ||
`import { b } from "./other"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
////import i = require("./i"); | ||
////import j = require("./j"); | ||
////[|const y = i;|] | ||
////j; | ||
|
||
verify.moveToNewFile({ | ||
newFileContents: { | ||
"/a.ts": | ||
`import j = require("./j"); | ||
j;`, | ||
"/y.ts": | ||
`import i = require("./i"); | ||
const y = i;`, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @allowJs: true | ||
|
||
// @Filename: /a.js | ||
////const { a, b } = require("./other"); | ||
////const p = 0; | ||
//// | ||
////[|const y = p + b; | ||
////const z = 0; | ||
////exports.z = 0;|] | ||
////a; y; z; | ||
|
||
// @Filename: /user.ts | ||
////const { x, y } = require("./a"); | ||
|
||
// TODO: GH#23793 This will crash if the blank line between `const p` and `const y` is removed | ||
|
||
verify.moveToNewFile({ | ||
newFileContents: { | ||
"/a.js": | ||
// TODO: GH#22330 | ||
`const { y, z } = require("./y"); | ||
|
||
const { a, } = require("./other"); | ||
const p = 0; | ||
exports.p = p; | ||
|
||
a; y; z;`, | ||
|
||
"/y.js": | ||
`const { b } = require("./other"); | ||
const { p } = require("./a"); | ||
const y = p + b; | ||
exports.y = y; | ||
const z = 0; | ||
exports.z = 0;`, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @allowJs: true | ||
|
||
// @Filename: /a.js | ||
////exports.x = 0; | ||
////[|exports.y = 0;|] | ||
|
||
// @Filename: /user.js | ||
////const { x, y } = require("./a"); | ||
//// | ||
|
||
// TODO: GH#23728 Shouldn't need `////` above | ||
|
||
verify.moveToNewFile({ | ||
newFileContents: { | ||
"/a.js": | ||
`exports.x = 0; | ||
`, | ||
|
||
"/y.js": | ||
`exports.y = 0;`, | ||
|
||
"/user.js": | ||
// TODO: GH#22330 | ||
`const { x, } = require("./a"); | ||
const { y } = require("./y"); | ||
`, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: extra newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could consider linting for
no-padding
.