Disallow modifiers in object literal property assignment

Fixes bug #5994
This commit is contained in:
Ryan Cavanaugh
2015-12-08 10:11:29 -08:00
parent 7c1ef22cff
commit 92d7d1c953
5 changed files with 57 additions and 0 deletions
+5
View File
@@ -15969,6 +15969,11 @@ namespace ts {
return grammarErrorOnNode((<ShorthandPropertyAssignment>prop).equalsToken, Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment);
}
// Modifiers cannot appear in property assignments
if (prop.modifiers && prop.modifiers.length > 0) {
grammarErrorOnNode(prop.modifiers[0], Diagnostics.Modifiers_cannot_appear_here);
}
// ECMA-262 11.1.5 Object Initialiser
// If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true
// a.This production is contained in strict code and IsDataDescriptor(previous) is true and
+1
View File
@@ -3981,6 +3981,7 @@ namespace ts {
}
else {
const propertyAssignment = <PropertyAssignment>createNode(SyntaxKind.PropertyAssignment, fullStart);
propertyAssignment.modifiers = modifiers;
propertyAssignment.name = propertyName;
propertyAssignment.questionToken = questionToken;
parseExpected(SyntaxKind.ColonToken);
@@ -0,0 +1,24 @@
tests/cases/compiler/modifiersInObjectLiterals.ts(2,2): error TS1184: Modifiers cannot appear here.
tests/cases/compiler/modifiersInObjectLiterals.ts(3,2): error TS1184: Modifiers cannot appear here.
tests/cases/compiler/modifiersInObjectLiterals.ts(4,2): error TS1184: Modifiers cannot appear here.
tests/cases/compiler/modifiersInObjectLiterals.ts(5,2): error TS1184: Modifiers cannot appear here.
==== tests/cases/compiler/modifiersInObjectLiterals.ts (4 errors) ====
let data = {
public foo: 'hey',
~~~~~~
!!! error TS1184: Modifiers cannot appear here.
private bar: 'nay',
~~~~~~~
!!! error TS1184: Modifiers cannot appear here.
protected baz: 'oh my',
~~~~~~~~~
!!! error TS1184: Modifiers cannot appear here.
abstract noWay: 'yes'
~~~~~~~~
!!! error TS1184: Modifiers cannot appear here.
};
data.foo + data.bar + data.baz + data.noWay
@@ -0,0 +1,19 @@
//// [modifiersInObjectLiterals.ts]
let data = {
public foo: 'hey',
private bar: 'nay',
protected baz: 'oh my',
abstract noWay: 'yes'
};
data.foo + data.bar + data.baz + data.noWay
//// [modifiersInObjectLiterals.js]
var data = {
foo: 'hey',
bar: 'nay',
baz: 'oh my',
noWay: 'yes'
};
data.foo + data.bar + data.baz + data.noWay;
@@ -0,0 +1,8 @@
let data = {
public foo: 'hey',
private bar: 'nay',
protected baz: 'oh my',
abstract noWay: 'yes'
};
data.foo + data.bar + data.baz + data.noWay