Skip to content

Commit c46d990

Browse files
Merge remote-tracking branch 'origin/master'
# Conflicts: # CHANGELOG.md # package.json # src/index.js
2 parents c32c7f9 + 6f8ff19 commit c46d990

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [3.0.0](https://github.com/postcss-modules-local-by-default/compare/v3.0.0-rc.2...v3.0.0) - 2020-10-13
7+
8+
### Fixes
9+
10+
- compatibility with plugins other plugins
11+
- handle animation short name
12+
- perf
13+
614
## [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
715

816
### BREAKING CHANGE

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-modules-scope",
3-
"version": "3.0.0-rc.2",
3+
"version": "3.0.0",
44
"description": "A CSS Modules transform to extract export statements from local-scope classes",
55
"main": "src/index.js",
66
"engines": {

src/index.js

+24-25
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const plugin = (options = {}) => {
8888

8989
return {
9090
postcssPlugin: "postcss-modules-scope",
91-
OnceExit(root, { rule }) {
91+
Once(root, { rule }) {
9292
const exports = Object.create(null);
9393

9494
function exportScopedName(name, rawName) {
@@ -188,15 +188,13 @@ const plugin = (options = {}) => {
188188
// Find any :import and remember imported names
189189
const importedNames = {};
190190

191-
root.walkRules((rule) => {
192-
if (/^:import\(.+\)$/.test(rule.selector)) {
193-
rule.walkDecls((decl) => {
194-
importedNames[decl.prop] = true;
195-
});
196-
}
191+
root.walkRules(/^:import\(.+\)$/, (rule) => {
192+
rule.walkDecls((decl) => {
193+
importedNames[decl.prop] = true;
194+
});
197195
});
198196

199-
// Find any :local classes
197+
// Find any :local selectors
200198
root.walkRules((rule) => {
201199
let parsedSelector = selectorParser().astSync(rule);
202200

@@ -233,30 +231,31 @@ const plugin = (options = {}) => {
233231
decl.remove();
234232
});
235233

234+
// Find any :local values
236235
rule.walkDecls((decl) => {
236+
if (!/:local\s*\((.+?)\)/.test(decl.value)) {
237+
return;
238+
}
239+
237240
let tokens = decl.value.split(/(,|'[^']*'|"[^"]*")/);
238241

239242
tokens = tokens.map((token, idx) => {
240243
if (idx === 0 || tokens[idx - 1] === ",") {
241244
let result = token;
242245

243-
const localMatch = /^(\s*):local\s*\((.+?)\)/.exec(token);
244-
const nextLocalMatch = /:local\s*\((.+?)\)/.exec(token);
246+
const localMatch = /:local\s*\((.+?)\)/.exec(token);
245247

246248
if (localMatch) {
247-
result =
248-
localMatch[1] +
249-
exportScopedName(localMatch[2]) +
250-
token.substr(localMatch[0].length);
251-
} else if (nextLocalMatch) {
252-
const input = nextLocalMatch.input;
253-
const matchPattern = nextLocalMatch[0];
254-
const matchVal = nextLocalMatch[1];
249+
const input = localMatch.input;
250+
const matchPattern = localMatch[0];
251+
const matchVal = localMatch[1];
255252
const newVal = exportScopedName(matchVal);
253+
256254
result = input.replace(matchPattern, newVal);
257255
} else {
258-
// do nothing
256+
return token;
259257
}
258+
260259
return result;
261260
} else {
262261
return token;
@@ -268,14 +267,14 @@ const plugin = (options = {}) => {
268267
});
269268

270269
// Find any :local keyframes
271-
root.walkAtRules((atRule) => {
272-
if (/keyframes$/i.test(atRule.name)) {
273-
const localMatch = /^\s*:local\s*\((.+?)\)\s*$/.exec(atRule.params);
270+
root.walkAtRules(/keyframes$/i, (atRule) => {
271+
const localMatch = /^\s*:local\s*\((.+?)\)\s*$/.exec(atRule.params);
274272

275-
if (localMatch) {
276-
atRule.params = exportScopedName(localMatch[1]);
277-
}
273+
if (!localMatch) {
274+
return;
278275
}
276+
277+
atRule.params = exportScopedName(localMatch[1]);
279278
});
280279

281280
// If we found any :locals, insert an :export rule

0 commit comments

Comments
 (0)