Skip to content

Instantly share code, notes, and snippets.

@Quramy
Created November 14, 2018 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quramy/5abf83a011e16e1f2e22e603b87dd75c to your computer and use it in GitHub Desktop.
Save Quramy/5abf83a011e16e1f2e22e603b87dd75c to your computer and use it in GitHub Desktop.
extract identifiers and split files

I want a tsssercmd to extract a selected identifier (function, const, class, type, etc...) to other new file.

{
  command: "extractAndCreateFile",
  file: "./main.js",
  location: {
    line: 2, col: 10
  },
  toFile: "./sum.js"
}

And the above resuest returns:

  • textChanges for main.js
  • textChanges for sum.js
// before refactoring
// main.js
function sum(a: number, b: number) {
return a + b;
}
function main() {
console.log(sum(10, 10));
}
// after refactoring
// sum.js
export function sum(a: number, b: number) {
return a + b;
}
// main.js
import { sum } from "./sum";
function main() {
console.log(sum(10, 10));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment