You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ju...@apache.org on 2020/06/22 14:47:01 UTC

[netbeans] branch master updated: [NETBEANS-4434] Code Completion doesn't work when script type attribute value is "module"

This is an automated email from the ASF dual-hosted git repository.

junichi11 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 8b507cb  [NETBEANS-4434] Code Completion doesn't work when script type attribute value is "module"
     new d8fa98f  Merge pull request #2184 from junichi11/netbeans-4434-script-type-module-cc
8b507cb is described below

commit 8b507cbb5b1d61638cfa1422bb51d8f313546d03
Author: Junichi Yamamoto <ju...@apache.org>
AuthorDate: Sat Jun 13 02:46:30 2020 +0900

    [NETBEANS-4434] Code Completion doesn't work when script type attribute value is "module"
---
 .../modules/html/editor/completion/AttrValuesCompletion.java   |  2 +-
 .../modules/html/editor/embedding/JsEmbeddingProvider.java     | 10 +++++++++-
 .../modules/html/editor/embedding/JsEmbeddingProviderTest.java |  2 ++
 .../javascript2/editor/embedding/JsEmbeddingProvider.java      |  4 +++-
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/completion/AttrValuesCompletion.java b/ide/html.editor/src/org/netbeans/modules/html/editor/completion/AttrValuesCompletion.java
index b01d4a3..b482208 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/completion/AttrValuesCompletion.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/completion/AttrValuesCompletion.java
@@ -44,7 +44,7 @@ public abstract class AttrValuesCompletion {
     private static final ValueCompletion<HtmlCompletionItem> LINK_TYPE_SUPPORT =
             new ValuesSetSupport(new String[]{"text/css", "text/javascript"});
     private static final ValueCompletion<HtmlCompletionItem> SCRIPT_TYPE_SUPPORT = 
-            new ValuesSetSupport(new String[]{"text/javascript"});
+            new ValuesSetSupport(new String[]{"text/javascript", "module"}); // NOI18N
     private static final ValueCompletion<HtmlCompletionItem> STYLE_TYPE_SUPPORT = 
             new ValuesSetSupport(new String[]{"text/css"});
     private static final ValueCompletion<HtmlCompletionItem> TRUE_FALSE_SUPPORT =
diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/embedding/JsEmbeddingProvider.java b/ide/html.editor/src/org/netbeans/modules/html/editor/embedding/JsEmbeddingProvider.java
index da04c95..5c1b8b8 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/embedding/JsEmbeddingProvider.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/embedding/JsEmbeddingProvider.java
@@ -59,6 +59,7 @@ public class JsEmbeddingProvider extends EmbeddingProvider {
     private static final Logger LOGGER = Logger.getLogger(JsEmbeddingProvider.class.getSimpleName());
     private static final String JS_MIMETYPE = "text/javascript"; //NOI18N
     private static final String BABEL_MIMETYPE = "text/babel"; //NOI18N
+    private static final String SCRIPT_TYPE_MODULE = "module"; //NOI18N
     private static final String NETBEANS_IMPORT_FILE = "__netbeans_import__"; // NOI18N
     private boolean cancelled = true;
     private final Language JS_LANGUAGE;
@@ -210,7 +211,7 @@ public class JsEmbeddingProvider extends EmbeddingProvider {
 
     private void handleScript(Snapshot snapshot, TokenSequence<HTMLTokenId> ts, JsAnalyzerState state, List<Embedding> embeddings) {
         String scriptType = (String) ts.token().getProperty(HTMLTokenId.SCRIPT_TYPE_TOKEN_PROPERTY);
-        if (scriptType == null || JS_MIMETYPE.equals(scriptType) || BABEL_MIMETYPE.equals(scriptType)) {
+        if (isValidScriptTypeAttributeValue(scriptType)) {
             state.in_javascript = true;
             // Emit the block verbatim
             int sourceStart = ts.offset();
@@ -222,6 +223,13 @@ public class JsEmbeddingProvider extends EmbeddingProvider {
         }
     }
 
+    private boolean isValidScriptTypeAttributeValue(String scriptType) {
+        return scriptType == null
+                || JS_MIMETYPE.equals(scriptType)
+                || BABEL_MIMETYPE.equals(scriptType)
+                || SCRIPT_TYPE_MODULE.equals(scriptType);
+    }
+
     private void handleOpenTag(Snapshot snapshot, TokenSequence<HTMLTokenId> ts, List<Embedding> embeddings) {
         // TODO - if we see a <script src="someurl"> block that also
         // has a nonempty body, warn - the body will be ignored!!
diff --git a/ide/html.editor/test/unit/src/org/netbeans/modules/html/editor/embedding/JsEmbeddingProviderTest.java b/ide/html.editor/test/unit/src/org/netbeans/modules/html/editor/embedding/JsEmbeddingProviderTest.java
index 5589201..2d2cfdd 100644
--- a/ide/html.editor/test/unit/src/org/netbeans/modules/html/editor/embedding/JsEmbeddingProviderTest.java
+++ b/ide/html.editor/test/unit/src/org/netbeans/modules/html/editor/embedding/JsEmbeddingProviderTest.java
@@ -55,6 +55,8 @@ public class JsEmbeddingProviderTest extends CslTestBase {
                 + "}\n"
                 + "\n"
                 + "");
+
+        assertEmbedding("<script type=\"module\">alert();</script>", "alert();\n");
     }
 
     public void testCustomEL() {
diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/embedding/JsEmbeddingProvider.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/embedding/JsEmbeddingProvider.java
index d70dc56..265c94a 100644
--- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/embedding/JsEmbeddingProvider.java
+++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/embedding/JsEmbeddingProvider.java
@@ -52,6 +52,8 @@ import org.netbeans.modules.parsing.spi.TaskFactory;
 public final class JsEmbeddingProvider extends EmbeddingProvider {
 
     private static final int PRIORITY = 0;  //First one
+    private static final String JS_MIMETYPE = "text/javascript"; // NOI18N
+    private static final String SCRIPT_TYPE_MODULE = "module"; // NOI18N
 
     public static final String NETBEANS_IMPORT_FILE = "__netbeans_import__"; // NOI18N
     // ------------------------------------------------------------------------
@@ -699,7 +701,7 @@ public final class JsEmbeddingProvider extends EmbeddingProvider {
             HTMLTokenId htmlId = htmlToken.id();
             if (htmlId == HTMLTokenId.SCRIPT) {
                 String scriptType = (String)htmlToken.getProperty(HTMLTokenId.SCRIPT_TYPE_TOKEN_PROPERTY);
-                if(scriptType == null || "text/javascript".equals(scriptType)) {
+                if(scriptType == null || JS_MIMETYPE.equals(scriptType) || SCRIPT_TYPE_MODULE.equals(scriptType)) {
                     state.in_javascript = true;
                     // Emit the block verbatim
                     int sourceStart = ts.offset();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists