Skip to content

Commit 6eb8e31

Browse files
fabiosantoscodemichaelficarra
authored andcommitted
support 'regex' property when 'value' is null (estools#396)
1 parent fb7b56f commit 6eb8e31

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

escodegen.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,10 @@
23122312
}
23132313
}
23142314

2315+
if (expr.regex) {
2316+
return '/' + expr.regex.pattern + '/' + expr.regex.flags;
2317+
}
2318+
23152319
if (expr.value === null) {
23162320
return 'null';
23172321
}
@@ -2328,9 +2332,6 @@
23282332
return expr.value ? 'true' : 'false';
23292333
}
23302334

2331-
if (expr.regex) {
2332-
return '/' + expr.regex.pattern + '/' + expr.regex.flags;
2333-
}
23342335
return generateRegExp(expr.value);
23352336
},
23362337

test/test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4429,6 +4429,32 @@ data = {
44294429
value: '/[P QR]/\\g',
44304430
range: [8, 18]
44314431
}]
4432+
},
4433+
4434+
'var x = /foo/i;': {
4435+
generateFrom: {
4436+
type: 'Program',
4437+
body: [{
4438+
type: 'VariableDeclaration',
4439+
kind: 'var',
4440+
declarations: [{
4441+
type: 'VariableDeclarator',
4442+
id: {
4443+
type: 'Identifier',
4444+
name: 'x',
4445+
},
4446+
init: {
4447+
type: 'Literal',
4448+
value: null,
4449+
raw: '/foo/i',
4450+
regex: {
4451+
pattern: 'foo',
4452+
flags: 'i'
4453+
}
4454+
},
4455+
}]
4456+
}],
4457+
}
44324458
}
44334459

44344460
},

0 commit comments

Comments
 (0)