rip-lang 3.13.79 → 3.13.80
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/README.md +1 -1
- package/package.json +1 -1
- package/src/compiler.js +16 -2
- package/src/components.js +60 -40
- package/src/typecheck.js +2 -0
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
|
-
<a href="CHANGELOG.md"><img src="https://img.shields.io/badge/version-3.13.
|
|
12
|
+
<a href="CHANGELOG.md"><img src="https://img.shields.io/badge/version-3.13.80-blue.svg" alt="Version"></a>
|
|
13
13
|
<a href="#zero-dependencies"><img src="https://img.shields.io/badge/dependencies-ZERO-brightgreen.svg" alt="Dependencies"></a>
|
|
14
14
|
<a href="#"><img src="https://img.shields.io/badge/tests-1%2C436%2F1%2C436-brightgreen.svg" alt="Tests"></a>
|
|
15
15
|
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License"></a>
|
package/package.json
CHANGED
package/src/compiler.js
CHANGED
|
@@ -297,6 +297,11 @@ export class CodeGenerator {
|
|
|
297
297
|
if (entry.loc) {
|
|
298
298
|
this.sourceMap.addMapping(lineOffset, 0, entry.loc.r, entry.loc.c);
|
|
299
299
|
}
|
|
300
|
+
if (entry.subLocs) {
|
|
301
|
+
for (const { lineOffset: lo, loc } of entry.subLocs) {
|
|
302
|
+
if (loc) this.sourceMap.addMapping(lineOffset + lo, 0, loc.r, loc.c);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
300
305
|
lineOffset += entry.code.split('\n').length;
|
|
301
306
|
}
|
|
302
307
|
}
|
|
@@ -619,7 +624,12 @@ export class CodeGenerator {
|
|
|
619
624
|
if (!blockStmts.includes(h) || !generated.endsWith('}')) generated += ';';
|
|
620
625
|
}
|
|
621
626
|
let loc = Array.isArray(stmt) ? stmt.loc : null;
|
|
622
|
-
|
|
627
|
+
let entry = { code: generated, loc };
|
|
628
|
+
if (this._pendingComponentLineLocs) {
|
|
629
|
+
entry.subLocs = this._pendingComponentLineLocs;
|
|
630
|
+
this._pendingComponentLineLocs = null;
|
|
631
|
+
}
|
|
632
|
+
return entry;
|
|
623
633
|
});
|
|
624
634
|
let statementsCode = stmtEntries.map(e => e.code).join('\n');
|
|
625
635
|
|
|
@@ -3397,10 +3407,14 @@ declare function __computed<T>(fn: () => T): Computed<T>;
|
|
|
3397
3407
|
declare function __effect(fn: () => void | (() => void)): () => void;
|
|
3398
3408
|
declare function __batch<T>(fn: () => T): T;
|
|
3399
3409
|
declare function __readonly<T>(v: T): Readonly<{ value: T }>;
|
|
3410
|
+
declare function __pushComponent(component: any): any;
|
|
3411
|
+
declare function __popComponent(prev: any): void;
|
|
3412
|
+
declare function __handleComponentError(error: any, component: any): void;
|
|
3413
|
+
declare function __clsx(...args: any[]): string;
|
|
3400
3414
|
declare function setContext(key: string, value: any): void;
|
|
3401
3415
|
declare function getContext(key: string): any;
|
|
3402
3416
|
declare function hasContext(key: string): boolean;
|
|
3403
|
-
declare class __Component { constructor(props?: any); [key: string]: any; }
|
|
3417
|
+
declare class __Component { constructor(props?: any); _create?(): any; _setup?(): void; _root?: any; _children?: any[]; [key: string]: any; }
|
|
3404
3418
|
`;
|
|
3405
3419
|
}
|
|
3406
3420
|
|
package/src/components.js
CHANGED
|
@@ -713,35 +713,35 @@ export function installComponentSupport(CodeGenerator, Lexer) {
|
|
|
713
713
|
} else if (op === 'state') {
|
|
714
714
|
const varName = getMemberName(stmt[1]);
|
|
715
715
|
if (varName) {
|
|
716
|
-
stateVars.push({ name: varName, value: stmt[2], isPublic: isPublicProp(stmt[1]), type: getMemberType(stmt[1]) });
|
|
716
|
+
stateVars.push({ name: varName, value: stmt[2], isPublic: isPublicProp(stmt[1]), type: getMemberType(stmt[1]), loc: stmt.loc });
|
|
717
717
|
memberNames.add(varName);
|
|
718
718
|
reactiveMembers.add(varName);
|
|
719
719
|
}
|
|
720
720
|
} else if (op === 'computed') {
|
|
721
721
|
const varName = getMemberName(stmt[1]);
|
|
722
722
|
if (varName) {
|
|
723
|
-
derivedVars.push({ name: varName, expr: stmt[2] });
|
|
723
|
+
derivedVars.push({ name: varName, expr: stmt[2], loc: stmt.loc });
|
|
724
724
|
memberNames.add(varName);
|
|
725
725
|
reactiveMembers.add(varName);
|
|
726
726
|
}
|
|
727
727
|
} else if (op === 'readonly') {
|
|
728
728
|
const varName = getMemberName(stmt[1]);
|
|
729
729
|
if (varName) {
|
|
730
|
-
readonlyVars.push({ name: varName, value: stmt[2], isPublic: isPublicProp(stmt[1]), type: getMemberType(stmt[1]) });
|
|
730
|
+
readonlyVars.push({ name: varName, value: stmt[2], isPublic: isPublicProp(stmt[1]), type: getMemberType(stmt[1]), loc: stmt.loc });
|
|
731
731
|
memberNames.add(varName);
|
|
732
732
|
}
|
|
733
733
|
} else if (op === '=') {
|
|
734
734
|
const varName = getMemberName(stmt[1]);
|
|
735
735
|
if (varName) {
|
|
736
736
|
if (LIFECYCLE_HOOKS.has(varName)) {
|
|
737
|
-
lifecycleHooks.push({ name: varName, value: stmt[2] });
|
|
737
|
+
lifecycleHooks.push({ name: varName, value: stmt[2], loc: stmt.loc });
|
|
738
738
|
} else {
|
|
739
739
|
const val = stmt[2];
|
|
740
740
|
if (Array.isArray(val) && (val[0] === '->' || val[0] === '=>')) {
|
|
741
|
-
methods.push({ name: varName, func: val });
|
|
741
|
+
methods.push({ name: varName, func: val, loc: stmt.loc });
|
|
742
742
|
memberNames.add(varName);
|
|
743
743
|
} else {
|
|
744
|
-
stateVars.push({ name: varName, value: val, isPublic: isPublicProp(stmt[1]) });
|
|
744
|
+
stateVars.push({ name: varName, value: val, isPublic: isPublicProp(stmt[1]), loc: stmt.loc });
|
|
745
745
|
memberNames.add(varName);
|
|
746
746
|
reactiveMembers.add(varName);
|
|
747
747
|
}
|
|
@@ -757,9 +757,9 @@ export function installComponentSupport(CodeGenerator, Lexer) {
|
|
|
757
757
|
if (!Array.isArray(pair)) continue;
|
|
758
758
|
const [methodName, funcDef] = pair;
|
|
759
759
|
if (typeof methodName === 'string' && LIFECYCLE_HOOKS.has(methodName)) {
|
|
760
|
-
lifecycleHooks.push({ name: methodName, value: funcDef });
|
|
760
|
+
lifecycleHooks.push({ name: methodName, value: funcDef, loc: pair.loc });
|
|
761
761
|
} else if (typeof methodName === 'string') {
|
|
762
|
-
methods.push({ name: methodName, func: funcDef });
|
|
762
|
+
methods.push({ name: methodName, func: funcDef, loc: pair.loc });
|
|
763
763
|
memberNames.add(methodName);
|
|
764
764
|
}
|
|
765
765
|
}
|
|
@@ -783,9 +783,21 @@ export function installComponentSupport(CodeGenerator, Lexer) {
|
|
|
783
783
|
this._autoEventHandlers = autoEventHandlers.size > 0 ? autoEventHandlers : null;
|
|
784
784
|
|
|
785
785
|
const lines = [];
|
|
786
|
+
const lineLocs = [];
|
|
786
787
|
let blockFactoriesCode = '';
|
|
787
788
|
|
|
788
|
-
|
|
789
|
+
let totalLines = 0;
|
|
790
|
+
const pushLine = (line, loc) => {
|
|
791
|
+
if (loc) lineLocs.push({ lineOffset: totalLines, loc });
|
|
792
|
+
lines.push(line);
|
|
793
|
+
totalLines += line.split('\n').length;
|
|
794
|
+
};
|
|
795
|
+
const pushPlain = (line) => {
|
|
796
|
+
lines.push(line);
|
|
797
|
+
totalLines += line.split('\n').length;
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
pushPlain('class extends __Component {');
|
|
789
801
|
|
|
790
802
|
// --- Init (called by __Component constructor) ---
|
|
791
803
|
if (this.options.lspMode) {
|
|
@@ -800,47 +812,47 @@ export function installComponentSupport(CodeGenerator, Lexer) {
|
|
|
800
812
|
const propsType = typedProps.length > 0
|
|
801
813
|
? `{ ${typedProps.join(', ')}, [key: string]: any }`
|
|
802
814
|
: 'any';
|
|
803
|
-
|
|
815
|
+
pushPlain(` _init(props: ${propsType}) {`);
|
|
804
816
|
} else {
|
|
805
|
-
|
|
817
|
+
pushPlain(' _init(props) {');
|
|
806
818
|
}
|
|
807
819
|
|
|
808
820
|
// Constants (readonly)
|
|
809
|
-
for (const { name, value, isPublic } of readonlyVars) {
|
|
821
|
+
for (const { name, value, isPublic, loc } of readonlyVars) {
|
|
810
822
|
const val = this.generateInComponent(value, 'value');
|
|
811
|
-
|
|
823
|
+
pushLine(isPublic
|
|
812
824
|
? ` this.${name} = props.${name} ?? ${val};`
|
|
813
|
-
: ` this.${name} = ${val}
|
|
825
|
+
: ` this.${name} = ${val};`, loc);
|
|
814
826
|
}
|
|
815
827
|
|
|
816
828
|
// Accepted vars (from ancestor context via getContext)
|
|
817
829
|
for (const name of acceptedVars) {
|
|
818
|
-
|
|
830
|
+
pushPlain(` this.${name} = getContext('${name}');`);
|
|
819
831
|
}
|
|
820
832
|
|
|
821
833
|
// State variables (__state handles signal passthrough)
|
|
822
|
-
for (const { name, value, isPublic } of stateVars) {
|
|
834
|
+
for (const { name, value, isPublic, loc } of stateVars) {
|
|
823
835
|
const val = this.generateInComponent(value, 'value');
|
|
824
|
-
|
|
836
|
+
pushLine(isPublic
|
|
825
837
|
? ` this.${name} = __state(props.__bind_${name}__ ?? props.${name} ?? ${val});`
|
|
826
|
-
: ` this.${name} = __state(${val})
|
|
838
|
+
: ` this.${name} = __state(${val});`, loc);
|
|
827
839
|
}
|
|
828
840
|
|
|
829
841
|
// Computed (derived)
|
|
830
|
-
for (const { name, expr } of derivedVars) {
|
|
842
|
+
for (const { name, expr, loc } of derivedVars) {
|
|
831
843
|
if (this.is(expr, 'block')) {
|
|
832
844
|
const transformed = this.transformComponentMembers(expr);
|
|
833
845
|
const body = this.generateFunctionBody(transformed);
|
|
834
|
-
|
|
846
|
+
pushLine(` this.${name} = __computed(() => ${body});`, loc);
|
|
835
847
|
} else {
|
|
836
848
|
const val = this.generateInComponent(expr, 'value');
|
|
837
|
-
|
|
849
|
+
pushLine(` this.${name} = __computed(() => ${val});`, loc);
|
|
838
850
|
}
|
|
839
851
|
}
|
|
840
852
|
|
|
841
853
|
// Offered vars (share with descendants via setContext — after all members are initialized)
|
|
842
854
|
for (const name of offeredVars) {
|
|
843
|
-
|
|
855
|
+
pushPlain(` setContext('${name}', this.${name});`);
|
|
844
856
|
}
|
|
845
857
|
|
|
846
858
|
// Effects
|
|
@@ -850,73 +862,81 @@ export function installComponentSupport(CodeGenerator, Lexer) {
|
|
|
850
862
|
if (this.is(effectBody, 'block')) {
|
|
851
863
|
const transformed = this.transformComponentMembers(effectBody);
|
|
852
864
|
const body = this.generateFunctionBody(transformed, [], true);
|
|
853
|
-
|
|
865
|
+
pushLine(` __effect(${isAsync}() => ${body});`, effect.loc);
|
|
854
866
|
} else {
|
|
855
867
|
const effectCode = this.generateInComponent(effectBody, 'value');
|
|
856
|
-
|
|
868
|
+
pushLine(` __effect(${isAsync}() => { ${effectCode}; });`, effect.loc);
|
|
857
869
|
}
|
|
858
870
|
}
|
|
859
871
|
|
|
860
|
-
|
|
872
|
+
pushPlain(' }');
|
|
861
873
|
|
|
862
874
|
// --- Methods ---
|
|
863
|
-
for (const { name, func } of methods) {
|
|
875
|
+
for (const { name, func, loc } of methods) {
|
|
864
876
|
if (Array.isArray(func) && (func[0] === '->' || func[0] === '=>')) {
|
|
865
877
|
const [, params, methodBody] = func;
|
|
866
878
|
const paramStr = Array.isArray(params) ? params.map(p => this.formatParam(p)).join(', ') : '';
|
|
867
879
|
const transformed = this.reactiveMembers ? this.transformComponentMembers(methodBody) : methodBody;
|
|
868
880
|
const isAsync = this.containsAwait(methodBody);
|
|
869
881
|
const bodyCode = this.generateFunctionBody(transformed, params || []);
|
|
870
|
-
|
|
882
|
+
pushLine(` ${isAsync ? 'async ' : ''}${name}(${paramStr}) ${bodyCode}`, loc);
|
|
871
883
|
}
|
|
872
884
|
}
|
|
873
885
|
|
|
874
886
|
// --- Lifecycle hooks ---
|
|
875
|
-
for (const { name, value } of lifecycleHooks) {
|
|
887
|
+
for (const { name, value, loc } of lifecycleHooks) {
|
|
876
888
|
if (Array.isArray(value) && (value[0] === '->' || value[0] === '=>')) {
|
|
877
889
|
const [, params, hookBody] = value;
|
|
878
890
|
const paramStr = Array.isArray(params) ? params.map(p => this.formatParam(p)).join(', ') : '';
|
|
879
891
|
const transformed = this.reactiveMembers ? this.transformComponentMembers(hookBody) : hookBody;
|
|
880
892
|
const isAsync = this.containsAwait(hookBody);
|
|
881
893
|
const bodyCode = this.generateFunctionBody(transformed, params || []);
|
|
882
|
-
|
|
894
|
+
pushLine(` ${isAsync ? 'async ' : ''}${name}(${paramStr}) ${bodyCode}`, loc);
|
|
883
895
|
}
|
|
884
896
|
}
|
|
885
897
|
|
|
886
898
|
// --- Render block (fine-grained) ---
|
|
887
|
-
if (renderBlock
|
|
899
|
+
if (renderBlock) {
|
|
888
900
|
const renderBody = renderBlock[1];
|
|
889
901
|
const result = this.buildRender(renderBody);
|
|
890
902
|
|
|
891
|
-
if (result.blockFactories.length > 0) {
|
|
903
|
+
if (!this.options.lspMode && result.blockFactories.length > 0) {
|
|
892
904
|
blockFactoriesCode = result.blockFactories.join('\n\n') + '\n\n';
|
|
893
905
|
}
|
|
894
906
|
|
|
895
|
-
|
|
907
|
+
pushLine(' _create() {', renderBlock.loc);
|
|
896
908
|
for (const line of result.createLines) {
|
|
897
|
-
|
|
909
|
+
pushPlain(` ${line}`);
|
|
898
910
|
}
|
|
899
|
-
|
|
900
|
-
|
|
911
|
+
pushPlain(` return ${result.rootVar};`);
|
|
912
|
+
pushPlain(' }');
|
|
901
913
|
|
|
902
|
-
if (result.setupLines.length > 0) {
|
|
903
|
-
|
|
914
|
+
if (!this.options.lspMode && result.setupLines.length > 0) {
|
|
915
|
+
pushPlain(' _setup() {');
|
|
904
916
|
for (const line of result.setupLines) {
|
|
905
|
-
|
|
917
|
+
pushPlain(` ${line}`);
|
|
906
918
|
}
|
|
907
|
-
|
|
919
|
+
pushPlain(' }');
|
|
908
920
|
}
|
|
909
921
|
}
|
|
910
922
|
|
|
911
|
-
|
|
923
|
+
pushPlain('}');
|
|
912
924
|
|
|
913
925
|
// Restore context
|
|
914
926
|
this.componentMembers = prevComponentMembers;
|
|
915
927
|
this.reactiveMembers = prevReactiveMembers;
|
|
916
928
|
this._autoEventHandlers = prevAutoEventHandlers;
|
|
917
929
|
|
|
930
|
+
// Store line-level source mappings for the parent statement entry
|
|
931
|
+
if (lineLocs.length > 0) {
|
|
932
|
+
this._pendingComponentLineLocs = lineLocs;
|
|
933
|
+
}
|
|
934
|
+
|
|
918
935
|
// If block factories exist, wrap in IIFE so they're in scope
|
|
919
936
|
if (blockFactoriesCode) {
|
|
937
|
+
// Adjust lineOffsets for the IIFE wrapper + block factories prefix
|
|
938
|
+
const prefixLines = blockFactoriesCode.split('\n').length;
|
|
939
|
+
for (const entry of lineLocs) entry.lineOffset += prefixLines;
|
|
920
940
|
return `(() => {\n${blockFactoriesCode}return ${lines.join('\n')};\n})()`;
|
|
921
941
|
}
|
|
922
942
|
|
package/src/typecheck.js
CHANGED
|
@@ -41,6 +41,8 @@ export const SKIP_CODES = new Set([
|
|
|
41
41
|
2307, // Cannot find module
|
|
42
42
|
2393, // Duplicate function implementation
|
|
43
43
|
2451, // Cannot redeclare block-scoped variable
|
|
44
|
+
2554, // Expected N arguments but got M (generated event handler wrappers pass event arg)
|
|
45
|
+
7006, // Parameter implicitly has 'any' type (generated event callback params)
|
|
44
46
|
1064, // Return type of async function must be Promise
|
|
45
47
|
2582, // Cannot find name 'test' (test runner globals)
|
|
46
48
|
2593, // Cannot find name 'describe' (test runner globals)
|