@@ -1095,6 +1095,204 @@ extension type Foo(int value) {
10951095 frontendServer.close ();
10961096 }, timeout: new Timeout .factor (100 ));
10971097
1098+ test ('compile expression to JavaScript when delta is rejected' , () async {
1099+ File fileLib = new File ('${tempDir .path }/lib.dart' )..createSync ();
1100+ fileLib.writeAsStringSync ("foo() => 42;\n " );
1101+ File file = new File ('${tempDir .path }/foo.dart' )..createSync ();
1102+ // Initial compile contains a generic class so an edit can be made later
1103+ // that is known to be rejected.
1104+ file.writeAsStringSync (
1105+ "import 'lib.dart'; class A<T, S> {} main1() => print(foo);\n " );
1106+ File packageConfig =
1107+ new File ('${tempDir .path }/.dart_tool/package_config.json' )
1108+ ..createSync (recursive: true )
1109+ ..writeAsStringSync ('''
1110+ {
1111+ "configVersion": 2,
1112+ "packages": [
1113+ {
1114+ "name": "hello",
1115+ "rootUri": "../",
1116+ "packageUri": "./"
1117+ }
1118+ ]
1119+ }
1120+ ''' );
1121+ File dillFile = new File ('${tempDir .path }/app.dill' );
1122+ expect (dillFile.existsSync (), equals (false ));
1123+ final List <String > args = < String > [
1124+ '--sdk-root=${sdkRoot .toFilePath ()}' ,
1125+ '--incremental' ,
1126+ '--platform=${ddcPlatformKernel .path }' ,
1127+ '--output-dill=${dillFile .path }' ,
1128+ '--target=dartdevc' ,
1129+ // TODO(nshahan): Remove these two flags when library bundle format is
1130+ // the default without passing --dartdevc-canary.
1131+ '--dartdevc-module-format=ddc' ,
1132+ '--dartdevc-canary' ,
1133+ '--packages=${packageConfig .path }' ,
1134+ ];
1135+
1136+ FrontendServer frontendServer = new FrontendServer ();
1137+ final Future <int > result = frontendServer.open (args);
1138+ frontendServer.compile (file.path);
1139+ int count = 0 ;
1140+ frontendServer.listen ((Result compiledResult) {
1141+ CompilationResult result =
1142+ new CompilationResult .parse (compiledResult.status);
1143+ if (count == 0 ) {
1144+ // First request was to 'compile', which resulted in full kernel file.
1145+ expect (result.errorsCount, 0 );
1146+ expect (dillFile.existsSync (), equals (true ));
1147+ expect (result.filename, dillFile.path);
1148+ frontendServer.accept ();
1149+
1150+ frontendServer.compileExpressionToJs (
1151+ expression: 'main1' ,
1152+ libraryUri: 'package:hello/foo.dart' ,
1153+ line: 1 ,
1154+ column: 1 ,
1155+ );
1156+ count += 1 ;
1157+ } else if (count == 1 ) {
1158+ // Second request was to 'compile-expression', which resulted in
1159+ // kernel file with a function that wraps compiled expression.
1160+ expect (result.errorsCount, 0 );
1161+ File outputFile = new File (result.filename);
1162+ expect (outputFile.existsSync (), equals (true ));
1163+ expect (outputFile.lengthSync (), isPositive);
1164+
1165+ // Removing a generic class type argument is known to cause a reload
1166+ // rejection.
1167+ file.writeAsStringSync (
1168+ "import 'lib.dart'; class A<T> {} main() => foo();\n " );
1169+
1170+ frontendServer.recompile (file.uri, entryPoint: file.path);
1171+ count += 1 ;
1172+ } else if (count == 2 ) {
1173+ // Third request was to recompile the script after renaming a
1174+ // function.
1175+ expect (result.errorsCount, 1 );
1176+ frontendServer.reject ();
1177+ count += 1 ;
1178+ } else if (count == 3 ) {
1179+ // Fourth request was to reject the compilation results.
1180+ expect (result.errorsCount, 0 );
1181+ frontendServer.compileExpressionToJs (
1182+ expression: 'main1' ,
1183+ libraryUri: 'package:hello/foo.dart' ,
1184+ line: 1 ,
1185+ column: 1 ,
1186+ );
1187+ count += 1 ;
1188+ } else {
1189+ expect (count, 4 );
1190+ // Fifth request was to 'compile-expression' that references original
1191+ // function, which should still be successful.
1192+ expect (result.errorsCount, 0 );
1193+ frontendServer.quit ();
1194+ }
1195+ });
1196+
1197+ expect (await result, 0 );
1198+ frontendServer.close ();
1199+ }, timeout: new Timeout .factor (100 ));
1200+
1201+ test ('compile expression to JavaScript when delta is accepted' , () async {
1202+ File fileLib = new File ('${tempDir .path }/lib.dart' )..createSync ();
1203+ fileLib.writeAsStringSync ("foo() => 42;\n " );
1204+ File file = new File ('${tempDir .path }/foo.dart' )..createSync ();
1205+ file.writeAsStringSync ("import 'lib.dart'; main1() => print(foo);\n " );
1206+ File packageConfig =
1207+ new File ('${tempDir .path }/.dart_tool/package_config.json' )
1208+ ..createSync (recursive: true )
1209+ ..writeAsStringSync ('''
1210+ {
1211+ "configVersion": 2,
1212+ "packages": [
1213+ {
1214+ "name": "hello",
1215+ "rootUri": "../",
1216+ "packageUri": "./"
1217+ }
1218+ ]
1219+ }
1220+ ''' );
1221+ File dillFile = new File ('${tempDir .path }/app.dill' );
1222+ expect (dillFile.existsSync (), equals (false ));
1223+ final List <String > args = < String > [
1224+ '--sdk-root=${sdkRoot .toFilePath ()}' ,
1225+ '--incremental' ,
1226+ '--platform=${ddcPlatformKernel .path }' ,
1227+ '--output-dill=${dillFile .path }' ,
1228+ '--target=dartdevc' ,
1229+ // TODO(nshahan): Remove these two flags when library bundle format is
1230+ // the default without passing --dartdevc-canary.
1231+ '--dartdevc-module-format=ddc' ,
1232+ '--dartdevc-canary' ,
1233+ '--packages=${packageConfig .path }' ,
1234+ ];
1235+
1236+ FrontendServer frontendServer = new FrontendServer ();
1237+ final Future <int > result = frontendServer.open (args);
1238+ frontendServer.compile (file.path);
1239+ int count = 0 ;
1240+ frontendServer.listen ((Result compiledResult) {
1241+ CompilationResult result =
1242+ new CompilationResult .parse (compiledResult.status);
1243+ if (count == 0 ) {
1244+ // First request was to 'compile', which resulted in full kernel file.
1245+ expect (result.errorsCount, 0 );
1246+ expect (dillFile.existsSync (), equals (true ));
1247+ expect (result.filename, dillFile.path);
1248+ frontendServer.accept ();
1249+
1250+ frontendServer.compileExpressionToJs (
1251+ expression: 'main1' ,
1252+ libraryUri: 'package:hello/foo.dart' ,
1253+ line: 1 ,
1254+ column: 1 ,
1255+ );
1256+ count += 1 ;
1257+ } else if (count == 1 ) {
1258+ // Second request was to 'compile-expression', which resulted in
1259+ // kernel file with a function that wraps compiled expression.
1260+ expect (result.errorsCount, 0 );
1261+ File outputFile = new File (result.filename);
1262+ expect (outputFile.existsSync (), equals (true ));
1263+ expect (outputFile.lengthSync (), isPositive);
1264+
1265+ file.writeAsStringSync ("import 'lib.dart'; main() => foo();\n " );
1266+ frontendServer.recompile (file.uri, entryPoint: file.path);
1267+ count += 1 ;
1268+ } else if (count == 2 ) {
1269+ // Third request was to recompile the script after renaming a
1270+ // function.
1271+ expect (result.errorsCount, 0 );
1272+ File dillIncFile = new File ('${dillFile .path }.incremental.dill' );
1273+ expect (dillIncFile.existsSync (), equals (true ));
1274+ expect (result.filename, dillIncFile.path);
1275+ frontendServer.accept ();
1276+ frontendServer.compileExpressionToJs (
1277+ expression: 'main' ,
1278+ libraryUri: 'package:hello/foo.dart' ,
1279+ line: 1 ,
1280+ column: 1 ,
1281+ );
1282+ count += 1 ;
1283+ } else {
1284+ expect (count, 3 );
1285+ // Fourth request was to 'compile-expression' that references the new
1286+ // function, which should still be successful.
1287+ expect (result.errorsCount, 0 );
1288+ frontendServer.quit ();
1289+ }
1290+ });
1291+
1292+ expect (await result, 0 );
1293+ frontendServer.close ();
1294+ }, timeout: new Timeout .factor (100 ));
1295+
10981296 test ('reject - recreate issue 55357' , () async {
10991297 File file = new File ('${tempDir .path }/foo.dart' )..createSync ();
11001298 file.writeAsStringSync (
@@ -2342,6 +2540,8 @@ e() {
23422540 '--output-dill=${dillFile .path }' ,
23432541 '--target=dartdevc' ,
23442542 // Errors are only emitted with the DDC library bundle format.
2543+ // TODO(nshahan): Remove these two flags when library bundle format
2544+ // is the default without passing --dartdevc-canary.
23452545 '--dartdevc-module-format=ddc' ,
23462546 '--dartdevc-canary' ,
23472547 '--packages=${packageConfig .path }' ,
0 commit comments