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

Commit 3e8fb58

Browse files
committed
feat(sassimportentry): integrate makeimport
1 parent 8cb7e56 commit 3e8fb58

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

src/interop/importer/sassImportEntry.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { log } from '../../util/logger';
2+
import { getFnPtrHandler } from '../fnPtrHandler';
23
import { StringMethodInterface } from '../interopUtility';
34
import { wrapSassImporter } from './wrapSassImporter';
45

6+
type importCallbackType = (
7+
path: string,
8+
importEntry: SassImportEntryInterface,
9+
compiler: any
10+
) => Array<SassImportEntryInterface>;
11+
512
/**
613
* Interop interface to `Sass_Import_Entry`
714
*
@@ -42,23 +49,41 @@ class SassImportEntry implements SassImportEntryInterface {
4249
* Raw pointer to `struct Sass_Import_Entry*`
4350
* @internal
4451
*/
45-
public readonly sassImportEntryPtr: number;
52+
public sassImportEntryPtr: number;
53+
/**
54+
* Hold pointer to function added via `addFunction`, to be removed when disposing entry instance.
55+
*/
56+
private callbackPtr: number;
57+
4658
constructor(
4759
private readonly cwrapImporter: ReturnType<typeof wrapSassImporter>,
4860
private readonly strMethod: StringMethodInterface,
49-
rel: string,
50-
abs: string,
51-
source: string,
52-
sourceMap: string
53-
) {
61+
private readonly fnPtrHandler: ReturnType<typeof getFnPtrHandler>
62+
) {}
63+
64+
public makeImport(_importCallback: importCallbackType): void {
65+
function boo(_path: number, _cb: number, _comp: number) {
66+
//noop
67+
}
68+
this.callbackPtr = this.fnPtrHandler.add(boo);
69+
this.sassImportEntryPtr = this.cwrapImporter.make_importer(
70+
this.callbackPtr,
71+
0,
72+
0 /* TODO: need way to pass cookie */
73+
);
74+
75+
log(`SassImportEntry: created new instance`, { sassImportEntryPtr: this.sassImportEntryPtr });
76+
}
77+
78+
public makeImporter(rel: string, abs: string, source: string, sourceMap: string): void {
5479
//make_import_entry internally just calls make_import
5580
this.sassImportEntryPtr = this.cwrapImporter.make_import(
5681
this.strMethod.alloc(rel),
5782
this.strMethod.alloc(abs),
5883
this.strMethod.alloc(source),
5984
this.strMethod.alloc(sourceMap)
6085
);
61-
log(`SassImportEntry: created new instance`, { sassOptionsPtr: this.sassImportEntryPtr });
86+
log(`SassImportEntry: created new instance`, { sassImportEntryPtr: this.sassImportEntryPtr });
6287
}
6388

6489
public get error(): { message: string; line: number; column: number } {
@@ -100,7 +125,8 @@ class SassImportEntry implements SassImportEntryInterface {
100125

101126
public dispose(): void {
102127
this.cwrapImporter.delete_import(this.sassImportEntryPtr);
128+
this.fnPtrHandler.remove(this.callbackPtr);
103129
}
104130
}
105131

106-
export { SassImportEntryInterface, SassImportEntry };
132+
export { SassImportEntryInterface, SassImportEntry, importCallbackType };

src/interop/importer/wrapSassImporter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import { cwrapSignature } from 'emscripten-wasm-loader';
88
//TODO: verify return type / param type of cwrapped signature for Sass_Import_Entry
99
const wrapSassImporter = (cwrap: cwrapSignature) => ({
1010
//Sass_Importer_Entry sass_make_importer (Sass_Importer_Fn importer, double priority, void* cookie);
11-
make_importer: cwrap<(importFnPtr: number, cookie: number) => number>(`sass_make_importer`, 'number', [
11+
make_importer: cwrap<(importFnPtr: number, priority: number, cookie: number) => number>(
12+
`sass_make_importer`,
1213
'number',
13-
'number'
14-
]),
14+
['number', 'number', 'number']
15+
),
1516
//Sass_C_Import_Fn sass_importer_get_function (Sass_C_Import_Callback fn);
1617
importer_get_function: cwrap<(importCallbackPtr: number) => number>(`sass_importer_get_function`, 'number', [
1718
'number'

0 commit comments

Comments
 (0)