From 0045cb21ba2a18f134beeb8b5b9d7101e9ee74c7 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Mon, 30 Dec 2019 01:04:30 -0800 Subject: [PATCH] Colons are apparently another token type that doesn't survive passing through the parser, so rescue any comments attached to colons --- lib/coffeescript/rewriter.js | 2 +- src/rewriter.coffee | 2 +- test/comments.coffee | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/coffeescript/rewriter.js b/lib/coffeescript/rewriter.js index b671e5a3..d06f611c 100644 --- a/lib/coffeescript/rewriter.js +++ b/lib/coffeescript/rewriter.js @@ -1116,6 +1116,6 @@ // `STRING_START` isn’t on this list because its `locationData` matches that of // the node that becomes `StringWithInterpolations`, and therefore // `addDataToNode` attaches `STRING_START`’s tokens to that node. - DISCARDED = ['(', ')', '[', ']', '{', '}', '.', '..', '...', ',', '=', '++', '--', '?', 'AS', 'AWAIT', 'CALL_START', 'CALL_END', 'DEFAULT', 'DO', 'DO_IIFE', 'ELSE', 'EXTENDS', 'EXPORT', 'FORIN', 'FOROF', 'FORFROM', 'IMPORT', 'INDENT', 'INDEX_SOAK', 'INTERPOLATION_START', 'INTERPOLATION_END', 'LEADING_WHEN', 'OUTDENT', 'PARAM_END', 'REGEX_START', 'REGEX_END', 'RETURN', 'STRING_END', 'THROW', 'UNARY', 'YIELD'].concat(IMPLICIT_UNSPACED_CALL.concat(IMPLICIT_END.concat(CALL_CLOSERS.concat(CONTROL_IN_IMPLICIT)))); + DISCARDED = ['(', ')', '[', ']', '{', '}', ':', '.', '..', '...', ',', '=', '++', '--', '?', 'AS', 'AWAIT', 'CALL_START', 'CALL_END', 'DEFAULT', 'DO', 'DO_IIFE', 'ELSE', 'EXTENDS', 'EXPORT', 'FORIN', 'FOROF', 'FORFROM', 'IMPORT', 'INDENT', 'INDEX_SOAK', 'INTERPOLATION_START', 'INTERPOLATION_END', 'LEADING_WHEN', 'OUTDENT', 'PARAM_END', 'REGEX_START', 'REGEX_END', 'RETURN', 'STRING_END', 'THROW', 'UNARY', 'YIELD'].concat(IMPLICIT_UNSPACED_CALL.concat(IMPLICIT_END.concat(CALL_CLOSERS.concat(CONTROL_IN_IMPLICIT)))); }).call(this); diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 3e5ea03c..6c927359 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -837,7 +837,7 @@ CONTROL_IN_IMPLICIT = ['IF', 'TRY', 'FINALLY', 'CATCH', 'CLASS', 'SWITCH'] # `STRING_START` isn’t on this list because its `locationData` matches that of # the node that becomes `StringWithInterpolations`, and therefore # `addDataToNode` attaches `STRING_START`’s tokens to that node. -DISCARDED = ['(', ')', '[', ']', '{', '}', '.', '..', '...', ',', '=', '++', '--', '?', +DISCARDED = ['(', ')', '[', ']', '{', '}', ':', '.', '..', '...', ',', '=', '++', '--', '?', 'AS', 'AWAIT', 'CALL_START', 'CALL_END', 'DEFAULT', 'DO', 'DO_IIFE', 'ELSE', 'EXTENDS', 'EXPORT', 'FORIN', 'FOROF', 'FORFROM', 'IMPORT', 'INDENT', 'INDEX_SOAK', 'INTERPOLATION_START', 'INTERPOLATION_END', 'LEADING_WHEN', 'OUTDENT', 'PARAM_END', diff --git a/test/comments.coffee b/test/comments.coffee index 5485df20..7a048fdc 100644 --- a/test/comments.coffee +++ b/test/comments.coffee @@ -1003,7 +1003,7 @@ test "#4706: Flow comments after class name", -> var Container; Container = class Container/*:: */ { - method() { + method/*:: */() { return true; } @@ -1120,3 +1120,16 @@ test "#4756: Comment before ? operation", -> return (ref = this.foo) != null ? ref : 42; })(); ''' + +test "#5241: Comment after :", -> + eqJS ''' + return + a: # Comment + b: 1 + ''', ''' + return { + a: { // Comment + b: 1 + } + }; + '''