diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e20dd07d..3fc092a15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +### Bug Fixes + +- Fixed `const` variables not properly marked as `const`, #1866. + ## v0.22.11 (2022-01-18) ### Features diff --git a/src/lib/converter/symbols.ts b/src/lib/converter/symbols.ts index 0fe559ce9..3bd7e2840 100644 --- a/src/lib/converter/symbols.ts +++ b/src/lib/converter/symbols.ts @@ -930,19 +930,6 @@ function convertVariableAsFunction( exportSymbol ); setModifiers(symbol, accessDeclaration, reflection); - // Does anyone care about this? I doubt it... - if ( - declaration && - hasAllFlags(symbol.flags, ts.SymbolFlags.BlockScopedVariable) - ) { - reflection.setFlag( - ReflectionFlag.Const, - hasAllFlags( - (declaration || symbol.valueDeclaration).parent.flags, - ts.NodeFlags.Const - ) - ); - } context.finalizeDeclarationReflection(reflection, symbol, exportSymbol); @@ -1066,6 +1053,16 @@ function setModifiers( hasAllFlags(modifiers, ts.ModifierFlags.Abstract) ); + if ( + reflection.kindOf(ReflectionKind.Variable) && + hasAllFlags(symbol.flags, ts.SymbolFlags.BlockScopedVariable) + ) { + reflection.setFlag( + ReflectionFlag.Const, + hasAllFlags(declaration.parent.flags, ts.NodeFlags.Const) + ); + } + // ReflectionFlag.Static happens when constructing the reflection. // We don't have sufficient information here to determine if it ought to be static. } diff --git a/src/test/converter/class/specs-with-lump-categories.json b/src/test/converter/class/specs-with-lump-categories.json index eaf604b8e..71b694145 100644 --- a/src/test/converter/class/specs-with-lump-categories.json +++ b/src/test/converter/class/specs-with-lump-categories.json @@ -188,7 +188,8 @@ "kind": 32, "kindString": "Variable", "flags": { - "isPrivate": true + "isPrivate": true, + "isConst": true }, "comment": { "shortText": "A variable that is made private via comment." @@ -205,7 +206,8 @@ "kind": 32, "kindString": "Variable", "flags": { - "isProtected": true + "isProtected": true, + "isConst": true }, "comment": { "shortText": "A variable that is made protected via comment." diff --git a/src/test/converter/class/specs.json b/src/test/converter/class/specs.json index 50ddf3ff4..c83913395 100644 --- a/src/test/converter/class/specs.json +++ b/src/test/converter/class/specs.json @@ -188,7 +188,8 @@ "kind": 32, "kindString": "Variable", "flags": { - "isPrivate": true + "isPrivate": true, + "isConst": true }, "comment": { "shortText": "A variable that is made private via comment." @@ -205,7 +206,8 @@ "kind": 32, "kindString": "Variable", "flags": { - "isProtected": true + "isProtected": true, + "isConst": true }, "comment": { "shortText": "A variable that is made protected via comment." diff --git a/src/test/converter/declaration/specs.json b/src/test/converter/declaration/specs.json index 274a9b832..0572bfe1c 100644 --- a/src/test/converter/declaration/specs.json +++ b/src/test/converter/declaration/specs.json @@ -73,7 +73,9 @@ "name": "x", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "intrinsic", "name": "number" @@ -206,7 +208,9 @@ "name": "ActionSet", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "reference", "qualifiedName": "ts.server.ActionSet", diff --git a/src/test/converter/exports/specs.json b/src/test/converter/exports/specs.json index b55dc6322..72c7345ee 100644 --- a/src/test/converter/exports/specs.json +++ b/src/test/converter/exports/specs.json @@ -105,7 +105,9 @@ "name": "Member", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "literal", "value": 1 @@ -117,7 +119,9 @@ "name": "Module", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "reference", "id": 29, @@ -130,7 +134,9 @@ "name": "TypedMember", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "reference", "id": 29, @@ -143,7 +149,9 @@ "name": "TypedModule", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "reference", "id": 29, @@ -356,7 +364,9 @@ "name": "default", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "literal", "value": 5 @@ -386,7 +396,9 @@ "name": "x", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "literal", "value": 5 @@ -511,7 +523,9 @@ "name": "a", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "comment": { "shortText": "A simple named export that will be exported from export.ts" }, diff --git a/src/test/converter/function/specs.json b/src/test/converter/function/specs.json index 8853f87ce..ee6cc342a 100644 --- a/src/test/converter/function/specs.json +++ b/src/test/converter/function/specs.json @@ -318,9 +318,7 @@ "name": "all", "kind": 64, "kindString": "Function", - "flags": { - "isConst": true - }, + "flags": {}, "signatures": [ { "id": 100, @@ -1544,9 +1542,7 @@ "name": "variableFunction", "kind": 64, "kindString": "Function", - "flags": { - "isConst": true - }, + "flags": {}, "signatures": [ { "id": 84, diff --git a/src/test/converter/js/specs.json b/src/test/converter/js/specs.json index c6aeb8f22..800bbcd15 100644 --- a/src/test/converter/js/specs.json +++ b/src/test/converter/js/specs.json @@ -28,9 +28,7 @@ "name": "export=", "kind": 64, "kindString": "Function", - "flags": { - "isConst": true - }, + "flags": {}, "signatures": [ { "id": 3, @@ -536,7 +534,9 @@ "name": "ColumnType", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "comment": {}, "type": { "type": "reflection", @@ -591,9 +591,7 @@ "name": "usedFoo", "kind": 64, "kindString": "Function", - "flags": { - "isConst": true - }, + "flags": {}, "signatures": [ { "id": 8, diff --git a/src/test/converter/mixin/specs.json b/src/test/converter/mixin/specs.json index b17567de4..a6646787e 100644 --- a/src/test/converter/mixin/specs.json +++ b/src/test/converter/mixin/specs.json @@ -1053,9 +1053,7 @@ "name": "Mixin1Func", "kind": 64, "kindString": "Function", - "flags": { - "isConst": true - }, + "flags": {}, "signatures": [ { "id": 20, @@ -1158,9 +1156,7 @@ "name": "Mixin2", "kind": 64, "kindString": "Function", - "flags": { - "isConst": true - }, + "flags": {}, "signatures": [ { "id": 34, @@ -1273,9 +1269,7 @@ "name": "Mixin3", "kind": 64, "kindString": "Function", - "flags": { - "isConst": true - }, + "flags": {}, "signatures": [ { "id": 52, diff --git a/src/test/converter/types/specs.json b/src/test/converter/types/specs.json index 2efa19c28..621aba3a1 100644 --- a/src/test/converter/types/specs.json +++ b/src/test/converter/types/specs.json @@ -80,7 +80,9 @@ "name": "BigIntLiteralType", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "literal", "value": { @@ -95,7 +97,9 @@ "name": "NegativeBigIntLiteralType", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "literal", "value": { @@ -110,7 +114,9 @@ "name": "negativeOne", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "literal", "value": -1 @@ -122,7 +128,9 @@ "name": "numArray", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "array", "elementType": { @@ -661,7 +669,9 @@ "name": "x", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "literal", "value": 1 @@ -843,7 +853,9 @@ "name": "leadingRest", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "tuple", "elements": [ @@ -870,7 +882,9 @@ "name": "namedTuple", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "tuple", "elements": [ @@ -901,7 +915,9 @@ "name": "withOptionalElements", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "tuple", "elements": [ @@ -932,7 +948,9 @@ "name": "withRestType", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "tuple", "elements": [ @@ -959,7 +977,9 @@ "name": "withRestTypeNames", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "tuple", "elements": [ @@ -1114,7 +1134,9 @@ "name": "a", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "typeOperator", "operator": "unique", diff --git a/src/test/converter/variables/specs.json b/src/test/converter/variables/specs.json index 2a96d1676..7456c00ac 100644 --- a/src/test/converter/variables/specs.json +++ b/src/test/converter/variables/specs.json @@ -198,7 +198,9 @@ "name": "complex", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "comment": { "shortText": "A const of a complex type." }, @@ -253,7 +255,9 @@ "name": "custom", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "comment": { "shortText": "An exported const of the custom array type." }, @@ -523,7 +527,9 @@ "name": "callbackReturn", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "reflection", "declaration": { @@ -743,7 +749,9 @@ "name": "objectLiteral", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "comment": { "shortText": "An object literal." }, @@ -1289,7 +1297,9 @@ "name": "myConst", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "type": { "type": "literal", "value": 15 diff --git a/src/test/converter/variables/specs.nodoc.json b/src/test/converter/variables/specs.nodoc.json index 2f561a56b..b6f9e6e33 100644 --- a/src/test/converter/variables/specs.nodoc.json +++ b/src/test/converter/variables/specs.nodoc.json @@ -198,7 +198,9 @@ "name": "complex", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "comment": { "shortText": "A const of a complex type." }, @@ -253,7 +255,9 @@ "name": "custom", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "comment": { "shortText": "An exported const of the custom array type." }, @@ -357,7 +361,9 @@ "name": "objectLiteral", "kind": 32, "kindString": "Variable", - "flags": {}, + "flags": { + "isConst": true + }, "comment": { "shortText": "An object literal." },