resolve function
Resolves dartSource as a library package:test_lib/test_lib.dart.
Example:
lib = await resolveLibrary(
'''
@Component(
selector: 'example',
template: 'Hello World',
)
class ExampleComponent {}
''',
);
-
additionalFiles: May provide additional files available to the program:resolveLibrary( ''' @Component( selector: 'example', templateUrl: 'example.html', ) class ExampleComponent {} ''', additionalFiles: { AssetId( 'test_lib', 'lib/example.html', ): ''' <div>Hello World</div> ''', }, ) -
includeAngularDeps: Setfalseto not includeimport 'angular.dart'. This may be used to simulate scenarios where the user has forgotten to add an import to Angular, or where you would want the import specified as an alternative entry-point.
Implementation
Future<LibraryElement> resolve(
String dartSource, {
Map<AssetId, String> additionalFiles = const {},
bool includeAngularDeps = true,
}) async {
// Add library and import directives to the top.
dartSource = [
if (includeAngularDeps) "import '$_angularLibPath';",
'',
dartSource,
].join('\n');
final sources = {
// Map<AssetId, String> -> Map<String, String>
for (final entry in additionalFiles.entries)
_assetToPath(entry.key): entry.value,
// Adds an additional file (dartSource).
_assetToPath(_defaultAssetId): dartSource,
};
final config = await _cachedPackageConfig;
final result = await withEnabledExperiments(
() => resolveSources(
sources,
(resolver) => resolver.libraryFor(_defaultAssetId),
packageConfig: config,
),
['non-nullable'],
);
return result;
}