Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow leading logical operators #5407

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/v2/browser-compiler-legacy/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/v2/browser-compiler-modern/coffeescript.js

Large diffs are not rendered by default.

222 changes: 222 additions & 0 deletions docs/v2/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -23059,6 +23059,16 @@ <h1>CoffeeScript Test Suite</h1>
^
'''

test 'leading logical followed by :: should parse as continuation', ->
assertErrorFormat '''
a
and ::b
''','''
[stdin]:2:7: error: unexpected ::
and ::b
^^
'''

</script>
<script type="text/x-coffeescript" class="test" id="eval">
if vm = require? 'vm'
Expand Down Expand Up @@ -23801,6 +23811,218 @@ <h1>CoffeeScript Test Suite</h1>

eq 3, new B().c()

test "logical and/or should continue lines", ->
ok not (
yes
and no
)

ok not (
1
and 0
)

ok 'abc'
&& 123

ok 'abc'
&& 123

ok 'abc'
or 123

ok 'abc'
or 123

ok 'abc'
|| 123

ok 'abc'
|| 123

a =
and : 'b'
or : 'a'
ok 'a' is a.or

b =
or : 'b'
and : 'a'
ok 'a' is b.and

yup = -> yes
nope = -> no

eq 3,
yes
and yup
c: 2
and 3

eq 3,
yes
and yup
c: 2
and 3

eq 3,
no
or nope
c: 2
or 3

eq 3,
no
or nope
c: 2
or 3

eq 5,
yes
and yup
c: 2
if yes
3
else
4
and 5

eq 5,
yes
and yup
c: 2
if yes
3
else
4
and 5

eq yes,
yes
and yup
c: 2
if yes
3
else
4
and 5

eq yes,
yes
and yup
c: 2
if yes
3
else
4
and 5

eq 2,
no
or nope -> 1
or 2

eq 2,
no
or nope -> 1
or 2

eq 2,
no
or nope ->
1
or 2

eq 2,
no
or nope ->
1
or 2

eq no,
no
or nope ->
1
or 2

eq no,
no
or nope ->
1
or 2

eq no,
no
or nope ->
1
or 2

f = ({c}) -> c
eq 3,
yes
and f
c:
no
or 3

eq 3,
yes
and f
c:
no
or 3

eq 1,
yes
and f
c:
1
or 3

eq 3,
if yes
and yes
3

eq 3,
if yes
and yes
3

eq 3,
if yes
and yes
3

eq 3,
if yes
and yes
3

test "leading and/or should continue object property", ->
obj =
a: yes
and yes
eq yes, obj.a

obj =
b: 1
a: yes
and yes
eq yes, obj.a

obj =
a: yes
and yes
b: 1
eq yes, obj.a

# when object doesn't start line, don't treat as continuation of object property
f = -> no
eq yes,
f a: 1
or yes

</script>
<script type="text/x-coffeescript" class="test" id="function_invocation">
# Function Invocation
Expand Down
2 changes: 1 addition & 1 deletion lib/coffeescript-browser-compiler-legacy/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/coffeescript-browser-compiler-modern/coffeescript.js

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion lib/coffeescript/grammar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions lib/coffeescript/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading