fix is_regexp() in tokenize()
This commit is contained in:
parent
9ac7491e70
commit
4568cba7b6
1 changed files with 18 additions and 1 deletions
19
ox/js.py
19
ox/js.py
|
@ -49,6 +49,23 @@ def parse_JSONC(source):
|
||||||
def tokenize(source):
|
def tokenize(source):
|
||||||
# see https://github.com/mozilla/narcissus/blob/master/lib/jslex.js
|
# see https://github.com/mozilla/narcissus/blob/master/lib/jslex.js
|
||||||
IDENTIFIER = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
|
IDENTIFIER = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
|
||||||
|
KEYWORD = [
|
||||||
|
'break',
|
||||||
|
'case', 'catch', 'class', 'const', 'continue',
|
||||||
|
'debugger', 'default', 'delete', 'do',
|
||||||
|
'else', 'enum', 'export', 'extends',
|
||||||
|
'finally', 'for', 'function',
|
||||||
|
'if', 'implements', 'import', 'in', 'instanceof', 'interface',
|
||||||
|
'let', 'module',
|
||||||
|
'new',
|
||||||
|
'package', 'private', 'protected', 'public',
|
||||||
|
'return',
|
||||||
|
'super', 'switch', 'static',
|
||||||
|
'this', 'throw', 'try', 'typeof',
|
||||||
|
'var', 'void',
|
||||||
|
'yield',
|
||||||
|
'while', 'with'
|
||||||
|
]
|
||||||
LINEBREAK = '\n\r'
|
LINEBREAK = '\n\r'
|
||||||
NUMBER = '01234567890'
|
NUMBER = '01234567890'
|
||||||
OPERATOR = [
|
OPERATOR = [
|
||||||
|
@ -87,7 +104,7 @@ def tokenize(source):
|
||||||
else:
|
else:
|
||||||
token = tokens[i]
|
token = tokens[i]
|
||||||
is_regexp = (
|
is_regexp = (
|
||||||
token['type'] == 'keyword' and not token['value'] in ['false', 'null', 'true']
|
token['type'] == 'identifier' and token['value'] in KEYWORDS
|
||||||
) or (
|
) or (
|
||||||
token['type'] == 'operator' and not token['value'] in ['++', '--', ')', ']', '}']
|
token['type'] == 'operator' and not token['value'] in ['++', '--', ')', ']', '}']
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue