UNPKG

functionalscript

Version:

FunctionalScript is a purely functional subset of JavaScript

75 lines (74 loc) 2.77 kB
import { sort } from "../../types/object/module.f.js"; import { setReplace } from "../../types/ordered_map/module.f.js"; import { transpile } from "./module.f.js"; import { stringifyAsTree } from "../serializer/module.f.js"; import { createVirtualIo } from "../../io/virtual/module.f.js"; const virtualFs = map => { return createVirtualIo(map).fs; }; export default { parse: () => { const map = setReplace('a')('export default 1')(null); const fs = virtualFs(map); const result = transpile(fs)('a'); if (result[0] === 'error') { throw result[1]; } const s = stringifyAsTree(sort)(result[1]); if (s !== '1') { throw s; } }, parseWithSubModule: () => { const map = setReplace('a/b')('import c from "c"\nexport default c')(null); const map2 = setReplace('a/c')('export default 2')(map); const fs = virtualFs(map2); const result = transpile(fs)('a/b'); if (result[0] === 'error') { throw result[1]; } const s = stringifyAsTree(sort)(result[1]); if (s !== '2') { throw s; } }, parseWithSubModules: () => { const map = setReplace('a')('import b from "b"\nimport c from "c"\nexport default [b,c,b]')(null); const map2 = setReplace('b')('import d from "d"\nexport default [0,d]')(map); const map3 = setReplace('c')('import d from "d"\nexport default [1,d]')(map2); const map4 = setReplace('d')('export default 2')(map3); const fs = virtualFs(map4); const result = transpile(fs)('a'); if (result[0] === 'error') { throw result[1]; } const s = stringifyAsTree(sort)(result[1]); if (s !== '[[0,2],[1,2],[0,2]]') { throw s; } }, parseWithFileNotFoundError: () => { const map = setReplace('a')('import b from "b"\nexport default b')(null); const fs = virtualFs(map); const result = transpile(fs)('a'); if (result[0] !== 'error') { throw result; } if (result[1].message !== 'file not found') { throw result; } }, parseWithCycleError: () => { const map = setReplace('a')('import b from "b"\nimport c from "c"\nexport default [b,c,b]')(null); const map2 = setReplace('b')('import c from "c"\nexport default c')(map); const map3 = setReplace('c')('import b from "b"\nexport default b')(map2); const fs = virtualFs(map3); const result = transpile(fs)('a'); if (result[0] !== 'error') { throw result; } if (result[1].message !== 'circular dependency') { throw result; } }, };