|
1 | 1 | import { log } from '../../util/logger';
|
| 2 | +import { getFnPtrHandler } from '../fnPtrHandler'; |
2 | 3 | import { StringMethodInterface } from '../interopUtility';
|
3 | 4 | import { wrapSassImporter } from './wrapSassImporter';
|
4 | 5 |
|
| 6 | +type importCallbackType = ( |
| 7 | + path: string, |
| 8 | + importEntry: SassImportEntryInterface, |
| 9 | + compiler: any |
| 10 | +) => Array<SassImportEntryInterface>; |
| 11 | + |
5 | 12 | /**
|
6 | 13 | * Interop interface to `Sass_Import_Entry`
|
7 | 14 | *
|
@@ -42,23 +49,41 @@ class SassImportEntry implements SassImportEntryInterface {
|
42 | 49 | * Raw pointer to `struct Sass_Import_Entry*`
|
43 | 50 | * @internal
|
44 | 51 | */
|
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 | + |
46 | 58 | constructor(
|
47 | 59 | private readonly cwrapImporter: ReturnType<typeof wrapSassImporter>,
|
48 | 60 | 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 { |
54 | 79 | //make_import_entry internally just calls make_import
|
55 | 80 | this.sassImportEntryPtr = this.cwrapImporter.make_import(
|
56 | 81 | this.strMethod.alloc(rel),
|
57 | 82 | this.strMethod.alloc(abs),
|
58 | 83 | this.strMethod.alloc(source),
|
59 | 84 | this.strMethod.alloc(sourceMap)
|
60 | 85 | );
|
61 |
| - log(`SassImportEntry: created new instance`, { sassOptionsPtr: this.sassImportEntryPtr }); |
| 86 | + log(`SassImportEntry: created new instance`, { sassImportEntryPtr: this.sassImportEntryPtr }); |
62 | 87 | }
|
63 | 88 |
|
64 | 89 | public get error(): { message: string; line: number; column: number } {
|
@@ -100,7 +125,8 @@ class SassImportEntry implements SassImportEntryInterface {
|
100 | 125 |
|
101 | 126 | public dispose(): void {
|
102 | 127 | this.cwrapImporter.delete_import(this.sassImportEntryPtr);
|
| 128 | + this.fnPtrHandler.remove(this.callbackPtr); |
103 | 129 | }
|
104 | 130 | }
|
105 | 131 |
|
106 |
| -export { SassImportEntryInterface, SassImportEntry }; |
| 132 | +export { SassImportEntryInterface, SassImportEntry, importCallbackType }; |
0 commit comments