@@ -106,6 +106,7 @@ import {
106
106
Range ,
107
107
DecoratorKind ,
108
108
AssertionKind ,
109
+ SourceKind ,
109
110
110
111
Statement ,
111
112
BlockStatement ,
@@ -135,6 +136,7 @@ import {
135
136
WhileStatement ,
136
137
137
138
Expression ,
139
+ ExportDefaultStatement ,
138
140
AssertionExpression ,
139
141
BinaryExpression ,
140
142
CallExpression ,
@@ -151,16 +153,15 @@ import {
151
153
ParenthesizedExpression ,
152
154
PropertyAccessExpression ,
153
155
TernaryExpression ,
156
+ CoalesceExpression ,
154
157
ArrayLiteralExpression ,
155
158
StringLiteralExpression ,
156
159
UnaryPostfixExpression ,
157
160
UnaryPrefixExpression ,
158
161
159
162
nodeIsConstantValue ,
160
163
findDecorator ,
161
- isTypeOmitted ,
162
- ExportDefaultStatement ,
163
- SourceKind
164
+ isTypeOmitted
164
165
} from "./ast" ;
165
166
166
167
import {
@@ -1146,7 +1147,7 @@ export class Compiler extends DiagnosticEmitter {
1146
1147
assert ( instance . prototype . arrowKind ) ;
1147
1148
1148
1149
// none of the following can be an arrow function
1149
- assert ( ! instance . isAny ( CommonFlags . CONSTRUCTOR | CommonFlags . GET | CommonFlags . SET | CommonFlags . MAIN ) ) ;
1150
+ assert ( ! instance . isAny ( CommonFlags . CONSTRUCTOR | CommonFlags . GET | CommonFlags . SET ) ) ;
1150
1151
1151
1152
let expr = this . compileExpression ( ( < ExpressionStatement > bodyNode ) . expression , returnType ,
1152
1153
Constraints . CONV_IMPLICIT
@@ -2849,6 +2850,10 @@ export class Compiler extends DiagnosticEmitter {
2849
2850
expr = this . compileTernaryExpression ( < TernaryExpression > expression , contextualType , constraints ) ;
2850
2851
break ;
2851
2852
}
2853
+ case NodeKind . COALESCE : {
2854
+ expr = this . compileCoalesceExpression ( < CoalesceExpression > expression , contextualType , constraints ) ;
2855
+ break ;
2856
+ }
2852
2857
case NodeKind . UNARYPOSTFIX : {
2853
2858
expr = this . compileUnaryPostfixExpression ( < UnaryPostfixExpression > expression , contextualType , constraints ) ;
2854
2859
break ;
@@ -2892,9 +2897,13 @@ export class Compiler extends DiagnosticEmitter {
2892
2897
contextualType : Type ,
2893
2898
constraints : Constraints = Constraints . NONE
2894
2899
) : ExpressionRef {
2895
- return this . module . precomputeExpression (
2896
- this . compileExpression ( expression , contextualType , constraints )
2897
- ) ;
2900
+ var orig = this . compileExpression ( expression , contextualType , constraints ) ;
2901
+ var expr = this . module . precomputeExpression ( orig ) ;
2902
+ if ( orig != expr ) {
2903
+ let skippedAutoreleases = this . skippedAutoreleases ;
2904
+ if ( skippedAutoreleases . has ( orig ) ) skippedAutoreleases . add ( expr ) ;
2905
+ }
2906
+ return expr ;
2898
2907
}
2899
2908
2900
2909
convertExpression (
@@ -5734,9 +5743,41 @@ export class Compiler extends DiagnosticEmitter {
5734
5743
5735
5744
var module = this . module ;
5736
5745
var flow = this . currentFlow ;
5746
+ var targetExpression = expression . expression ;
5747
+
5748
+ // TODO: In these cases we compile the target of an element or property
5749
+ // access, but not the element or property access itself, essentially
5750
+ // skipping over optional chaining.
5751
+ switch ( targetExpression . kind ) {
5752
+ case NodeKind . ELEMENTACCESS : {
5753
+ if ( ( < ElementAccessExpression > targetExpression ) . isOptionalChaining ) {
5754
+ this . error (
5755
+ DiagnosticCode . Not_implemented ,
5756
+ ( < ElementAccessExpression > targetExpression ) . expression . range . atEnd
5757
+ ) ;
5758
+ }
5759
+ break ;
5760
+ }
5761
+ case NodeKind . PROPERTYACCESS : {
5762
+ if ( ( < PropertyAccessExpression > targetExpression ) . isOptionalChaining ) {
5763
+ this . error (
5764
+ DiagnosticCode . Not_implemented ,
5765
+ ( < PropertyAccessExpression > targetExpression ) . expression . range . atEnd
5766
+ ) ;
5767
+ }
5768
+ break ;
5769
+ }
5770
+ }
5771
+ // TODO
5772
+ if ( expression . isOptionalChaining ) {
5773
+ this . error (
5774
+ DiagnosticCode . Not_implemented ,
5775
+ targetExpression . range . atEnd
5776
+ ) ;
5777
+ }
5737
5778
5738
5779
// handle call to super
5739
- if ( expression . expression . kind == NodeKind . SUPER ) {
5780
+ if ( targetExpression . kind == NodeKind . SUPER ) {
5740
5781
let flow = this . currentFlow ;
5741
5782
let actualFunction = flow . actualFunction ;
5742
5783
if ( ! actualFunction . is ( CommonFlags . CONSTRUCTOR ) ) {
@@ -5793,7 +5834,7 @@ export class Compiler extends DiagnosticEmitter {
5793
5834
}
5794
5835
5795
5836
// otherwise resolve normally
5796
- var target = this . resolver . lookupExpression ( expression . expression , flow ) ; // reports
5837
+ var target = this . resolver . lookupExpression ( targetExpression , flow ) ; // reports
5797
5838
if ( ! target ) return module . unreachable ( ) ;
5798
5839
5799
5840
var signature : Signature | null ;
@@ -5817,7 +5858,7 @@ export class Compiler extends DiagnosticEmitter {
5817
5858
if ( ! prototype . is ( CommonFlags . GENERIC ) ) {
5818
5859
this . error (
5819
5860
DiagnosticCode . Type_0_is_not_generic ,
5820
- expression . expression . range , prototype . internalName
5861
+ targetExpression . range , prototype . internalName
5821
5862
) ;
5822
5863
return module . unreachable ( ) ;
5823
5864
}
@@ -5879,7 +5920,7 @@ export class Compiler extends DiagnosticEmitter {
5879
5920
// invalid because the type is effectively unknown inside the function body
5880
5921
this . error (
5881
5922
DiagnosticCode . Type_argument_expected ,
5882
- expression . expression . range . atEnd
5923
+ targetExpression . range . atEnd
5883
5924
) ;
5884
5925
return this . module . unreachable ( ) ;
5885
5926
}
@@ -5962,15 +6003,15 @@ export class Compiler extends DiagnosticEmitter {
5962
6003
}
5963
6004
case ElementKind . FUNCTION_TARGET : {
5964
6005
signature = ( < FunctionTarget > target ) . signature ;
5965
- indexArg = this . compileExpression ( expression . expression , ( < FunctionTarget > target ) . type , Constraints . CONV_IMPLICIT ) ;
6006
+ indexArg = this . compileExpression ( targetExpression , ( < FunctionTarget > target ) . type , Constraints . CONV_IMPLICIT ) ;
5966
6007
break ;
5967
6008
}
5968
6009
5969
6010
case ElementKind . PROPERTY_PROTOTYPE : { // static property
5970
6011
let getterPrototype = assert ( ( < PropertyPrototype > target ) . getterPrototype ) ;
5971
6012
let getterInstance = this . resolver . resolveFunction ( getterPrototype , null ) ;
5972
6013
if ( ! getterInstance ) return module . unreachable ( ) ;
5973
- indexArg = this . compileCallDirect ( getterInstance , [ ] , expression . expression ) ;
6014
+ indexArg = this . compileCallDirect ( getterInstance , [ ] , targetExpression ) ;
5974
6015
signature = this . currentType . signatureReference ;
5975
6016
if ( ! signature ) {
5976
6017
this . error (
@@ -5983,7 +6024,7 @@ export class Compiler extends DiagnosticEmitter {
5983
6024
}
5984
6025
case ElementKind . PROPERTY : { // instance property
5985
6026
let getterInstance = assert ( ( < Property > target ) . getterInstance ) ;
5986
- indexArg = this . compileCallDirect ( getterInstance , [ ] , expression . expression ,
6027
+ indexArg = this . compileCallDirect ( getterInstance , [ ] , targetExpression ,
5987
6028
this . compileExpression ( assert ( this . resolver . currentThisExpression ) , this . options . usizeType )
5988
6029
) ;
5989
6030
signature = this . currentType . signatureReference ;
@@ -6948,6 +6989,14 @@ export class Compiler extends DiagnosticEmitter {
6948
6989
contextualType : Type ,
6949
6990
constraints : Constraints
6950
6991
) : ExpressionRef {
6992
+
6993
+ if ( expression . isOptionalChaining ) {
6994
+ this . error (
6995
+ DiagnosticCode . Not_implemented ,
6996
+ expression . expression . range . atEnd
6997
+ ) ;
6998
+ }
6999
+
6951
7000
var module = this . module ;
6952
7001
var targetExpression = expression . expression ;
6953
7002
var targetType = this . resolver . resolveExpression ( targetExpression , this . currentFlow ) ; // reports
@@ -7951,6 +8000,14 @@ export class Compiler extends DiagnosticEmitter {
7951
8000
ctxType : Type ,
7952
8001
constraints : Constraints
7953
8002
) : ExpressionRef {
8003
+
8004
+ if ( expression . isOptionalChaining ) {
8005
+ this . error (
8006
+ DiagnosticCode . Not_implemented ,
8007
+ expression . expression . range . atEnd
8008
+ ) ;
8009
+ }
8010
+
7954
8011
var module = this . module ;
7955
8012
var flow = this . currentFlow ;
7956
8013
@@ -8138,6 +8195,18 @@ export class Compiler extends DiagnosticEmitter {
8138
8195
return expr ;
8139
8196
}
8140
8197
8198
+ compileCoalesceExpression (
8199
+ expression : CoalesceExpression ,
8200
+ ctxType : Type ,
8201
+ constraints : Constraints
8202
+ ) : ExpressionRef {
8203
+ this . error (
8204
+ DiagnosticCode . Not_implemented ,
8205
+ expression . range
8206
+ ) ;
8207
+ return this . module . unreachable ( ) ;
8208
+ }
8209
+
8141
8210
compileUnaryPostfixExpression (
8142
8211
expression : UnaryPostfixExpression ,
8143
8212
contextualType : Type ,
0 commit comments