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

@as-covers/transform

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@as-covers/transform - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

97

lib/index.js

@@ -22,2 +22,3 @@ "use strict";

const visitor_as_1 = require("visitor-as");
const transformRange_1 = require("visitor-as/dist/transformRange");
// @ts-ignore

@@ -31,3 +32,2 @@ const line_column_1 = __importDefault(require("line-column"));

globalStatements = [];
sources = [];
ignoredLines = new Set();

@@ -54,2 +54,3 @@ // Declare properties.

return;
const replacer = new transformRange_1.RangeTransform(expr);
// Create id. (Hash)

@@ -59,6 +60,6 @@ const rightId = util_1.createPointID(name, rightLine, rightCol, "CoverType.Expression");

const rightDeclareStatement = visitor_as_1.SimpleParser.parseStatement(`__coverDeclare("${name}", ${rightId}, ${rightLine}, ${rightCol}, CoverType.Expression)`, true);
// Grab the declare statement source.
const rightDeclareStatementSource = rightDeclareStatement.range.source;
replacer.visit(rightDeclareStatement);
// Create new Expression
let rightCoverExpression = visitor_as_1.SimpleParser.parseExpression(`(__cover(${rightId}), $$REPLACE_ME)`);
replacer.visit(rightCoverExpression);
// Replace $$REPLACE_ME with the expresion

@@ -69,4 +70,2 @@ rightCoverExpression.expression.expressions[1] =

expr.right = rightCoverExpression;
// Push Declare Statement to sources
this.sources.push(rightDeclareStatementSource);
// Push Declare Statement to global statements.

@@ -89,10 +88,10 @@ this.globalStatements.push(rightDeclareStatement);

const funcId = util_1.createPointID(name, funcLine, funcCol, "CoverType.Function");
const replacer = new transformRange_1.RangeTransform(dec);
const funcDeclareStatement = visitor_as_1.SimpleParser.parseStatement(`__coverDeclare("${name}", ${funcId}, ${funcLine}, ${funcCol}, CoverType.Function)`, true);
const funcDeclareStatementSource = funcDeclareStatement.range.source;
replacer.visit(funcDeclareStatement);
// The cover statement
const funcCoverStatement = visitor_as_1.SimpleParser.parseStatement(`__cover(${funcId})`, true);
const funcCoverStatementSource = funcCoverStatement.range.source;
replacer.visit(funcCoverStatement);
const bodyBlock = dec.body;
bodyBlock.statements.unshift(funcCoverStatement);
this.sources.push(funcCoverStatementSource);
this.sources.push(funcDeclareStatementSource);
this.globalStatements.push(funcDeclareStatement);

@@ -110,11 +109,9 @@ }

return;
const replacer = new transformRange_1.RangeTransform(node);
const parmId = util_1.createPointID(name, parmLine, parmCol, "CoverType.Expression");
const parmDeclareStatement = visitor_as_1.SimpleParser.parseStatement(`__coverDeclare("${name}", ${parmId}, ${parmLine}, ${parmCol}, CoverType.Expression)`, true);
const parmDeclareStatementSource = parmDeclareStatement.range.source;
replacer.visit(parmDeclareStatement);
const parmCoverExpression = visitor_as_1.SimpleParser.parseExpression(`(__cover(${parmId}), $$REPLACE_ME)`);
const parmCoverExpressionSource = parmCoverExpression.range.source;
parmCoverExpression.expression.expressions[1] =
node.initializer;
replacer.visit(parmCoverExpression);
node.initializer = parmCoverExpression;
this.sources.push(parmDeclareStatementSource, parmCoverExpressionSource);
this.globalStatements.push(parmDeclareStatement);

@@ -134,12 +131,11 @@ }

