Skip to content

Commit e769423

Browse files
committed
Merge pull request #3774 from lydell/unicode-spaces
Fix #2516, #3560: Unicode space handling
2 parents c478f28 + 9ec427b commit e769423

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

lib/coffee-script/lexer.js

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

src/lexer.coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ BOM = 65279
731731

732732
# Token matching regexes.
733733
IDENTIFIER = /// ^
734-
( [$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]* )
734+
(?!\d)
735+
( (?: (?!\s)[$\w\x7f-\uffff] )+ )
735736
( [^\n\S]* : (?!:) )? # Is this a property name?
736737
///
737738

test/compilation.coffee

+26
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,32 @@ test "Issue #986: Unicode identifiers", ->
5252
λ = 5
5353
eq λ, 5
5454

55+
test "#2516: Unicode spaces should not be part of identifiers", ->
56+
a = (x) -> x * 2
57+
b = 3
58+
eq 6, a b # U+00A0 NO-BREAK SPACE
59+
eq 6, a b # U+1680 OGHAM SPACE MARK
60+
eq 6, a b # U+2000 EN QUAD
61+
eq 6, a b # U+2001 EM QUAD
62+
eq 6, a b # U+2002 EN SPACE
63+
eq 6, a b # U+2003 EM SPACE
64+
eq 6, a b # U+2004 THREE-PER-EM SPACE
65+
eq 6, a b # U+2005 FOUR-PER-EM SPACE
66+
eq 6, a b # U+2006 SIX-PER-EM SPACE
67+
eq 6, a b # U+2007 FIGURE SPACE
68+
eq 6, a b # U+2008 PUNCTUATION SPACE
69+
eq 6, a b # U+2009 THIN SPACE
70+
eq 6, a b # U+200A HAIR SPACE
71+
eq 6, a b # U+202F NARROW NO-BREAK SPACE
72+
eq 6, a b # U+205F MEDIUM MATHEMATICAL SPACE
73+
eq 6, a b # U+3000 IDEOGRAPHIC SPACE
74+
75+
# #3560: Non-breaking space (U+00A0) (before `'c'`)
76+
eq 5, {c: 5}[ 'c' ]
77+
78+
# A line where every space in non-breaking
79+
  eq 1 + 12  
80+
5581
test "don't accidentally stringify keywords", ->
5682
ok (-> this == 'this')() is false
5783

0 commit comments

Comments
 (0)