From 12c11573492eefe036109c32a0fbc2fe04a13a37 Mon Sep 17 00:00:00 2001 From: Maxime LUCE Date: Wed, 7 Apr 2021 13:05:48 +0200 Subject: [PATCH 01/22] feat: pass source markup to transformers (if provided) --- src/autoProcess.ts | 15 ++++++++++++--- src/modules/markup.ts | 9 ++++++++- src/modules/tagInfo.ts | 2 ++ src/processors/typescript.ts | 2 ++ src/types/index.ts | 1 + test/autoProcess/externalFiles.test.ts | 10 +++++++--- test/modules/modules.test.ts | 1 + test/transformers/typescript.test.ts | 1 + 8 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/autoProcess.ts b/src/autoProcess.ts index c1f05dd5..3951ea7c 100644 --- a/src/autoProcess.ts +++ b/src/autoProcess.ts @@ -60,7 +60,7 @@ type AutoPreprocessOptions = { export const transform = async ( name: string, options: TransformerOptions, - { content, map, filename, attributes }: TransformerArgs, + { content, markup, map, filename, attributes }: TransformerArgs, ): Promise => { if (options === false) { return { code: content }; @@ -75,6 +75,7 @@ export const transform = async ( return transformer({ content, + markup, filename, map, attributes, @@ -151,6 +152,7 @@ export function sveltePreprocess( ): Preprocessor => async (svelteFile) => { let { content, + markup, filename, lang, alias, @@ -187,6 +189,7 @@ export function sveltePreprocess( const transformed = await transform(lang, transformerOptions, { content, + markup, filename, attributes, }); @@ -205,6 +208,7 @@ export function sveltePreprocess( if (transformers.replace) { const transformed = await transform('replace', transformers.replace, { content, + markup: content, filename, }); @@ -221,11 +225,13 @@ export function sveltePreprocess( const script: PreprocessorGroup['script'] = async ({ content, attributes, + markup: fullMarkup, filename, }) => { const transformResult: Processed = await scriptTransformer({ content, attributes, + markup: fullMarkup, filename, }); @@ -235,7 +241,7 @@ export function sveltePreprocess( const transformed = await transform( 'babel', getTransformerOptions('babel'), - { content: code, map, filename, attributes }, + { content: code, markup: fullMarkup, map, filename, attributes }, ); code = transformed.code; @@ -250,11 +256,13 @@ export function sveltePreprocess( const style: PreprocessorGroup['style'] = async ({ content, attributes, + markup: fullMarkup, filename, }) => { const transformResult = await cssTransformer({ content, attributes, + markup: fullMarkup, filename, }); @@ -275,6 +283,7 @@ export function sveltePreprocess( const transformed = await transform('postcss', postcssOptions, { content: code, + markup: fullMarkup, map, filename, attributes, @@ -288,7 +297,7 @@ export function sveltePreprocess( const transformed = await transform( 'globalStyle', getTransformerOptions('globalStyle'), - { content: code, map, filename, attributes }, + { content: code, markup: fullMarkup, map, filename, attributes }, ); code = transformed.code; diff --git a/src/modules/markup.ts b/src/modules/markup.ts index 704842fd..21ac30db 100644 --- a/src/modules/markup.ts +++ b/src/modules/markup.ts @@ -17,7 +17,13 @@ export async function transformMarkup( /** If no