Skip to content

Commit

Permalink
fix(chains): fix chained call exp
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Heavner committed Mar 10, 2020
1 parent bdb84ea commit 3896d4b
Show file tree
Hide file tree
Showing 7 changed files with 1,865 additions and 1,300 deletions.
10 changes: 5 additions & 5 deletions diagram/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</style>


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

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

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

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"devDependencies": {
"@types/jest": "23.3.2",
"semantic-release": "15.7.2",
"@types/jest": "23.3.2",
"@types/lodash": "4.14.112",
"@types/node": "^11.9.0",
"babel-code-frame": "6.26.0",
Expand Down
14 changes: 8 additions & 6 deletions src/ASTVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,15 @@ export class ASTVisitor extends BaseVisitor {
*
* @memberOf ASTVisitor
*/
public CallExpression({ id, args }: NodeContext): ASTNode {
public CallExpression({ id, args, properties }: NodeContext): ASTNode {
properties = this.asArray(properties)
const tail = properties.length > 0 ? last(properties) : args
return {
...this.Location(id, args),
...this.Location(id, tail),
args,
callee: id,
type: 'CallExpression'
properties,
type: 'CallExpression',
}
}

Expand Down Expand Up @@ -757,7 +760,7 @@ export class ASTVisitor extends BaseVisitor {
this.singleArgument(ctx) ||
this.mapArguments(ctx, ({ id, properties = [], args = '' }) => {
if (args) {
return this.asNode(this.CallExpression({ id, args }), ctx)
return this.asNode(this.CallExpression({ id, args, properties }), ctx)
} else {
return this.asNode(this.ObjectMemberExpression({ id, properties }), ctx)
}
Expand All @@ -778,7 +781,7 @@ export class ASTVisitor extends BaseVisitor {
this.singleArgument(ctx) ||
this.mapArguments(ctx, ({ property, args }) => {
if (args) {
return this.CallExpression({ id: property, args })
return this.CallExpression({ id: property, args, properties: [] })
} else {
return this.ObjectMemberExpression({ id: property, properties: [] })
}
Expand Down Expand Up @@ -841,7 +844,6 @@ export class ASTVisitor extends BaseVisitor {
)
})
}

/**
*
*
Expand Down
8 changes: 7 additions & 1 deletion test/location.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ describe('Location tests', () => {
test('Should identify location of multiline statement', () => {
expect(() => {
const ast = sourceAST(['function gotoStatement()', ' mylabel:', ' print "Anthony was here!"', '', ' goto mylabel', 'end function', ''].join('\n'))

expect(ast.range).toEqual([0, 92])
}).not.toThrow()
})

test('Should find chains', () => {
expect(() => {
const ast = sourceAST('logUtil().debug("Writing hideScores:{0} to registry", v)', 'BlockStatement')
expect(ast.range).toEqual([0, 56])
}).not.toThrow()
})
})
2 changes: 1 addition & 1 deletion tsconfig.jest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"compilerOptions": {
"module": "commonjs"
}
}
}
16 changes: 12 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["dom", "es6", "es2015"],
"lib": [
"dom",
"es6",
"es2015"
],
"module": "commonjs",
"outDir": "dist",
"moduleResolution": "node",
Expand All @@ -19,10 +23,14 @@
"removeComments": true,
"sourceMap": false,
"target": "es6",
"typeRoots": ["node_modules/@types"]
"typeRoots": [
"node_modules/@types"
]
},
"typeAcquisition": {
"enable": true
},
"include": ["src"]
}
"include": [
"src"
]
}
Loading

0 comments on commit 3896d4b

Please sign in to comment.