Skip to content

Commit

Permalink
Fix for TypeScript params with access modifiers and default values
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonVolo committed Oct 11, 2021
1 parent 9f7aba0 commit 7b5b25b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class HttpHandler {

constructor(
protected routes = 5,
) {
let q = 5;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-ignore
function decycle(u){var f=[],c=[];return function p(o,i){var t,e,n,r=o&&o.toJSON instanceof Function?o.toJSON():o;if(typeof r=="object"&&r!==null){for(t=0;t<f.length;t+=1)if(f[t]===r)return{$ref:c[t]};if(f.push(r),c.push(i),Object.prototype.toString.apply(r)==="[object Array]")for(n=[],t=0;t<r.length;t+=1)n[t]=p(r[t],i+"["+t+"]");else{n={};for(e in r)Object.prototype.hasOwnProperty.call(r,e)&&(n[e]=p(r[e],i+"["+JSON.stringify(e)+"]"))}return n}return r}(u,"$")}

export class HttpHandler {

constructor(
protected routes = 5,
) {
console.log(
'[logitall] __testfixtures__/method-constructor-logparams-access-modifier-default-param.input.ts:5:constructor()'
);

console.log(
`[logitall] __testfixtures__/method-constructor-logparams-access-modifier-default-param.input.ts:5::param routes value:
${JSON.stringify(decycle(routes))}`
);

let q = 5;
}
}
1 change: 1 addition & 0 deletions __tests__/transform-test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,24 @@ const buildParamLoggingList = (paramNodes, relPathToFile, linenum, functionName)
// Babel parses the function parameter node into a TSParameterProperty node
// So in that case we need to dig one level deeper to get the name of the parameter.
if (!currentNodeName && currentNode.type === 'TSParameterProperty') {
// The solution is to get TSParameterProperty.paramter.name
currentNodeName = currentNode.parameter.name;
// The solution is to get TSParameterProperty.paramter.name or some variation of that

// Check to see if this is TypeScript with an assigment, e.g.
// export class HttpHandler {

// constructor(
// protected routes = 5,
// ) {
// let q = 5;
// }
// }
//
// If so, then go get routes we need to do theTypeScriptNode.parameter.left.name;
if (currentNode.parameter.type == 'AssignmentPattern') {
currentNodeName = currentNode.parameter.left.name;
} else {
currentNodeName = currentNode.parameter.name;
}
}

if (currentNode.type == 'ObjectPattern') {
Expand Down

0 comments on commit 7b5b25b

Please sign in to comment.