Skip to content

Commit 4f42220

Browse files
committed
Working version.
0 parents  commit 4f42220

11 files changed

+183
-0
lines changed

.editorconfig

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.js]
15+
indent_style = tab
16+
indent_size = 4

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules/
2+
npm-debug.log

.jshintrc

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"bitwise": true,
3+
"camelcase": true,
4+
"curly": true,
5+
"eqeqeq": true,
6+
"forin": false,
7+
"freeze": true,
8+
"immed": true,
9+
"indent": 4,
10+
"latedef": true,
11+
"newcap": true,
12+
"noarg": true,
13+
"noempty": false,
14+
"nonew": true,
15+
"quotmark": true,
16+
"undef": true,
17+
"unused": true,
18+
"strict": true,
19+
"trailing": true,
20+
"maxparams": 4,
21+
22+
"eqnull": true,
23+
"funcscope": true,
24+
"globalstrict": true,
25+
"lastsemic": true,
26+
"smarttabs": true,
27+
28+
"browser": false,
29+
"devel": true,
30+
"node": true
31+
}

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- '0.10'

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright 2014 Ingvar Stepanyan, aster
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# aster-parse-js
2+
[![NPM version][npm-image]][npm-url]
3+
[![Build Status][travis-image]][travis-url]
4+
5+
> Parse js with aster.
6+
7+
## Usage
8+
9+
This is internal module and should be used as part of [aster-parse](https://npmjs.org/package/aster-parse) or [aster-src](https://npmjs.org/package/aster-src).
10+
11+
## License
12+
13+
[MIT License](http://en.wikipedia.org/wiki/MIT_License)
14+
15+
[npm-url]: https://npmjs.org/package/aster-parse-js
16+
[npm-image]: https://badge.fury.io/js/aster-parse-js.png
17+
18+
[travis-url]: http://travis-ci.org/asterjs/aster-parse-js
19+
[travis-image]: https://secure.travis-ci.org/asterjs/aster-parse-js.png?branch=master

index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
var Rx = require('rx');
4+
var parse = require('esprima').parse;
5+
6+
module.exports = function (options) {
7+
options = options || {};
8+
9+
var loc = options.loc !== false;
10+
var attachComment = !!options.comments;
11+
12+
return function (files) {
13+
return files.map(function (file) {
14+
return parse(file.contents, {loc: loc, source: file.path, attachComment: attachComment});
15+
});
16+
};
17+
};

package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "aster-parse-js",
3+
"version": "0.0.1",
4+
"description": "Parse js with aster.",
5+
"author": "Ingvar Stepanyan <[email protected]> (https://github.com/RReverser)",
6+
"repository": "asterjs/aster-parse-js",
7+
"license": "MIT",
8+
"keywords": [
9+
"aster-plugin",
10+
"ast",
11+
"javascript",
12+
"transform",
13+
"modify"
14+
],
15+
"main": "index.js",
16+
"scripts": {
17+
"test": "mocha"
18+
},
19+
"dependencies": {
20+
"esprima": "^1.2.2",
21+
"rx": "^2.2.24"
22+
},
23+
"devDependencies": {
24+
"mocha": "*"
25+
}
26+
}

test/mocha.opts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--reporter spec

test/test.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* global describe, it */
2+
3+
'use strict';
4+
5+
var assert = require('assert'),
6+
Rx = require('rx'),
7+
parseJs = require('..'),
8+
parse = require('esprima').parse;
9+
10+
it('without comments', function (done) {
11+
var file = {path: 'file.js', contents: 'a = 1;'},
12+
input = [file],
13+
expected = [parse(file.contents, {loc: true, source: file.path})];
14+
15+
// simulating file sequence and applying transformation
16+
parseJs()(Rx.Observable.fromArray(input))
17+
// checking against array of expected results iteratively
18+
.zip(expected, assert.deepEqual)
19+
// subscribing to check results
20+
.subscribe(function () {}, done, done);
21+
});
22+
23+
it('with comments', function (done) {
24+
var file = {path: 'file.js', contents: '/* hello, world! */a = 1;'},
25+
input = [file],
26+
expected = [parse(file.contents, {loc: true, source: file.path, attachComment: true})];
27+
28+
// simulating file sequence and applying transformation
29+
parseJs({comments: true})(Rx.Observable.fromArray(input))
30+
// checking against array of expected results iteratively
31+
.zip(expected, assert.deepEqual)
32+
// subscribing to check results
33+
.subscribe(function () {}, done, done);
34+
});
35+
36+
it('no location tracking', function (done) {
37+
var file = {path: 'file.js', contents: 'a = 1;'},
38+
input = [file],
39+
expected = [parse(file.contents)];
40+
41+
// simulating file sequence and applying transformation
42+
parseJs({loc: false})(Rx.Observable.fromArray(input))
43+
// checking against array of expected results iteratively
44+
.zip(expected, assert.deepEqual)
45+
// subscribing to check results
46+
.subscribe(function () {}, done, done);
47+
});

0 commit comments

Comments
 (0)