fix(client): add support for editable regions in TypeScript and TSX files (#67537)

This commit is contained in:
Rustom Yadav
2026-05-23 01:23:53 +05:30
committed by GitHub
parent f261638612
commit e08b9f992f
2 changed files with 35 additions and 0 deletions
@@ -54,10 +54,15 @@ export function insertEditableRegions(challengeFiles = []) {
return '\n/* User Editable Region */\n'; return '\n/* User Editable Region */\n';
case 'py': case 'py':
return '\n# User Editable Region\n'; return '\n# User Editable Region\n';
case 'js': case 'js':
case 'ts':
return '\n// User Editable Region\n'; return '\n// User Editable Region\n';
case 'jsx': case 'jsx':
case 'tsx':
return '\n{/* User Editable Region */}\n'; return '\n{/* User Editable Region */}\n';
default: default:
return '\nUser Editable Region\n'; return '\nUser Editable Region\n';
} }
@@ -89,5 +89,35 @@ describe('create-question-epic', () => {
insertEditableRegions(multiCertChallengeFiles) insertEditableRegions(multiCertChallengeFiles)
).not.toThrow(); ).not.toThrow();
}); });
it.each([
['html', '<!-- User Editable Region -->'],
['css', '/* User Editable Region */'],
['py', '# User Editable Region'],
['js', '// User Editable Region'],
['ts', '// User Editable Region'],
['jsx', '{/* User Editable Region */}'],
['tsx', '{/* User Editable Region */}'],
['unknown', 'User Editable Region']
])('should insert correct comment syntax for %s files', (ext, comment) => {
const challengeFiles = [
{
contents: 'line1\nline2\nline3\nline4',
editableRegionBoundaries: [1, 3],
ext,
fileKey: `file-${ext}`,
history: [`index.${ext}`],
head: '',
id: '',
name: 'index',
path: `index.${ext}`,
seed: 'line1\nline2\nline3\nline4',
tail: ''
}
];
const result = insertEditableRegions(challengeFiles);
expect(result[0].contents).toContain(comment);
});
}); });
}); });