AstBundle class
A transportable unit containing an entry point and all required modules.
AstBundle is the primary distribution format for pre-parsed D4rt scripts.
It encapsulates one or more SCompilationUnit modules that can be executed
by D4rtRunner without requiring the Dart analyzer.
Serialization Formats
| Format | Methods | Use Case |
|---|---|---|
| JSON | toJson / fromJson | Debugging, tool integration |
| Bytes | toBytes / fromBytes | Network transfer, in-memory |
| ZIP | toZip / fromZip | File distribution (.ast) |
| File | saveToFile / fromFile | Disk I/O with auto-detection |
Example
// Create and save a bundle
final bundle = AstBundle(
entryPointUri: 'bin/main.dart',
modules: {'bin/main.dart': mainAst, 'lib/utils.dart': utilsAst},
);
bundle.saveToFile('my_script.ast');
// Load and execute
final loaded = AstBundle.fromFile('my_script.ast');
final runner = D4rtRunner();
runner.execute(ast: loaded.entryPoint);
Constructors
-
AstBundle({required String entryPointUri, required Map<
String, SCompilationUnit> modules, Map<String, String> ? sources}) - Creates an AstBundle with the given entry point and modules.
-
AstBundle.fromBytes(List<
int> bytes) -
Deserializes a bundle from gzip-compressed JSON bytes.
factory
- AstBundle.fromFile(String path)
-
Loads a bundle from a file.
factory
-
AstBundle.fromJson(Map<
String, dynamic> json) -
Deserializes a bundle from a JSON map.
factory
-
AstBundle.fromZip(List<
int> bytes) -
Deserializes a bundle from ZIP archive bytes.
factory
Properties
- entryPoint → SCompilationUnit
-
The entry point SCompilationUnit.
no setter
- entryPointUri → String
-
URI identifying the entry point module.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isSingleModule → bool
-
Whether this bundle contains only the entry point module.
no setter
- moduleCount → int
-
Number of modules in this bundle.
no setter
-
modules
→ Map<
String, SCompilationUnit> -
All modules in this bundle, keyed by their URI.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
sources
→ Map<
String, String> ? -
Optional Dart source code for each module, keyed by URI.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
saveToFile(
String path) → void - Saves this bundle to a file in ZIP archive format.
-
toBytes(
) → List< int> - Serializes this bundle as gzip-compressed JSON bytes.
-
toJson(
) → Map< String, dynamic> - Serializes this bundle to a JSON-compatible map.
-
toString(
) → String -
A string representation of this object.
override
-
toZip(
) → List< int> - Serializes this bundle as a ZIP archive.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited