parse method
Parse source code into a CompilationUnit.
Parses source once into a D4rtProgram that executeProgram can run
any number of times, on this interpreter or another.
This is execute split at its one expensive step that does not depend on the run: an embedder that runs the same script repeatedly caches the program and pays for the parse once. A parse error is raised here, as the SourceCodeD4rtException execute would raise.
basePath is part of the program rather than of the run because the
parsed unit is anchored at <basePath>/main.dart, exactly as execute
anchors it; executeProgram resolves relative imports against it.
The program carries only syntax. Everything a run derives from it — declarations, static coordinates, the environment — is rebuilt by each executeProgram, so two runs of one program share no state.
Implementation
D4rtProgram parse(String source, {String? basePath}) => D4rtProgram._(
source: source,
basePath: basePath,
unit: _parseDirectSource(source, basePath),
);