Skip to content

Commit

Permalink
fix(Parser): From recast to espree
Browse files Browse the repository at this point in the history
 The architecture script was failing with ES6+ code.
 fix #7
  • Loading branch information
nfroidure committed Nov 8, 2017
1 parent 6c51d97 commit afc9015
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
8 changes: 4 additions & 4 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This service needs some other services. To be able to mock and

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

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



Expand All @@ -34,7 +34,7 @@ architecture notes. It should be structured like that:
{body}
```
[See in context](./src/jsarch.js#L155-L165)
[See in context](./src/jsarch.js#L166-L176)
Expand Down Expand Up @@ -64,7 +64,7 @@ If you wish to add the architecture notes in a README.md file
you will have to set the `titleLevel` option to as much `#`
as necessar to fit the title hierarchy of you README file.
[See in context](./src/jsarch.js#L20-L28)
[See in context](./src/jsarch.js#L29-L37)
Expand All @@ -76,7 +76,7 @@ By default, links to the architecture notes right in the code
To override it, use the `base` option.
[See in context](./src/jsarch.js#L32-L40)
[See in context](./src/jsarch.js#L41-L49)
Expand Down
Binary file modified DEPENDENCIES.mmd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified bin/jsarch.js
100644 → 100755
Empty file.
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"cz": "env NODE_ENV=${NODE_ENV:-cli} git cz",
"graph": "npm run graph:build && npm run graph:generate",
"graph:build": "MERMAID_RUN=1 node bin/jsarch.js > DEPENDENCIES.mmd",
"graph:generate": "mermaid DEPENDENCIES.mmd -v -p",
"graph:generate": "mmdc -i DEPENDENCIES.mmd -o DEPENDENCIES.mmd.png",
"jsarch": "node bin/jsarch.js",
"lint": "eslint src/*.js",
"metapak": "metapak || echo 'Please `npm install --save-dev metapak`' && exit 0",
Expand All @@ -47,9 +47,9 @@
"bluebird": "^3.4.7",
"commander": "^2.9.0",
"debug": "2.6.1",
"espree": "^3.5.1",
"glob": "^7.1.1",
"knifecycle": "^1.3.1",
"recast": "^0.11.18",
"yerror": "^1.0.2"
},
"devDependencies": {
Expand All @@ -59,9 +59,13 @@
"cz-conventional-changelog": "^2.0.0",
"eslint": "3.16.0",
"eslint-config-simplifield": "4.1.1",
"eslint-plugin-mongodb": "0.2.4",
"eslint-plugin-node": "^5.2.1",
"eslint-plugin-promise": "^3.6.0",
"istanbul": "0.4.5",
"jsdoc-to-markdown": "^2.0.1",
"mermaid": "^7.0.0",
"mermaid": "^7.1.0",
"mermaid.cli": "^0.3.1",
"metapak": "0.0.18",
"metapak-nfroidure": "0.4.1",
"mocha": "3.2.0",
Expand Down
29 changes: 26 additions & 3 deletions src/jsarch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

const YError = require('yerror');
const path = require('path');
const recast = require('recast');
const espree = require('espree', {
attachComment: true,
ecmaVersion: 8,
ecmaFeatures: {
jsx: false,
globalReturn: false,
impliedStrict: false,
experimentalObjectRestSpread: true,
},
});
const types = require('ast-types');
const { compareNotes } = require('./compareNotes');

Expand Down Expand Up @@ -110,7 +119,9 @@ function jsArch({
titleLevel + architectureNote.num.split('.').map(() => '#').join('') +
' ' + architectureNote.title + eol + eol +
architectureNote.content.replace(
new RegExp('([\r\n]+)[ \t]{' + architectureNote.loc.indent + '}', 'g'),
new RegExp('([\r\n]+)[ \t]{' +
architectureNote.loc.start.column +
'}', 'g'),
'$1'
) + eol + eol +
'[See in context](' +
Expand Down Expand Up @@ -183,7 +194,19 @@ function _extractArchitectureNotes({ fs, log }, filePath) {
throw YError.wrap(err, 'E_FILE_FAILURE', filePath);
})
.then((content) => {
const ast = recast.parse(content);
const ast = espree.parse(content, {
attachComment: true,
loc: true,
range: true,
ecmaVersion: 8,
ecmaFeatures: {
jsx: false,
sourceType: 'module',
globalReturn: false,
impliedStrict: false,
experimentalObjectRestSpread: true,
},
});
const architectureNotes = [];

types.visit(ast, {
Expand Down

0 comments on commit afc9015

Please sign in to comment.