@@ -1839,6 +1839,7 @@ export class Parser extends DiagnosticEmitter {
1839
1839
) : Node | null {
1840
1840
1841
1841
// before:
1842
+ // 'declare'?
1842
1843
// ('public' | 'private' | 'protected')?
1843
1844
// ('static' | 'abstract')?
1844
1845
// 'readonly'?
@@ -1870,6 +1871,32 @@ export class Parser extends DiagnosticEmitter {
1870
1871
// implemented methods are virtual
1871
1872
if ( isInterface ) flags |= CommonFlags . VIRTUAL ;
1872
1873
1874
+ var declareStart = 0 ;
1875
+ var declareEnd = 0 ;
1876
+ var contextIsAmbient = parent . is ( CommonFlags . AMBIENT ) ;
1877
+ if ( tn . skip ( Token . DECLARE ) ) {
1878
+ if ( isInterface ) {
1879
+ this . error (
1880
+ DiagnosticCode . _0_modifier_cannot_be_used_here ,
1881
+ tn . range ( ) , "declare"
1882
+ ) ;
1883
+ } else {
1884
+ if ( contextIsAmbient ) {
1885
+ this . error (
1886
+ DiagnosticCode . A_declare_modifier_cannot_be_used_in_an_already_ambient_context ,
1887
+ tn . range ( )
1888
+ ) ; // recoverable
1889
+ } else {
1890
+ flags |= CommonFlags . DECLARE | CommonFlags . AMBIENT ;
1891
+ declareStart = tn . tokenPos ;
1892
+ declareEnd = tn . pos ;
1893
+ }
1894
+ }
1895
+ if ( ! startPos ) startPos = tn . tokenPos ;
1896
+ } else if ( contextIsAmbient ) {
1897
+ flags |= CommonFlags . AMBIENT ;
1898
+ }
1899
+
1873
1900
var accessStart = 0 ;
1874
1901
var accessEnd = 0 ;
1875
1902
if ( tn . skip ( Token . PUBLIC ) ) {
@@ -2108,6 +2135,13 @@ export class Parser extends DiagnosticEmitter {
2108
2135
2109
2136
// method: '(' Parameters (':' Type)? '{' Statement* '}' ';'?
2110
2137
if ( tn . skip ( Token . OPENPAREN ) ) {
2138
+ if ( flags & CommonFlags . DECLARE ) {
2139
+ this . error (
2140
+ DiagnosticCode . _0_modifier_cannot_appear_on_class_elements_of_this_kind ,
2141
+ tn . range ( declareStart , declareEnd ) , "declare"
2142
+ ) ; // recoverable
2143
+ }
2144
+
2111
2145
let signatureStart = tn . tokenPos ;
2112
2146
let parameters = this . parseParameters ( tn , isConstructor ) ;
2113
2147
if ( ! parameters ) return null ;
@@ -2249,6 +2283,13 @@ export class Parser extends DiagnosticEmitter {
2249
2283
2250
2284
// field: (':' Type)? ('=' Expression)? ';'?
2251
2285
} else {
2286
+ if ( flags & CommonFlags . DECLARE ) {
2287
+ this . error (
2288
+ DiagnosticCode . Not_implemented_0 ,
2289
+ tn . range ( declareStart , declareEnd ) , "Ambient fields"
2290
+ ) ; // recoverable
2291
+ }
2292
+
2252
2293
if ( flags & CommonFlags . ABSTRACT ) {
2253
2294
this . error (
2254
2295
DiagnosticCode . _0_modifier_cannot_be_used_here ,
@@ -2291,6 +2332,12 @@ export class Parser extends DiagnosticEmitter {
2291
2332
}
2292
2333
let initializer : Expression | null = null ;
2293
2334
if ( tn . skip ( Token . EQUALS ) ) {
2335
+ if ( flags & CommonFlags . AMBIENT ) {
2336
+ this . error (
2337
+ DiagnosticCode . Initializers_are_not_allowed_in_ambient_contexts ,
2338
+ tn . range ( )
2339
+ ) ; // recoverable
2340
+ }
2294
2341
initializer = this . parseExpression ( tn ) ;
2295
2342
if ( ! initializer ) return null ;
2296
2343
}
0 commit comments