Skip to content

Commit

Permalink
Fixed issue when entry point was detected with no main (#30)
Browse files Browse the repository at this point in the history
* fixed no main stuff

* Fixed formatting
  • Loading branch information
JackHerring authored and jrote1 committed Jul 27, 2017
1 parent ada5f94 commit 4c80684
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/src/transformer/map_generator_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,28 @@ 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);

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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4c80684

Please sign in to comment.