mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-18 03:43:28 -06:00
Fix object type literal regression
This commit is contained in:
parent
c93f454549
commit
40a2a2584d
@ -783,7 +783,7 @@
|
||||
"category": "Error",
|
||||
"code": 1245
|
||||
},
|
||||
"An interface property cannot have an initializer.": {
|
||||
"An object type property cannot have an initializer.": {
|
||||
"category": "Error",
|
||||
"code": 1246
|
||||
},
|
||||
|
||||
@ -2230,7 +2230,6 @@ namespace ts {
|
||||
const fullStart = scanner.getStartPos();
|
||||
const name = parsePropertyName();
|
||||
const questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
|
||||
const modifiers = parseModifiers();
|
||||
|
||||
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
|
||||
const method = <MethodSignature>createNode(SyntaxKind.MethodSignature, fullStart);
|
||||
@ -2251,21 +2250,8 @@ namespace ts {
|
||||
|
||||
// Although interfaces cannot not have initializers, we attempt to parse an initializer
|
||||
// so we can report that an interface cannot have an initializer.
|
||||
//
|
||||
// For instance properties specifically, since they are evaluated inside the constructor,
|
||||
// we do *not * want to parse yield expressions, so we specifically turn the yield context
|
||||
// off. The grammar would look something like this:
|
||||
//
|
||||
// MemberVariableDeclaration[Yield]:
|
||||
// AccessibilityModifier_opt PropertyName TypeAnnotation_opt Initialiser_opt[In];
|
||||
// AccessibilityModifier_opt static_opt PropertyName TypeAnnotation_opt Initialiser_opt[In, ?Yield];
|
||||
//
|
||||
// The checker may still error in the static case to explicitly disallow the yield expression.
|
||||
const initializer = modifiers && modifiers.flags & NodeFlags.Static
|
||||
? allowInAnd(parseNonParameterInitializer)
|
||||
: doOutsideOfContext(ParserContextFlags.Yield | ParserContextFlags.DisallowIn, parseNonParameterInitializer);
|
||||
if (initializer !== undefined) {
|
||||
parseErrorAtCurrentToken(Diagnostics.An_interface_property_cannot_have_an_initializer);
|
||||
if (token === SyntaxKind.EqualsToken && lookAhead(() => parseNonParameterInitializer()) !== undefined) {
|
||||
parseErrorAtCurrentToken(Diagnostics.An_object_type_property_cannot_have_an_initializer);
|
||||
}
|
||||
|
||||
parseTypeMemberSemicolon();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user