Skip to content
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

Inline comment fix and refactoring #184

Merged
merged 12 commits into from
Apr 19, 2022
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
coverage/
.tern-port
test/src/**/*.js
playground
22 changes: 10 additions & 12 deletions lib/astupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const updateComment = require('./updateComment.js')

let patterns = []

const buildExplicitCases = (funcdecl, patterndecls) => {
const buildExplicitCases = (patterndecls) => {
const patterncases = []
let flag = false
for (const pattern of patterndecls) {
Expand Down Expand Up @@ -44,10 +44,10 @@ const buildDefaultCase = (funcdecl) => {
return defaultcase
}

const formMultiPatternAst = (funcdecl, patterndecls, ast) => {
const formMultiPatternAst = (funcdecl, patterndecls) => {
const funcdeclbody = { type: 'BlockStatement', body: [] }
const blockstmtbody = { type: 'SwitchStatement', cases: [] }
const [cases, flag] = buildExplicitCases(funcdecl, patterndecls)
const [cases, flag] = buildExplicitCases(patterndecls)
const testTempl = funcdecl.declarations[0].init.params[0]
blockstmtbody.discriminant = testTempl
if (flag === true) {
Expand Down Expand Up @@ -107,30 +107,28 @@ const formFunctionAst = (funcdecl, patterndecls) => {
const processSubTree = (decl) => {
if (isArrowFuncDecl(decl)) {
if (isFunction(decl)) {
// funcdeclns
// function declarations
const funcast = formFunctionAst(decl, patterns)
patterns = []
return funcast
} else {
// patternfuncdeclns
// pattern matched function declarations
patterns.push(decl)
return null
}
}
return decl
}

const updateAst = (mayBeAst) => {
const ast = mayBeAst
let newbody = []
const updateAst = (ast) => {
let newBody = []
const declarations = ast.body

declarations.forEach((decl) => {
const subtree = processSubTree(decl)
if (subtree !== null) newbody.push(subtree)
if (subtree !== null) newBody.push(subtree)
})
newbody = updateComment(newbody, ast)
ast.body = newbody
newBody = updateComment(newBody)
ast.body = newBody
return ast
}

Expand Down
Loading