From 4c8068446483e13005f898f3b11b3d39745cf27d Mon Sep 17 00:00:00 2001 From: JackHerring Date: Thu, 27 Jul 2017 10:21:15 +0100 Subject: [PATCH] Fixed issue when entry point was detected with no main (#30) * fixed no main stuff * Fixed formatting --- .../transformer/map_generator_transformer.dart | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/src/transformer/map_generator_transformer.dart b/lib/src/transformer/map_generator_transformer.dart index 08e9562..993ebc4 100644 --- a/lib/src/transformer/map_generator_transformer.dart +++ b/lib/src/transformer/map_generator_transformer.dart @@ -18,8 +18,8 @@ class MapGeneratorTransformer extends Transformer with ResolverTransformer { var outputPath = path.url.join(path.url.dirname(id.path), mappingsFileName); var generatedAssetId = new AssetId(id.package, outputPath); - _transformEntryFile( - transform, resolver, mappingsFileName, mappingsClassName); + if (!_transformEntryFile( + transform, resolver, mappingsFileName, mappingsClassName)) return; var mappingsFile = new MappingsGenerator(resolver, id, _options.formatCode) .generate(mappingsClassName, _options.libraryNames); @@ -27,11 +27,19 @@ class MapGeneratorTransformer extends Transformer with ResolverTransformer { transform.addOutput(new Asset.fromString(generatedAssetId, mappingsFile)); } - void _transformEntryFile(Transform transform, Resolver resolver, + bool _transformEntryFile(Transform transform, Resolver resolver, String mappingsFileName, String mappingsClassName) { AssetId id = transform.primaryInput.id; var lib = resolver.getLibrary(id); var unit = lib.definingCompilationUnit.computeNode(); + + if (unit.declarations + .where( + (d) => d is FunctionDeclaration && d.name.toString() == 'main') + .toList() + .length == + 0) return false; + var transaction = resolver.createTextEditTransaction(lib); var importParameters = _getImportParameters(unit); @@ -85,6 +93,8 @@ class MapGeneratorTransformer extends Transformer with ResolverTransformer { var printer = transaction.commit(); printer.build(id.path); transform.addOutput(new Asset.fromString(id, printer.text)); + + return true; } _EntryPointImportParameters _getImportParameters(dynamic unit) {