-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shared interfaces for various AST nodes #1445
Conversation
Fixes #1401 and #1414. Adds `Dependency`, `SassDeclaration`, and `SassReference` interfaces, which expose some getters that multiple AST nodes have in common with a single type. These also add getters for common subspans (URL, name, and namespace) to the interfaces. To allow for `FunctionExpression` to have a common interface with the other two reference nodes, its old `name` getter has been renamed to `interpolatedName`, and the new `name` getter now is either just a string, or null if the name is interpolated.
? interpolatedName.asPlain?.replaceAll('_', '-') | ||
: interpolatedName.asPlain; | ||
/// If this function is a plain CSS function, use [originalName] instead. | ||
final String name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make this a getter, since a single String.replaceAll()
isn't very expensive.
var quote = skipRule.text[0]; | ||
var end = skipRule.text.indexOf(quote, 1); | ||
return skipRule.subspan(0, end + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be worth making a Span utility as well.
if (namespace != null) { | ||
startSpan = startSpan.withoutInitialIdentifier().subspan(1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding SpanExtensions.withoutNamespace()
.
lib/src/parse/parser.dart
Outdated
} | ||
} | ||
int escapeCharacter() => | ||
consumeEscapedCharacter(scanner); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: reformat
lib/src/utils.dart
Outdated
return scanner.readChar(); | ||
} | ||
} | ||
|
||
extension SpanExtensions on FileSpan { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is big enough now that it should maybe go into its own file.
Fixes #1401 and #1414.
Adds
Dependency
,SassDeclaration
, andSassReference
interfaces,which expose some getters that multiple AST nodes have in common with a
single type.
These also add getters for common subspans (URL, name, and namespace) to
the interfaces.
To allow for
FunctionExpression
to have a common interface with theother two reference nodes, its old
name
getter has been renamed tointerpolatedName
, and the newname
getter now is either just astring, or null if the name is interpolated.