Skip to content

Commit

Permalink
Register mjs as javascript extension and treat such files as modules
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasblaesing committed Jun 2, 2024
1 parent 517d269 commit b1b7b01
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsTokenId> language) {
if (BaseParserResult.isEmbedded(snapshot)) {
return isModule(snapshot, language, 0, Integer.MAX_VALUE);
Expand Down

0 comments on commit b1b7b01

Please sign in to comment.