Skip to content

Commit

Permalink
feat(espower): adjust filepath in power-assert output if sourceMap op…
Browse files Browse the repository at this point in the history
…tion is given
  • Loading branch information
twada committed Aug 16, 2014
1 parent 755abcc commit f919d59
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
11 changes: 8 additions & 3 deletions build/espower.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Instrumentor.prototype.instrument = function (ast) {
argumentPath,
canonicalCode,
powerAssertCallee,
filepath,
lineNum,
argumentModified = false,
skipping = false,
Expand Down Expand Up @@ -184,11 +185,14 @@ Instrumentor.prototype.instrument = function (ast) {
});
if (pos && pos.line) {
// console.log(JSON.stringify(pos, null, 2));
filepath = pos.source;
lineNum = pos.line;
} else {
filepath = that.options.path;
lineNum = currentNode.loc.start.line;
}
} else {
filepath = that.options.path;
lineNum = currentNode.loc.start.line;
}
return undefined;
Expand Down Expand Up @@ -235,6 +239,7 @@ Instrumentor.prototype.instrument = function (ast) {
// leaving target assertion
canonicalCode = null;
lineNum = null;
filepath = null;
assertionPath = null;
powerAssertCallee = null;
return undefined;
Expand Down Expand Up @@ -273,7 +278,7 @@ Instrumentor.prototype.instrument = function (ast) {
argumentPath = null;
if (argumentModified) {
argumentModified = false;
return that.captureArgument(resultTree, canonicalCode, powerAssertCallee, lineNum);
return that.captureArgument(resultTree, canonicalCode, powerAssertCallee, filepath, lineNum);
}
}

Expand All @@ -283,12 +288,12 @@ Instrumentor.prototype.instrument = function (ast) {
return result;
};

Instrumentor.prototype.captureArgument = function (node, canonicalCode, powerAssertCallee, lineNum) {
Instrumentor.prototype.captureArgument = function (node, canonicalCode, powerAssertCallee, filepath, lineNum) {
var n = newNodeWithLocationCopyOf(node),
props = [],
newCallee = updateLocRecursively(espurify(powerAssertCallee), n);
addLiteralTo(props, n, 'content', canonicalCode);
addLiteralTo(props, n, 'filepath', this.options.path);
addLiteralTo(props, n, 'filepath', filepath);
addLiteralTo(props, n, 'line', lineNum);
return n({
type: syntax.CallExpression,
Expand Down
11 changes: 8 additions & 3 deletions lib/instrumentor.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Instrumentor.prototype.instrument = function (ast) {
argumentPath,
canonicalCode,
powerAssertCallee,
filepath,
lineNum,
argumentModified = false,
skipping = false,
Expand Down Expand Up @@ -93,11 +94,14 @@ Instrumentor.prototype.instrument = function (ast) {
});
if (pos && pos.line) {
// console.log(JSON.stringify(pos, null, 2));
filepath = pos.source;
lineNum = pos.line;
} else {
filepath = that.options.path;
lineNum = currentNode.loc.start.line;
}
} else {
filepath = that.options.path;
lineNum = currentNode.loc.start.line;
}
return undefined;
Expand Down Expand Up @@ -144,6 +148,7 @@ Instrumentor.prototype.instrument = function (ast) {
// leaving target assertion
canonicalCode = null;
lineNum = null;
filepath = null;
assertionPath = null;
powerAssertCallee = null;
return undefined;
Expand Down Expand Up @@ -182,7 +187,7 @@ Instrumentor.prototype.instrument = function (ast) {
argumentPath = null;
if (argumentModified) {
argumentModified = false;
return that.captureArgument(resultTree, canonicalCode, powerAssertCallee, lineNum);
return that.captureArgument(resultTree, canonicalCode, powerAssertCallee, filepath, lineNum);
}
}

Expand All @@ -192,12 +197,12 @@ Instrumentor.prototype.instrument = function (ast) {
return result;
};

Instrumentor.prototype.captureArgument = function (node, canonicalCode, powerAssertCallee, lineNum) {
Instrumentor.prototype.captureArgument = function (node, canonicalCode, powerAssertCallee, filepath, lineNum) {
var n = newNodeWithLocationCopyOf(node),
props = [],
newCallee = updateLocRecursively(espurify(powerAssertCallee), n);
addLiteralTo(props, n, 'content', canonicalCode);
addLiteralTo(props, n, 'filepath', this.options.path);
addLiteralTo(props, n, 'filepath', filepath);
addLiteralTo(props, n, 'line', lineNum);
return n({
type: syntax.CallExpression,
Expand Down
2 changes: 1 addition & 1 deletion test/espower_option_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ describe('SourceMap support', function () {

var espoweredCode = escodegen.generate(espoweredAST, {format: {compact: true}});

assert.equal(espoweredCode, "var str='foo';var anotherStr='bar';assert.equal(assert._expr(assert._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr)',line:4}),assert._expr(assert._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr)',line:4}));");
assert.equal(espoweredCode, "var str='foo';var anotherStr='bar';assert.equal(assert._expr(assert._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr)',filepath:'/path/to/raw/original_test.js',line:4}),assert._expr(assert._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr)',filepath:'/path/to/raw/original_test.js',line:4}));");
});
});

Expand Down

0 comments on commit f919d59

Please sign in to comment.