Skip to content

Commit

Permalink
Fix browser files to have the same API as the nodejs ones (#9004)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Nov 9, 2018
1 parent 74f969b commit 504b331
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
25 changes: 20 additions & 5 deletions packages/babel-core/src/transform-file-browser.js
@@ -1,14 +1,29 @@
// @flow
import type { FileResult } from "./transformation";

export default function transformFile(
filename: string,
opts?: Object = {},
callback: (?Error, FileResult | null) => void,
// duplicated from transform-file so we do not have to import anything here
type TransformFile = {
(filename: string, callback: Function): void,
(filename: string, opts: ?Object, callback: Function): void,
};

export const transformFile: TransformFile = (function transformFile(
filename,
opts,
callback,
) {
if (typeof opts === "function") {
callback = opts;
}

callback(new Error("Transforming files is not supported in browsers"), null);
}: Function);

export function transformFileSync() {
throw new Error("Transforming files is not supported in browsers");
}

export function transformFileAsync() {
return Promise.reject(
new Error("Transforming files is not supported in browsers"),
);
}
5 changes: 0 additions & 5 deletions packages/babel-core/src/transform-file-sync-browser.js

This file was deleted.

8 changes: 8 additions & 0 deletions packages/babel-core/src/transform-file.js
Expand Up @@ -9,6 +9,14 @@ import {
type FileResultCallback,
} from "./transformation";

import typeof * as transformFileBrowserType from "./transform-file-browser";
import typeof * as transformFileType from "./transform-file";

// Kind of gross, but essentially asserting that the exports of this module are the same as the
// exports of transform-file-browser, since this file may be replaced at bundle time with
// transform-file-browser.
((({}: any): $Exact<transformFileBrowserType>): $Exact<transformFileType>);

type TransformFile = {
(filename: string, callback: FileResultCallback): void,
(filename: string, opts: ?InputOptions, callback: FileResultCallback): void,
Expand Down

0 comments on commit 504b331

Please sign in to comment.