Skip to content

Commit

Permalink
initial URL and URLSearchParams commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Nov 12, 2018
1 parent 13d5fe7 commit a16ab2e
Show file tree
Hide file tree
Showing 35 changed files with 2,678 additions and 52 deletions.
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,36 @@
- `Symbol.patternMatch` ([for stage 1 pattern matching proposal](https://github.com/tc39/proposal-pattern-matching))
- `Symbol.dispose` ([for stage 1 `using` statement proposal](https://github.com/tc39/proposal-using-statement))
- `Promise.allSettled` ([stage 1 proposal](https://github.com/jasonwilliams/proposal-promise-allSettled))
- `.forEach` method to iterable DOM collections ([#329](https://github.com/zloirock/core-js/issues/329))
- `URL` and `URLSearchParam` [from `URL` standard](https://url.spec.whatwg.org/), also [stage 0 proposal to ECMAScript](https://github.com/jasnell/proposal-url)
- `URL`
- `URL#href`
- `URL#origin`
- `URL#protocol`
- `URL#username`
- `URL#password`
- `URL#host`
- `URL#hostname`
- `URL#port`
- `URL#pathname`
- `URL#search`
- `URL#searchParams`
- `URL#hash`
- `URL#toString`
- `URL#toJSON`
- `URLSearchParams`
- `URLSearchParams#append`
- `URLSearchParams#delete`
- `URLSearchParams#get`
- `URLSearchParams#getAll`
- `URLSearchParams#has`
- `URLSearchParams#set`
- `URLSearchParams#sort`
- `URLSearchParams#toString`
- `URLSearchParams#keys`
- `URLSearchParams#values`
- `URLSearchParams#entries`
- `URLSearchParams#@@iterator`
- `.forEach` method on iterable DOM collections ([#329](https://github.com/zloirock/core-js/issues/329))
- Improve existing features:
- Add triggering unhandled `Promise` rejection events (instead of only global handlers), [#205](https://github.com/zloirock/core-js/issues/205).
- Add support of `@@isConcatSpreadable` to `Array#concat`.
Expand Down
105 changes: 81 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ Promise.resolve(32).then(x => console.log(x)); // => 32
- [stage 0 proposals](#stage-0-proposals)
- [pre-stage 0 proposals](#pre-stage-0-proposals)
- [Web standards](#web-standards)
- [setTimeout / setInterval](#settimeout--setinterval)
- [setImmediate](#setimmediate)
- [queueMicrotask](#queuemicrotask)
- [`setTimeout` and `setInterval`](#settimeout-and-setinterval)
- [`setImmediate`](#setimmediate)
- [`queueMicrotask`](#queuemicrotask)
- [`URL` and `URLSearchParams`](#url-and-urlsearchparams)
- [iterable DOM collections](#iterable-dom-collections)
- [Iteration helpers](#iteration-helpers)
- [Missing polyfills](#missing-polyfills)
Expand Down Expand Up @@ -535,7 +536,7 @@ class RegExp {
@@replace(string: string, replaceValue: Function | string): string;
@@search(string: string): number;
@@split(string: string, limit: number): Array<string>;
get flags: string; // IE9+
readonly attribute flags: string; // IE9+
}
```
[*CommonJS entry points:*](#commonjs)
Expand Down Expand Up @@ -1024,7 +1025,7 @@ class Map {
keys(): Iterator<key>;
entries(): Iterator<[key, value]>;
@@iterator(): Iterator<[key, value]>;
get size: number;
readonly attribute size: number;
}
```
[*CommonJS entry points:*](#commonjs)
Expand Down Expand Up @@ -1078,7 +1079,7 @@ class Set {
keys(): Iterator<value>;
entries(): Iterator<[value, value]>;
@@iterator(): Iterator<value>;
get size: number;
readonly attribute size: number;
}
```
[*CommonJS entry points:*](#commonjs)
Expand Down Expand Up @@ -1194,7 +1195,7 @@ Modules [`es.array-buffer.constructor`](https://github.com/zloirock/core-js/blob
class ArrayBuffer {
constructor(length: any): ArrayBuffer;
slice(start: any, end: any): ArrayBuffer;
get byteLength: number;
readonly attribute byteLength: number;
static isView(arg: any): boolean;
}

Expand All @@ -1216,9 +1217,9 @@ class DataView {
setUint32(offset: any, value: any, littleEndian?: boolean = false): void;
setFloat32(offset: any, value: any, littleEndian?: boolean = false): void;
setFloat64(offset: any, value: any, littleEndian?: boolean = false): void;
get buffer: ArrayBuffer;
get byteLength: number;
get byteOffset: number;
readonly attribute buffer: ArrayBuffer;
readonly attribute byteLength: number;
readonly attribute byteOffset: number;
}

class [
Expand Down Expand Up @@ -1261,10 +1262,10 @@ class [
keys(): Iterator<index>;
entries(): Iterator<[index, value]>;
@@iterator(): Iterator<value>;
get buffer: ArrayBuffer;
get byteLength: number;
get byteOffset: number;
get length: number;
readonly attribute buffer: ArrayBuffer;
readonly attribute byteLength: number;
readonly attribute byteOffset: number;
readonly attribute length: number;
BYTES_PER_ELEMENT: number;
static from(items: Iterable | ArrayLike, mapFn?: (value: any, index: number) => any, thisArg?: any): %TypedArray%;
static of(...args: Array<mixed>): %TypedArray%;
Expand Down Expand Up @@ -1533,7 +1534,7 @@ globalThis.Array === Array; // => true
* `Symbol#description` [proposal](https://github.com/tc39/proposal-Symbol-description) - module [`esnext.symbol.description`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.description.js)
```js
class Symbol {
get description: string | void;
readonly attribute description: string | void;
}
```
[*CommonJS entry points:*](#commonjs)
Expand Down Expand Up @@ -1572,7 +1573,7 @@ core-js(-pure)/features/set/union
[*Examples*](https://goo.gl/YjaxTN):
```js
new Set([1, 2, 3]).union([3, 4, 5]); // => Set {1, 2, 3, 4, 5}
new Set([1, 2, 3]).intersection([3, 4, 5]); // => Set {3}
new Set([1, 2, 3]).intersection([3, 4, 5]); // => Set {3}
new Set([1, 2, 3]).difference([3, 4, 5]); // => Set {1, 2}
new Set([1, 2, 3]).symmetricDifference([3, 4, 5]); // => Set {1, 2, 4, 5}
```
Expand All @@ -1585,9 +1586,8 @@ core-js(-pure)/stage/1
* Getting last item from `Array` [proposal](https://github.com/keithamus/proposal-array-last) - modules [`esnext.array.last-item`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.last-item.js) and [`esnext.array.last-index`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.last-index.js)
```js
class Array {
get lastItem: value;
set lastItem(value);
get lastIndex: uint;
attribute lastItem: any;
readonly attribute lastIndex: uint;
}
```
[*CommonJS entry points:*](#commonjs)
Expand Down Expand Up @@ -1797,7 +1797,7 @@ class Observable {
@@observable(): this;
static of(...items: Aray<mixed>): Observable;
static from(x: Observable | Iterable): Observable;
static get @@species: this;
static readonly attribute @@species: this;
}
class Symbol {
Expand Down Expand Up @@ -1938,6 +1938,7 @@ core-js(-pure)/features/symbol/dispose
```js
core-js(-pure)/stage/0
```
* `URL` [proposal](https://github.com/jasnell/proposal-url), see more info [in web standards namespace](#url-and-urlsearchparams)
* `String#at` [proposal](https://github.com/mathiasbynens/String.prototype.at) - module [`esnext.string.at`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.string.at.js)
```js
class String {
Expand Down Expand Up @@ -2019,7 +2020,7 @@ Reflect.getOwnMetadata('foo', object); // => 'bar'
```js
core-js(-pure)/web
```
#### setTimeout / setInterval
#### `setTimeout` and `setInterval`
Module [`web.timers`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.timers.js). Additional arguments fix for IE9-.
```js
function setTimeout(callback: any, time: any, ...args: Array<mixed>): number;
Expand All @@ -2037,7 +2038,7 @@ setTimeout(log.bind(null, 42), 1000);
// After:
setTimeout(log, 1000, 42);
```
#### setImmediate
#### `setImmediate`
Module [`web.immediate`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.immediate.js). [`setImmediate` proposal](https://developer.mozilla.org/en-US/docs/Web/API/Window.setImmediate) polyfill.
```js
function setImmediate(callback: any, ...args: Array<mixed>): number;
Expand All @@ -2059,7 +2060,8 @@ clearImmediate(setImmediate(() => {
console.log('Message will not be displayed');
}));
```
#### queueMicrotask

#### `queueMicrotask`
[Spec](https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-queuemicrotask), module [`web.queue-microtask`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.queue-microtask.js)
```js
function queueMicrotask(fn: Function): void;
Expand All @@ -2074,6 +2076,61 @@ core-js(-pure)/features/queue-microtask
queueMicrotask(() => console.log('called as microtask'));
```

#### `URL` and `URLSearchParams`
[`URL` standard](https://url.spec.whatwg.org/) implementation. Modules [`web.url`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url.js), [`web.url.to-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url.to-json.js), [`web.url-search-params`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url-search-params.js), [`web.url-search-params.sort`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url-search-params.sort.js).
```js
class URL {
constructor(url: string, base?: string);
attribute href: string;
readonly attribute origin: string;
attribute protocol: string;
attribute username: string;
attribute password: string;
attribute host: string;
attribute hostname: string;
attribute port: string;
attribute pathname: string;
attribute search: string;
readonly attribute searchParams: URLSearchParams;
attribute hash: string;
toJSON(): string;
toString(): string;
}
class URLSearchParams {
constructor(params?: string | Iterable<[key, value]> | Object);
append(name: string, value: string): void;
delete(name: string): void;
get(name: string): string | void;
getAll(name: string): Array<string>;
has(name: string): boolean;
set(name: string, value: string): void;
sort(): void;
toString(): string;
forEach(callbackfn: (value: any, index: number, target: any) => void, thisArg: any): void;
entries(): Iterator<[key, value]>;
keys(): Iterator<key>;
values(): Iterator<value>;
@@iterator(): Iterator<[key, value]>;
}
```
[*CommonJS entry points:*](#commonjs)
```js
core-js/proposals/url
core-js(-pure)/web/url
core-js(-pure)/web/url-search-params
core-js(-pure)/features/url
core-js/features/url/to-json
core-js(-pure)/features/url-search-params
core-js/features/url-search-params/sort
```
[*Examples*]():
```js
const url = new URL('http://zloirock.ru/');
const params = new URLSearchParams('?a=1&b=2&a=3');
```

#### Iterable DOM collections
Some DOM collections should have [iterable interface](https://heycam.github.io/webidl/#idl-iterable) or should be [inherited from `Array`](https://heycam.github.io/webidl/#LegacyArrayClass). That means they should have `forEach`, `keys`, `values`, `entries` and `@@iterator` methods for iteration. So add them. Modules [`web.dom-collections.iterator`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.dom-collections.iterator.js) and [`web.dom-collections.for-each`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.dom-collections.for-each.js).
```js
Expand Down Expand Up @@ -2112,8 +2169,8 @@ class [
}
class [DOMTokenList, NodeList] {
entries(): Iterator<[key, value]>;
forEach(callbackfn: (value: any, index: number, target: any) => void, thisArg: any): void;
entries(): Iterator<[key, value]>;
keys(): Iterator<key>;
values(): Iterator<value>;
@@iterator(): Iterator<value>;
Expand Down
4 changes: 4 additions & 0 deletions packages/core-js-builder/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ module.exports = {
'web.immediate',
'web.queue-microtask',
'web.timers',
'web.url',
'web.url.to-json',
'web.url-search-params',
'web.url-search-params.sort',
],
/* eslint-disable prefer-template */
banner: '/**\n' +
Expand Down
8 changes: 4 additions & 4 deletions packages/core-js-pure/override/internals/redefine-all.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var hide = require('../internals/hide');
var redefine = require('../internals/redefine');

module.exports = function (target, src, safe) {
module.exports = function (target, src, options) {
for (var key in src) {
if (safe && target[key]) target[key] = src[key];
else hide(target, key, src[key]);
if (options && options.unsafe && target[key]) target[key] = src[key];
else redefine(target, key, src[key], options);
} return target;
};
7 changes: 6 additions & 1 deletion packages/core-js-pure/override/internals/redefine.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
module.exports = require('../internals/hide');
var hide = require('../internals/hide');

module.exports = function (target, key, value, options) {
if (options && options.enumerable) target[key] = value;
else hide(target, key, value);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty
1 change: 1 addition & 0 deletions packages/core-js-pure/override/modules/web.url.to-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty
4 changes: 4 additions & 0 deletions packages/core-js/features/url-search-params/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('../../modules/web.url-search-params');
require('../../modules/web.url-search-params.sort');

module.exports = require('../../internals/path').URLSearchParams;
1 change: 1 addition & 0 deletions packages/core-js/features/url-search-params/sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('../../modules/web.url-search-params.sort');
6 changes: 6 additions & 0 deletions packages/core-js/features/url/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require('../../modules/web.url');
require('../../modules/web.url.to-json');
require('../../modules/web.url-search-params');
require('../../modules/web.url-search-params.sort');

module.exports = require('../../internals/path').URL;
1 change: 1 addition & 0 deletions packages/core-js/features/url/to-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('../../modules/web.url.to-json');
4 changes: 4 additions & 0 deletions packages/core-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,8 @@ require('./modules/web.dom-collections.iterator');
require('./modules/web.immediate');
require('./modules/web.queue-microtask');
require('./modules/web.timers');
require('./modules/web.url');
require('./modules/web.url.to-json');
require('./modules/web.url-search-params');
require('./modules/web.url-search-params.sort');
module.exports = require('./internals/path');
23 changes: 12 additions & 11 deletions packages/core-js/internals/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ var setGlobal = require('../internals/set-global');
var copyConstructorProperties = require('../internals/copy-constructor-properties');

/*
options.target - name of the target object
options.global - target is the global object
options.stat - export as static methods of target
options.proto - export as prototype methods of target
options.real - real prototype method for the `pure` version
options.forced - export even if the native feature is available
options.bind - bind methods to the target, required for the `pure` version
options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
options.unsafe - use the simple assignment of property instead of delete + defineProperty
options.sham - add a flag to not completely full polyfills
options.target - name of the target object
options.global - target is the global object
options.stat - export as static methods of target
options.proto - export as prototype methods of target
options.real - real prototype method for the `pure` version
options.forced - export even if the native feature is available
options.bind - bind methods to the target, required for the `pure` version
options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
options.unsafe - use the simple assignment of property instead of delete + defineProperty
options.sham - add a flag to not completely full polyfills
options.enumerable - export as enumerable property
*/
module.exports = function (options, source) {
var TARGET = options.target;
Expand All @@ -39,6 +40,6 @@ module.exports = function (options, source) {
hide(sourceProperty, 'sham', true);
}
// extend global
redefine(target, key, sourceProperty, options.unsafe);
redefine(target, key, sourceProperty, options);
}
};
13 changes: 13 additions & 0 deletions packages/core-js/internals/native-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var IS_PURE = require('../internals/is-pure');
var ITERATOR = require('../internals/well-known-symbol')('iterator');

module.exports = !require('../internals/fails')(function () {
var url = new URL('b?e=1', 'http://a');
var searchParams = url.searchParams;
url.pathname = 'c%20d';
return (IS_PURE && (!url.toJSON || !searchParams.sort))
|| url.href !== 'http://a/c%20d?e=1'
|| searchParams.get('e') !== '1'
|| String(new URLSearchParams('?a=1')) !== 'a=1'
|| !searchParams[ITERATOR];
});
4 changes: 2 additions & 2 deletions packages/core-js/internals/redefine-all.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var redefine = require('../internals/redefine');

module.exports = function (target, src, safe) {
for (var key in src) redefine(target, key, src[key], safe);
module.exports = function (target, src, options) {
for (var key in src) redefine(target, key, src[key], options);
return target;
};
Loading

0 comments on commit a16ab2e

Please sign in to comment.