From 592731838a0357b992fdccca72df484a118f4134 Mon Sep 17 00:00:00 2001 From: Zongyang Li Date: Sat, 28 May 2022 17:13:53 +0800 Subject: [PATCH 1/2] fix toDict issue of Literal null --- esprima/character.py | 2 +- esprima/visitor.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/esprima/character.py b/esprima/character.py index 929706c..2b225fd 100644 --- a/esprima/character.py +++ b/esprima/character.py @@ -82,7 +82,7 @@ del U_CATEGORIES, UNICODE_LETTER, UNICODE_COMBINING_MARK del UNICODE_DIGIT, UNICODE_CONNECTOR_PUNCTUATION -del DECIMAL_CONV, OCTAL_CONV, HEX_CONV +# del DECIMAL_CONV, OCTAL_CONV, HEX_CONV class Character: @staticmethod diff --git a/esprima/visitor.py b/esprima/visitor.py index ad32375..9180a03 100644 --- a/esprima/visitor.py +++ b/esprima/visitor.py @@ -282,7 +282,10 @@ def visit_dict(self, obj): v = yield item k = unicode(k) items.append((self.map.get(k, k), v)) - yield Visited(dict(items)) + items = dict(items) + if "type" in items.keys() and "raw" in items.keys() and items["type"] == 'Literal' and items["raw"] == "null": + items["value"] = None + yield Visited(items) def visit_SRE_Pattern(self, obj): yield Visited({}) From 3916a1ea4b01e1cff49ea276d6d1de0680e7639f Mon Sep 17 00:00:00 2001 From: Zongyang Li <39323787+NITROGENousFish@users.noreply.github.com> Date: Mon, 18 Jul 2022 01:32:45 +0800 Subject: [PATCH 2/2] Update regex toDict error handeling --- esprima/visitor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esprima/visitor.py b/esprima/visitor.py index 9180a03..236f0c4 100644 --- a/esprima/visitor.py +++ b/esprima/visitor.py @@ -285,6 +285,8 @@ def visit_dict(self, obj): items = dict(items) if "type" in items.keys() and "raw" in items.keys() and items["type"] == 'Literal' and items["raw"] == "null": items["value"] = None + if "type" in items.keys() and "raw" in items.keys() and items["type"] == 'Literal' and "regex" in items.keys() and type(items["value"]) == re.Pattern: + items["value"] = None yield Visited(items) def visit_SRE_Pattern(self, obj):