Skip to content

Commit c6bd47b

Browse files
Copilotkobenguyent
andauthored
fix: module.exports error by converting languageDetection to ES modules (#575)
* Initial plan * Fix module.exports error by converting languageDetection to ES modules Co-authored-by: kobenguyent <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: kobenguyent <[email protected]>
1 parent 5e48453 commit c6bd47b

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/components/ScenarioSource.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
<script>
141141
import axios from 'axios';
142142
import EditorNotFound from './EditorNotFound';
143-
const { detectLanguage, getLanguageDisplayName } = require('../utils/languageDetection');
143+
import { detectLanguage, getLanguageDisplayName } from '../utils/languageDetection';
144144
145145
export default {
146146
name: 'ScenarioSource',

src/utils/languageDetection.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ function isMonacoLanguageSupported(language) {
152152
return supportedLanguages.includes(language);
153153
}
154154

155-
// Export for CommonJS (Node.js tests) and ES modules (Vue.js components)
156-
module.exports = {
155+
// Export using ES modules syntax for modern bundlers
156+
export {
157157
detectLanguage,
158-
getLanguageDisplayName,
158+
getLanguageDisplayName,
159159
isMonacoLanguageSupported
160160
};

test/language-detection.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
const test = require('ava');
2-
const { detectLanguage, getLanguageDisplayName } = require('../src/utils/languageDetection.js');
2+
3+
// Use dynamic import for ES modules
4+
let detectLanguage, getLanguageDisplayName;
5+
6+
test.before(async () => {
7+
const module = await import('../src/utils/languageDetection.js');
8+
detectLanguage = module.detectLanguage;
9+
getLanguageDisplayName = module.getLanguageDisplayName;
10+
});
311

412
test('detectLanguage › should detect JavaScript files correctly', t => {
513
const result = detectLanguage('test.js');

0 commit comments

Comments
 (0)