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
Basic support for namespacing get-function calls #13
Conversation
Resolves #11. If the argument passed to get-function is a string literal, we'll add a namespace if necessary. For all other get-function calls, we'll emit a warning saying that a namespace may be required. We might eventually be able to detect some of these with some more sophisticated logic here, but for now we'll just handle the basics.
lib/src/migrator.dart
Outdated
} else { | ||
_warn( | ||
"WARNING: Could not determine if namespace is required for " | ||
"get-function call @", |
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: What's this @
for?
Also changes warning message to use span.message and updates tests to use only ASCII characters for checking log.
lib/src/migrator.dart
Outdated
var beforeParen = node.span.end.offset - 1; | ||
_currentMigration.patches.add(Patch( | ||
node.span.file.span(beforeParen, beforeParen), | ||
", \$module: $namespace")); |
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: Emit quotes around the namespace, in case it's a color name or something. There is actually a Sass library named true
, so this isn't even purely hypothetical.
, | ||
8 | $fn4: get-function($x); | ||
| ^^ | ||
' |
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.
Also test a getting a function from a core library when the function's namespaced name doesn't match its original name, and getting a function from a library named true
or whatever.
if (nameArgument is! StringExpression || | ||
(nameArgument as StringExpression).text.asPlain == null) { | ||
print(nameArgument.span.message( | ||
"WARNING - get-function call may require \$module parameter")); |
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.
It's probably a good idea to print this to stderr.
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.
Is there an equivalent to the prints
matcher for testing stderr?
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.
Unfortunately no there isn't. Usually when I'm testing command-line executables, I just run them via Process.runSync()
or the test_process
package so I don't have to worry about mocking out all the APIs.
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.
Okay, in that case, I'll leave this as is for now. I've made an issue (#14) for this, which I'll handle in a separate PR
Resolves #11.
If the argument passed to get-function is a string literal, we'll add a namespace if necessary.
For all other
get-function
calls, we'll emit a warning saying that a namespace may be required. We might eventually be able to detect some of these with some more sophisticated logic here, but for now we'll just handle the basics.