Skip to content

Commit a40a7b2

Browse files
committed
Change to use Unicode regex
1 parent 5f38ae1 commit a40a7b2

File tree

4 files changed

+6
-61
lines changed

4 files changed

+6
-61
lines changed

build.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

lib/index.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {start as startRe, cont as contRe} from './regex.js'
1+
const startRe = /[$_\p{ID_Start}]/u
2+
const contRe = /[$_\u{200C}\u{200D}\p{ID_Continue}]/u
3+
const re = /^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u
24

35
/**
46
* Checks if the given character code can start an identifier.
@@ -23,8 +25,7 @@ export function start(code) {
2325
*/
2426
// To do: support astrals.
2527
export function cont(code) {
26-
const character = String.fromCharCode(code)
27-
return startRe.test(character) || contRe.test(character)
28+
return contRe.test(String.fromCharCode(code))
2829
}
2930

3031
/**
@@ -36,12 +37,5 @@ export function cont(code) {
3637
* Whether `name` can be an identifier.
3738
*/
3839
export function name(name) {
39-
let index = -1
40-
41-
while (++index < name.length) {
42-
if (!(index ? cont : start)(name.charCodeAt(index))) return false
43-
}
44-
45-
// `false` if `name` is empty.
46-
return index > 0
40+
return re.test(name)
4741
}

lib/regex.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@
3333
],
3434
"devDependencies": {
3535
"@types/node": "^20.0.0",
36-
"@types/regenerate": "^1.0.0",
37-
"@unicode/unicode-15.0.0": "^1.0.0",
3836
"c8": "^8.0.0",
3937
"prettier": "^3.0.0",
40-
"regenerate": "^1.0.0",
4138
"remark-cli": "^11.0.0",
4239
"remark-preset-wooorm": "^9.0.0",
4340
"type-coverage": "^2.0.0",
@@ -46,12 +43,11 @@
4643
},
4744
"scripts": {
4845
"prepack": "npm run build && npm run format",
49-
"generate": "node --conditions development build.js",
5046
"build": "tsc --build --clean && tsc --build && type-coverage",
5147
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
5248
"test-api": "node --conditions development test.js",
5349
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
54-
"test": "npm run generate && npm run build && npm run format && npm run test-coverage"
50+
"test": "npm run build && npm run format && npm run test-coverage"
5551
},
5652
"prettier": {
5753
"tabWidth": 2,

0 commit comments

Comments
 (0)