Skip to content

Commit bf2a726

Browse files
author
Michael Vurchio
committed
Stop using regex named grouped in favor of node 8 supports
1 parent 9d0ef3a commit bf2a726

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

CHANGELOG.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
# Svelte preprocess CSS Modules, changelog
22

3+
## 1.3.1 (Nov 22, 2020)
4+
Add support for old version of nodes (node 8 & node 10 tested)
5+
36
## 1.3.0 (Nov 22, 2020)
4-
- Feature: CSS Modules from imports
5-
- Fix: *global selector* Regex is now working with an attached bracket to the selector (missing space was throwing an error) `.myclass{ }`
6-
- Dev: use of typescript, set up eslint and prettier
7+
8+
### Feature
9+
Apply CSS Modules from imported stylesheets
10+
11+
### Fixes
12+
*global selector* Regex is now working with an attached bracket to the selector (missing space was throwing an error) `.myclass{ }`
13+
14+
### Plugin Development
15+
Set up typescript, eslint and prettier
716

817
## 1.2.1 (Oct 31, 2020)
918
- Fix class chaining and pseudo selector [pull request #8](https://github.com/micantoine/svelte-preprocess-cssmodules/pull/8)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-preprocess-cssmodules",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "Svelte preprocessor to generate CSS Modules classname on Svelte components",
55
"keywords": [
66
"svelte",

src/lib/patterns.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const PATTERN_MODULE = /\$(style)?\.(:?[\w\d-]*)/gm;
22
export const PATTERN_PATH_UNALLOWED = /[<>:"/\\|?*]/g;
33
export const PATTERN_STYLE = /<style(\s[^]*?)?>([^]*?)<\/style>/gi;
44
export const PATTERN_IMPORT = /(?<!\/\/\s*)import\s*(?:(.+)\s+from\s+)?['|"](.+?(s?css))['|"];?/gm;
5-
export const PATTERN_CLASS_SELECTOR = /\.(?<className>.+?(?=\W)+)(?![-_])/g;
5+
export const PATTERN_CLASS_SELECTOR = /\.(.+?(?=\W)+)(?![-_])/g;
66

77
export const PATTERN_CLASS_DIRECTIVE = (className: string): RegExp =>
88
new RegExp(`<.+\\s*class:(${className})\\b`, 'gm');

src/processors/parseMarkup.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const parseMarkup = async (
9696

9797
const classlist = new Map();
9898
Array.from(matchAll(fileContent, PATTERN_CLASS_SELECTOR)).forEach((matchItem) => {
99+
const className = matchItem[1];
99100
// set array from exported className
100101
const destructuredImportRegex = /\{([\w,\s]+)\}/gm;
101102
const isDestructuredImport: boolean = varName.search(destructuredImportRegex) !== -1;
@@ -109,7 +110,7 @@ const parseMarkup = async (
109110
}
110111
}
111112

112-
const camelCaseClassName = camelCase(matchItem.groups.className);
113+
const camelCaseClassName = camelCase(className);
113114

114115
if (
115116
!classlist.has(camelCaseClassName) &&
@@ -120,11 +121,11 @@ const parseMarkup = async (
120121
filename,
121122
content,
122123
fileContent,
123-
matchItem.groups.className,
124+
className,
124125
pluginOptions
125126
);
126127
classlist.set(camelCaseClassName, interpolatedName);
127-
cssModuleList[matchItem.groups.className] = interpolatedName;
128+
cssModuleList[className] = interpolatedName;
128129

129130
// consider use with class directive
130131
const directiveClass = isDestructuredImport

0 commit comments

Comments
 (0)