Comparing version 2.18.1 to 2.18.2
@@ -34,4 +34,2 @@ 'use strict'; | ||
//fixBabelObjectProperty(ast); | ||
traverse(ast, getVars({ | ||
@@ -58,34 +56,2 @@ use, | ||
// @babel/traverse uses ObjectProperty in ObjectPattern | ||
// but according to standard Property should be used | ||
// all other parsers use Property. | ||
// | ||
// Remove when this will be fixed | ||
// https://github.com/babel/babel/issues/9251 | ||
// https://github.com/babel/babel/pull/9258 | ||
/* | ||
function fixBabelObjectProperty(ast) { | ||
traverse(ast, { | ||
noScope: true, | ||
FunctionExpression(path) { | ||
console.log(path.node.loc); | ||
}, | ||
ObjectMethod(path) { | ||
console.log(path.node.loc); | ||
}, | ||
enter(path) { | ||
if (path.type === 'Property') { | ||
path.node.type = 'ObjectProperty'; | ||
return; | ||
} | ||
if (path.type === 'FunctionExpression') { | ||
path.node.type = 'ObjectMethod'; | ||
return; | ||
} | ||
}, | ||
}); | ||
} | ||
*/ | ||
function getScopeNumber(name, scope) { | ||
@@ -92,0 +58,0 @@ let done = false; |
@@ -5,3 +5,4 @@ 'use strict'; | ||
const alignSpaces = require('align-spaces'); | ||
const babelParser = require('@babel/parser'); | ||
const cherow = require('cherow'); | ||
const toBabel = require('estree-to-babel'); | ||
@@ -16,3 +17,5 @@ const getVars = require('./get-vars'); | ||
parse(source) { | ||
return babelParser.parse(source); | ||
return toBabel(cherow.parse(source, { | ||
loc: true, | ||
})); | ||
}, | ||
@@ -35,11 +38,8 @@ }; | ||
const {code} = recast.print(ast, { | ||
trailingComma: true, | ||
}); | ||
const {code} = recast.print(ast); | ||
const aligned = alignSpaces(code); | ||
const result = fixStrictMode(aligned); | ||
return { | ||
code: `${shebang}${result}`, | ||
code: `${shebang}${aligned}`, | ||
unused, | ||
@@ -49,32 +49,2 @@ }; | ||
// when unused variable located in a root scope | ||
// near 'use strict' directive | ||
// it generates something like this: | ||
// | ||
// "use strict";; | ||
// | ||
// or | ||
// | ||
// "use strict"; | ||
// const nextVar = require('some'); | ||
// | ||
// in case unused variable located in function scope | ||
// such problem doesn't occure but | ||
// there is no way to determine scope of a variable | ||
// before generating result | ||
// | ||
// tests : | ||
// - strict-mode | ||
// - return-statement | ||
// | ||
// In case removing with function do not fail any test | ||
// should be removed as soon as possible | ||
function fixStrictMode(a) { | ||
return a | ||
.replace(';;', ';') | ||
.replace(`'use strict';`, `'use strict';\n`) | ||
.replace(`'use strict';\n\n\n`, `'use strict';\n\n`); | ||
} | ||
module.exports.parse = parse; | ||
@@ -81,0 +51,0 @@ function parse(source) { |
{ | ||
"name": "putout", | ||
"version": "2.18.1", | ||
"version": "2.18.2", | ||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
@@ -27,3 +27,2 @@ "description": "find and remove unused variables", | ||
"dependencies": { | ||
"@babel/parser": "^7.2.3", | ||
"@babel/traverse": "^7.1.6", | ||
@@ -33,2 +32,4 @@ "@babel/types": "^7.2.0", | ||
"chalk": "^2.4.1", | ||
"cherow": "^1.6.9", | ||
"estree-to-babel": "^1.0.1", | ||
"glob": "^7.1.3", | ||
@@ -35,0 +36,0 @@ "recast": "^0.16.1", |
Sorry, the diff of this file is not supported yet
26823
11
604
+ Addedcherow@^1.6.9
+ Addedestree-to-babel@^1.0.1
+ Addedcherow@1.6.9(transitive)
+ Addedestree-to-babel@1.8.2(transitive)
- Removed@babel/parser@^7.2.3