@xnoxs/flux-lang 3.4.0 → 3.4.1

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/dist/flux-cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /*!
3
- * flux-lang v3.4.0
3
+ * flux-lang v3.4.1
4
4
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
5
5
  * (c) 2026 Flux Lang Contributors
6
6
  * Released under the MIT License
@@ -7203,7 +7203,7 @@ var require_package = __commonJS({
7203
7203
  "package.json"(exports2, module2) {
7204
7204
  module2.exports = {
7205
7205
  name: "@xnoxs/flux-lang",
7206
- version: "3.4.0",
7206
+ version: "3.4.1",
7207
7207
  description: "Flux \u2014 A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.",
7208
7208
  main: "dist/flux.cjs.js",
7209
7209
  module: "dist/flux.esm.js",
@@ -8643,136 +8643,258 @@ function cmdInit(name) {
8643
8643
  const projectName = name || "my-flux-app";
8644
8644
  const dir = path.resolve(projectName);
8645
8645
  if (fs.existsSync(dir)) {
8646
- console.error(clr(C.red, `[Error] Directory already exists: ${projectName}`));
8646
+ console.error(clr(C.red, `\u2717 Directory already exists: ${projectName}`));
8647
8647
  process.exit(1);
8648
8648
  }
8649
8649
  fs.mkdirSync(dir, { recursive: true });
8650
8650
  fs.mkdirSync(path.join(dir, "src"), { recursive: true });
8651
- fs.writeFileSync(path.join(dir, "src", "main.flux"), [
8652
- "// Welcome to Flux Lang v2.0!",
8653
- "",
8654
- "// --- Basic ---",
8655
- 'val greeting = "Hello, Flux!"',
8656
- "print(greeting)",
8657
- "",
8658
- "// --- Async / Await ---",
8659
- "async fn fetchData(url):",
8660
- " try:",
8661
- " val res = await fetch(url)",
8662
- " val data = await res.json()",
8663
- " return data",
8664
- " catch(e):",
8665
- ' print("Fetch error:", e.message)',
8666
- " return null",
8667
- "",
8668
- "// --- Destructuring ---",
8669
- 'val person = { name: "Budi", age: 25, city: "Jakarta" }',
8670
- "val { name, age } = person",
8671
- 'print("Name: {name}, Age: {age}")',
8672
- "",
8673
- "// --- Optional chaining & nullish coalescing ---",
8674
- "val user = null",
8675
- 'val displayName = user?.name ?? "Anonymous"',
8676
- 'print("User:", displayName)',
8677
- "",
8678
- "// --- Spread ---",
8679
- "val nums = [1, 2, 3]",
8680
- "val more = [...nums, 4, 5, 6]",
8681
- 'print("Numbers:", more)',
8682
- "",
8683
- "// --- Rest params ---",
8684
- "fn sum(...args):",
8685
- " return args.reduce((acc, x) -> acc + x, 0)",
8686
- "",
8687
- 'print("Sum:", sum(1, 2, 3, 4, 5))',
8688
- "",
8689
- "// --- Default params ---",
8690
- 'fn greet(name = "World") -> "Hello, {name}!"',
8691
- "print(greet())",
8692
- 'print(greet("Flux"))',
8693
- "",
8694
- "// --- Error handling ---",
8695
- "fn divide(a, b):",
8696
- " if b == 0:",
8697
- ' throw new Error("Division by zero")',
8698
- " return a / b",
8699
- "",
8700
- "try:",
8701
- " print(divide(10, 2))",
8702
- " print(divide(10, 0))",
8703
- "catch(e):",
8704
- ' print("Error:", e.message)',
8705
- "finally:",
8706
- ' print("Done.")',
8707
- ""
8708
- ].join("\n"), "utf8");
8709
- fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify({
8651
+ fs.mkdirSync(path.join(dir, "tests"), { recursive: true });
8652
+ fs.writeFileSync(path.join(dir, "src", "main.flux"), `// ${projectName} \u2014 built with Flux Lang v${VERSION}
8653
+ // Run: flux run src/main.flux
8654
+
8655
+ // \u2500\u2500 Algebraic Data Types + Pattern Matching \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8656
+ type Shape = Circle(radius) | Rect(width, height) | Triangle(base, height)
8657
+
8658
+ fn area(shape):
8659
+ match shape:
8660
+ when Circle(r): return Math.PI * r * r
8661
+ when Rect(w, h): return w * h
8662
+ when Triangle(b, h): return 0.5 * b * h
8663
+
8664
+ fn describe(shape):
8665
+ match shape:
8666
+ when Circle(r): return "Circle(r={r:.2f})"
8667
+ when Rect(w, h): return "Rect({w:.1f}x{h:.1f})"
8668
+ when Triangle(b, h): return "Triangle(b={b:.1f}, h={h:.1f})"
8669
+
8670
+ // \u2500\u2500 Result type \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8671
+ type Result = Ok(value) | Err(message)
8672
+
8673
+ fn safeDivide(a, b):
8674
+ if b == 0: return Err("division by zero")
8675
+ return Ok(a / b)
8676
+
8677
+ // \u2500\u2500 Utility functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8678
+ fn greet(name): return "Hello from Flux, {name}!"
8679
+
8680
+ fn formatList(items):
8681
+ if items.length == 0: return "(empty)"
8682
+ return "[" + items.join(", ") + "]"
8683
+
8684
+ fn clamp(value, lo, hi):
8685
+ if value < lo: return lo
8686
+ if value > hi: return hi
8687
+ return value
8688
+
8689
+ // \u2500\u2500 Pipe operator + stdlib \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8690
+ val numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
8691
+ val processed = numbers
8692
+ |> filter(n -> n > 3)
8693
+ |> map(n -> n * n)
8694
+ |> sort
8695
+
8696
+ // \u2500\u2500 Main \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8697
+ print(greet("${projectName}"))
8698
+ print("Squares > 3: {formatList(processed)}")
8699
+ print("clamp(12, 0, 10) = {clamp(12, 0, 10)}")
8700
+
8701
+ val shapes = [Circle(5.0), Rect(8.0, 3.0), Triangle(6.0, 4.0)]
8702
+ for shape in shapes:
8703
+ val a = area(shape)
8704
+ print("{describe(shape)} area={a:.2f}")
8705
+
8706
+ match safeDivide(10.0, 3.0):
8707
+ when Ok(v): print("10 / 3 = {v:.4f}")
8708
+ when Err(e): print("Error: {e}")
8709
+ `, "utf8");
8710
+ fs.writeFileSync(path.join(dir, "src", "utils.flux"), `// Utility functions for ${projectName}
8711
+ // Use with: flux bundle src/main.flux (bundles imports automatically)
8712
+
8713
+ export fn greet(name):
8714
+ return "\u26A1 Hello from Flux, {name}!"
8715
+
8716
+ export fn formatList(items):
8717
+ if items.length == 0: return "(empty)"
8718
+ return "[" + items.join(", ") + "]"
8719
+
8720
+ export fn clamp(value, lo, hi):
8721
+ if value < lo: return lo
8722
+ if value > hi: return hi
8723
+ return value
8724
+
8725
+ export fn sum(nums):
8726
+ return nums.reduce((acc, x) -> acc + x, 0)
8727
+
8728
+ export fn average(nums):
8729
+ if nums.length == 0: return 0
8730
+ return sum(nums) / nums.length
8731
+ `, "utf8");
8732
+ fs.writeFileSync(path.join(dir, "tests", "main.test.flux"), `// Tests for ${projectName}
8733
+ // Run: flux test tests/
8734
+
8735
+ // \u2500\u2500 Functions under test \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8736
+ fn add(a, b):
8737
+ return a + b
8738
+
8739
+ fn mul(a, b):
8740
+ return a * b
8741
+
8742
+ fn clamp(value, lo, hi):
8743
+ if value < lo: return lo
8744
+ if value > hi: return hi
8745
+ return value
8746
+
8747
+ fn average(nums):
8748
+ if nums.length == 0: return 0
8749
+ return nums.reduce((s, x) -> s + x, 0) / nums.length
8750
+
8751
+ type Result = Ok(value) | Err(message)
8752
+
8753
+ fn safeDivide(a, b):
8754
+ if b == 0: return Err("div by zero")
8755
+ return Ok(a / b)
8756
+
8757
+ // \u2500\u2500 Test functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8758
+ fn test_add():
8759
+ assert(add(1, 2) == 3, "1+2=3")
8760
+ assert(add(0, 0) == 0, "0+0=0")
8761
+ assert(add(-1, 1) == 0, "-1+1=0")
8762
+
8763
+ fn test_mul():
8764
+ assert(mul(3, 4) == 12, "3*4=12")
8765
+ assert(mul(0, 5) == 0, "0*5=0")
8766
+
8767
+ fn test_clamp():
8768
+ assert(clamp(5, 0, 10) == 5, "within range")
8769
+ assert(clamp(-1, 0, 10) == 0, "below min")
8770
+ assert(clamp(15, 0, 10) == 10, "above max")
8771
+
8772
+ fn test_average():
8773
+ assert(average([2, 4, 6]) == 4, "average of 2,4,6")
8774
+ assert(average([]) == 0, "empty list")
8775
+
8776
+ fn test_safe_divide():
8777
+ val ok = safeDivide(10, 2)
8778
+ match ok:
8779
+ when Ok(v): assert(v == 5, "10/2=5")
8780
+ when Err(e): assert(false, "unexpected error")
8781
+ val err = safeDivide(10, 0)
8782
+ match err:
8783
+ when Ok(v): assert(false, "expected error")
8784
+ when Err(e): assert(e == "div by zero", "error message")
8785
+
8786
+ fn test_pipe_operator():
8787
+ val result = [1, 2, 3, 4, 5] |> filter(n -> n > 2) |> map(n -> n * 2)
8788
+ assert(result.length == 3, "filter length")
8789
+ assert(result[0] == 6, "first element")
8790
+ assert(result[2] == 10, "last element")
8791
+ `, "utf8");
8792
+ const fluxJson = {
8710
8793
  name: projectName,
8711
8794
  version: "1.0.0",
8712
- description: `A Flux Lang project`,
8795
+ description: `A Flux Lang v${VERSION} project`,
8796
+ author: "",
8797
+ license: "MIT",
8798
+ entry: "src/main.flux",
8799
+ outDir: "dist",
8800
+ sourcemap: false,
8801
+ typecheck: true,
8713
8802
  scripts: {
8714
- start: `flux run src/main.flux`,
8715
- build: `flux bundle src/main.flux -o dist/bundle.js`,
8716
- dev: `flux watch src/main.flux`,
8717
- check: `flux check src/main.flux`
8803
+ start: "flux run src/main.flux",
8804
+ build: "flux bundle src/main.flux -o dist/bundle.js",
8805
+ dev: "flux watch src/main.flux",
8806
+ check: "flux check src/main.flux",
8807
+ test: "flux test tests/",
8808
+ fmt: "flux fmt src/",
8809
+ lint: "flux lint src/"
8718
8810
  },
8719
8811
  dependencies: {},
8720
- devDependencies: { "flux-lang": `^${VERSION}` }
8721
- }, null, 2), "utf8");
8722
- fs.writeFileSync(path.join(dir, "flux.config.js"), [
8723
- "// Flux Lang project configuration",
8724
- "// All options are optional \u2014 CLI flags always override these values.",
8725
- "module.exports = {",
8726
- " // jsxTarget : 'browser', // 'browser' | 'server' | 'react'",
8727
- " // outDir : './dist', // output directory for compiled files",
8728
- " // sourcemap : false, // generate .js.map files",
8729
- " // mangle : true, // obfuscate names in output",
8730
- " // ignore : [], // glob patterns to skip in `flux test`",
8731
- " // entry : 'src/main.flux', // default entry for `flux bundle`",
8732
- "};"
8733
- ].join("\n"), "utf8");
8812
+ devDependencies: { "@xnoxs/flux-lang": `^${VERSION}` }
8813
+ };
8814
+ fs.writeFileSync(path.join(dir, "flux.json"), JSON.stringify(fluxJson, null, 2) + "\n", "utf8");
8734
8815
  fs.writeFileSync(path.join(dir, ".gitignore"), [
8735
8816
  "node_modules/",
8736
8817
  "dist/",
8818
+ "flux_modules/",
8737
8819
  "*.js.map",
8738
- ".DS_Store"
8739
- ].join("\n"), "utf8");
8740
- fs.writeFileSync(path.join(dir, "README.md"), [
8741
- `# ${projectName}`,
8742
- "",
8743
- "A project built with [Flux Lang](https://github.com/flux-lang/flux-lang) v2.",
8744
- "",
8745
- "## Getting Started",
8746
- "",
8747
- "```bash",
8748
- "npm install",
8749
- "flux run src/main.flux",
8750
- "```",
8751
- "",
8752
- "## Commands",
8753
- "",
8754
- "| Command | Description |",
8755
- "|---|---|",
8756
- "| `npm start` | Run main.flux |",
8757
- "| `npm run build` | Bundle to dist/ |",
8758
- "| `npm run dev` | Watch mode |",
8759
- "| `npm run check` | Check syntax |",
8820
+ ".DS_Store",
8760
8821
  ""
8761
8822
  ].join("\n"), "utf8");
8823
+ fs.writeFileSync(path.join(dir, "README.md"), `# ${projectName}
8824
+
8825
+ A project built with [Flux Lang](https://flux-lang.dev) v${VERSION} \u2014 the self-hosted compiler written in Flux itself.
8826
+
8827
+ ## Quick Start
8828
+
8829
+ \`\`\`bash
8830
+ flux run src/main.flux
8831
+ \`\`\`
8832
+
8833
+ ## Project Structure
8834
+
8835
+ \`\`\`
8836
+ ${projectName}/
8837
+ \u251C\u2500\u2500 src/
8838
+ \u2502 \u251C\u2500\u2500 main.flux # Entry point
8839
+ \u2502 \u2514\u2500\u2500 utils.flux # Utility functions
8840
+ \u251C\u2500\u2500 tests/
8841
+ \u2502 \u2514\u2500\u2500 main.test.flux # Test suite
8842
+ \u251C\u2500\u2500 flux.json # Project config
8843
+ \u2514\u2500\u2500 README.md
8844
+ \`\`\`
8845
+
8846
+ ## Commands
8847
+
8848
+ | Command | Description |
8849
+ |---|---|
8850
+ | \`flux run src/main.flux\` | Run the project |
8851
+ | \`flux bundle src/main.flux -o dist/bundle.js\` | Bundle to single file |
8852
+ | \`flux watch src/main.flux\` | Watch mode \u2014 auto-recompile |
8853
+ | \`flux check src/main.flux\` | Type check + static analysis |
8854
+ | \`flux test tests/\` | Run all tests |
8855
+ | \`flux fmt src/\` | Format source code |
8856
+ | \`flux lint src/\` | Lint for issues |
8857
+ | \`flux add <package>\` | Add a dependency |
8858
+
8859
+ ## flux.json Reference
8860
+
8861
+ \`\`\`json
8862
+ {
8863
+ "entry": "src/main.flux", // default entry for flux bundle
8864
+ "outDir": "dist", // output directory
8865
+ "sourcemap": false, // generate .js.map files
8866
+ "typecheck": true, // run type checker on compile
8867
+ "scripts": { ... } // runnable with: flux run <name>
8868
+ }
8869
+ \`\`\`
8870
+
8871
+ ## Learn More
8872
+
8873
+ - [Flux Docs](https://flux-lang.dev/docs)
8874
+ - [Playground](https://flux-lang.dev/playground)
8875
+ - [Self-Hosted Compiler](https://flux-lang.dev/self-hosted)
8876
+ - [npm package](https://www.npmjs.com/package/@xnoxs/flux-lang)
8877
+ `, "utf8");
8878
+ const files = [
8879
+ `${projectName}/src/main.flux`,
8880
+ `${projectName}/src/utils.flux`,
8881
+ `${projectName}/tests/main.test.flux`,
8882
+ `${projectName}/flux.json`,
8883
+ `${projectName}/.gitignore`,
8884
+ `${projectName}/README.md`
8885
+ ];
8762
8886
  console.log();
8763
- console.log(clr(C.green, `\u2713 Project created: ${projectName}/`));
8887
+ console.log(clr(C.green, `\u2713 Created: `) + clr(C.bold, `${projectName}/`));
8764
8888
  console.log();
8765
- console.log(clr(C.gray, " Files created:"));
8766
- console.log(" " + clr(C.cyan, `${projectName}/src/main.flux`));
8767
- console.log(" " + clr(C.cyan, `${projectName}/flux.config.js`));
8768
- console.log(" " + clr(C.cyan, `${projectName}/package.json`));
8769
- console.log(" " + clr(C.cyan, `${projectName}/.gitignore`));
8770
- console.log(" " + clr(C.cyan, `${projectName}/README.md`));
8889
+ console.log(clr(C.gray, " Files:"));
8890
+ for (const f of files) console.log(" " + clr(C.cyan, f));
8771
8891
  console.log();
8772
8892
  console.log(clr(C.bold, " Next steps:"));
8773
8893
  console.log(` ${clr(C.yellow, `cd ${projectName}`)}`);
8774
- console.log(` ${clr(C.yellow, "npm install")}`);
8775
- console.log(` ${clr(C.yellow, "flux run src/main.flux")}`);
8894
+ console.log(` ${clr(C.yellow, `flux run src/main.flux`)}`);
8895
+ console.log();
8896
+ console.log(clr(C.gray, ` Or run the test suite:`));
8897
+ console.log(` ${clr(C.yellow, `flux test tests/`)}`);
8776
8898
  console.log();
8777
8899
  }
8778
8900
  function cmdCompile(filePath, opts) {
package/dist/flux.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * flux-lang v3.4.0
2
+ * flux-lang v3.4.1
3
3
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
4
4
  * (c) 2026 Flux Lang Contributors
5
5
  * Released under the MIT License
package/dist/flux.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * flux-lang v3.4.0
2
+ * flux-lang v3.4.1
3
3
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
4
4
  * (c) 2026 Flux Lang Contributors
5
5
  * Released under the MIT License
package/dist/flux.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * flux-lang v3.4.0
2
+ * flux-lang v3.4.1
3
3
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
4
4
  * (c) 2026 Flux Lang Contributors
5
5
  * Released under the MIT License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xnoxs/flux-lang",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.",
5
5
  "main": "dist/flux.cjs.js",
6
6
  "module": "dist/flux.esm.js",