How to use the createSourceFile function from typescript

Find comprehensive JavaScript typescript.createSourceFile code examples handpicked from public code repositorys.

434
435
436
437
438
439
440
441
442
443
                return node;
            }
        });
};

const sourceFile = ts.createSourceFile(
    'index.ts',
    source,
    ts.ScriptTarget.ESNext,
    /* setParentNodes */ true,
fork icon116
star icon294
watch icon29

+ 3 other calls in file

573
574
575
576
577
578
579
580
581
582
583
584


/**
 * Check if UIStrings presents in the file
 */
function hasUIStrings(content) {
  const sourceFile = ts.createSourceFile('', content, ts.ScriptTarget.ESNext, true);
  return (findUIStringsNode(sourceFile) !== null);
}


/**
fork icon13
star icon33
watch icon7

+ 33 other calls in file

497
498
499
500
501
502
503
504
505
506
507
/**
 * @param {string} sourceStr String of the form 'const UIStrings = {...}'.
 * @return {Record<string, ParsedUIString>}
 */
function parseUIStrings(sourceStr) {
  const tsAst = tsc.createSourceFile('uistrings', sourceStr, tsc.ScriptTarget.ES2019, true, tsc.ScriptKind.JS);


  const extractionError = new Error('UIStrings declaration was not extracted correctly by the collect-strings regex.');
  const uiStringsStatement = tsAst.statements[0];
  if (tsAst.statements.length !== 1)
fork icon13
star icon33
watch icon7

+ 36 other calls in file

1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
// We fix this with a simple regex replace later on, but it means the
// WebGLConstants constants enum needs to be defined in the file before it can
// be used.  This block of code reads in the TS file, finds the WebGLConstants
// declaration, and then writes the file back out (in memory to source) with
// WebGLConstants being the first module.
const node = typescript.createSourceFile(
  "Source/Cesium.d.ts",
  source,
  typescript.ScriptTarget.Latest
);
fork icon0
star icon1
watch icon1

+ 1755 other calls in file

68
69
70
71
72
73
74
75
76
77
      throw e;
    }
  } else {
    throw new Error('Unexpected filename ' + filename);
  }
  return ts.createSourceFile(filename, source, 'ES5', '0');
},
readFile(filename) {
  return ts.sys.readFile(filename);
},
fork icon0
star icon0
watch icon1

258
259
260
261
262
263
264
265
266
267
if (cached) {
    return cached;
}
const content = this.readFile(fileName);
if (content !== undefined) {
    const sf = ts.createSourceFile(utils_1.workaroundResolve(fileName), content, languageVersion, true);
    if (this.cacheSourceFiles) {
        this._sourceFileCache.set(p, sf);
    }
    return sf;
fork icon0
star icon0
watch icon1

35
36
37
38
39
40
41
42
43
44
    };
}
const allowFastPath = options.typeCheck === false && !emitSourceMap;
const outputs = new Map();
const tempFilename = 'bo-default-file.js';
const tempSourceFile = ts.createSourceFile(tempFilename, content, ts.ScriptTarget.Latest, allowFastPath);
const parseDiagnostics = tempSourceFile.parseDiagnostics;
const tsOptions = {
    // We target latest so that there is no downleveling.
    target: ts.ScriptTarget.Latest,
fork icon0
star icon0
watch icon1

Other functions in typescript

Sorted by popularity

function icon

typescript.SyntaxKind is the most popular function in typescript (82777 examples)