-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major refactor of mutation paths/AST traversal
- Loading branch information
Showing
9 changed files
with
157 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
- get CLI e2e test working | ||
- `--strict` mode with stuff to ensure no mutation happens | ||
- `--strict` mode with stuff to ensure no mutation happens in plugins (mutators in particular) | ||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import fs = require("fs-extra"); | ||
import R = require("ramda"); | ||
import updateIn = require("./util/update-in"); | ||
|
||
import estraverse = require("estraverse"); | ||
import CommentManager = require("./comments"); | ||
|
||
// TODO this should be injected somehow | ||
import shouldSkip = require("./skippers"); | ||
|
||
// the nice thing about this is that the plugins that are returned | ||
// originate with the MutatorFinder argument, which simplifies testing | ||
function getMutantLocations (locator: MutatorFinder, ast: ESTree.Node): MutantLocation[] { | ||
const mutantLocations: MutantLocation[] = []; | ||
const manager = new CommentManager(); | ||
|
||
estraverse.traverse(ast, { | ||
enter: function (node: ESTree.Node) { | ||
const locs: MutantLocation[] = applyVisitor(node, this, manager, locator); | ||
mutantLocations.push(...locs); | ||
}, | ||
}); | ||
return mutantLocations; | ||
} | ||
|
||
// No typings for estraverse.Controller :/ | ||
function applyVisitor (node: ESTree.Node, controller: any, manager: CommentManager, locator: MutatorFinder): MutantLocation[] { | ||
const path : string[] = controller.path(); | ||
|
||
// TODO -- `shouldSkip` is the last part here which is in local module state rather than coming from an | ||
// argument | ||
if (shouldSkip(node, path)) { | ||
controller.skip(); | ||
return []; | ||
} | ||
|
||
manager.applyNode(node); | ||
|
||
return locator(node) | ||
.filter(plugin => !manager.hasName(plugin.name)) | ||
.filter(m => m.filter == null || m.filter(node)) | ||
.map(plugin => ({node, path, mutator: plugin})) | ||
} | ||
|
||
export = R.curry(getMutantLocations); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.