Type-check options.js and index.js (#490)

This commit is contained in:
Andy
2017-04-26 14:18:17 -07:00
committed by Henry Zhu
parent 7627c5a2be
commit 47cade874c
3 changed files with 29 additions and 20 deletions

View File

@@ -1,17 +1,21 @@
// @flow
// A second optional argument can be given to further configure
// the parser process. These options are recognized:
export const defaultOptions: {
sourceType: string,
sourceFilename: any,
startLine: number,
allowReturnOutsideFunction: boolean,
allowImportExportEverywhere: boolean,
allowSuperOutsideMethod: boolean,
plugins: Array<string>,
strictMode: any,
ranges: boolean,
} = {
export type Options = {
sourceType: "script" | "module";
sourceFilename?: string;
startLine: number;
allowReturnOutsideFunction: boolean;
allowImportExportEverywhere: boolean;
allowSuperOutsideMethod: boolean;
plugins: $ReadOnlyArray<string>;
strictMode: ?boolean;
ranges: boolean;
};
export const defaultOptions: Options = {
// Source type ("script" or "module") for different semantics
sourceType: "script",
// Source filename.
@@ -44,8 +48,8 @@ export const defaultOptions: {
// Interpret and default an options object
export function getOptions(opts?: Object): Object {
const options = {};
export function getOptions(opts: ?Options): Options {
const options: any = {};
for (const key in defaultOptions) {
options[key] = opts && key in opts ? opts[key] : defaultOptions[key];
}