-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(codegen): function prologue resolution edge cases #3005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b45fc62
fix(codegen): function prologue resolution edge cases
icecrasher321 8aabf06
remove hacky fallback
icecrasher321 87dcd53
case insensitive lookup
icecrasher321 e20ec7a
fix python nan and inf resolution
icecrasher321 0e9bcdf
remove template literal check
icecrasher321 c264481
fix tests
icecrasher321 12239a0
consolidate literal gen
icecrasher321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * Formats a JavaScript/TypeScript value as a code literal for the target language. | ||
| * Handles special cases like null, undefined, booleans, and Python-specific number representations. | ||
| * | ||
| * @param value - The value to format | ||
| * @param language - Target language ('javascript' or 'python') | ||
| * @returns A string literal representation valid in the target language | ||
| * | ||
| * @example | ||
| * formatLiteralForCode(null, 'python') // => 'None' | ||
| * formatLiteralForCode(true, 'python') // => 'True' | ||
| * formatLiteralForCode(NaN, 'python') // => "float('nan')" | ||
| * formatLiteralForCode("hello", 'javascript') // => '"hello"' | ||
| * formatLiteralForCode({a: 1}, 'python') // => "json.loads('{\"a\":1}')" | ||
| */ | ||
| export function formatLiteralForCode(value: unknown, language: 'javascript' | 'python'): string { | ||
| const isPython = language === 'python' | ||
|
|
||
| if (value === undefined) { | ||
| return isPython ? 'None' : 'undefined' | ||
| } | ||
| if (value === null) { | ||
| return isPython ? 'None' : 'null' | ||
| } | ||
| if (typeof value === 'boolean') { | ||
| return isPython ? (value ? 'True' : 'False') : String(value) | ||
| } | ||
| if (typeof value === 'number') { | ||
| if (Number.isNaN(value)) { | ||
| return isPython ? "float('nan')" : 'NaN' | ||
| } | ||
| if (value === Number.POSITIVE_INFINITY) { | ||
| return isPython ? "float('inf')" : 'Infinity' | ||
| } | ||
| if (value === Number.NEGATIVE_INFINITY) { | ||
| return isPython ? "float('-inf')" : '-Infinity' | ||
| } | ||
| return String(value) | ||
| } | ||
| if (typeof value === 'string') { | ||
| return JSON.stringify(value) | ||
| } | ||
| // Objects and arrays - Python needs json.loads() because JSON true/false/null aren't valid Python | ||
| if (isPython) { | ||
| return `json.loads(${JSON.stringify(JSON.stringify(value))})` | ||
| } | ||
| return JSON.stringify(value) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.