diff --git a/src/com/google/javascript/jscomp/DiagnosticGroups.java b/src/com/google/javascript/jscomp/DiagnosticGroups.java index d01494c8a11..dd1a6daf6f0 100644 --- a/src/com/google/javascript/jscomp/DiagnosticGroups.java +++ b/src/com/google/javascript/jscomp/DiagnosticGroups.java @@ -228,6 +228,7 @@ public static DiagnosticGroup forName(String name) { "nonStandardJsDocs", RhinoErrorReporter.BAD_JSDOC_ANNOTATION, RhinoErrorReporter.INVALID_PARAM, + RhinoErrorReporter.JSDOC_IMPORT_TYPE_WARNING, CheckJSDoc.JSDOC_IN_BLOCK_COMMENT); public static final DiagnosticGroup INVALID_CASTS = diff --git a/src/com/google/javascript/jscomp/RhinoErrorReporter.java b/src/com/google/javascript/jscomp/RhinoErrorReporter.java index 255bd6c665d..920cd147a21 100644 --- a/src/com/google/javascript/jscomp/RhinoErrorReporter.java +++ b/src/com/google/javascript/jscomp/RhinoErrorReporter.java @@ -48,6 +48,10 @@ class RhinoErrorReporter { static final DiagnosticType JSDOC_MISSING_TYPE_WARNING = DiagnosticType.disabled("JSC_JSDOC_MISSING_TYPE_WARNING", "{0}"); + // Import is supported by VSCode and is pretty much a standard now. + static final DiagnosticType JSDOC_IMPORT_TYPE_WARNING = + DiagnosticType.disabled("JSC_JSDOC_IMPORT_TYPE_WARNING", "{0}"); + static final DiagnosticType TOO_MANY_TEMPLATE_PARAMS = DiagnosticType.disabled("JSC_TOO_MANY_TEMPLATE_PARAMS", "{0}"); @@ -153,6 +157,9 @@ private RhinoErrorReporter(AbstractCompiler compiler) { // Unresolved types that aren't forward declared. .put(Pattern.compile(".*Unknown type.*"), UNRECOGNIZED_TYPE_ERROR) + // Import annotation errors. + .put(Pattern.compile("^Bad type annotation. Import in typedef.*"), JSDOC_IMPORT_TYPE_WARNING) + // Type annotation errors. .put(Pattern.compile("^Bad type annotation.*"), TYPE_PARSE_ERROR) diff --git a/src/com/google/javascript/jscomp/parsing/JsDocInfoParser.java b/src/com/google/javascript/jscomp/parsing/JsDocInfoParser.java index 04648efae32..b716f302cf6 100644 --- a/src/com/google/javascript/jscomp/parsing/JsDocInfoParser.java +++ b/src/com/google/javascript/jscomp/parsing/JsDocInfoParser.java @@ -1941,7 +1941,11 @@ private Node parseTypeExpressionAnnotation(JsDocToken token) { if (typeNode != null) { skipEOLs(); if (!match(JsDocToken.RIGHT_CURLY)) { - reportTypeSyntaxWarning("msg.jsdoc.missing.rc"); + if (typeNode.isString() && typeNode.getString() == "import") { + reportTypeSyntaxWarning("msg.jsdoc.import"); + } else { + reportTypeSyntaxWarning("msg.jsdoc.missing.rc"); + } } else { next(); } diff --git a/src/com/google/javascript/rhino/Messages.properties b/src/com/google/javascript/rhino/Messages.properties index b66ec1fed95..3bf7c9cd290 100644 --- a/src/com/google/javascript/rhino/Messages.properties +++ b/src/com/google/javascript/rhino/Messages.properties @@ -351,3 +351,6 @@ msg.jsdoc.typetransformation.extra.param =\ msg.jsdoc.typetransformation.invalid.inside =\ Invalid expression inside {0} + +msg.jsdoc.import =\ + Import in typedef is not supported. diff --git a/test/com/google/javascript/jscomp/parsing/JsDocInfoParserTest.java b/test/com/google/javascript/jscomp/parsing/JsDocInfoParserTest.java index 4b55c67ae85..2e7539d4007 100644 --- a/test/com/google/javascript/jscomp/parsing/JsDocInfoParserTest.java +++ b/test/com/google/javascript/jscomp/parsing/JsDocInfoParserTest.java @@ -691,6 +691,13 @@ public void testMalformedThisAnnotation() { "Bad type annotation. type not recognized due to syntax error." + BAD_TYPE_WIKI_LINK); } + @Test + public void testParseImportTypeError() { + parse( + "@type {import('http').Stream} */", + "Bad type annotation. Import in typedef is not supported." + BAD_TYPE_WIKI_LINK); + } + @Test public void testParseFunctionalTypeError1() { parse(