Skip to content

Commit

Permalink
Don't crash when an empty importer list is passed to the legacy API (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Feb 24, 2022
1 parent 159fe83 commit 9ea8800
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/src/legacy/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export class LegacyImporterWrapper<sync extends 'sync' | 'async'>
// the modern API, so we always return `null` in this case.
private expectingRelativeLoad = true;

// TODO: Support prev from a load path

constructor(
private readonly self: LegacyPluginThis,
private readonly callbacks: Array<LegacyImporter<sync>>,
Expand Down Expand Up @@ -220,6 +218,8 @@ export class LegacyImporterWrapper<sync extends 'sync' | 'async'>
prev: string,
{fromImport}: {fromImport: boolean}
): PromiseOr<LegacyImporterResult, sync> {
assert(this.callbacks.length > 0);

const self: LegacyImporterThis = {...this.self, fromImport};
self.options = {...self.options, context: self};

Expand Down
28 changes: 15 additions & 13 deletions lib/src/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,21 @@ function convertOptions<sync extends 'sync' | 'async'>(
functions[signature] = wrapFunction(self, callback, sync);
}

const importers = options.importer
? [
new LegacyImporterWrapper(
self,
options.importer instanceof Array
? options.importer
: [options.importer],
options.includePaths ?? [],
options.file ?? 'stdin',
sync
),
]
: undefined;
const importers =
options.importer &&
(!(options.importer instanceof Array) || options.importer.length > 0)
? [
new LegacyImporterWrapper(
self,
options.importer instanceof Array
? options.importer
: [options.importer],
options.includePaths ?? [],
options.file ?? 'stdin',
sync
),
]
: undefined;

return {
functions,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-embedded",
"version": "1.49.8",
"version": "1.49.9-dev",
"protocol-version": "1.0.0",
"compiler-version": "1.49.8",
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol",
Expand Down

0 comments on commit 9ea8800

Please sign in to comment.