@@ -696,6 +696,30 @@ public class JavaScriptCompiler {
696
696
}
697
697
}
698
698
}
699
+ case . superMemberExpression( let superMemberExpression) :
700
+ guard superMemberExpression. isOptional == false else {
701
+ throw CompilerError . unsupportedFeatureError ( " Optional chaining is not supported in super member expressions " )
702
+ }
703
+
704
+ guard let property = superMemberExpression. property else {
705
+ throw CompilerError . invalidNodeError ( " Missing property in super member expression " )
706
+ }
707
+
708
+ switch property {
709
+ case . name( let name) :
710
+ if let op = assignmentOperator {
711
+ // Example: super.foo += 1
712
+ emit ( UpdateSuperProperty ( propertyName: name, operator: op) , withInputs: [ rhs] )
713
+ } else {
714
+ // Example: super.foo = 1
715
+ emit ( SetSuperProperty ( propertyName: name) , withInputs: [ rhs] )
716
+ }
717
+
718
+ case . expression( let expr) :
719
+ let property = try compileExpression ( expr)
720
+ // Example: super[expr] = 1
721
+ emit ( SetComputedSuperProperty ( ) , withInputs: [ property, rhs] )
722
+ }
699
723
700
724
701
725
case . identifier( let identifier) :
@@ -924,6 +948,7 @@ public class JavaScriptCompiler {
924
948
925
949
// See if this is a function or a method call
926
950
if case . memberExpression( let memberExpression) = callExpression. callee. expression {
951
+ // obj.foo(...) or obj[expr](...)
927
952
let object = try compileExpression ( memberExpression. object)
928
953
guard let property = memberExpression. property else { throw CompilerError . invalidNodeError ( " missing property in member expression in call expression " ) }
929
954
switch property {
@@ -941,6 +966,18 @@ public class JavaScriptCompiler {
941
966
return emit ( CallComputedMethod ( numArguments: arguments. count, isGuarded: callExpression. isOptional) , withInputs: [ object, method] + arguments) . output
942
967
}
943
968
}
969
+ } else if case . superMemberExpression( let superMemberExpression) = callExpression. callee. expression {
970
+ // super.foo(...)
971
+ guard !isSpreading else {
972
+ throw CompilerError . unsupportedFeatureError ( " Spread calls with super are not supported " )
973
+ }
974
+ guard case . name( let methodName) = superMemberExpression. property else {
975
+ throw CompilerError . invalidNodeError ( " Super method calls must use a property name " )
976
+ }
977
+ guard !callExpression. isOptional else {
978
+ throw CompilerError . unsupportedFeatureError ( " Optional chaining with super method calls is not supported " )
979
+ }
980
+ return emit ( CallSuperMethod ( methodName: methodName, numArguments: arguments. count) , withInputs: arguments) . output
944
981
// Now check if it is a V8 intrinsic function
945
982
} else if case . v8IntrinsicIdentifier( let v8Intrinsic) = callExpression. callee. expression {
946
983
guard !isSpreading else { throw CompilerError . unsupportedFeatureError ( " Not currently supporting spread calls to V8 intrinsics " ) }
@@ -957,6 +994,21 @@ public class JavaScriptCompiler {
957
994
}
958
995
}
959
996
997
+ case . callSuperConstructor( let callSuperConstructor) :
998
+ let ( arguments, spreads) = try compileCallArguments ( callSuperConstructor. arguments)
999
+ let isSpreading = spreads. contains ( true )
1000
+
1001
+ if isSpreading {
1002
+ throw CompilerError . unsupportedFeatureError ( " Spread arguments are not supported in super constructor calls " )
1003
+ }
1004
+ guard !callSuperConstructor. isOptional else {
1005
+ throw CompilerError . unsupportedFeatureError ( " Optional chaining is not supported in super constructor calls " )
1006
+ }
1007
+ emit ( CallSuperConstructor ( numArguments: arguments. count) , withInputs: arguments)
1008
+ // In JS, the result of calling the super constructor is just |this|, but in FuzzIL the operation doesn't have an output (because |this| is always available anyway)
1009
+ return lookupIdentifier ( " this " ) ! // we can force unwrap because |this| always exists in the context where |super| exists
1010
+
1011
+
960
1012
case . newExpression( let newExpression) :
961
1013
let callee = try compileExpression ( newExpression. callee)
962
1014
let ( arguments, spreads) = try compileCallArguments ( newExpression. arguments)
@@ -981,6 +1033,27 @@ public class JavaScriptCompiler {
981
1033
return emit ( GetComputedProperty ( isGuarded: memberExpression. isOptional) , withInputs: [ object, property] ) . output
982
1034
}
983
1035
}
1036
+
1037
+ case . superMemberExpression( let superMemberExpression) :
1038
+ guard superMemberExpression. isOptional == false else {
1039
+ throw CompilerError . unsupportedFeatureError ( " Optional chaining is not supported in super member expressions " )
1040
+ }
1041
+ guard let property = superMemberExpression. property else {
1042
+ throw CompilerError . invalidNodeError ( " Missing property in super member expression " )
1043
+ }
1044
+
1045
+ switch property {
1046
+ case . name( let name) :
1047
+ return emit ( GetSuperProperty ( propertyName: name) , withInputs: [ ] ) . output
1048
+
1049
+ case . expression( let expr) :
1050
+ if case . numberLiteral( let literal) = expr. expression, let _ = Int64 ( exactly: literal. value) {
1051
+ throw CompilerError . unsupportedFeatureError ( " GetElement is not supported in super member expressions " )
1052
+ } else {
1053
+ let compiledProperty = try compileExpression ( expr)
1054
+ return emit ( GetComputedSuperProperty ( ) , withInputs: [ compiledProperty] ) . output
1055
+ }
1056
+ }
984
1057
985
1058
case . unaryExpression( let unaryExpression) :
986
1059
if unaryExpression. operator == " typeof " {
0 commit comments