All files / packages/fds-uif/generator-lwc/src/utils compile.ts

0% Statements 0/12
0% Branches 0/2
100% Functions 0/0
0% Lines 0/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                                         
import ts, { SourceFile } from "typescript";
 
/**
 * Compile the source file and report errors. Verifies behavior.ts output.
 *
 * @param sourceFile Root ts files
 */
export function compile(sourceFile: SourceFile) {
    // 3. Set up a custom compiler host that does not write to disk
  const filename = 'virtual.ts';
  const host = ts.createCompilerHost({});
  // Virtual file no type references
  sourceFile.typeReferenceDirectives = [];
  host.getSourceFile = (name, languageVersion) => {
    console.log('load source file:', name);
    if (name === filename) return sourceFile;
    return ts.createCompilerHost({}).getSourceFile(name, languageVersion);
  };
  // Override writeFile to do nothing
  host.writeFile = (name, text) => {
    console.log(`[Virtual File System] Skipped writing: ${name}`);
  };
 
  // 4. Create the program with the custom host
  try {
    const program = ts.createProgram([filename], {
      target: ts.ScriptTarget.ESNext,
      //paths: {
      //  'lwc': ['/node_modules/lwc']
      //}
    }, host);
    const emitResult = program.emit(); 
    console.log('emitResult', emitResult);
  } catch (e) {
    console.log(e);
  }
}