我正在使用摩纳哥编辑器打字稿 . 有没有办法获得当前模型的AST?是否可以修改树,以便编辑器对更改做出反应?我想为打字稿做简单的重构工具?
摩纳哥不公开其AST,但您可以使用jscodeshift代替:
const editor = monaco.editor.create( document.querySelector("#editor"), {value: 'var foo;'})// editor content: var foo; const newValue = jscodeshift(editor.getValue()) .findVariableDeclarators('foo') .renameTo('bar') .toSource(); editor.setValue(newValue); // editor content: var bar;
相关的东西:据我所知,i 'm using monaco the edit TypeScript code based on Compiler API but then the code actually run in the backend since typeScript compiler dont'支持浏览器 . https://typescript-api-playground.glitch.me
2 回答
摩纳哥不公开其AST,但您可以使用jscodeshift代替:
相关的东西:据我所知,i 'm using monaco the edit TypeScript code based on Compiler API but then the code actually run in the backend since typeScript compiler dont'支持浏览器 . https://typescript-api-playground.glitch.me