From de9ac1240abcb68121f1ccf91f9f40779a03efc6 Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Tue, 5 Dec 2017 12:28:11 -0800 Subject: [PATCH] WIP: pass options object to preprocess hooks So that file id (& eventually other options?) can be passed to each of the preprocess hooks --- src/index.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 081660d3d8..fb774a2fb7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,7 +50,7 @@ function parseAttributes(str: string) { return attrs; } -async function replaceTagContents(source, type: 'script' | 'style', preprocessor: Preprocessor) { +async function replaceTagContents(source, type: 'script' | 'style', preprocessor: Preprocessor, options: PreprocessOptions) { const exp = new RegExp(`<${type}([\\S\\s]*?)>([\\S\\s]*?)<\\/${type}>`, 'ig'); const match = exp.exec(source); @@ -59,7 +59,8 @@ async function replaceTagContents(source, type: 'script' | 'style', preprocessor const content: string = match[2]; const processed: { code: string, map?: SourceMap | string } = await preprocessor({ content, - attributes + attributes, + options }); if (processed && processed.code) { @@ -77,16 +78,19 @@ async function replaceTagContents(source, type: 'script' | 'style', preprocessor export async function preprocess(source: string, options: PreprocessOptions) { const { markup, style, script } = options; if (!!markup) { - const processed: { code: string, map?: SourceMap | string } = await markup({ content: source }); + const processed: { code: string, map?: SourceMap | string } = await markup({ + content: source, + options + }); source = processed.code; } if (!!style) { - source = await replaceTagContents(source, 'style', style); + source = await replaceTagContents(source, 'style', style, options); } if (!!script) { - source = await replaceTagContents(source, 'script', script); + source = await replaceTagContents(source, 'script', script, options); } return {