Skip to content

Why not export a sync parse method? #119

Description

@aak1247

Since parse might be used in some pipeline operation, not all these pipelines are promise-friendly.

And this method could have been sync:

public async parseFiles(
        filePathes: string[],
        rootPath: string): Promise<File[]> {
        return filePathes
            .map((o) => {
                let scriptKind: ScriptKind = ScriptKind.Unknown;
                const parsed = parse(o);
                switch (parsed.ext.toLowerCase()) {
                    case 'js':
                        scriptKind = ScriptKind.JS;
                        break;
                    case 'jsx':
                        scriptKind = ScriptKind.JSX;
                        break;
                    case 'ts':
                        scriptKind = ScriptKind.TS;
                        break;
                    case 'tsx':
                        scriptKind = ScriptKind.TSX;
                        break;
                }
                return createSourceFile(
                    o,
                    readFileSync(o).toString(),
                    ScriptTarget.ES2015,
                    true,
                    scriptKind,
                );
            })
            .map(o => this.parseTypescript(o, rootPath));
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions