Skip to main content

tom_ast_model 0.3.5 copy "tom_ast_model: ^0.3.5" to clipboard
tom_ast_model: ^0.3.5 copied to clipboard

Serializable AST model for Dart source code. A complete, self-contained AST representation with JSON serialization — independent of the Dart analyzer and any interpreter runtime.

0.3.5 #

Fixed — the scope resolver models an if-case's scope (ghissues85, GitHub #27) #

An if-case statement or element binds its pattern variables in an Environment of its own, holding the guard and the then branch. StaticResolver did not model it, so a read of a pattern variable that shadows a local (var c = 1; if (2 case final c) return c;, or [if (x case final c) c]) was given the local's depth-0 slot, and the interpreter read a slot of the case environment that does not exist.

  • opensLexicalFrame names an if-case statement and an if-case element;
  • StaticResolver visits the scrutinee and the else branch outside, the case clause and the then branch inside an opaque frame, so such a read is left to the name lookup.

Bundles written before this carry the wrong coordinate for such a read; re-bundle a program that has one.

0.3.4 #

Added — SIfElement.caseClause (ghissues85, GitHub #27) #

A collection if element can be an if-case ([if (x case final c) c]). The analyzer's IfElement carries the case clause, as its IfStatement does; the mirror's SIfStatement held it, SIfElement did not, so a bundle could not represent an if-case element. SIfElement.caseClause is that field: optional, written to JSON only when set, and visited last by visitChildren (as on SIfStatement). A bundle without it reads as before; the bundle format version is unchanged.

0.3.3 #

Changed — SAnnotation.name is an SIdentifier (ghissues78, GitHub #22) #

The same change as 0.4.0, published in the 0.3 line so that every package on tom_ast_model ^0.3.2 - the published tom_d4rt_ast among them - takes it (0.4.0 is otherwise identical; prefer 0.3.3).

An annotation's name was typed SSimpleIdentifier?, narrower than the analyzer's Annotation.name (an Identifier), so a prefixed annotation such as Serverpod's @_isc.useResult (@m.useResult) could not be represented and tom_ast_generator's converter failed with type 'SPrefixedIdentifier' is not a subtype of type 'SSimpleIdentifier?'. SAnnotation.name is now SIdentifier?: an SSimpleIdentifier for @override, an SPrefixedIdentifier for @m.useResult and @m.Foo.named(1). It is decoded by the node discriminator, so a bundle written with a simple name still reads; the bundle format version does not change.

A reader that used annotation.name?.name reads annotation.name?.identifierName (m.useResult for a prefixed name), or checks for SSimpleIdentifier / SPrefixedIdentifier.

0.4.0 #

Identical to 0.3.3: the same change, published first under a minor bump that the 0.3 consumers (the published tom_d4rt_ast) could not resolve.

0.3.2 #

Added — the static facts table of a resolved bundle (ghissues69, GitHub #18 option 3) #

SStaticFacts, the optional table a resolving bundler (tom_ast_generator's resolving check) writes beside a bundle's modules, and its JSON codec:

  • SExtensionCallFact - the static type of an extension member access's receiver, the extension it resolves to and its type arguments;
  • STypeArgumentsFact - the inferred type arguments of a generic call, an instance creation or a collection literal that does not write them;
  • SFactType - a type as a structured reference (kind, library URI, name, type arguments, nullability; function and record types as their spelling), interned in one table per bundle;
  • SFactsStamp - the Dart SDK and package versions the facts were computed against;
  • SStaticFactsBuilder - interns types and collects facts.

Facts are keyed by module URI and the node's offset:length (SStaticFacts.factAt). A table of another SStaticFacts.format reads as null. No node class changed: the mirror stays a one-to-one copy of the analyzer's AST.

0.3.1 #

Changed — two more analyzer 14 shapes (vstdm3) #

SSwitchMember declares labels (a List<SLabel>), as analyzer's SwitchMember does, so a switch's labels are read without a per-kind cast; and SCompilationUnit.declarations is a List<SCompilationUnitMember>, as analyzer's CompilationUnit.declarations is. 0.3.0 was not published; this is the first 0.3 release.

0.3.0 #

Changed (breaking) — the model mirrors analyzer 14's AST shapes (vstdm3) #

analyzer 13 and 14 reshaped several node families. The model follows them, so tom_ast_generator can keep copying 1:1 and the analyzer-free interpreter can read the same structure as tom_d4rt. Bundles written with 0.2.x do not load; they are regenerated from source with a matching toolchain.

  • Formal parameters. SSimpleFormalParameter, SDefaultFormalParameter, SFunctionTypedFormalParameter and SNormalFormalParameter are gone. SFormalParameter holds every parameter's fields itself (name, type, metadata, isConst / isFinal / isCovariant, isRequired, isNamed and the derived isRequiredPositional / isOptionalPositional / isRequiredNamed / isOptionalNamed / isPositional / isOptional), a default value is an SFormalParameterDefaultClause, and the (params) of a function-typed parameter an SFunctionTypedFormalParameterSuffix. The kinds are SRegularFormalParameter, SFieldFormalParameter and SSuperFormalParameter. parameterName is gone; read name?.name.
  • Named arguments. SNamedExpression is gone: an argument list holds SArguments (an SExpression or an SNamedArgument with name and argumentExpression), and a record literal SRecordLiteralFields (an SExpression or an SRecordLiteralNamedField with name and fieldExpression).
  • Labels. SLabel.label is now SLabel.name, non-null; break and continue name an SLabelReference.
  • Class-like declarations. SClassDeclaration and SEnumDeclaration carry their name and type parameters in namePart (SClassNamePart: SNameWithTypeParameters or SPrimaryConstructorDeclaration) and their members in body (SClassBody: SBlockClassBody / SEmptyClassBody; SEnumBody: SBlockEnumBody / SEmptyEnumBody, with the constants). SMixinDeclaration and SExtensionDeclaration carry their members in body. SExtensionTypeDeclaration is named by its primary constructor (namePart, also primaryConstructor), whose one parameter is the representation field; SRepresentationDeclaration is gone.
  • SNamedCompilationUnitMember is gone, as in analyzer.
  • SLibraryDirective.name and SPartOfDirective.libraryName are SDottedNames; SConstructorDeclaration.returnType is typeName.

0.2.2 #

Added — SConfiguration and SDottedName: conditional import/export branches (sce49) #

SImportDirective carried uri, prefix, combinators, isDeferred and metadata — and no configurations; SExportDirective was the same. A directive written

import 'stub.dart' if (dart.library.io) 'io.dart';

therefore had nowhere to put its branch, so a converter dropped it: the directive survived as import 'stub.dart';, not reported, not warned about, and not recorded anywhere. Every consumer downstream saw a well-formed import of the default URI with no way to learn that a branch had been discarded — and conditional imports are the standard Dart mechanism for VM-vs-web divergence.

SConfiguration (name, optional == '...' test value, branch URI) and SDottedName (the condition's dart.library.io) are the missing nodes, and both directives now carry a configurations list with JSON round-tripping, structural equality and visitor dispatch (visitConfiguration, visitDottedName).

The conditions are preserved, not evaluated. Which branch applies depends on the target platform, which this model does not know; resolving it belongs to the bundler at compile time or the runner at load time. A field that exists can be resolved later — a dropped one cannot be recovered at all.

A patch bump rather than a minor one, although 0.2.0 set the precedent of a minor for an additive node. tom_ast_generator depends on this package AND on tom_d4rt_ast, which constrains it to ^0.2.0; under pub's 0.x rules a 0.3.0 is breaking, so it could not resolve against a published tom_d4rt_ast until that package shipped a raised constraint — which it cannot right now. Adding API is not a breaking change, so the patch is also the semantically accurate bump.

0.2.1 #

Changed — formatted the tree once (scd82) #

Every package in this repo already declares an SDK floor above the 3.7 tall-style boundary, so the formatter can no longer produce two layouts here. What was not true is that the trees were formatted: until this commit, running dart format on any single file rewrote it wholesale and buried whatever real edit came with it.

Proven layout-only rather than assumed. git diff -w cannot establish it, because the tall style splits lines and a whitespace-insensitive diff still counts a moved boundary as a change. What was checked is the token stream, per file, twice: whitespace stripped, then whitespace and commas stripped. The single changed file is identical to HEAD under that normalisation.

dart analyze is clean, the suite passes (7 tests), and the formatter is now idempotent here.

0.2.0 #

  • Add SRecordTypeField — the fields of a record type annotation (int and String label in (int, {String label})) were previously unrepresentable, so a converter had nowhere to put them and dropped them into an opaque placeholder. The arity survived; the field types and the named-field keys did not, which left the interpreter unable to answer (42, label: 'answer') is (int, {String label}).
  • Breaking: SRecordTypeAnnotation.positionalFields / .namedFields are now List<SRecordTypeField> instead of List<SAstNode>, so a consumer cannot silently receive a field it can read nothing off. Bundles serialised before this version still deserialise — their fields come back typeless and nameless rather than being dropped, which preserves the recorded arity.

0.1.3 #

  • Housekeeping: test artifacts now live in a gitignored testlog/ folder; doc/ no longer ships machine-generated baselines or last_testrun.json. No code changes.

0.1.2 #

  • Documentation: limitations and user guide updated; README aligned with the source-primary documentation reframe across the D4rt ecosystem.

0.1.1 #

  • Add StaticResolver and the resolvedSlot / declSlot node fields that back the interpreter's slot-based variable resolution (static name → frame slot binding computed once, replacing per-access map lookups).
  • Add ForEachPartsWithPattern support so pattern-destructuring for-in loops round-trip through the serializable AST.

0.1.0 #

  • Initial release — extracted from tom_d4rt_ast
  • Pure AST model classes with JSON serialization
  • Zero external dependencies
0
likes
160
points
608
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Serializable AST model for Dart source code. A complete, self-contained AST representation with JSON serialization — independent of the Dart analyzer and any interpreter runtime.

Homepage
Repository (GitHub)
View/report issues

Topics

#ast #dart #serialization #interpreter

License

BSD-3-Clause (license)

More

Packages that depend on tom_ast_model