Skip to content

Commit e7ff747

Browse files
committed
Port small fix
1 parent b3c6a92 commit e7ff747

File tree

3 files changed

+2
-68
lines changed

3 files changed

+2
-68
lines changed

internal/checker/grammarchecks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ func (c *Checker) checkGrammarProperty(node *ast.Node /*Union[PropertyDeclaratio
19211921
if c.languageVersion < core.ScriptTargetES2015 && ast.IsPrivateIdentifier(propertyName) {
19221922
return c.grammarErrorOnNode(propertyName, diagnostics.Private_identifiers_are_only_available_when_targeting_ECMAScript_2015_and_higher)
19231923
}
1924-
if c.languageVersion < core.ScriptTargetES2015 && ast.IsAutoAccessorPropertyDeclaration(node) {
1924+
if c.languageVersion < core.ScriptTargetES2015 && ast.IsAutoAccessorPropertyDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 {
19251925
return c.grammarErrorOnNode(propertyName, diagnostics.Properties_with_the_accessor_modifier_are_only_available_when_targeting_ECMAScript_2015_and_higher)
19261926
}
19271927
if ast.IsAutoAccessorPropertyDeclaration(node) && c.checkGrammarForInvalidQuestionMark(node.AsPropertyDeclaration().PostfixToken, diagnostics.An_accessor_property_cannot_be_declared_optional) {

testdata/baselines/reference/submodule/compiler/accessorInAmbientContextES5.errors.txt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,26 @@
1-
accessorInAmbientContextES5.ts(4,14): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
2-
accessorInAmbientContextES5.ts(5,21): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
3-
accessorInAmbientContextES5.ts(6,22): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
4-
accessorInAmbientContextES5.ts(7,29): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
5-
accessorInAmbientContextES5.ts(12,18): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
6-
accessorInAmbientContextES5.ts(19,18): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
71
accessorInAmbientContextES5.ts(25,14): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
82

93

10-
==== accessorInAmbientContextES5.ts (7 errors) ====
4+
==== accessorInAmbientContextES5.ts (1 errors) ====
115
// Should allow accessor in ambient contexts even when targeting ES5
126

137
declare class AmbientClass {
148
accessor prop1: string;
15-
~~~~~
16-
!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
179
static accessor prop2: number;
18-
~~~~~
19-
!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
2010
private accessor prop3: boolean;
21-
~~~~~
22-
!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
2311
private static accessor prop4: symbol;
24-
~~~~~
25-
!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
2612
}
2713

2814
declare namespace AmbientNamespace {
2915
class C {
3016
accessor prop: string;
31-
~~~~
32-
!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
3317
}
3418
}
3519

3620
// Should also work in .d.ts files (simulated with declare)
3721
declare module "some-module" {
3822
export class ExportedClass {
3923
accessor value: any;
40-
~~~~~
41-
!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.
4224
}
4325
}
4426

testdata/baselines/reference/submodule/compiler/accessorInAmbientContextES5.errors.txt.diff

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)