Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b21653

Browse files
jquenseevilebottnawi
authored andcommitted
feat: values replace in selectors (#2)
BREAKING CHANGE: values replace in selectors
1 parent 1383b62 commit 0b21653

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

‎package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"autotest": "chokidar src test -c 'npm test'",
1414
"cover": "nyc mocha",
1515
"travis": "yarn lint && yarn cover",
16-
"prepublish": "yarn test"
16+
"prepublishOnly": "yarn test"
1717
},
1818
"repository": {
1919
"type": "git",
@@ -34,12 +34,12 @@
3434
"chokidar-cli": "^1.0.1",
3535
"codecov.io": "^0.1.2",
3636
"coveralls": "^3.0.2",
37-
"mocha": "^5.2.0",
3837
"eslint": "^5.9.0",
38+
"mocha": "^5.2.0",
3939
"nyc": "^13.1.0"
4040
},
4141
"dependencies": {
42-
"icss-replace-symbols": "^1.1.0",
42+
"icss-utils": "^4.0.0",
4343
"postcss": "^7.0.6"
4444
}
4545
}

‎src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

33
const postcss = require('postcss');
4-
const ICSSReplaceSymbols = require('icss-replace-symbols');
5-
const replaceSymbols = require('icss-replace-symbols');
4+
const ICSSUtils = require('icss-utils');
65

76
const matchImports = /^(.+?|\([\s\S]+?\))\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/;
87
const matchValueDefinition = /(?:\s+|^)([\w-]+):?\s+(.+?)\s*$/g;
@@ -26,7 +25,7 @@ module.exports = postcss.plugin(
2625
while ((matches = matchValueDefinition.exec(atRule.params))) {
2726
let [, /*match*/ key, value] = matches;
2827
// Add to the definitions, knowing that values can refer to each other
29-
definitions[key] = replaceSymbols.replaceAll(definitions,value);
28+
definitions[key] = ICSSUtils.replaceValueSymbols(value,definitions);
3029
atRule.remove();
3130
}
3231
};
@@ -87,7 +86,7 @@ module.exports = postcss.plugin(
8786
}
8887

8988
/* Perform replacements */
90-
ICSSReplaceSymbols.default(css, definitions);
89+
ICSSUtils.replaceSymbols(css, definitions);
9190

9291
/* Add export rules if any */
9392
if (exportDeclarations.length > 0) {

‎test/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ describe('constants', () => {
4848
);
4949
});
5050

51+
it('should replace selectors within the file', () => {
52+
test(
53+
'@value colorValue red; .colorValue { color: colorValue; }',
54+
':export {\n colorValue: red;\n}\n.red { color: red; }'
55+
);
56+
});
57+
5158
it('should import and re-export a simple constant', () => {
5259
test(
5360
'@value red from "./colors.css";',

‎yarn.lock

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,15 @@ chalk@^2.0.0, chalk@^2.1.0, chalk@^2.4.1:
354354
escape-string-regexp "^1.0.5"
355355
supports-color "^5.3.0"
356356

357+
chalk@^2.4.2:
358+
version "2.4.2"
359+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
360+
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
361+
dependencies:
362+
ansi-styles "^3.2.1"
363+
escape-string-regexp "^1.0.5"
364+
supports-color "^5.3.0"
365+
357366
chardet@^0.7.0:
358367
version "0.7.0"
359368
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
@@ -1141,9 +1150,12 @@ iconv-lite@^0.4.24, iconv-lite@^0.4.4:
11411150
dependencies:
11421151
safer-buffer ">= 2.1.2 < 3"
11431152

1144-
icss-replace-symbols@^1.1.0:
1145-
version "1.1.0"
1146-
resolved "https://registry.yarnpkg.com/icss-replace-symbols/-/icss-replace-symbols-1.1.0.tgz#06ea6f83679a7749e386cfe1fe812ae5db223ded"
1153+
icss-utils@^4.0.0:
1154+
version "4.0.0"
1155+
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-4.0.0.tgz#d52cf4bcdcfa1c45c2dbefb4ffdf6b00ef608098"
1156+
integrity sha512-bA/xGiwWM17qjllIs9X/y0EjsB7e0AV08F3OL8UPsoNkNRibIuu8f1eKTnQ8QO1DteKKTxTUAn+IEWUToIwGOA==
1157+
dependencies:
1158+
postcss "^7.0.5"
11471159

11481160
ignore-walk@^3.0.1:
11491161
version "3.0.1"
@@ -2011,6 +2023,15 @@ posix-character-classes@^0.1.0:
20112023
version "0.1.1"
20122024
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
20132025

2026+
postcss@^7.0.5:
2027+
version "7.0.14"
2028+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.14.tgz#4527ed6b1ca0d82c53ce5ec1a2041c2346bbd6e5"
2029+
integrity sha512-NsbD6XUUMZvBxtQAJuWDJeeC4QFsmWsfozWxCJPWf3M55K9iu2iMDaKqyoOdTJ1R4usBXuxlVFAIo8rZPQD4Bg==
2030+
dependencies:
2031+
chalk "^2.4.2"
2032+
source-map "^0.6.1"
2033+
supports-color "^6.1.0"
2034+
20142035
postcss@^7.0.6:
20152036
version "7.0.6"
20162037
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.6.tgz#6dcaa1e999cdd4a255dcd7d4d9547f4ca010cdc2"
@@ -2505,6 +2526,13 @@ supports-color@^5.3.0, supports-color@^5.4.0, supports-color@^5.5.0:
25052526
dependencies:
25062527
has-flag "^3.0.0"
25072528

2529+
supports-color@^6.1.0:
2530+
version "6.1.0"
2531+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"
2532+
integrity sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==
2533+
dependencies:
2534+
has-flag "^3.0.0"
2535+
25082536
table@^5.0.2:
25092537
version "5.1.0"
25102538
resolved "https://registry.yarnpkg.com/table/-/table-5.1.0.tgz#69a54644f6f01ad1628f8178715b408dc6bf11f7"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /