Skip to content

Commit

Permalink
feat: add default parser plugins to support common syntax out of the box
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 authored and adrians5j committed Jul 7, 2020
1 parent 04c7566 commit 9dcac3c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/__tests__/defaultParserPlugins.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const defaultParserPlugins = require('../utils/defaultParserPlugins')

test('must merge the plugins', () => {
expect(defaultParserPlugins(['foo'])).toEqual(['typescript', 'classProperties', 'foo'])
})

test('must dedupe the plugins', () => {
expect(defaultParserPlugins(['foo', 'typescript'])).toEqual(['typescript', 'classProperties', 'foo'])
})

test('must handle undefined plugins', () => {
expect(defaultParserPlugins(undefined)).toEqual(['typescript', 'classProperties'])
})

test('must handle null plugins', () => {
expect(defaultParserPlugins(null)).toEqual(['typescript', 'classProperties'])
})

test('must handle empty plugins', () => {
expect(defaultParserPlugins([])).toEqual(['typescript', 'classProperties'])
})
6 changes: 6 additions & 0 deletions src/utils/defaultParserPlugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

const DEFAULT_PARSER_PLUGINS = ['typescript', 'classProperties'];

module.exports = plugins => [
...new Set([...DEFAULT_PARSER_PLUGINS, ...(plugins || [])])
];
7 changes: 6 additions & 1 deletion src/utils/extractSrcDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const glob = require("glob");
const fs = require("fs");
const get = require("lodash.get");
const parse = require("./parse");
const defaultParserPlugins = require('./defaultParserPlugins');

const isIgnoredPath = ({ path, instance, adioRc }) => {
let dirs = get(instance, "config.ignoreDirs") || [];
Expand Down Expand Up @@ -43,7 +44,11 @@ module.exports = ({ dir, instance, adioRc }) => {
src,
config: {
parser: {
...get(adioRc, "parser", get(instance, "config.parser", {}))
...get(adioRc, "parser", get(instance, "config.parser", {})),
// include commonly needed plugins
plugins: defaultParserPlugins(
get(adioRc, "parser.plugins", get(instance, "config.parser.plugins", []))
)
},
traverse: get(adioRc, "traverse", get(instance, "config.traverse"))
}
Expand Down

0 comments on commit 9dcac3c

Please sign in to comment.