From 6e4341d45481223a629f63a58a8ecfe64dda0156 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 302e54a378f813..38842d5c4a125b 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1022,6 +1022,7 @@ function domainToUnicode(domain) { } 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 1dfab2eaaf7fca..933ffe13b4d9e4 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 98349021586f1a..0b42eca5032d53 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 667738f817b707..aa3a0d9929bf52 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