diff --git a/CHANGELOG.md b/CHANGELOG.md index c1ba2ac..a08eeac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [3.0.0](https://github.com/postcss-modules-local-by-default/compare/v3.0.0-rc.2...v3.0.0) - 2020-10-13 + +### Fixes + +- compatibility with plugins other plugins +- handle animation short name +- perf + ## [3.0.0-rc.2](https://github.com/postcss-modules-local-by-default/compare/v3.0.0-rc.1...v3.0.0-rc.2) - 2020-10-11 ### BREAKING CHANGE diff --git a/package.json b/package.json index b428388..9605f10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-modules-scope", - "version": "3.0.0-rc.2", + "version": "3.0.0", "description": "A CSS Modules transform to extract export statements from local-scope classes", "main": "src/index.js", "engines": { diff --git a/src/index.js b/src/index.js index f5107a5..3197752 100644 --- a/src/index.js +++ b/src/index.js @@ -88,7 +88,7 @@ const plugin = (options = {}) => { return { postcssPlugin: "postcss-modules-scope", - OnceExit(root, { rule }) { + Once(root, { rule }) { const exports = Object.create(null); function exportScopedName(name, rawName) { @@ -188,15 +188,13 @@ const plugin = (options = {}) => { // Find any :import and remember imported names const importedNames = {}; - root.walkRules((rule) => { - if (/^:import\(.+\)$/.test(rule.selector)) { - rule.walkDecls((decl) => { - importedNames[decl.prop] = true; - }); - } + root.walkRules(/^:import\(.+\)$/, (rule) => { + rule.walkDecls((decl) => { + importedNames[decl.prop] = true; + }); }); - // Find any :local classes + // Find any :local selectors root.walkRules((rule) => { let parsedSelector = selectorParser().astSync(rule); @@ -233,30 +231,31 @@ const plugin = (options = {}) => { decl.remove(); }); + // Find any :local values rule.walkDecls((decl) => { + if (!/:local\s*\((.+?)\)/.test(decl.value)) { + return; + } + let tokens = decl.value.split(/(,|'[^']*'|"[^"]*")/); tokens = tokens.map((token, idx) => { if (idx === 0 || tokens[idx - 1] === ",") { let result = token; - const localMatch = /^(\s*):local\s*\((.+?)\)/.exec(token); - const nextLocalMatch = /:local\s*\((.+?)\)/.exec(token); + const localMatch = /:local\s*\((.+?)\)/.exec(token); if (localMatch) { - result = - localMatch[1] + - exportScopedName(localMatch[2]) + - token.substr(localMatch[0].length); - } else if (nextLocalMatch) { - const input = nextLocalMatch.input; - const matchPattern = nextLocalMatch[0]; - const matchVal = nextLocalMatch[1]; + const input = localMatch.input; + const matchPattern = localMatch[0]; + const matchVal = localMatch[1]; const newVal = exportScopedName(matchVal); + result = input.replace(matchPattern, newVal); } else { - // do nothing + return token; } + return result; } else { return token; @@ -268,14 +267,14 @@ const plugin = (options = {}) => { }); // Find any :local keyframes - root.walkAtRules((atRule) => { - if (/keyframes$/i.test(atRule.name)) { - const localMatch = /^\s*:local\s*\((.+?)\)\s*$/.exec(atRule.params); + root.walkAtRules(/keyframes$/i, (atRule) => { + const localMatch = /^\s*:local\s*\((.+?)\)\s*$/.exec(atRule.params); - if (localMatch) { - atRule.params = exportScopedName(localMatch[1]); - } + if (!localMatch) { + return; } + + atRule.params = exportScopedName(localMatch[1]); }); // If we found any :locals, insert an :export rule