diff --git a/lib/coffeescript/lexer.js b/lib/coffeescript/lexer.js index c067570dea..d933f71791 100644 --- a/lib/coffeescript/lexer.js +++ b/lib/coffeescript/lexer.js @@ -10,7 +10,7 @@ // where locationData is {first_line, first_column, last_line, last_column, last_line_exclusive, last_column_exclusive}, which is a // format that can be fed directly into [Jison](https://github.com/zaach/jison). These // are read by jison in the `parser.lexer` function defined in coffeescript.coffee. - var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARABLE_LEFT_SIDE, COMPARE, COMPOUND_ASSIGN, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_COMMENT, HERE_JSTOKEN, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INSIDE_JSX, INVERSES, JSTOKEN, JSX_ATTRIBUTE, JSX_FRAGMENT_IDENTIFIER, JSX_IDENTIFIER, JSX_IDENTIFIER_PART, JSX_INTERPOLATION, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, Lexer, MATH, MULTI_DENT, NOT_REGEX, NUMBER, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, REGEX_INVALID_ESCAPE, RELATION, RESERVED, Rewriter, SHIFT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_INVALID_ESCAPE, STRING_SINGLE, STRING_START, TRAILING_SPACES, UNARY, UNARY_MATH, UNFINISHED, VALID_FLAGS, WHITESPACE, addTokenData, attachCommentsToNode, compact, count, flatten, invertLiterate, isForFrom, isUnassignable, key, locationDataToString, merge, parseNumber, repeat, replaceUnicodeCodePointEscapes, starts, throwSyntaxError, + var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARABLE_LEFT_SIDE, COMPARE, COMPOUND_ASSIGN, DISTINCT_DECL, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_COMMENT, HERE_JSTOKEN, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INSIDE_JSX, INVERSES, JSTOKEN, JSX_ATTRIBUTE, JSX_FRAGMENT_IDENTIFIER, JSX_IDENTIFIER, JSX_IDENTIFIER_PART, JSX_INTERPOLATION, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, Lexer, MATH, MULTI_DENT, NOT_REGEX, NUMBER, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, REGEX_INVALID_ESCAPE, RELATION, RESERVED, Rewriter, SHIFT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_INVALID_ESCAPE, STRING_SINGLE, STRING_START, TRAILING_SPACES, UNARY, UNARY_MATH, UNFINISHED, VALID_FLAGS, WHITESPACE, addTokenData, attachCommentsToNode, compact, count, flatten, invertLiterate, isForFrom, isUnassignable, key, locationDataToString, merge, parseNumber, repeat, replaceUnicodeCodePointEscapes, starts, throwSyntaxError, indexOf = [].indexOf, slice = [].slice; @@ -1109,6 +1109,8 @@ if (CODE.test(value)) { this.tagParameters(); } + } else if (match = DISTINCT_DECL.exec(this.chunk)) { + [value] = match; } else { value = this.chunk.charAt(0); } @@ -1139,6 +1141,9 @@ return value.length; } } + if (value === '@=') { + tag = 'DECLARATION'; + } if (value === '(' && (prev != null ? prev[0] : void 0) === 'IMPORT') { prev[0] = 'DYNAMIC_IMPORT'; } @@ -1945,4 +1950,8 @@ // Additional indent in front of these is ignored. INDENTABLE_CLOSERS = [')', '}', ']']; + // Proposed syntax for "declarations", which are checked to be unique in a scope and can therefore + // have additional semantic information attached which would otherwise be erased. + DISTINCT_DECL = /^(?:@=)/; // distinct var decl which can have a specific comment attached. + }).call(this); diff --git a/src/lexer.coffee b/src/lexer.coffee index d2a3cd35da..51195b59c9 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -756,6 +756,8 @@ exports.Lexer = class Lexer if match = OPERATOR.exec @chunk [value] = match @tagParameters() if CODE.test value + else if match = DISTINCT_DECL.exec @chunk + [value] = match else value = @chunk.charAt 0 tag = value @@ -781,6 +783,9 @@ exports.Lexer = class Lexer @error message, origin[2] if message return value.length if skipToken + if value is '@=' + tag = 'DECLARATION' + if value is '(' and prev?[0] is 'IMPORT' prev[0] = 'DYNAMIC_IMPORT' @@ -1479,3 +1484,9 @@ LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'] # Additional indent in front of these is ignored. INDENTABLE_CLOSERS = [')', '}', ']'] + +# Proposed syntax for "declarations", which are checked to be unique in a scope and can therefore +# have additional semantic information attached which would otherwise be erased. +DISTINCT_DECL = /// ^ ( + ?: @= # distinct var decl which can have a specific comment attached. +) ///