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

Commit 5c520d3

Browse files
committed
feat(sasscontext): implement sasscontext
1 parent 2f40992 commit 5c520d3

File tree

2 files changed

+73
-12
lines changed

2 files changed

+73
-12
lines changed

src/interop/file/sassContext.ts

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,53 @@
1+
import { StringMethodInterface } from '../interopUtility';
2+
import { wrapSassContext } from '../wrapSassContext';
3+
4+
/**
5+
* struct Sass_Context
6+
*/
17
interface SassContextInterface {
2-
errorStatus: any;
3-
errorMessage: any;
4-
outputString: any;
5-
sourceMapString: any;
8+
/**
9+
* Property accessor to `sass_context_get_error_status`
10+
*/
11+
errorStatus: number;
12+
/**
13+
* Property accessor to `sass_context_get_error_message`
14+
*/
15+
errorMessage: string;
16+
/**
17+
* Property accessor to `sass_context_get_output_string`
18+
*/
19+
outputString: string;
20+
/**
21+
* Property accessor to `sass_context_get_source_map_string`
22+
*/
23+
sourceMapString: string;
24+
}
25+
26+
class SassContext implements SassContextInterface {
27+
constructor(
28+
public readonly sassContextPtr: number,
29+
private readonly cwrapCtx: ReturnType<typeof wrapSassContext>,
30+
private readonly strMethod: StringMethodInterface
31+
) {}
32+
33+
public get errorStatus(): number {
34+
return this.cwrapCtx.context_get_error_status(this.sassContextPtr);
35+
}
36+
37+
public get errorMessage(): string {
38+
const messagePtr = this.cwrapCtx.context_get_error_message(this.sassContextPtr);
39+
return this.strMethod.ptrToString(messagePtr);
40+
}
41+
42+
public get outputString(): string {
43+
const outputPtr = this.cwrapCtx.context_get_output_string(this.sassContextPtr);
44+
return this.strMethod.ptrToString(outputPtr);
45+
}
46+
47+
public get sourceMapString(): string {
48+
const sourceMapPtr = this.cwrapCtx.context_get_source_map_string(this.sassContextPtr);
49+
return this.strMethod.ptrToString(sourceMapPtr);
50+
}
651
}
752

8-
class SassContext {}
53+
export { SassContextInterface, SassContext };

src/interop/wrapSassContext.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const wrapSassContext = (cwrap: cwrapSignature) => ({
1313
make_data_context: null,
1414

1515
//int sass_compile_file_context (struct Sass_File_Context* ctx);
16-
compile_file_context: null,
16+
compile_file_context: cwrap<(sassFileContextptr: number) => number>(`sass_compile_file_context`, 'number', [
17+
'number'
18+
]),
1719
//int sass_compile_data_context (struct Sass_Data_Context* ctx);
1820
compile_data_context: null,
1921

@@ -62,23 +64,37 @@ const wrapSassContext = (cwrap: cwrapSignature) => ({
6264
data_context_set_options: null,
6365

6466
//const char* sass_context_get_output_string (struct Sass_Context* ctx);
65-
context_get_output_string: null,
67+
context_get_output_string: cwrap<(sassContextPtr: number) => number>(`sass_context_get_output_string`, 'number', [
68+
'number'
69+
]),
6670
//int sass_context_get_error_status (struct Sass_Context* ctx);
67-
context_get_error_status: null,
71+
context_get_error_status: cwrap<(sassContextPtr: number) => number>(`sass_context_get_error_status`, 'number', [
72+
'number'
73+
]),
6874
//const char* sass_context_get_error_json (struct Sass_Context* ctx);
69-
context_get_error_json: null,
75+
context_get_error_json: cwrap<(sassContextPtr: number) => number>(`sass_context_get_error_json`, 'number', [
76+
'number'
77+
]),
7078
//const char* sass_context_get_error_text (struct Sass_Context* ctx);
71-
context_get_error_text: null,
79+
context_get_error_text: cwrap<(sassContextPtr: number) => number>(`sass_context_get_error_text`, 'number', [
80+
'number'
81+
]),
7282
//const char* sass_context_get_error_message (struct Sass_Context* ctx);
73-
context_get_error_message: null,
83+
context_get_error_message: cwrap<(sassContextPtr: number) => number>(`sass_context_get_error_message`, 'number', [
84+
'number'
85+
]),
7486
//const char* sass_context_get_error_file (struct Sass_Context* ctx);
7587
context_get_error_file: null,
7688
//size_t sass_context_get_error_line (struct Sass_Context* ctx);
7789
context_get_error_line: null,
7890
//size_t sass_context_get_error_column (struct Sass_Context* ctx);
7991
context_get_error_column: null,
8092
//const char* sass_context_get_source_map_string (struct Sass_Context* ctx);
81-
context_get_source_map_string: null,
93+
context_get_source_map_string: cwrap<(sassContextPtr: number) => number>(
94+
`sass_context_get_source_map_string`,
95+
'number',
96+
['number']
97+
),
8298
//char** sass_context_get_included_files (struct Sass_Context* ctx);
8399
context_get_included_files: null,
84100

0 commit comments

Comments
 (0)