Skip to content

Commit db92530

Browse files
author
hartsantler
committed
fixed JS(" new XXX")
1 parent 1dc78a8 commit db92530

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

pythonjs/pythonjs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,9 @@ def _inline_code_helper(self, s):
919919
## TODO, should newline be changed here?
920920
s = s.replace('\n', '\\n').replace('\0', '\\0') ## AttributeError: 'BinOp' object has no attribute 's' - this is caused by bad quotes
921921
if s.strip().startswith('#'): s = '/*%s*/'%s
922-
if '"' in s or "'" in s: ## can not trust direct-replace hacks
922+
if '__new__>>' in s: ## fixes inline `JS("new XXX")`
923+
s = s.replace('__new__>>', ' new ')
924+
elif '"' in s or "'" in s: ## can not trust direct-replace hacks
923925
pass
924926
else:
925927
if ' or ' in s:

regtests/lang/new.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'''
2+
js new keyword
3+
'''
4+
5+
def main():
6+
#a = new Date() ## this also works
7+
a = JS(' new Date()')
8+
TestError( a.getFullYear()==2014 )

0 commit comments

Comments
 (0)