diff --git a/.eslintrc.json b/.eslintrc.json index 39963d32..81104c48 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,11 +1,9 @@ { "parserOptions": { - "ecmaVersion": 5 + "ecmaVersion": 6, + "sourceType": "module" }, "extends": "eslint:recommended", - "env": { - "commonjs": true - }, "rules": { "strict": [2, "global"], "block-scoped-var": 2, diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70427e62..aa57eb55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,8 @@ jobs: - uses: actions/checkout@v2 - uses: purescript-contrib/setup-purescript@main + with: + purescript: "unstable" - uses: actions/setup-node@v1 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index c5e19e60..42e937eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] Breaking changes: +- Migrated FFI to ES Modules (#287 by @kl0tl and @JordanMartinez) New features: diff --git a/package.json b/package.json index 3ed6897b..8382d607 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ }, "devDependencies": { "eslint": "^7.15.0", - "purescript-psa": "^0.8.0", - "pulp": "^15.0.0", + "purescript-psa": "^0.8.2", + "pulp": "16.0.0-0", "rimraf": "^3.0.2" } } diff --git a/src/Control/Apply.js b/src/Control/Apply.js index 0b4720ca..149f4385 100644 --- a/src/Control/Apply.js +++ b/src/Control/Apply.js @@ -1,6 +1,4 @@ -"use strict"; - -exports.arrayApply = function (fs) { +export const arrayApply = function (fs) { return function (xs) { var l = fs.length; var k = xs.length; diff --git a/src/Control/Bind.js b/src/Control/Bind.js index f21afc29..fa0dbaeb 100644 --- a/src/Control/Bind.js +++ b/src/Control/Bind.js @@ -1,6 +1,4 @@ -"use strict"; - -exports.arrayBind = function (arr) { +export const arrayBind = function (arr) { return function (f) { var result = []; for (var i = 0, l = arr.length; i < l; i++) { diff --git a/src/Data/Bounded.js b/src/Data/Bounded.js index 246f8ac8..094350bd 100644 --- a/src/Data/Bounded.js +++ b/src/Data/Bounded.js @@ -1,10 +1,8 @@ -"use strict"; +export const topInt = 2147483647; +export const bottomInt = -2147483648; -exports.topInt = 2147483647; -exports.bottomInt = -2147483648; +export const topChar = String.fromCharCode(65535); +export const bottomChar = String.fromCharCode(0); -exports.topChar = String.fromCharCode(65535); -exports.bottomChar = String.fromCharCode(0); - -exports.topNumber = Number.POSITIVE_INFINITY; -exports.bottomNumber = Number.NEGATIVE_INFINITY; +export const topNumber = Number.POSITIVE_INFINITY; +export const bottomNumber = Number.NEGATIVE_INFINITY; diff --git a/src/Data/Eq.js b/src/Data/Eq.js index 2a2ae3ea..6e8303cb 100644 --- a/src/Data/Eq.js +++ b/src/Data/Eq.js @@ -1,18 +1,16 @@ -"use strict"; - var refEq = function (r1) { return function (r2) { return r1 === r2; }; }; -exports.eqBooleanImpl = refEq; -exports.eqIntImpl = refEq; -exports.eqNumberImpl = refEq; -exports.eqCharImpl = refEq; -exports.eqStringImpl = refEq; +export const eqBooleanImpl = refEq; +export const eqIntImpl = refEq; +export const eqNumberImpl = refEq; +export const eqCharImpl = refEq; +export const eqStringImpl = refEq; -exports.eqArrayImpl = function (f) { +export const eqArrayImpl = function (f) { return function (xs) { return function (ys) { if (xs.length !== ys.length) return false; diff --git a/src/Data/EuclideanRing.js b/src/Data/EuclideanRing.js index a19fe503..057e6c3e 100644 --- a/src/Data/EuclideanRing.js +++ b/src/Data/EuclideanRing.js @@ -1,19 +1,17 @@ -"use strict"; - -exports.intDegree = function (x) { +export const intDegree = function (x) { return Math.min(Math.abs(x), 2147483647); }; // See the Euclidean definition in // https://en.m.wikipedia.org/wiki/Modulo_operation. -exports.intDiv = function (x) { +export const intDiv = function (x) { return function (y) { if (y === 0) return 0; return y > 0 ? Math.floor(x / y) : -Math.floor(x / -y); }; }; -exports.intMod = function (x) { +export const intMod = function (x) { return function (y) { if (y === 0) return 0; var yy = Math.abs(y); @@ -21,7 +19,7 @@ exports.intMod = function (x) { }; }; -exports.numDiv = function (n1) { +export const numDiv = function (n1) { return function (n2) { return n1 / n2; }; diff --git a/src/Data/Functor.js b/src/Data/Functor.js index 73ecc1f5..095e5332 100644 --- a/src/Data/Functor.js +++ b/src/Data/Functor.js @@ -1,6 +1,4 @@ -"use strict"; - -exports.arrayMap = function (f) { +export const arrayMap = function (f) { return function (arr) { var l = arr.length; var result = new Array(l); diff --git a/src/Data/HeytingAlgebra.js b/src/Data/HeytingAlgebra.js index a076fd3f..80990b40 100644 --- a/src/Data/HeytingAlgebra.js +++ b/src/Data/HeytingAlgebra.js @@ -1,17 +1,15 @@ -"use strict"; - -exports.boolConj = function (b1) { +export const boolConj = function (b1) { return function (b2) { return b1 && b2; }; }; -exports.boolDisj = function (b1) { +export const boolDisj = function (b1) { return function (b2) { return b1 || b2; }; }; -exports.boolNot = function (b) { +export const boolNot = function (b) { return !b; }; diff --git a/src/Data/Ord.js b/src/Data/Ord.js index 67c1a058..548760e5 100644 --- a/src/Data/Ord.js +++ b/src/Data/Ord.js @@ -1,5 +1,3 @@ -"use strict"; - var unsafeCompareImpl = function (lt) { return function (eq) { return function (gt) { @@ -12,13 +10,13 @@ var unsafeCompareImpl = function (lt) { }; }; -exports.ordBooleanImpl = unsafeCompareImpl; -exports.ordIntImpl = unsafeCompareImpl; -exports.ordNumberImpl = unsafeCompareImpl; -exports.ordStringImpl = unsafeCompareImpl; -exports.ordCharImpl = unsafeCompareImpl; +export const ordBooleanImpl = unsafeCompareImpl; +export const ordIntImpl = unsafeCompareImpl; +export const ordNumberImpl = unsafeCompareImpl; +export const ordStringImpl = unsafeCompareImpl; +export const ordCharImpl = unsafeCompareImpl; -exports.ordArrayImpl = function (f) { +export const ordArrayImpl = function (f) { return function (xs) { return function (ys) { var i = 0; diff --git a/src/Data/Ring.js b/src/Data/Ring.js index c6b4a329..cceb66c8 100644 --- a/src/Data/Ring.js +++ b/src/Data/Ring.js @@ -1,13 +1,11 @@ -"use strict"; - -exports.intSub = function (x) { +export const intSub = function (x) { return function (y) { /* jshint bitwise: false */ return x - y | 0; }; }; -exports.numSub = function (n1) { +export const numSub = function (n1) { return function (n2) { return n1 - n2; }; diff --git a/src/Data/Semigroup.js b/src/Data/Semigroup.js index f1f1abad..1909f557 100644 --- a/src/Data/Semigroup.js +++ b/src/Data/Semigroup.js @@ -1,12 +1,10 @@ -"use strict"; - -exports.concatString = function (s1) { +export const concatString = function (s1) { return function (s2) { return s1 + s2; }; }; -exports.concatArray = function (xs) { +export const concatArray = function (xs) { return function (ys) { if (xs.length === 0) return ys; if (ys.length === 0) return xs; diff --git a/src/Data/Semiring.js b/src/Data/Semiring.js index 7f38e42e..2d537c18 100644 --- a/src/Data/Semiring.js +++ b/src/Data/Semiring.js @@ -1,26 +1,24 @@ -"use strict"; - -exports.intAdd = function (x) { +export const intAdd = function (x) { return function (y) { /* jshint bitwise: false */ return x + y | 0; }; }; -exports.intMul = function (x) { +export const intMul = function (x) { return function (y) { /* jshint bitwise: false */ return x * y | 0; }; }; -exports.numAdd = function (n1) { +export const numAdd = function (n1) { return function (n2) { return n1 + n2; }; }; -exports.numMul = function (n1) { +export const numMul = function (n1) { return function (n2) { return n1 * n2; }; diff --git a/src/Data/Show.js b/src/Data/Show.js index 4a85cd66..1f7b4038 100644 --- a/src/Data/Show.js +++ b/src/Data/Show.js @@ -1,15 +1,13 @@ -"use strict"; - -exports.showIntImpl = function (n) { +export const showIntImpl = function (n) { return n.toString(); }; -exports.showNumberImpl = function (n) { +export const showNumberImpl = function (n) { var str = n.toString(); return isNaN(str + ".0") ? str : str + ".0"; }; -exports.showCharImpl = function (c) { +export const showCharImpl = function (c) { var code = c.charCodeAt(0); if (code < 0x20 || code === 0x7F) { switch (c) { @@ -26,7 +24,7 @@ exports.showCharImpl = function (c) { return c === "'" || c === "\\" ? "'\\" + c + "'" : "'" + c + "'"; }; -exports.showStringImpl = function (s) { +export const showStringImpl = function (s) { var l = s.length; return "\"" + s.replace( /[\0-\x1F\x7F"\\]/g, // eslint-disable-line no-control-regex @@ -50,7 +48,7 @@ exports.showStringImpl = function (s) { ) + "\""; }; -exports.showArrayImpl = function (f) { +export const showArrayImpl = function (f) { return function (xs) { var ss = []; for (var i = 0, l = xs.length; i < l; i++) { @@ -60,13 +58,13 @@ exports.showArrayImpl = function (f) { }; }; -exports.cons = function (head) { +export const cons = function (head) { return function (tail) { return [head].concat(tail); }; }; -exports.join = function (separator) { +export const join = function (separator) { return function (xs) { return xs.join(separator); }; diff --git a/src/Data/Show/Generic.js b/src/Data/Show/Generic.js index 53338044..59ff681e 100644 --- a/src/Data/Show/Generic.js +++ b/src/Data/Show/Generic.js @@ -1,6 +1,4 @@ -"use strict"; - -exports.intercalate = function (separator) { +export const intercalate = function (separator) { return function (xs) { var len = xs.length; if (len === 0) return ""; diff --git a/src/Data/Symbol.js b/src/Data/Symbol.js index b4b6e28f..b2941408 100644 --- a/src/Data/Symbol.js +++ b/src/Data/Symbol.js @@ -1,8 +1,6 @@ -"use strict"; - // module Data.Symbol -exports.unsafeCoerce = function (arg) { +export const unsafeCoerce = function (arg) { return arg; }; diff --git a/src/Data/Unit.js b/src/Data/Unit.js index 379ba659..3eff8c28 100644 --- a/src/Data/Unit.js +++ b/src/Data/Unit.js @@ -1,3 +1 @@ -"use strict"; - -exports.unit = undefined; +export const unit = undefined; diff --git a/src/Record/Unsafe.js b/src/Record/Unsafe.js index c47acf8d..af2d506f 100644 --- a/src/Record/Unsafe.js +++ b/src/Record/Unsafe.js @@ -1,18 +1,16 @@ -"use strict"; - -exports.unsafeHas = function (label) { +export const unsafeHas = function (label) { return function (rec) { return {}.hasOwnProperty.call(rec, label); }; }; -exports.unsafeGet = function (label) { +export const unsafeGet = function (label) { return function (rec) { return rec[label]; }; }; -exports.unsafeSet = function (label) { +export const unsafeSet = function (label) { return function (value) { return function (rec) { var copy = {}; @@ -27,7 +25,7 @@ exports.unsafeSet = function (label) { }; }; -exports.unsafeDelete = function (label) { +export const unsafeDelete = function (label) { return function (rec) { var copy = {}; for (var key in rec) { diff --git a/test/Test/Main.js b/test/Test/Main.js index f3989122..b25cdaca 100644 --- a/test/Test/Main.js +++ b/test/Test/Main.js @@ -1,6 +1,4 @@ -"use strict"; - -exports.testNumberShow = function(showNumber) { +export function testNumberShow(showNumber) { return function() { function testAll(cases) { cases.forEach(function(c) { @@ -16,29 +14,29 @@ exports.testNumberShow = function(showNumber) { } testAll([ - // Within Int range - [0.0, "0.0"], - [1.0, "1.0"], - [-1.0, "-1.0"], - [500.0, "500.0"], + // Within Int range + [0.0, "0.0"], + [1.0, "1.0"], + [-1.0, "-1.0"], + [500.0, "500.0"], - // Outside Int range - [1e10, "10000000000.0"], - [1e10 + 0.5, "10000000000.5"], - [-1e10, "-10000000000.0"], - [-1e10 - 0.5, "-10000000000.5"], + // Outside Int range + [1e10, "10000000000.0"], + [1e10 + 0.5, "10000000000.5"], + [-1e10, "-10000000000.0"], + [-1e10 - 0.5, "-10000000000.5"], - // With exponent - [1e21, "1e+21"], - [1e-21, "1e-21"], + // With exponent + [1e21, "1e+21"], + [1e-21, "1e-21"], - // With decimal and exponent - [1.5e21, "1.5e+21"], - [1.5e-10, "1.5e-10"], + // With decimal and exponent + [1.5e21, "1.5e+21"], + [1.5e-10, "1.5e-10"], - [NaN, "NaN"], - [Infinity, "Infinity"], - [-Infinity, "-Infinity"], - ]); + [NaN, "NaN"], + [Infinity, "Infinity"], + [-Infinity, "-Infinity"], + ]); }; -}; +} diff --git a/test/Test/Utils.js b/test/Test/Utils.js index bea69b25..ae5b410a 100644 --- a/test/Test/Utils.js +++ b/test/Test/Utils.js @@ -1,7 +1,5 @@ -"use strict"; - -exports.throwErr = function(msg) { +export function throwErr(msg) { return function() { throw new Error(msg); }; -}; +}