Permalink
Browse files

Support space separator as white space

  • Loading branch information...
Constellation committed Mar 5, 2012
1 parent fa49a96 commit 5858be9ca5a38794466a3ccc671afe1dd2dee9a8
Showing with 44 additions and 3 deletions.
  1. +3 −2 esprima.js
  2. +36 −1 test/test.js
  3. +5 −0 tools/generate-unicode-regex.py
View
@@ -249,9 +249,10 @@ parseStatement: true, parseSourceElement: true */
// 7.2 White Space
function isWhiteSpace(ch) {
- // TODO Unicode "space separator"
return (ch === ' ') || (ch === '\u0009') || (ch === '\u000B') ||
- (ch === '\u000C') || (ch === '\u00A0') || (ch === '\uFEFF');
+ (ch === '\u000C') || (ch === '\u00A0') ||
+ (ch.charCodeAt(0) >= 0x1680 &&
+ '\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\uFEFF'.indexOf(ch) >= 0);
}
// 7.3 Line Terminators
View
@@ -731,8 +731,43 @@ data = {
start: { line: 1, column: 0 },
end: { line: 1, column: 7 }
}
- }
+ },
+ '\u2163\u2161\u200A=\u2009[]': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'AssignmentExpression',
+ operator: '=',
+ left: {
+ type: 'Identifier',
+ name: '\u2163\u2161',
+ range: [0, 1],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 2 }
+ }
+ },
+ right: {
+ type: 'ArrayExpression',
+ elements: [],
+ range: [5, 6],
+ loc: {
+ start: { line: 1, column: 5 },
+ end: { line: 1, column: 7 }
+ }
+ },
+ range: [0, 6],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 7 }
+ }
+ },
+ range: [0, 6],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 7 }
+ }
+ }
},
@@ -28,6 +28,10 @@ def generate_non_ascii_identifier_part(self):
r = [ ch for ch in range(0x0080, 0xFFFF + 1) if self.detector.is_identifier_part(ch)]
return self._generate_range(r)
+ def generate_non_ascii_separator_space(self):
+ r = [ ch for ch in range(0x0080, 0xFFFF + 1) if self.detector.is_separator_space(ch)]
+ return self._generate_range(r)
+
def _generate_range(self, r):
if len(r) == 0:
return '[]'
@@ -154,6 +158,7 @@ def main(source):
generator = analyze(source)
print generator.generate_non_ascii_identifier_start()
print generator.generate_non_ascii_identifier_part()
+ print generator.generate_non_ascii_separator_space()
if __name__ == '__main__':
main(sys.argv[1])

0 comments on commit 5858be9

Please sign in to comment.