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

Improve document#createElement by returning teh well HTML Element instance #478

Closed
wants to merge 2 commits into from

Conversation

angelozerr
Copy link
Contributor

This PR gives the capability to return the well HTML instance according the createElement parameter :

  • here a sample with any element :
var elt = document.createElement('any') // here elt is an instance of Element
  • here a sample with HTML div :
var div= document.createElement('div') // here elt is an instance of HTMLDivElement
div.a // Ctrl+Space shows align attribute (only available for div).

To support that, I needed to create a tern function Browser_createElement that I have added inside def.js. It's not very clean. I think brower.json should be tranformed to a tern plugin browser.js.

@marijnh
Copy link
Member

marijnh commented Jan 20, 2015

I think this is complexity without much gain. The plugin will still be completely ignorant about what kind of element, for example, document.body.firstChild should return. Just add the align property to Element, like I've done with other properties that only occur on some types of elements (such as getContext and value).

@marijnh marijnh closed this Jan 20, 2015
@angelozerr
Copy link
Contributor Author

@marijnh I have created this PR, because I have started to wtrite a plugin which improve browser.json with getElementById

<html>
  <div id="MyId" ></div>
</html>
var div = document.getElementById('MyId'') 
div. // here Ctrl+Space shows align

To do that I load inside a tern plugin HTML with parse5. And once this issue inikulin/parse5#30 will be done I could manage Go definition when user Ctrl+click on "MyId".

@marijnh
Copy link
Member

marijnh commented Jan 23, 2015

I don't see a way to reliably do this -- even if you have a reference HTML document, DOM structure, you won't be able to return appropriate types for things like firstChild. Even getElementById only works reliably if the script didn't update the DOM. I think it is a better idea to stick to just putting all possible properties on the Element type itself, and accepting the dynamic typing as inavoidable here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants