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: mockContractScan mask() no longer blanks exports after a JSX-text apostrophe (#12794)

[._.]/ Adam Eivyd58015b19987
diff --git a/scripts/lib/mockContractScan.js b/scripts/lib/mockContractScan.js
index f196d72854..af37078b36 100644
--- a/scripts/lib/mockContractScan.js
+++ b/scripts/lib/mockContractScan.js
@@ -23,6 +23,17 @@ function startsRegex(source, at) {
return before === '' || /[(,=:[!&|?{};>]$/.test(before) || /\breturn$/.test(before);
}
+const KEYWORD_BEFORE_STRING = /(?:^|[^\w$.])(?:return|case|typeof|in|of|yield|await|default|else|do|void|delete|new|throw|instanceof|from|import|export|as)$/;
+
+/**
+ * A quote glued to the end of an identifier cannot open a string literal, so it
+ * is JSX text or prose (`scene's`), not code. Keywords legitimately precede strings.
+ */
+function isTextApostrophe(source, at) {
+ if (!/[\w$]/.test(source[at - 1] ?? '')) return false;
+ return !KEYWORD_BEFORE_STRING.test(source.slice(Math.max(0, at - 12), at));
+}
+
/** Blank comments and string/template text (keeping `${}` code), preserving offsets. */
export function mask(source) {
const out = source.split('');
@@ -58,7 +69,7 @@ export function mask(source) {
}
blank(i + 1, j);
i = j + 1;
- } else if (ch === '\'' || ch === '"') {
+ } else if ((ch === '\'' || ch === '"') && !isTextApostrophe(source, i)) {
let j = i + 1;
while (j < source.length && source[j] !== ch) j += source[j] === '\\' ? 2 : 1;
blank(i + 1, j);
diff --git a/server/mockContractConventions.test.js b/server/mockContractConventions.test.js
index 7d8abf905f..6d3361e6ea 100644
--- a/server/mockContractConventions.test.js
+++ b/server/mockContractConventions.test.js
@@ -8,7 +8,7 @@ import { execFileSync } from 'node:child_process';
import { existsSync, readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
-import { exportNames, mockDrift } from '../scripts/lib/mockContractScan.js';
+import { exportNames, mask, mockDrift } from '../scripts/lib/mockContractScan.js';
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
@@ -37,6 +37,23 @@ describe('vi.mock factory contract conventions', () => {
expect(drift(probe, src)).toEqual(['server/lib/__probe.test.js:1 — ./validation.js mocks plantedDeadKey']);
});
+ it('does not read a JSX-text apostrophe as a string opener (#12794)', () => {
+ const src = [
+ 'export function Panel() {',
+ " return <p>Style is prepended to every scene's image prompt.</p>;",
+ '}',
+ 'export default Panel;',
+ ].join('\n');
+ expect(mask(src)).toContain('export default Panel');
+ expect(mask("export const a = 'x';\nexport const b = 1;")).toContain('export const b');
+ expect(mask("export const c = 'don\\'t';")).not.toContain('don');
+ });
+
+ it('collects the default export of a component with an apostrophe in JSX text (#12794)', () => {
+ const file = join(ROOT, 'client/src/components/writers-room/StoryboardConfigTab.jsx');
+ expect([...exportNames(file)]).toEqual(['default']);
+ });
+
it('follows export * when collecting real exports', () => {
expect(exportNames(join(ROOT, 'server/lib/index.js')).size).toBeGreaterThan(50);
});