Skip to content

Conversation

@mrdziuban
Copy link
Contributor

@mrdziuban mrdziuban commented Nov 4, 2024

Fixes #348

Rather than just checking if green or blue are falsy, the code now checks if they're undefined or null.

@google-cla
Copy link

google-cla bot commented Nov 4, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.


let red: number;
if (!green || !blue) {
if (green == undefined || blue == undefined) {
Copy link
Contributor

@ntkme ntkme Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use triple equal instead of double equal if you are comparing with undefined, or otherwise linter will complain.

Suggested change
if (green == undefined || blue == undefined) {
if (green === undefined || blue === undefined) {

If you want to check both undefined and null, you have to do them separately, due to how linter is setup here. You can run linter with npm run check locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, just pushed a change to explicitly check for both undefined and null

Comment on lines 8 to 10
function isUndefinedOrNull<A>(a: A): boolean {
return a === undefined || a === null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document this, and put it in utils.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out there was already an isNullOrUndefined function in lib/src/utils.ts so I'm using that now

import {SassColor} from '../../value/color';
import {LegacyValueBase} from './base';

function isUndefinedOrNull<A>(a: A): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function isUndefinedOrNull<A>(a: A): boolean {
function isUndefinedOrNull(a: unknown): boolean {

@nex3 nex3 merged commit 2e03e8e into sass:main Nov 12, 2024
nex3 added a commit to sass/dart-sass that referenced this pull request Nov 12, 2024
nex3 added a commit to sass/dart-sass that referenced this pull request Nov 12, 2024
@mrdziuban mrdziuban deleted the more-explicit-green-blue-checks branch November 13, 2024 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LegacyColor has incorrect RGB values when either green or blue are zero

3 participants