Skip to content

Commit

Permalink
dedupe annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed May 20, 2020
1 parent e85c323 commit 33b3441
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 144 deletions.
35 changes: 25 additions & 10 deletions generate_annotations.js
Expand Up @@ -91,6 +91,18 @@ function convertSignature(signature) {
});
}

function arrayEqual(a1, a2) {
if (a1.length !== a2.length) {
return false;
}
for (let i = 0; i < a1.length; i += 1) {
if (a1[i] !== a2[i]) {
return false;
}
}
return true;
}

const out = [];

program.getSourceFile('index.ts').statements.forEach((stmt, i) => {
Expand All @@ -109,16 +121,19 @@ program.getSourceFile('index.ts').statements.forEach((stmt, i) => {
construct: [],
};

type.getCallSignatures()
.filter((s) => s.parameters.length > 0)
.forEach((signature) => {
data.call.push(convertSignature(signature));
});
type.getConstructSignatures()
.filter((s) => s.parameters.length > 0)
.forEach((signature) => {
data.construct.push(convertSignature(signature));
});
const C = (signatures, a) => {
signatures
.filter((s) => s.parameters.length > 0)
.forEach((signature) => {
const s = convertSignature(signature);
if (!a.some((e) => arrayEqual(s, e))) {
a.push(s);
}
});
};

C(type.getCallSignatures(), data.call);
C(type.getConstructSignatures(), data.construct);

data.call.sort((a, b) => a.length - b.length);
data.construct.sort((a, b) => a.length - b.length);
Expand Down

0 comments on commit 33b3441

Please sign in to comment.