|
|
@ -86,28 +86,6 @@ async function replace_async(
|
|
|
|
return out;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default async function preprocess(
|
|
|
|
|
|
|
|
source: string,
|
|
|
|
|
|
|
|
preprocessor: PreprocessorGroup | PreprocessorGroup[],
|
|
|
|
|
|
|
|
options?: { filename?: string }
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
// @ts-ignore todo: doublecheck
|
|
|
|
|
|
|
|
const filename = (options && options.filename) || preprocessor.filename; // legacy
|
|
|
|
|
|
|
|
const dependencies = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const preprocessors = preprocessor
|
|
|
|
|
|
|
|
? Array.isArray(preprocessor) ? preprocessor : [preprocessor]
|
|
|
|
|
|
|
|
: []; // noop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const markup = preprocessors.map(p => p.markup).filter(Boolean);
|
|
|
|
|
|
|
|
const script = preprocessors.map(p => p.script).filter(Boolean);
|
|
|
|
|
|
|
|
const style = preprocessors.map(p => p.style).filter(Boolean);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sourcemap_list is sorted in reverse order from last map (index 0) to first map (index -1)
|
|
|
|
|
|
|
|
// so we use sourcemap_list.unshift() to add new maps
|
|
|
|
|
|
|
|
// https://github.com/ampproject/remapping#multiple-transformations-of-a-file
|
|
|
|
|
|
|
|
const sourcemap_list: Array<Processed['map']> = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get_replacement(
|
|
|
|
function get_replacement(
|
|
|
|
filename: string,
|
|
|
|
filename: string,
|
|
|
|
offset: number,
|
|
|
|
offset: number,
|
|
|
@ -117,7 +95,6 @@ export default async function preprocess(
|
|
|
|
prefix: string,
|
|
|
|
prefix: string,
|
|
|
|
suffix: string
|
|
|
|
suffix: string
|
|
|
|
): StringWithSourcemap {
|
|
|
|
): StringWithSourcemap {
|
|
|
|
|
|
|
|
|
|
|
|
const generated_prefix = StringWithSourcemap.from_source(
|
|
|
|
const generated_prefix = StringWithSourcemap.from_source(
|
|
|
|
filename, prefix, get_location(offset));
|
|
|
|
filename, prefix, get_location(offset));
|
|
|
|
const generated_suffix = StringWithSourcemap.from_source(
|
|
|
|
const generated_suffix = StringWithSourcemap.from_source(
|
|
|
@ -136,6 +113,28 @@ export default async function preprocess(
|
|
|
|
return map;
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default async function preprocess(
|
|
|
|
|
|
|
|
source: string,
|
|
|
|
|
|
|
|
preprocessor: PreprocessorGroup | PreprocessorGroup[],
|
|
|
|
|
|
|
|
options?: { filename?: string }
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
// @ts-ignore todo: doublecheck
|
|
|
|
|
|
|
|
const filename = (options && options.filename) || preprocessor.filename; // legacy
|
|
|
|
|
|
|
|
const dependencies = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const preprocessors = preprocessor
|
|
|
|
|
|
|
|
? Array.isArray(preprocessor) ? preprocessor : [preprocessor]
|
|
|
|
|
|
|
|
: []; // noop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const markup = preprocessors.map(p => p.markup).filter(Boolean);
|
|
|
|
|
|
|
|
const script = preprocessors.map(p => p.script).filter(Boolean);
|
|
|
|
|
|
|
|
const style = preprocessors.map(p => p.style).filter(Boolean);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sourcemap_list is sorted in reverse order from last map (index 0) to first map (index -1)
|
|
|
|
|
|
|
|
// so we use sourcemap_list.unshift() to add new maps
|
|
|
|
|
|
|
|
// https://github.com/ampproject/remapping#multiple-transformations-of-a-file
|
|
|
|
|
|
|
|
const sourcemap_list: Array<Processed['map']> = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (const fn of markup) {
|
|
|
|
for (const fn of markup) {
|
|
|
|
|
|
|
|
|
|
|
|
// run markup preprocessor
|
|
|
|
// run markup preprocessor
|
|
|
|