Skip to content

Commit e22bd5c

Browse files
committed
fix: add mode types, improve type definitions
This change adds a new ace-modes.d.ts file (references in the main ace.d.ts), which declares types for everything in the `ace/src/mode` folder. It's been done semi-automatically, and every mode or highlight rules have the same base type, even though technically different modes can have different sub-types (so currently we are omitting some information). Type definitions are excluded in the ace-builds package. Also included small fixes for existing types, like EditSession or Config.
1 parent 990745a commit e22bd5c

File tree

3 files changed

+1229
-13
lines changed

3 files changed

+1229
-13
lines changed

Makefile.dryice.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ function ace() {
171171
}
172172

173173
function buildTypes() {
174-
var definitions = fs.readFileSync(ACE_HOME + '/ace.d.ts', 'utf8');
174+
var aceCodeModeDefinitions = '/// <reference path="./ace-modes.d.ts" />';
175+
// ace-builds package has different structure and can't use mode types defined for the ace-code.
176+
// ace-builds modes are declared along with other modules in the ace-modules.d.ts file below.
177+
var definitions = fs.readFileSync(ACE_HOME + '/ace.d.ts', 'utf8').replace(aceCodeModeDefinitions, '');
175178
var paths = fs.readdirSync(BUILD_DIR + '/src-noconflict');
176179
var moduleRef = '/// <reference path="./ace-modules.d.ts" />';
177180

@@ -193,21 +196,20 @@ function buildTypes() {
193196

194197
fs.writeFileSync(BUILD_DIR + '/ace.d.ts', moduleRef + '\n' + definitions);
195198
fs.writeFileSync(BUILD_DIR + '/ace-modules.d.ts', pathModules);
196-
197199
var esmUrls = [];
200+
198201
var loader = paths.map(function(path) {
199202
if (/\.js$/.test(path) && !/^ace\.js$/.test(path)) {
200203
var moduleName = path.split('.')[0].replace(/-/, "/");
201204
if (/^worker/.test(moduleName))
202205
moduleName = "mode" + moduleName.slice(6) + "_worker";
203206
moduleName = moduleName.replace(/keybinding/, "keyboard");
204-
205207
esmUrls.push("ace.config.setModuleLoader('ace/" + moduleName + "', () => import('./src-noconflict/" + path + "'));");
206208
return "ace.config.setModuleUrl('ace/" + moduleName + "', require('file-loader?esModule=false!./src-noconflict/" + path + "'));";
207209
}
208210
}).join('\n');
209211
var esmLoader = esmUrls.join('\n');
210-
212+
211213
fs.writeFileSync(BUILD_DIR + '/webpack-resolver.js', loader, "utf8");
212214
fs.writeFileSync(BUILD_DIR + '/esm-resolver.js', esmLoader, "utf8");
213215
}

0 commit comments

Comments
 (0)