static translateKotlinToJs()

in src/webdemo-api.js [52:125]


  static translateKotlinToJs(
    code,
    compilerVersion,
    platform,
    args,
    hiddenDependencies,
  ) {
    const MINIMAL_VERSION_IR = '1.5.0';
    const MINIMAL_VERSION_WASM = '1.9.0';
    const MINIMAL_VERSION_SWIFT_EXPORT = '2.0.0';

    if (
      platform === TargetPlatforms.JS_IR &&
      compilerVersion < MINIMAL_VERSION_IR
    ) {
      return Promise.resolve({
        output: '',
        errors: [
          {
            severity: 'ERROR',
            message: `JS IR compiler backend accessible only since ${MINIMAL_VERSION_IR} version`,
          },
        ],
        jsCode: '',
      });
    }

    if (isWasmRelated(platform) && compilerVersion < MINIMAL_VERSION_WASM) {
      return Promise.resolve({
        output: '',
        errors: [
          {
            severity: 'ERROR',
            message: `Wasm compiler backend accessible only since ${MINIMAL_VERSION_WASM} version`,
          },
        ],
        jsCode: '',
      });
    }

    if (
      platform === TargetPlatforms.SWIFT_EXPORT &&
      compilerVersion < MINIMAL_VERSION_SWIFT_EXPORT
    ) {
      return Promise.resolve({
        output: '',
        errors: [
          {
            severity: 'ERROR',
            message: `Swift export accessible only since ${MINIMAL_VERSION_SWIFT_EXPORT} version`,
          },
        ],
        jsCode: '',
      });
    }

    return executeCode(
      API_URLS.COMPILE(platform, compilerVersion),
      code,
      compilerVersion,
      platform,
      args,
      hiddenDependencies,
    ).then(function (data) {
      let output = '';
      let errorsAndWarnings = flatten(Object.values(data.errors));
      return {
        output: output,
        errors: errorsAndWarnings,
        jsCode: data.jsCode,
        wasm: data.wasm,
      };
    });
  }