-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Remove type casts in example sources for display #3537
Conversation
I'm not sure if this really does the trick for all cases... |
*/ | ||
function cleanupScriptSource(src) { | ||
// The regex to replace … goog.require … and … renderer: exampleNS. … lines | ||
var lineRegEx = /.*(goog\.require(.*);|.*renderer: exampleNS\..*,?)[\n]*/g; |
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.
Should be defined outside the function to avoid RegEx parsing with every function call.
Looks good - maybe you'll want to address my two minor comments before merging. Even if the regex does not catch all cases, it is a good starting point for later improvements. |
Thanks @ahocevar. I want to test the results first again... It may be that the regex chnges code i don't want it to change. |
The regex fails to clean up e.g. view.fitExtent(
vectorSource.getExtent(), /** @type {ol.Size} */ (map.getSize())); and turns it into view.fitExtent(
vectorSource.getExtent(), ); ( Other files with problematic constructs are var geom = /** @type {ol.geom.Polygon} */(polygon.clone().transform(
sourceProj, 'EPSG:4326')); It may be that the regular expression can be enhanced, but I fear this is going to be hard. A) I could limit the regex to the attribution options ( var geom = /** @type {ol.geom.Polygon} */(polygon.clone().transform(
sourceProj, 'EPSG:4326')); var geom = (polygon.clone().transform(
sourceProj, 'EPSG:4326')); C) or I close this PR as fruitless. Opinions? |
B) would most probably be the easiest way. |
I think both B and C would be fine. |
Hah, I think I have an easy solution that'll do all I originally intended... I'll see if I can rework this tomorrow. |
I went for option B as suggested. I think this still is a nice little enhancement and one thing less that may confuse first-time readers. The surrounding round braces stay now, but they do not harm. All problematic cases of the original commit are no longer an issue. @ahocevar your other remarks are adressed, thanks for your review.
I am no longer sure if I can come up with something that also does remove the Anybody willing to give this another look? TIA. |
// opening curly brackets, any non-whitespace characters, closing curly brace, | ||
// an optional space, the end of a multiline comment followed by any number of | ||
// whitespace characters | ||
var cleanTypecastRegEx = /(\/\*\* ?@type \{\S*\} ?\*\/\s*)/g; |
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.
The group is not really needed here.
I might have concerns with this patch, so I'd like to review it before it is merged. Thanks. |
I had misunderstood this patch. I thought it changed the examples' code, while it changed the code that is displayed in the example's page! That being said, option B (remove typecast but leave brackets) sounds like a half-baked solution to me. So I'd either address the issue completely or go with option C (close this PR as fruitless). |
No problem. I'll close it then. Any ideas howwe could accomplish this? |
This PR suggests that we remove inline type casts when we display our examples.
Before:
After: