Fix node6 support for Object.entries and URL object (#548)
This patch introduces a polyfill for Object.entries which is missing in Node 6
This commit is contained in:
parent
4e3b6a1f57
commit
2c4dfbfd88
@ -16,7 +16,7 @@
|
||||
const EventEmitter = require('events');
|
||||
const helper = require('./helper');
|
||||
const Multimap = require('./Multimap');
|
||||
const {URL} = require('url');
|
||||
const url = require('url');
|
||||
|
||||
class NetworkManager extends EventEmitter {
|
||||
/**
|
||||
@ -356,13 +356,13 @@ function generateRequestHash(request) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {string} urlString
|
||||
* @return {string}
|
||||
*/
|
||||
function removeURLHash(url) {
|
||||
const urlObject = new URL(url);
|
||||
function removeURLHash(urlString) {
|
||||
const urlObject = url.parse(urlString);
|
||||
urlObject.hash = '';
|
||||
return urlObject.toString();
|
||||
return url.format(urlObject);
|
||||
}
|
||||
|
||||
NetworkManager.Events = {
|
||||
|
@ -218,4 +218,9 @@ class Helper {
|
||||
}
|
||||
}
|
||||
|
||||
// Polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
|
||||
if (!Object.entries)
|
||||
Object.entries = obj => Object.keys(obj).map(key => [key, obj[key]]);
|
||||
|
||||
|
||||
module.exports = Helper;
|
||||
|
@ -76,7 +76,7 @@ ESTreeWalker.SkipSubtree = {};
|
||||
|
||||
/** @enum {!Array.<string>} */
|
||||
ESTreeWalker._walkOrder = {
|
||||
'AwaitExpression': ['arguments'],
|
||||
'AwaitExpression': ['argument'],
|
||||
'ArrayExpression': ['elements'],
|
||||
'ArrowFunctionExpression': ['params', 'body'],
|
||||
'AssignmentExpression': ['left', 'right'],
|
||||
|
@ -53,7 +53,7 @@ const asyncToGenerator = fn => {
|
||||
function transformAsyncFunctions(text) {
|
||||
const edits = [];
|
||||
|
||||
const ast = esprima.parseScript(text, {range: true});
|
||||
const ast = esprima.parseScript(text, {range: true, tolerant: true});
|
||||
const walker = new ESTreeWalker(node => {
|
||||
if (node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'ArrowFunctionExpression')
|
||||
onFunction(node);
|
||||
|
@ -64,4 +64,10 @@ describe('TransformAsyncFunctions', function() {
|
||||
expect(output instanceof Promise).toBe(true);
|
||||
output.then(result => expect(result).toBe(123)).then(done);
|
||||
});
|
||||
it('should work with double await', function(done) {
|
||||
const input = `async function f(){ return 23 + await Promise.resolve(50 + await Promise.resolve(50)); } f();`;
|
||||
const output = eval(transformAsyncFunctions(input));
|
||||
expect(output instanceof Promise).toBe(true);
|
||||
output.then(result => expect(result).toBe(123)).then(done);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user