Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: values should be replaced in selectors as well #2

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"autotest": "chokidar src test -c 'npm test'",
"cover": "nyc mocha",
"travis": "yarn lint && yarn cover",
"prepublish": "yarn test"
"prepublishOnly": "yarn test"
},
"repository": {
"type": "git",
Expand All @@ -34,12 +34,12 @@
"chokidar-cli": "^1.0.1",
"codecov.io": "^0.1.2",
"coveralls": "^3.0.2",
"mocha": "^5.2.0",
"eslint": "^5.9.0",
"mocha": "^5.2.0",
"nyc": "^13.1.0"
},
"dependencies": {
"icss-replace-symbols": "^1.1.0",
"icss-utils": "^4.0.0",
"postcss": "^7.0.6"
}
}
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const postcss = require('postcss');
const ICSSReplaceSymbols = require('icss-replace-symbols');
const replaceSymbols = require('icss-replace-symbols');
const ICSSUtils = require('icss-utils');

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

/* Perform replacements */
ICSSReplaceSymbols.default(css, definitions);
ICSSUtils.replaceSymbols(css, definitions);

/* Add export rules if any */
if (exportDeclarations.length > 0) {
Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ describe('constants', () => {
);
});

it('should replace selectors within the file', () => {
test(
'@value colorValue red; .colorValue { color: colorValue; }',
':export {\n colorValue: red;\n}\n.red { color: red; }'
);
});

it('should import and re-export a simple constant', () => {
test(
'@value red from "./colors.css";',
Expand Down
34 changes: 31 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,15 @@ chalk@^2.0.0, chalk@^2.1.0, chalk@^2.4.1:
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
dependencies:
ansi-styles "^3.2.1"
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chardet@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
Expand Down Expand Up @@ -1141,9 +1150,12 @@ iconv-lite@^0.4.24, iconv-lite@^0.4.4:
dependencies:
safer-buffer ">= 2.1.2 < 3"

icss-replace-symbols@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/icss-replace-symbols/-/icss-replace-symbols-1.1.0.tgz#06ea6f83679a7749e386cfe1fe812ae5db223ded"
icss-utils@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-4.0.0.tgz#d52cf4bcdcfa1c45c2dbefb4ffdf6b00ef608098"
integrity sha512-bA/xGiwWM17qjllIs9X/y0EjsB7e0AV08F3OL8UPsoNkNRibIuu8f1eKTnQ8QO1DteKKTxTUAn+IEWUToIwGOA==
dependencies:
postcss "^7.0.5"

ignore-walk@^3.0.1:
version "3.0.1"
Expand Down Expand Up @@ -2011,6 +2023,15 @@ posix-character-classes@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"

postcss@^7.0.5:
version "7.0.14"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.14.tgz#4527ed6b1ca0d82c53ce5ec1a2041c2346bbd6e5"
integrity sha512-NsbD6XUUMZvBxtQAJuWDJeeC4QFsmWsfozWxCJPWf3M55K9iu2iMDaKqyoOdTJ1R4usBXuxlVFAIo8rZPQD4Bg==
dependencies:
chalk "^2.4.2"
source-map "^0.6.1"
supports-color "^6.1.0"

postcss@^7.0.6:
version "7.0.6"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.6.tgz#6dcaa1e999cdd4a255dcd7d4d9547f4ca010cdc2"
Expand Down Expand Up @@ -2505,6 +2526,13 @@ supports-color@^5.3.0, supports-color@^5.4.0, supports-color@^5.5.0:
dependencies:
has-flag "^3.0.0"

supports-color@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"
integrity sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==
dependencies:
has-flag "^3.0.0"

table@^5.0.2:
version "5.1.0"
resolved "https://registry.yarnpkg.com/table/-/table-5.1.0.tgz#69a54644f6f01ad1628f8178715b408dc6bf11f7"
Expand Down