Skip to content

Commit

Permalink
fix: ensure the ecma version is correct when calling parser using fla…
Browse files Browse the repository at this point in the history
…t config
  • Loading branch information
G-Rath committed Sep 15, 2024
1 parent f29efa9 commit b80bd59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/src/core/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ describe('parse(content, { settings, ecmaFeatures })', function () {
it('prefers languageOptions.parserOptions over parserOptions', () => {
const parseSpy = sinon.spy();
parseStubParser.parse = parseSpy;
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);
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);
});
});
5 changes: 5 additions & 0 deletions utils/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ exports.default = function parse(path, content, context) {
parserOptions = Object.assign({}, parserOptions);
parserOptions.ecmaFeatures = Object.assign({}, parserOptions.ecmaFeatures);

// fallback to the ecma version in languageOptions when using flat config
if (context.languageOptions) {
parserOptions.ecmaVersion = parserOptions.ecmaVersion || context.languageOptions.ecmaVersion;
}

// always include comments and tokens (for doc parsing)
parserOptions.comment = true;
parserOptions.attachComment = true; // keeping this for backward-compat with older parsers
Expand Down

0 comments on commit b80bd59

Please sign in to comment.