Skip to content

Commit

Permalink
corrects import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
mkslanc committed Nov 19, 2024
1 parent 44f7f07 commit 2583e1c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 146 deletions.
15 changes: 5 additions & 10 deletions ace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,16 +953,11 @@ declare module "ace-code" {
value?: any;
}) | null, options?: any): Editor;
export function createEditSession(text: import("ace-code/src/document").Document | string, mode?: import("ace-code").Ace.SyntaxMode): EditSession;
import Editor_5 = require("ace-code/src/editor");
import Editor = Editor_5.Editor;
import EditSession_3 = require("ace-code/src/edit_session");
import EditSession = EditSession_3.EditSession;
import Range_13 = require("ace-code/src/range");
import Range = Range_13.Range;
import UndoManager_2 = require("ace-code/src/undomanager");
import UndoManager = UndoManager_2.UndoManager;
import Renderer_1 = require("ace-code/src/virtual_renderer");
import Renderer = Renderer_1.VirtualRenderer;
import { Editor } from "ace-code/src/editor";
import { EditSession } from "ace-code/src/edit_session";
import { Range } from "ace-code/src/range";
import { UndoManager } from "ace-code/src/undomanager";
import { VirtualRenderer as Renderer } from "ace-code/src/virtual_renderer";
export var version: "1.36.5";
export { Range, Editor, EditSession, UndoManager, Renderer as VirtualRenderer };
}
18 changes: 18 additions & 0 deletions tool/ace_declaration_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ function fixDeclaration(content, aceNamespacePath) {
let allReferences = referencePaths.join("\n") + "\n/// <reference path=\"./ace-modes.d.ts\" />\n";
output = allReferences + output;
}
output = correctImportStatements(output);
output = cleanComments(output);
output = formatDts(outputName, output);
fs.writeFileSync(outputName, output);
Expand All @@ -418,6 +419,23 @@ function fixDeclaration(content, aceNamespacePath) {
checkFinalDeclaration(finalDeclarations);
}

