Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
support options.parserPlugins
Browse files Browse the repository at this point in the history
  • Loading branch information
chinesedfan committed Oct 2, 2018
1 parent 3efe5f3 commit d27a9e3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
31 changes: 16 additions & 15 deletions src/parsers/babylon-parser.js
@@ -1,20 +1,21 @@
const babylon = require('@babel/parser')

module.exports = type => input =>
module.exports = (type, plugins) => input =>
babylon.parse(input, {
sourceType: 'module',
plugins: [
'jsx',
type,
'objectRestSpread',
['decorators', { decoratorsBeforeExport: true }],
'classProperties',
'exportExtensions',
'asyncGenerators',
'functionBind',
'functionSent',
'dynamicImport',
'optionalCatchBinding',
'optionalChaining'
]
plugins: [type].concat(
plugins || [
'jsx',
'objectRestSpread',
['decorators', { decoratorsBeforeExport: true }],
'classProperties',
'exportExtensions',
'asyncGenerators',
'functionBind',
'functionSent',
'dynamicImport',
'optionalCatchBinding',
'optionalChaining'
]
)
})
2 changes: 1 addition & 1 deletion src/parsers/index.js
Expand Up @@ -109,6 +109,6 @@ module.exports = (input, absolutePath, options) => {
const typedParser = absolutePath.endsWith('.ts') || absolutePath.endsWith('.tsx')
? 'typescript'
: 'flow'
const ast = estreeParse(typedParser)(input)
const ast = estreeParse(typedParser, options.parserPlugins)(input)
return processStyledComponentsFile(ast, absolutePath, options)
}
48 changes: 48 additions & 0 deletions test/options.test.js
Expand Up @@ -183,4 +183,52 @@ describe('options', () => {
})
})
})

describe('parserPlugins', () => {
// NOTE beforeEach() runs _after_ the beforeAll() hooks of the describe() blocks, so `fixture`
// will have the right path
beforeEach(done => {
const plugins = [
'jsx',
'objectRestSpread',
['decorators', { decoratorsBeforeExport: true }],
'classProperties',
'exportExtensions',
'asyncGenerators',
'functionBind',
'functionSent',
'dynamicImport',
'optionalCatchBinding',
'optionalChaining',
// Enable experimental feature
'exportDefaultFrom'
]

stylelint
.lint({
code: "export Container from './Container';",
config: {
processors: [[processor, { parserPlugins: plugins }]],
rules
}
})
.then(result => {
data = result
done()
})
.catch(err => {
console.log(err)
data = err
done()
})
})

it('should have one result', () => {
expect(data.results.length).toEqual(1)
})

it('should have not errored', () => {
expect(data.results[0].errored).toEqual(undefined)
})
})
})

0 comments on commit d27a9e3

Please sign in to comment.