Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash when an empty importer list is passed to the legacy API #114

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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