mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 19:42:56 +01:00
Run prettier
This commit is contained in:
parent
21ceb6a387
commit
b87c75d7e9
20 changed files with 3351 additions and 2779 deletions
|
|
@ -2,59 +2,58 @@
|
|||
// which can do work on a bg thread.
|
||||
|
||||
// This version of the vfs edits the global scope (in the case of a webworker, this is 'self')
|
||||
importScripts("https://unpkg.com/@typescript/vfs@1.3.0/dist/vfs.globals.js")
|
||||
importScripts('https://unpkg.com/@typescript/vfs@1.3.0/dist/vfs.globals.js');
|
||||
|
||||
/** @type { import("@typescript/vfs") } */
|
||||
const tsvfs = globalThis.tsvfs
|
||||
const tsvfs = globalThis.tsvfs;
|
||||
|
||||
/** @type {import("../src/tsWorker").CustomTSWebWorkerFactory }*/
|
||||
const worker = (TypeScriptWorker, ts, libFileMap) => {
|
||||
return class MonacoTSWorker extends TypeScriptWorker {
|
||||
return class MonacoTSWorker extends TypeScriptWorker {
|
||||
// Adds a custom function to the webworker
|
||||
async getDTSEmitForFile(fileName) {
|
||||
const result = await this.getEmitOutput(fileName);
|
||||
const firstDTS = result.outputFiles.find((o) => o.name.endsWith('.d.ts'));
|
||||
return (firstDTS && firstDTS.text) || '';
|
||||
}
|
||||
|
||||
// Adds a custom function to the webworker
|
||||
async getDTSEmitForFile(fileName) {
|
||||
const result = await this.getEmitOutput(fileName)
|
||||
const firstDTS = result.outputFiles.find(o => o.name.endsWith(".d.ts"))
|
||||
return (firstDTS && firstDTS.text) || ""
|
||||
}
|
||||
async printAST(fileName) {
|
||||
console.log('Creating virtual TS project');
|
||||
const compilerOptions = this.getCompilationSettings();
|
||||
const fsMap = new Map();
|
||||
for (const key of Object.keys(libFileMap)) {
|
||||
fsMap.set(key, '/' + libFileMap[key]);
|
||||
}
|
||||
|
||||
async printAST(fileName) {
|
||||
console.log("Creating virtual TS project")
|
||||
const compilerOptions = this.getCompilationSettings()
|
||||
const fsMap = new Map()
|
||||
for (const key of Object.keys(libFileMap)) {
|
||||
fsMap.set(key, "/" + libFileMap[key])
|
||||
}
|
||||
const thisCode = await this.getScriptText(fileName);
|
||||
fsMap.set('index.ts', thisCode);
|
||||
|
||||
const thisCode = await this.getScriptText(fileName)
|
||||
fsMap.set("index.ts", thisCode)
|
||||
console.log('Starting up TS program');
|
||||
const system = tsvfs.createSystem(fsMap);
|
||||
const host = tsvfs.createVirtualCompilerHost(system, compilerOptions, ts);
|
||||
|
||||
console.log("Starting up TS program")
|
||||
const system = tsvfs.createSystem(fsMap)
|
||||
const host = tsvfs.createVirtualCompilerHost(system, compilerOptions, ts)
|
||||
const program = ts.createProgram({
|
||||
rootNames: [...fsMap.keys()],
|
||||
options: compilerOptions,
|
||||
host: host.compilerHost
|
||||
});
|
||||
|
||||
const program = ts.createProgram({
|
||||
rootNames: [...fsMap.keys()],
|
||||
options: compilerOptions,
|
||||
host: host.compilerHost,
|
||||
})
|
||||
// Now I can look at the AST for the .ts file too
|
||||
const mainSrcFile = program.getSourceFile('index.ts');
|
||||
let miniAST = 'SourceFile';
|
||||
|
||||
// Now I can look at the AST for the .ts file too
|
||||
const mainSrcFile = program.getSourceFile("index.ts")
|
||||
let miniAST = "SourceFile"
|
||||
const recurse = (parent, depth) => {
|
||||
if (depth > 5) return;
|
||||
ts.forEachChild(parent, (node) => {
|
||||
const spaces = ' '.repeat(depth + 1);
|
||||
miniAST += `\n${spaces}${ts.SyntaxKind[node.kind]}`;
|
||||
recurse(node, depth + 1);
|
||||
});
|
||||
};
|
||||
recurse(mainSrcFile, 0);
|
||||
return miniAST;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const recurse = (parent, depth) => {
|
||||
if (depth > 5) return
|
||||
ts.forEachChild(parent, node => {
|
||||
const spaces = " ".repeat(depth + 1)
|
||||
miniAST += `\n${spaces}${ts.SyntaxKind[node.kind]}`
|
||||
recurse(node, depth + 1)
|
||||
})
|
||||
}
|
||||
recurse(mainSrcFile, 0)
|
||||
return miniAST
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.customTSWorkerFactory = worker
|
||||
self.customTSWorkerFactory = worker;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue