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
Make URLSearchParams compliant with the spec and browser #1055
Conversation
This needs tests to ensure this is spec compliant now |
@kyranet Sure.
|
3 similar comments
@kyranet Sure.
|
@kyranet Sure.
|
@kyranet Sure.
|
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.
LGTM
Generators are iterators. Generators are functions that codify iterators. Something like: class Foo {
*keys() {
yield "foo";
yield "bar";
}
}
const foo = new Foo();
const keys = foo.keys();
console.log(Symbol.iterator in keys); // true Is exactly the spec functionality, except that it logs out I think we need to align to what is being done in #1062 so until #1062 settles down and this gets realigned to that, we should hold off merging. |
@kitsonk Okay, I see. Thanks for your explanation. |
and it needs tests |
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.
A few comments...
js/dom_types.ts
Outdated
@@ -90,7 +90,7 @@ export interface ProgressEventInit extends EventInit { | |||
total?: number; | |||
} | |||
|
|||
export interface URLSearchParams { | |||
export interface URLSearchParams extends DomIterable<string, string>{ |
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.
I don't think this has been through the formatter again. Prettier would have inserted a space before the opening brace.
js/globals.ts
Outdated
@@ -6,7 +6,7 @@ import { globalEval } from "./global_eval"; | |||
import { libdeno } from "./libdeno"; | |||
import * as textEncoding from "./text_encoding"; | |||
import * as timers from "./timers"; | |||
import * as urlSearchParams from "./url_search_params"; | |||
import * as urlSearchParams_ from "./url_search_params"; |
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.
you don't need to underscore this... it is only needed when there is a name collision in the global namespace, (e.g. console
or fetch
). Since there is no global variable named urlSearchParams
it is safe to use.
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.
My bad, I just thought it was the same as the browser.
js/mixins/dom_iterable.ts
Outdated
@@ -24,19 +24,19 @@ export function DomIterableMixin<K, V, TBase extends Constructor>( | |||
// tslint:disable-next-line:variable-name | |||
const DomIterable = class extends Base { | |||
*entries(): IterableIterator<[K, V]> { | |||
for (const entry of (this as any)[dataSymbol].entries()) { | |||
for (const entry of (this as any)[dataSymbol]) { |
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.
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.
I don't think need to create a seperate change in here. for const entry of Array<k, v>
as same as for const entry of Map<k, v>
.
js/mixins/dom_iterable.ts
Outdated
yield entry; | ||
} | ||
} | ||
|
||
*keys(): IterableIterator<K> { | ||
for (const key of (this as any)[dataSymbol].keys()) { | ||
for (const [key,] of (this as any)[dataSymbol]) { |
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.
#1056 has this as:
for (const [key,] of (this as any)[dataSymbol]) { | |
for (const [key] of (this as any)[dataSymbol]) { |
which is better
js/url_search_params.ts
Outdated
export const URLSearchParams = DomIterableMixin<string, string, typeof URLSearchParamsBase>( | ||
URLSearchParamsBase, | ||
params | ||
); |
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.
not run through the formatter or this would have been changed to break before EOF as well as on line 146 lacking spacing before the opening parenthesis.
js/url_search_params.ts
Outdated
.map( | ||
tuple => | ||
`${encodeURIComponent(tuple[0])}=${encodeURIComponent(tuple[1])}` | ||
) | ||
.join("&"); | ||
} | ||
} | ||
|
||
// @internal |
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.
There should be no need for @internal
here.
|
||
// @internal | ||
// tslint:disable:max-line-length | ||
// tslint:disable-next-line:variable-name |
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.
// tslint:disable-next-line:variable-name | |
// tslint:disable-next-line:variable-name max-line-length |
But even then, Prettier should break the generic arguments up.
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.
Thanks.
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.
So yeah, now with the wrapping after running through prettier, max-line-length
is redundant.
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.
This was preemptively approved. Please address @kitsonk's comments.
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.
One minor nit, but other than that LGTM.
Also, it should cleanly apply, but we have overlapping changes with #1056.
|
||
// @internal | ||
// tslint:disable:max-line-length | ||
// tslint:disable-next-line:variable-name |
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.
So yeah, now with the wrapping after running through prettier, max-line-length
is redundant.
@kitsonk Yes, the problem is think about how to reuse. |
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.
LGTM - thank you - and sorry for the delay! Having some issues with appveyor build but will land once those are settled. I've rebased and squashed the branch.
Closing old PRs. Please open a new one if this hasn't been resolved yet. |
Looks like #1049 superseded this anyway? |
According to MDN Docs
keys
,values
andentries
shouldn't a generator function, and need to return aIterator
.For example:
in chrome and firefox: