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

Add jsdomparser #13920

Merged
merged 10 commits into from
Apr 13, 2020
Merged

Add jsdomparser #13920

merged 10 commits into from
Apr 13, 2020

Conversation

juancarlospaco
Copy link
Collaborator

  • Add jsdomparser the DOM Parser for JavaScript target.

@alaviss
Copy link
Collaborator

alaviss commented Apr 8, 2020

Can't this be added directly to dom?

@juancarlospaco
Copy link
Collaborator Author

Only Document is used from dom, I do not want to Kitchen Sink the dom module.

@timotheecour
Copy link
Member

this belongs in dom. I'd agree for a separate module if jsdomparser were a large module or could grow large, but this is not the case.

lib/js/dom.nim Outdated
func newDOMParser*(): DOMParser {.importcpp: "(new DOMParser()​​)".}
## DOM Parser constructor.

func parseFromString*(this: DOMParser; str: cstring; mimeType = "text/html".cstring): Document {.importcpp.}
Copy link
Member

@timotheecour timotheecour Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or we can just remove the default mimeType and keep it barebones. JS is a wild place and things can change really fast. We should just provide a barebones wrapper and call it a day.

lib/js/dom.nim Outdated
@@ -985,6 +985,16 @@ type
once*: bool
passive*: bool

since (1, 3):
type DOMParser* = ref object ## \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshedding: Should this be DomParser (and newDomParser)? Quoting NEP-1:

In the age of HTTP, HTML, FTP, TCP, IP, UTF, WWW it is foolish to pretend these are somewhat special words requiring all uppercase. Instead treat them as what they are: Real words. So it's parseUrl rather than parseURL, checkHttpHeader instead of checkHTTPHeader etc.

Don't know if DOM counts on the same level as HTTP and HTML but I don't really know if the "level" matters either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's DomParser and newDomParser indeed.

Copy link
Contributor

@dom96 dom96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but see my and @hlaaftana's comment.

@@ -9,7 +9,7 @@

## Declaration of the Document Object Model for the `JavaScript backend
## <backends.html#backends-the-javascript-target>`_.

include "system/inclrtl"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being added?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not needed and should be removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it includes since but you shouldn't have to manually include it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to otherwise you get CT error; but if we merged #11865 we could import it instead of including it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again putting it out there that I consider this since thing to be a waste of time.

lib/js/dom.nim Outdated


since (1, 3):
func newDOMParser*(): DOMParser {.importcpp: "(new DOMParser()​​)".}
Copy link
Member

@timotheecour timotheecour Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work, you must've pasted from a webpage and introduced an invisible symbol (see cat -e). you should make sure examples work

also, you should remove outer parens

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be .importjs: "new DOMParser()"

Copy link
Collaborator Author

@juancarlospaco juancarlospaco Apr 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#13891 (comment) (Doc Test exit non-zero)

func newDOMParser*(): DOMParser {.importcpp: "(new DOMParser()​​)".}
## DOM Parser constructor.

func parseFromString*(this: DOMParser; str: cstring; mimeType: cstring): Document {.importcpp.}
Copy link
Member

@timotheecour timotheecour Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still meh on that; at least provide an enum to make life easier for users eg:

type MimeTypeDom = enum
  textHtml = "text/html" etc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't. JS grows relatively fast and change really quickly, so we should not spent too much time chasing these things. Different browsers might support more MIME types, and it's not really our place to dictate how to use an API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with alaviss on this point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine, we can later introduce

type MimeTypes = enum
  textHtml = "text/html".cstring
  # etc

and use it as:
let a = prsr.parseFromString("<html>...</html>".cstring, $textHtml)

(but not sure what's the difference with fetch API case https://github.com/nim-lang/Nim/pull/12531/files#r403861811

So what, please use enums.
)

@juancarlospaco juancarlospaco requested a review from Araq April 11, 2020 04:41
@@ -9,7 +9,7 @@

## Declaration of the Document Object Model for the `JavaScript backend
## <backends.html#backends-the-javascript-target>`_.

include "system/inclrtl"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again putting it out there that I consider this since thing to be a waste of time.

@dom96 dom96 merged commit 0a84219 into nim-lang:devel Apr 13, 2020
@juancarlospaco
Copy link
Collaborator Author

Without since the already shipped --useVersion: feature wont work, sorry nothing I can do.

Thanks. 🙂

@juancarlospaco juancarlospaco deleted the jsdomparser branch April 13, 2020 13:41
@timotheecour
Copy link
Member

timotheecour commented Apr 14, 2020

Once again putting it out there that I consider this since thing to be a waste of time.

/cc @dom96
I kind of agree (although I would call it adding un-needed complexity) but we need some kind of policy on this, we can't have it in some PR's and not on others depending on who's reviewing/merging; this should be debated/resolved in a single location (ie, an RFC); so instead of writing it here, create an RFC

@Araq
Copy link
Member

Araq commented Apr 14, 2020

And what would be the content of the RFC? "I don't understand the -std=c99 switch"? Opinions are valuable if you shaped them after you understood the problem... Bringing it up again and again wastes my time.

@timotheecour timotheecour mentioned this pull request Apr 14, 2020
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.

7 participants