Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply latest nlm generator #69

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "groupon-es5"
"extends": "groupon/es5"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/package-lock.json
/yarn.lock
node_modules/
npm-debug.log
Expand Down
22 changes: 9 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
language: node_js
node_js:
- '0.10'
- '4'
before_install:
- npm install -g npm@latest-2
before_deploy:
- 'git config --global user.email "opensource@groupon.com"'
- 'git config --global user.name "Groupon"'
- 4.6.1
- 6.11.5
- 8.9.0
deploy:
provider: script
script: ./node_modules/.bin/nlm release
skip_cleanup: true
'on':
branch: master
node: '4'
- provider: script
script: ./node_modules/.bin/nlm release
skip_cleanup: true
'on':
branch: master
node: 8.9.0
4 changes: 3 additions & 1 deletion lib/cson-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

'use strict';

var stringify = require('./stringify');
var parse = require('./parse');

module.exports = {
stringify: stringify,
parse: parse
parse: parse,
};
23 changes: 15 additions & 8 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

'use strict';

var runInThisContext = require('vm').runInThisContext;
var nodes = require('coffee-script').nodes;

Expand Down Expand Up @@ -89,7 +91,9 @@ var nodeTransforms = {
var expressions;
expressions = node.expressions;
if (!expressions || expressions.length !== 1) {
throw new SyntaxError(syntaxErrorMessage(node, 'One top level value expected'));
throw new SyntaxError(
syntaxErrorMessage(node, 'One top level value expected')
);
}
return transformNode(expressions[0]);
},
Expand Down Expand Up @@ -177,8 +181,9 @@ var nodeTransforms = {
case '>>':
return left >> right;
default:
throw new SyntaxError(syntaxErrorMessage(node,
'Unknown binary operator ' + node.operator));
throw new SyntaxError(
syntaxErrorMessage(node, 'Unknown binary operator ' + node.operator)
);
}
} else {
switch (node.operator) {
Expand All @@ -187,20 +192,22 @@ var nodeTransforms = {
case '~':
return ~transformNode(node.first);
default:
throw new SyntaxError(syntaxErrorMessage(node,
'Unknown unary operator ' + node.operator));
throw new SyntaxError(
syntaxErrorMessage(node, 'Unknown unary operator ' + node.operator)
);
}
}
},
Parens: function Parens(node, transformNode) {
var expressions;
expressions = node.body.expressions;
if (!expressions || expressions.length !== 1) {
throw new SyntaxError(syntaxErrorMessage(node,
'Parenthesis may only contain one expression'));
throw new SyntaxError(
syntaxErrorMessage(node, 'Parenthesis may only contain one expression')
);
}
return transformNode(expressions[0]);
}
},
};

function parse(source, reviver) {
Expand Down
51 changes: 31 additions & 20 deletions lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

'use strict';

var jsIdentifierRE = /^[a-z_$][a-z0-9_$]*$/i;
var tripleQuotesRE = /'''/g;
var SPACES = ' ';
Expand All @@ -39,7 +41,7 @@ function contains(str1, str2) {
}

function newlineWrap(str) {
return str && ('\n' + str + '\n');
return str && '\n' + str + '\n';
}

function isObject(obj) {
Expand All @@ -66,26 +68,31 @@ function indentLines(indent, str) {
if (str === '') {
return str;
}
return str.split('\n').map(indentLine.bind(null, indent)).join('\n');
return str
.split('\n')
.map(indentLine.bind(null, indent))
.join('\n');
}

function singleQuoteStringify(str) {
return "'"
+ JSON.stringify(str)
.slice(1, -1)
.replace(/\\"/g, '"')
.replace(/'/g, "\\'")
+ "'";
return (
"'" +
JSON.stringify(str)
.slice(1, -1)
.replace(/\\"/g, '"')
.replace(/'/g, "\\'") +
"'"
);
}

function quoteType(str) {
return contains(str, "'") && !contains(str, '"') ? 'double' : 'single';
}

function onelineStringify(str) {
return (
quoteType(str) === 'single' ? singleQuoteStringify : JSON.stringify
)(str);
return (quoteType(str) === 'single' ? singleQuoteStringify : JSON.stringify)(
str
);
}

function buildKeyPairs(visitNode, indent, obj) {
Expand All @@ -95,11 +102,13 @@ function buildKeyPairs(visitNode, indent, obj) {
key = onelineStringify(key);
}
var serializedValue = visitNode(value, {
bracesRequired: !indent
bracesRequired: !indent,
});
if (indent) {
serializedValue = isObject(value) && Object.keys(value).length > 0 ?
'\n' + (indentLines(indent, serializedValue)) : ' ' + serializedValue;
serializedValue =
isObject(value) && Object.keys(value).length > 0
? '\n' + indentLines(indent, serializedValue)
: ' ' + serializedValue;
}
return key + ':' + serializedValue;
});
Expand All @@ -108,11 +117,12 @@ function buildKeyPairs(visitNode, indent, obj) {
function visitArray(visitNode, indent, arr) {
var items = arr.map(function visitElement(value) {
return visitNode(value, {
bracesRequired: true
bracesRequired: true,
});
});
var serializedItems = indent ?
newlineWrap(indentLines(indent, items.join('\n'))) : items.join(',');
var serializedItems = indent
? newlineWrap(indentLines(indent, items.join('\n')))
: items.join(',');
return '[' + serializedItems + ']';
}

Expand All @@ -125,7 +135,7 @@ function visitObject(visitNode, indent, obj, arg) {
if (indent) {
var keyPairLines = keypairs.join('\n');
if (bracesRequired) {
return '{' + (newlineWrap(indentLines(indent, keyPairLines))) + '}';
return '{' + newlineWrap(indentLines(indent, keyPairLines)) + '}';
}
return keyPairLines;
}
Expand All @@ -143,11 +153,12 @@ function visitString(visitNode, indent, str) {
return onelineStringify(str);
}
string = str.replace(/\\/g, '\\\\').replace(tripleQuotesRE, "\\'''");
return "'''" + (newlineWrap(indentLines(indent, string))) + "'''";
return "'''" + newlineWrap(indentLines(indent, string)) + "'''";
}

function stringify(data, visitor, indent) {
if (typeof data === 'function' || typeof data === 'undefined') return undefined;
if (typeof data === 'function' || typeof data === 'undefined')
return undefined;
indent = parseIndent(indent);

var normalized = JSON.parse(JSON.stringify(data, visitor));
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"homepage": "https://github.com/groupon/cson-parser",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/groupon/cson-parser"
"url": "https://github.com/groupon/cson-parser"
},
"bugs": {
"url": "https://github.com/groupon/cson-parser/issues"
Expand All @@ -29,12 +29,15 @@
},
"devDependencies": {
"assertive": "^2.1.0",
"eslint": "^2.0.0",
"eslint-config-groupon-es5": "^3.0.0",
"eslint-plugin-import": "^1.6.1",
"eslint-plugin-node": "^2.0.0",
"eslint": "^4.7.1",
"eslint-config-groupon": "^5.0.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-prettier": "^2.4.0",
"mocha": "^3.1.2",
"nlm": "^3.0.0"
"nlm": "^3.0.0",
"nodemon": "^1.0.0",
"prettier": "^1.9.2"
},
"author": {
"name": "Groupon",
Expand Down
4 changes: 1 addition & 3 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "groupon/node4",
"env": {
"mocha": true
},
"rules": {
"func-names": 0
}
}
1 change: 0 additions & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--compilers test.coffee:coffee-script/register
--recursive
Loading