Mangler engine does not work when provided with generators
Closed this issue · 0 comments
Bug Report
- Package(s): core
- Version(s):
v0.1.24
Description
When the mangler engine of the core package is provided with a generator as Iterable
for various input values it won't work properly. This is due to the fact that a generator (typically) only iterates it's values once, whereas the mangler engine in some cases iterates over inputs multiple times. (*)
Proof of Concept
In this example the Iterable
of files provided to WebMangler is a generator of files. This will result in (a) the files not being mangled and (b) returning an empty generator.
The bug is not limited to the files input. Just by looking at the code it is clear that at least the MangleExpression
s returned by language plugins are subject to the same bug.
import webmangler from "webmangler";
import { BuiltInLanguagesSupport } from "webmangler/languages";
import { RecommendedManglers } from "webmangler/manglers";
const files = function*() {
yield { type: "css", content: "..." };
yield { type: "html", content: "..." };
yield { type: "js", content: "..." };
};
const mangledFiles = webmangler(files(), {
plugins: [new RecommendedManglers()],
languages: [new BuiltInLanguagesSupport()],
});
console.log(mangledFiles); // Will be an empty generator
(*): This bug may be present in other places in the code base as well. If you identified an instance of this bug, please report it or submit a Pull Request with a fix.