`index` should return `null` for a non-existent element rather than `false` #832

Closed
nex3 opened this Issue Jul 2, 2013 · 7 comments

Projects

None yet

4 participants

@nex3

The current API for index was written before SassScript had a null type, but now that we do we should move it to return null.

We could go through a deprecation process for this, which would involve detecting whenever the return value was used somewhere where the distinction between null and false matters (e.g. index(...) == false). It's unlikely that anyone's doing that, though, so we may be able to get away with no deprecation process.

@chriseppstein
Sass member

So we'd need to make a DeprecatedFalse class or something to that effect?

@HugoGiraudel

Why not returning false? It makes sense.

@chriseppstein
Sass member

I think we should also return null instead of 0 for str-index().

@nex3

@chriseppstein wrote:
So we'd need to make a DeprecatedFalse class or something to that effect?

If we wanted to do the deprecation thing, yes.

I think we should also return null instead of 0 for str-index().

Agreed.

@HugoGiraudel wrote:
Why not returning false? It makes sense.

Because null is the standard value for indicating a lack of a result.

@chriseppstein chriseppstein referenced this issue Jul 29, 2013
Merged

Maps #864

@pdaoust

@chriseppstein I agree with returning null too -- I was just toying around with str-index() for the first time today, expecting it to work like index(), and discovered this myself. (By the way, thank you for having made index() return a falsy value rather than -1 like JavaScript does.)

@nex3

0 isn't falsy.

@pdaoust

@nex3 I was referring to the return value of index() rather than str-index().

@nex3 nex3 added a commit that referenced this issue Jan 23, 2014
@nex3 nex3 Have index() return null instead of false.
Closes #832
79bad1f
@nex3 nex3 closed this Jan 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment