Skip to content

Commit

Permalink
Parse Deprecation.forVersion on compiler side (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed May 30, 2024
1 parent 82e1590 commit 80f5a20
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
20 changes: 2 additions & 18 deletions lib/src/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,12 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import {deprecations} from './vendor/deprecations';
import {Deprecation, DeprecationOrId} from './vendor/sass';
import {DeprecationOrId} from './vendor/sass';
import {Version} from './version';

export {deprecations} from './vendor/deprecations';
export {Deprecation, DeprecationOrId, DeprecationStatus} from './vendor/sass';

/**
* Returns whether the given deprecation was active in the given version.
*/
function isActiveIn(deprecation: Deprecation, version: Version) {
const deprecatedIn = deprecation.deprecatedIn;
if (deprecation.status !== 'active' || !deprecatedIn) return false;
if (version.major > deprecatedIn.major) return true;
if (version.major < deprecatedIn.major) return false;
if (version.minor > deprecatedIn.minor) return true;
if (version.minor < deprecatedIn.minor) return false;
return version.patch >= deprecatedIn.patch;
}

/**
* Converts a mixed array of deprecations, IDs, and versions to an array of IDs
* that's ready to include in a CompileRequest.
Expand All @@ -31,9 +17,7 @@ export function getDeprecationIds(
): string[] {
return arr.flatMap(item => {
if (item instanceof Version) {
return Object.values(deprecations)
.filter(deprecation => isActiveIn(deprecation, item))
.map(deprecation => deprecation.id);
return arr.map(item => item.toString());
} else if (typeof item === 'string') {
return item;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/src/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import {
LegacyStringOptions,
Options,
StringOptions,
Importer,
FileImporter,
} from '../vendor/sass';
import {wrapFunction} from './value/wrap';
import {endOfLoadProtocol, LegacyImporterWrapper} from './importer';
Expand Down
3 changes: 3 additions & 0 deletions lib/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ export class Version implements api.Version {
parseInt(match[3])
);
}
toString(): string {
return `${this.major}.${this.minor}.${this.patch}`;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sass-embedded",
"version": "1.77.3",
"protocol-version": "2.7.0",
"protocol-version": "2.7.1",
"compiler-version": "1.77.3",
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol",
"repository": "sass/embedded-host-node",
Expand Down

0 comments on commit 80f5a20

Please sign in to comment.