Skip to content

Commit 9d0ef3a

Browse files
author
Michael Vurchio
committed
Add support for node 10
1 parent fdea659 commit 9d0ef3a

File tree

3 files changed

+126
-41
lines changed

3 files changed

+126
-41
lines changed

package-lock.json

Lines changed: 113 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@
4545
]
4646
},
4747
"dependencies": {
48-
"loader-utils": "^2.0.0"
48+
"@types/object.fromentries": "^2.0.0",
49+
"loader-utils": "^2.0.0",
50+
"object.fromentries": "^2.0.2",
51+
"string.prototype.matchall": "^4.0.3"
4952
},
5053
"devDependencies": {
51-
"@types/cssesc": "^3.0.0",
5254
"@types/loader-utils": "^2.0.1",
55+
"@types/string.prototype.matchall": "^4.0.0",
5356
"@typescript-eslint/eslint-plugin": "^4.4.0",
5457
"@typescript-eslint/parser": "^4.4.0",
5558
"eslint": "^7.10.0",
@@ -64,7 +67,7 @@
6467
"typescript": "^4.0.3"
6568
},
6669
"peerDependencies": {
67-
"svelte": "3.20.0",
70+
"svelte": "^3.20.0",
6871
"typescript": "^4.0.0"
6972
},
7073
"files": [

src/processors/parseMarkup.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import path from 'path';
22
import fs from 'fs';
3+
import matchAll from 'string.prototype.matchall';
4+
import fromEntries from 'object.fromentries';
35
import { PluginOptions, CSSModuleList } from '../types';
46
import {
57
PATTERN_CLASSNAME,
@@ -93,15 +95,15 @@ const parseMarkup = async (
9395
}
9496

9597
const classlist = new Map();
96-
Array.from(fileContent.matchAll(PATTERN_CLASS_SELECTOR)).forEach((matchItem) => {
98+
Array.from(matchAll(fileContent, PATTERN_CLASS_SELECTOR)).forEach((matchItem) => {
9799
// set array from exported className
98100
const destructuredImportRegex = /\{([\w,\s]+)\}/gm;
99101
const isDestructuredImport: boolean = varName.search(destructuredImportRegex) !== -1;
100102
let destructuredImportNames: string[] = [];
101103
if (isDestructuredImport) {
102-
const destructuredImport = Object.values(
103-
Object.fromEntries(varName.matchAll(destructuredImportRegex))
104-
)[0];
104+
const destructuredImport: string = Object.values(
105+
fromEntries(matchAll(varName, destructuredImportRegex))
106+
)[0].toString();
105107
if (destructuredImport) {
106108
destructuredImportNames = destructuredImport.replace(/\s/g, '').split(',');
107109
}
@@ -138,7 +140,7 @@ const parseMarkup = async (
138140
importedStyleType = extension;
139141
}
140142

141-
return `const ${varName} = ${JSON.stringify(Object.fromEntries(classlist))};`;
143+
return `const ${varName} = ${JSON.stringify(fromEntries(classlist))};`;
142144
} catch (err) {
143145
throw new Error(err);
144146
}

0 commit comments

Comments
 (0)