Skip to content

Commit

Permalink
Mark options as optional in parser types
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 8, 2024
1 parent 8e55b8c commit 9263d6c
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions packages/babel-parser/src/options.ts
Expand Up @@ -5,29 +5,31 @@ import type { PluginList } from "./plugin-utils.ts";

export type SourceType = "script" | "module" | "unambiguous";

export type Options = {
sourceType: SourceType;
export interface Options {
sourceType?: SourceType;
sourceFilename?: string;
startColumn: number;
startLine: number;
allowAwaitOutsideFunction: boolean;
allowReturnOutsideFunction: boolean;
allowNewTargetOutsideFunction: boolean;
allowImportExportEverywhere: boolean;
allowSuperOutsideMethod: boolean;
allowUndeclaredExports: boolean;
plugins: PluginList;
strictMode: boolean | undefined | null;
ranges: boolean;
tokens: boolean;
createImportExpressions: boolean;
createParenthesizedExpressions: boolean;
errorRecovery: boolean;
attachComment: boolean;
annexB: boolean;
};
startColumn?: number;
startLine?: number;
allowAwaitOutsideFunction?: boolean;
allowReturnOutsideFunction?: boolean;
allowNewTargetOutsideFunction?: boolean;
allowImportExportEverywhere?: boolean;
allowSuperOutsideMethod?: boolean;
allowUndeclaredExports?: boolean;
plugins?: PluginList;
strictMode?: boolean | undefined | null;
ranges?: boolean;
tokens?: boolean;
createImportExpressions?: boolean;
createParenthesizedExpressions?: boolean;
errorRecovery?: boolean;
attachComment?: boolean;
annexB?: boolean;
}

type OptionsWithDefaults = { [P in keyof Options]-?: Options[P] };

export const defaultOptions: Options = {
export const defaultOptions: OptionsWithDefaults = {
// Source type ("script" or "module") for different semantics
sourceType: "script",
// Source filename.
Expand Down Expand Up @@ -90,7 +92,7 @@ export const defaultOptions: Options = {

// Interpret and default an options object

export function getOptions(opts?: Options | null): Options {
export function getOptions(opts?: Options | null): OptionsWithDefaults {
if (opts == null) {
return { ...defaultOptions };
}
Expand Down

0 comments on commit 9263d6c

Please sign in to comment.