pull/4282/head
Maxim Matyunin 6 years ago
parent 9118bbb897
commit 4c4a39ca83

@ -80,7 +80,7 @@ async function process_markup(
return { return {
source: processed ? processed.code : source, source: processed ? processed.code : source,
dependencies: processed.dependencies, dependencies: processed.dependencies
}; };
} }
@ -91,7 +91,7 @@ async function process_script(
) { ) {
const dependencies = []; const dependencies = [];
const s = await replace_async( source = await replace_async(
source, source,
/<!--[^]*?-->|<script(\s[^]*?)?>([^]*?)<\/script>/gi, /<!--[^]*?-->|<script(\s[^]*?)?>([^]*?)<\/script>/gi,
async (match, attributes = '', content) => { async (match, attributes = '', content) => {
@ -104,15 +104,16 @@ async function process_script(
attributes: parse_attributes(attributes), attributes: parse_attributes(attributes),
filename filename
}); });
if (processed && processed.dependencies) dependencies.push(...processed.dependencies); if (processed && processed.dependencies) {
dependencies.push(...processed.dependencies);
}
return processed ? `<script${attributes}>${processed.code}</script>` : match; return processed ? `<script${attributes}>${processed.code}</script>` : match;
} }
); );
console.log(s, 'RETURREND');
return { return {
source: s, source,
dependencies, dependencies,
}; };
} }
@ -124,7 +125,7 @@ async function process_style(
) { ) {
const dependencies = []; const dependencies = [];
const s = await replace_async( source = await replace_async(
source, source,
/<!--[^]*?-->|<style(\s[^]*?)?>([^]*?)<\/style>/gi, /<!--[^]*?-->|<style(\s[^]*?)?>([^]*?)<\/style>/gi,
async (match, attributes = '', content) => { async (match, attributes = '', content) => {
@ -137,26 +138,26 @@ async function process_style(
filename filename
}); });
if (processed && processed.dependencies) dependencies.push(...processed.dependencies); if (processed && processed.dependencies) {
dependencies.push(...processed.dependencies);
}
return processed ? `<style${attributes}>${processed.code}</style>` : match; return processed ? `<style${attributes}>${processed.code}</style>` : match;
} }
); );
return { return {
source: s, source,
dependencies, dependencies,
}; };
} }
async function asyncForEach(array, callback) { async function async_for_each(array, callback) {
// eslint-disable-next-line
for (let index = 0; index < array.length; index++) { for (let index = 0; index < array.length; index++) {
// eslint-disable-next-line
await callback(array[index], index, array); await callback(array[index], index, array);
} }
} }
export default async function preprocess( export default async function preprocess(
source: string, source: string,
preprocessor: PreprocessorGroup | PreprocessorGroup[], preprocessor: PreprocessorGroup | PreprocessorGroup[],
@ -164,11 +165,12 @@ export default async function preprocess(
) { ) {
// @ts-ignore todo: doublecheck // @ts-ignore todo: doublecheck
const filename = (options && options.filename) || preprocessor.filename; // legacy const filename = (options && options.filename) || preprocessor.filename; // legacy
const strictOrder = options && options.strictOrder;
const dependencies = []; const dependencies = [];
const preprocessors = Array.isArray(preprocessor) ? preprocessor : [preprocessor]; const preprocessors = Array.isArray(preprocessor) ? preprocessor : [preprocessor];
const order = options.strictOrder const order = strictOrder
? preprocessors ? preprocessors
: [ : [
...preprocessors.map(({ markup }) => ({ markup })), ...preprocessors.map(({ markup }) => ({ markup })),
@ -176,27 +178,25 @@ export default async function preprocess(
...preprocessors.map(({ style }) => ({ style })), ...preprocessors.map(({ style }) => ({ style })),
]; ];
console.log(preprocessors); await async_for_each(order, async p => {
await asyncForEach(order, async p => {
let processed; let processed;
if (p.markup) { if (p.markup) {
processed = await process_markup(source, p.markup, filename); processed = await process_markup(source, p.markup, filename);
source = processed.source; source = processed.source;
dependencies.push(processed.dependencies); if (processed.dependencies.length) dependencies.push(...processed.dependencies);
} }
if (p.script) { if (p.script) {
processed = await process_script(source, p.script, filename); processed = await process_script(source, p.script, filename);
source = processed.source; source = processed.source;
dependencies.push(processed.dependencies); if (processed.dependencies.length) dependencies.push(...processed.dependencies);
} }
if (p.style) { if (p.style) {
processed = await process_style(source, p.style, filename); processed = await process_style(source, p.style, filename);
source = processed.source; source = processed.source;
dependencies.push(processed.dependencies); if (processed.dependencies.length) dependencies.push(...processed.dependencies);
} }
}); });

Loading…
Cancel
Save