Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
feat(buildoptioninterface): initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 10, 2018
1 parent d8c4025 commit e084fe5
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/interop/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const wrapContextInterface = (cwrap: cwrapSignature) => ({
//void sass_delete_compiler (struct Sass_Compiler* compiler);
delete_compiler: null,
//void sass_delete_options(struct Sass_Options* options);
delete_options: null,
delete_options: cwrap<(sassOptionsPtr: number) => void>(`sass_delete_options`, null, ['number']),

//void sass_delete_file_context (struct Sass_File_Context* ctx);
delete_file_context: null,
Expand Down Expand Up @@ -99,6 +99,22 @@ const wrapContextInterface = (cwrap: cwrapSignature) => ({
context_take_source_map_string: null
});

const buildOptionInterface = (_asmModule: SassAsmModule, wrapped: ReturnType<typeof wrapContextInterface>) => {
const { make_options, delete_options } = wrapped;

const create = () => {
const optionsPtr = make_options();

return {
dispose: () => delete_options(optionsPtr)
};
};

return {
create
};
};

/**
* Create interop interface around context.
* (https://github.com/sass/libsass/blob/master/docs/api-context.md)
Expand All @@ -107,8 +123,14 @@ const wrapContextInterface = (cwrap: cwrapSignature) => ({
*/
const buildContext = (asmModule: SassAsmModule) => {
const { cwrap } = asmModule;
wrapContextInterface(cwrap);
const wrapped = wrapContextInterface(cwrap);
//noop

const options = buildOptionInterface(asmModule, wrapped);

return {
options
};
};

export { buildContext };

0 comments on commit e084fe5

Please sign in to comment.