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

Commit e084fe5

Browse files
committed
feat(buildoptioninterface): initial implementation
1 parent d8c4025 commit e084fe5

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/interop/context.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const wrapContextInterface = (cwrap: cwrapSignature) => ({
2727
//void sass_delete_compiler (struct Sass_Compiler* compiler);
2828
delete_compiler: null,
2929
//void sass_delete_options(struct Sass_Options* options);
30-
delete_options: null,
30+
delete_options: cwrap<(sassOptionsPtr: number) => void>(`sass_delete_options`, null, ['number']),
3131

3232
//void sass_delete_file_context (struct Sass_File_Context* ctx);
3333
delete_file_context: null,
@@ -99,6 +99,22 @@ const wrapContextInterface = (cwrap: cwrapSignature) => ({
9999
context_take_source_map_string: null
100100
});
101101

102+
const buildOptionInterface = (_asmModule: SassAsmModule, wrapped: ReturnType<typeof wrapContextInterface>) => {
103+
const { make_options, delete_options } = wrapped;
104+
105+
const create = () => {
106+
const optionsPtr = make_options();
107+
108+
return {
109+
dispose: () => delete_options(optionsPtr)
110+
};
111+
};
112+
113+
return {
114+
create
115+
};
116+
};
117+
102118
/**
103119
* Create interop interface around context.
104120
* (https://github.com/sass/libsass/blob/master/docs/api-context.md)
@@ -107,8 +123,14 @@ const wrapContextInterface = (cwrap: cwrapSignature) => ({
107123
*/
108124
const buildContext = (asmModule: SassAsmModule) => {
109125
const { cwrap } = asmModule;
110-
wrapContextInterface(cwrap);
126+
const wrapped = wrapContextInterface(cwrap);
111127
//noop
128+
129+
const options = buildOptionInterface(asmModule, wrapped);
130+
131+
return {
132+
options
133+
};
112134
};
113135

114136
export { buildContext };

0 commit comments

Comments
 (0)