File tree 6 files changed +26
-2
lines changed
src/com/google/javascript
test/com/google/javascript/jscomp/parsing
6 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,7 @@ public static DiagnosticGroup forName(String name) {
228
228
"nonStandardJsDocs" ,
229
229
RhinoErrorReporter .BAD_JSDOC_ANNOTATION ,
230
230
RhinoErrorReporter .INVALID_PARAM ,
231
+ RhinoErrorReporter .JSDOC_IMPORT_TYPE_WARNING ,
231
232
CheckJSDoc .JSDOC_IN_BLOCK_COMMENT );
232
233
233
234
public static final DiagnosticGroup INVALID_CASTS =
Original file line number Diff line number Diff line change @@ -48,6 +48,10 @@ class RhinoErrorReporter {
48
48
static final DiagnosticType JSDOC_MISSING_TYPE_WARNING =
49
49
DiagnosticType .disabled ("JSC_JSDOC_MISSING_TYPE_WARNING" , "{0}" );
50
50
51
+ // Import is supported by VSCode and is pretty much a standard now.
52
+ static final DiagnosticType JSDOC_IMPORT_TYPE_WARNING =
53
+ DiagnosticType .disabled ("JSC_JSDOC_IMPORT_TYPE_WARNING" , "{0}" );
54
+
51
55
static final DiagnosticType TOO_MANY_TEMPLATE_PARAMS =
52
56
DiagnosticType .disabled ("JSC_TOO_MANY_TEMPLATE_PARAMS" , "{0}" );
53
57
@@ -153,6 +157,11 @@ private RhinoErrorReporter(AbstractCompiler compiler) {
153
157
// Unresolved types that aren't forward declared.
154
158
.put (Pattern .compile (".*Unknown type.*" ), UNRECOGNIZED_TYPE_ERROR )
155
159
160
+ // Import annotation errors.
161
+ .put (
162
+ Pattern .compile ("^Bad type annotation. Import in typedef.*" ),
163
+ JSDOC_IMPORT_TYPE_WARNING )
164
+
156
165
// Type annotation errors.
157
166
.put (Pattern .compile ("^Bad type annotation.*" ), TYPE_PARSE_ERROR )
158
167
Original file line number Diff line number Diff line change @@ -1939,7 +1939,11 @@ private Node parseTypeExpressionAnnotation(JsDocToken token) {
1939
1939
if (typeNode != null ) {
1940
1940
skipEOLs ();
1941
1941
if (!match (JsDocToken .RIGHT_CURLY )) {
1942
- reportTypeSyntaxWarning ("msg.jsdoc.missing.rc" );
1942
+ if (typeNode .isString () && "import" .equals (typeNode .getString ())) {
1943
+ reportTypeSyntaxWarning ("msg.jsdoc.import" );
1944
+ } else {
1945
+ reportTypeSyntaxWarning ("msg.jsdoc.missing.rc" );
1946
+ }
1943
1947
} else {
1944
1948
next ();
1945
1949
}
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change @@ -351,3 +351,6 @@ msg.jsdoc.typetransformation.extra.param =\
351
351
352
352
msg.jsdoc.typetransformation.invalid.inside =\
353
353
Invalid expression inside {0}
354
+
355
+ msg.jsdoc.import =\
356
+ Import in typedef is not supported.
Original file line number Diff line number Diff line change @@ -691,6 +691,13 @@ public void testMalformedThisAnnotation() {
691
691
"Bad type annotation. type not recognized due to syntax error." + BAD_TYPE_WIKI_LINK );
692
692
}
693
693
694
+ @ Test
695
+ public void testParseImportTypeError () {
696
+ parse (
697
+ "@type {import('http').Stream} */" ,
698
+ "Bad type annotation. Import in typedef is not supported." + BAD_TYPE_WIKI_LINK );
699
+ }
700
+
694
701
@ Test
695
702
public void testParseFunctionalTypeError1 () {
696
703
parse (
You can’t perform that action at this time.
0 commit comments