Skip to content

Commit

Permalink
perf: simpler error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Anidetrix committed May 10, 2020
1 parent 247693c commit 438d5b1
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export default (options: Options = {}): Plugin => {
deps: new Set(),
assets: new Map<string, Uint8Array>(),
warn: this.warn.bind(this),
error: this.error.bind(this),
plugin: this,
options: {},
};
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/less/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const loader: Loader<LESSLoaderOptions> = {
test: /\.less$/i,
async process({ code, map }) {
const less = await loadModule("less");
if (!less) this.error("You need to install `less` package in order to process Less files");
if (!less) throw new Error("You need to install `less` package in order to process Less files");

const res = await less.render(code, {
...this.options,
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/postcss/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const loader: Loader<PostCSSLoaderOptions> = {
async process({ code, map, extracted }) {
const { options } = this;

const config = await loadConfig(this.id, options.config).catch(this.error);
const config = await loadConfig(this.id, options.config);

const plugins = [
...[
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/sass/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const loader: Loader<SASSLoaderOptions> = {
async process({ code, map }) {
const { options } = this;

const [sass, type] = await loadSass(options.impl).catch(this.error);
const [sass, type] = await loadSass(options.impl);

// `fibers` doesn't work in testing
const useFibers = options.fibers ?? (type === "sass" && process.env.NODE_ENV !== "test");
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/stylus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const loader: Loader<StylusLoaderOptions> = {
async process({ code, map }) {
const stylus = await loadModule("stylus");
if (!stylus)
this.error("You need to install `stylus` package in order to process Stylus files");
throw new Error("You need to install `stylus` package in order to process Stylus files");

const style = stylus(code, { ...this.options })
.set("filename", this.id)
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ export type LoaderContext<TLoaderOptions = ObjectWithUnknownProps> = {
readonly assets: Map<string, Uint8Array>;
/** Function for emitting a waring */
readonly warn: PluginContext["warn"];
/** Function for emitting an error */
readonly error: PluginContext["error"];
/** https://rollupjs.org/guide/en#plugin-context */
readonly plugin: PluginContext;
};
Expand Down

0 comments on commit 438d5b1

Please sign in to comment.