File: parser.coffee

package info (click to toggle)
coffeescript 2.7.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,360 kB
  • sloc: makefile: 20; xml: 9; sh: 6; javascript: 5
file content (80 lines) | stat: -rw-r--r-- 2,406 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Parser
# ---------

test "operator precedence for logical operators", ->
  source = '''
    a or b and c
  '''
  {body: block} = CoffeeScript.nodes source
  [expression] = block.expressions
  eq expression.first.base.value, 'a'
  eq expression.operator, '||'
  eq expression.second.first.base.value, 'b'
  eq expression.second.operator, '&&'
  eq expression.second.second.base.value, 'c'

test "operator precedence for bitwise operators", ->
  source = '''
    a | b ^ c & d
  '''
  {body: block} = CoffeeScript.nodes source
  [expression] = block.expressions
  eq expression.first.base.value, 'a'
  eq expression.operator, '|'
  eq expression.second.first.base.value, 'b'
  eq expression.second.operator, '^'
  eq expression.second.second.first.base.value, 'c'
  eq expression.second.second.operator, '&'
  eq expression.second.second.second.base.value, 'd'

test "operator precedence for binary ? operator", ->
  source = '''
     a ? b and c
  '''
  {body: block} = CoffeeScript.nodes source
  [expression] = block.expressions
  eq expression.first.base.value, 'a'
  eq expression.operator, '?'
  eq expression.second.first.base.value, 'b'
  eq expression.second.operator, '&&'
  eq expression.second.second.base.value, 'c'

test "new calls have a range including the new", ->
  source = '''
    a = new B().c(d)
  '''
  {body: block} = CoffeeScript.nodes source

  assertColumnRange = (node, firstColumn, lastColumn) ->
    eq node.locationData.first_line, 0
    eq node.locationData.first_column, firstColumn
    eq node.locationData.last_line, 0
    eq node.locationData.last_column, lastColumn

  [assign] = block.expressions
  outerCall = assign.value.base
  innerValue = outerCall.variable
  innerCall = innerValue.base

  assertColumnRange assign, 0, 15
  assertColumnRange outerCall, 4, 15
  assertColumnRange innerValue, 4, 12
  assertColumnRange innerCall, 4, 10

test "location data is properly set for nested `new`", ->
  source = '''
    new new A()()
  '''
  {body: block} = CoffeeScript.nodes source

  assertColumnRange = (node, firstColumn, lastColumn) ->
    eq node.locationData.first_line, 0
    eq node.locationData.first_column, firstColumn
    eq node.locationData.last_line, 0
    eq node.locationData.last_column, lastColumn

  [{base: outerCall}] = block.expressions
  innerCall = outerCall.variable

  assertColumnRange outerCall, 0, 12
  assertColumnRange innerCall, 4, 10