Repository: PrismJS/prism
Pull request #3506 (2022-07-26 08:31:19)

Update Scala keywords to support Scala 3
Add several soft keywords that have been introduced in Scala 3.

github-actions[bot]: 
<!--
  0 failure: 
  0 warning: 
  
  1 markdown notices
  DangerID: danger-id-Danger;
-->



## No JS Changes
<p align="right">
  Generated by :no_entry_sign: <a href="https://danger.systems/js">dangerJS</a> against df975d747ca3c4cf0e9db7054a1b5a2856ff6532
</p>

julienrf: Thank you @RunDevelopment for your help. I’ve added a test but I was unable to update the test:

~~~ text
$ npm run test:languages -- --update

> prismjs@1.28.0 test:languages /tmp/prism
> mocha tests/run.js "--update"

<function>:7
      return await import(url.pathToFileURL(file));
                   ^

SyntaxError: Expected an operand but found import
    at Module._compile (internal/modules/cjs/loader.js:891:18)
    at Object.<anonymous> (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/tmp/prism/node_modules/mocha/lib/mocha.js:16:16)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.<anonymous> (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
~~~

Maybe my version of node is too old? I use version 14.20.0, which should be OK according to your README?

Running `npm run build` failed as well:

~~~ text
$ npm run build                     

> prismjs@1.28.0 build /tmp/prism
> gulp

no native wasm support detected
no binaryen method succeeded. consider enabling more options, like interpreting, if you want that: https://github.com/kripken/emscripten/wiki/WebAssembly#binaryen-methods
no binaryen method succeeded. consider enabling more options, like interpreting, if you want that: https://github.com/kripken/emscripten/wiki/WebAssembly#binaryen-methods

/tmp/prism/node_modules/wawoff2/build/woff2/compress_binding.js:1
(function (exports, require, module, __filename, __dirname) {var Module=typeof Module!=="undefined"?Module:{};var Module={"locateFile":(function(filename){return __dirname+"/"+filename})};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_IS_SHELL=false;if(Module["ENVIRONMENT"]){if(Module["ENVIRONMENT"]==="WEB"){ENVIRONMENT_IS_WEB=true}else if(Module["ENVIRONMENT"]==="WORKER"){ENVIRONMENT_IS_WORKER=true}else if(Module["ENVIRONMENT"]==="NODE"){ENVIRONMENT_IS_NODE=true}else if(Module["ENVIRONMENT"]==="SHELL"){ENVIRONMENT_IS_SHELL=true}else{throw new Error("The provided Module['ENVIRONMENT'] value is not valid. It must be one of: WEB|WORKER|NODE|SHELL.")}}else{ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_IS_NODE
abort("no binaryen method succeeded. consider enabling more options, like interpreting, if you want that: https://github.com/kripken/emscripten/wiki/WebAssembly#binaryen-methods"). Build with -s ASSERTIONS=1 for more info.
~~~

I am not sure how to move forward.
RunDevelopment: No, NodeJS v14.x is supported. We use that version is our CI.

Are you sure you installed our dependencies correctly? Please you `npm ci`.
julienrf: I did `rm -rf node_modules` and then `npm ci`. Then `npm run test:languages -- --update` failed the same way.
RunDevelopment: That is **very** strange. My only guess is that npm is not actually using node to run our tests and build scripts. We recently had [a similar issue](https://github.com/PrismJS/prism/pull/3505#issuecomment-1193957678).

For now, I rebuilt and updated the tests for you. 

Patch:
diff --git a/components/prism-scala.js b/components/prism-scala.js
index 40b96fa1..9ba46492 100644
--- a/components/prism-scala.js
+++ b/components/prism-scala.js
@@ -8,7 +8,7 @@ Prism.languages.scala = Prism.languages.extend('java', {
 		pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
 		greedy: true
 	},
-	'keyword': /<-|=>|\b(?:abstract|case|catch|class|def|do|else|extends|final|finally|for|forSome|if|implicit|import|lazy|match|new|null|object|override|package|private|protected|return|sealed|self|super|this|throw|trait|try|type|val|var|while|with|yield)\b/,
+	'keyword': /<-|=>|\b(?:abstract|case|catch|class|def|derives|do|else|enum|extends|extension|final|finally|for|forSome|given|if|implicit|import|infix|inline|lazy|match|new|null|object|opaque|open|override|package|private|protected|return|sealed|self|super|this|throw|trait|transparent|try|type|using|val|var|while|with|yield)\b/,
 	'number': /\b0x(?:[\da-f]*\.)?[\da-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e\d+)?[dfl]?/i,
 	'builtin': /\b(?:Any|AnyRef|AnyVal|Boolean|Byte|Char|Double|Float|Int|Long|Nothing|Short|String|Unit)\b/,
 	'symbol': /'[^\d\s\\]\w*/
diff --git a/components/prism-scala.min.js b/components/prism-scala.min.js
index 1f3db0b8..6d7220d6 100644
--- a/components/prism-scala.min.js
+++ b/components/prism-scala.min.js
@@ -1,1 +1,1 @@
-Prism.languages.scala=Prism.languages.extend("java",{"triple-quoted-string":{pattern:/"""[\s\S]*?"""/,greedy:!0,alias:"string"},string:{pattern:/("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,greedy:!0},keyword:/<-|=>|\b(?:abstract|case|catch|class|def|do|else|extends|final|finally|for|forSome|if|implicit|import|lazy|match|new|null|object|override|package|private|protected|return|sealed|self|super|this|throw|trait|try|type|val|var|while|with|yield)\b/,number:/\b0x(?:[\da-f]*\.)?[\da-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e\d+)?[dfl]?/i,builtin:/\b(?:Any|AnyRef|AnyVal|Boolean|Byte|Char|Double|Float|Int|Long|Nothing|Short|String|Unit)\b/,symbol:/'[^\d\s\\]\w*/}),Prism.languages.insertBefore("scala","triple-quoted-string",{"string-interpolation":{pattern:/\b[a-z]\w*(?:"""(?:[^$]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*?"""|"(?:[^$"\r\n]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*")/i,greedy:!0,inside:{id:{pattern:/^\w+/,greedy:!0,alias:"function"},escape:{pattern:/\\\$"|\$[$"]/,greedy:!0,alias:"symbol"},interpolation:{pattern:/\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,greedy:!0,inside:{punctuation:/^\$\{?|\}$/,expression:{pattern:/[\s\S]+/,inside:Prism.languages.scala}}},string:/[\s\S]+/}}}),delete Prism.languages.scala["class-name"],delete Prism.languages.scala.function;
\ No newline at end of file
+Prism.languages.scala=Prism.languages.extend("java",{"triple-quoted-string":{pattern:/"""[\s\S]*?"""/,greedy:!0,alias:"string"},string:{pattern:/("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,greedy:!0},keyword:/<-|=>|\b(?:abstract|case|catch|class|def|derives|do|else|enum|extends|extension|final|finally|for|forSome|given|if|implicit|import|infix|inline|lazy|match|new|null|object|opaque|open|override|package|private|protected|return|sealed|self|super|this|throw|trait|transparent|try|type|using|val|var|while|with|yield)\b/,number:/\b0x(?:[\da-f]*\.)?[\da-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e\d+)?[dfl]?/i,builtin:/\b(?:Any|AnyRef|AnyVal|Boolean|Byte|Char|Double|Float|Int|Long|Nothing|Short|String|Unit)\b/,symbol:/'[^\d\s\\]\w*/}),Prism.languages.insertBefore("scala","triple-quoted-string",{"string-interpolation":{pattern:/\b[a-z]\w*(?:"""(?:[^$]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*?"""|"(?:[^$"\r\n]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*")/i,greedy:!0,inside:{id:{pattern:/^\w+/,greedy:!0,alias:"function"},escape:{pattern:/\\\$"|\$[$"]/,greedy:!0,alias:"symbol"},interpolation:{pattern:/\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,greedy:!0,inside:{punctuation:/^\$\{?|\}$/,expression:{pattern:/[\s\S]+/,inside:Prism.languages.scala}}},string:/[\s\S]+/}}}),delete Prism.languages.scala["class-name"],delete Prism.languages.scala.function;
\ No newline at end of file


Test patch:
diff --git a/tests/languages/scala/keyword_feature.test b/tests/languages/scala/keyword_feature.test
index 9e3cfb4d..859dac03 100644
--- a/tests/languages/scala/keyword_feature.test
+++ b/tests/languages/scala/keyword_feature.test
@@ -1,15 +1,19 @@
 <- =>
 
 abstract case catch
-class def do else
-extends final finally
-for forSome if
-implicit import; lazy
+class def derives do
+else enum extends extension
+final finally
+for forSome given if
+implicit import;
+infix inline lazy
 match new null object
+opaque open
 override package private
 protected return sealed
 self super this throw
-trait try type val
+trait transparent try
+type using val
 var while with yield
 
 ----------------------------------------------------
@@ -17,19 +21,71 @@ var while with yield
 [
 	["keyword", "<-"], ["keyword", "=>"],
 
-	["keyword", "abstract"], ["keyword", "case"], ["keyword", "catch"],
-	["keyword", "class"], ["keyword", "def"], ["keyword", "do"], ["keyword", "else"],
-	["keyword", "extends"], ["keyword", "final"], ["keyword", "finally"],
-	["keyword", "for"], ["keyword", "forSome"], ["keyword", "if"],
-	["keyword", "implicit"], ["keyword", "import"], ["punctuation", ";"], ["keyword", "lazy"],
-	["keyword", "match"], ["keyword", "new"], ["keyword", "null"], ["keyword", "object"],
-	["keyword", "override"], ["keyword", "package"], ["keyword", "private"],
-	["keyword", "protected"], ["keyword", "return"], ["keyword", "sealed"],
-	["keyword", "self"], ["keyword", "super"], ["keyword", "this"], ["keyword", "throw"],
-	["keyword", "trait"], ["keyword", "try"], ["keyword", "type"], ["keyword", "val"],
-	["keyword", "var"], ["keyword", "while"], ["keyword", "with"], ["keyword", "yield"]
+	["keyword", "abstract"],
+	["keyword", "case"],
+	["keyword", "catch"],
+
+	["keyword", "class"],
+	["keyword", "def"],
+	["keyword", "derives"],
+	["keyword", "do"],
+
+	["keyword", "else"],
+	["keyword", "enum"],
+	["keyword", "extends"],
+	["keyword", "extension"],
+
+	["keyword", "final"],
+	["keyword", "finally"],
+
+	["keyword", "for"],
+	["keyword", "forSome"],
+	["keyword", "given"],
+	["keyword", "if"],
+
+	["keyword", "implicit"],
+	["keyword", "import"],
+	["punctuation", ";"],
+
+	["keyword", "infix"],
+	["keyword", "inline"],
+	["keyword", "lazy"],
+
+	["keyword", "match"],
+	["keyword", "new"],
+	["keyword", "null"],
+	["keyword", "object"],
+
+	["keyword", "opaque"],
+	["keyword", "open"],
+
+	["namespace", ["override"]],
+	["keyword", "package"],
+	["keyword", "private"],
+
+	["keyword", "protected"],
+	["keyword", "return"],
+	["keyword", "sealed"],
+
+	["keyword", "self"],
+	["keyword", "super"],
+	["keyword", "this"],
+	["keyword", "throw"],
+
+	["keyword", "trait"],
+	["keyword", "transparent"],
+	["keyword", "try"],
+
+	["keyword", "type"],
+	["keyword", "using"],
+	["keyword", "val"],
+
+	["keyword", "var"],
+	["keyword", "while"],
+	["keyword", "with"],
+	["keyword", "yield"]
 ]
 
 ----------------------------------------------------
 
-Checks for keywords.
\ No newline at end of file
+Checks for keywords.