Skip to content

Chore release 3.0.0 #27

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 3 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
chore(release): 3.0.0
  • Loading branch information
alexander-akait committed Oct 13, 2020
commit 74e3744414d009c0266687b8f1526f435994f23f
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
49 changes: 24 additions & 25 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down