rip-lang 3.14.4 → 3.14.5
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/docs/dist/rip.js +122 -124
- package/docs/dist/rip.min.js +59 -59
- package/docs/dist/rip.min.js.br +0 -0
- package/package.json +1 -1
- package/src/compiler.js +21 -23
package/docs/dist/rip.min.js.br
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/compiler.js
CHANGED
|
@@ -1472,7 +1472,7 @@ export class CodeEmitter {
|
|
|
1472
1472
|
let stmts = body.slice(1);
|
|
1473
1473
|
this.indentLevel++;
|
|
1474
1474
|
let lines = [];
|
|
1475
|
-
if (!noVar) lines.push(
|
|
1475
|
+
if (!noVar) lines.push(`let ${itemVarPattern} = ${iterCode}[${idxName}];`);
|
|
1476
1476
|
if (guard) {
|
|
1477
1477
|
lines.push(`if (${this.emit(guard, 'value')}) {`);
|
|
1478
1478
|
this.indentLevel++;
|
|
@@ -1492,8 +1492,8 @@ export class CodeEmitter {
|
|
|
1492
1492
|
: loopHeader + `{ ${this.emit(body, 'statement')}; }`;
|
|
1493
1493
|
}
|
|
1494
1494
|
return guard
|
|
1495
|
-
? loopHeader + `{ ${itemVarPattern} = ${iterCode}[${idxName}]; if (${this.emit(guard, 'value')}) ${this.emit(body, 'statement')}; }`
|
|
1496
|
-
: loopHeader + `{ ${itemVarPattern} = ${iterCode}[${idxName}]; ${this.emit(body, 'statement')}; }`;
|
|
1495
|
+
? loopHeader + `{ let ${itemVarPattern} = ${iterCode}[${idxName}]; if (${this.emit(guard, 'value')}) ${this.emit(body, 'statement')}; }`
|
|
1496
|
+
: loopHeader + `{ let ${itemVarPattern} = ${iterCode}[${idxName}]; ${this.emit(body, 'statement')}; }`;
|
|
1497
1497
|
}
|
|
1498
1498
|
|
|
1499
1499
|
// Index variable → traditional for loop
|
|
@@ -1503,7 +1503,7 @@ export class CodeEmitter {
|
|
|
1503
1503
|
if (this.is(body, 'block')) {
|
|
1504
1504
|
code += '{\n';
|
|
1505
1505
|
this.indentLevel++;
|
|
1506
|
-
code += this.indent() +
|
|
1506
|
+
code += this.indent() + `let ${itemVarPattern} = ${iterCode}[${indexVar}];\n`;
|
|
1507
1507
|
if (guard) {
|
|
1508
1508
|
code += this.indent() + `if (${this.unwrap(this.emit(guard, 'value'))}) {\n`;
|
|
1509
1509
|
this.indentLevel++;
|
|
@@ -1517,8 +1517,8 @@ export class CodeEmitter {
|
|
|
1517
1517
|
code += this.indent() + '}';
|
|
1518
1518
|
} else {
|
|
1519
1519
|
code += guard
|
|
1520
|
-
? `{ ${itemVarPattern} = ${iterCode}[${indexVar}]; if (${this.unwrap(this.emit(guard, 'value'))}) ${this.emit(body, 'statement')}; }`
|
|
1521
|
-
: `{ ${itemVarPattern} = ${iterCode}[${indexVar}]; ${this.emit(body, 'statement')}; }`;
|
|
1520
|
+
? `{ let ${itemVarPattern} = ${iterCode}[${indexVar}]; if (${this.unwrap(this.emit(guard, 'value'))}) ${this.emit(body, 'statement')}; }`
|
|
1521
|
+
: `{ let ${itemVarPattern} = ${iterCode}[${indexVar}]; ${this.emit(body, 'statement')}; }`;
|
|
1522
1522
|
}
|
|
1523
1523
|
return code;
|
|
1524
1524
|
}
|
|
@@ -1542,8 +1542,7 @@ export class CodeEmitter {
|
|
|
1542
1542
|
}
|
|
1543
1543
|
|
|
1544
1544
|
// Default: for-of
|
|
1545
|
-
let
|
|
1546
|
-
let code = `for (${bind}${itemVarPattern} of ${this.emit(iterable, 'value')}) `;
|
|
1545
|
+
let code = `for (let ${itemVarPattern} of ${this.emit(iterable, 'value')}) `;
|
|
1547
1546
|
code += guard ? this.emitLoopBodyWithGuard(body, guard) : this.emitLoopBody(body);
|
|
1548
1547
|
return code;
|
|
1549
1548
|
}
|
|
@@ -1558,7 +1557,7 @@ export class CodeEmitter {
|
|
|
1558
1557
|
|
|
1559
1558
|
let [keyVar, valueVar] = Array.isArray(vars) ? vars : [vars];
|
|
1560
1559
|
let objCode = this.emit(obj, 'value');
|
|
1561
|
-
let code = `for (${keyVar} in ${objCode}) `;
|
|
1560
|
+
let code = `for (let ${keyVar} in ${objCode}) `;
|
|
1562
1561
|
|
|
1563
1562
|
if (own && !valueVar && !guard) {
|
|
1564
1563
|
if (this.is(body, 'block')) {
|
|
@@ -1576,7 +1575,7 @@ export class CodeEmitter {
|
|
|
1576
1575
|
this.indentLevel++;
|
|
1577
1576
|
let lines = [];
|
|
1578
1577
|
if (own) lines.push(`if (!Object.hasOwn(${objCode}, ${keyVar})) continue;`);
|
|
1579
|
-
lines.push(
|
|
1578
|
+
lines.push(`let ${valueVar} = ${objCode}[${keyVar}];`);
|
|
1580
1579
|
if (guard) {
|
|
1581
1580
|
lines.push(`if (${this.emit(guard, 'value')}) {`);
|
|
1582
1581
|
this.indentLevel++;
|
|
@@ -1591,7 +1590,7 @@ export class CodeEmitter {
|
|
|
1591
1590
|
}
|
|
1592
1591
|
let inline = '';
|
|
1593
1592
|
if (own) inline += `if (!Object.hasOwn(${objCode}, ${keyVar})) continue; `;
|
|
1594
|
-
inline +=
|
|
1593
|
+
inline += `let ${valueVar} = ${objCode}[${keyVar}]; `;
|
|
1595
1594
|
if (guard) inline += `if (${this.emit(guard, 'value')}) `;
|
|
1596
1595
|
inline += `${this.emit(body, 'statement')};`;
|
|
1597
1596
|
return code + `{ ${inline} }`;
|
|
@@ -1638,7 +1637,7 @@ export class CodeEmitter {
|
|
|
1638
1637
|
itemVarPattern = this.emitDestructuringPattern(firstVar);
|
|
1639
1638
|
else itemVarPattern = firstVar;
|
|
1640
1639
|
|
|
1641
|
-
let code = `for ${awaitKw}(${itemVarPattern} of ${iterCode}) `;
|
|
1640
|
+
let code = `for ${awaitKw}(let ${itemVarPattern} of ${iterCode}) `;
|
|
1642
1641
|
|
|
1643
1642
|
if (needsTempVar && destructStmts.length > 0) {
|
|
1644
1643
|
let stmts = this.unwrapBlock(body);
|
|
@@ -2012,17 +2011,16 @@ export class CodeEmitter {
|
|
|
2012
2011
|
let header = isNeg
|
|
2013
2012
|
? `for (let ${idxN} = ${ic}.length - 1; ${idxN} >= 0; ${update})`
|
|
2014
2013
|
: `for (let ${idxN} = 0; ${idxN} < ${ic}.length; ${update})`;
|
|
2015
|
-
return { header, setup: noVar ? null :
|
|
2014
|
+
return { header, setup: noVar ? null : `let ${ivp} = ${ic}[${idxN}];` };
|
|
2016
2015
|
}
|
|
2017
2016
|
if (indexVar) {
|
|
2018
2017
|
let ic = this.emit(iterable, 'value');
|
|
2019
2018
|
return {
|
|
2020
2019
|
header: `for (let ${indexVar} = 0; ${indexVar} < ${ic}.length; ${indexVar}++)`,
|
|
2021
|
-
setup:
|
|
2020
|
+
setup: `let ${ivp} = ${ic}[${indexVar}];`,
|
|
2022
2021
|
};
|
|
2023
2022
|
}
|
|
2024
|
-
|
|
2025
|
-
return { header: `for (${bind}${ivp} of ${this.emit(iterable, 'value')})`, setup: null };
|
|
2023
|
+
return { header: `for (let ${ivp} of ${this.emit(iterable, 'value')})`, setup: null };
|
|
2026
2024
|
}
|
|
2027
2025
|
|
|
2028
2026
|
// Shared: parse a for-of (object) iterator and return { header, own, vv, oc, kvp }.
|
|
@@ -2032,7 +2030,7 @@ export class CodeEmitter {
|
|
|
2032
2030
|
let kvp = (this.is(kv, 'array') || this.is(kv, 'object'))
|
|
2033
2031
|
? this.emitDestructuringPattern(kv) : kv;
|
|
2034
2032
|
let oc = this.emit(iterable, 'value');
|
|
2035
|
-
return { header: `for (${kvp} in ${oc})`, own, vv, oc, kvp };
|
|
2033
|
+
return { header: `for (let ${kvp} in ${oc})`, own, vv, oc, kvp };
|
|
2036
2034
|
}
|
|
2037
2035
|
|
|
2038
2036
|
// Shared: parse a for-as (iterator) spec and return { header }.
|
|
@@ -2041,7 +2039,7 @@ export class CodeEmitter {
|
|
|
2041
2039
|
let [fv] = va;
|
|
2042
2040
|
let ivp = (this.is(fv, 'array') || this.is(fv, 'object'))
|
|
2043
2041
|
? this.emitDestructuringPattern(fv) : fv;
|
|
2044
|
-
return { header: `for ${isAwait ? 'await ' : ''}(${ivp} of ${this.emit(iterable, 'value')})` };
|
|
2042
|
+
return { header: `for ${isAwait ? 'await ' : ''}(let ${ivp} of ${this.emit(iterable, 'value')})` };
|
|
2045
2043
|
}
|
|
2046
2044
|
|
|
2047
2045
|
emitComprehension(head, rest, context) {
|
|
@@ -2068,7 +2066,7 @@ export class CodeEmitter {
|
|
|
2068
2066
|
code += this.indent() + header + ' {\n';
|
|
2069
2067
|
this.indentLevel++;
|
|
2070
2068
|
if (own) code += this.indent() + `if (!Object.hasOwn(${oc}, ${kvp})) continue;\n`;
|
|
2071
|
-
if (vv) code += this.indent() +
|
|
2069
|
+
if (vv) code += this.indent() + `let ${vv} = ${oc}[${kvp}];\n`;
|
|
2072
2070
|
} else if (iterType === 'for-as') {
|
|
2073
2071
|
let { header } = this._forAsHeader(vars, iterable, iter[3]);
|
|
2074
2072
|
code += this.indent() + header + ' {\n';
|
|
@@ -2132,10 +2130,10 @@ export class CodeEmitter {
|
|
|
2132
2130
|
if (iterType === 'for-of') {
|
|
2133
2131
|
let [kv, vv] = vars;
|
|
2134
2132
|
let oc = this.emit(iterable, 'value');
|
|
2135
|
-
code += this.indent() + `for (${kv} in ${oc}) {\n`;
|
|
2133
|
+
code += this.indent() + `for (let ${kv} in ${oc}) {\n`;
|
|
2136
2134
|
this.indentLevel++;
|
|
2137
2135
|
if (own) code += this.indent() + `if (!Object.hasOwn(${oc}, ${kv})) continue;\n`;
|
|
2138
|
-
if (vv) code += this.indent() +
|
|
2136
|
+
if (vv) code += this.indent() + `let ${vv} = ${oc}[${kv}];\n`;
|
|
2139
2137
|
}
|
|
2140
2138
|
}
|
|
2141
2139
|
for (let guard of guards) { code += this.indent() + `if (${this.emit(guard, 'value')}) {\n`; this.indentLevel++; }
|
|
@@ -2792,7 +2790,7 @@ export class CodeEmitter {
|
|
|
2792
2790
|
code += this.indent() + header + ' {\n';
|
|
2793
2791
|
this.indentLevel++;
|
|
2794
2792
|
if (own) code += this.indent() + `if (!Object.hasOwn(${oc}, ${kvp})) continue;\n`;
|
|
2795
|
-
if (vv) code += this.indent() +
|
|
2793
|
+
if (vv) code += this.indent() + `let ${vv} = ${oc}[${kvp}];\n`;
|
|
2796
2794
|
if (guards?.length > 0) { code += this.indent() + `if (${guards.map(g => this.emit(g, 'value')).join(' && ')}) {\n`; this.indentLevel++; }
|
|
2797
2795
|
emitBody();
|
|
2798
2796
|
if (guards?.length > 0) { this.indentLevel--; code += this.indent() + '}\n'; }
|
|
@@ -2864,7 +2862,7 @@ export class CodeEmitter {
|
|
|
2864
2862
|
code += header + ' {\n';
|
|
2865
2863
|
this.indentLevel++;
|
|
2866
2864
|
if (own) code += this.indent() + `if (!Object.hasOwn(${oc}, ${kvp})) continue;\n`;
|
|
2867
|
-
if (vv) code += this.indent() +
|
|
2865
|
+
if (vv) code += this.indent() + `let ${vv} = ${oc}[${kvp}];\n`;
|
|
2868
2866
|
emitBody();
|
|
2869
2867
|
this.indentLevel--;
|
|
2870
2868
|
code += this.indent() + '}';
|