Skip to content

Commit a9f0c77

Browse files
committed
Use a Map and some minor regex tweaks
1 parent 38f641a commit a9f0c77

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"devDependencies": {
4848
"ava": "*",
4949
"coveralls": "^2.11.2",
50-
"execa": "^0.7.0",
50+
"execa": "^0.8.0",
5151
"import-fresh": "^2.0.0",
5252
"matcha": "^0.7.0",
5353
"nyc": "^11.0.2",

templates.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
'use strict';
2-
const TEMPLATE_REGEX = /(?:\\(u[a-f0-9]{4}|x[a-f0-9]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
2+
const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
33
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
44
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
5-
const ESCAPE_REGEX = /\\(u[0-9a-f]{4}|x[0-9a-f]{2}|.)|([^\\])/gi;
6-
7-
const ESCAPES = {
8-
n: '\n',
9-
r: '\r',
10-
t: '\t',
11-
b: '\b',
12-
f: '\f',
13-
v: '\v',
14-
0: '\0',
15-
'\\': '\\',
16-
e: '\u001b',
17-
a: '\u0007'
18-
};
5+
const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
6+
7+
const ESCAPES = new Map([
8+
['n', '\n'],
9+
['r', '\r'],
10+
['t', '\t'],
11+
['b', '\b'],
12+
['f', '\f'],
13+
['v', '\v'],
14+
['0', '\0'],
15+
['\\', '\\'],
16+
['e', '\u001B'],
17+
['a', '\u0007']
18+
]);
1919

2020
function unescape(c) {
2121
if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
2222
return String.fromCharCode(parseInt(c.slice(1), 16));
2323
}
2424

25-
return ESCAPES[c] || c;
25+
return ESCAPES.get(c) || c;
2626
}
2727

2828
function parseArguments(name, args) {

0 commit comments

Comments
 (0)