Skip to content

Escape apostrophes in docstrings #877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions transcrypt/modules/org/transcrypt/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ def visit_ClassDef (self, node):
if self.allowDocAttribs:
docString = ast.get_docstring (node)
if docString:
self.emit (' .__setdoc__ (\'{}\')', docString.replace ('\n', '\\n '))
self.emit (' .__setdoc__ (\'{}\')', docString.replace ('\n', '\\n ').replace('\'', '\\\''))

# Deal with data class var assigns, a flavor of special class var assigns
if isDataClass: # Constructor + params have to be generated, no real class vars, just syntactically
Expand Down Expand Up @@ -2747,7 +2747,7 @@ def pushPropertyAccessor(functionName):
if self.allowDocAttribs:
docString = ast.get_docstring (node)
if docString:
self.emit (' .__setdoc__ (\'{}\')', docString.replace ('\n', '\\n '))
self.emit (' .__setdoc__ (\'{}\')', docString.replace ('\n', '\\n ').replace('\'', '\\\''))


if decorate:
Expand Down Expand Up @@ -3102,7 +3102,7 @@ def visit_Module (self, node):

# Insert docstring at hoist location, further hoists are PRE(!)pended
if self.allowDocAttribs and docString:
self.emit ('export var __doc__ = \'{}\';\n', docString.replace ('\n', '\\n'))
self.emit ('export var __doc__ = \'{}\';\n', docString.replace ('\n', '\\n').replace ('\'', '\\\''))

'''
Make the globals () function work as well as possible in conjunction with JavaScript 6 modules rather than closures
Expand Down