Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] update preprocessor types #6904

Merged
merged 2 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/compiler/preprocess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PreprocessResult implements Source {

get_location: ReturnType<typeof getLocator>;

constructor(public source: string, public filename: string) {
constructor(public source: string, public filename?: string) {
this.update_source({ string: source });

// preprocess source must be relative to itself or equal null
Expand Down Expand Up @@ -179,10 +179,10 @@ async function process_tag(
return { string, map, dependencies };
}

async function process_markup(filename: string, process: MarkupPreprocessor, source: Source) {
async function process_markup(process: MarkupPreprocessor, source: Source) {
const processed = await process({
content: source.source,
filename
filename: source.filename
});

if (processed) {
Expand All @@ -206,8 +206,7 @@ export default async function preprocess(
preprocessor: PreprocessorGroup | PreprocessorGroup[],
options?: { filename?: string }
): Promise<Processed> {
// @ts-ignore todo: doublecheck
const filename = (options && options.filename) || preprocessor.filename; // legacy
const filename: string | undefined = (options && options.filename) || (preprocessor as any).filename; // legacy

const preprocessors = preprocessor ? (Array.isArray(preprocessor) ? preprocessor : [preprocessor]) : [];

Expand All @@ -221,7 +220,7 @@ export default async function preprocess(
// to make debugging easier = detect low-resolution sourcemaps in fn combine_mappings

for (const process of markup) {
result.update_source(await process_markup(filename, process, result));
result.update_source(await process_markup(process, result));
}

for (const process of script) {
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/preprocess/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface Source {
source: string;
get_location: (search: number) => Location;
file_basename: string;
filename: string;
filename?: string;
}

export interface Processed {
Expand All @@ -19,8 +19,8 @@ export interface Processed {

export type MarkupPreprocessor = (options: {
content: string;
filename: string;
}) => Processed | Promise<Processed>;
filename?: string;
}) => Processed | void | Promise<Processed | void>;

export type Preprocessor = (options: {
/**
Expand All @@ -33,7 +33,7 @@ export type Preprocessor = (options: {
*/
markup: string;
filename?: string;
}) => Processed | Promise<Processed>;
}) => Processed | void | Promise<Processed | void>;

export interface PreprocessorGroup {
markup?: MarkupPreprocessor;
Expand Down