question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Namespacing modules

See original GitHub issue

Right now the only way to namespace a module is by nesting in a BEM format which gets messy real quick. I propose that a @namespace syntax be introduced. With this we could have:

// _mod-module.scss
@namespace 'mod-module';
.foo{}
.bar{}

that interprets as this in CSS:

/* app.css */
.mod-module__foo{}
.mod-module__bar{}

Another option would be to leave the name spacing to when the module is being imported. This way we can specify modules we want to be namespaced from the manifest/index Sass file

// _mod-module.scss
.foo{}
.bar{}
@import 'mod-module', 'modModule';

this way the @namespace syntax is not required so it produces:

/* app.css */
.modModule__foo{}
.modModule__bar{}

taking the name of the namespace as second argument to @import

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
josephrexmecommented, May 19, 2017

I agree but there’s a solution to everything. Using ack, this would find every selectors you need for the nested syntax:

ack --scss -l -Q .mod-module | ack -x '&__foo'

and for the new proposed syntax which is:

@module '.mod-module';

.foo{}
.bar{}

this should do the search:

ack --scss -l -Q .mod-module | ack -x 'foo'

As you’ve said it should be coupled with the module system but we have that better in Sass right now and not CSS. Hopefully we get houdini soon and all these can just be added extensions for CSS but Sass is the biggest hope for such a feature now. I hope this can be looked into more closely and reconsidered

0reactions
ArmorDarkscommented, May 19, 2017

To be honest, when working with BEM, I do not recommend any form of concatenation, even &__foo {}, since it makes search-n-finding of such selectors much harder, especially in large projects. So, whole idea with namespacing as part of Sass feature sounds very vague for me.

At least for now I don’t see how Sass could handle this well, It should be part of CSS and closely coupled with imports (module system), then we won’t have obscurity and A LOT of potential edge cases introduced by Sass-only directive.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Namespaces and Modules - TypeScript
Namespaces are a TypeScript-specific way to organize code. Namespaces are simply named JavaScript objects in the global namespace. This makes namespaces a very ......
Read more >
Ruby Primer - Modules as Namespaces - RubyMonk
Namespacing is a way of bundling logically related objects together. Modules serve as a convenient tool for this. This allows classes or modules...
Read more >
Namespacing With Modules · A Guide to Porting C ... - locka99
C++ namespaces allow you to group your functions, variables and classes into logical blocks and allow the compiler to disambiguate them from other...
Read more >
Modules | Vuex
Namespacing #. By default, actions and mutations are still registered under the global namespace - this allows multiple modules to react to the ......
Read more >
Module Files Are Namespaces - Learning Python by - O'Reilly
In Python-speak, modules are a namespace—a place where names are created. And names that live in a module are called its attributes. Technically,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found