diff --git a/src/finders/request/index.ts b/src/finders/request/index.ts index 84b985f..f758383 100644 --- a/src/finders/request/index.ts +++ b/src/finders/request/index.ts @@ -71,6 +71,16 @@ export default function caseRequestModeFinder( if (res !== undefined) { return res; } + + if (_key && res !== null) { + return { + link: _key, + linked: false, + line_index: index, + key: _key, + mode: 'property' + }; + } } else { // Method matching const reqIndex = line.indexOf('req'); diff --git a/src/finders/request/property.ts b/src/finders/request/property.ts index e6cafec..5cb01df 100644 --- a/src/finders/request/property.ts +++ b/src/finders/request/property.ts @@ -6,7 +6,7 @@ export default function requestMethodFinder( _key: string, line: string, index: number -): IBlock | void { +): IBlock | null | void { let key; let link; const extracted = variableKeyExtractor(line); @@ -29,7 +29,7 @@ export default function requestMethodFinder( } if (_key.includes('getMethod(') || _key.includes('getUrl(')) { // uWebSockets.js has native `getMethod` and `getUrl` support - return undefined; + return null; } if ( (_key === 'req;' || _key === 'request;') && diff --git a/tests/analyze.spec.js b/tests/analyze.spec.js index 1b7a14d..f031388 100644 --- a/tests/analyze.spec.js +++ b/tests/analyze.spec.js @@ -115,6 +115,21 @@ describe('property parse', () => { } ]); }); + it('req.ip', () => { + expect( + analyze((request, response) => { + response.end(request.ip); + }) + ).toEqual([ + { + key: 'ip', + line_index: 1, + link: 'ip', + linked: false, + mode: 'property' + } + ]); + }); }); describe('request property parse', () => {