How to use the @codemod/core.transform function in @codemod/core

To help you get started, we’ve selected a few @codemod/core 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 resugar / resugar / packages / resugar-test-runner / src / index.ts View on Github external
function transform(code: string, config?: any): string {
    const result = codemodTransform(code, {
      plugins: [...plugins.map(plugin => (config ? [plugin, config] : plugin))]
    });

    if (!result || !result.code) {
      throw new Error(`transform returned no code`);
    }

    return result.code;
  }
}
github codemod-js / codemod / packages / cli / src / transpile-requires.ts View on Github external
if (!useBabelConfig) {
    options.configFile = useBabelConfig;
  }

  if (!useBabelConfig) {
    if (TypeScriptExtensions.has(ext)) {
      presets.push(require.resolve('@babel/preset-typescript'));
    }

    presets.push([
      require.resolve('@babel/preset-env'),
      { useBuiltIns: 'entry', corejs: { version: 3, proposals: true } }
    ]);
  }

  const result = transform(code, options);

  if (!result) {
    throw new Error(`[${filename}] babel transform returned null`);
  }

  return result.code as string;
}
github decaffeinate / decaffeinate / src / stages / resugar / index.ts View on Github external
static run(content: string, options: Options): StageResult {
    const log = logger(this.name);
    log(content);

    const code = transform(content, {
      plugins: Array.from(this.getPluginsForOptions(options))
    }).code as string;

    return {
      code,
      suggestions: []
    };
  }
github codemod-js / codemod / packages / cli / src / InlineTransformer.ts View on Github external
async transform(filepath: string, content: string): Promise {
    const options: TransformOptions = {
      filename: filepath,
      babelrc: this.findBabelConfig,
      plugins: this.plugins,
      printer: this.printer
    };

    if (!this.findBabelConfig) {
      options.configFile = this.findBabelConfig;
    }

    const result = transform(content, options);

    if (!result) {
      throw new Error(`[${filepath}] babel transform returned null`);
    }

    return result.code as string;
  }
}
github resugar / resugar / script / _commands / run.ts View on Github external
export default async function main(
  args: ReadonlyArray,
  stdin: typeof process.stdin,
  stdout: typeof process.stdout
): Promise {
  const input = await readStream(stdin);
  stdout.write(transform(input, {
    plugins: [
      codemodDeclarationsBlockScope,
      codemodFunctionsArrow,
      codemodModulesCommonJS,
      codemodObjectsConcise,
      codemodObjectsDestructuring,
      codemodObjectsShorthand,
      codemodStringsTemplate
    ]
  }).code as string);
  return 0;
}

@codemod/core

Runs babel plugins for codemods, i.e. by preserving formatting using Recast.

Apache-2.0
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis

Popular @codemod/core functions

Similar packages