Skip to content

Commit afc9015

Browse files
committed
fix(Parser): From recast to espree
The architecture script was failing with ES6+ code. fix #7
1 parent 6c51d97 commit afc9015

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

ARCHITECTURE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This service needs some other services. To be able to mock and
1919

2020
![Dependencies Graph](./DEPENDENCIES.mmd.png)
2121

22-
[See in context](./src/jsarch.js#L45-L56)
22+
[See in context](./src/jsarch.js#L54-L65)
2323

2424

2525

@@ -34,7 +34,7 @@ architecture notes. It should be structured like that:
3434
{body}
3535
```
3636
37-
[See in context](./src/jsarch.js#L155-L165)
37+
[See in context](./src/jsarch.js#L166-L176)
3838
3939
4040
@@ -64,7 +64,7 @@ If you wish to add the architecture notes in a README.md file
6464
you will have to set the `titleLevel` option to as much `#`
6565
as necessar to fit the title hierarchy of you README file.
6666
67-
[See in context](./src/jsarch.js#L20-L28)
67+
[See in context](./src/jsarch.js#L29-L37)
6868
6969
7070
@@ -76,7 +76,7 @@ By default, links to the architecture notes right in the code
7676
7777
To override it, use the `base` option.
7878
79-
[See in context](./src/jsarch.js#L32-L40)
79+
[See in context](./src/jsarch.js#L41-L49)
8080
8181
8282

DEPENDENCIES.mmd.png

-30.2 KB
Loading

bin/jsarch.js

100644100755
File mode changed.

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"cz": "env NODE_ENV=${NODE_ENV:-cli} git cz",
2222
"graph": "npm run graph:build && npm run graph:generate",
2323
"graph:build": "MERMAID_RUN=1 node bin/jsarch.js > DEPENDENCIES.mmd",
24-
"graph:generate": "mermaid DEPENDENCIES.mmd -v -p",
24+
"graph:generate": "mmdc -i DEPENDENCIES.mmd -o DEPENDENCIES.mmd.png",
2525
"jsarch": "node bin/jsarch.js",
2626
"lint": "eslint src/*.js",
2727
"metapak": "metapak || echo 'Please `npm install --save-dev metapak`' && exit 0",
@@ -47,9 +47,9 @@
4747
"bluebird": "^3.4.7",
4848
"commander": "^2.9.0",
4949
"debug": "2.6.1",
50+
"espree": "^3.5.1",
5051
"glob": "^7.1.1",
5152
"knifecycle": "^1.3.1",
52-
"recast": "^0.11.18",
5353
"yerror": "^1.0.2"
5454
},
5555
"devDependencies": {
@@ -59,9 +59,13 @@
5959
"cz-conventional-changelog": "^2.0.0",
6060
"eslint": "3.16.0",
6161
"eslint-config-simplifield": "4.1.1",
62+
"eslint-plugin-mongodb": "0.2.4",
63+
"eslint-plugin-node": "^5.2.1",
64+
"eslint-plugin-promise": "^3.6.0",
6265
"istanbul": "0.4.5",
6366
"jsdoc-to-markdown": "^2.0.1",
64-
"mermaid": "^7.0.0",
67+
"mermaid": "^7.1.0",
68+
"mermaid.cli": "^0.3.1",
6569
"metapak": "0.0.18",
6670
"metapak-nfroidure": "0.4.1",
6771
"mocha": "3.2.0",

src/jsarch.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22

33
const YError = require('yerror');
44
const path = require('path');
5-
const recast = require('recast');
5+
const espree = require('espree', {
6+
attachComment: true,
7+
ecmaVersion: 8,
8+
ecmaFeatures: {
9+
jsx: false,
10+
globalReturn: false,
11+
impliedStrict: false,
12+
experimentalObjectRestSpread: true,
13+
},
14+
});
615
const types = require('ast-types');
716
const { compareNotes } = require('./compareNotes');
817

@@ -110,7 +119,9 @@ function jsArch({
110119
titleLevel + architectureNote.num.split('.').map(() => '#').join('') +
111120
' ' + architectureNote.title + eol + eol +
112121
architectureNote.content.replace(
113-
new RegExp('([\r\n]+)[ \t]{' + architectureNote.loc.indent + '}', 'g'),
122+
new RegExp('([\r\n]+)[ \t]{' +
123+
architectureNote.loc.start.column +
124+
'}', 'g'),
114125
'$1'
115126
) + eol + eol +
116127
'[See in context](' +
@@ -183,7 +194,19 @@ function _extractArchitectureNotes({ fs, log }, filePath) {
183194
throw YError.wrap(err, 'E_FILE_FAILURE', filePath);
184195
})
185196
.then((content) => {
186-
const ast = recast.parse(content);
197+
const ast = espree.parse(content, {
198+
attachComment: true,
199+
loc: true,
200+
range: true,
201+
ecmaVersion: 8,
202+
ecmaFeatures: {
203+
jsx: false,
204+
sourceType: 'module',
205+
globalReturn: false,
206+
impliedStrict: false,
207+
experimentalObjectRestSpread: true,
208+
},
209+
});
187210
const architectureNotes = [];
188211

189212
types.visit(ast, {

0 commit comments

Comments
 (0)