Created
February 7, 2018 23:22
-
-
Save evmar/54461d7fb2a491955c1e82ae5b656c22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// taze: Set from //third_party/javascript/node_modules/typescript:es2015.collection | |
import * as fs from 'fs'; // from //third_party/javascript/typings/node | |
import * as ts from 'typescript'; | |
function load(fileName: string, names: Set<string>) { | |
const text = fs.readFileSync(fileName, 'utf8'); | |
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.ES5, true); | |
sf.forEachChild((node) => { | |
switch (node.kind) { | |
case ts.SyntaxKind.InterfaceDeclaration: | |
case ts.SyntaxKind.TypeAliasDeclaration: | |
case ts.SyntaxKind.FunctionDeclaration: | |
case ts.SyntaxKind.ModuleDeclaration: | |
const named = node as (ts.InterfaceDeclaration | ts.TypeAliasDeclaration | | |
ts.FunctionDeclaration | ts.ModuleDeclaration); | |
if (named.name) names.add(named.name.getText()); | |
break; | |
case ts.SyntaxKind.VariableStatement: | |
const stmt = node as ts.VariableStatement; | |
for (const decl of stmt.declarationList.declarations) { | |
if (decl.name.kind === ts.SyntaxKind.Identifier) { | |
names.add(decl.name.getText()); | |
} else { | |
console.error(`TODO: '${decl.name.getText()}' var`); | |
} | |
} | |
break; | |
case ts.SyntaxKind.EndOfFileToken: | |
break; | |
default: | |
console.error(`TODO: ${ts.SyntaxKind[node.kind]}`); | |
} | |
}); | |
} | |
const nameSet = new Set<string>(); | |
for (const fileName of process.argv.slice(2)) { | |
load(fileName, nameSet); | |
} | |
const names = Array.from(nameSet); | |
names.sort(); | |
for (const name of names) { | |
console.log(`"${name}",`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment