Skip to content

Commit 1cce268

Browse files
CompuIvesSaraVieira
authored andcommitted
Make getMode return undefined as default instead of 'typescript' (codesandbox#2007)
* Make getMode return undefined as default instead of 'typescript' * Fix window typing * Remove unnecessary extension from import path
1 parent f4fba71 commit 1cce268

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

packages/app/src/app/components/CodeEditor/CodeMirror/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
319319
const currentModule = this.currentModule;
320320

321321
if (!documentCache[currentModule.id]) {
322-
const mode = await this.getMode(currentModule.title);
322+
const mode = (await this.getMode(currentModule.title)) || 'typescript';
323323

324324
documentCache[currentModule.id] = new CodeMirror.Doc(
325325
currentModule.code || '',
@@ -421,7 +421,7 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
421421
CodeMirror.commands.save = this.handleSaveCode;
422422
}
423423

424-
const mode = await this.getMode(title);
424+
const mode = (await this.getMode(title)) || 'typescript';
425425

426426
documentCache[id] = new CodeMirror.Doc(code || '', mode);
427427

@@ -452,7 +452,7 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
452452

453453
configureEmmet = async () => {
454454
const { title } = this.currentModule;
455-
const mode = await this.getMode(title);
455+
const mode = (await this.getMode(title)) || 'typescript';
456456

457457
const newMode = mode === 'htmlmixed' ? 'html' : mode;
458458
const addon = newMode === 'jsx' ? { jsx: true } : null;

packages/app/src/app/components/CodeEditor/Monaco/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
10231023
}
10241024

10251025
lint = async (code: string, title: string, version: number) => {
1026-
const mode = await getMode(title, this.monaco);
1026+
const mode = (await getMode(title, this.monaco)) || 'typescript';
10271027
if (this.settings.lintEnabled) {
10281028
if (mode === 'javascript' || mode === 'vue') {
10291029
if (this.lintWorker) {
@@ -1219,7 +1219,8 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
12191219
// Related issue: https://github.com/Microsoft/monaco-editor/issues/461
12201220
const lib = this.addLib(module.code || '', path);
12211221

1222-
const mode = await getMode(module.title, this.monaco);
1222+
const mode =
1223+
(await getMode(module.title, this.monaco)) || 'typescript';
12231224

12241225
if (
12251226
mode !== 'javascript' &&

packages/app/src/app/components/CodeEditor/Monaco/mode.js renamed to packages/app/src/app/components/CodeEditor/Monaco/mode.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const requireAMDModule = paths =>
2-
new Promise(resolve => window.require(paths, () => resolve()));
2+
new Promise(resolve => (window as any).require(paths, () => resolve()));
33

44
export default async (title: string, monaco) => {
55
if (title == null) return 'javascript';
@@ -11,6 +11,7 @@ export default async (title: string, monaco) => {
1111
if (kind[1] === 'scss') return 'scss';
1212
if (kind[1] === 'json') return 'json';
1313
if (kind[1] === 'html') return 'html';
14+
if (kind[1] === 'svelte') return 'html';
1415
if (kind[1] === 'vue') {
1516
if (
1617
monaco.languages.getLanguages &&
@@ -26,5 +27,5 @@ export default async (title: string, monaco) => {
2627
if (/tsx?$/.test(kind[1])) return 'typescript';
2728
}
2829

29-
return 'typescript';
30+
return undefined;
3031
};

packages/app/src/app/components/CodeEditor/MonacoDiff/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default class MonacoDiff extends React.Component<Props>
5959
modifiedCode: string,
6060
title: string
6161
) => {
62-
const mode = await getMode(title, this.monaco);
62+
const mode = (await getMode(title, this.monaco)) || 'typescript';
6363
const originalModel = this.monaco.editor.createModel(originalCode, mode);
6464
const modifiedModel = this.monaco.editor.createModel(modifiedCode, mode);
6565

0 commit comments

Comments
 (0)