Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stryker-mutator/instrumenter

Package Overview
Dependencies
Maintainers
4
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stryker-mutator/instrumenter - npm Package Compare versions

Comparing version 4.5.1 to 4.6.0

12

CHANGELOG.md

@@ -6,2 +6,14 @@ # Change Log

# [4.6.0](https://github.com/stryker-mutator/stryker-js/compare/v4.5.1...v4.6.0) (2021-04-16)
### Features
* **mutation range:** allow specifying a mutation range ([#2751](https://github.com/stryker-mutator/stryker-js/issues/2751)) ([84647cf](https://github.com/stryker-mutator/stryker-js/commit/84647cf8c4052dead95d4d23a0e9c0c66e54292c))
* **rename:** rename to StrykerJS ([#2813](https://github.com/stryker-mutator/stryker-js/issues/2813)) ([dc08592](https://github.com/stryker-mutator/stryker-js/commit/dc08592c09c0fe5fcc21db03dc2da4e03713f46b)), closes [#2754](https://github.com/stryker-mutator/stryker-js/issues/2754)
## [4.5.1](https://github.com/stryker-mutator/stryker/compare/v4.5.0...v4.5.1) (2021-03-11)

@@ -8,0 +20,0 @@

2

dist/src/instrumenter.d.ts

@@ -10,3 +10,3 @@ import { Logger } from '@stryker-mutator/api/logging';

* * Adding mutant coverage expressions in the source code.
* @see https://github.com/stryker-mutator/stryker/issues/1514
* @see https://github.com/stryker-mutator/stryker-js/issues/1514
*/

@@ -13,0 +13,0 @@ export declare class Instrumenter {

@@ -16,3 +16,3 @@ "use strict";

* * Adding mutant coverage expressions in the source code.
* @see https://github.com/stryker-mutator/stryker/issues/1514
* @see https://github.com/stryker-mutator/stryker-js/issues/1514
*/

@@ -34,3 +34,3 @@ class Instrumenter {

const ast = await parse(file.textContent, file.name);
transformers_1.transform(ast, mutantCollector, { options });
transformers_1.transform(ast, mutantCollector, { options: Object.assign(Object.assign({}, options), { mutationRanges: options.mutationRanges.map(toBabelLineNumber) }) });
const mutatedContent = printers_1.print(ast);

@@ -62,2 +62,5 @@ outFiles.push(new core_1.File(file.name, mutatedContent));

Instrumenter.inject = plugin_1.tokens(plugin_1.commonTokens.logger);
function toBabelLineNumber(range) {
return Object.assign(Object.assign({}, range), { end: Object.assign(Object.assign({}, range.end), { line: range.end.line + 1 }), start: Object.assign(Object.assign({}, range.start), { line: range.start.line + 1 }) });
}
//# sourceMappingURL=instrumenter.js.map

@@ -8,3 +8,3 @@ export * from './mutant-placer';

* Represents a mutant placer, tries to place a mutant in the AST with corresponding mutation switch and mutant covering expression
* @see https://github.com/stryker-mutator/stryker/issues/1514
* @see https://github.com/stryker-mutator/stryker-js/issues/1514
* @param node The ast node to try and replace with a mutated

@@ -11,0 +11,0 @@ * @param mutants The mutants to place in the AST node

@@ -13,3 +13,3 @@ "use strict";

* Represents a mutant placer, tries to place a mutant in the AST with corresponding mutation switch and mutant covering expression
* @see https://github.com/stryker-mutator/stryker/issues/1514
* @see https://github.com/stryker-mutator/stryker-js/issues/1514
* @param node The ast node to try and replace with a mutated

@@ -32,6 +32,6 @@ * @param mutants The mutants to place in the AST node

const message = `${placer.name} could not place mutants with type(s): "${mutants.map((mutant) => mutant.mutatorName).join(', ')}"`;
const errorMessage = `${location} ${message}. Either remove this file from the list of files to be mutated, or ignore the mutators. Please report this issue at https://github.com/stryker-mutator/stryker/issues/new?assignees=&labels=%F0%9F%90%9B+Bug&template=bug_report.md&title=${encodeURIComponent(message)}.`;
const errorMessage = `${location} ${message}. Either remove this file from the list of files to be mutated, or ignore the mutators. Please report this issue at https://github.com/stryker-mutator/stryker-js/issues/new?assignees=&labels=%F0%9F%90%9B+Bug&template=bug_report.md&title=${encodeURIComponent(message)}.`;
let builtError = new Error(errorMessage);
try {
// `buildCodeFrameError` is kind of flaky, see https://github.com/stryker-mutator/stryker/issues/2695
// `buildCodeFrameError` is kind of flaky, see https://github.com/stryker-mutator/stryker-js/issues/2695
builtError = node.buildCodeFrameError(errorMessage);

@@ -38,0 +38,0 @@ }

@@ -26,4 +26,4 @@ import { NodePath } from '@babel/core';

* }
* @see https://github.com/stryker-mutator/stryker/issues/2314
* @see https://github.com/stryker-mutator/stryker/issues/2474
* @see https://github.com/stryker-mutator/stryker-js/issues/2314
* @see https://github.com/stryker-mutator/stryker-js/issues/2474
*/

@@ -30,0 +30,0 @@ private isInvalidConstructorBody;

@@ -42,4 +42,4 @@ "use strict";

* }
* @see https://github.com/stryker-mutator/stryker/issues/2314
* @see https://github.com/stryker-mutator/stryker/issues/2474
* @see https://github.com/stryker-mutator/stryker-js/issues/2314
* @see https://github.com/stryker-mutator/stryker-js/issues/2474
*/

@@ -46,0 +46,0 @@ isInvalidConstructorBody(blockStatement) {

@@ -6,3 +6,2 @@ import { NodePath } from '@babel/core';

name: string;
private readonly operators;
mutate(path: NodePath): NodeMutation[];

@@ -9,0 +8,0 @@ private isSupported;

@@ -6,17 +6,18 @@ "use strict";

const types = tslib_1.__importStar(require("@babel/types"));
var UnaryOperators;
(function (UnaryOperators) {
UnaryOperators["+"] = "-";
UnaryOperators["-"] = "+";
UnaryOperators["~"] = "";
})(UnaryOperators || (UnaryOperators = {}));
var UnaryOperator;
(function (UnaryOperator) {
UnaryOperator["+"] = "-";
UnaryOperator["-"] = "+";
UnaryOperator["~"] = "";
})(UnaryOperator || (UnaryOperator = {}));
class UnaryOperatorMutator {
constructor() {
this.name = 'UnaryOperator';
this.operators = UnaryOperators;
}
mutate(path) {
if (path.isUnaryExpression() && this.isSupported(path.node.operator) && path.node.prefix) {
const mutatedOperators = this.operators[path.node.operator];
const replacement = mutatedOperators.length > 0 ? types.unaryExpression(mutatedOperators, path.node.argument) : types.cloneNode(path.node.argument, false);
const mutatedOperator = UnaryOperator[path.node.operator];
const replacement = mutatedOperator.length
? types.unaryExpression(mutatedOperator, path.node.argument)
: types.cloneNode(path.node.argument, false);
return [

@@ -32,3 +33,3 @@ {

isSupported(operator) {
return Object.keys(this.operators).includes(operator);
return Object.keys(UnaryOperator).includes(operator);
}

@@ -35,0 +36,0 @@ }

@@ -17,9 +17,15 @@ "use strict";

const file = new core_2.File({ filename: originFileName }, { code: rawContent, ast: root });
// Range filters that are in scope for the current file
const mutantRangesForCurrentFile = options.mutationRanges.filter((mutantRange) => mutantRange.fileName === originFileName);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
core_1.traverse(file.ast, {
enter(path) {
if (syntax_helpers_1.isTypeNode(path) || syntax_helpers_1.isImportDeclaration(path) || path.isDecorator()) {
// Don't mutate type declarations or import statements
// Don't mutate import statements, type definitions and nodes that don't have overlap with the current range filter
if (syntax_helpers_1.isTypeNode(path) ||
syntax_helpers_1.isImportDeclaration(path) ||
path.isDecorator() ||
(mutantRangesForCurrentFile.length && mutantRangesForCurrentFile.every((range) => !syntax_helpers_1.locationOverlaps(range, path.node.loc)))) {
path.skip();
}
else {
else if (!mutantRangesForCurrentFile.length || mutantRangesForCurrentFile.some((range) => syntax_helpers_1.locationIncluded(range, path.node.loc))) {
mutators_1.mutate(path, options).forEach((mutant) => {

@@ -26,0 +32,0 @@ mutantCollector.add(originFileName, mutant, offset === null || offset === void 0 ? void 0 : offset.position, offset === null || offset === void 0 ? void 0 : offset.line);

@@ -0,3 +1,6 @@

import { MutationRange } from '@stryker-mutator/api/core';
import { MutatorOptions } from '../mutators';
export declare type TransformerOptions = MutatorOptions;
export interface TransformerOptions extends MutatorOptions {
mutationRanges: readonly MutationRange[];
}
//# sourceMappingURL=transformer-options.d.ts.map

@@ -31,2 +31,12 @@ import { INSTRUMENTER_CONSTANTS as ID } from '@stryker-mutator/api/core';

export declare function isImportDeclaration(path: NodePath): boolean;
/**
* Determines if a location (needle) is included in an other location (haystack)
* @param haystack The range to look in
* @param needle the range to search for
*/
export declare function locationIncluded(haystack: types.SourceLocation, needle: types.SourceLocation): boolean;
/**
* Determines if two locations overlap with each other
*/
export declare function locationOverlaps(a: types.SourceLocation, b: types.SourceLocation): boolean;
//# sourceMappingURL=syntax-helpers.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isImportDeclaration = exports.isTypeNode = exports.mutationCoverageSequenceExpression = exports.createMutatedAst = exports.offsetLocations = exports.eqNode = exports.mutantTestExpression = exports.instrumentationBabelHeader = exports.ID = void 0;
exports.locationOverlaps = exports.locationIncluded = exports.isImportDeclaration = exports.isTypeNode = exports.mutationCoverageSequenceExpression = exports.createMutatedAst = exports.offsetLocations = exports.eqNode = exports.mutantTestExpression = exports.instrumentationBabelHeader = exports.ID = void 0;
const tslib_1 = require("tslib");

@@ -183,2 +183,22 @@ const core_1 = require("@stryker-mutator/api/core");

exports.isImportDeclaration = isImportDeclaration;
/**
* Determines if a location (needle) is included in an other location (haystack)
* @param haystack The range to look in
* @param needle the range to search for
*/
function locationIncluded(haystack, needle) {
const startIncluded = haystack.start.line < needle.start.line || (haystack.start.line === needle.start.line && haystack.start.column <= needle.start.column);
const endIncluded = haystack.end.line > needle.end.line || (haystack.end.line === needle.end.line && haystack.end.column >= needle.end.column);
return startIncluded && endIncluded;
}
exports.locationIncluded = locationIncluded;
/**
* Determines if two locations overlap with each other
*/
function locationOverlaps(a, b) {
const startIncluded = a.start.line < b.end.line || (a.start.line === b.end.line && a.start.column <= b.end.column);
const endIncluded = a.end.line > b.start.line || (a.end.line === b.start.line && a.end.column >= b.start.column);
return startIncluded && endIncluded;
}
exports.locationOverlaps = locationOverlaps;
//# sourceMappingURL=syntax-helpers.js.map
{
"name": "@stryker-mutator/instrumenter",
"version": "4.5.1",
"version": "4.6.0",
"description": "The code instrumenter used in Stryker, the JavaScript mutation testing framework",

@@ -13,3 +13,3 @@ "main": "dist/src/index.js",

"type": "git",
"url": "https://github.com/stryker-mutator/stryker",
"url": "https://github.com/stryker-mutator/stryker-js.git",
"directory": "packages/instrumenter"

@@ -30,3 +30,3 @@ },

"bugs": {
"url": "https://github.com/stryker-mutator/stryker/issues"
"url": "https://github.com/stryker-mutator/stryker-js/issues"
},

@@ -42,10 +42,10 @@ "homepage": "https://stryker-mutator.io",

"@babel/preset-typescript": "~7.13.0 ",
"@stryker-mutator/api": "4.5.1",
"@stryker-mutator/util": "4.5.1",
"angular-html-parser": "~1.7.0",
"@stryker-mutator/api": "4.6.0",
"@stryker-mutator/util": "4.6.0",
"angular-html-parser": "~1.8.0",
"weapon-regex": "~0.4.1"
},
"devDependencies": {
"@babel/preset-react": "~7.12.1",
"@stryker-mutator/test-helpers": "4.5.1",
"@babel/preset-react": "~7.13.13",
"@stryker-mutator/test-helpers": "4.6.0",
"@types/babel__core": "~7.1.10",

@@ -58,3 +58,3 @@ "@types/babel__generator": "~7.6.2",

},
"gitHead": "d777b6da78657b2be77099b096c5dbfee5a36339"
"gitHead": "78c63606467f80f16ac61e5c0e1447fa56654f05"
}

@@ -5,3 +5,3 @@ import path from 'path';

import { Logger } from '@stryker-mutator/api/logging';
import { File } from '@stryker-mutator/api/core';
import { File, MutationRange } from '@stryker-mutator/api/core';

@@ -19,3 +19,3 @@ import { createParser } from './parsers';

* * Adding mutant coverage expressions in the source code.
* @see https://github.com/stryker-mutator/stryker/issues/1514
* @see https://github.com/stryker-mutator/stryker-js/issues/1514
*/

@@ -35,3 +35,3 @@ export class Instrumenter {

const ast = await parse(file.textContent, file.name);
transform(ast, mutantCollector, { options });
transform(ast, mutantCollector, { options: { ...options, mutationRanges: options.mutationRanges.map(toBabelLineNumber) } });
const mutatedContent = print(ast);

@@ -53,1 +53,15 @@ outFiles.push(new File(file.name, mutatedContent));

}
function toBabelLineNumber(range: MutationRange): MutationRange {
return {
...range,
end: {
...range.end,
line: range.end.line + 1,
},
start: {
...range.start,
line: range.start.line + 1,
},
};
}

@@ -17,3 +17,3 @@ import path from 'path';

* Represents a mutant placer, tries to place a mutant in the AST with corresponding mutation switch and mutant covering expression
* @see https://github.com/stryker-mutator/stryker/issues/1514
* @see https://github.com/stryker-mutator/stryker-js/issues/1514
* @param node The ast node to try and replace with a mutated

@@ -34,3 +34,3 @@ * @param mutants The mutants to place in the AST node

const message = `${placer.name} could not place mutants with type(s): "${mutants.map((mutant) => mutant.mutatorName).join(', ')}"`;
const errorMessage = `${location} ${message}. Either remove this file from the list of files to be mutated, or ignore the mutators. Please report this issue at https://github.com/stryker-mutator/stryker/issues/new?assignees=&labels=%F0%9F%90%9B+Bug&template=bug_report.md&title=${encodeURIComponent(
const errorMessage = `${location} ${message}. Either remove this file from the list of files to be mutated, or ignore the mutators. Please report this issue at https://github.com/stryker-mutator/stryker-js/issues/new?assignees=&labels=%F0%9F%90%9B+Bug&template=bug_report.md&title=${encodeURIComponent(
message

@@ -40,3 +40,3 @@ )}.`;

try {
// `buildCodeFrameError` is kind of flaky, see https://github.com/stryker-mutator/stryker/issues/2695
// `buildCodeFrameError` is kind of flaky, see https://github.com/stryker-mutator/stryker-js/issues/2695
builtError = node.buildCodeFrameError(errorMessage);

@@ -43,0 +43,0 @@ } catch {

@@ -45,4 +45,4 @@ import { types, NodePath } from '@babel/core';

* }
* @see https://github.com/stryker-mutator/stryker/issues/2314
* @see https://github.com/stryker-mutator/stryker/issues/2474
* @see https://github.com/stryker-mutator/stryker-js/issues/2314
* @see https://github.com/stryker-mutator/stryker-js/issues/2474
*/

@@ -49,0 +49,0 @@ private isInvalidConstructorBody(blockStatement: NodePath<types.BlockStatement>): boolean {

@@ -38,3 +38,3 @@ import { types, NodePath } from '@babel/core';

return mutatedOperators.map((mutatedOperator) => {
const replacement = types.cloneNode(path.node, false) as types.BinaryExpression;
const replacement = types.cloneNode(path.node, false);
replacement.operator = mutatedOperator;

@@ -41,0 +41,0 @@

@@ -8,3 +8,3 @@ import * as types from '@babel/types';

enum UnaryOperators {
enum UnaryOperator {
'+' = '-',

@@ -18,9 +18,8 @@ '-' = '+',

private readonly operators = UnaryOperators;
public mutate(path: NodePath): NodeMutation[] {
if (path.isUnaryExpression() && this.isSupported(path.node.operator) && path.node.prefix) {
const mutatedOperators = this.operators[path.node.operator];
const replacement =
mutatedOperators.length > 0 ? types.unaryExpression(mutatedOperators as any, path.node.argument) : types.cloneNode(path.node.argument, false);
const mutatedOperator = UnaryOperator[path.node.operator];
const replacement = mutatedOperator.length
? types.unaryExpression(mutatedOperator as '-' | '+', path.node.argument)
: types.cloneNode(path.node.argument, false);

@@ -38,5 +37,5 @@ return [

private isSupported(operator: string): operator is keyof typeof UnaryOperators {
return Object.keys(this.operators).includes(operator);
private isSupported(operator: string): operator is keyof typeof UnaryOperator {
return Object.keys(UnaryOperator).includes(operator);
}
}

@@ -10,3 +10,3 @@ import { traverse } from '@babel/core';

import { mutate } from '../mutators';
import { instrumentationBabelHeader, isTypeNode, isImportDeclaration } from '../util/syntax-helpers';
import { instrumentationBabelHeader, isTypeNode, isImportDeclaration, locationIncluded, locationOverlaps } from '../util/syntax-helpers';
import { AstFormat } from '../syntax';

@@ -24,8 +24,17 @@

const file = new File({ filename: originFileName }, { code: rawContent, ast: root });
// Range filters that are in scope for the current file
const mutantRangesForCurrentFile = options.mutationRanges.filter((mutantRange) => mutantRange.fileName === originFileName);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
traverse(file.ast, {
enter(path) {
if (isTypeNode(path) || isImportDeclaration(path) || path.isDecorator()) {
// Don't mutate type declarations or import statements
// Don't mutate import statements, type definitions and nodes that don't have overlap with the current range filter
if (
isTypeNode(path) ||
isImportDeclaration(path) ||
path.isDecorator() ||
(mutantRangesForCurrentFile.length && mutantRangesForCurrentFile.every((range) => !locationOverlaps(range, path.node.loc!)))
) {
path.skip();
} else {
} else if (!mutantRangesForCurrentFile.length || mutantRangesForCurrentFile.some((range) => locationIncluded(range, path.node.loc!))) {
mutate(path, options).forEach((mutant) => {

@@ -32,0 +41,0 @@ mutantCollector.add(originFileName, mutant, offset?.position, offset?.line);

@@ -0,3 +1,7 @@

import { MutationRange } from '@stryker-mutator/api/core';
import { MutatorOptions } from '../mutators';
export type TransformerOptions = MutatorOptions;
export interface TransformerOptions extends MutatorOptions {
mutationRanges: readonly MutationRange[];
}

@@ -204,1 +204,22 @@ import { INSTRUMENTER_CONSTANTS as ID } from '@stryker-mutator/api/core';

}
/**
* Determines if a location (needle) is included in an other location (haystack)
* @param haystack The range to look in
* @param needle the range to search for
*/
export function locationIncluded(haystack: types.SourceLocation, needle: types.SourceLocation): boolean {
const startIncluded =
haystack.start.line < needle.start.line || (haystack.start.line === needle.start.line && haystack.start.column <= needle.start.column);
const endIncluded = haystack.end.line > needle.end.line || (haystack.end.line === needle.end.line && haystack.end.column >= needle.end.column);
return startIncluded && endIncluded;
}
/**
* Determines if two locations overlap with each other
*/
export function locationOverlaps(a: types.SourceLocation, b: types.SourceLocation): boolean {
const startIncluded = a.start.line < b.end.line || (a.start.line === b.end.line && a.start.column <= b.end.column);
const endIncluded = a.end.line > b.start.line || (a.end.line === b.start.line && a.end.column >= b.start.column);
return startIncluded && endIncluded;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc