Merge pull request #11605 from Microsoft/vladima/convert-enums-to-const

convert all enums to const enums when building protocol.d.ts
This commit is contained in:
Vladimir Matveev 2016-10-14 08:11:23 -07:00
parent a09f00bb11
commit 6417dab60b
2 changed files with 9 additions and 1 deletions

1
.gitignore vendored
View File

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

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