Skip to content

Commit a51c06c

Browse files
committed
Add build to avoid using regexpu-core in runtime
1 parent 2a6cb09 commit a51c06c

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

lib/parse.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
var Parser = require("fastparse");
4-
var regexpu = require("regexpu-core");
4+
var uniRegexp = require("./uni-regexp");
55

66
function unescape(str) {
77
return str.replace(/\\(.)/g, "$1");
@@ -175,8 +175,8 @@ function getSelectors() {
175175
// ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_)
176176
//
177177
// 10ffff is the maximum allowed in current Unicode
178-
selectors[regexpu("\\.((?:\\\\.|[A-Za-z_\\-\\u{00a0}-\\u{10ffff}])(?:\\\\.|[A-Za-z_\\-0-9\\u{00a0}-\\u{10ffff}])*)", "u")] = typeMatch("class");
179-
selectors[regexpu("#((?:\\\\.|[A-Za-z_\\-\\u{00a0}-\\u{10ffff}])(?:\\\\.|[A-Za-z_\\-0-9\\u{00a0}-\\u{10ffff}])*)", "u")] = typeMatch("id");
178+
selectors[uniRegexp.typeMatchClass] = typeMatch("class");
179+
selectors[uniRegexp.typeMatchId] = typeMatch("id");
180180
var selectorsSecondHalf = {
181181
":(not|matches|has|local|global)\\((\\s*)": nestedPseudoClassStartMatch,
182182
":((?:\\\\.|[A-Za-z_\\-0-9])+)\\(": pseudoClassStartMatch,

lib/stringify.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
"use strict";
22

3-
var regexpu = require("regexpu-core");
4-
var identifierEscapeRegexp = new RegExp(
5-
regexpu("(^[^A-Za-z_\\-\\u{00a0}-\\u{10ffff}]|^--|[^A-Za-z_0-9\\-\\u{00a0}-\\u{10ffff}])", "ug"),
6-
"g"
7-
);
3+
var uniRegexp = require("./uni-regexp");
4+
var identifierEscapeRegexp = new RegExp(uniRegexp.identifierEscapeRegexp, "g");
85

96
function escape(str, identifier) {
107
if(str === "*") {

lib/uni-regexp.js

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"main": "lib/index.js",
66
"scripts": {
77
"lint": "eslint .",
8-
"pretest": "npm run lint",
8+
"pretest": "npm run build && npm run lint",
99
"test": "mocha",
1010
"cover": "nyc npm test",
11+
"build": "node scripts/build-regexpu.js",
1112
"report:coveralls": "nyc report --reporter=text-lcov | coveralls",
1213
"report:codecov": "nyc report --reporter=text-lcov | codecov --pipe",
1314
"publish-patch": "npm test && npm version patch && git push && git push --tags && npm publish"
@@ -31,15 +32,15 @@
3132
"homepage": "https://github.com/css-modules/css-selector-tokenizer",
3233
"dependencies": {
3334
"cssesc": "^3.0.0",
34-
"fastparse": "^1.1.2",
35-
"regexpu-core": "^4.6.0"
35+
"fastparse": "^1.1.2"
3636
},
3737
"devDependencies": {
3838
"codecov": "^3.6.5",
3939
"coveralls": "^3.0.9",
4040
"eslint": "^6.8.0",
4141
"mocha": "^7.1.0",
42-
"nyc": "^15.0.0"
42+
"nyc": "^15.0.0",
43+
"regexpu-core": "^4.6.0"
4344
},
4445
"directories": {
4546
"test": "test"

scripts/build-regexpu.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var fs = require("fs");
2+
var path = require("path");
3+
var regexpu = require("regexpu-core");
4+
5+
var uniReg = {
6+
typeMatchClass: regexpu(
7+
"\\.((?:\\\\.|[A-Za-z_\\-\\u{00a0}-\\u{10ffff}])(?:\\\\.|[A-Za-z_\\-0-9\\u{00a0}-\\u{10ffff}])*)",
8+
"u"
9+
),
10+
typeMatchId: regexpu(
11+
"#((?:\\\\.|[A-Za-z_\\-\\u{00a0}-\\u{10ffff}])(?:\\\\.|[A-Za-z_\\-0-9\\u{00a0}-\\u{10ffff}])*)",
12+
"u"
13+
),
14+
identifierEscapeRegexp: regexpu(
15+
"(^[^A-Za-z_\\-\\u{00a0}-\\u{10ffff}]|^--|[^A-Za-z_0-9\\-\\u{00a0}-\\u{10ffff}])",
16+
"ug"
17+
),
18+
};
19+
20+
var targetFile = path.join(__dirname, "../lib/uni-regexp.js");
21+
22+
fs.writeFileSync(
23+
targetFile,
24+
"/* AUTO GENERATED */\nmodule.exports = " + JSON.stringify(uniReg, null, 4)
25+
);
26+
console.log('Done building ' + targetFile)

0 commit comments

Comments
 (0)