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 6.2.3 to 6.3.0

.mocharc.cjs

11

CHANGELOG.md

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

# [6.3.0](https://github.com/stryker-mutator/stryker-js/compare/v6.2.3...v6.3.0) (2022-10-30)
### Bug Fixes
- **deps:** update dependency angular-html-parser to ~2.1.0 ([#3797](https://github.com/stryker-mutator/stryker-js/issues/3797)) ([33eb2b1](https://github.com/stryker-mutator/stryker-js/commit/33eb2b1e2cb5915ea85ec02fe2a9e41b6f58d8d0))
### Features
- **ci:** forbid `.only` in CI pipeline tests ([#3823](https://github.com/stryker-mutator/stryker-js/issues/3823)) ([051ec93](https://github.com/stryker-mutator/stryker-js/commit/051ec937809468751a74c9e01cacd27ceb1acca2))
- **disableTypeChecks:** add option 'true' to disable all type checks ([#3765](https://github.com/stryker-mutator/stryker-js/issues/3765)) ([3c3d298](https://github.com/stryker-mutator/stryker-js/commit/3c3d2988c616a8bb8e7cdb76d4c16ddb948a3011))
## [6.2.3](https://github.com/stryker-mutator/stryker-js/compare/v6.2.2...v6.2.3) (2022-10-10)

@@ -8,0 +19,0 @@

import { File } from './file.js';
import { ParserOptions } from './parsers/index.js';
/**
* Disables TypeScript type checking for a single file by inserting `// @ts-nocheck` commands.
* It also does this for *.js files, as they can be type checked by typescript as well.
* Other file types are silently ignored
*
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#-ts-nocheck-in-typescript-files
*/
export declare function disableTypeChecks(file: File, options: ParserOptions): Promise<File>;
//# sourceMappingURL=disable-type-checks.d.ts.map

21

dist/src/disable-type-checks.js

@@ -7,4 +7,16 @@ import { notEmpty } from '@stryker-mutator/util';

const startingCommentRegex = /(^\s*\/\*.*?\*\/)/gs;
/**
* Disables TypeScript type checking for a single file by inserting `// @ts-nocheck` commands.
* It also does this for *.js files, as they can be type checked by typescript as well.
* Other file types are silently ignored
*
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#-ts-nocheck-in-typescript-files
*/
export async function disableTypeChecks(file, options) {
if (isJSFileWithoutTSDirectives(file)) {
const format = getFormat(file.name);
if (!format) {
// Readme files and stuff don't need disabling.
return file;
}
if (isJSFileWithoutTSDirectives(file, format)) {
// Performance optimization. Only parse the file when it has a change of containing a `// @ts-` directive

@@ -27,4 +39,3 @@ return {

}
function isJSFileWithoutTSDirectives(file) {
const format = getFormat(file.name);
function isJSFileWithoutTSDirectives(file, format) {
return (format === AstFormat.TS || format === AstFormat.JS) && !tsDirectiveLikeRegEx.test(file.content);

@@ -41,3 +52,3 @@ }

if (newLineIndex > 0) {
return `${code.substr(0, newLineIndex)}\n// @ts-nocheck\n${code.substr(newLineIndex + 1)}`;
return `${code.substring(0, newLineIndex)}\n// @ts-nocheck\n${code.substring(newLineIndex + 1)}`;
}

@@ -52,3 +63,3 @@ else {

const commentMatch = startingCommentRegex.exec(code);
return `${(_a = commentMatch === null || commentMatch === void 0 ? void 0 : commentMatch[1].concat('\n')) !== null && _a !== void 0 ? _a : ''}// @ts-nocheck\n${code.substr((_b = commentMatch === null || commentMatch === void 0 ? void 0 : commentMatch[1].length) !== null && _b !== void 0 ? _b : 0)}`;
return `${(_a = commentMatch === null || commentMatch === void 0 ? void 0 : commentMatch[1].concat('\n')) !== null && _a !== void 0 ? _a : ''}// @ts-nocheck\n${code.substring((_b = commentMatch === null || commentMatch === void 0 ? void 0 : commentMatch[1].length) !== null && _b !== void 0 ? _b : 0)}`;
}

@@ -55,0 +66,0 @@ }

@@ -1,6 +0,5 @@

import { AstFormat, AstByFormat } from '../syntax/index.js';
import { ParserOptions } from './parser-options.js';
import { createParser, getFormat } from './create-parser.js';
export type { ParserOptions };
export declare function createParser(parserOptions: ParserOptions): <T extends AstFormat = AstFormat>(code: string, fileName: string, formatOverride?: T | undefined) => Promise<AstByFormat[T]>;
export declare function getFormat(fileName: string, override?: AstFormat): AstFormat;
export { createParser, getFormat };
//# sourceMappingURL=index.d.ts.map

@@ -1,47 +0,3 @@

import path from 'path';
import { AstFormat } from '../syntax/index.js';
import { createParser as createJSParser } from './js-parser.js';
import { parseTS, parseTsx } from './ts-parser.js';
import { parse as htmlParse } from './html-parser.js';
export function createParser(parserOptions) {
const jsParse = createJSParser(parserOptions);
return function parse(code, fileName, formatOverride) {
const format = getFormat(fileName, formatOverride);
switch (format) {
case AstFormat.JS:
return jsParse(code, fileName);
case AstFormat.Tsx:
return parseTsx(code, fileName);
case AstFormat.TS:
return parseTS(code, fileName);
case AstFormat.Html:
return htmlParse(code, fileName, { parse });
}
};
}
export function getFormat(fileName, override) {
if (override) {
return override;
}
else {
const ext = path.extname(fileName).toLowerCase();
switch (ext) {
case '.js':
case '.jsx':
case '.mjs':
case '.cjs':
return AstFormat.JS;
case '.ts':
return AstFormat.TS;
case '.tsx':
return AstFormat.Tsx;
case '.vue':
case '.html':
case '.htm':
return AstFormat.Html;
default:
throw new Error(`Unable to parse ${fileName}. No parser registered for ${ext}!`);
}
}
}
import { createParser, getFormat } from './create-parser.js';
export { createParser, getFormat };
//# sourceMappingURL=index.js.map
{
"name": "@stryker-mutator/instrumenter",
"version": "6.2.3",
"version": "6.3.0",
"description": "The code instrumenter used in Stryker, the JavaScript mutation testing framework",

@@ -41,5 +41,5 @@ "main": "dist/src/index.js",

"@babel/preset-typescript": "~7.18.0",
"@stryker-mutator/api": "6.2.3",
"@stryker-mutator/util": "6.2.3",
"angular-html-parser": "~2.0.0",
"@stryker-mutator/api": "6.3.0",
"@stryker-mutator/util": "6.3.0",
"angular-html-parser": "~2.1.0",
"weapon-regex": "~1.0.2"

@@ -49,3 +49,3 @@ },

"@babel/preset-react": "7.18.6",
"@stryker-mutator/test-helpers": "6.2.3",
"@stryker-mutator/test-helpers": "6.3.0",
"@types/babel__core": "7.1.19",

@@ -57,3 +57,3 @@ "@types/babel__generator": "7.6.4",

},
"gitHead": "b77094ae33c7c9bae5167a91d87ec765843c6df7"
"gitHead": "28706dbe660e3156bc775c3465cbd2ce91f2e23f"
}

@@ -13,4 +13,16 @@ import type { types } from '@babel/core';

/**
* Disables TypeScript type checking for a single file by inserting `// @ts-nocheck` commands.
* It also does this for *.js files, as they can be type checked by typescript as well.
* Other file types are silently ignored
*
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#-ts-nocheck-in-typescript-files
*/
export async function disableTypeChecks(file: File, options: ParserOptions): Promise<File> {
if (isJSFileWithoutTSDirectives(file)) {
const format = getFormat(file.name);
if (!format) {
// Readme files and stuff don't need disabling.
return file;
}
if (isJSFileWithoutTSDirectives(file, format)) {
// Performance optimization. Only parse the file when it has a change of containing a `// @ts-` directive

@@ -22,2 +34,3 @@ return {

}
const parse = createParser(options);

@@ -35,4 +48,3 @@ const ast = await parse(file.content, file.name);

function isJSFileWithoutTSDirectives(file: File) {
const format = getFormat(file.name);
function isJSFileWithoutTSDirectives(file: File, format: AstFormat) {
return (format === AstFormat.TS || format === AstFormat.JS) && !tsDirectiveLikeRegEx.test(file.content);

@@ -50,3 +62,3 @@ }

if (newLineIndex > 0) {
return `${code.substr(0, newLineIndex)}\n// @ts-nocheck\n${code.substr(newLineIndex + 1)}`;
return `${code.substring(0, newLineIndex)}\n// @ts-nocheck\n${code.substring(newLineIndex + 1)}`;
} else {

@@ -59,3 +71,3 @@ return code;

const commentMatch = startingCommentRegex.exec(code);
return `${commentMatch?.[1].concat('\n') ?? ''}// @ts-nocheck\n${code.substr(commentMatch?.[1].length ?? 0)}`;
return `${commentMatch?.[1].concat('\n') ?? ''}// @ts-nocheck\n${code.substring(commentMatch?.[1].length ?? 0)}`;
}

@@ -62,0 +74,0 @@ }

@@ -1,54 +0,5 @@

import path from 'path';
import { AstFormat, AstByFormat } from '../syntax/index.js';
import { createParser as createJSParser } from './js-parser.js';
import { parseTS, parseTsx } from './ts-parser.js';
import { parse as htmlParse } from './html-parser.js';
import { ParserOptions } from './parser-options.js';
import { createParser, getFormat } from './create-parser.js';
export type { ParserOptions };
export function createParser(
parserOptions: ParserOptions
): <T extends AstFormat = AstFormat>(code: string, fileName: string, formatOverride?: T | undefined) => Promise<AstByFormat[T]> {
const jsParse = createJSParser(parserOptions);
return function parse<T extends AstFormat = AstFormat>(code: string, fileName: string, formatOverride?: T): Promise<AstByFormat[T]> {
const format = getFormat(fileName, formatOverride);
switch (format) {
case AstFormat.JS:
return jsParse(code, fileName) as Promise<AstByFormat[T]>;
case AstFormat.Tsx:
return parseTsx(code, fileName) as Promise<AstByFormat[T]>;
case AstFormat.TS:
return parseTS(code, fileName) as Promise<AstByFormat[T]>;
case AstFormat.Html:
return htmlParse(code, fileName, { parse }) as Promise<AstByFormat[T]>;
}
};
}
export function getFormat(fileName: string, override?: AstFormat): AstFormat {
if (override) {
return override;
} else {
const ext = path.extname(fileName).toLowerCase();
switch (ext) {
case '.js':
case '.jsx':
case '.mjs':
case '.cjs':
return AstFormat.JS;
case '.ts':
return AstFormat.TS;
case '.tsx':
return AstFormat.Tsx;
case '.vue':
case '.html':
case '.htm':
return AstFormat.Html;
default:
throw new Error(`Unable to parse ${fileName}. No parser registered for ${ext}!`);
}
}
}
export { createParser, getFormat };

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