Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] ExportMap / flat config: include languageOptions in context #3052

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

## [Unreleased]

### Fixed
- `ExportMap` / flat config: include `languageOptions` in context ([#3052], thanks [@michaelfaith])

## [2.30.0] - 2024-09-02

### Added
Expand Down Expand Up @@ -1129,6 +1132,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#3052]: https://github.com/import-js/eslint-plugin-import/pull/3052
[#3036]: https://github.com/import-js/eslint-plugin-import/pull/3036
[#3033]: https://github.com/import-js/eslint-plugin-import/pull/3033
[#3018]: https://github.com/import-js/eslint-plugin-import/pull/3018
Expand Down
3 changes: 2 additions & 1 deletion src/exportMap/childContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let prevSettings = '';
* also calculate a cacheKey, where parts of the cacheKey hash are memoized
*/
export default function childContext(path, context) {
const { settings, parserOptions, parserPath } = context;
const { settings, parserOptions, parserPath, languageOptions } = context;

if (JSON.stringify(settings) !== prevSettings) {
settingsHash = hashObject({ settings }).digest('hex');
Expand All @@ -28,5 +28,6 @@ export default function childContext(path, context) {
parserOptions,
parserPath,
path,
languageOptions,
};
}
51 changes: 51 additions & 0 deletions tests/src/exportMap/childContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { expect } from 'chai';

import childContext from '../../../src/exportMap/childContext';

describe('childContext', () => {
const settings = {
setting1: true,
setting2: false,
};
const parserOptions = {
ecmaVersion: 'latest',
sourceType: 'module',
};
const parserPath = 'path/to/parser';
const path = 'path/to/src/file';
const languageOptions = {
ecmaVersion: 2024,
sourceType: 'module',
parser: {},
};

// https://github.com/import-js/eslint-plugin-import/issues/3051
it('should pass context properties through, if present', () => {
const mockContext = {
settings,
parserOptions,
parserPath,
languageOptions,
};

const result = childContext(path, mockContext);

expect(result.settings).to.deep.equal(settings);
expect(result.parserOptions).to.deep.equal(parserOptions);
expect(result.parserPath).to.equal(parserPath);
expect(result.languageOptions).to.deep.equal(languageOptions);
});

it('should add path and cacheKey to context', () => {
const mockContext = {
settings,
parserOptions,
parserPath,
};

const result = childContext(path, mockContext);

expect(result.path).to.equal(path);
expect(result.cacheKey).to.be.a('string');
});
});