Skip to content

Commit a4b6e8a

Browse files
committedNov 26, 2022
Heregex Comment
Fixes #5428 This fix is simple enough but it causes a substantial change in behavior for Heregexes. `#` inside of a character class shouldn't be considered a comment. By treating `#` without whitespace in front as non-comments we could have slight compatability with Python. There are other places in the CoffeeScript source where people avoided escaping the `#` by keeping it next to non-whitespace characters even outside of a character class. This is different than how Python does it and is probably a bug but maybe it is too late with the de facto CoffeeScript2 behavior. I'm not sure if this should be merged in since it changes the behavior quite a lot. Maybe another one for the CoffeeScript3/Civet bucket. Refs --- Python Docs: https://docs.python.org/3/library/re.html#re.X
1 parent 1dfa23b commit a4b6e8a

File tree

8 files changed

+17
-17
lines changed

8 files changed

+17
-17
lines changed
 

‎docs/v2/browser-compiler-legacy/coffeescript.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/v2/browser-compiler-modern/coffeescript.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/coffeescript-browser-compiler-legacy/coffeescript.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/coffeescript-browser-compiler-modern/coffeescript.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/coffeescript/lexer.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/coffeescript/nodes.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/lexer.coffee

+7-7
Original file line numberDiff line numberDiff line change
@@ -1341,10 +1341,10 @@ HERE_JSTOKEN = ///^ ``` ((?: [^`\\] | \\[\s\S] | `(?!``) )*) ``` ///
13411341
# String-matching-regexes.
13421342
STRING_START = /^(?:'''|"""|'|")/
13431343

1344-
STRING_SINGLE = /// ^(?: [^\\'] | \\[\s\S] )* ///
1345-
STRING_DOUBLE = /// ^(?: [^\\"#] | \\[\s\S] | \#(?!\{) )* ///
1346-
HEREDOC_SINGLE = /// ^(?: [^\\'] | \\[\s\S] | '(?!'') )* ///
1347-
HEREDOC_DOUBLE = /// ^(?: [^\\"#] | \\[\s\S] | "(?!"") | \#(?!\{) )* ///
1344+
STRING_SINGLE = /// ^(?: [^\\'] | \\[\s\S] )* ///
1345+
STRING_DOUBLE = /// ^(?: [^\\"\#] | \\[\s\S] | \#(?!\{) )* ///
1346+
HEREDOC_SINGLE = /// ^(?: [^\\'] | \\[\s\S] | '(?!'') )* ///
1347+
HEREDOC_DOUBLE = /// ^(?: [^\\"\#] | \\[\s\S] | "(?!"") | \#(?!\{) )* ///
13481348

13491349
INSIDE_JSX = /// ^(?:
13501350
[^
@@ -1376,19 +1376,19 @@ VALID_FLAGS = /^(?!.*(.).*\1)[gimsuy]*$/
13761376
HEREGEX = /// ^
13771377
(?:
13781378
# Match any character, except those that need special handling below.
1379-
[^\\/#\s]
1379+
[^\\/\#\s]
13801380
# Match `\` followed by any character.
13811381
| \\[\s\S]
13821382
# Match any `/` except `///`.
13831383
| /(?!//)
13841384
# Match `#` which is not part of interpolation, e.g. `#{}`.
13851385
| \#(?!\{)
13861386
# Comments consume everything until the end of the line, including `///`.
1387-
| \s+(?:#(?!\{).*)?
1387+
| \s*(?:\#(?!\{).*)?
13881388
)*
13891389
///
13901390

1391-
HEREGEX_COMMENT = /(\s+)(#(?!{).*)/gm
1391+
HEREGEX_COMMENT = /(\s*)(#(?!{).*)/gm
13921392

13931393
REGEX_ILLEGAL = /// ^ ( / | /{3}\s*) (\*) ///
13941394

‎src/nodes.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -5783,7 +5783,7 @@ STRING_OMIT = ///
57835783
HEREGEX_OMIT = ///
57845784
((?:\\\\)+) # Consume (and preserve) an even number of backslashes.
57855785
| \\(\s) # Preserve escaped whitespace.
5786-
| \s+(?:#.*)? # Remove whitespace and comments.
5786+
| \s+(?:\#.*)? # Remove whitespace and comments.
57875787
///g
57885788

57895789
# Helper Functions

0 commit comments

Comments
 (0)