functionalscript 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/djs/module.f.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Io } from '../io/module.f.ts';
1
2
  import type { Primitive as JsonPrimitive } from '../json/module.f.ts';
2
3
  export type Object = {
3
4
  readonly [k in string]: Unknown;
@@ -5,3 +6,4 @@ export type Object = {
5
6
  export type Array = readonly Unknown[];
6
7
  export type Primitive = JsonPrimitive | bigint | undefined;
7
8
  export type Unknown = Primitive | Object | Array;
9
+ export declare const run: ({ console: { error }, fs, process: { argv } }: Io) => void;
package/djs/module.f.js CHANGED
@@ -1 +1,25 @@
1
- export {};
1
+ import { transpile } from "./transpiler/module.f.js";
2
+ import { stringify } from "./serializer/module.f.js";
3
+ import { sort } from "../types/object/module.f.js";
4
+ const stringifyUnknown = stringify(sort);
5
+ export const run = ({ console: { error }, fs, process: { argv } }) => {
6
+ const args = argv.slice(2);
7
+ if (args.length < 2) {
8
+ error('Error: Requires 2 or more arguments');
9
+ return;
10
+ }
11
+ const inputFileName = args[0];
12
+ const outputFileName = args[1];
13
+ const result = transpile(fs)(inputFileName);
14
+ switch (result[0]) {
15
+ case 'ok': {
16
+ const output = stringifyUnknown(result[1]);
17
+ fs.writeFileSync(outputFileName, output);
18
+ break;
19
+ }
20
+ case 'error': {
21
+ error(`Parse error: ${result[1]}`);
22
+ break;
23
+ }
24
+ }
25
+ };
@@ -15,7 +15,8 @@ const mapDjs = context => path => {
15
15
  };
16
16
  const transpileWithImports = path => parseModuleResult => context => {
17
17
  if (parseModuleResult[0] === 'ok') {
18
- const pathsCombine = listMap(pathConcat(path))(parseModuleResult[1][0]);
18
+ const dir = pathConcat(path)('..');
19
+ const pathsCombine = listMap(pathConcat(dir))(parseModuleResult[1][0]);
19
20
  const contextWithImports = fold(foldNextModuleOp)({ ...context, stack: { first: path, tail: context.stack } })(pathsCombine);
20
21
  if (contextWithImports.error !== null) {
21
22
  return contextWithImports;
@@ -20,10 +20,10 @@ export default {
20
20
  }
21
21
  },
22
22
  parseWithSubModule: () => {
23
- const map = setReplace('a')('import b from "b"\nexport default b')(null);
24
- const map2 = setReplace('a/b')('export default 2')(map);
23
+ const map = setReplace('a/b')('import c from "c"\nexport default c')(null);
24
+ const map2 = setReplace('a/c')('export default 2')(map);
25
25
  const fs = virtualFs(map2);
26
- const result = transpile(fs)('a');
26
+ const result = transpile(fs)('a/b');
27
27
  if (result[0] === 'error') {
28
28
  throw result[1];
29
29
  }
@@ -34,9 +34,9 @@ export default {
34
34
  },
35
35
  parseWithSubModules: () => {
36
36
  const map = setReplace('a')('import b from "b"\nimport c from "c"\nexport default [b,c,b]')(null);
37
- const map2 = setReplace('a/b')('import d from "../d"\nexport default [0,d]')(map);
38
- const map3 = setReplace('a/c')('import d from "../d"\nexport default [1,d]')(map2);
39
- const map4 = setReplace('a/d')('export default 2')(map3);
37
+ const map2 = setReplace('b')('import d from "d"\nexport default [0,d]')(map);
38
+ const map3 = setReplace('c')('import d from "d"\nexport default [1,d]')(map2);
39
+ const map4 = setReplace('d')('export default 2')(map3);
40
40
  const fs = virtualFs(map4);
41
41
  const result = transpile(fs)('a');
42
42
  if (result[0] === 'error') {
@@ -60,8 +60,8 @@ export default {
60
60
  },
61
61
  parseWithCycleError: () => {
62
62
  const map = setReplace('a')('import b from "b"\nimport c from "c"\nexport default [b,c,b]')(null);
63
- const map2 = setReplace('a/b')('import c from "../c"\nexport default c')(map);
64
- const map3 = setReplace('a/c')('import b from "../b"\nexport default b')(map2);
63
+ const map2 = setReplace('b')('import c from "c"\nexport default c')(map);
64
+ const map3 = setReplace('c')('import b from "b"\nexport default b')(map2);
65
65
  const fs = virtualFs(map3);
66
66
  const result = transpile(fs)('a');
67
67
  if (result[0] !== 'error') {
package/fsc.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import io from "./io/node-io.js";
3
+ import { run } from "./djs/module.f.js";
4
+ run(io);
package/io/module.f.d.ts CHANGED
@@ -5,8 +5,13 @@ export type Fs = {
5
5
  };
6
6
  export type Console = {
7
7
  readonly log: (...d: unknown[]) => void;
8
+ readonly error: (...d: unknown[]) => void;
8
9
  };
9
10
  export type Io = {
10
11
  readonly console: Console;
11
12
  readonly fs: Fs;
13
+ readonly process: Process;
14
+ };
15
+ export type Process = {
16
+ readonly argv: string[];
12
17
  };
package/io/node-io.js ADDED
@@ -0,0 +1,7 @@
1
+ import fs from 'node:fs';
2
+ import process from "node:process";
3
+ export default {
4
+ console,
5
+ fs,
6
+ process
7
+ };
@@ -1,10 +1,14 @@
1
1
  import { at } from "../types/map/module.f.js";
2
2
  export const createVirtualIo = (files) => ({
3
3
  console: {
4
- log: (..._d) => { }
4
+ log: (..._d) => { },
5
+ error: (..._d) => { }
5
6
  },
6
7
  fs: {
7
8
  writeFileSync: (_file, _data) => { },
8
9
  readFileSync: (path, _options) => { return at(path)(files); }
10
+ },
11
+ process: {
12
+ argv: []
9
13
  }
10
14
  });
package/package.json CHANGED
@@ -1,23 +1,30 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "files": [
6
+ "fsc.js",
7
+ "io/node-io.js",
6
8
  "**/*.f.d.ts",
7
9
  "**/*.f.js"
8
10
  ],
9
11
  "description": "FunctionalScript is a functional subset of JavaScript",
10
12
  "scripts": {
11
13
  "tsc-emit": "tsc --NoEmit false",
14
+ "n": "node --frozen-intrinsics --trace-uncaught",
12
15
  "prepack": "npm run tsc-emit",
13
- "test20": "npm run prepack && node --trace-uncaught ./dev/test.js",
14
- "test22": "tsc && node --experimental-strip-types --trace-uncaught ./dev/test.ts",
15
- "test": "tsc && node --trace-uncaught ./dev/test.ts",
16
- "index": "node ./dev/index.ts",
17
- "version": "node ./nodejs/version/main.ts",
18
- "fsc": "node ./main.ts",
16
+ "git-clean": "git clean -xf",
17
+ "test20": "npm run tsc-emit && npm run n ./dev/test.js",
18
+ "test22": "tsc && npm run n -- --experimental-strip-types ./dev/test.ts",
19
+ "test": "tsc && npm run n ./dev/test.ts",
20
+ "index": "npm run n ./dev/index.ts",
21
+ "version": "npm run n ./nodejs/version/main.ts",
22
+ "fsc": "npm run n ./fsc.ts",
19
23
  "update": "npm run version && npm run index && npm install"
20
24
  },
25
+ "bin": {
26
+ "fsc": "fsc.js"
27
+ },
21
28
  "repository": {
22
29
  "type": "git",
23
30
  "url": "git+https://github.com/functionalscript/functionalscript.git"
@@ -38,7 +45,7 @@
38
45
  },
39
46
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
40
47
  "devDependencies": {
41
- "@types/node": "^22.13.4",
42
- "typescript": "^5.7.3"
48
+ "@types/node": "^22.13.10",
49
+ "typescript": "^5.8.2"
43
50
  }
44
51
  }
package/path/module.f.js CHANGED
@@ -1,4 +1,3 @@
1
- import {} from "../types/function/operator/module.f.js";
2
1
  import { fold, last, take, length, concat as listConcat } from "../types/list/module.f.js";
3
2
  import { join } from "../types/string/module.f.js";
4
3
  import { concat as stringConcat } from "../types/string/module.f.js";
@@ -13,10 +12,8 @@ const foldNormalizeOp = input => state => {
13
12
  case '..': {
14
13
  return listConcat(state)([input]);
15
14
  }
16
- default: {
17
- return take(length(state) - 1)(state);
18
- }
19
15
  }
16
+ return take(length(state) - 1)(state);
20
17
  }
21
18
  default: {
22
19
  return listConcat(state)([input]);
@@ -24,7 +21,7 @@ const foldNormalizeOp = input => state => {
24
21
  }
25
22
  };
26
23
  export const normalize = path => {
27
- const split = path.split('/');
24
+ const split = path.replaceAll('\\', '/').split('/');
28
25
  const foldResult = fold(foldNormalizeOp)([])(split);
29
26
  return join('/')(foldResult);
30
27
  };