Skip to content

Commit 964fbea

Browse files
committed
Fix up for 'async'
1 parent 92d7d1c commit 964fbea

5 files changed

Lines changed: 28 additions & 14 deletions

File tree

src/compiler/checker.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15970,9 +15970,14 @@ namespace ts {
1597015970
}
1597115971

1597215972
// Modifiers cannot appear in property assignments
15973-
if (prop.modifiers && prop.modifiers.length > 0) {
15974-
grammarErrorOnNode(prop.modifiers[0], Diagnostics.Modifiers_cannot_appear_here);
15975-
}
15973+
forEach(prop.modifiers, mod => {
15974+
if (mod.kind !== SyntaxKind.AsyncKeyword) {
15975+
grammarErrorOnNode(mod, Diagnostics._0_modifier_cannot_be_used_here, getTextOfNode(mod));
15976+
}
15977+
else if (prop.kind !== SyntaxKind.MethodDeclaration) {
15978+
grammarErrorOnNode(mod, Diagnostics._0_modifier_cannot_be_used_here, getTextOfNode(mod));
15979+
}
15980+
});
1597615981

1597715982
// ECMA-262 11.1.5 Object Initialiser
1597815983
// If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true

tests/baselines/reference/modifiersInObjectLiterals.errors.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
tests/cases/compiler/modifiersInObjectLiterals.ts(2,2): error TS1184: Modifiers cannot appear here.
2-
tests/cases/compiler/modifiersInObjectLiterals.ts(3,2): error TS1184: Modifiers cannot appear here.
3-
tests/cases/compiler/modifiersInObjectLiterals.ts(4,2): error TS1184: Modifiers cannot appear here.
4-
tests/cases/compiler/modifiersInObjectLiterals.ts(5,2): error TS1184: Modifiers cannot appear here.
1+
tests/cases/compiler/modifiersInObjectLiterals.ts(2,2): error TS1042: 'public' modifier cannot be used here.
2+
tests/cases/compiler/modifiersInObjectLiterals.ts(3,2): error TS1042: 'private' modifier cannot be used here.
3+
tests/cases/compiler/modifiersInObjectLiterals.ts(4,2): error TS1042: 'protected' modifier cannot be used here.
4+
tests/cases/compiler/modifiersInObjectLiterals.ts(5,2): error TS1042: 'abstract' modifier cannot be used here.
55

66

77
==== tests/cases/compiler/modifiersInObjectLiterals.ts (4 errors) ====
88
let data = {
99
public foo: 'hey',
1010
~~~~~~
11-
!!! error TS1184: Modifiers cannot appear here.
11+
!!! error TS1042: 'public' modifier cannot be used here.
1212
private bar: 'nay',
1313
~~~~~~~
14-
!!! error TS1184: Modifiers cannot appear here.
14+
!!! error TS1042: 'private' modifier cannot be used here.
1515
protected baz: 'oh my',
1616
~~~~~~~~~
17-
!!! error TS1184: Modifiers cannot appear here.
17+
!!! error TS1042: 'protected' modifier cannot be used here.
1818
abstract noWay: 'yes'
1919
~~~~~~~~
20-
!!! error TS1184: Modifiers cannot appear here.
20+
!!! error TS1042: 'abstract' modifier cannot be used here.
2121
};
2222

2323
data.foo + data.bar + data.baz + data.noWay
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
tests/cases/compiler/objectLiteralMemberWithModifiers1.ts(1,11): error TS1042: 'public' modifier cannot be used here.
12
tests/cases/compiler/objectLiteralMemberWithModifiers1.ts(1,11): error TS1184: Modifiers cannot appear here.
23

34

4-
==== tests/cases/compiler/objectLiteralMemberWithModifiers1.ts (1 errors) ====
5+
==== tests/cases/compiler/objectLiteralMemberWithModifiers1.ts (2 errors) ====
56
var v = { public foo() { } }
67
~~~~~~
8+
!!! error TS1042: 'public' modifier cannot be used here.
9+
~~~~~~
710
!!! error TS1184: Modifiers cannot appear here.

tests/baselines/reference/objectLiteralMemberWithModifiers2.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
tests/cases/compiler/objectLiteralMemberWithModifiers2.ts(1,11): error TS1042: 'public' modifier cannot be used here.
12
tests/cases/compiler/objectLiteralMemberWithModifiers2.ts(1,22): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
23
tests/cases/compiler/objectLiteralMemberWithModifiers2.ts(1,22): error TS2378: A 'get' accessor must return a value.
34

45

5-
==== tests/cases/compiler/objectLiteralMemberWithModifiers2.ts (2 errors) ====
6+
==== tests/cases/compiler/objectLiteralMemberWithModifiers2.ts (3 errors) ====
67
var v = { public get foo() { } }
8+
~~~~~~
9+
!!! error TS1042: 'public' modifier cannot be used here.
710
~~~
811
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
912
~~~
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors10.ts(2,3): error TS1042: 'public' modifier cannot be used here.
12
tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors10.ts(2,14): error TS2378: A 'get' accessor must return a value.
23

34

4-
==== tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors10.ts (1 errors) ====
5+
==== tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors10.ts (2 errors) ====
56
var v = {
67
public get foo() { }
8+
~~~~~~
9+
!!! error TS1042: 'public' modifier cannot be used here.
710
~~~
811
!!! error TS2378: A 'get' accessor must return a value.
912
};

0 commit comments

Comments
 (0)