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: recognize a regex at the start of a template interpolation in the import-case scanner (#12302)

[._.]/ Adam Eivya59825c013c3
diff --git a/scripts/check-import-case.js b/scripts/check-import-case.js
index 1fe8591a80..b1eaa47f92 100644
--- a/scripts/check-import-case.js
+++ b/scripts/check-import-case.js
@@ -91,6 +91,8 @@ function scanCode(source) {
blank(from, source.length);
return source.length;
};
+ // After readTemplate: a closed template is an operand ('`'); entering `${` starts a fresh expression, so a leading `/` is a regex ('{' is a regex-start context).
+ const templateEnd = (end) => (source[end - 1] === '`' ? '`' : '{');
while (i < source.length) {
const ch = source[i];
const two = source.slice(i, i + 2);
@@ -112,7 +114,7 @@ function scanCode(source) {
prev = ch;
} else if (ch === '`') {
i = readTemplate(i);
- prev = '`';
+ prev = templateEnd(i);
} else if (ch === '/' && (prev === '' || '(,=:[!&|?{;+-*%<>~^'.includes(prev) || !endsExpression() && (prev === ')' || /[\w$]/.test(prev))) && !isPostfixStep()) {
// `}` is deliberately not a regex start: it usually ends an object/function expression (`{} / d`), and mis-scanning a rare regex statement after a block is safer than dropping later imports from the check.
let j = i + 1;
@@ -135,7 +137,7 @@ function scanCode(source) {
if (templates.length > 0 && templates[templates.length - 1] === depth) {
templates.pop();
i = readTemplate(i);
- prev = '`';
+ prev = templateEnd(i);
continue;
}
}
diff --git a/scripts/check-import-case.test.js b/scripts/check-import-case.test.js
index 5d444d16bb..af5c3b5278 100644
--- a/scripts/check-import-case.test.js
+++ b/scripts/check-import-case.test.js
@@ -45,6 +45,14 @@ describe('relativeSpecifiers ignores non-executable text', () => {
expect(relativeSpecifiers(source)).toEqual(['./InExpression.js', './Real.js', './AfterString.js']);
});
+ it('reads a leading regex in a template interpolation as a regex, and a closed template as an operand', () => {
+ const source = [
+ "const t = `${/x'/.test(s) ? import('./LeadingRegex.js') : null}`;",
+ "const u = `a` / 2; await import('./AfterTemplate.js');",
+ ].join('\n');
+ expect(relativeSpecifiers(source)).toEqual(['./LeadingRegex.js', './AfterTemplate.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');",