Skip to content

Commit

Permalink
fix: upgrade monaco editor (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Dec 30, 2024
1 parent 90516f6 commit f7358e7
Show file tree
Hide file tree
Showing 28 changed files with 118 additions and 97 deletions.
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"lint": {
"rules": {
"include": ["verbatim-module-syntax"],
"exclude": ["no-explicit-any", "no-sloppy-imports"]
},
"exclude": [
Expand Down
58 changes: 27 additions & 31 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"@viz-js/viz": "^3.3.1",
"allotment": "^1.20.0",
"circular-json": "^0.5.9",
"code-block-writer": "^13.0.2",
"code-block-writer": "^13.0.3",
"lz-string": "^1.4.4",
"monaco-editor": "^0.44.0",
"monaco-editor": "^0.52.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-monaco-editor": "0.55.0",
"react-monaco-editor": "0.56.2",
"react-spinners": "^0.13.6",
"react-treeview": "^0.4.7",
"ts-morph": "^23.0.0"
"ts-morph": "^25.0.0"
},
"devDependencies": {
"@types/circular-json": "^0.4.0",
Expand All @@ -32,7 +32,7 @@
"@vitejs/plugin-react": "^4.2.1",
"glob": "^10.3.10",
"ts-factory-code-generator-generator": "^0.7.0",
"typescript": "5.0.2",
"typescript": "5.7.2",
"vite": "^5.2.9",
"vite-plugin-monaco-editor": "^1.1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/analyzers/TsAnalyzer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Project, Symbol, Type } from "ts-morph";
import { Project, type Symbol, type Type } from "ts-morph";

export class TsAnalyzer {
private readonly tsSymbol: Symbol;
Expand Down
8 changes: 4 additions & 4 deletions src/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
compilerVersionCollection,
getCompilerApi,
hasLoadedCompilerApi,
ScriptKind,
ScriptTarget,
type ScriptKind,
type ScriptTarget,
} from "./compiler/index.js";
import { CodeEditorTheme } from "./components/index.js";
import type { CodeEditorTheme } from "./components/index.js";
import { appReducer, deriveEditorTheme } from "./reducers/index.js";
import { ApiLoadingState, StoreState } from "./types/index.js";
import { ApiLoadingState, type StoreState } from "./types/index.js";
import { sleep, StateSaver, UrlSaver } from "./utils/index.js";

const initialScriptTarget: ScriptTarget = 99 /* Latest */;
Expand Down
4 changes: 2 additions & 2 deletions src/actions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CompilerApi, Node } from "../compiler/index.js";
import type { CompilerApi, Node } from "../compiler/index.js";
import { actions as constants } from "../constants/index.js";
import { ApiLoadingState, OptionsState } from "../types/index.js";
import type { ApiLoadingState, OptionsState } from "../types/index.js";

export interface SetCode {
type: constants.SET_CODE;
Expand Down
30 changes: 26 additions & 4 deletions src/compiler/CompilerApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import * as ts from "typescript";
import { CompilerPackageNames } from "./compilerVersions.generated.js";
import type * as ts from "typescript";
import type { CompilerPackageNames } from "./compilerVersions.generated.js";

export declare enum FlowFlags {
TrueCondition,
FalseCondition,
Start,
Assignment,
BranchLabel,
LoopLabel,
Call,
SwitchClause,
Shared,
Referenced,
}

export interface CompilerApi {
createSourceFile: typeof ts.createSourceFile;
Expand All @@ -15,7 +28,7 @@ export interface CompilerApi {
ObjectFlags: typeof ts.ObjectFlags;
SymbolFlags: typeof ts.SymbolFlags;
TypeFlags: typeof ts.TypeFlags;
FlowFlags: typeof ts.FlowFlags;
FlowFlags: typeof FlowFlags;
// Internal enum
CheckFlags: object;
// Internal enum
Expand Down Expand Up @@ -48,4 +61,13 @@ export type TypeFlags = ts.TypeFlags;
export type SyntaxKind = ts.SyntaxKind;
export type CompilerHost = ts.CompilerHost;
export type CommentRange = ts.CommentRange;
export type FlowNode = ts.FlowNode;

export interface FlowNode {
id?: object;
node?: {
getText(): string;
};
antecedents: FlowNode[];
flags: FlowFlags;
getText(): string;
}
2 changes: 1 addition & 1 deletion src/compiler/convertOptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "@std/expect";
import { Theme } from "../types/index.js";
import { CompilerApi } from "./CompilerApi.js";
import type { CompilerApi } from "./CompilerApi.js";
import { convertOptions } from "./convertOptions.js";

function getCompilerApi(scriptKind: any, scriptTarget: any) {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/convertOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OptionsState } from "../types/index.js";
import { CompilerApi, ScriptKind, ScriptTarget } from "./CompilerApi.js";
import type { OptionsState } from "../types/index.js";
import type { CompilerApi, ScriptKind, ScriptTarget } from "./CompilerApi.js";

export function convertOptions(apiFrom: CompilerApi | undefined, apiTo: CompilerApi, options: OptionsState) {
if (apiFrom == null || apiFrom === apiTo) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/createSourceFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertNever } from "../utils/index.js";
import {
import type {
CompilerApi,
CompilerHost,
CompilerOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/getChildrenFunction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TreeMode } from "../types/index.js";
import { assertNever } from "../utils/index.js";
import { Node, SourceFile } from "./CompilerApi.js";
import type { Node, SourceFile } from "./CompilerApi.js";

export function getChildrenFunction(mode: TreeMode, sourceFile: SourceFile) {
switch (mode) {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/getCompilerApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { importCompilerApi, importLibFiles } from "./compiler.generated.js";
import { CompilerApi } from "./CompilerApi.js";
import { CompilerPackageNames } from "./compilerVersions.generated.js";
import type { CompilerApi } from "./CompilerApi.js";
import type { CompilerPackageNames } from "./compilerVersions.generated.js";

const compilerTypes: { [name: string]: Promise<CompilerApi> } = {};
const compilerTypesLoaded: { [name: string]: true } = {};
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/getDescendantAtRange.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TreeMode } from "../types/index.js";
import { CompilerApi, Node, SourceFile } from "./CompilerApi.js";
import type { TreeMode } from "../types/index.js";
import type { CompilerApi, Node, SourceFile } from "./CompilerApi.js";
import { getChildrenFunction } from "./getChildrenFunction.js";
import { getStartSafe } from "./getStartSafe.js";

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/getFactoryCodeGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FactoryCodeGenerator, getGenerateFactoryCodeFunction } from "./compiler.generated.js";
import { CompilerPackageNames } from "./compilerVersions.generated.js";
import { type FactoryCodeGenerator, getGenerateFactoryCodeFunction } from "./compiler.generated.js";
import type { CompilerPackageNames } from "./compilerVersions.generated.js";

const cache: { [packageName: string]: Promise<FactoryCodeGenerator> } = {};
const hasLoadedVersion: { [packageName: string]: true } = {};
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/getStartSafe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Node, SourceFile } from "./CompilerApi.js";
import type { Node, SourceFile } from "./CompilerApi.js";

export function getStartSafe(node: Node, sourceFile: SourceFile) {
// workaround for compiler api bug with getStart(sourceFile, true) (see PR #35029 in typescript repo)
Expand Down
4 changes: 2 additions & 2 deletions src/components/CodeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as monacoEditorForTypes from "monaco-editor";
import React from "react";
import * as ReactMonacoEditorForTypes from "react-monaco-editor";
import type * as ReactMonacoEditorForTypes from "react-monaco-editor";
import type { EditorDidMount } from "react-monaco-editor";
import { LineAndColumnComputer } from "../utils/index.js";
import { Spinner } from "./Spinner.js";
Expand Down Expand Up @@ -170,7 +170,7 @@ export class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState
minimap: { enabled: false },
readOnly: this.props.readOnly,
quickSuggestions: false,
occurrencesHighlight: false,
occurrencesHighlight: "off",
selectionHighlight: false,
codeLens: false,
suggestOnTriggerCharacters: false,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ExternalLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import type React from "react";

export function ExternalLink(props: { text: string; url: string }): React.ReactElement {
return <a href={props.url} target="_blank" rel="noopener noreferrer">{props.text}</a>;
Expand Down
4 changes: 2 additions & 2 deletions src/components/FactoryCodeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { FactoryCodeGenerator, getFactoryCodeGenerator } from "../compiler/index.js";
import { CompilerState } from "../types/index.js";
import { type FactoryCodeGenerator, getFactoryCodeGenerator } from "../compiler/index.js";
import type { CompilerState } from "../types/index.js";
import { Box } from "../utils/index.js";
import { CodeEditor } from "./CodeEditor.js";
import { Spinner } from "./Spinner.js";
Expand Down
6 changes: 3 additions & 3 deletions src/components/FlowNodeGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { instance as vizJsInstance, Viz } from "@viz-js/viz";
import { instance as vizJsInstance, type Viz } from "@viz-js/viz";
import React from "react";

import { FlowFlags, FlowNode } from "typescript";
import { useAppContext } from "../AppContext.js";
import { CompilerApi } from "../compiler/index.js";
import type { CompilerApi, FlowFlags, FlowNode } from "../compiler/index.js";
import { enumUtils } from "../utils/index.js";

export interface FlowNodeGraphProps {
Expand All @@ -16,6 +15,7 @@ function quoted(txt: string): string {
}

function getFlagText(api: CompilerApi, flags: FlowFlags) {
const { FlowFlags } = api;
// These are optimizations, not semantic flags.
flags = flags & ~(FlowFlags.Shared | FlowFlags.Referenced);
switch (flags) {
Expand Down
15 changes: 8 additions & 7 deletions src/components/Options.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useRef, useState } from "react";
import type React from "react";
import { useRef, useState } from "react";
import {
CompilerApi,
CompilerPackageNames,
type CompilerApi,
type CompilerPackageNames,
compilerVersionCollection,
ScriptKind,
ScriptTarget,
type ScriptKind,
type ScriptTarget,
} from "../compiler/index.js";
import { useOnClickOutside } from "../hooks/index.js";
import { OptionsState } from "../types/index.js";
import { Theme, TreeMode } from "../types/index.js";
import type { OptionsState } from "../types/index.js";
import { type Theme, TreeMode } from "../types/index.js";
import { enumUtils } from "../utils/index.js";
import { ExternalLink } from "./ExternalLink.js";

Expand Down
Loading

0 comments on commit f7358e7

Please sign in to comment.