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

Commit 995fb91

Browse files
committed
support options.parserPlugins
1 parent 3efe5f3 commit 995fb91

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

src/parsers/babylon-parser.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
const babylon = require('@babel/parser')
22

3-
module.exports = type => input =>
3+
module.exports = (type, plugins) => input =>
44
babylon.parse(input, {
55
sourceType: 'module',
6-
plugins: [
6+
plugins: [type].concat(plugins || [
77
'jsx',
8-
type,
98
'objectRestSpread',
109
['decorators', { decoratorsBeforeExport: true }],
1110
'classProperties',
@@ -16,5 +15,5 @@ module.exports = type => input =>
1615
'dynamicImport',
1716
'optionalCatchBinding',
1817
'optionalChaining'
19-
]
18+
])
2019
})

src/parsers/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,6 @@ module.exports = (input, absolutePath, options) => {
109109
const typedParser = absolutePath.endsWith('.ts') || absolutePath.endsWith('.tsx')
110110
? 'typescript'
111111
: 'flow'
112-
const ast = estreeParse(typedParser)(input)
112+
const ast = estreeParse(typedParser, options.parserPlugins)(input)
113113
return processStyledComponentsFile(ast, absolutePath, options)
114114
}

test/options.test.js

+48
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,52 @@ describe('options', () => {
183183
})
184184
})
185185
})
186+
187+
describe('parserPlugins', () => {
188+
// NOTE beforeEach() runs _after_ the beforeAll() hooks of the describe() blocks, so `fixture`
189+
// will have the right path
190+
beforeEach(done => {
191+
const plugins = [
192+
'jsx',
193+
'objectRestSpread',
194+
['decorators', { decoratorsBeforeExport: true }],
195+
'classProperties',
196+
'exportExtensions',
197+
'asyncGenerators',
198+
'functionBind',
199+
'functionSent',
200+
'dynamicImport',
201+
'optionalCatchBinding',
202+
'optionalChaining',
203+
// Enable experimental feature
204+
'exportDefaultFrom'
205+
]
206+
207+
stylelint
208+
.lint({
209+
code: "export Container from './Container';",
210+
config: {
211+
processors: [[processor, { parserPlugins: plugins }]],
212+
rules
213+
}
214+
})
215+
.then(result => {
216+
data = result
217+
done()
218+
})
219+
.catch(err => {
220+
console.log(err)
221+
data = err
222+
done()
223+
})
224+
})
225+
226+
it('should have one result', () => {
227+
expect(data.results.length).toEqual(1)
228+
})
229+
230+
it('should have not errored', () => {
231+
expect(data.results[0].errored).toEqual(undefined)
232+
})
233+
})
186234
})

0 commit comments

Comments
 (0)