From e43904759e4ff18bf6b218d9dfc898fafe9062e4 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Wed, 21 Dec 2016 13:41:29 -0800 Subject: [PATCH] url: export URLSearchParams Fixes: #10761 --- lib/internal/url.js | 1 + lib/url.js | 1 + test/parallel/test-whatwg-url-searchparams-append.js | 8 ++------ .../test-whatwg-url-searchparams-constructor.js | 8 ++------ test/parallel/test-whatwg-url-searchparams-delete.js | 10 ++++------ .../parallel/test-whatwg-url-searchparams-foreach.js | 12 ++++-------- test/parallel/test-whatwg-url-searchparams-get.js | 8 ++------ test/parallel/test-whatwg-url-searchparams-getall.js | 9 ++------- test/parallel/test-whatwg-url-searchparams-has.js | 8 ++------ test/parallel/test-whatwg-url-searchparams-set.js | 8 ++------ .../test-whatwg-url-searchparams-stringifier.js | 8 ++------ 11 files changed, 24 insertions(+), 57 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index e8dcacc56dc164..0eee3855cecd1c 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -933,6 +933,7 @@ function urlToOptions(url) { } exports.URL = URL; +exports.URLSearchParams = URLSearchParams; exports.originFor = originFor; exports.domainToASCII = domainToASCII; exports.domainToUnicode = domainToUnicode; diff --git a/lib/url.js b/lib/url.js index 8bdfd0cb668f63..4ad6e31bb0e901 100644 --- a/lib/url.js +++ b/lib/url.js @@ -17,6 +17,7 @@ exports.resolve = urlResolve; exports.resolveObject = urlResolveObject; exports.format = urlFormat; exports.URL = internalUrl.URL; +exports.URLSearchParams = internalUrl.URLSearchParams; exports.originFor = internalUrl.originFor; exports.domainToASCII = internalUrl.domainToASCII; exports.domainToUnicode = internalUrl.domainToUnicode; diff --git a/test/parallel/test-whatwg-url-searchparams-append.js b/test/parallel/test-whatwg-url-searchparams-append.js index 1f61cb0d11bb6b..5ef92252be5d9e 100644 --- a/test/parallel/test-whatwg-url-searchparams-append.js +++ b/test/parallel/test-whatwg-url-searchparams-append.js @@ -2,13 +2,9 @@ require('../common'); const assert = require('assert'); -const URL = require('url').URL; +const URLSearchParams = require('url').URLSearchParams; -const m = new URL('http://example.org'); -let params = m.searchParams; - -// Until we export URLSearchParams -const URLSearchParams = params.constructor; +let params; // Append same name params = new URLSearchParams(); diff --git a/test/parallel/test-whatwg-url-searchparams-constructor.js b/test/parallel/test-whatwg-url-searchparams-constructor.js index 34ccb4c37d55f3..9b7ca1e4e9c54a 100644 --- a/test/parallel/test-whatwg-url-searchparams-constructor.js +++ b/test/parallel/test-whatwg-url-searchparams-constructor.js @@ -2,13 +2,9 @@ require('../common'); const assert = require('assert'); -const URL = require('url').URL; +const URLSearchParams = require('url').URLSearchParams; -const m = new URL('http://example.org'); -let params = m.searchParams; - -// Until we export URLSearchParams -const URLSearchParams = params.constructor; +let params; // Basic URLSearchParams construction params = new URLSearchParams(); diff --git a/test/parallel/test-whatwg-url-searchparams-delete.js b/test/parallel/test-whatwg-url-searchparams-delete.js index b08a3b76867572..71bb7487a75087 100644 --- a/test/parallel/test-whatwg-url-searchparams-delete.js +++ b/test/parallel/test-whatwg-url-searchparams-delete.js @@ -2,13 +2,11 @@ require('../common'); const assert = require('assert'); -const URL = require('url').URL; +const url = require('url'); +const URL = url.URL; +const URLSearchParams = url.URLSearchParams; -const m = new URL('http://example.org'); -let params = m.searchParams; - -// Until we export URLSearchParams -const URLSearchParams = params.constructor; +let params; // Delete basics params = new URLSearchParams('a=b&c=d'); diff --git a/test/parallel/test-whatwg-url-searchparams-foreach.js b/test/parallel/test-whatwg-url-searchparams-foreach.js index b6d684b06743b0..199d01b8fdfbcc 100644 --- a/test/parallel/test-whatwg-url-searchparams-foreach.js +++ b/test/parallel/test-whatwg-url-searchparams-foreach.js @@ -2,18 +2,14 @@ require('../common'); const assert = require('assert'); -const URL = require('url').URL; - -const m = new URL('http://example.org'); -let params = m.searchParams; - -// Until we export URLSearchParams -const URLSearchParams = params.constructor; +const url = require('url'); +const URL = url.URL; +const URLSearchParams = url.URLSearchParams; let a, b, i; // ForEach Check -params = new URLSearchParams('a=1&b=2&c=3'); +const params = new URLSearchParams('a=1&b=2&c=3'); const keys = []; const values = []; params.forEach(function(value, key) { diff --git a/test/parallel/test-whatwg-url-searchparams-get.js b/test/parallel/test-whatwg-url-searchparams-get.js index cfc6c345a6b3ee..7ddfb67e8b8a7b 100644 --- a/test/parallel/test-whatwg-url-searchparams-get.js +++ b/test/parallel/test-whatwg-url-searchparams-get.js @@ -2,13 +2,9 @@ require('../common'); const assert = require('assert'); -const URL = require('url').URL; +const URLSearchParams = require('url').URLSearchParams; -const m = new URL('http://example.org'); -let params = m.searchParams; - -// Until we export URLSearchParams -const URLSearchParams = params.constructor; +let params; // Get basics params = new URLSearchParams('a=b&c=d'); diff --git a/test/parallel/test-whatwg-url-searchparams-getall.js b/test/parallel/test-whatwg-url-searchparams-getall.js index 8333982d688c3b..34805164ab1b38 100644 --- a/test/parallel/test-whatwg-url-searchparams-getall.js +++ b/test/parallel/test-whatwg-url-searchparams-getall.js @@ -2,14 +2,9 @@ require('../common'); const assert = require('assert'); -const URL = require('url').URL; - -const m = new URL('http://example.org'); -let params = m.searchParams; - -// Until we export URLSearchParams -const URLSearchParams = params.constructor; +const URLSearchParams = require('url').URLSearchParams; +let params; let matches; // getAll() basics diff --git a/test/parallel/test-whatwg-url-searchparams-has.js b/test/parallel/test-whatwg-url-searchparams-has.js index c884227e0b0f1d..cd8901da2398b7 100644 --- a/test/parallel/test-whatwg-url-searchparams-has.js +++ b/test/parallel/test-whatwg-url-searchparams-has.js @@ -2,13 +2,9 @@ require('../common'); const assert = require('assert'); -const URL = require('url').URL; +const URLSearchParams = require('url').URLSearchParams; -const m = new URL('http://example.org'); -let params = m.searchParams; - -// Until we export URLSearchParams -const URLSearchParams = params.constructor; +let params; // Has basics params = new URLSearchParams('a=b&c=d'); diff --git a/test/parallel/test-whatwg-url-searchparams-set.js b/test/parallel/test-whatwg-url-searchparams-set.js index 2d9ae8aaa8d021..5ab2bbe8d8ac39 100644 --- a/test/parallel/test-whatwg-url-searchparams-set.js +++ b/test/parallel/test-whatwg-url-searchparams-set.js @@ -2,13 +2,9 @@ require('../common'); const assert = require('assert'); -const URL = require('url').URL; +const URLSearchParams = require('url').URLSearchParams; -const m = new URL('http://example.org'); -let params = m.searchParams; - -// Until we export URLSearchParams -const URLSearchParams = params.constructor; +let params; // Set basics params = new URLSearchParams('a=b&c=d'); diff --git a/test/parallel/test-whatwg-url-searchparams-stringifier.js b/test/parallel/test-whatwg-url-searchparams-stringifier.js index 0a53df634454b6..c591425461a9d1 100644 --- a/test/parallel/test-whatwg-url-searchparams-stringifier.js +++ b/test/parallel/test-whatwg-url-searchparams-stringifier.js @@ -2,13 +2,9 @@ require('../common'); const assert = require('assert'); -const URL = require('url').URL; +const URLSearchParams = require('url').URLSearchParams; -const m = new URL('http://example.org'); -let params = m.searchParams; - -// Until we export URLSearchParams -const URLSearchParams = params.constructor; +let params; // Serialize space // querystring does not currently handle spaces intelligently