Skip to content

Commit 9ea8800

Browse files
authored
Don't crash when an empty importer list is passed to the legacy API (#114)
1 parent 159fe83 commit 9ea8800

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

lib/src/legacy/importer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ export class LegacyImporterWrapper<sync extends 'sync' | 'async'>
7171
// the modern API, so we always return `null` in this case.
7272
private expectingRelativeLoad = true;
7373

74-
// TODO: Support prev from a load path
75-
7674
constructor(
7775
private readonly self: LegacyPluginThis,
7876
private readonly callbacks: Array<LegacyImporter<sync>>,
@@ -220,6 +218,8 @@ export class LegacyImporterWrapper<sync extends 'sync' | 'async'>
220218
prev: string,
221219
{fromImport}: {fromImport: boolean}
222220
): PromiseOr<LegacyImporterResult, sync> {
221+
assert(this.callbacks.length > 0);
222+
223223
const self: LegacyImporterThis = {...this.self, fromImport};
224224
self.options = {...self.options, context: self};
225225

lib/src/legacy/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,21 @@ function convertOptions<sync extends 'sync' | 'async'>(
134134
functions[signature] = wrapFunction(self, callback, sync);
135135
}
136136

137-
const importers = options.importer
138-
? [
139-
new LegacyImporterWrapper(
140-
self,
141-
options.importer instanceof Array
142-
? options.importer
143-
: [options.importer],
144-
options.includePaths ?? [],
145-
options.file ?? 'stdin',
146-
sync
147-
),
148-
]
149-
: undefined;
137+
const importers =
138+
options.importer &&
139+
(!(options.importer instanceof Array) || options.importer.length > 0)
140+
? [
141+
new LegacyImporterWrapper(
142+
self,
143+
options.importer instanceof Array
144+
? options.importer
145+
: [options.importer],
146+
options.includePaths ?? [],
147+
options.file ?? 'stdin',
148+
sync
149+
),
150+
]
151+
: undefined;
150152

151153
return {
152154
functions,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sass-embedded",
3-
"version": "1.49.8",
3+
"version": "1.49.9-dev",
44
"protocol-version": "1.0.0",
55
"compiler-version": "1.49.8",
66
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol",

0 commit comments

Comments
 (0)