Skip to content
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

Heregex Comment #5435

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/v2/browser-compiler-legacy/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/v2/browser-compiler-modern/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/v2/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -26000,7 +26000,7 @@ <h1>CoffeeScript Test Suite</h1>
# TODO: improve heregex interpolation tests

test "heregex interpolation", ->
eq /\\#{}\\"/ + '', ///
eq /\#{}\\"/ + '', ///
#{
"#{ '\\' }" # normal comment
}
Expand Down
2 changes: 1 addition & 1 deletion lib/coffeescript-browser-compiler-legacy/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/coffeescript-browser-compiler-modern/coffeescript.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/coffeescript/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/coffeescript/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1341,10 +1341,10 @@ HERE_JSTOKEN = ///^ ``` ((?: [^`\\] | \\[\s\S] | `(?!``) )*) ``` ///
# String-matching-regexes.
STRING_START = /^(?:'''|"""|'|")/

STRING_SINGLE = /// ^(?: [^\\'] | \\[\s\S] )* ///
STRING_DOUBLE = /// ^(?: [^\\"#] | \\[\s\S] | \#(?!\{) )* ///
HEREDOC_SINGLE = /// ^(?: [^\\'] | \\[\s\S] | '(?!'') )* ///
HEREDOC_DOUBLE = /// ^(?: [^\\"#] | \\[\s\S] | "(?!"") | \#(?!\{) )* ///
STRING_SINGLE = /// ^(?: [^\\'] | \\[\s\S] )* ///
STRING_DOUBLE = /// ^(?: [^\\"\#] | \\[\s\S] | \#(?!\{) )* ///
HEREDOC_SINGLE = /// ^(?: [^\\'] | \\[\s\S] | '(?!'') )* ///
HEREDOC_DOUBLE = /// ^(?: [^\\"\#] | \\[\s\S] | "(?!"") | \#(?!\{) )* ///

INSIDE_JSX = /// ^(?:
[^
Expand Down Expand Up @@ -1376,15 +1376,15 @@ VALID_FLAGS = /^(?!.*(.).*\1)[gimsuy]*$/
HEREGEX = /// ^
(?:
# Match any character, except those that need special handling below.
[^\\/#\s]
[^\\/\#\s]
# Match `\` followed by any character.
| \\[\s\S]
# Match any `/` except `///`.
| /(?!//)
# Match `#` which is not part of interpolation, e.g. `#{}`.
| \#(?!\{)
# Comments consume everything until the end of the line, including `///`.
| \s+(?:#(?!\{).*)?
| \s*(?:\#(?!\{).*)?
)*
///

Expand Down
4 changes: 2 additions & 2 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5782,8 +5782,8 @@ STRING_OMIT = ///
///g
HEREGEX_OMIT = ///
((?:\\\\)+) # Consume (and preserve) an even number of backslashes.
| \\(\s) # Preserve escaped whitespace.
| \s+(?:#.*)? # Remove whitespace and comments.
| \\(\s|\#) # Preserve escaped whitespace and '#'.
| \s*(?:\#.*)? # Remove whitespace and comments.
///g

# Helper Functions
Expand Down
2 changes: 1 addition & 1 deletion test/interpolation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ ok /^a[\s\S]+b$/.test "a#{ (x) -> x %% 2 }b"
# TODO: improve heregex interpolation tests

test "heregex interpolation", ->
eq /\\#{}\\"/ + '', ///
eq /\#{}\\"/ + '', ///
#{
"#{ '\\' }" # normal comment
}
Expand Down