简体   繁体   English

摩纳哥编辑器JavaScript语法关键字突出显示

[英]Monaco-Editor JavaScript Syntax Highlighting of Keywords

When using monaco-editor (0.15.6) embedded in a web page for editing javascript the syntax highlighting/colorization displays incorrect colors for object properties/functions if the property name or function name corresponds to a language keyword (such as 'delete' or 'throw'). 当使用嵌入在网页中的monaco-editor(0.15.6)来编辑javascript时,如果属性名称或函数名称对应于语言关键字(例如'delete'或'扔')。 The syntax highlighting/colorization in VS Code does not have this same issue, so wonder if there is a way to fix/override this behavior when using monaco-editor in a browser. VS Code中的语法突出显示/着色没有相同的问题,因此想知道在浏览器中使用monaco-editor时是否有一种方法可以解决/替代此行为。 Here is an example of the highlighting when an object has a property named 'delete' 这是对象具有名为“ delete”的属性时的突出显示示例

You will notice that the property named 'prop2' has the correct color, however the property named 'delete' does not. 您会注意到,名为“ prop2”的属性具有正确的颜色,但是名为“ delete”的属性却没有。 Theme and language setup are below: 主题和语言设置如下:

  monaco.editor.setTheme('vs-dark');
  monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
    noSemanticValidation: false,
    noSyntaxValidation: false,
  });
  monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
    allowNonTsExtensions: true,
    experimentalDecorators: true,
    esModuleInterop: true,
    allowSyntheticDefaultImports: true,
    noImplicitAny: true,
    module: monaco.languages.typescript.ModuleKind.ESNext,
    target: monaco.languages.typescript.ScriptTarget.ESNext,
    allowJs: true,
    checkJs: true,
    noUnusedLocals: true,
    noFallthroughCasesInSwitch: true,
    noImplicitThis: true,
    typeRoots: ["node_modules/@types"]
  });

Any tips appreciated! 任何提示表示赞赏!

Not sure, but I think it's because delete is a reserved word. 不确定,但是我认为这是因为delete是保留字。 All your properties will have the same colors. 您所有的属性都将具有相同的颜色。 But reserved words will have a different color. 但是保留字将具有不同的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM