Skip to content

Commit 21b9ae6

Browse files
authored
Fixes #104 (#111)
1 parent 1e5a54e commit 21b9ae6

8 files changed

Lines changed: 222 additions & 196 deletions

jswinrt/jswinrt/TextWriter.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class TextWriter
4747
{
4848
Write(first);
4949
}
50+
else if constexpr (std::is_arithmetic_v<First>)
51+
{
52+
Write(first);
53+
}
5054
else
5155
{
5256
FAIL_FAST();
@@ -100,6 +104,13 @@ class TextWriter
100104
m_buffer.insert(m_buffer.end(), value.begin(), value.end());
101105
}
102106

107+
template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, int> = 0>
108+
void Write(T value)
109+
{
110+
// TODO: Could be more efficient w/ std::to_chars or something similar
111+
Write(std::to_string(value));
112+
}
113+
103114
void Write(const char value)
104115
{
105116
m_buffer.push_back(value);

jswinrt/jswinrt/TypescriptWriter.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,22 @@ class TypescriptWriter
8686
{
8787
continue;
8888
};
89-
textWriter.WriteIndentedLine("%,"sv, TextWriter::ToCamelCase(std::string(field.Name())));
89+
90+
textWriter.WriteIndentedLine("% = %,"sv, TextWriter::ToCamelCase(std::string(field.Name())), [&]() {
91+
auto value = field.Constant();
92+
switch (value.Type())
93+
{
94+
case winmd::reader::ConstantType::Int32:
95+
textWriter.Write("%", value.ValueInt32());
96+
break;
97+
case winmd::reader::ConstantType::UInt32:
98+
textWriter.Write("%", value.ValueUInt32());
99+
break;
100+
default:
101+
// Enum values are signed or unsigned 32-bit integers
102+
FAIL_FAST();
103+
}
104+
});
90105
}
91106
textWriter.ReduceIndent();
92107
textWriter.WriteIndentedLine();

tests/TestArtifacts/TestComponent.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,10 @@ declare namespace TestComponent {
477477
}
478478

479479
enum TestEnum {
480-
first,
481-
second,
482-
third,
483-
fourth,
480+
first = 1,
481+
second = 2,
482+
third = 3,
483+
fourth = 4,
484484
}
485485

