Skip to content
Permalink
Browse files

perf(parse): Check depth is set to 3

  • Loading branch information...
iamthes committed Nov 20, 2017
1 parent ee62992 commit 24c320fb778e83aa3d68992f24b4bc8485f73e86
Showing with 37 additions and 2 deletions.
  1. +2 −1 package.json
  2. +26 −0 src/parse.spec.ts
  3. +9 −1 src/parse.ts
@@ -28,7 +28,8 @@
"release:undo": "git reset --hard HEAD~ -- && node -p \"let {execSync: x} = require('child_process'); `${x(`git tag -d ${x(`git for-each-ref refs/tags --sort=-taggerdate --format=%(refname:short) --count=1`)}`)}`\"",
"prepublishOnly": "npm run build",
"setup": "npm i -g commitizen standard-version && commitizen init cz-conventional-changelog --save-dev",
"commit": "git-cz"
"commit": "git-cz",
"benchmark": "ts-node node_modules/benchmarko/lib/bin.js -f benchmarks/parse-module-node"
},
"dependencies": {
"object-values": "^1.0.0",
@@ -121,3 +121,29 @@ it('should extract declared module events', async () => {
assert.equal(event.name, 'EventEmitter');
assert.equal(event.module, 'events');
});

it('not too deep parse', async () => {
const source = `
export function deep() {
const x = {a: {c: {d: 1}}};
return () => a => b => c => () => ({
export = x;
});
};
}`;
const result = await parse(source);
assert.equal(result.length, 1);
assert.equal(result[0].name, 'deep');
});

// it('duplicates must be removed', async () => {
// const source = `declare module "child_process" {
// export function spawnSync(command: string): SpawnSyncReturns<Buffer>;
// export function spawnSync(command: string, options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
// }`;
// debugger
// const result = await parse(source);
// assert.equal(result.length, 1);
// assert.equal(result[0].name, 'spawnSync');
// assert.equal(result[0].module, 'child_process');
// });
@@ -70,7 +70,15 @@ export function parse(sourceText: string, options: ParseOptions = {}): Entry[] {
result.push(new Entry({ module, cjs: true, ts: true }));
} break;
}
ts.forEachChild(node, walk);
if (node.kind === ts.SyntaxKind.SourceFile
|| node.kind === ts.SyntaxKind.ModuleDeclaration
|| get('parent.kind', node) === ts.SyntaxKind.SourceFile
|| get('parent.kind', node) === ts.SyntaxKind.ModuleDeclaration
|| get('parent.parent.kind', node) === ts.SyntaxKind.SourceFile
|| get('parent.parent.kind', node) === ts.SyntaxKind.ModuleDeclaration
) {
ts.forEachChild(node, walk);
}
}
return result;
}

0 comments on commit 24c320f

Please sign in to comment.
You can’t perform that action at this time.