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

Function compileFile

compiler/companion/src/native/CompileNativeCommand.ts:47–102  ·  view source on GitHub ↗
(
  workspace: Workspace,
  syntaxCheck: boolean,
  options: NativeCompilerOptions,
  inputFile: string,
  modulePath: string,
)

Source from the content-addressed store, hash-verified

45}
46
47export function compileFile(
48 workspace: Workspace,
49 syntaxCheck: boolean,
50 options: NativeCompilerOptions,
51 inputFile: string,
52 modulePath: string,
53): NativeCompilerIR.Base[] {
54 const openedFile = workspace.getOpenedFile(inputFile);
55 const sourceFile = openedFile.sourceFile;
56 const typeChecker = openedFile.workspaceProject.typeChecker;
57
58 if (syntaxCheck) {
59 const diagnostics = workspace.getDiagnosticsSync(inputFile);
60 checkErrors(sourceFile, diagnostics.diagnostics);
61 }
62
63 if (Workspace.requiresTSXProcessor(inputFile)) {
64 // If we need the TSX processor, we need to go through the regular TS compiler
65 // to transpile the TSX AST before we compile the output using the NativeCompiler
66
67 const cancelToken = new CancelationTokenImpl();
68
69 const outputIR: NativeCompilerIR.Base[] = [];
70 const transforms: ts.TransformerFactory<ts.SourceFile>[] = [
71 (context) => (node) => {
72 const compiler = new NativeCompiler(node, inputFile, modulePath, typeChecker, options);
73 outputIR.push(...compiler.compile());
74
75 // Once we are done compiled with the NativeCompiler, we can ask the TS compiler to stop
76 // processing this file. We don't need TS to JS compilation.
77 cancelToken.requestCancellation();
78
79 // Return empty source file as we finished the processing
80 return context.factory.updateSourceFile(
81 node,
82 [],
83 node.isDeclarationFile,
84 undefined,
85 undefined,
86 undefined,
87 undefined,
88 );
89 return node;
90 },
91 ];
92
93 workspace.doEmitFile(inputFile, cancelToken, {
94 before: transforms,
95 });
96
97 return outputIR;
98 } else {
99 const compiler = new NativeCompiler(sourceFile, inputFile, modulePath, typeChecker, options);
100 return compiler.compile();
101 }
102}
103
104function generateNativeModuleName(relativePaths: string[]): string {

Callers 3

compileAsIRStringFunction · 0.90
compileAsCFunction · 0.90
compileNativeFunction · 0.85

Calls 8

compileMethod · 0.95
requestCancellationMethod · 0.95
checkErrorsFunction · 0.85
getOpenedFileMethod · 0.80
getDiagnosticsSyncMethod · 0.80
requiresTSXProcessorMethod · 0.80
doEmitFileMethod · 0.80
pushMethod · 0.45

Tested by 2

compileAsIRStringFunction · 0.72
compileAsCFunction · 0.72