Skip to content

Commit b80bd59

Browse files
committed
fix: ensure the ecma version is correct when calling parser using flat config
1 parent f29efa9 commit b80bd59

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

tests/src/core/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,6 @@ describe('parse(content, { settings, ecmaFeatures })', function () {
136136
it('prefers languageOptions.parserOptions over parserOptions', () => {
137137
const parseSpy = sinon.spy();
138138
parseStubParser.parse = parseSpy;
139-
expect(parse.bind(null, path, content, { settings: {}, parserPath: 'espree', languageOptions: { parserOptions: { sourceType: 'module', ecmaVersion: 2015, ecmaFeatures: { jsx: true } } }, parserOptions: { sourceType: 'script' } })).not.to.throw(Error);
139+
expect(parse.bind(null, path, content, { settings: {}, parserPath: 'espree', languageOptions: { sourceType: 'module', ecmaVersion: 2015, parserOptions: { sourceType: 'module', ecmaFeatures: { jsx: true } } }, parserOptions: { sourceType: 'script' } })).not.to.throw(Error);
140140
});
141141
});

utils/parse.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ exports.default = function parse(path, content, context) {
116116
parserOptions = Object.assign({}, parserOptions);
117117
parserOptions.ecmaFeatures = Object.assign({}, parserOptions.ecmaFeatures);
118118

119+
// fallback to the ecma version in languageOptions when using flat config
120+
if (context.languageOptions) {
121+
parserOptions.ecmaVersion = parserOptions.ecmaVersion || context.languageOptions.ecmaVersion;
122+
}
123+
119124
// always include comments and tokens (for doc parsing)
120125
parserOptions.comment = true;
121126
parserOptions.attachComment = true; // keeping this for backward-compat with older parsers

0 commit comments

Comments
 (0)