摩纳哥编辑可以访问AST

时间:2017-11-20 10:14:41

标签: monaco-editor

我使用摩纳哥编辑器打字稿。有没有办法获得当前模型的AST?是否可以修改树,以便编辑器对更改做出反应?我想为打字稿做简单的重构工具?

2 个答案:

答案 0 :(得分:0)

Monaco不公开其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;

答案 1 :(得分:0)

与某事有关:我正在使用Monaco基于Compiler API的可编辑TypeScript代码,但是据我所知,该代码实际上在后端运行,因为TypeScript编译器不支持浏览器。 https://typescript-api-playground.glitch.me

相关问题