486486
class TestObject {

tests/TestArtifacts/Windows.Foundation.Collections.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
declare namespace Windows.Foundation.Collections {
44
enum CollectionChange {
5-
reset,
6-
itemInserted,
7-
itemRemoved,
8-
itemChanged,
5+
reset = 0,
6+
itemInserted = 1,
7+
itemRemoved = 2,
8+
itemChanged = 3,
99
}
1010

1111
interface IIterable<T> {

tests/TestArtifacts/Windows.Foundation.Diagnostics.d.ts

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ declare namespace Windows.Foundation.Diagnostics {
1212
}
1313

1414
enum CausalityRelation {
15-
assignDelegate,
16-
join,
17-
choice,
18-
cancel,
19-
error,
15+
assignDelegate = 0,
16+
join = 1,
17+
choice = 2,
18+
cancel = 3,
19+
error = 4,
2020
}
2121

2222
enum CausalitySource {
23-
application,
24-
library,
25-
system,
23+
application = 0,
24+
library = 1,
25+
system = 2,
2626
}
2727

2828
enum CausalitySynchronousWork {
29-
completionNotification,
30-
progressNotification,
31-
execution,
29+
completionNotification = 0,
30+
progressNotification = 1,
31+
execution = 2,
3232
}
3333

3434
enum CausalityTraceLevel {
35-
required,
36-
important,
37-
verbose,
35+
required = 0,
36+
important = 1,
37+
verbose = 2,
3838
}
3939

4040
class ErrorDetails {
@@ -45,11 +45,11 @@ declare namespace Windows.Foundation.Diagnostics {
4545
}
4646

4747
enum ErrorOptions {
48-
none,
49-
suppressExceptions,
50-
forceExceptions,
51-
useSetErrorInfo,
52-
suppressSetErrorInfo,
48+
none = 0,
49+
suppressExceptions = 1,
50+
forceExceptions = 2,
51+
useSetErrorInfo = 4,
52+
suppressSetErrorInfo = 8,
5353
}
5454

5555
class FileLoggingSession implements Windows.Foundation.Diagnostics.IFileLoggingSession, Windows.Foundation.IClosable {
@@ -174,25 +174,25 @@ declare namespace Windows.Foundation.Diagnostics {
174174
}
175175

176176
enum LoggingFieldFormat {
177-
default,
178-
hidden,
179-
string,
180-
boolean,
181-
hexadecimal,
182-
processId,
183-
threadId,
184-
port,
185-
ipv4Address,
186-
ipv6Address,
187-
socketAddress,
188-
xml,
189-
json,
190-
win32Error,
191-
nTStatus,
192-
hResult,
193-
fileTime,
194-
signed,
195-
unsigned,
177+
default = 0,
178+
hidden = 1,
179+
string = 2,
180+
boolean = 3,
181+
hexadecimal = 4,
182+
processId = 5,
183+
threadId = 6,
184+
port = 7,
185+
ipv4Address = 8,
186+
ipv6Address = 9,
187+
socketAddress = 10,
188+
xml = 11,
189+
json = 12,
190+
win32Error = 13,
191+
nTStatus = 14,
192+
hResult = 15,
193+
fileTime = 16,
194+
signed = 17,
195+
unsigned = 18,
196196
}
197197

198198
class LoggingFields {
@@ -315,21 +315,21 @@ declare namespace Windows.Foundation.Diagnostics {
315315
}
316316

317317
enum LoggingLevel {
318-
verbose,
319-
information,
320-
warning,
321-
error,
322-
critical,
318+
verbose = 0,
319+
information = 1,
320+
warning = 2,
321+
error = 3,
322+
critical = 4,
323323
}
324324

325325
enum LoggingOpcode {
326-
info,
327-
start,
328-
stop,
329-
reply,
330-
resume,
331-
suspend,
332-
send,
326+
info = 0,
327+
start = 1,
328+
stop = 2,
329+
reply = 6,
330+
resume = 7,
331+
suspend = 8,
332+
send = 9,
333333
}
334334

335335
class LoggingOptions {

tests/TestArtifacts/Windows.Foundation.Metadata.d.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ declare namespace Windows.Foundation.Metadata {
3636
}
3737

3838
enum AttributeTargets {
39-
all,
40-
delegate,
41-
enum,
42-
event,
43-
field,
44-
interface,
45-
method,
46-
parameter,
47-
property,
48-
runtimeClass,
49-
struct,
50-
interfaceImpl,
51-
apiContract,
39+
all = 4294967295,
40+
delegate = 1,
41+
enum = 2,
42+
event = 4,
43+
field = 8,
44+
interface = 16,
45+
method = 64,
46+
parameter = 128,
47+
property = 256,
48+
runtimeClass = 512,
49+
struct = 1024,
50+
interfaceImpl = 2048,
51+
apiContract = 8192,
5252
}
5353

5454
class AttributeUsageAttribute {
@@ -62,8 +62,8 @@ declare namespace Windows.Foundation.Metadata {
6262
}
6363

6464
enum CompositionType {
65-
protected,
66-
public,
65+
protected = 1,
66+
public = 2,
6767
}
6868

6969
class ContractVersionAttribute {
@@ -87,8 +87,8 @@ declare namespace Windows.Foundation.Metadata {
8787
}
8888

8989
enum DeprecationType {
90-
deprecate,
91-
remove,
90+
deprecate = 0,
91+
remove = 1,
9292
}
9393

9494
class DualApiPartitionAttribute {
@@ -109,16 +109,16 @@ declare namespace Windows.Foundation.Metadata {
109109
}
110110

111111
enum FeatureStage {
112-
alwaysDisabled,
113-
disabledByDefault,
114-
enabledByDefault,
115-
alwaysEnabled,
112+
alwaysDisabled = 0,
113+
disabledByDefault = 1,
114+
enabledByDefault = 2,
115+
alwaysEnabled = 3,
116116
}
117117

118118
enum GCPressureAmount {
119-
low,
120-
medium,
121-
high,
119+
low = 0,
120+
medium = 1,
121+
high = 2,
122122
}
123123

124124
class GCPressureAttribute {
@@ -147,10 +147,10 @@ declare namespace Windows.Foundation.Metadata {
147147
}
148148

149149
enum MarshalingType {
150-
none,
151-
agile,
152-
standard,
153-
invalidMarshaling,
150+
none = 1,
151+
agile = 2,
152+
standard = 3,
153+
invalidMarshaling = 0,
154154
}
155155

156156
class MetadataMarshalAttribute {
@@ -171,8 +171,8 @@ declare namespace Windows.Foundation.Metadata {
171171
}
172172

173173
enum Platform {
174-
windows,
175-
windowsPhone,
174+
windows = 0,
175+
windowsPhone = 1,
176176
}
177177

178178
class PlatformAttribute {
@@ -207,10 +207,10 @@ declare namespace Windows.Foundation.Metadata {
207207
}
208208

209209
enum ThreadingModel {
210-
sTA,
211-
mTA,
212-
both,
213-
invalidThreading,
210+
sTA = 1,
211+
mTA = 2,
212+
both = 3,
213+
invalidThreading = 0,
214214
}
215215

216216
class VariantAttribute {

0 commit comments

Comments
 (0)