MCPcopy Create free account
hub / github.com/Snapchat/Valdi / formatJsModule

Function formatJsModule

valdi/src/valdi/runtime/JavaScript/JavaScriptUtils.cpp:770–788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

768}
769
770std::string formatJsModule(const std::string_view& jsModule) {
771 std::string_view modulePrefix = "(function(require, module, exports) { ";
772 std::string_view moduleSuffix = "\n})";
773
774 std::string_view preamble;
775 if (!hasPrefix(jsModule, 0, "\"use strict\";\n")) {
776 preamble = "if (module) module.sourceMapLineOffset = 1;\n";
777 }
778
779 std::string formattedModule;
780 formattedModule.reserve(modulePrefix.size() + preamble.size() + jsModule.size() + moduleSuffix.size());
781 formattedModule.append(modulePrefix);
782 formattedModule.append(preamble);
783
784 formattedModule.append(reinterpret_cast<const char*>(jsModule.data()), jsModule.size());
785 formattedModule.append(moduleSuffix);
786
787 return formattedModule;
788}
789
790static uint32_t kPreCompiledJsModuleMagic = 0x0100C634;
791

Callers 3

preCompileMethod · 0.85
loadJsModuleFromBytesMethod · 0.85
preCompileMethod · 0.85

Calls 5

appendMethod · 0.65
hasPrefixFunction · 0.50
reserveMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected