Skip to content

Commit 6f52bac

Browse files
author
Sam Heavner
committed
fix(chains): fix chained call exp
1 parent bdb84ea commit 6f52bac

6 files changed

Lines changed: 33 additions & 18 deletions

File tree

diagram/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
</style>
1010

1111

12-
<link rel='stylesheet' href='https://unpkg.com/chevrotain@3.4.0/diagrams/diagrams.css'>
12+
<link rel='stylesheet' href='https://unpkg.com/chevrotain@3.7.2/diagrams/diagrams.css'>
1313

14-
<script src='https://unpkg.com/chevrotain@3.4.0/diagrams/vendor/railroad-diagrams.js'></script>
15-
<script src='https://unpkg.com/chevrotain@3.4.0/diagrams/src/diagrams_builder.js'></script>
16-
<script src='https://unpkg.com/chevrotain@3.4.0/diagrams/src/diagrams_behavior.js'></script>
17-
<script src='https://unpkg.com/chevrotain@3.4.0/diagrams/src/main.js'></script>
14+
<script src='https://unpkg.com/chevrotain@3.7.2/diagrams/vendor/railroad-diagrams.js'></script>
15+
<script src='https://unpkg.com/chevrotain@3.7.2/diagrams/src/diagrams_builder.js'></script>
16+
<script src='https://unpkg.com/chevrotain@3.7.2/diagrams/src/diagrams_behavior.js'></script>
17+
<script src='https://unpkg.com/chevrotain@3.7.2/diagrams/src/main.js'></script>
1818

1919
<div id="diagrams" align="center"></div>
2020

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"devDependencies": {
3636
"@types/jest": "23.3.2",
3737
"semantic-release": "15.7.2",
38-
"@types/jest": "23.3.2",
3938
"@types/lodash": "4.14.112",
4039
"@types/node": "^11.9.0",
4140
"babel-code-frame": "6.26.0",

src/ASTVisitor.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,15 @@ export class ASTVisitor extends BaseVisitor {
715715
*
716716
* @memberOf ASTVisitor
717717
*/
718-
public CallExpression({ id, args }: NodeContext): ASTNode {
718+
public CallExpression({ id, args, properties }: NodeContext): ASTNode {
719+
properties = this.asArray(properties)
720+
const tail = properties.length > 0 ? last(properties) : args
719721
return {
720-
...this.Location(id, args),
722+
...this.Location(id, tail),
721723
args,
722724
callee: id,
723-
type: 'CallExpression'
725+
properties,
726+
type: 'CallExpression',
724727
}
725728
}
726729

@@ -757,7 +760,7 @@ export class ASTVisitor extends BaseVisitor {
757760
this.singleArgument(ctx) ||
758761
this.mapArguments(ctx, ({ id, properties = [], args = '' }) => {
759762
if (args) {
760-
return this.asNode(this.CallExpression({ id, args }), ctx)
763+
return this.asNode(this.CallExpression({ id, args, properties }), ctx)
761764
} else {
762765
return this.asNode(this.ObjectMemberExpression({ id, properties }), ctx)
763766
}
@@ -778,7 +781,7 @@ export class ASTVisitor extends BaseVisitor {
778781
this.singleArgument(ctx) ||
779782
this.mapArguments(ctx, ({ property, args }) => {
780783
if (args) {
781-
return this.CallExpression({ id: property, args })
784+
return this.CallExpression({ id: property, args, properties: [] })
782785
} else {
783786
return this.ObjectMemberExpression({ id: property, properties: [] })
784787
}
@@ -841,7 +844,6 @@ export class ASTVisitor extends BaseVisitor {
841844
)
842845
})
843846
}
844-
845847
/**
846848
*
847849
*

test/location.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ describe('Location tests', () => {
1414
test('Should identify location of multiline statement', () => {
1515
expect(() => {
1616
const ast = sourceAST(['function gotoStatement()', ' mylabel:', ' print "Anthony was here!"', '', ' goto mylabel', 'end function', ''].join('\n'))
17-
1817
expect(ast.range).toEqual([0, 92])
1918
}).not.toThrow()
2019
})
20+
21+
test('Should find chains', () => {
22+
expect(() => {
23+
const ast = sourceAST('logUtil().debug("Writing hideScores:{0} to registry", v)', 'BlockStatement')
24+
expect(ast.range).toEqual([0, 56])
25+
}).not.toThrow()
26+
})
2127
})

tsconfig.jest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"compilerOptions": {
44
"module": "commonjs"
55
}
6-
}
6+
}

tsconfig.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
"declaration": true,
88
"emitDecoratorMetadata": true,
99
"experimentalDecorators": true,
10-
"lib": ["dom", "es6", "es2015"],
10+
"lib": [
11+
"dom",
12+
"es6",
13+
"es2015"
14+
],
1115
"module": "commonjs",
1216
"outDir": "dist",
1317
"moduleResolution": "node",
@@ -19,10 +23,14 @@
1923
"removeComments": true,
2024
"sourceMap": false,
2125
"target": "es6",
22-
"typeRoots": ["node_modules/@types"]
26+
"typeRoots": [
27+
"node_modules/@types"
28+
]
2329
},
2430
"typeAcquisition": {
2531
"enable": true
2632
},
27-
"include": ["src"]
28-
}
33+
"include": [
34+
"src"
35+
]
36+
}

0 commit comments

Comments
 (0)