From b1b7b01de389afd6265e14bf7ae2ce0d3f02ffd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Thu, 30 May 2024 22:01:01 +0200 Subject: [PATCH] Register mjs as javascript extension and treat such files as modules --- .../modules/javascript2/editor/JsLanguage.java | 2 +- .../javascript2/editor/parser/SanitizingParser.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsLanguage.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsLanguage.java index dab743021b24..583374967d66 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsLanguage.java +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsLanguage.java @@ -48,7 +48,7 @@ public class JsLanguage extends DefaultLanguageConfig { @MIMEResolver.ExtensionRegistration( - extension={ "js", "sdoc", "jsx" }, + extension={ "js", "sdoc", "jsx", "mjs" }, displayName="#JsResolver", mimeType=JsTokenId.JAVASCRIPT_MIME_TYPE, position=190 diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/parser/SanitizingParser.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/parser/SanitizingParser.java index 13fe3c7b75a7..7022cbbd7aaf 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/parser/SanitizingParser.java +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/parser/SanitizingParser.java @@ -620,11 +620,22 @@ public void setSanitization(Sanitize sanitization) { public boolean isModule() { if (isModule == null) { - isModule = isModule(snapshot, language); + if(isModuleFromExtension()) { + isModule = true; + } else { + isModule = isModule(snapshot, language); + } } return isModule; } + private boolean isModuleFromExtension() { + FileObject fileObject = snapshot.getSource().getFileObject(); + return language == JsTokenId.javascriptLanguage() + && fileObject != null + && "mjs".equals(fileObject.getExt()); + } + private static boolean isModule(Snapshot snapshot, Language language) { if (BaseParserResult.isEmbedded(snapshot)) { return isModule(snapshot, language, 0, Integer.MAX_VALUE);