@xnoxs/flux-lang 3.5.2 → 4.0.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/CHANGELOG.md +31 -0
- package/README.md +3 -1
- package/dist/flux-cli.js +219 -15
- package/dist/flux.cjs.js +86 -3
- package/dist/flux.esm.js +86 -3
- package/dist/flux.min.js +20 -20
- package/package.json +1 -1
- package/src/self/cli.js +1 -1
- package/src/self/codegen.flux +5 -2
- package/src/self/codegen.js +1 -794
- package/src/self/css-preprocessor.js +1 -1
- package/src/self/lexer.flux +1 -1
- package/src/self/lexer.js +1 -713
- package/src/self/lexer.stage2.js +700 -0
- package/src/self/parser.flux +41 -0
- package/src/self/parser.js +1 -1571
- package/src/self/pkg.flux +107 -10
- package/src/self/pkg.js +108 -2
- package/src/self/test-runner.js +1 -1
- package/src/self/transpiler.flux +14 -4
- package/src/self/transpiler.js +1 -83
- package/src/self/type-checker.flux +12 -0
- package/src/self/type-checker.js +1 -1114
package/dist/flux.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* flux-lang
|
|
2
|
+
* flux-lang v4.0.0
|
|
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
|
|
@@ -35,6 +35,7 @@ var require_lexer = __commonJS({
|
|
|
35
35
|
VAL: "VAL",
|
|
36
36
|
FN: "FN",
|
|
37
37
|
RETURN: "RETURN",
|
|
38
|
+
DECLARE: "DECLARE",
|
|
38
39
|
// Keywords — control flow
|
|
39
40
|
IF: "IF",
|
|
40
41
|
ELSE: "ELSE",
|
|
@@ -171,6 +172,7 @@ var require_lexer = __commonJS({
|
|
|
171
172
|
val: T.VAL,
|
|
172
173
|
fn: T.FN,
|
|
173
174
|
return: T.RETURN,
|
|
175
|
+
declare: T.DECLARE,
|
|
174
176
|
if: T.IF,
|
|
175
177
|
else: T.ELSE,
|
|
176
178
|
for: T.FOR,
|
|
@@ -308,7 +310,17 @@ var require_lexer = __commonJS({
|
|
|
308
310
|
if (this.ch() === "\\") {
|
|
309
311
|
this.adv();
|
|
310
312
|
const e = this.adv();
|
|
311
|
-
|
|
313
|
+
if (e === "u") {
|
|
314
|
+
const hex = this.src.slice(this.pos, this.pos + 4);
|
|
315
|
+
this.pos += 4;
|
|
316
|
+
text += String.fromCharCode(parseInt(hex, 16));
|
|
317
|
+
} else if (e === "x") {
|
|
318
|
+
const hex = this.src.slice(this.pos, this.pos + 2);
|
|
319
|
+
this.pos += 2;
|
|
320
|
+
text += String.fromCharCode(parseInt(hex, 16));
|
|
321
|
+
} else {
|
|
322
|
+
text += { n: "\n", t: " ", r: "\r", '"': '"', "'": "'", "\\": "\\", "{": "{", "}": "}" }[e] || "\\" + e;
|
|
323
|
+
}
|
|
312
324
|
} else if (this.ch() === "{") {
|
|
313
325
|
parts.push({ type: "text", value: text });
|
|
314
326
|
text = "";
|
|
@@ -503,7 +515,17 @@ var require_lexer = __commonJS({
|
|
|
503
515
|
if (this.ch() === "\\") {
|
|
504
516
|
this.adv();
|
|
505
517
|
const e = this.adv();
|
|
506
|
-
|
|
518
|
+
if (e === "u") {
|
|
519
|
+
const hex = this.src.slice(this.pos, this.pos + 4);
|
|
520
|
+
this.pos += 4;
|
|
521
|
+
s += String.fromCharCode(parseInt(hex, 16));
|
|
522
|
+
} else if (e === "x") {
|
|
523
|
+
const hex = this.src.slice(this.pos, this.pos + 2);
|
|
524
|
+
this.pos += 2;
|
|
525
|
+
s += String.fromCharCode(parseInt(hex, 16));
|
|
526
|
+
} else {
|
|
527
|
+
s += { n: "\n", t: " ", r: "\r", "'": "'", "\\": "\\" }[e] || "\\" + e;
|
|
528
|
+
}
|
|
507
529
|
} else {
|
|
508
530
|
s += this.adv();
|
|
509
531
|
}
|
|
@@ -1026,6 +1048,8 @@ var require_parser = __commonJS({
|
|
|
1026
1048
|
if (decorators.length) n.decorators = decorators;
|
|
1027
1049
|
return n;
|
|
1028
1050
|
}
|
|
1051
|
+
case T.DECLARE:
|
|
1052
|
+
return this.parseDeclareDecl();
|
|
1029
1053
|
case T.IF:
|
|
1030
1054
|
return this.parseIf();
|
|
1031
1055
|
case T.FOR:
|
|
@@ -1496,6 +1520,48 @@ var require_parser = __commonJS({
|
|
|
1496
1520
|
}
|
|
1497
1521
|
this.err("Expected -> or : after function signature");
|
|
1498
1522
|
}
|
|
1523
|
+
// ── declare fn/val/var/class ───────────────────────────────────
|
|
1524
|
+
parseDeclareDecl() {
|
|
1525
|
+
const loc = this.eat(T.DECLARE);
|
|
1526
|
+
const tok = this.peek();
|
|
1527
|
+
if (tok.type === T.FN || tok.type === T.ASYNC) {
|
|
1528
|
+
const isAsync = tok.type === T.ASYNC;
|
|
1529
|
+
this.skip();
|
|
1530
|
+
if (isAsync) this.eat(T.FN);
|
|
1531
|
+
const KEYWORD_AS_NAME = /* @__PURE__ */ new Set([T.NEW, T.DELETE, T.FROM, T.AS, T.DEFAULT, T.IS, T.IN, T.TYPE]);
|
|
1532
|
+
const name = this.check(T.IDENT) || KEYWORD_AS_NAME.has(this.peek().type) ? this.skip().value : null;
|
|
1533
|
+
const params = this.parseParamList();
|
|
1534
|
+
let retType = null;
|
|
1535
|
+
if (this.check(T.ARROW)) {
|
|
1536
|
+
this.pos++;
|
|
1537
|
+
retType = this.parseTypeAnn();
|
|
1538
|
+
} else if (this.check(T.COLON)) {
|
|
1539
|
+
this.pos++;
|
|
1540
|
+
retType = this.parseTypeAnn();
|
|
1541
|
+
}
|
|
1542
|
+
this.skipNewlines();
|
|
1543
|
+
const decl = { type: "FnDecl", name, params, retType, body: [], inline: false, async: isAsync, loc: tok };
|
|
1544
|
+
return { type: "DeclareDecl", decl, loc };
|
|
1545
|
+
}
|
|
1546
|
+
if (tok.type === T.VAL || tok.type === T.VAR) {
|
|
1547
|
+
const kind = tok.type === T.VAR ? "var" : "val";
|
|
1548
|
+
this.skip();
|
|
1549
|
+
const name = this.eat(T.IDENT).value;
|
|
1550
|
+
let typeAnn = null;
|
|
1551
|
+
if (this.maybe(T.COLON)) typeAnn = this.parseTypeAnn();
|
|
1552
|
+
this.skipNewlines();
|
|
1553
|
+
const decl = { type: "VarDecl", kind, name, typeAnn, init: null, loc: tok };
|
|
1554
|
+
return { type: "DeclareDecl", decl, loc };
|
|
1555
|
+
}
|
|
1556
|
+
if (tok.type === T.CLASS) {
|
|
1557
|
+
this.skip();
|
|
1558
|
+
const name = this.eat(T.IDENT).value;
|
|
1559
|
+
this.skipNewlines();
|
|
1560
|
+
const decl = { type: "ClassDecl", name, fields: [], methods: [], loc: tok };
|
|
1561
|
+
return { type: "DeclareDecl", decl, loc };
|
|
1562
|
+
}
|
|
1563
|
+
this.err("Expected fn, async fn, val, var, or class after declare");
|
|
1564
|
+
}
|
|
1499
1565
|
// ── async fn ──────────────────────────────────────────────────
|
|
1500
1566
|
parseAsyncFn() {
|
|
1501
1567
|
this.eat(T.ASYNC);
|
|
@@ -2607,6 +2673,9 @@ function _fmt(v, s) {
|
|
|
2607
2673
|
return this.genInterfaceDecl(node);
|
|
2608
2674
|
case "EnumDecl":
|
|
2609
2675
|
return this.genEnumDecl(node);
|
|
2676
|
+
case "DeclareDecl":
|
|
2677
|
+
return;
|
|
2678
|
+
// ambient declaration — no JS output
|
|
2610
2679
|
case "ExprStmt":
|
|
2611
2680
|
return this.emit(this.genExpr(node.expr) + ";");
|
|
2612
2681
|
default:
|
|
@@ -5609,6 +5678,20 @@ var require_type_checker = __commonJS({
|
|
|
5609
5678
|
}
|
|
5610
5679
|
break;
|
|
5611
5680
|
}
|
|
5681
|
+
case "DeclareDecl": {
|
|
5682
|
+
const d = node.decl;
|
|
5683
|
+
if (d.type === "FnDecl") {
|
|
5684
|
+
const retType = d.retType ? parseAnnotation(d.retType) : null;
|
|
5685
|
+
const paramTypes = d.params.map((p) => p.typeAnn ? parseAnnotation(p.typeAnn) : T_UNKNOWN);
|
|
5686
|
+
if (d.name) env.set(d.name, T_FN(paramTypes, retType || T_UNKNOWN));
|
|
5687
|
+
} else if (d.type === "VarDecl") {
|
|
5688
|
+
const t = d.typeAnn ? parseAnnotation(d.typeAnn) : T_UNKNOWN;
|
|
5689
|
+
env.set(d.name, t);
|
|
5690
|
+
} else if (d.type === "ClassDecl") {
|
|
5691
|
+
env.set(d.name, T_NAMED(d.name));
|
|
5692
|
+
}
|
|
5693
|
+
break;
|
|
5694
|
+
}
|
|
5612
5695
|
case "TypeDecl":
|
|
5613
5696
|
for (const v of node.variants) {
|
|
5614
5697
|
if (v.fields.length === 0) env.set(v.name, T_NAMED(node.name));
|