|
| 1 | +# Partial Namespaces: Draft 1.0 |
| 2 | + |
| 3 | +*([Issue](https://github.com/sass/sass/issues/2800))* |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +* [Background](#background) |
| 8 | +* [Summary](#summary) |
| 9 | +* [Procedures](#procedures) |
| 10 | + * [Determining a `@use` Rule's Namespace](#determining-a-use-rules-namespace) |
| 11 | +* [Deprecation Process](#deprecation-process) |
| 12 | + |
| 13 | +## Background |
| 14 | + |
| 15 | +> This section is non-normative. |
| 16 | +
|
| 17 | +In the new Sass [module system][] as written, the implicit namespace of a `@use` |
| 18 | +rule that loads a partial with an explicit leading underscore contains that |
| 19 | +underscore. This was unintended and confusing, making the namespace look like a |
| 20 | +private identifier and making it different than the same file's namespace |
| 21 | +imported without the underscore. |
| 22 | + |
| 23 | +[module system]: ../accepted/module-system.md |
| 24 | + |
| 25 | +## Summary |
| 26 | + |
| 27 | +> This section is non-normative. |
| 28 | +
|
| 29 | +The underscore will be stripped from the namespace, so `@use "_styles"` will |
| 30 | +have the implicit namespace `styles` rather than `_styles`. |
| 31 | + |
| 32 | +## Procedures |
| 33 | + |
| 34 | +### Determining a `@use` Rule's Namespace |
| 35 | + |
| 36 | +This modifies the existing algorithm for [Determining a `@use` Rule's |
| 37 | +Namespace][] to read as follows (new text in bold): |
| 38 | + |
| 39 | +[Determining a `@use` Rule's Namespace]: ../spec/at-rules/use.md#determining-a-use-rules-namespace |
| 40 | + |
| 41 | +* If `rule` has an `'as'` clause `as`: |
| 42 | + |
| 43 | + * If `as` has an identifier, return it. |
| 44 | + |
| 45 | + * Otherwise, return `null`. The rule is global. |
| 46 | + |
| 47 | +* Let `path` be the `rule`'s URL's [path][URL path]. |
| 48 | + |
| 49 | + [URL path]: https://url.spec.whatwg.org/#concept-url-path |
| 50 | + |
| 51 | +* Let `basename` be the text after the final `/` in `path`, or the entire `path` |
| 52 | + if `path` doesn't contain `/`. |
| 53 | + |
| 54 | +* Let `module-name` be the text before the first `.` in `path`, or the entire |
| 55 | + `path` if `path` doesn't contain `.`. |
| 56 | + |
| 57 | +* **If `module-name` begins with `_`, remove the leading `_` and set |
| 58 | + `module-name` to the result.** |
| 59 | + |
| 60 | +* If `module-name` isn't a Sass identifier, throw an error. |
| 61 | + |
| 62 | +* Return `module-name`. |
| 63 | + |
| 64 | +## Deprecation Process |
| 65 | + |
| 66 | +Although this is technically a breaking change, it will be made without a |
| 67 | +deprecation process for the following reasons: |
| 68 | + |
| 69 | +* Including a leading underscore in a loaded URL is unnecessary, and very few |
| 70 | + stylesheets do it in practice. |
| 71 | + |
| 72 | +* The module system is still very young and not yet super widely used, so it's |
| 73 | + even more unlikely that leading underscores are used in `@use` statements in |
| 74 | + particular. |
| 75 | + |
| 76 | +* This is a fix for an unintended bug in the spec rather than a change to |
| 77 | + intended behavior that users were expected to rely upon. |
0 commit comments