Skip to content

Commit 038f2a8

Browse files
committed
Fixed const variables not properly marked const
Resolves #1866
1 parent 33d164b commit 038f2a8

File tree

12 files changed

+116
-67
lines changed

12 files changed

+116
-67
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
### Bug Fixes
4+
5+
- Fixed `const` variables not properly marked as `const`, #1866.
6+
37
## v0.22.11 (2022-01-18)
48

59
### Features

src/lib/converter/symbols.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -930,19 +930,6 @@ function convertVariableAsFunction(
930930
exportSymbol
931931
);
932932
setModifiers(symbol, accessDeclaration, reflection);
933-
// Does anyone care about this? I doubt it...
934-
if (
935-
declaration &&
936-
hasAllFlags(symbol.flags, ts.SymbolFlags.BlockScopedVariable)
937-
) {
938-
reflection.setFlag(
939-
ReflectionFlag.Const,
940-
hasAllFlags(
941-
(declaration || symbol.valueDeclaration).parent.flags,
942-
ts.NodeFlags.Const
943-
)
944-
);
945-
}
946933

947934
context.finalizeDeclarationReflection(reflection, symbol, exportSymbol);
948935

@@ -1066,6 +1053,16 @@ function setModifiers(
10661053
hasAllFlags(modifiers, ts.ModifierFlags.Abstract)
10671054
);
10681055

1056+
if (
1057+
reflection.kindOf(ReflectionKind.Variable) &&
1058+
hasAllFlags(symbol.flags, ts.SymbolFlags.BlockScopedVariable)
1059+
) {
1060+
reflection.setFlag(
1061+
ReflectionFlag.Const,
1062+
hasAllFlags(declaration.parent.flags, ts.NodeFlags.Const)
1063+
);
1064+
}
1065+
10691066
// ReflectionFlag.Static happens when constructing the reflection.
10701067
// We don't have sufficient information here to determine if it ought to be static.
10711068
}

