mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Disallow modifiers in object literal property assignment
Fixes bug #5994
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user