From 7e07c8e8d8380a1891fa471e20deee73214dc47c Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 4 Nov 2021 20:41:22 +0800 Subject: [PATCH 1/2] fix: loosen preprocessor types --- src/compiler/preprocess/types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/preprocess/types.ts b/src/compiler/preprocess/types.ts index 4ac441b5e6b1..af49705c25f7 100644 --- a/src/compiler/preprocess/types.ts +++ b/src/compiler/preprocess/types.ts @@ -19,8 +19,8 @@ export interface Processed { export type MarkupPreprocessor = (options: { content: string; - filename: string; -}) => Processed | Promise; + filename?: string; +}) => Processed | void | Promise; export type Preprocessor = (options: { /** @@ -33,7 +33,7 @@ export type Preprocessor = (options: { */ markup: string; filename?: string; -}) => Processed | Promise; +}) => Processed | void | Promise; export interface PreprocessorGroup { markup?: MarkupPreprocessor; From 6cc98a4b36ab441bf836e7e0d61d7330701f75f3 Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 5 Nov 2021 00:09:00 +0800 Subject: [PATCH 2/2] refactor(preprocess): fix filename type --- src/compiler/preprocess/index.ts | 11 +++++------ src/compiler/preprocess/types.ts | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/compiler/preprocess/index.ts b/src/compiler/preprocess/index.ts index c2a8e3b7d217..ab2ede29e030 100644 --- a/src/compiler/preprocess/index.ts +++ b/src/compiler/preprocess/index.ts @@ -30,7 +30,7 @@ class PreprocessResult implements Source { get_location: ReturnType; - 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 @@ -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) { @@ -206,8 +206,7 @@ export default async function preprocess( preprocessor: PreprocessorGroup | PreprocessorGroup[], options?: { filename?: string } ): Promise { - // @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]) : []; @@ -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) { diff --git a/src/compiler/preprocess/types.ts b/src/compiler/preprocess/types.ts index af49705c25f7..b1e605238db9 100644 --- a/src/compiler/preprocess/types.ts +++ b/src/compiler/preprocess/types.ts @@ -7,7 +7,7 @@ export interface Source { source: string; get_location: (search: number) => Location; file_basename: string; - filename: string; + filename?: string; } export interface Processed {