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

@:native("$eval") for function DollarEval not converted to $eval in Puppeteer #60

Closed
rb1147x opened this issue Oct 20, 2020 · 3 comments

Comments

@rb1147x
Copy link

rb1147x commented Oct 20, 2020

Using Puppeteer there is a function: page.$eval and several other functions using the $ character (more info: https://github.com/puppeteer/puppeteer/blob/v5.3.1/docs/api.md#pageselector).

Externs get generated as page.DollarEval, however, the JS output keeps DollarEval instead of converting to $eval

Example:

From Puppeteer externs generated by dts2hx:

@:native("$eval")
	@:overload(function<R, X1>(selector:String, pageFunction:(element:js.html.DOMElement, x1:UnwrapElementHandle<X1>) -> ts.AnyOf2<js.lib.Promise<R>, R>, x1:X1):js.lib.Promise<WrapElementHandle<R>> { })
	@:overload(function<R, X1, X2>(selector:String, pageFunction:(element:js.html.DOMElement, x1:UnwrapElementHandle<X1>, x2:UnwrapElementHandle<X2>) -> ts.AnyOf2<js.lib.Promise<R>, R>, x1:X1, x2:X2):js.lib.Promise<WrapElementHandle<R>> { })
	@:overload(function<R, X1, X2, X3>(selector:String, pageFunction:(element:js.html.DOMElement, x1:UnwrapElementHandle<X1>, x2:UnwrapElementHandle<X2>, x3:UnwrapElementHandle<X3>) -> ts.AnyOf2<js.lib.Promise<R>, R>, x1:X1, x2:X2, x3:X3):js.lib.Promise<WrapElementHandle<R>> { })
	@:overload(function<R>(selector:String, pageFunction:(element:js.html.DOMElement, args:haxe.extern.Rest<Dynamic>) -> ts.AnyOf2<js.lib.Promise<R>, R>, args:haxe.extern.Rest<SerializableOrJSHandle>):js.lib.Promise<WrapElementHandle<R>> { })
	function DollarEval<R>(selector:String, pageFunction:(element:js.html.DOMElement) -> ts.AnyOf2<js.lib.Promise<R>, R>):js.lib.Promise<WrapElementHandle<R>>;

Usage:

page.DollarEval('div[itemscope="itemscope"]', function (el) {
   return el.innerHTML;
}).then(function(v) {
   trace(v);
});

JS output:

page.DollarEval("div[itemscope=\"itemscope\"]",function(el) {
  return el.innerHTML;
}).then(function(v) {
  console.log("src/Main.hx:36:",v);
});

Is this maybe a larger Haxe issue not supporting the $ character in @:native?

Thanks.

@haxiomic
Copy link
Owner

haxiomic commented Oct 20, 2020

Hey @rb1147x, this is indeed an issue in haxe, the problem is @:native isn't yet supported on typedefs. There are proposals and PRs to enable this like HaxeFoundation/haxe#9433 and HaxeFoundation/haxe#5105 but nothing has landed in the compiler yet

You may be able to change these to interfaces to fix for now (although it's not something dts2hx will do automatically because most of the time we need the properties of typedefs for other parts of the externs to work)

I agree this is a pain and it's one of the major long-term issues with haxe js externs

@haxiomic
Copy link
Owner

Closing as a duplicate
#48
#55

@rb1147x
Copy link
Author

rb1147x commented Oct 20, 2020

Oh, okay, thanks for the quick response!

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

No branches or pull requests

2 participants