When optimizing TypeScript class methods that call other methods from the same class, the helper methods were being appended OUTSIDE the class definition. This caused syntax errors because class-specific keywords like `private` are only valid inside a class body. Changes: - Add _find_same_class_helpers() method to identify helper methods belonging to the same class as the target method - Modify extract_code_context() to include same-class helpers inside the class wrapper and filter them from the helpers list - Fix all JavaScript/TypeScript tests by adding export keywords to test code so functions can be discovered by discover_functions() - Add comprehensive tests for same-class helper extraction Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
41 lines
No EOL
983 B
JavaScript
41 lines
No EOL
983 B
JavaScript
/**
|
|
* Formatting helper functions.
|
|
*/
|
|
|
|
/**
|
|
* Format a number to specified decimal places.
|
|
* @param num - Number to format
|
|
* @param decimals - Number of decimal places
|
|
* @returns Formatted number
|
|
*/
|
|
export function formatNumber(num, decimals) {
|
|
return Number(num.toFixed(decimals));
|
|
}
|
|
|
|
/**
|
|
* Validate that input is a valid number.
|
|
* @param value - Value to validate
|
|
* @param name - Parameter name for error message
|
|
* @throws Error if value is not a valid number
|
|
*/
|
|
export function validateInput(value, name) {
|
|
if (typeof value !== 'number' || isNaN(value)) {
|
|
throw new Error(`Invalid ${name}: must be a number`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Format currency with symbol.
|
|
* @param amount - Amount to format
|
|
* @param symbol - Currency symbol
|
|
* @returns Formatted currency string
|
|
*/
|
|
export function formatCurrency(amount, symbol = '$') {
|
|
return `${symbol}${formatNumber(amount, 2)}`;
|
|
}
|
|
|
|
module.exports = {
|
|
formatNumber,
|
|
validateInput,
|
|
formatCurrency
|
|
}; |