From b471224aadefc6afe1e99ebaa366bf7b0b51b3d1 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Thu, 12 Dec 2024 14:58:53 -0800 Subject: [PATCH] [web] allows imports to line-break --- lib/web_ui/lib/src/engine/renderer.dart | 34 ++++++++++++++++--------- web_sdk/sdk_rewriter.dart | 1 + web_sdk/test/sdk_rewriter_test.dart | 28 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/lib/web_ui/lib/src/engine/renderer.dart b/lib/web_ui/lib/src/engine/renderer.dart index aa3e8bfc9be66..9bd017994c303 100644 --- a/lib/web_ui/lib/src/engine/renderer.dart +++ b/lib/web_ui/lib/src/engine/renderer.dart @@ -8,7 +8,8 @@ import 'dart:math' as math; import 'dart:typed_data'; import 'package:ui/src/engine.dart'; -import 'package:ui/src/engine/skwasm/skwasm_impl.dart' if (dart.library.html) 'package:ui/src/engine/skwasm/skwasm_stub.dart'; +import 'package:ui/src/engine/skwasm/skwasm_impl.dart' + if (dart.library.html) 'package:ui/src/engine/skwasm/skwasm_stub.dart'; import 'package:ui/ui.dart' as ui; import 'package:ui/ui_web/src/ui_web.dart' as ui_web; @@ -43,11 +44,12 @@ abstract class Renderer { if (!useCanvasKit) { // The user requested 'html' or 'auto' either in the command-line or JS. final String requested = - configuration.requestedRendererType ?? - (FlutterConfiguration.flutterWebAutoDetect ? 'auto' : 'html'); + configuration.requestedRendererType ?? + (FlutterConfiguration.flutterWebAutoDetect ? 'auto' : 'html'); printWarning( 'The HTML Renderer is being deprecated. Stop using the "$requested" renderer mode.' - '\nSee: https://docs.flutter.dev/to/web-html-renderer-deprecation'); + '\nSee: https://docs.flutter.dev/to/web-html-renderer-deprecation', + ); } return true; }()); @@ -120,14 +122,18 @@ abstract class Renderer { ui.ImageFilter createBlurImageFilter({ double sigmaX = 0.0, double sigmaY = 0.0, - ui.TileMode? tileMode}); - ui.ImageFilter createDilateImageFilter({ double radiusX = 0.0, double radiusY = 0.0}); - ui.ImageFilter createErodeImageFilter({ double radiusX = 0.0, double radiusY = 0.0}); + ui.TileMode? tileMode, + }); + ui.ImageFilter createDilateImageFilter({double radiusX = 0.0, double radiusY = 0.0}); + ui.ImageFilter createErodeImageFilter({double radiusX = 0.0, double radiusY = 0.0}); ui.ImageFilter createMatrixImageFilter( Float64List matrix4, { - ui.FilterQuality filterQuality = ui.FilterQuality.low + ui.FilterQuality filterQuality = ui.FilterQuality.low, + }); + ui.ImageFilter composeImageFilters({ + required ui.ImageFilter outer, + required ui.ImageFilter inner, }); - ui.ImageFilter composeImageFilters({required ui.ImageFilter outer, required ui.ImageFilter inner}); Future instantiateImageCodec( Uint8List list, { @@ -143,8 +149,12 @@ abstract class Renderer { FutureOr createImageFromImageBitmap(DomImageBitmap imageSource); - FutureOr createImageFromTextureSource(JSAny object, - {required int width, required int height, required bool transferOwnership}); + FutureOr createImageFromTextureSource( + JSAny object, { + required int width, + required int height, + required bool transferOwnership, + }); void decodeImageFromPixels( Uint8List pixels, @@ -155,7 +165,7 @@ abstract class Renderer { int? rowBytes, int? targetWidth, int? targetHeight, - bool allowUpscaling = true + bool allowUpscaling = true, }); ui.ImageShader createImageShader( diff --git a/web_sdk/sdk_rewriter.dart b/web_sdk/sdk_rewriter.dart index bb69a4cdaf471..5a0e36c9a8766 100644 --- a/web_sdk/sdk_rewriter.dart +++ b/web_sdk/sdk_rewriter.dart @@ -79,6 +79,7 @@ List generatePartsPatterns(String libraryName, bool isPublic) { // Remove library directives. AllReplacer(RegExp(r'\nlibrary .+;'), ''), // Remove imports/exports from all part files. + AllReplacer(RegExp(r"\nimport '.+'\n\s*if \(dart.library.html\) '.*';"), ''), AllReplacer(RegExp(r'\nimport\s*.*'), ''), AllReplacer(RegExp(r'\nexport\s*.*'), ''), AllReplacer(RegExp(r'\n@DefaultAsset(.*)'), ''), diff --git a/web_sdk/test/sdk_rewriter_test.dart b/web_sdk/test/sdk_rewriter_test.dart index cc1eae42607c8..94d002fb4100a 100644 --- a/web_sdk/test/sdk_rewriter_test.dart +++ b/web_sdk/test/sdk_rewriter_test.dart @@ -192,4 +192,32 @@ void printSomething() { expect(getExtraImportsForLibrary('web_test_fonts'), isEmpty); expect(getExtraImportsForLibrary('web_locale_keymap'), isEmpty); }); + + test('allows imports to line-break', () { + const String source = ''' +import 'package:some_package/some_package.dart'; +import 'package:ui/src/engine/skwasm/skwasm_impl.dart' + if (dart.library.html) 'package:ui/src/engine/skwasm/skwasm_stub.dart'; +import 'package:some_package/some_package' as some_package; + +void printSomething() { + print('something'); +} +'''; + + const String expected = ''' +part of dart._engine; + +void printSomething() { + print('something'); +} +'''; + + final String result = processSource( + source, + (String source) => preprocessPartFile(source, 'engine'), + generatePartsPatterns('engine', false), + ); + expect(result, expected); + }); }