Skip to content

Discussion on Interpolation #13

@matthew-dean

Description

@matthew-dean

Related to #12. Moved from that issue:

For interpolators, I could see us doing one of two things:

  1. just use variable interpolation syntax for both:
.class@{#ns[@var]} { }

.class@{#ns[prop]} { }

...but that leaves a redundant @ in the first example:
2. Use a more generic interpolation syntax, such as borrowing from mustache: {{ }} (but could be another pair of something, if the language starts to look too curly-bracy. But used here just to demo concept)

.class{{#ns[@var]}} { }
.class{{#ns[prop]}} { }
// or for local
.class{{@var}} { }
.class{{$prop}} { }

Existing interpolation syntax (1) could be deprecated but still supported throughout 3.x.

For single property accessing, syntax doesn't need to change.

color: red;
border-color: $color;

One possible benefit of adopting a new interpolation syntax is that it doesn't need to just contain identifiers but could, like mustache, contain expressions:

.icon_{{ @startNum + @i + 1 }} { }

That's just a possible benefit, not a necessity.

Response from @seven-phases-max (which I agreed with):

As for the selector interpolation stuff, I would not take it so far yet. It's a big story on its own.
After all, the @{} syntax initially was invented for strings only, then when (~"@{var}") (almost accidentally) was found to also be usable in selectors, it was decided to be reduced to just @{var}.
The biggest problem with those curly braces in selectors is that they really make things harder to read because of the same symbol used for CSS {} block itself. So while @{} found its way to selector interpolation for some historical reasons, if we are about inventing a new syntax (especially if it's targeting for an arbitrary Less statements to appear there), the {{ }} is the last thing I'd vote for (ref.).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions