rip-lang 3.13.52 → 3.13.53

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rip-lang",
3
- "version": "3.13.52",
3
+ "version": "3.13.53",
4
4
  "description": "A modern language that compiles to JavaScript",
5
5
  "type": "module",
6
6
  "main": "src/compiler.js",
package/src/compiler.js CHANGED
@@ -237,6 +237,8 @@ export class CodeGenerator {
237
237
  // Components
238
238
  'component': 'generateComponent',
239
239
  'render': 'generateRender',
240
+ 'offer': 'generateOffer',
241
+ 'accept': 'generateAccept',
240
242
 
241
243
  // Types
242
244
  'enum': 'generateEnum',
package/src/components.js CHANGED
@@ -610,16 +610,33 @@ export function installComponentSupport(CodeGenerator, Lexer) {
610
610
  const methods = [];
611
611
  const lifecycleHooks = [];
612
612
  const effects = [];
613
+ const offeredVars = [];
614
+ const acceptedVars = [];
613
615
  let renderBlock = null;
614
616
 
615
617
  const memberNames = new Set();
616
618
  const reactiveMembers = new Set();
617
619
 
618
- for (const stmt of statements) {
620
+ for (let stmt of statements) {
619
621
  if (!Array.isArray(stmt)) continue;
620
- const [op] = stmt;
622
+ let [op] = stmt;
623
+
624
+ if (op === 'offer') {
625
+ stmt = stmt[1];
626
+ if (!Array.isArray(stmt)) continue;
627
+ op = stmt[0];
628
+ const varName = getMemberName(stmt[1]);
629
+ if (varName) offeredVars.push(varName);
630
+ }
621
631
 
622
- if (op === 'state') {
632
+ if (op === 'accept') {
633
+ const varName = typeof stmt[1] === 'string' ? stmt[1] : getMemberName(stmt[1]);
634
+ if (varName) {
635
+ acceptedVars.push(varName);
636
+ memberNames.add(varName);
637
+ reactiveMembers.add(varName);
638
+ }
639
+ } else if (op === 'state') {
623
640
  const varName = getMemberName(stmt[1]);
624
641
  if (varName) {
625
642
  stateVars.push({ name: varName, value: stmt[2], isPublic: isPublicProp(stmt[1]) });
@@ -707,6 +724,11 @@ export function installComponentSupport(CodeGenerator, Lexer) {
707
724
  : ` this.${name} = ${val};`);
708
725
  }
709
726
 
727
+ // Accepted vars (from ancestor context via getContext)
728
+ for (const name of acceptedVars) {
729
+ lines.push(` this.${name} = getContext('${name}');`);
730
+ }
731
+
710
732
  // State variables (__state handles signal passthrough)
711
733
  for (const { name, value, isPublic } of stateVars) {
712
734
  const val = this.generateInComponent(value, 'value');
@@ -727,6 +749,11 @@ export function installComponentSupport(CodeGenerator, Lexer) {
727
749
  }
728
750
  }
729
751
 
752
+ // Offered vars (share with descendants via setContext — after all members are initialized)
753
+ for (const name of offeredVars) {
754
+ lines.push(` setContext('${name}', this.${name});`);
755
+ }
756
+
730
757
  // Effects
731
758
  for (const effect of effects) {
732
759
  const effectBody = effect[2];
@@ -831,6 +858,14 @@ export function installComponentSupport(CodeGenerator, Lexer) {
831
858
  throw new Error('render blocks can only be used inside a component');
832
859
  };
833
860
 
861
+ proto.generateOffer = function(head, rest, context, sexpr) {
862
+ throw new Error('offer can only be used inside a component');
863
+ };
864
+
865
+ proto.generateAccept = function(head, rest, context, sexpr) {
866
+ throw new Error('accept can only be used inside a component');
867
+ };
868
+
834
869
  // ==========================================================================
835
870
  // Render Tree Emission
836
871
  // ==========================================================================
@@ -743,6 +743,8 @@ grammar =
743
743
  o 'Expression'
744
744
  o 'ExpressionLine'
745
745
  o 'Statement'
746
+ o 'OFFER Expression', '["offer", 2]'
747
+ o 'ACCEPT IDENTIFIER', '["accept", 2]'
746
748
  ]
747
749
 
748
750
  # Render block: template DSL for fine-grained reactive DOM.
@@ -940,7 +942,7 @@ operators = """
940
942
  right YIELD
941
943
  right = : COMPOUND_ASSIGN RETURN THROW EXTENDS
942
944
  right FORIN FOROF FORAS FORASAWAIT BY WHEN
943
- right IF ELSE FOR WHILE UNTIL LOOP SUPER CLASS COMPONENT RENDER IMPORT EXPORT DYNAMIC_IMPORT
945
+ right IF ELSE FOR WHILE UNTIL LOOP SUPER CLASS COMPONENT RENDER IMPORT EXPORT DYNAMIC_IMPORT OFFER ACCEPT
944
946
  left POST_IF
945
947
  """.trim().split('\n').reverse().map (line) -> line.trim().split /\s+/
946
948
 
package/src/lexer.js CHANGED
@@ -61,7 +61,7 @@ let JS_KEYWORDS = new Set([
61
61
  let RIP_KEYWORDS = new Set([
62
62
  'undefined', 'Infinity', 'NaN',
63
63
  'then', 'unless', 'until', 'loop', 'of', 'by', 'when', 'def',
64
- 'component', 'render',
64
+ 'component', 'render', 'offer', 'accept',
65
65
  'enum', 'interface',
66
66
  ]);
67
67