Skip to content

Allow to suppress import in typedef JSDoc parse error. #3323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/com/google/javascript/jscomp/DiagnosticGroups.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
7 changes: 7 additions & 0 deletions src/com/google/javascript/jscomp/RhinoErrorReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}");

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions src/com/google/javascript/rhino/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down