X Tutup
Skip to content

Commit a87c5d9

Browse files
author
Tim Blasi
committed
fix(dart/transform): Gracefully handle empty .ng_meta.json files
Fix the `template_compiler` step to gracefully handle null & empty .ng_meta.json files.
1 parent 7d83959 commit a87c5d9

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

modules_dart/transform/lib/src/transform/template_compiler/compile_data_creator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import 'package:barback/barback.dart';
2222
Future<CompileDataResults> createCompileData(
2323
AssetReader reader, AssetId assetId) async {
2424
return logElapsedAsync(() async {
25-
return (await _CompileDataCreator.create(reader, assetId))
26-
.createCompileData();
25+
final creator = await _CompileDataCreator.create(reader, assetId);
26+
return creator != null ? creator.createCompileData() : null;
2727
}, operationName: 'createCompileData', assetId: assetId);
2828
}
2929

modules_dart/transform/lib/src/transform/template_compiler/generator.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import 'compile_data_creator.dart';
2828
Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
2929
{bool reflectPropertiesAsAttributes: false}) async {
3030
var viewDefResults = await createCompileData(reader, assetId);
31+
if (viewDefResults == null) return null;
3132
final directiveMetadatas = viewDefResults.ngMeta.types.values;
3233
if (directiveMetadatas.isNotEmpty) {
3334
var processor = new reg.Processor();

modules_dart/transform/test/transform/template_compiler/all_tests.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,34 @@ void allTests() {
318318
expect(ngDeps.setters).toContain('text');
319319
expect(ngDeps.setters.length).toEqual(1);
320320
});
321+
322+
it('should gracefully handle null .ng_meta.json files', () async {
323+
final dne =
324+
new AssetId('package', 'lib/file_that_does_not_exist.ng_meta.json');
325+
326+
var didThrow = false;
327+
await process(dne).then((out) {
328+
expect(out).toBeNull();
329+
}).catchError((_) {
330+
didThrow = true;
331+
});
332+
333+
expect(didThrow).toBeFalse();
334+
});
335+
336+
it('should gracefully handle empty .ng_meta.json files', () async {
337+
final emptyId = new AssetId('package', 'lib/empty.ng_meta.json');
338+
reader.addAsset(emptyId, '');
339+
340+
var didThrow = false;
341+
await process(emptyId).then((out) {
342+
expect(out).toBeNull();
343+
}).catchError((_) {
344+
didThrow = true;
345+
});
346+
347+
expect(didThrow).toBeFalse();
348+
});
321349
}
322350

323351
void _formatThenExpectEquals(String actual, String expected) {

0 commit comments

Comments
 (0)
X Tutup