Skip to content

Commit

Permalink
Add event-eliminator mutator
Browse files Browse the repository at this point in the history
  • Loading branch information
federicobond committed Aug 16, 2018
1 parent eeca48f commit 4c56f13
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function generateAllMutations(files) {

const mutator = new mutators.CompositeMutator([
new mutators.ConditionalBoundaryMutator(),
new mutators.LiteralMutator()
new mutators.LiteralMutator(),
new mutators.EventEliminatorMutator()
])

for (const file of files) {
Expand Down
25 changes: 25 additions & 0 deletions src/mutators/event-eliminator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const Mutation = require('../mutation')

function EventEliminatorMutator() {}

EventEliminatorMutator.prototype.name = 'event-remover'

EventEliminatorMutator.prototype.getMutations = function(file, source, visit) {
const mutations = []

visit({
EmitStatement: (node) => {
const start = node.range[0]
const end = node.range[1]

const text = source.slice(start, end + 1)
const replacement = '/* commented out ' + text + ' */'

mutations.push(new Mutation(file, start, end + 1, replacement))
}
})

return mutations
}

module.exports = EventEliminatorMutator
2 changes: 2 additions & 0 deletions src/mutators/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const ConditionalBoundaryMutator = require('./conditional-boundary')
const EventEliminatorMutator = require('./event-eliminator')
const LiteralMutator = require('./literal')

function CompositeMutator(mutators) {
Expand All @@ -15,6 +16,7 @@ CompositeMutator.prototype.getMutations = function(file, source, visit) {

module.exports = {
ConditionalBoundaryMutator: ConditionalBoundaryMutator,
EventEliminatorMutator: EventEliminatorMutator,
LiteralMutator: LiteralMutator,
CompositeMutator: CompositeMutator
}

0 comments on commit 4c56f13

Please sign in to comment.