source_span
source_span copied to clipboard
Consider not using runtimeType
This causes code-size warnings when compiling to js:
Hint: Using '.runtimeType.toString()' causes the compiler to generate more code because it needs to preserve type arguments on generic classes, even if they are not necessary elsewhere. If used only for debugging, consider using option --lax-runtime-type-to-string to reduce the code size impact.
And we only use it in:
https://github.com/dart-lang/source_span/blob/24151fd80e4557a626f81f2bc0d6a2ebde172cae/lib/src/span_mixin.dart#L82-L83
Maybe we can just change it to:
String toString() => '<SourceSpan: from $start to $end "$text">';
And have subclasses overwrite toString to ensure that they keep their name.
This sounds reasonable to me; I doubt it's critical that the toString() method identify the exact subclass of the sourcespan.
For posterity, the lint we want to enable to catch violations here is no_runtimeType_toString (that lint does have an issue where it doesn't report all violations: https://github.com/dart-lang/linter/issues/3635).