-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2640447
commit 8a60569
Showing
3 changed files
with
1,941 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,26 @@ | ||
const acorn = require('acorn'); | ||
const escodegen = require('escodegen'); | ||
|
||
module.exports = function(source) { | ||
return source.replace(/(\\n\s*)/g, ''); | ||
}; | ||
const tree = acorn.parse(source, { sourceType: 'module' }); | ||
traverse(tree); | ||
return escodegen.generate(tree); | ||
}; | ||
|
||
function isObject(item) { | ||
return Object.prototype.toString.call(item) === '[object Object]'; | ||
} | ||
|
||
function traverse(input) { | ||
if (Array.isArray(input)) { | ||
input.forEach(item => traverse(item)); | ||
} | ||
else if (isObject(input)) { | ||
for (let key in input) { | ||
if (typeof input[key] === 'string') { | ||
input[key] = input[key].replace(/(\n\s*)/g, ''); | ||
} | ||
traverse(input[key]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.