functionalscript
Version:
FunctionalScript is a purely functional subset of JavaScript
81 lines (80 loc) • 2.09 kB
JavaScript
import { init } from "./module.f.js";
import { one } from "../text/ascii/module.f.js";
import { stringify } from "../json/module.f.js";
const s = stringify(i => i);
const f = v => {
const n = one(v);
return s(init(n)[0]);
};
// this doesn't change a name of the function
const fn = (f, name) => ({ [name]: f }[name]);
const withName = (name) =>
// translated into one command: define a `function [name]() { return undefined }`
Object.getOwnPropertyDescriptor({ [name]: () => undefined }, name).value;
export default {
a: () => {
const x = f('1');
if (x !== '["1"]') {
throw x;
}
},
fn: () => {
const o = {
["hello world!"]: () => undefined
};
const f = o["hello world!"];
const { name } = f;
if (name !== "hello world!") {
throw name;
}
//
const f1 = { ["boring"]: () => undefined }["boring"];
if (f1.name !== "boring") {
throw f1.name;
}
//
const x = fn(() => undefined, "hello").name;
if (x !== "") {
throw x;
}
//
const m = withName("boring2").name;
if (m !== "boring2") {
throw m;
}
//
const a = function x() { return undefined; };
if (a.name !== "x") {
throw a.name;
}
},
//
f1: () => {
const m1 = () => undefined;
if (m1.name !== "m1") {
throw m1.name;
}
},
//
f2: () => {
const m11 = (() => undefined);
if (m11.name !== "m11") {
throw m11.name;
}
},
//
f3: () => {
const m2 = true ? () => undefined : () => undefined;
// for `bun` it is `m2`:
// if (m2.name !== "") { throw m2.name }
// see also https://github.com/oven-sh/bun/issues/20398
},
f4: () => {
const id = (i) => i;
const f = id(() => undefined);
// for `bun` it is `m2`:
if (f.name !== "") {
throw f.name;
}
}
};