Skip to content

Commit

Permalink
release 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jan 19, 2017
1 parent 2640447 commit 8a60569
Show file tree
Hide file tree
Showing 3 changed files with 1,941 additions and 3 deletions.
27 changes: 25 additions & 2 deletions index.js
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]);
}
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "template-string-optimize-loader",
"version": "1.0.2",
"version": "2.0.0",
"description": "template string optimize loader module for webpack",
"main": "index.js",
"scripts": {
Expand All @@ -9,9 +9,11 @@
"author": "chenjiahan",
"license": "ISC",
"devDependencies": {
"acorn": "^4.0.4",
"babel": "^6.3.26",
"babel-loader": "^6.2.1",
"babel-preset-es2015": "^6.3.13",
"escodegen": "^1.8.1",
"webpack": "^1.12.10"
},
"bugs": {
Expand Down
Loading

0 comments on commit 8a60569

Please sign in to comment.