How to use the @parcel/ts-utils.LanguageServiceHost function in @parcel/ts-utils

To help you get started, we’ve selected a few @parcel/ts-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github parcel-bundler / parcel / packages / validators / typescript / src / TypeScriptValidator.js View on Github external
async validate({asset, config, options}) {
    let ts = await options.packageManager.require('typescript', asset.filePath);

    // This should never happen...
    if (!config) return;

    let {baseDir, configHash, tsconfig} = config;
    if (tsconfig && !langServiceCache[configHash]) {
      let parsedCommandLine = ts.parseJsonConfigFileContent(
        tsconfig,
        ts.sys,
        baseDir,
      );

      langServiceCache[configHash] = ts.createLanguageService(
        new LanguageServiceHost(options.inputFS, ts, parsedCommandLine),
        ts.createDocumentRegistry(),
      );
    }

    if (!langServiceCache[configHash]) return;

    const diagnostics = langServiceCache[configHash].getSemanticDiagnostics(
      asset.filePath,
    );

    let validatorResult = {
      warnings: [],
      errors: [],
    };

    if (diagnostics.length > 0) {

@parcel/ts-utils

MIT
Latest version published 8 months ago

Package Health Score

85 / 100
Full package analysis

Similar packages