Commit e3d50e0d authored by Robert Knight's avatar Robert Knight

Convert src/shared/{polyfills, test, settings.js} to ES modules

Convert all the modules under src/shared to ES modules except for those
which:

 1. Would have a default export if converted to an ES module AND
 2. Are imported by a module still written in CoffeeScript in src/annotator/

For modules which meet these criteria there is some additional work
required to make the tests for the CoffeeScript modules still work after
the conversion.
parent c97d7fad
const wgxpath = require('wicked-good-xpath'); import * as wgxpath from 'wicked-good-xpath';
wgxpath.install(); wgxpath.install();
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
// nb. The imports which add entire classes (Promise, Set etc.) will also add // nb. The imports which add entire classes (Promise, Set etc.) will also add
// all features for later ES years, so this can result in some duplication with // all features for later ES years, so this can result in some duplication with
// bundles for later ES years. // bundles for later ES years.
require('core-js/es/promise'); import 'core-js/es/promise';
require('core-js/es/map'); import 'core-js/es/map';
require('core-js/es/number'); import 'core-js/es/number';
require('core-js/es/set'); import 'core-js/es/set';
require('core-js/es/symbol'); import 'core-js/es/symbol';
require('core-js/es/array/fill'); import 'core-js/es/array/fill';
require('core-js/es/array/find'); import 'core-js/es/array/find';
require('core-js/es/array/find-index'); import 'core-js/es/array/find-index';
require('core-js/es/array/from'); import 'core-js/es/array/from';
require('core-js/es/object/assign'); import 'core-js/es/object/assign';
require('core-js/es/string/includes'); import 'core-js/es/string/includes';
require('core-js/es/string/ends-with'); import 'core-js/es/string/ends-with';
require('core-js/es/string/starts-with'); import 'core-js/es/string/starts-with';
require('core-js/es/array/includes'); import 'core-js/es/array/includes';
require('core-js/es/object/entries'); import 'core-js/es/object/entries';
require('core-js/es/object/values'); import 'core-js/es/object/values';
require('whatwg-fetch'); import 'whatwg-fetch';
...@@ -95,7 +95,7 @@ const needsPolyfill = { ...@@ -95,7 +95,7 @@ const needsPolyfill = {
* Return the subset of polyfill sets from `needed` which are needed by the * Return the subset of polyfill sets from `needed` which are needed by the
* current browser. * current browser.
*/ */
function requiredPolyfillSets(needed) { export function requiredPolyfillSets(needed) {
return needed.filter(set => { return needed.filter(set => {
const checker = needsPolyfill[set]; const checker = needsPolyfill[set];
if (!checker) { if (!checker) {
...@@ -104,7 +104,3 @@ function requiredPolyfillSets(needed) { ...@@ -104,7 +104,3 @@ function requiredPolyfillSets(needed) {
return checker(); return checker();
}); });
} }
module.exports = {
requiredPolyfillSets,
};
const { requiredPolyfillSets } = require('../'); import { requiredPolyfillSets } from '../';
function stubOut(obj, property, replacement = undefined) { function stubOut(obj, property, replacement = undefined) {
const saved = obj[property]; const saved = obj[property];
......
require('js-polyfills/url'); import 'js-polyfills/url';
...@@ -25,7 +25,7 @@ function assign(dest, src) { ...@@ -25,7 +25,7 @@ function assign(dest, src) {
* *
* @param {Document|Element} document - The root element to search. * @param {Document|Element} document - The root element to search.
*/ */
function jsonConfigsFrom(document) { export function jsonConfigsFrom(document) {
const config = {}; const config = {};
const settingsElements = document.querySelectorAll( const settingsElements = document.querySelectorAll(
'script.js-hypothesis-config' 'script.js-hypothesis-config'
...@@ -47,7 +47,3 @@ function jsonConfigsFrom(document) { ...@@ -47,7 +47,3 @@ function jsonConfigsFrom(document) {
return config; return config;
} }
module.exports = {
jsonConfigsFrom: jsonConfigsFrom,
};
const Bridge = require('../bridge'); import Bridge from '../bridge';
const RPC = require('../frame-rpc'); import RPC from '../frame-rpc';
describe('shared.bridge', function() { describe('shared.bridge', function() {
const sandbox = sinon.createSandbox(); const sandbox = sinon.createSandbox();
......
const Discovery = require('../discovery'); import Discovery from '../discovery';
function createWindow() { function createWindow() {
return { return {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* @param {Promise} promise * @param {Promise} promise
* @param {string} expectedErr - Expected `message` property of error * @param {string} expectedErr - Expected `message` property of error
*/ */
function assertPromiseIsRejected(promise, expectedErr) { export function assertPromiseIsRejected(promise, expectedErr) {
const rejectFlag = {}; const rejectFlag = {};
return promise return promise
.catch(err => { .catch(err => {
...@@ -33,7 +33,7 @@ function assertPromiseIsRejected(promise, expectedErr) { ...@@ -33,7 +33,7 @@ function assertPromiseIsRejected(promise, expectedErr) {
* *
* Consider using `assertPromiseIsRejected` instead. * Consider using `assertPromiseIsRejected` instead.
*/ */
function toResult(promise) { export function toResult(promise) {
return promise return promise
.then(function(result) { .then(function(result) {
return { result: result }; return { result: result };
...@@ -42,8 +42,3 @@ function toResult(promise) { ...@@ -42,8 +42,3 @@ function toResult(promise) {
return { error: err }; return { error: err };
}); });
} }
module.exports = {
assertPromiseIsRejected,
toResult,
};
const settings = require('../settings'); import * as settings from '../settings';
const sandbox = sinon.createSandbox(); const sandbox = sinon.createSandbox();
......
const warnOnce = require('../warn-once'); import warnOnce from '../warn-once';
describe('warnOnce', () => { describe('warnOnce', () => {
beforeEach(() => { beforeEach(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment