-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the host side of the deprecations API #279
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b24285b
Implement Deprecations API
jathak 1dcd6be
Merge branch 'main' into deprecations
jathak 70b34cf
Properly propagate deprecation types to warnings
jathak c4d8c0a
Update versions
jathak 90fd85d
Prettier fixes
jathak e83d466
Code review and changes from other PRs
jathak 37d6725
Don't update version or compiler-version
jathak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
// Copyright 2024 Google LLC. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import * as api from './vendor/sass'; | ||
|
||
export {Deprecation, DeprecationOrId, DeprecationStatus} from './vendor/sass'; | ||
|
||
export class Version implements api.Version { | ||
constructor( | ||
readonly major: number, | ||
readonly minor: number, | ||
readonly patch: number | ||
) {} | ||
static parse(version: string): Version { | ||
const match = version.match(/^(\d+)\.(\d+)\.(\d+)$/); | ||
if (match === null) { | ||
throw new Error(`Invalid version ${version}`); | ||
} | ||
return new Version( | ||
parseInt(match[1]), | ||
parseInt(match[2]), | ||
parseInt(match[3]) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Returns whether the given deprecation was active in the given version. | ||
*/ | ||
function isActiveIn(deprecation: api.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. | ||
*/ | ||
export function getDeprecationIds( | ||
arr: (api.DeprecationOrId | Version)[] | ||
): string[] { | ||
return arr.flatMap(item => { | ||
if (item instanceof Version) { | ||
return Object.values(deprecations) | ||
.filter(deprecation => isActiveIn(deprecation, item)) | ||
.map(deprecation => deprecation.id); | ||
} else if (typeof item === 'string') { | ||
return item; | ||
} | ||
return item.id; | ||
}); | ||
} | ||
|
||
export const deprecations: typeof api.deprecations = { | ||
'call-string': { | ||
id: 'call-string', | ||
status: 'active', | ||
deprecatedIn: new Version(0, 0, 0), | ||
obsoleteIn: null, | ||
description: 'Passing a string directly to meta.call().', | ||
}, | ||
elseif: { | ||
id: 'elseif', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 3, 2), | ||
obsoleteIn: null, | ||
description: '@elseif.', | ||
}, | ||
'moz-document': { | ||
id: 'moz-document', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 7, 2), | ||
obsoleteIn: null, | ||
description: '@-moz-document.', | ||
}, | ||
'relative-canonical': { | ||
id: 'relative-canonical', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 14, 2), | ||
obsoleteIn: null, | ||
}, | ||
'new-global': { | ||
id: 'new-global', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 17, 2), | ||
obsoleteIn: null, | ||
description: 'Declaring new variables with !global.', | ||
}, | ||
'color-module-compat': { | ||
id: 'color-module-compat', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 23, 0), | ||
obsoleteIn: null, | ||
description: | ||
'Using color module functions in place of plain CSS functions.', | ||
}, | ||
'slash-div': { | ||
id: 'slash-div', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 33, 0), | ||
obsoleteIn: null, | ||
description: '/ operator for division.', | ||
}, | ||
'bogus-combinators': { | ||
id: 'bogus-combinators', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 54, 0), | ||
obsoleteIn: null, | ||
description: 'Leading, trailing, and repeated combinators.', | ||
}, | ||
'strict-unary': { | ||
id: 'strict-unary', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 55, 0), | ||
obsoleteIn: null, | ||
description: 'Ambiguous + and - operators.', | ||
}, | ||
'function-units': { | ||
id: 'function-units', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 56, 0), | ||
obsoleteIn: null, | ||
description: 'Passing invalid units to built-in functions.', | ||
}, | ||
'duplicate-var-flags': { | ||
id: 'duplicate-var-flags', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 62, 0), | ||
obsoleteIn: null, | ||
description: 'Using !default or !global multiple times for one variable.', | ||
}, | ||
'null-alpha': { | ||
id: 'null-alpha', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 62, 3), | ||
obsoleteIn: null, | ||
description: 'Passing null as alpha in the JS API.', | ||
}, | ||
'abs-percent': { | ||
id: 'abs-percent', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 65, 0), | ||
obsoleteIn: null, | ||
description: 'Passing percentages to the Sass abs() function.', | ||
}, | ||
'fs-importer-cwd': { | ||
id: 'fs-importer-cwd', | ||
status: 'active', | ||
deprecatedIn: new Version(1, 73, 0), | ||
obsoleteIn: null, | ||
description: | ||
'Using the current working directory as an implicit load path.', | ||
}, | ||
import: { | ||
id: 'import', | ||
status: 'future', | ||
deprecatedIn: null, | ||
obsoleteIn: null, | ||
description: '@import rules.', | ||
}, | ||
'user-authored': { | ||
id: 'user-authored', | ||
status: 'user', | ||
deprecatedIn: null, | ||
obsoleteIn: null, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: document this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done