Add null literal. #374

Closed
wants to merge 2 commits into
from

3 participants

@petebrowne

Modified pull request from #361 with suggested changes.

I've left string operations with nulls as they were:

selector {
  property: 'foo' + null; // 'foo'
  property: 'foo' - null; // 'foo-'
  // etc...
}

But added a SyntaxError whenever a null is involved in other operations:

selector {
  property: null + 1; // Sass::SyntaxError
  property: black / null; // Sass::SyntaxError
  // etc...
}

Also, we discussed properties not printing when they have empty values. Currently, a SyntaxError is thrown in that case. Is there any reason to change from this?

@petebrowne petebrowne referenced this pull request May 2, 2012
Closed

Add `nil` literal #361

@chriseppstein
Sass member

@petebrowne The reason to omit properties that are set to null, an empty string, or an empty list is that it optimizes a very common case of omitting a property that not explicitly passed without a bunch of @if boilerplate. It's also not obviously a conceptual error because if you set a property to nothing has a very similar feeling to not setting it.

@petebrowne

The following will still throw a SyntaxError:

selector {
  property: ;
}

But properties with resolved values that are empty are omitted:

$null-value: null;

selector {
  a: null-value;
  b: $null;
  c: 'foo';
}

Would produce:

selector {
  c: 'foo'; }
@nex3 nex3 added a commit that closed this pull request May 11, 2012
@nex3 nex3 Merge branch 'null-literal'
Closes #374
709c5a9
@nex3 nex3 closed this in 709c5a9 May 11, 2012
@nex3 nex3 added a commit that referenced this pull request May 11, 2012
@nex3 nex3 Disallow null in String operations.
Update #374
a78bba7
@nex3 nex3 added a commit that referenced this pull request May 11, 2012
@nex3 nex3 Mention null in @if documentation.
Update #374
8ca7e2a
@nex3

I merged this in, with the change that null now throws an error for all non-boolean operations, including with strings.

@petebrowne

Awesome! @chriseppstein, @nex3 Thanks for the help & suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment