Escape string literals in codegen output
Summary:
The codegen emits string literals in generated C++, Java, and Objective-C code. These literals can contain characters that need escaping, such as quotes and backslashes, or non-ASCII characters that may cause compilation issues in native code. Credit to Akhilesh Chandra for pointing this out.
Added language-specific functions to emit string literals in generators/Utils.js. Internally it uses JSON.stringify which handles double quotes, backslashes, and ASCII control sequences. Applied this escaping to string literals emitted in the code generators.
Note: the code generator interpolates some values outside of string literals, like this (__hostFunction_${hasteModuleName}SpecJSI_${propertyName}):
return ` methodMap_["${toJavaString(propertyName)}"] = MethodMetadata {${argCount}, __hostFunction_${hasteModuleName}SpecJSI_${propertyName}};`;
This commit does not cover those scenarios.
Changelog:
[GENERAL] [FIXED] - Escape values interpolated in string literals for Turbo Native Module codegen
Test Plan:
Added a unit test for the escaping functions. yarn jest packages/react-native-codegen
Do you mind having a look at why the lint and the test_js are failing in CI and fix it, please?
@cipolleschi Thank you for the fast review! The lint errors are fixed, CI is green.