From 16599690a51f5423ee2c4d875fb428fb82d6766f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 2 Dec 2017 23:08:56 -0500 Subject: [PATCH] always return something --- src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 681df56fda..1ce6595062 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,6 +55,7 @@ function parseAttributes(str: string) { async function replaceTagContents(source, type: 'script' | 'style', preprocessor: Preprocessor) { const exp = new RegExp(`<${type}([\\S\\s]*?)>([\\S\\s]*?)<\\/${type}>`, 'ig'); const match = exp.exec(source); + if (match) { const attributes: Record = parseAttributes(match[1]); const content: string = match[2]; @@ -62,8 +63,17 @@ async function replaceTagContents(source, type: 'script' | 'style', preprocessor content, attributes }); - return source.slice(0, match.index) + (processed.code || content) + source.slice(0, match.index + match[0].length); + + if (processed && processed.code) { + return ( + source.slice(0, match.index) + + processed.code + + source.slice(0, match.index + match[0].length) + ); + } } + + return source; } export async function preprocess(source: string, options: PreprocessOptions) {