Skip to content
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

Infer Element subclass from query() parameter #4238

Closed
DartBot opened this issue Jul 27, 2012 · 8 comments
Closed

Infer Element subclass from query() parameter #4238

DartBot opened this issue Jul 27, 2012 · 8 comments
Assignees
Labels
type-enhancement A request for a change that isn't a bug
Milestone

Comments

@DartBot
Copy link

DartBot commented Jul 27, 2012

This issue was originally filed by mn...@gmail.com


In the Dart Editor, if I write dart:html code like this:

    var input = form.query("input.subject");
    var subject = input.value;

I get a warning on input.value saying ""value" is not a member of Element". To fix the warning, I insert a cast:

    var input = form.query("input.subject") as InputElement;
    var subject = input.value;

Because the query string is "input.subject", it's obvious that query() returns an InputElement (or null). Where possible, the Editor should infer Element subclasses from the argument to query(). It can fall back to Element if inference fails.

@dgrove
Copy link
Contributor

dgrove commented Jul 29, 2012

Removed Type-Defect label.
Added Type-Enhancement, Area-Editor, Triaged labels.

@clayberg
Copy link

Set owner to @scheglov.
Added this to the Later milestone.

@scheglov
Copy link
Contributor

Hm...
Yes, this may be interesting.
That will be "query" specific, but this function may be important enough to do this.

@mndrix, do you think that specifying element type in "query" is something usual?
I'm not web programmer, but I suppose that just specifying class or id is enough in most cases.
OTOH, if specifying element type will help Editor, and it is shorter than "as InputElement", than it may be preferable. Not sure however how many people will realize this.

@DartBot
Copy link
Author

DartBot commented Jul 31, 2012

This comment was originally written by mndr...@gmail.com


A quick analysis of one of my larger JavaScript projects shows that 46% of our jQuery CSS selectors use element types in a way that Editor inference would succeed. My Dart code base isn't as big, but I assume it will follow the same proportion.

I agree that developers will use element types in query() selectors more frequently once they know that it helps inference. If the Editor implements an inference technique, I think many developers will discover it (like I discovered 'as' inference).

@scheglov
Copy link
Contributor

Added Accepted label.

@scheglov
Copy link
Contributor

scheglov commented Aug 1, 2012

@scheglov
Copy link
Contributor

scheglov commented Aug 1, 2012

https://code.google.com/p/dart/source/detail?r=10128

Now we support simple selectors in query().
I.e. "div", "div#id", "div.class" and "div[foo='bar']".

We don't support "body div", i.e. any selector with space, because we can not prove (without full CSS selector parsing) that space is separator of elements, not part of attribute value in "input[value='my value']".


Added Fixed label.

@clayberg
Copy link

Removed this from the Later milestone.
Added this to the M1 milestone.

@DartBot DartBot added this to the M1 milestone Sep 18, 2012
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants