Skip to content

Commit

Permalink
refactor(babel-plugin-espower): inline slimDown function
Browse files Browse the repository at this point in the history
make clone module unnecessary
  • Loading branch information
twada committed Mar 20, 2016
1 parent 80086b1 commit 222f134
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
36 changes: 13 additions & 23 deletions lib/babel-assertion-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var babelgen = require('babel-generator');
var define = require('define-properties');
var toBeCaptured = require('./to-be-captured');
var toBeSkipped = require('./to-be-skipped');
var clone = require('clone');
var fs = require('fs');
var helperCode = '(' +
fs.readFileSync(require.resolve('./power-assert-recorder.js'), 'utf8')
Expand Down Expand Up @@ -192,7 +191,7 @@ BabelAssertionVisitor.prototype.parseCanonicalCode = function (file, code) {
});

return {
tokens: offsetTokens(tokens).map(slimDown),
tokens: offsetAndSlimDownTokens(tokens),
expression: offsetTree
};
};
Expand All @@ -205,37 +204,28 @@ function wrappedInAsync (jsCode) {
return 'async function wrapper() { ' + jsCode + ' }';
}

function offsetTokens (tokens) {
function offsetAndSlimDownTokens (tokens) {
var i, token, result = [];
var columnOffset;
for(i = 0; i < tokens.length; i += 1) {
token = clone(tokens[i]);
token = tokens[i];
if (i === 0) {
columnOffset = token.loc.start.column;
}
token.range = [
token.loc.start.column - columnOffset,
token.loc.end.column - columnOffset
];
delete token.loc;
result.push(token);
result.push({
type: {
label: token.type.label
},
value: token.value,
range: [
token.loc.start.column - columnOffset,
token.loc.end.column - columnOffset
]
});
}
return result;
}

function slimDown (token) {
return {
type: {
label: token.type.label
},
value: token.value,
range: [
token.range[0],
token.range[1]
]
};
}

BabelAssertionVisitor.prototype.captureArgument = function (node) {
var t = this.babel.types;
var props = {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"babel-generator": "^6.1.0",
"babylon": "^6.1.0",
"call-matcher": "^0.1.0",
"clone": "^1.0.2",
"define-properties": "^1.1.2",
"espower-location-detector": "^0.1.1",
"espurify": "^1.5.0",
Expand Down

0 comments on commit 222f134

Please sign in to comment.