Skip to content

Commit 559e735

Browse files
helixbassGeoffreyBooth
authored andcommitted
AST: clean up AST tests (#5261)
* this property * clean up AST tests * updated grammar * export location data * export default class location data
1 parent 09caa21 commit 559e735

File tree

5 files changed

+187
-124
lines changed

5 files changed

+187
-124
lines changed

lib/coffeescript/grammar.js

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

lib/coffeescript/parser.js

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

src/grammar.coffee

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,12 @@ grammar =
493493
o 'EXPORT { }', -> new ExportNamedDeclaration new ExportSpecifierList []
494494
o 'EXPORT { ExportSpecifierList OptComma }', -> new ExportNamedDeclaration new ExportSpecifierList $3
495495
o 'EXPORT Class', -> new ExportNamedDeclaration $2
496-
o 'EXPORT Identifier = Expression', -> new ExportNamedDeclaration new Assign $2, $4, null,
497-
moduleDeclaration: 'export'
498-
o 'EXPORT Identifier = TERMINATOR Expression', -> new ExportNamedDeclaration new Assign $2, $5, null,
499-
moduleDeclaration: 'export'
500-
o 'EXPORT Identifier = INDENT Expression OUTDENT', -> new ExportNamedDeclaration new Assign $2, $5, null,
501-
moduleDeclaration: 'export'
496+
o 'EXPORT Identifier = Expression', -> new ExportNamedDeclaration LOC(2,4)(new Assign $2, $4, null,
497+
moduleDeclaration: 'export')
498+
o 'EXPORT Identifier = TERMINATOR Expression', -> new ExportNamedDeclaration LOC(2,5)(new Assign $2, $5, null,
499+
moduleDeclaration: 'export')
500+
o 'EXPORT Identifier = INDENT Expression OUTDENT', -> new ExportNamedDeclaration LOC(2,6)(new Assign $2, $5, null,
501+
moduleDeclaration: 'export')
502502
o 'EXPORT DEFAULT Expression', -> new ExportDefaultDeclaration $3
503503
o 'EXPORT DEFAULT INDENT Object OUTDENT', -> new ExportDefaultDeclaration new Value $4
504504
o 'EXPORT EXPORT_ALL FROM String', -> new ExportAllDeclaration new Literal($2), $4

test/abstract_syntax_tree.coffee

Lines changed: 55 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,20 @@ test "AST as expected for ThisLiteral node", ->
685685
testExpression '@',
686686
type: 'ThisExpression'
687687
shorthand: yes
688-
# TODO: `@prop` property access isn't covered yet in these tests.
688+
689+
testExpression '@b',
690+
type: 'MemberExpression'
691+
object:
692+
type: 'ThisExpression'
693+
shorthand: yes
694+
property: ID 'b'
695+
696+
testExpression 'this.b',
697+
type: 'MemberExpression'
698+
object:
699+
type: 'ThisExpression'
700+
shorthand: no
701+
property: ID 'b'
689702

690703
test "AST as expected for UndefinedLiteral node", ->
691704
testExpression 'undefined',
@@ -769,25 +782,6 @@ test "AST as expected for AwaitReturn node", ->
769782
argument: NUMBER 2
770783
]
771784

772-
# test "AST as expected for Value node", ->
773-
# testExpression 'for i in [] then i',
774-
# body:
775-
# type: 'Value'
776-
# isDefaultValue: no
777-
# base:
778-
# value: 'i'
779-
# properties: []
780-
781-
# testExpression 'if 1 then 1 else 2',
782-
# body:
783-
# type: 'Value'
784-
# isDefaultValue: no
785-
# elseBody:
786-
# type: 'Value'
787-
# isDefaultValue: no
788-
789-
# # TODO: Figgure out the purpose of `isDefaultValue`. It's not set in `Switch` either.
790-
791785
test "AST as expected for Call node", ->
792786
testExpression 'fn()',
793787
type: 'CallExpression'
@@ -1329,28 +1323,6 @@ test "AST as expected for Range node", ->
13291323
to:
13301324
value: 2
13311325

1332-
# testExpression 'for x in [42...43] then',
1333-
# range: yes
1334-
# source:
1335-
# type: 'Range'
1336-
# exclusive: yes
1337-
# equals: ''
1338-
# from:
1339-
# value: '42'
1340-
# to:
1341-
# value: '43'
1342-
1343-
# testExpression 'for x in [y..z] then',
1344-
# range: yes
1345-
# source:
1346-
# type: 'Range'
1347-
# exclusive: no
1348-
# equals: '='
1349-
# from:
1350-
# value: 'y'
1351-
# to:
1352-
# value: 'z'
1353-
13541326
test "AST as expected for Slice node", ->
13551327
testExpression 'x[..y]',
13561328
property:
@@ -1375,18 +1347,18 @@ test "AST as expected for Slice node", ->
13751347
from: null
13761348
to: null
13771349