if (dec.body) {
// Grab the name
// Grab the metadata
const name = dec.range.source.normalizedPath;
// Get coordinates
const funcLc = this.linecol.fromIndex(dec.range.start);
// Line
const funcLine = funcLc.line;
// Column
const funcCol = funcLc.col;
// check ignored lines
if (this.ignoredLines.has(funcLine))
return;
const replacer = new transformRange_1.RangeTransform(dec);
// Generate id hash from information

@@ -149,6 +145,3 @@ const funcId = util_1.createPointID(name, funcLine, funcCol, "CoverType.Function");

const funcDeclareStatement = visitor_as_1.SimpleParser.parseStatement(`__coverDeclare("${name}", ${funcId}, ${funcLine}, ${funcCol}, CoverType.Function)`, true);
// Grab declare statement source
const funcDeclareStatementSource = funcDeclareStatement.range.source;
// Push declare statement to sources
this.sources.push(funcDeclareStatementSource);
replacer.visit(funcDeclareStatement);
// Push declare stastement to globalStatements

@@ -164,2 +157,3 @@ this.globalStatements.push(funcDeclareStatement);

}`);
replacer.visit(bodyStatement);
// Grab the return statement of the body

@@ -173,4 +167,2 @@ const bodyReturn = bodyStatement.statements[1];

bodyReturn.value = body.expression;
// Push the body statement to sourcesssssssss
this.sources.push(bodyStatement.range.source);
// Finally, replace the function body with our generated block-statement body.

@@ -183,4 +175,3 @@ dec.body = body;

const funcCoverStatement = visitor_as_1.SimpleParser.parseStatement(`__cover(${funcId})`, true);
// Grab the cover statement's source
const funcCoverStatementSource = funcCoverStatement.range.source;
replacer.visit(funcCoverStatement);
// Grab the body and cast it as a BlockStatement

@@ -190,4 +181,2 @@ const bodyBlock = dec.body;

bodyBlock.statements.unshift(funcCoverStatement);
// Push it to the sources
this.sources.push(funcCoverStatementSource);
}

@@ -216,2 +205,3 @@ }

if (ifTrue.kind !== as_1.NodeKind.BLOCK && !this.ignoredLines.has(trueLine)) {
const replacer = new transformRange_1.RangeTransform(ifTrue);
// Get id from hash

@@ -221,6 +211,6 @@ const ifTrueId = util_1.createPointID(name, trueLine, trueCol, "CoverType.Expression");

const coverDeclareStatement = visitor_as_1.SimpleParser.parseStatement(`__coverDeclare("${name}", ${ifTrueId}, ${trueLine}, ${trueCol}, CoverType.Expression)`, true);
// Grab coverDeclare source
const coverDeclareStatementSource = coverDeclareStatement.range.source;
replacer.visit(coverDeclareStatement);
// Create new cover statement as a block.
const coverStatement = visitor_as_1.SimpleParser.parseStatement(`{__cover(${ifTrueId})};`, true);
replacer.visit(coverStatement);
// This pushes the old value right below the __cover(id)

@@ -230,4 +220,2 @@ coverStatement.statements.push(ifTrue);

stmt.ifTrue = coverStatement;
// Push coverDeclare to sources
this.sources.push(coverDeclareStatementSource);
// Push coverDeclare to globalStatements

@@ -247,2 +235,3 @@ this.globalStatements.push(coverDeclareStatement);

!this.ignoredLines.has(falseLine)) {
const replacer = new transformRange_1.RangeTransform(ifFalse);
// Create id from hash

@@ -252,6 +241,6 @@ const ifFalseId = util_1.createPointID(name, falseLine, falseCol, "CoverType.Expression");

const coverDeclareStatement = visitor_as_1.SimpleParser.parseStatement(`__coverDeclare("${name}", ${ifFalseId}, ${falseLine}, ${falseCol}, CoverType.Expression)`, true);
// Grab coverDeclare statement source
const coverDeclareStatementSource = coverDeclareStatement.range.source;
replacer.visit(coverDeclareStatement);
// Create new cover statement as a block.
const coverStatement = visitor_as_1.SimpleParser.parseStatement(`{__cover(${ifFalseId})};`, true);
replacer.visit(coverStatement);
// Add old body right after __cover(id)

@@ -261,4 +250,2 @@ coverStatement.statements.push(ifFalse);

stmt.ifFalse = coverStatement;
// Push coverDeclare statement source to sources
this.sources.push(coverDeclareStatementSource);
// Push to globalStatements

@@ -304,2 +291,3 @@ this.globalStatements.push(coverDeclareStatement);

if (!this.ignoredLines.has(trueLine)) {
const replacer = new transformRange_1.RangeTransform(trueExpression);
// Create id from hash

@@ -309,5 +297,6 @@ const trueId = util_1.createPointID(name, trueLine, trueCol, "CoverType.Expression");

const trueDeclareStatement = visitor_as_1.SimpleParser.parseStatement(`__coverDeclare("${name}", ${trueId}, ${trueLine}, ${trueCol}, CoverType.Expression)`, true);
const trueDeclareStatementSource = trueDeclareStatement.range.source;
replacer.visit(trueDeclareStatement);
// Create cover expression
let trueCoverExpression = visitor_as_1.SimpleParser.parseExpression(`(__cover(${trueId}), $$REPLACE_ME)`);
replacer.visit(trueCoverExpression);
// Replace $$REPLACE_ME with the original value

@@ -318,4 +307,2 @@ trueCoverExpression.expression.expressions[1] =

expr.ifThen = trueCoverExpression;
// Push declare statement to global and sources
this.sources.push(trueDeclareStatementSource);
this.globalStatements.push(trueDeclareStatement);

@@ -329,2 +316,3 @@ }

if (!this.ignoredLines.has(falseLine)) {
const replacer = new transformRange_1.RangeTransform(falseExpression);
// Create id from hash

@@ -334,5 +322,6 @@ const falseId = util_1.createPointID(name, falseLine, falseCol, "CoverType.Expression");

const falseDeclareStatement = visitor_as_1.SimpleParser.parseStatement(`__coverDeclare("${name}", ${falseId}, ${falseLine}, ${falseCol}, CoverType.Expression)`, true);
const falseDeclareStatementSource = falseDeclareStatement.range.source;
replacer.visit(falseDeclareStatement);
// Create cover expression and cast a ParenthesizedExpression
const falseCoverExpression = visitor_as_1.SimpleParser.parseExpression(`(__cover(${falseId}), $$REPLACE_ME)`);
replacer.visit(falseCoverExpression);
// Replace $$REPLACE_ME with the original value

@@ -343,4 +332,2 @@ falseCoverExpression.expression.expressions[1] =

expr.ifElse = falseCoverExpression;
// Push to global and sources
this.sources.push(falseDeclareStatementSource);
this.globalStatements.push(falseDeclareStatement);

@@ -363,2 +350,3 @@ }

return;
const replacer = new transformRange_1.RangeTransform(stmt);
// Create id from hash

@@ -368,10 +356,6 @@ const caseId = util_1.createPointID(name, caseLine, caseCol, "CoverType.Block");

const caseDeclareStatement = visitor_as_1.SimpleParser.parseStatement(`__coverDeclare("${name}", ${caseId}, ${caseLine}, ${caseCol}, CoverType.Block)`, true);
// Get declare statement source
const caseDeclareStatementSource = caseDeclareStatement.range.source;
replacer.visit(caseDeclareStatement);
// Create a cover statement
const caseCoverStatement = visitor_as_1.SimpleParser.parseStatement(`__cover(${caseId})`);
// Get cover statement source
const caseCoverStatementSource = caseCoverStatement.range.source;
// Push declare statement and cover to sources
this.sources.push(caseDeclareStatementSource, caseCoverStatementSource);
replacer.visit(caseCoverStatement);
// Push declare to global

@@ -397,2 +381,3 @@ this.globalStatements.push(caseDeclareStatement);

return;
const replacer = new transformRange_1.RangeTransform(node);
// Create id from hash

@@ -402,8 +387,6 @@ const blockCoverId = util_1.createPointID(name, blockLine, blockCol, "CoverType.Block");

const declareStatement = visitor_as_1.SimpleParser.parseStatement(`__coverDeclare("${name}", ${blockCoverId}, ${blockLine}, ${blockCol}, CoverType.Block)`, true);
const declareStatementSource = declareStatement.range.source;
replacer.visit(declareStatement);
// Create cover statement
const coverStatement = visitor_as_1.SimpleParser.parseStatement(`__cover(${blockCoverId})`);
const coverStatementSource = coverStatement.range.source;
// Push cover and declare to sources
this.sources.push(declareStatementSource, coverStatementSource);
replacer.visit(coverStatement);
// Push declare to global

@@ -451,14 +434,4 @@ this.globalStatements.push(declareStatement);

}
// Create different file names to prevent interference (increment)
let i = 0;
for (const source of transformer.sources) {
let id = i++;
source.normalizedPath = `~/lib/as-covers${id}.ts`;
source.internalPath = `~/lib/as-covers${id}`;
source.simplePath = `~/lib/as-covers${id}`;
parser.sources.push(source);
// Modify file names (incremental)
}
}
};
//# sourceMappingURL=index.js.map
{
"name": "@as-covers/transform",
"version": "0.2.0",
"version": "0.2.1",
"description": "The transform that enables code coverage for assemblyscript",

@@ -26,3 +26,3 @@ "main": "lib/index.js",

],
"gitHead": "493072e36200635266e3778f1ce1977f93697d8a"
"gitHead": "4194d38184f20687bd8e7124728368b69b84598f"
}

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