Skip to content

Commit 9cb45b0

Browse files
author
Alexey Litvinov
committed
Prefix hashes with underscores based on CSS spec
1 parent 08341bc commit 9cb45b0

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
.gitignore
33
.npmignore
44
.travis.yml
5-
test.js
5+
test
66
yarn.lock

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Helper for building generic names, similar to webpack",
55
"main": "index.js",
66
"scripts": {
7-
"test": "tape test.js"
7+
"test": "tape test/*.js"
88
},
99
"repository": {
1010
"type": "git",

test/cssspec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
const genericNames = require('../index');
4+
const test = require('tape');
5+
6+
// According to the CSS spec, identifiers cannot
7+
// start with a digit, two hyphens, or a hyphen
8+
// followed by a digit.
9+
//
10+
// relates: https://github.com/webpack/css-loader/commit/da27c07d0df25a38699344c13b6614c53a469fd9
11+
12+
test('identity', t => {
13+
const generate = genericNames('[local]');
14+
15+
t.equal(generate('foo', '/test/case/source.css'), 'foo');
16+
t.end();
17+
});
18+
19+
test('leading digit', t => {
20+
const generate = genericNames('0[local]');
21+
22+
t.equal(generate('foo', '/test/case/source.css'), '_0foo');
23+
t.end();
24+
});
25+
26+
test('leading digit in the token', t => {
27+
const generate = genericNames('[local]');
28+
29+
t.equal(generate('0foo', '/test/case/source.css'), '_0foo');
30+
t.end();
31+
});
32+
33+
test('leading two hyphens', t => {
34+
const generate = genericNames('--[local]');
35+
36+
t.equal(generate('foo', '/test/case/source.css'), '_--foo');
37+
t.end();
38+
});
39+
40+
test('leading hyphen and digit', t => {
41+
const generate = genericNames('-0[local]');
42+
43+
t.equal(generate('foo', '/test/case/source.css'), '_-0foo');
44+
t.end();
45+
});

test.js renamed to test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const genericNames = require('./index');
3+
const genericNames = require('../index');
44
const test = require('tape');
55

66
const pattern = '[name]__[local]___[hash:base64:5]';

0 commit comments

Comments
 (0)