Skip to content

Commit 571e9df

Browse files
zdenkoGeoffreyBooth
authored andcommitted
fix #4874 (#4888)
1 parent a73f66b commit 571e9df

File tree

3 files changed

+74
-6
lines changed

3 files changed

+74
-6
lines changed

lib/coffeescript/lexer.js

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,10 @@ exports.Lexer = class Lexer
454454
indent = match[0]
455455

456456
prev = @prev()
457-
backslash = prev? and prev[0] is '\\'
457+
backslash = prev?[0] is '\\'
458458
@seenFor = no unless backslash and @seenFor
459-
@seenImport = no unless @importSpecifierList
460-
@seenExport = no unless @exportSpecifierList
459+
@seenImport = no unless (backslash and @seenImport) or @importSpecifierList
460+
@seenExport = no unless (backslash and @seenExport) or @exportSpecifierList
461461

462462
size = indent.length - 1 - indent.lastIndexOf '\n'
463463
noNewlines = @unfinished()

test/modules.coffee

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,3 +853,70 @@ test "#4491: import- and export-specific lexing should stop after import/export
853853
854854
from('foo');
855855
"""
856+
857+
# Issue #4874: Backslash not supported in import or export statements
858+
test "#4874: backslash `import`", ->
859+
860+
eqJS """
861+
import foo \
862+
from 'lib'
863+
864+
foo a
865+
""",
866+
"""
867+
import foo from 'lib';
868+
869+
foo(a);
870+
"""
871+
872+
eqJS """
873+
import \
874+
foo \
875+
from \
876+
'lib'
877+
878+
foo a
879+
""",
880+
"""
881+
import foo from 'lib';
882+
883+
foo(a);
884+
"""
885+
886+
eqJS """
887+
import \
888+
utilityBelt \
889+
, {
890+
each
891+
} from \
892+
'underscore'
893+
""",
894+
"""
895+
import utilityBelt, {
896+
each
897+
} from 'underscore';
898+
"""
899+
900+
test "#4874: backslash `export`", ->
901+
eqJS """
902+
export \
903+
* \
904+
from \
905+
'underscore'
906+
""",
907+
"""
908+
export * from 'underscore';
909+
"""
910+
911+
eqJS """
912+
export \
913+
{ max, min } \
914+
from \
915+
'underscore'
916+
""",
917+
"""
918+
export {
919+
max,
920+
min
921+
} from 'underscore';
922+
"""

0 commit comments

Comments
 (0)