1378-
# testExpression '"abc"[...2]',
1379-
# type: 'MemberExpression'
1380-
# property:
1381-
# type: 'Range'
1382-
# from: null
1383-
# to:
1384-
# type: 'NumericLiteral'
1385-
# value: 2
1386-
# exclusive: yes
1387-
# computed: yes
1388-
# optional: no
1389-
# shorthand: no
1350+
testExpression '"abc"[...2]',
1351+
type: 'MemberExpression'
1352+
property:
1353+
type: 'Range'
1354+
from: null
1355+
to:
1356+
type: 'NumericLiteral'
1357+
value: 2
1358+
exclusive: yes
1359+
computed: yes
1360+
optional: no
1361+
shorthand: no
13901362

13911363
testExpression 'x[...][a..][b...][..c][...d]',
13921364
type: 'MemberExpression'
@@ -1562,10 +1534,6 @@ test "AST as expected for Obj node", ->
15621534
]
15631535
implicit: yes
15641536

1565-
# # TODO: Test destructuring.
1566-
1567-
# # console.log JSON.stringify expression, ["type", "generated", "lhs", "value", "properties", "variable"], 2
1568-
15691537
test "AST as expected for Arr node", ->
15701538
testExpression '[]',
15711539
type: 'ArrayExpression'
@@ -1579,8 +1547,6 @@ test "AST as expected for Arr node", ->
15791547
{operator: '!'}
15801548
]
15811549

1582-
# # TODO: Test destructuring.
1583-
15841550
test "AST as expected for Class node", ->
15851551
testStatement 'class Klass',
15861552
type: 'ClassDeclaration'
@@ -1998,7 +1964,18 @@ test "AST as expected for ExportNamedDeclaration node", ->
19981964
source: null
19991965
exportKind: 'value'
20001966

2001-
# testStatement 'export class A',
1967+
testStatement 'export class A',
1968+
type: 'ExportNamedDeclaration'
1969+
declaration:
1970+
type: 'ClassDeclaration'
1971+
id: ID 'A', declaration: yes
1972+
superClass: null
1973+
body:
1974+
type: 'ClassBody'
1975+
body: []
1976+
specifiers: []
1977+
source: null
1978+
exportKind: 'value'
20021979

20031980
testStatement 'export {x as y, z as default}',
20041981
type: 'ExportNamedDeclaration'
@@ -2298,8 +2275,6 @@ test "AST as expected for Assign node", ->
22982275
operator: '?='
22992276
]
23002277

2301-
# # `FuncGlyph` node isn't exported.
2302-
23032278
test "AST as expected for Code node", ->
23042279
testExpression '=>',
23052280
type: 'ArrowFunctionExpression'
@@ -2696,14 +2671,15 @@ test "AST as expected for Splat node", ->
26962671
postfix: no
26972672
]
26982673

2699-
# # TODO: Test object splats.
2700-
27012674
test "AST as expected for Expansion node", ->
2702-
# testExpression '(...) ->',
2703-
# type: 'Code'
2704-
# params: [
2705-
# {type: 'Expansion'}
2706-
# ]
2675+
testExpression '(..., b) ->',
2676+
type: 'FunctionExpression'
2677+
params: [
2678+
type: 'RestElement'
2679+
argument: null
2680+
,
2681+
ID 'b'
2682+
]
27072683

27082684
testExpression '[..., b] = c',
27092685
type: 'AssignmentExpression'
@@ -3180,21 +3156,20 @@ test "AST as expected for Existence node", ->
31803156
operator: '?'
31813157
prefix: no
31823158

3183-
# # NOTE: Soaking is covered in `Call` and `Access` nodes.
3184-
31853159
test "AST as expected for Parens node", ->
31863160
testExpression '(hmmmmm)',
31873161
type: 'Identifier'
31883162
name: 'hmmmmm'
31893163

3190-
# testExpression '(a + b) / c',
3191-
# type: 'Op'
3192-
# operator: '/'
3193-
# first:
3194-
# type: 'Parens'
3195-
# body:
3196-
# type: 'Op'
3197-
# operator: '+'
3164+
testExpression '(a + b) / c',
3165+
type: 'BinaryExpression'
3166+
operator: '/'
3167+
left:
3168+
type: 'BinaryExpression'
3169+
operator: '+'
3170+
left: ID 'a'
3171+
right: ID 'b'
3172+
right: ID 'c'
31983173

31993174
testExpression '(((1)))',
32003175
type: 'NumericLiteral'
@@ -3600,8 +3575,6 @@ test "AST as expected for For node", ->
36003575
name:
36013576
type: 'ArrayPattern'
36023577

3603-
# # TODO: Figure out the purpose of `pattern` and `returns`.
3604-
36053578
test "AST as expected for Switch node", ->
36063579
testStatement '''
36073580
switch x
@@ -3736,8 +3709,6 @@ test "AST as expected for Switch node", ->
37363709
]
37373710
]
37383711

3739-
# # TODO: File issue for compile error when using `then` or `;` where `\n` is rn.
3740-
37413712
test "AST as expected for If node", ->
37423713
testStatement 'if maybe then yes',
37433714
type: 'IfStatement'

0 commit comments

Comments
 (0)