Skip to content

Commit aefcd4b

Browse files
chore: refactor
1 parent b18c377 commit aefcd4b

File tree

4 files changed

+78
-54
lines changed

4 files changed

+78
-54
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@ This project adheres to [Semantic Versioning](http://semver.org/).
7676
[0.0.9]: https://github.com/postcss-modules-local-by-default/compare/v0.0.8...v0.0.9
7777
[0.0.10]: https://github.com/postcss-modules-local-by-default/compare/v0.0.9...v0.0.10
7878
[0.0.11]: https://github.com/postcss-modules-local-by-default/compare/v0.0.10...v0.0.11
79-
[0.0.11]: https://github.com/postcss-modules-local-by-default/compare/v1.3.1...v2.0.0
79+
[2.0.0]: https://github.com/postcss-modules-local-by-default/compare/v1.3.1...v2.0.0
8080
[2.0.1]: https://github.com/postcss-modules-local-by-default/compare/v2.0.0...v2.0.1

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function localizeDeclValue(valueNode, context) {
201201
}
202202

203203
function localizeAnimationShorthandDeclValueNodes(nodes, context) {
204-
let validIdent = /^-?[_a-z][_a-z0-9-]*$/i;
204+
const validIdent = /^-?[_a-z][_a-z0-9-]*$/i;
205205

206206
/*
207207
The spec defines some keywords that you can use to describe properties such as the timing
@@ -238,7 +238,7 @@ function localizeAnimationShorthandDeclValueNodes(nodes, context) {
238238
$unset: Infinity
239239
};
240240

241-
let didParseAnimationName = false;
241+
const didParseAnimationName = false;
242242
const parsedAnimationKeywords = {};
243243
return nodes.map(function(valueNode) {
244244
const value =

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-modules-local-by-default",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "A CSS Modules transform to make local scope the default",
55
"main": "src/index.js",
66
"engines": {

test.js

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
var test = require('tape');
2-
var postcss = require('postcss');
3-
var plugin = require('./');
4-
var name = require('./package.json').name;
1+
'use strict';
52

6-
var tests = [
3+
const test = require('tape');
4+
const postcss = require('postcss');
5+
const plugin = require('./');
6+
const name = require('./package.json').name;
7+
8+
const tests = [
79
{
810
should: 'scope selectors',
911
input: '.foobar {}',
@@ -157,7 +159,8 @@ var tests = [
157159
{
158160
should: 'localize animation with vendor prefix',
159161
input: '.foo { -webkit-animation: bar; animation: bar; }',
160-
expected: ':local(.foo) { -webkit-animation: :local(bar); animation: :local(bar); }'
162+
expected:
163+
':local(.foo) { -webkit-animation: :local(bar); animation: :local(bar); }'
161164
},
162165
{
163166
should: 'not localize other rules',
@@ -171,23 +174,29 @@ var tests = [
171174
},
172175
{
173176
should: 'handle a complex animation rule',
174-
input: '.foo { animation: foo, bar 5s linear 2s infinite alternate, barfoo 1s; }',
175-
expected: ':local(.foo) { animation: :local(foo), :local(bar) 5s linear 2s infinite alternate, :local(barfoo) 1s; }'
177+
input:
178+
'.foo { animation: foo, bar 5s linear 2s infinite alternate, barfoo 1s; }',
179+
expected:
180+
':local(.foo) { animation: :local(foo), :local(bar) 5s linear 2s infinite alternate, :local(barfoo) 1s; }'
176181
},
177182
{
178183
should: 'handle animations where the first value is not the animation name',
179184
input: '.foo { animation: 1s foo; }',
180185
expected: ':local(.foo) { animation: 1s :local(foo); }'
181186
},
182187
{
183-
should: 'handle animations where the first value is not the animation name whilst also using keywords',
188+
should:
189+
'handle animations where the first value is not the animation name whilst also using keywords',
184190
input: '.foo { animation: 1s normal ease-out infinite foo; }',
185-
expected: ':local(.foo) { animation: 1s normal ease-out infinite :local(foo); }'
191+
expected:
192+
':local(.foo) { animation: 1s normal ease-out infinite :local(foo); }'
186193
},
187194
{
188195
should: 'handle animations with custom timing functions',
189-
input: '.foo { animation: 1s normal cubic-bezier(0.25, 0.5, 0.5. 0.75) foo; }',
190-
expected: ':local(.foo) { animation: 1s normal cubic-bezier(0.25, 0.5, 0.5. 0.75) :local(foo); }'
196+
input:
197+
'.foo { animation: 1s normal cubic-bezier(0.25, 0.5, 0.5. 0.75) foo; }',
198+
expected:
199+
':local(.foo) { animation: 1s normal cubic-bezier(0.25, 0.5, 0.5. 0.75) :local(foo); }'
191200
},
192201
{
193202
should: 'handle animations whose names are keywords',
@@ -202,7 +211,8 @@ var tests = [
202211
{
203212
should: 'handle "constructor" as animation name',
204213
input: '.foo { animation: constructor constructor; }',
205-
expected: ':local(.foo) { animation: :local(constructor) :local(constructor); }'
214+
expected:
215+
':local(.foo) { animation: :local(constructor) :local(constructor); }'
206216
},
207217
{
208218
should: 'default to global when mode provided',
@@ -247,7 +257,8 @@ var tests = [
247257
{
248258
should: 'localize keyframes',
249259
input: '@keyframes foo { from { color: red; } to { color: blue; } }',
250-
expected: '@keyframes :local(foo) { from { color: red; } to { color: blue; } }'
260+
expected:
261+
'@keyframes :local(foo) { from { color: red; } to { color: blue; } }'
251262
},
252263
{
253264
should: 'localize keyframes in global default mode',
@@ -257,8 +268,10 @@ var tests = [
257268
},
258269
{
259270
should: 'localize explicit keyframes',
260-
input: '@keyframes :local(foo) { 0% { color: red; } 33.3% { color: yellow; } 100% { color: blue; } } @-webkit-keyframes :global(bar) { from { color: red; } to { color: blue; } }',
261-
expected: '@keyframes :local(foo) { 0% { color: red; } 33.3% { color: yellow; } 100% { color: blue; } } @-webkit-keyframes bar { from { color: red; } to { color: blue; } }'
271+
input:
272+
'@keyframes :local(foo) { 0% { color: red; } 33.3% { color: yellow; } 100% { color: blue; } } @-webkit-keyframes :global(bar) { from { color: red; } to { color: blue; } }',
273+
expected:
274+
'@keyframes :local(foo) { 0% { color: red; } 33.3% { color: yellow; } 100% { color: blue; } } @-webkit-keyframes bar { from { color: red; } to { color: blue; } }'
262275
},
263276
{
264277
should: 'ignore :export statements',
@@ -274,7 +287,8 @@ var tests = [
274287
should: 'compile in pure mode',
275288
input: ':global(.foo).bar, [type="radio"] ~ .label, :not(.foo), #bar {}',
276289
options: { mode: 'pure' },
277-
expected: '.foo:local(.bar), [type="radio"] ~ :local(.label), :not(:local(.foo)), :local(#bar) {}'
290+
expected:
291+
'.foo:local(.bar), [type="radio"] ~ :local(.label), :not(:local(.foo)), :local(#bar) {}'
278292
},
279293
{
280294
should: 'compile explict global element',
@@ -381,16 +395,19 @@ var tests = [
381395
},
382396
{
383397
should: 'not modify urls without option',
384-
input: '.a { background: url(./image.png); }\n' +
398+
input:
399+
'.a { background: url(./image.png); }\n' +
385400
':global .b { background: url(image.png); }\n' +
386401
'.c { background: url("./image.png"); }',
387-
expected: ':local(.a) { background: url(./image.png); }\n' +
402+
expected:
403+
':local(.a) { background: url(./image.png); }\n' +
388404
'.b { background: url(image.png); }\n' +
389405
':local(.c) { background: url("./image.png"); }'
390406
},
391407
{
392408
should: 'rewrite url in local block',
393-
input: '.a { background: url(./image.png); }\n' +
409+
input:
410+
'.a { background: url(./image.png); }\n' +
394411
':global .b { background: url(image.png); }\n' +
395412
'.c { background: url("./image.png"); }\n' +
396413
'.d { background: -webkit-image-set(url("./image.png") 1x, url("./image2x.png") 2x); }\n' +
@@ -401,16 +418,17 @@ var tests = [
401418
'@keyframes ani2 { 0% { src: url("./image.png"); } }',
402419
options: {
403420
rewriteUrl: function(global, url) {
404-
var mode = global ? 'global' : 'local';
421+
const mode = global ? 'global' : 'local';
405422
return '(' + mode + ')' + url + '"' + mode + '"';
406423
}
407424
},
408-
expected: ':local(.a) { background: url((local\\)./image.png\\\"local\\\"); }\n' +
409-
'.b { background: url((global\\)image.png\\\"global\\\"); }\n' +
410-
':local(.c) { background: url(\"(local)./image.png\\\"local\\\"\"); }\n' +
411-
':local(.d) { background: -webkit-image-set(url(\"(local)./image.png\\\"local\\\"\") 1x, url(\"(local)./image2x.png\\\"local\\\"\") 2x); }\n' +
412-
'@font-face { src: url(\"(local)./font.woff\\\"local\\\"\"); }\n' +
413-
'@-webkit-font-face { src: url(\"(local)./font.woff\\\"local\\\"\"); }\n' +
425+
expected:
426+
':local(.a) { background: url((local\\)./image.png\\"local\\"); }\n' +
427+
'.b { background: url((global\\)image.png\\"global\\"); }\n' +
428+
':local(.c) { background: url("(local)./image.png\\"local\\""); }\n' +
429+
':local(.d) { background: -webkit-image-set(url("(local)./image.png\\"local\\"") 1x, url("(local)./image2x.png\\"local\\"") 2x); }\n' +
430+
'@font-face { src: url("(local)./font.woff\\"local\\""); }\n' +
431+
'@-webkit-font-face { src: url("(local)./font.woff\\"local\\""); }\n' +
414432
'@media screen { :local(.a) { src: url("(local)./image.png\\"local\\""); } }\n' +
415433
'@keyframes ani1 { 0% { src: url("(global)image.png\\"global\\""); } }\n' +
416434
'@keyframes :local(ani2) { 0% { src: url("(local)./image.png\\"local\\""); } }'
@@ -423,40 +441,46 @@ var tests = [
423441
{
424442
should: 'not crash on a rule without nodes',
425443
input: (function() {
426-
var inner = postcss.rule({ selector: '.b', ruleWithoutBody: true });
427-
var outer = postcss.rule({ selector: '.a' }).push(inner);
428-
var root = postcss.root().push(outer);
444+
const inner = postcss.rule({ selector: '.b', ruleWithoutBody: true });
445+
const outer = postcss.rule({ selector: '.a' }).push(inner);
446+
const root = postcss.root().push(outer);
429447
inner.nodes = undefined;
430448
return root;
431449
})(),
432450
// postcss-less's stringify would honor `ruleWithoutBody` and omit the trailing `{}`
433451
expected: ':local(.a) {\n :local(.b) {}\n}'
434452
}
435-
436453
];
437454

438-
function process (css, options) {
439-
return postcss(plugin(options)).process(css).css;
455+
function process(css, options) {
456+
return postcss(plugin(options)).process(css).css;
440457
}
441458

442-
test(name, function (t) {
443-
t.plan(tests.length);
459+
test(name, function(t) {
460+
t.plan(tests.length);
444461

445-
tests.forEach(function (testCase) {
446-
var options = testCase.options;
447-
if(testCase.error) {
448-
t.throws(function() {
449-
process(testCase.input, options);
450-
}, testCase.error, 'should ' + testCase.should);
451-
} else {
452-
t.equal(process(testCase.input, options), testCase.expected, 'should ' + testCase.should);
453-
}
454-
});
462+
tests.forEach(function(testCase) {
463+
const options = testCase.options;
464+
if (testCase.error) {
465+
t.throws(
466+
function() {
467+
process(testCase.input, options);
468+
},
469+
testCase.error,
470+
'should ' + testCase.should
471+
);
472+
} else {
473+
t.equal(
474+
process(testCase.input, options),
475+
testCase.expected,
476+
'should ' + testCase.should
477+
);
478+
}
479+
});
455480
});
456481

457-
458-
test('should use the postcss plugin api', function (t) {
459-
t.plan(2);
460-
t.ok(plugin().postcssVersion, 'should be able to access version');
461-
t.equal(plugin().postcssPlugin, name, 'should be able to access name');
482+
test('should use the postcss plugin api', function(t) {
483+
t.plan(2);
484+
t.ok(plugin().postcssVersion, 'should be able to access version');
485+
t.equal(plugin().postcssPlugin, name, 'should be able to access name');
462486
});

0 commit comments

Comments
 (0)