Skip to content

Commit 6417dab

Browse files
committed
Merge pull request #11605 from Microsoft/vladima/convert-enums-to-const
convert all enums to const enums when building protocol.d.ts
1 parent a09f00b commit 6417dab

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ tests/cases/**/*.js.map
4141
scripts/debug.bat
4242
scripts/run.bat
4343
scripts/word2md.js
44+
scripts/buildProtocol.js
4445
scripts/ior.js
4546
scripts/buildProtocol.js
4647
scripts/*.js.map

scripts/buildProtocol.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ class DeclarationsWalker {
4242
return;
4343
}
4444
// splice declaration in final d.ts file
45-
const text = decl.getFullText();
45+
let text = decl.getFullText();
46+
if (decl.kind === ts.SyntaxKind.EnumDeclaration && !(decl.flags & ts.NodeFlags.Const)) {
47+
// patch enum declaration to make them constan
48+
const declStart = decl.getStart() - decl.getFullStart();
49+
const prefix = text.substring(0, declStart);
50+
const suffix = text.substring(declStart + "enum".length, decl.getEnd() - decl.getFullStart());
51+
text = prefix + "const enum" + suffix;
52+
}
4653
this.text += `${text}\n`;
4754

4855
// recursively pull all dependencies into result dts file

0 commit comments

Comments
 (0)