Skip to content

Commit 56817c8

Browse files
committed
add more baseline tests + refactor
1 parent 9f33bd9 commit 56817c8

16 files changed

+470
-217
lines changed

src/compiler/checker.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -13099,7 +13099,7 @@ namespace ts {
1309913099

1310013100
function isStringOrNumericLiteralType(type: Type): boolean {
1310113101
return type.flags & TypeFlags.Union ? every((<UnionType>type).types, t => !!(t.flags & TypeFlags.StringOrNumberLiteral && !(t.flags & (TypeFlags.EnumLike | TypeFlags.Intrinsic)))) :
13102-
!!(type.flags & TypeFlags.StringOrNumberLiteral) && !(type.flags & (TypeFlags.EnumLike | TypeFlags.Intrinsic))
13102+
!!(type.flags & TypeFlags.StringOrNumberLiteral) && !(type.flags & (TypeFlags.EnumLike | TypeFlags.Intrinsic));
1310313103
}
1310413104

1310513105
function getBaseTypeOfLiteralType(type: Type): Type {
@@ -21616,17 +21616,17 @@ namespace ts {
2161621616

2161721617
function checkUnaryExpression(node: PrefixUnaryExpression | PostfixUnaryExpression): Type {
2161821618
const symbol = isEntityNameExpression(node.operand) ? isPropertyAccessEntityNameExpression(node.operand) ?
21619-
getSymbolAtLocation((<PropertyAccessExpression>node.operand).name) : getResolvedSymbol(node.operand as Identifier) : undefined;
21619+
getSymbolAtLocation((<PropertyAccessExpression>node.operand).name) : getResolvedSymbol(node.operand) : undefined;
2162021620
if (symbol && isUnaryAssignmentOperator(node.operator) && !(getDeclarationNodeFlagsFromSymbol(symbol) & NodeFlags.Const)) {
2162121621
const operandType = getTypeOfSymbol(symbol);
2162221622
if (isStringOrNumericLiteralType(operandType)) {
2162321623
error(node.operand, Diagnostics.The_literal_type_0_cannot_be_modified, typeToString(operandType));
2162421624
}
2162521625
}
21626-
if (node.kind == SyntaxKind.PrefixUnaryExpression) {
21627-
return checkPrefixUnaryExpression(node)
21626+
if (node.kind === SyntaxKind.PrefixUnaryExpression) {
21627+
return checkPrefixUnaryExpression(node);
2162821628
}
21629-
return checkPostfixUnaryExpression(node)
21629+
return checkPostfixUnaryExpression(node);
2163021630
}
2163121631

2163221632
// Return true if type might be of the given kind. A union or intersection type might be of a given
@@ -21974,7 +21974,7 @@ namespace ts {
2197421974
let leftType: Type;
2197521975

2197621976
const symbol = isEntityNameExpression(left) ? isPropertyAccessEntityNameExpression(left) ?
21977-
getSymbolAtLocation((<PropertyAccessExpression>left).name) : getResolvedSymbol(left as Identifier) : undefined;
21977+
getSymbolAtLocation((<PropertyAccessExpression>left).name) : getResolvedSymbol(left) : undefined;
2197821978
if (symbol && isCompoundAssignmentOperator(operator) && !(getDeclarationNodeFlagsFromSymbol(symbol) & NodeFlags.Const)) {
2197921979
leftType = getTypeOfSymbol(getResolvedSymbol(left as Identifier));
2198021980
if (isStringOrNumericLiteralType(leftType)) {

src/compiler/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3791,7 +3791,7 @@ namespace ts {
37913791

37923792
export function isUnaryAssignmentOperator(token: SyntaxKind): boolean {
37933793
return token === SyntaxKind.PlusPlusToken
3794-
|| token === SyntaxKind.MinusMinusToken
3794+
|| token === SyntaxKind.MinusMinusToken;
37953795

37963796
}
37973797

tests/baselines/reference/enumLiteralTypes1.errors.txt

-119
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
tests/cases/conformance/types/literal/literalTypeProperty.ts(7,1): error TS2739: The literal type '10' cannot be modified.
2+
tests/cases/conformance/types/literal/literalTypeProperty.ts(8,1): error TS2739: The literal type '10' cannot be modified.
3+
tests/cases/conformance/types/literal/literalTypeProperty.ts(9,1): error TS2739: The literal type '10' cannot be modified.
4+
tests/cases/conformance/types/literal/literalTypeProperty.ts(10,1): error TS2739: The literal type '10' cannot be modified.
5+
tests/cases/conformance/types/literal/literalTypeProperty.ts(11,3): error TS2739: The literal type '10' cannot be modified.
6+
tests/cases/conformance/types/literal/literalTypeProperty.ts(12,3): error TS2739: The literal type '10' cannot be modified.
7+
tests/cases/conformance/types/literal/literalTypeProperty.ts(14,1): error TS2739: The literal type '10 | 11' cannot be modified.
8+
tests/cases/conformance/types/literal/literalTypeProperty.ts(15,1): error TS2739: The literal type '10 | 11' cannot be modified.
9+
tests/cases/conformance/types/literal/literalTypeProperty.ts(16,1): error TS2739: The literal type '10 | 11' cannot be modified.
10+
tests/cases/conformance/types/literal/literalTypeProperty.ts(17,1): error TS2739: The literal type '10 | 11' cannot be modified.
11+
tests/cases/conformance/types/literal/literalTypeProperty.ts(18,3): error TS2739: The literal type '10 | 11' cannot be modified.
12+
tests/cases/conformance/types/literal/literalTypeProperty.ts(19,3): error TS2739: The literal type '10 | 11' cannot be modified.
13+
14+
15+
==== tests/cases/conformance/types/literal/literalTypeProperty.ts (12 errors) ====
16+
declare class C {
17+
foo: 10;
18+
bar: 10 | 11
19+
}
20+
21+
var o = new C()
22+
o.foo ++
23+
~~~~~
24+
!!! error TS2739: The literal type '10' cannot be modified.
25+
o.foo += 1
26+
~~~~~
27+
!!! error TS2739: The literal type '10' cannot be modified.
28+
o.foo -= 1
29+
~~~~~
30+
!!! error TS2739: The literal type '10' cannot be modified.
31+
o.foo --
32+
~~~~~
33+
!!! error TS2739: The literal type '10' cannot be modified.
34+
++o.foo
35+
~~~~~
36+
!!! error TS2739: The literal type '10' cannot be modified.
37+
--o.foo
38+
~~~~~
39+
!!! error TS2739: The literal type '10' cannot be modified.
40+
41+
o.bar ++
42+
~~~~~
43+
!!! error TS2739: The literal type '10 | 11' cannot be modified.
44+
o.bar += 1
45+
~~~~~
46+
!!! error TS2739: The literal type '10 | 11' cannot be modified.
47+
o.bar -= 1
48+
~~~~~
49+
!!! error TS2739: The literal type '10 | 11' cannot be modified.
50+
o.bar --
51+
~~~~~
52+
!!! error TS2739: The literal type '10 | 11' cannot be modified.
53+
++o.bar
54+
~~~~~
55+
!!! error TS2739: The literal type '10 | 11' cannot be modified.
56+
--o.bar
57+
~~~~~
58+
!!! error TS2739: The literal type '10 | 11' cannot be modified.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//// [literalTypeProperty.ts]
2+
declare class C {
3+
foo: 10;
4+
bar: 10 | 11
5+
}
6+
7+
var o = new C()
8+
o.foo ++
9+
o.foo += 1
10+
o.foo -= 1
11+
o.foo --
12+
++o.foo
13+
--o.foo
14+
15+
o.bar ++
16+
o.bar += 1
17+
o.bar -= 1
18+
o.bar --
19+
++o.bar
20+
--o.bar
21+
22+
//// [literalTypeProperty.js]
23+
var o = new C();
24+
o.foo++;
25+
o.foo += 1;
26+
o.foo -= 1;
27+
o.foo--;
28+
++o.foo;
29+
--o.foo;
30+
o.bar++;
31+
o.bar += 1;
32+
o.bar -= 1;
33+
o.bar--;
34+
++o.bar;
35+
--o.bar;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
=== tests/cases/conformance/types/literal/literalTypeProperty.ts ===
2+
declare class C {
3+
>C : Symbol(C, Decl(literalTypeProperty.ts, 0, 0))
4+
5+
foo: 10;
6+
>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
7+
8+
bar: 10 | 11
9+
>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
10+
}
11+
12+
var o = new C()
13+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
14+
>C : Symbol(C, Decl(literalTypeProperty.ts, 0, 0))
15+
16+
o.foo ++
17+
>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
18+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
19+
>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
20+
21+
o.foo += 1
22+
>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
23+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
24+
>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
25+
26+
o.foo -= 1
27+
>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
28+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
29+
>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
30+
31+
o.foo --
32+
>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
33+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
34+
>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
35+
36+
++o.foo
37+
>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
38+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
39+
>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
40+
41+
--o.foo
42+
>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
43+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
44+
>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17))
45+
46+
o.bar ++
47+
>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
48+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
49+
>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
50+
51+
o.bar += 1
52+
>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
53+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
54+
>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
55+
56+
o.bar -= 1
57+
>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
58+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
59+
>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
60+
61+
o.bar --
62+
>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
63+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
64+
>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
65+
66+
++o.bar
67+
>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
68+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
69+
>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
70+
71+
--o.bar
72+
>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
73+
>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3))
74+
>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10))
75+

0 commit comments

Comments
 (0)