src/test/converter/class/specs-with-lump-categories.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@
188188
"kind": 32,
189189
"kindString": "Variable",
190190
"flags": {
191-
"isPrivate": true
191+
"isPrivate": true,
192+
"isConst": true
192193
},
193194
"comment": {
194195
"shortText": "A variable that is made private via comment."
@@ -205,7 +206,8 @@
205206
"kind": 32,
206207
"kindString": "Variable",
207208
"flags": {
208-
"isProtected": true
209+
"isProtected": true,
210+
"isConst": true
209211
},
210212
"comment": {
211213
"shortText": "A variable that is made protected via comment."

src/test/converter/class/specs.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@
188188
"kind": 32,
189189
"kindString": "Variable",
190190
"flags": {
191-
"isPrivate": true
191+
"isPrivate": true,
192+
"isConst": true
192193
},
193194
"comment": {
194195
"shortText": "A variable that is made private via comment."
@@ -205,7 +206,8 @@
205206
"kind": 32,
206207
"kindString": "Variable",
207208
"flags": {
208-
"isProtected": true
209+
"isProtected": true,
210+
"isConst": true
209211
},
210212
"comment": {
211213
"shortText": "A variable that is made protected via comment."

src/test/converter/declaration/specs.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
"name": "x",
7474
"kind": 32,
7575
"kindString": "Variable",
76-
"flags": {},
76+
"flags": {
77+
"isConst": true
78+
},
7779
"type": {
7880
"type": "intrinsic",
7981
"name": "number"
@@ -206,7 +208,9 @@
206208
"name": "ActionSet",
207209
"kind": 32,
208210
"kindString": "Variable",
209-
"flags": {},
211+
"flags": {
212+
"isConst": true
213+
},
210214
"type": {
211215
"type": "reference",
212216
"qualifiedName": "ts.server.ActionSet",

src/test/converter/exports/specs.json

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@
105105
"name": "Member",
106106
"kind": 32,
107107
"kindString": "Variable",
108-
"flags": {},
108+
"flags": {
109+
"isConst": true
110+
},
109111
"type": {
110112
"type": "literal",
111113
"value": 1
@@ -117,7 +119,9 @@
117119
"name": "Module",
118120
"kind": 32,
119121
"kindString": "Variable",
120-
"flags": {},
122+
"flags": {
123+
"isConst": true
124+
},
121125
"type": {
122126
"type": "reference",
123127
"id": 29,
@@ -130,7 +134,9 @@
130134
"name": "TypedMember",
131135
"kind": 32,
132136
"kindString": "Variable",
133-
"flags": {},
137+
"flags": {
138+
"isConst": true
139+
},
134140
"type": {
135141
"type": "reference",
136142
"id": 29,
@@ -143,7 +149,9 @@
143149
"name": "TypedModule",
144150
"kind": 32,
145151
"kindString": "Variable",
146-
"flags": {},
152+
"flags": {
153+
"isConst": true
154+
},
147155
"type": {
148156
"type": "reference",
149157
"id": 29,
@@ -356,7 +364,9 @@
356364
"name": "default",
357365
"kind": 32,
358366
"kindString": "Variable",
359-
"flags": {},
367+
"flags": {
368+
"isConst": true
369+
},
360370
"type": {
361371
"type": "literal",
362372
"value": 5
@@ -386,7 +396,9 @@
386396
"name": "x",
387397
"kind": 32,
388398
"kindString": "Variable",
389-
"flags": {},
399+
"flags": {
400+
"isConst": true
401+
},
390402
"type": {
391403
"type": "literal",
392404
"value": 5
@@ -511,7 +523,9 @@
511523
"name": "a",
512524
"kind": 32,
513525
"kindString": "Variable",
514-
"flags": {},
526+
"flags": {
527+
"isConst": true
528+
},
515529
"comment": {
516530
"shortText": "A simple named export that will be exported from export.ts"
517531
},

src/test/converter/function/specs.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,7 @@
318318
"name": "all",
319319
"kind": 64,
320320
"kindString": "Function",
321-
"flags": {
322-
"isConst": true
323-
},
321+
"flags": {},
324322
"signatures": [
325323
{
326324
"id": 100,
@@ -1544,9 +1542,7 @@
15441542
"name": "variableFunction",
15451543
"kind": 64,
15461544
"kindString": "Function",
1547-
"flags": {
1548-
"isConst": true
1549-
},
1545+
"flags": {},
15501546
"signatures": [
15511547
{
15521548
"id": 84,

src/test/converter/js/specs.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
"name": "export=",
2929
"kind": 64,
3030
"kindString": "Function",
31-
"flags": {
32-
"isConst": true
33-
},
31+
"flags": {},
3432
"signatures": [
3533
{
3634
"id": 3,
@@ -536,7 +534,9 @@
536534
"name": "ColumnType",
537535
"kind": 32,
538536
"kindString": "Variable",
539-
"flags": {},
537+
"flags": {
538+
"isConst": true
539+
},
540540
"comment": {},
541541
"type": {
542542
"type": "reflection",
@@ -591,9 +591,7 @@
591591
"name": "usedFoo",
592592
"kind": 64,
593593
"kindString": "Function",
594-
"flags": {
595-
"isConst": true
596-
},
594+
"flags": {},
597595
"signatures": [
598596
{
599597
"id": 8,

src/test/converter/mixin/specs.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,9 +1053,7 @@
10531053
"name": "Mixin1Func",
10541054
"kind": 64,
10551055
"kindString": "Function",
1056-
"flags": {
1057-
"isConst": true
1058-
},
1056+
"flags": {},
10591057
"signatures": [
10601058
{
10611059
"id": 20,
@@ -1158,9 +1156,7 @@
11581156
"name": "Mixin2",
11591157
"kind": 64,
11601158
"kindString": "Function",
1161-
"flags": {
1162-
"isConst": true
1163-
},
1159+
"flags": {},
11641160
"signatures": [
11651161
{
11661162
"id": 34,
@@ -1273,9 +1269,7 @@
12731269
"name": "Mixin3",
12741270
"kind": 64,
12751271
"kindString": "Function",
1276-
"flags": {
1277-
"isConst": true
1278-
},
1272+
"flags": {},
12791273
"signatures": [
12801274
{
12811275
"id": 52,

src/test/converter/types/specs.json

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@
8080
"name": "BigIntLiteralType",
8181
"kind": 32,
8282
"kindString": "Variable",
83-
"flags": {},
83+
"flags": {
84+
"isConst": true
85+
},
8486
"type": {
8587
"type": "literal",
8688
"value": {
@@ -95,7 +97,9 @@
9597
"name": "NegativeBigIntLiteralType",
9698
"kind": 32,
9799
"kindString": "Variable",
98-
"flags": {},
100+
"flags": {
101+
"isConst": true
102+
},
99103
"type": {
100104
"type": "literal",
101105
"value": {
@@ -110,7 +114,9 @@
110114
"name": "negativeOne",
111115
"kind": 32,
112116
"kindString": "Variable",
113-
"flags": {},
117+
"flags": {
118+
"isConst": true
119+
},
114120
"type": {
115121
"type": "literal",
116122
"value": -1
@@ -122,7 +128,9 @@
122128
"name": "numArray",
123129
"kind": 32,
124130
"kindString": "Variable",
125-
"flags": {},
131+
"flags": {
132+
"isConst": true
133+
},
126134
"type": {
127135
"type": "array",
128136
"elementType": {
@@ -661,7 +669,9 @@
661669
"name": "x",
662670
"kind": 32,
663671
"kindString": "Variable",
664-
"flags": {},
672+
"flags": {
673+
"isConst": true
674+
},
665675
"type": {
666676
"type": "literal",
667677
"value": 1
@@ -843,7 +853,9 @@
843853
"name": "leadingRest",
844854
"kind": 32,
845855
"kindString": "Variable",
846-
"flags": {},
856+
"flags": {
857+
"isConst": true
858+
},
847859
"type": {
848860
"type": "tuple",
849861
"elements": [
@@ -870,7 +882,9 @@
870882
"name": "namedTuple",
871883
"kind": 32,
872884
"kindString": "Variable",
873-
"flags": {},
885+
"flags": {
886+
"isConst": true
887+
},
874888
"type": {
875889
"type": "tuple",
876890
"elements": [
@@ -901,7 +915,9 @@
901915
"name": "withOptionalElements",
902916
"kind": 32,
903917
"kindString": "Variable",
904-
"flags": {},
918+
"flags": {
919+
"isConst": true
920+
},
905921
"type": {
906922
"type": "tuple",
907923
"elements": [
@@ -932,7 +948,9 @@
932948
"name": "withRestType",
933949
"kind": 32,
934950
"kindString": "Variable",
935-
"flags": {},
951+
"flags": {
952+
"isConst": true
953+
},
936954
"type": {
937955
"type": "tuple",
938956
"elements": [
@@ -959,7 +977,9 @@
959977
"name": "withRestTypeNames",
960978
"kind": 32,
961979
"kindString": "Variable",
962-
"flags": {},
980+
"flags": {
981+
"isConst": true
982+
},
963983
"type": {
964984
"type": "tuple",
965985
"elements": [
@@ -1114,7 +1134,9 @@
11141134
"name": "a",
11151135
"kind": 32,
11161136
"kindString": "Variable",
1117-
"flags": {},
1137+
"flags": {
1138+
"isConst": true
1139+
},
11181140
"type": {
11191141
"type": "typeOperator",
11201142
"operator": "unique",

0 commit comments

Comments
 (0)