0.0.0 • Published 2 years ago
eme v0.0.0
eme
Use the magic of AST to figure out variables to inject/return when extracting a method.
const {
sameScope, // destination scope is the same, you should skip injecting vars because they are all in scope anyways
isExpression, // if it's an expression then you should simply return the expression from the function
variablesToInject, // variables that need to be injected in the extracted function
variablesToReturn // variables that the donor scope has references to
} = eme({
// selection range relative to 'file'
location: {
start: { line: 2, col: 0 },
end: { line: 4, col: 80 },
},
// full contents of buffer/file
file: `
const { writeFile } = require('fs')
const text = 'hello world'
writeFile('hello.txt', text, 'utf8')
`,
// destination line where to extract method to
destination: 3
})