|
| 1 | +// Copyright 2026 Google LLC. Use of this source code is governed by an |
| 2 | +// MIT-style license that can be found in the LICENSE file or at |
| 3 | +// https://opensource.org/licenses/MIT. |
| 4 | + |
| 5 | +import {hash} from 'immutable'; |
| 6 | + |
| 7 | +import {Value} from './index'; |
| 8 | + |
| 9 | +/** A first-class SassScript module. */ |
| 10 | +export class SassModule extends Value { |
| 11 | + /** |
| 12 | + * This is the unique ID that the compiler uses to determine which module it |
| 13 | + * refers to. |
| 14 | + * |
| 15 | + * This is marked as public so that the protofier can access it, but it's not |
| 16 | + * part of the package's public API and should not be accessed by user code. |
| 17 | + * It may be renamed or removed without warning in the future. |
| 18 | + */ |
| 19 | + readonly id: number; |
| 20 | + |
| 21 | + /** |
| 22 | + * This is the unique context that the host uses to determine which |
| 23 | + * compilation this module belongs to. |
| 24 | + * |
| 25 | + * This is marked as public so that the protofier can access it, but it's not |
| 26 | + * part of the package's public API and should not be accessed by user code. |
| 27 | + * It may be renamed or removed without warning in the future. |
| 28 | + */ |
| 29 | + readonly compileContext: symbol; |
| 30 | + |
| 31 | + constructor(id: number, compileContext: symbol) { |
| 32 | + super(); |
| 33 | + this.id = id; |
| 34 | + this.compileContext = compileContext; |
| 35 | + } |
| 36 | + |
| 37 | + equals(other: Value): boolean { |
| 38 | + return ( |
| 39 | + other instanceof SassModule && |
| 40 | + other.compileContext === this.compileContext && |
| 41 | + other.id === this.id |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + hashCode(): number { |
| 46 | + return hash(this.id); |
| 47 | + } |
| 48 | + |
| 49 | + toString(): string { |
| 50 | + return `<compiler module ${this.id}>`; |
| 51 | + } |
| 52 | + |
| 53 | + assertModule(): SassModule { |
| 54 | + return this; |
| 55 | + } |
| 56 | +} |
0 commit comments