diff --git a/lib/command.js b/lib/command.js index 743e7439..3406926a 100644 --- a/lib/command.js +++ b/lib/command.js @@ -58,7 +58,7 @@ base = path.join(source); compile = function(source, topLevel) { return path.exists(source, function(exists) { - if (!exists) { + if (topLevel && !exists) { throw new Error("File not found: " + source); } return fs.stat(source, function(err, stats) { diff --git a/lib/lexer.js b/lib/lexer.js index 8107b1aa..8b95ee48 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -598,7 +598,7 @@ RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf']; JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED); exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS); - IDENTIFIER = /^([$A-Za-z_][$\w]*)([^\n\S]*:(?!:))?/; + IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/; NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i; HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/; OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/; @@ -613,7 +613,7 @@ HEREGEX_OMIT = /\s+(?:#.*)?/g; MULTILINER = /\n/g; HEREDOC_INDENT = /\n+([^\n\S]*)/g; - ASSIGNED = /^\s*@?([$A-Za-z_][$\w]*|['"].*['"])[^\n\S]*?[:=][^:=>]/; + ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/; LINE_CONTINUER = /^\s*(?:,|\??\.(?!\.)|::)/; TRAILING_SPACES = /\s+$/; NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/; diff --git a/lib/nodes.js b/lib/nodes.js index f7b1804c..ce9662d0 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1071,7 +1071,7 @@ this.context = context; this.param = options && options.param; } - Assign.prototype.METHOD_DEF = /^(?:(\S+)\.prototype\.|\S+?)?\b([$A-Za-z_][$\w]*)$/; + Assign.prototype.METHOD_DEF = /^(?:(\S+)\.prototype\.|\S+?)?\b([$A-Za-z_][$\w\x7f-\uffff]*)$/; Assign.prototype.children = ['variable', 'value']; Assign.prototype.assigns = function(name) { return this[this.context === 'object' ? 'value' : 'variable'].assigns(name); @@ -2150,7 +2150,7 @@ LEVEL_ACCESS = 6; TAB = ' '; TRAILING_WHITESPACE = /[ \t]+$/gm; - IDENTIFIER = /^[$A-Za-z_][$\w]*$/; + IDENTIFIER = /^[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*$/; SIMPLENUM = /^[+-]?\d+$/; IS_STRING = /^['"]/; utility = function(name) { diff --git a/src/command.coffee b/src/command.coffee index cdeb1279..b912c6cb 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -76,7 +76,7 @@ compileScripts = -> base = path.join(source) compile = (source, topLevel) -> path.exists source, (exists) -> - throw new Error "File not found: #{source}" unless exists + throw new Error "File not found: #{source}" if topLevel and not exists fs.stat source, (err, stats) -> if stats.isDirectory() fs.readdir source, (err, files) -> diff --git a/src/lexer.coffee b/src/lexer.coffee index 524cf76c..5d6bb39c 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -534,7 +534,7 @@ exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS) # Token matching regexes. IDENTIFIER = /// ^ - ( [$A-Za-z_][$\w]* ) + ( [$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]* ) ( [^\n\S]* : (?!:) )? # Is this a property name? /// @@ -591,7 +591,7 @@ MULTILINER = /\n/g HEREDOC_INDENT = /\n+([^\n\S]*)/g -ASSIGNED = /^\s*@?([$A-Za-z_][$\w]*|['"].*['"])[^\n\S]*?[:=][^:=>]/ +ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/ LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?!\.) | :: ) /// diff --git a/src/nodes.coffee b/src/nodes.coffee index 1afb4120..b5f99426 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -856,7 +856,7 @@ exports.Assign = class Assign extends Base @param = options and options.param # Matchers for detecting class/method names - METHOD_DEF: /^(?:(\S+)\.prototype\.|\S+?)?\b([$A-Za-z_][$\w]*)$/ + METHOD_DEF: /^(?:(\S+)\.prototype\.|\S+?)?\b([$A-Za-z_][$\w\x7f-\uffff]*)$/ children: ['variable', 'value'] @@ -1735,7 +1735,7 @@ TAB = ' ' # with Git. TRAILING_WHITESPACE = /[ \t]+$/gm -IDENTIFIER = /^[$A-Za-z_][$\w]*$/ +IDENTIFIER = /^[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*$/ SIMPLENUM = /^[+-]?\d+$/ # Is a literal value a string? diff --git a/test/_test_literals.coffee b/test/_test_literals.coffee index 70e9cc31..969e2995 100644 --- a/test/_test_literals.coffee +++ b/test/_test_literals.coffee @@ -268,3 +268,7 @@ six: -> 10 ok not one.six + +# Issue #986: Unicode identifiers. +λ = 5 +eq λ, 5