AST: clean up AST tests (#5261)
* this property * clean up AST tests * updated grammar * export location data * export default class location data
This commit is contained in:
parent
09caa217c2
commit
559e735994
|
@ -985,30 +985,33 @@
|
|||
}),
|
||||
o('EXPORT Identifier = Expression',
|
||||
function() {
|
||||
return new ExportNamedDeclaration(new Assign($2,
|
||||
return new ExportNamedDeclaration(LOC(2,
|
||||
4)(new Assign($2,
|
||||
$4,
|
||||
null,
|
||||
{
|
||||
moduleDeclaration: 'export'
|
||||
}));
|
||||
})));
|
||||
}),
|
||||
o('EXPORT Identifier = TERMINATOR Expression',
|
||||
function() {
|
||||
return new ExportNamedDeclaration(new Assign($2,
|
||||
return new ExportNamedDeclaration(LOC(2,
|
||||
5)(new Assign($2,
|
||||
$5,
|
||||
null,
|
||||
{
|
||||
moduleDeclaration: 'export'
|
||||
}));
|
||||
})));
|
||||
}),
|
||||
o('EXPORT Identifier = INDENT Expression OUTDENT',
|
||||
function() {
|
||||
return new ExportNamedDeclaration(new Assign($2,
|
||||
return new ExportNamedDeclaration(LOC(2,
|
||||
6)(new Assign($2,
|
||||
$5,
|
||||
null,
|
||||
{
|
||||
moduleDeclaration: 'export'
|
||||
}));
|
||||
})));
|
||||
}),
|
||||
o('EXPORT DEFAULT Expression',
|
||||
function() {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -493,12 +493,12 @@ grammar =
|
|||
o 'EXPORT { }', -> new ExportNamedDeclaration new ExportSpecifierList []
|
||||
o 'EXPORT { ExportSpecifierList OptComma }', -> new ExportNamedDeclaration new ExportSpecifierList $3
|
||||
o 'EXPORT Class', -> new ExportNamedDeclaration $2
|
||||
o 'EXPORT Identifier = Expression', -> new ExportNamedDeclaration new Assign $2, $4, null,
|
||||
moduleDeclaration: 'export'
|
||||
o 'EXPORT Identifier = TERMINATOR Expression', -> new ExportNamedDeclaration new Assign $2, $5, null,
|
||||
moduleDeclaration: 'export'
|
||||
o 'EXPORT Identifier = INDENT Expression OUTDENT', -> new ExportNamedDeclaration new Assign $2, $5, null,
|
||||
moduleDeclaration: 'export'
|
||||
o 'EXPORT Identifier = Expression', -> new ExportNamedDeclaration LOC(2,4)(new Assign $2, $4, null,
|
||||
moduleDeclaration: 'export')
|
||||
o 'EXPORT Identifier = TERMINATOR Expression', -> new ExportNamedDeclaration LOC(2,5)(new Assign $2, $5, null,
|
||||
moduleDeclaration: 'export')
|
||||
o 'EXPORT Identifier = INDENT Expression OUTDENT', -> new ExportNamedDeclaration LOC(2,6)(new Assign $2, $5, null,
|
||||
moduleDeclaration: 'export')
|
||||
o 'EXPORT DEFAULT Expression', -> new ExportDefaultDeclaration $3
|
||||
o 'EXPORT DEFAULT INDENT Object OUTDENT', -> new ExportDefaultDeclaration new Value $4
|
||||
o 'EXPORT EXPORT_ALL FROM String', -> new ExportAllDeclaration new Literal($2), $4
|
||||
|
|
|
@ -685,7 +685,20 @@ test "AST as expected for ThisLiteral node", ->
|
|||
testExpression '@',
|
||||
type: 'ThisExpression'
|
||||
shorthand: yes
|
||||
# TODO: `@prop` property access isn't covered yet in these tests.
|
||||
|
||||
testExpression '@b',
|
||||
type: 'MemberExpression'
|
||||
object:
|
||||
type: 'ThisExpression'
|
||||
shorthand: yes
|
||||
property: ID 'b'
|
||||
|
||||
testExpression 'this.b',
|
||||
type: 'MemberExpression'
|
||||
object:
|
||||
type: 'ThisExpression'
|
||||
shorthand: no
|
||||
property: ID 'b'
|
||||
|
||||
test "AST as expected for UndefinedLiteral node", ->
|
||||
testExpression 'undefined',
|
||||
|
@ -769,25 +782,6 @@ test "AST as expected for AwaitReturn node", ->
|
|||
argument: NUMBER 2
|
||||
]
|
||||
|
||||
# test "AST as expected for Value node", ->
|
||||
# testExpression 'for i in [] then i',
|
||||
# body:
|
||||
# type: 'Value'
|
||||
# isDefaultValue: no
|
||||
# base:
|
||||
# value: 'i'
|
||||
# properties: []
|
||||
|
||||
# testExpression 'if 1 then 1 else 2',
|
||||
# body:
|
||||
# type: 'Value'
|
||||
# isDefaultValue: no
|
||||
# elseBody:
|
||||
# type: 'Value'
|
||||
# isDefaultValue: no
|
||||
|
||||
# # TODO: Figgure out the purpose of `isDefaultValue`. It's not set in `Switch` either.
|
||||
|
||||
test "AST as expected for Call node", ->
|
||||
testExpression 'fn()',
|
||||
type: 'CallExpression'
|
||||
|
@ -1329,28 +1323,6 @@ test "AST as expected for Range node", ->
|
|||
to:
|
||||
value: 2
|
||||
|
||||
# testExpression 'for x in [42...43] then',
|
||||
# range: yes
|
||||
# source:
|
||||
# type: 'Range'
|
||||
# exclusive: yes
|
||||
# equals: ''
|
||||
# from:
|
||||
# value: '42'
|
||||
# to:
|
||||
# value: '43'
|
||||
|
||||
# testExpression 'for x in [y..z] then',
|
||||
# range: yes
|
||||
# source:
|
||||
# type: 'Range'
|
||||
# exclusive: no
|
||||
# equals: '='
|
||||
# from:
|
||||
# value: 'y'
|
||||
# to:
|
||||
# value: 'z'
|
||||
|
||||
test "AST as expected for Slice node", ->
|
||||
testExpression 'x[..y]',
|
||||
property:
|
||||
|
@ -1375,18 +1347,18 @@ test "AST as expected for Slice node", ->
|
|||
from: null
|
||||
to: null
|
||||
|
||||
# testExpression '"abc"[...2]',
|
||||
# type: 'MemberExpression'
|
||||
# property:
|
||||
# type: 'Range'
|
||||
# from: null
|
||||
# to:
|
||||
# type: 'NumericLiteral'
|
||||
# value: 2
|
||||
# exclusive: yes
|
||||
# computed: yes
|
||||
# optional: no
|
||||
# shorthand: no
|
||||
testExpression '"abc"[...2]',
|
||||
type: 'MemberExpression'
|
||||
property:
|
||||
type: 'Range'
|
||||
from: null
|
||||
to:
|
||||
type: 'NumericLiteral'
|
||||
value: 2
|
||||
exclusive: yes
|
||||
computed: yes
|
||||
optional: no
|
||||
shorthand: no
|
||||
|
||||
testExpression 'x[...][a..][b...][..c][...d]',
|
||||
type: 'MemberExpression'
|
||||
|
@ -1562,10 +1534,6 @@ test "AST as expected for Obj node", ->
|
|||
]
|
||||
implicit: yes
|
||||
|
||||
# # TODO: Test destructuring.
|
||||
|
||||
# # console.log JSON.stringify expression, ["type", "generated", "lhs", "value", "properties", "variable"], 2
|
||||
|
||||
test "AST as expected for Arr node", ->
|
||||
testExpression '[]',
|
||||
type: 'ArrayExpression'
|
||||
|
@ -1579,8 +1547,6 @@ test "AST as expected for Arr node", ->
|
|||
{operator: '!'}
|
||||
]
|
||||
|
||||
# # TODO: Test destructuring.
|
||||
|
||||
test "AST as expected for Class node", ->
|
||||
testStatement 'class Klass',
|
||||
type: 'ClassDeclaration'
|
||||
|
@ -1998,7 +1964,18 @@ test "AST as expected for ExportNamedDeclaration node", ->
|
|||
source: null
|
||||
exportKind: 'value'
|
||||
|
||||
# testStatement 'export class A',
|
||||
testStatement 'export class A',
|
||||
type: 'ExportNamedDeclaration'
|
||||
declaration:
|
||||
type: 'ClassDeclaration'
|
||||
id: ID 'A', declaration: yes
|
||||
superClass: null
|
||||
body:
|
||||
type: 'ClassBody'
|
||||
body: []
|
||||
specifiers: []
|
||||
source: null
|
||||
exportKind: 'value'
|
||||
|
||||
testStatement 'export {x as y, z as default}',
|
||||
type: 'ExportNamedDeclaration'
|
||||
|
@ -2298,8 +2275,6 @@ test "AST as expected for Assign node", ->
|
|||
operator: '?='
|
||||
]
|
||||
|
||||
# # `FuncGlyph` node isn't exported.
|
||||
|
||||
test "AST as expected for Code node", ->
|
||||
testExpression '=>',
|
||||
type: 'ArrowFunctionExpression'
|
||||
|
@ -2696,14 +2671,15 @@ test "AST as expected for Splat node", ->
|
|||
postfix: no
|
||||
]
|
||||
|
||||
# # TODO: Test object splats.
|
||||
|
||||
test "AST as expected for Expansion node", ->
|
||||
# testExpression '(...) ->',
|
||||
# type: 'Code'
|
||||
# params: [
|
||||
# {type: 'Expansion'}
|
||||
# ]
|
||||
testExpression '(..., b) ->',
|
||||
type: 'FunctionExpression'
|
||||
params: [
|
||||
type: 'RestElement'
|
||||
argument: null
|
||||
,
|
||||
ID 'b'
|
||||
]
|
||||
|
||||
testExpression '[..., b] = c',
|
||||
type: 'AssignmentExpression'
|
||||
|
@ -3180,21 +3156,20 @@ test "AST as expected for Existence node", ->
|
|||
operator: '?'
|
||||
prefix: no
|
||||
|
||||
# # NOTE: Soaking is covered in `Call` and `Access` nodes.
|
||||
|
||||
test "AST as expected for Parens node", ->
|
||||
testExpression '(hmmmmm)',
|
||||
type: 'Identifier'
|
||||
name: 'hmmmmm'
|
||||
|
||||
# testExpression '(a + b) / c',
|
||||
# type: 'Op'
|
||||
# operator: '/'
|
||||
# first:
|
||||
# type: 'Parens'
|
||||
# body:
|
||||
# type: 'Op'
|
||||
# operator: '+'
|
||||
testExpression '(a + b) / c',
|
||||
type: 'BinaryExpression'
|
||||
operator: '/'
|
||||
left:
|
||||
type: 'BinaryExpression'
|
||||
operator: '+'
|
||||
left: ID 'a'
|
||||
right: ID 'b'
|
||||
right: ID 'c'
|
||||
|
||||
testExpression '(((1)))',
|
||||
type: 'NumericLiteral'
|
||||
|
@ -3600,8 +3575,6 @@ test "AST as expected for For node", ->
|
|||
name:
|
||||
type: 'ArrayPattern'
|
||||
|
||||
# # TODO: Figure out the purpose of `pattern` and `returns`.
|
||||
|
||||
test "AST as expected for Switch node", ->
|
||||
testStatement '''
|
||||
switch x
|
||||
|
@ -3736,8 +3709,6 @@ test "AST as expected for Switch node", ->
|
|||
]
|
||||
]
|
||||
|
||||
# # TODO: File issue for compile error when using `then` or `;` where `\n` is rn.
|
||||
|
||||
test "AST as expected for If node", ->
|
||||
testStatement 'if maybe then yes',
|
||||
type: 'IfStatement'
|
||||
|
|
|
@ -1403,16 +1403,86 @@ test "AST location data as expected for ExportNamedDeclaration node", ->
|
|||
line: 1
|
||||
column: 9
|
||||
|
||||
# testAstLocationData 'export fn = ->',
|
||||
# type: 'ExportNamedDeclaration'
|
||||
# clause:
|
||||
# type: 'Assign'
|
||||
# variable:
|
||||
# value: 'fn'
|
||||
# value:
|
||||
# type: 'Code'
|
||||
testAstLocationData 'export fn = ->',
|
||||
type: 'ExportNamedDeclaration'
|
||||
declaration:
|
||||
left:
|
||||
start: 7
|
||||
end: 9
|
||||
range: [7, 9]
|
||||
loc:
|
||||
start:
|
||||
line: 1
|
||||
column: 7
|
||||
end:
|
||||
line: 1
|
||||
column: 9
|
||||
right:
|
||||
start: 12
|
||||
end: 14
|
||||
range: [12, 14]
|
||||
loc:
|
||||
start:
|
||||
line: 1
|
||||
column: 12
|
||||
end:
|
||||
line: 1
|
||||
column: 14
|
||||
start: 7
|
||||
end: 14
|
||||
range: [7, 14]
|
||||
loc:
|
||||
start:
|
||||
line: 1
|
||||
column: 7
|
||||
end:
|
||||
line: 1
|
||||
column: 14
|
||||
start: 0
|
||||
end: 14
|
||||
range: [0, 14]
|
||||
loc:
|
||||
start:
|
||||
line: 1
|
||||
column: 0
|
||||
end:
|
||||
line: 1
|
||||
column: 14
|
||||
|
||||
# testAstLocationData 'export class A',
|
||||
testAstLocationData 'export class A',
|
||||
type: 'ExportNamedDeclaration'
|
||||
declaration:
|
||||
id:
|
||||
start: 13
|
||||
end: 14
|
||||
range: [13, 14]
|
||||
loc:
|
||||
start:
|
||||
line: 1
|
||||
column: 13
|
||||
end:
|
||||
line: 1
|
||||
column: 14
|
||||
start: 7
|
||||
end: 14
|
||||
range: [7, 14]
|
||||
loc:
|
||||
start:
|
||||
line: 1
|
||||
column: 7
|
||||
end:
|
||||
line: 1
|
||||
column: 14
|
||||
start: 0
|
||||
end: 14
|
||||
range: [0, 14]
|
||||
loc:
|
||||
start:
|
||||
line: 1
|
||||
column: 0
|
||||
end:
|
||||
line: 1
|
||||
column: 14
|
||||
|
||||
testAstLocationData '''
|
||||
export {
|
||||
|
@ -1580,10 +1650,29 @@ test "AST location data as expected for ExportNamedDeclaration node", ->
|
|||
column: 43
|
||||
|
||||
test "AST location data as expected for ExportDefaultDeclaration node", ->
|
||||
# testAstLocationData 'export default class',
|
||||
# type: 'ExportDefaultDeclaration'
|
||||
# clause:
|
||||
# type: 'Class'
|
||||
testAstLocationData 'export default class',
|
||||
type: 'ExportDefaultDeclaration'
|
||||
declaration:
|
||||
start: 15
|
||||
end: 20
|
||||
range: [15, 20]
|
||||
loc:
|
||||
start:
|
||||
line: 1
|
||||
column: 15
|
||||
end:
|
||||
line: 1
|
||||
column: 20
|
||||
start: 0
|
||||
end: 20
|
||||
range: [0, 20]
|
||||
loc:
|
||||
start:
|
||||
line: 1
|
||||
column: 0
|
||||
end:
|
||||
line: 1
|
||||
column: 20
|
||||
|
||||
testAstLocationData 'export default "abc"',
|
||||
type: 'ExportDefaultDeclaration'
|
||||
|
|
Loading…
Reference in New Issue