1- /// A scope in which to resolve a chunk of code.
2- ///
3- /// TODO: Specify more what these mean, what fields are available (if any), etc.
4- abstract class Scope {}
5-
61/// The base class representing an arbitrary chunk of Dart code, which may or
72/// may not be syntactically or semantically valid yet.
83class Code {
9- /// The scope in which to resolve anything from [parts] that does not have its
10- /// own scope already defined.
11- final Scope ? scope;
12-
134 /// All the chunks of [Code] or raw [String] s that comprise this [Code]
145 /// object.
156 final List <Object > parts;
167
17- Code .fromString (String code, { this .scope} ) : parts = [code];
8+ Code .fromString (String code) : parts = [code];
189
19- Code .fromParts (this .parts, { this .scope} );
10+ Code .fromParts (this .parts);
2011}
2112
2213/// A piece of code representing a syntactically valid declaration.
2314class DeclarationCode extends Code {
24- DeclarationCode .fromString (String code, {Scope ? scope})
25- : super .fromString (code, scope: scope);
15+ DeclarationCode .fromString (String code) : super .fromString (code);
2616
27- DeclarationCode .fromParts (List <Object > parts, {Scope ? scope})
28- : super .fromParts (parts, scope: scope);
17+ DeclarationCode .fromParts (List <Object > parts) : super .fromParts (parts);
2918}
3019
3120/// A piece of code representing a syntactically valid element.
3221///
3322/// Should not include any trailing commas,
3423class ElementCode extends Code {
35- ElementCode .fromString (String code, {Scope ? scope})
36- : super .fromString (code, scope: scope);
24+ ElementCode .fromString (String code) : super .fromString (code);
3725
38- ElementCode .fromParts (List <Object > parts, {Scope ? scope})
39- : super .fromParts (parts, scope: scope);
26+ ElementCode .fromParts (List <Object > parts) : super .fromParts (parts);
4027}
4128
4229/// A piece of code representing a syntactically valid expression.
4330class ExpressionCode extends Code {
44- ExpressionCode .fromString (String code, {Scope ? scope})
45- : super .fromString (code, scope: scope);
31+ ExpressionCode .fromString (String code) : super .fromString (code);
4632
47- ExpressionCode .fromParts (List <Object > parts, {Scope ? scope})
48- : super .fromParts (parts, scope: scope);
33+ ExpressionCode .fromParts (List <Object > parts) : super .fromParts (parts);
4934}
5035
5136/// A piece of code representing a syntactically valid function body.
@@ -55,31 +40,25 @@ class ExpressionCode extends Code {
5540///
5641/// Both arrow and block function bodies are allowed.
5742class FunctionBodyCode extends Code {
58- FunctionBodyCode .fromString (String code, {Scope ? scope})
59- : super .fromString (code, scope: scope);
43+ FunctionBodyCode .fromString (String code) : super .fromString (code);
6044
61- FunctionBodyCode .fromParts (List <Object > parts, {Scope ? scope})
62- : super .fromParts (parts, scope: scope);
45+ FunctionBodyCode .fromParts (List <Object > parts) : super .fromParts (parts);
6346}
6447
6548/// A piece of code representing a syntactically valid identifier.
6649class IdentifierCode extends Code {
67- IdentifierCode .fromString (String code, {Scope ? scope})
68- : super .fromString (code, scope: scope);
50+ IdentifierCode .fromString (String code) : super .fromString (code);
6951
70- IdentifierCode .fromParts (List <Object > parts, {Scope ? scope})
71- : super .fromParts (parts, scope: scope);
52+ IdentifierCode .fromParts (List <Object > parts) : super .fromParts (parts);
7253}
7354
7455/// A piece of code identifying a named argument.
7556///
7657/// This should not include any trailing commas.
7758class NamedArgumentCode extends Code {
78- NamedArgumentCode .fromString (String code, {Scope ? scope})
79- : super .fromString (code, scope: scope);
59+ NamedArgumentCode .fromString (String code) : super .fromString (code);
8060
81- NamedArgumentCode .fromParts (List <Object > parts, {Scope ? scope})
82- : super .fromParts (parts, scope: scope);
61+ NamedArgumentCode .fromParts (List <Object > parts) : super .fromParts (parts);
8362}
8463
8564/// A piece of code identifying a syntactically valid function parameter.
@@ -92,22 +71,18 @@ class NamedArgumentCode extends Code {
9271/// construct and combine these together in a way that creates valid parameter
9372/// lists.
9473class ParameterCode extends Code {
95- ParameterCode .fromString (String code, {Scope ? scope})
96- : super .fromString (code, scope: scope);
74+ ParameterCode .fromString (String code) : super .fromString (code);
9775
98- ParameterCode .fromParts (List <Object > parts, {Scope ? scope})
99- : super .fromParts (parts, scope: scope);
76+ ParameterCode .fromParts (List <Object > parts) : super .fromParts (parts);
10077}
10178
10279/// A piece of code representing a syntactically valid statement.
10380///
10481/// Should always end with a semicolon.
10582class StatementCode extends Code {
106- StatementCode .fromString (String code, {Scope ? scope})
107- : super .fromString (code, scope: scope);
83+ StatementCode .fromString (String code) : super .fromString (code);
10884
109- StatementCode .fromParts (List <Object > parts, {Scope ? scope})
110- : super .fromParts (parts, scope: scope);
85+ StatementCode .fromParts (List <Object > parts) : super .fromParts (parts);
11186}
11287
11388extension Join <T extends Code > on List <T > {
0 commit comments