Skip to content

Update to PostCSS 5.x #17

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

Merged
merged 2 commits into from
Sep 15, 2015
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"homepage": "https://github.com/geelen/postcss-modules-scope",
"dependencies": {
"css-selector-tokenizer": "^0.5.0",
"postcss": "^4.1.11"
"postcss": "^5.0.4"
},
"devDependencies": {
"babel": "^5.4.7",
Expand Down
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {

// Find any :import and remember imported names
let importedNames = {};
css.eachRule(rule => {
css.walkRules(rule => {
if(/^:import\(.+\)$/.test(rule.selector)) {
rule.eachDecl(decl => {
rule.walkDecls(decl => {
importedNames[decl.prop] = true;
});
}
});

// Find any :local classes
css.eachRule(rule => {
css.walkRules(rule => {
let selector = Tokenizer.parse(rule.selector);
let newSelector = traverseNode(selector);
rule.selector = Tokenizer.stringify(newSelector);
rule.eachDecl("composes", decl => {
rule.walkDecls("composes", decl => {
let localNames = getSingleLocalNamesForComposes(selector);
let classes = decl.value.split(/\s+/);
classes.forEach((className) => {
Expand All @@ -110,9 +110,9 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
throw decl.error("referenced class name \"" + className + "\" in composes not found");
}
});
decl.removeSelf();
decl.remove();
});
rule.eachDecl(decl => {
rule.walkDecls(decl => {
var tokens = decl.value.split(/(,|'[^']*'|"[^"]*")/);
tokens = tokens.map((token, idx) => {
if(idx === 0 || tokens[idx - 1] === ',') {
Expand All @@ -131,7 +131,7 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
});

// Find any :local keyframes
css.eachAtRule(atrule => {
css.walkAtRules(atrule => {
if(/keyframes$/.test(atrule.name)) {
var localMatch = /^\s*:local\s*\((.+?)\)\s*$/.exec(atrule.params);
if(localMatch) {
Expand All @@ -148,7 +148,7 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
nodes: exportedNames.map(exportedName => postcss.decl({
prop: exportedName,
value: exports[exportedName].join(" "),
before: "\n ",
raws: { before: "\n " },
_autoprefixerDisabled: true
}))
}));
Expand Down
2 changes: 1 addition & 1 deletion test/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var postcss = require("postcss");
var processor = require("../");

function generateInvalidCSS(css) {
css.eachDecl(function(decl) {
css.walkDecls(function(decl) {
decl.value = decl.value.replace(/_colon_/g, ":"); // because using a : in the tests would make it invalid CSS.
});
}
Expand Down