/**
* Corrects the import statements in the provided text by replacing the old-style
* `require()` imports with modern ES6 `import` statements.
*/
function correctImportStatements(text) {
text = text.replace(
/import\s*\w+_\d+\s*=\s*require\(([\w\/"-]+)\);?.\s*import\s*(\w+)\s*=\s*\w+_\d+\.(\w+);?/gs,
(match, path, importName, exportName) => {
if (importName !== exportName) {
return `import {${exportName} as ${importName}} from ${path};`;
}
return `import {${exportName}} from ${path};`;
}
);
return text;
}

function cleanComments(text) {
text = text.replace(/^\s*\*\s*@(param|template|returns?|this|typedef)\s*({.+})?(\s*\[?[$\w]+\]?)?\s*$/gm, '');
text = text.replace(/@type\s*({.+})/g, '');
Expand Down
42 changes: 14 additions & 28 deletions types/ace-ext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ declare module "ace-code/src/ext/command_bar" {
}
export type Editor = import("ace-code/src/editor").Editor;
export type TooltipCommand = import("ace-code").Ace.TooltipCommand;
import Tooltip_2 = require("ace-code/src/tooltip");
import Tooltip = Tooltip_2.Tooltip;
import { Tooltip } from "ace-code/src/tooltip";
export var TOOLTIP_CLASS_NAME: string;
export var BUTTON_CLASS_NAME: string;
namespace Ace {
Expand Down Expand Up @@ -150,18 +149,12 @@ declare module "ace-code/src/ext/inline_autocomplete" {
*/
export function createInlineTooltip(parentEl: HTMLElement): CommandBarTooltip;
}
import Editor_2 = require("ace-code/src/editor");
import Editor = Editor_2.Editor;
import HashHandler_2 = require("ace-code/src/keyboard/hash_handler");
import HashHandler = HashHandler_2.HashHandler;
import AceInline_2 = require("ace-code/src/autocomplete/inline");
import AceInline = AceInline_2.AceInline;
import CommandBarTooltip_1 = require("ace-code/src/ext/command_bar");
import CommandBarTooltip = CommandBarTooltip_1.CommandBarTooltip;
import CompletionProvider_1 = require("ace-code/src/autocomplete");
import CompletionProvider = CompletionProvider_1.CompletionProvider;
import FilteredList_1 = require("ace-code/src/autocomplete");
import FilteredList = FilteredList_1.FilteredList;
import { Editor } from "ace-code/src/editor";
import { HashHandler } from "ace-code/src/keyboard/hash_handler";
import { AceInline } from "ace-code/src/autocomplete/inline";
import { CommandBarTooltip } from "ace-code/src/ext/command_bar";
import { CompletionProvider } from "ace-code/src/autocomplete";
import { FilteredList } from "ace-code/src/autocomplete";
}
declare module "ace-code/src/ext/searchbox-css" {
const _exports: string;
Expand Down Expand Up @@ -204,8 +197,7 @@ declare module "ace-code/src/ext/searchbox" {
show(value: string, isReplace?: boolean): void;
isFocused(): boolean;
}
import HashHandler_3 = require("ace-code/src/keyboard/hash_handler");
import HashHandler = HashHandler_3.HashHandler;
import { HashHandler } from "ace-code/src/keyboard/hash_handler";
}
declare module "ace-code/src/ext/elastic_tabstops_lite" {
export class ElasticTabstopsLite {
Expand All @@ -215,8 +207,7 @@ declare module "ace-code/src/ext/elastic_tabstops_lite" {
onChange: (delta: any) => void;
processRows(rows: number[]): void;
}
import Editor_3 = require("ace-code/src/editor");
import Editor = Editor_3.Editor;
import { Editor } from "ace-code/src/editor";
}
declare module "ace-code/src/ext/error_marker" {
export function showErrorMarker(editor: import("ace-code/src/editor").Editor, dir: number): void;
Expand All @@ -242,8 +233,7 @@ declare module "ace-code/src/ext/code_lens" {
export type EditSession = import("ace-code/src/edit_session").EditSession;
export type VirtualRenderer = import("ace-code/src/virtual_renderer").VirtualRenderer & {
};
import Editor_7 = require("ace-code/src/editor");
import Editor = Editor_7.Editor;
import { Editor } from "ace-code/src/editor";
}
declare module "ace-code/src/ext/emmet" {
export const commands: HashHandler;
Expand All @@ -253,10 +243,8 @@ declare module "ace-code/src/ext/emmet" {
export function isAvailable(editor: Editor, command: string): boolean;
export function load(cb: any): boolean;
export function setCore(e: any): void;
import HashHandler_5 = require("ace-code/src/keyboard/hash_handler");
import HashHandler = HashHandler_5.HashHandler;
import Editor_8 = require("ace-code/src/editor");
import Editor = Editor_8.Editor;
import { HashHandler } from "ace-code/src/keyboard/hash_handler";
import { Editor } from "ace-code/src/editor";
/**
* Implementation of {@link IEmmetEditor} interface for Ace
*/
Expand Down Expand Up @@ -360,8 +348,7 @@ declare module "ace-code/src/ext/emmet" {
}
declare module "ace-code/src/ext/hardwrap" {
export function hardWrap(editor: import("ace-code/src/editor").Editor, options: import("ace-code").Ace.HardWrapOptions): void;
import Editor_9 = require("ace-code/src/editor");
import Editor = Editor_9.Editor;
import { Editor } from "ace-code/src/editor";
}
declare module "ace-code/src/ext/menu_tools/settings_menu.css" {
const _exports: string;
Expand All @@ -378,8 +365,7 @@ declare module "ace-code/src/ext/menu_tools/get_editor_keyboard_shortcuts" {
}
declare module "ace-code/src/ext/keybinding_menu" {
export function init(editor: Editor): void;
import Editor_10 = require("ace-code/src/editor");
import Editor = Editor_10.Editor;
import { Editor } from "ace-code/src/editor";
}
declare module "ace-code/src/ext/linking" { }
declare module "ace-code/src/ext/modelist" {
Expand Down
Loading

0 comments on commit 2583e1c

Please sign in to comment.