convert all enums into const enums

This commit is contained in:
Vladimir Matveev 2016-10-13 15:43:32 -07:00
parent 67ac2d5ff9
commit d27bfccb79
2 changed files with 9 additions and 1 deletions

1
.gitignore vendored
View File

@ -39,6 +39,7 @@ tests/cases/**/*.js.map
scripts/debug.bat
scripts/run.bat
scripts/word2md.js
scripts/buildProtocol.js
scripts/ior.js
scripts/*.js.map
scripts/typings/

View File

@ -42,7 +42,14 @@ class DeclarationsWalker {
return;
}
// splice declaration in final d.ts file
const text = decl.getFullText();
let text = decl.getFullText();
if (decl.kind === ts.SyntaxKind.EnumDeclaration && !(decl.flags & ts.NodeFlags.Const)) {
// patch enum declaration to make them constan
const declStart = decl.getStart() - decl.getFullStart();
const prefix = text.substring(0, declStart);
const suffix = text.substring(declStart + "enum".length, decl.getEnd() - decl.getFullStart());
text = prefix + "const enum" + suffix;
}
this.text += `${text}\n`;
// recursively pull all dependencies into result dts file