microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
39.84k stars 3.55k forks source link

[Bug] Error: The parameters in nameBuiltin from elixir.js are globally replaced, causing compilation errors. #4613

Open Wendydesigner opened 1 month ago

Wendydesigner commented 1 month ago

Reproducible in vscode.dev or in VS Code Desktop?

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

I tried version 0.34.0 and encountered this issue. I'm not sure if this issue started occurring after 11.06.2021.

Monaco Editor Playground Code

No response

Reproduction Steps

vite": "^4.4.5", "monaco-editor": "^0.50.0",

From vite.config.ts

export default defineConfig({
  define: {
    __ENV__: JSON.stringify(process.env.NODE_ENV),
  },

From package.json

  "scripts": {
    "dev": "NODE_ENV=dev vite",
    "build:production": "NODE_ENV=production run-p build-only",
    "build:qa": "NODE_ENV=qa run-p build-only",
  },

Actual (Problematic) Behavior

[error] [commonjs--resolver] Unexpected token (93:43) in /opt/jenkins/workspace/6398857-cs-fe-cs-fe-config-infra-newtest/node_modules/monaco-editor/esm/vs/basic-languages/elixir/elixir.js
file: /opt/jenkins/workspace/6398857-cs-fe-cs-fe-config-infra-newtest/node_modules/monaco-editor/esm/vs/basic-languages/elixir/elixir.js:93:43
92:   constants: ["true", "false", "nil"],
93:   nameBuiltin: ["__MODULE__", "__DIR__", ""qa"", "__CALLER__", "__STACKTRACE__"],
94:   operator: /-[->]?|!={0,2}|\*{1,2}|\/|\\\\|&{1,3}|\.\.?|\^(?:\^\^)?|\+\+?|<(?:-|<<|=|>|\|>|~>?)?|=~|={1,3}|>(?:=|>>)...
95:   variableName: /[a-z_][a-zA-Z0-9_]*[?!]?/,

Expected Behavior

No response

Additional Context

No response

Wendydesigner commented 1 month ago

The patch has been applied, and the compilation succeeded.

diff --git a/node_modules/monaco-editor/esm/vs/basic-languages/elixir/elixir.js b/node_modules/monaco-editor/esm/vs/basic-languages/elixir/elixir.js
index c7fa54b..2edaec3 100644
--- a/node_modules/monaco-editor/esm/vs/basic-languages/elixir/elixir.js
+++ b/node_modules/monaco-editor/esm/vs/basic-languages/elixir/elixir.js
@@ -92,7 +92,7 @@ var language = {
     "with"
   ],
   constants: ["true", "false", "nil"],
-  nameBuiltin: ["__MODULE__", "__DIR__", "__ENV__", "__CALLER__", "__STACKTRACE__"],
+  nameBuiltin: ["__MODULE__", "__DIR__", __ENV__, "__CALLER__", "__STACKTRACE__"],
   // Matches any of the operator names:
   // <<< >>> ||| &&& ^^^ ~~~ === !== ~>> <~> |~> <|> == != <= >= && || \\ <> ++ -- |> =~ -> <- ~> <~ :: .. = < > + - * / | . ^ & !
   operator: /-[->]?|!={0,2}|\*{1,2}|\/|\\\\|&{1,3}|\.\.?|\^(?:\^\^)?|\+\+?|<(?:-|<<|=|>|\|>|~>?)?|=~|={1,3}|>(?:=|>>)?|\|~>|\|>|\|{1,3}|~>>?|~~~|::/,