Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: treat division after postfix ++/-- as division in import-case scanner (#12302)

[._.]/ Adam Eivy87c9f9c87fe5
diff --git a/scripts/check-import-case.js b/scripts/check-import-case.js
index 7389ccbf68..d86da95cd4 100644
--- a/scripts/check-import-case.js
+++ b/scripts/check-import-case.js
@@ -51,7 +51,11 @@ function scanCode(source) {
const templates = []; // brace depth at which each open `${` resumes template text
let depth = 0;
let prev = ''; // last significant code character
+ let prevAt = -1; // its index in source
let i = 0;
+ // `x++ / y`: a prefix ++/-- needs an operand, never a regex, so an adjacent
+ // doubled +/- before `/` always ends an expression.
+ const isPostfixStep = () => (prev === '+' || prev === '-') && prevAt > 0 && source[prevAt - 1] === prev;
const readTemplate = (from) => {
let j = from + 1;
while (j < source.length) {
@@ -89,7 +93,7 @@ function scanCode(source) {
} else if (ch === '`') {
i = readTemplate(i);
prev = '`';
- } else if (ch === '/' && (prev === '' || '(,=:[!&|?{};+-*%<>~^'.includes(prev))) {
+ } else if (ch === '/' && (prev === '' || '(,=:[!&|?{};+-*%<>~^'.includes(prev)) && !isPostfixStep()) {
let j = i + 1;
let inClass = false;
while (j < source.length && source[j] !== '\n' && (inClass || source[j] !== '/')) {
@@ -112,7 +116,7 @@ function scanCode(source) {
continue;
}
}
- if (!/\s/.test(ch)) prev = ch;
+ if (!/\s/.test(ch)) { prev = ch; prevAt = i; }
i += 1;
}
}
diff --git a/scripts/check-import-case.test.js b/scripts/check-import-case.test.js
index 0358265cc7..2a94ba8206 100644
--- a/scripts/check-import-case.test.js
+++ b/scripts/check-import-case.test.js
@@ -44,6 +44,17 @@ describe('relativeSpecifiers ignores non-executable text', () => {
].join('\n');
expect(relativeSpecifiers(source)).toEqual(['./InExpression.js', './Real.js', './AfterString.js']);
});
+
+ it("treats division after postfix ++/-- and closing tokens as division, so later imports stay checked", () => {
+ const source = [
+ "const r1 = count++ / divisor; await import('./AfterInc.js');",
+ "const r2 = count-- / divisor; await import('./AfterDec.js');",
+ "const r3 = (a + b) / 2; await import('./AfterParen.js');",
+ "const r4 = list[0] / 2; await import('./AfterBracket.js');",
+ "const r5 = a + /x/.source.length; await import('./AfterRegex.js');",
+ ].join("\n");
+ expect(relativeSpecifiers(source)).toEqual(['./AfterInc.js', './AfterDec.js', './AfterParen.js', './AfterBracket.js', './AfterRegex.js']);
+ });
});
describe('importCaseMismatches', () => {