Skip to content

Commit f046728

Browse files
authored
Fixed completion crashes related to JSDocImportTag (microsoft#59527)
1 parent 2937728 commit f046728

8 files changed

+154
-1
lines changed

src/compiler/binder.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1191,10 +1191,10 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
11911191
case SyntaxKind.JSDocEnumTag:
11921192
bindJSDocTypeAlias(node as JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag);
11931193
break;
1194-
// In source files and blocks, bind functions first to match hoisting that occurs at runtime
11951194
case SyntaxKind.JSDocImportTag:
11961195
bindJSDocImportTag(node as JSDocImportTag);
11971196
break;
1197+
// In source files and blocks, bind functions first to match hoisting that occurs at runtime
11981198
case SyntaxKind.SourceFile: {
11991199
bindEachFunctionsFirst((node as SourceFile).statements);
12001200
bind((node as SourceFile).endOfFileToken);
@@ -2105,7 +2105,10 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
21052105
}
21062106

21072107
function bindJSDocImportTag(node: JSDocImportTag) {
2108+
// don't bind the importClause yet; that's delayed until bindJSDocImports
21082109
bind(node.tagName);
2110+
bind(node.moduleSpecifier);
2111+
bind(node.attributes);
21092112

21102113
if (typeof node.comment !== "string") {
21112114
bindEach(node.comment);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @strict: true
4+
5+
// @filename: global.d.ts
6+
//// interface ImportAttributes {
7+
//// type: "json";
8+
//// }
9+
10+
// @filename: index.ts
11+
//// import * as ns from "" with { type: "/**/" };
12+
13+
verify.completions({
14+
marker: "",
15+
exact: ["json"],
16+
isNewIdentifierLocation: false,
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @strict: true
4+
5+
// @filename: global.d.ts
6+
//// interface ImportAttributes {
7+
//// type: "json";
8+
//// }
9+
10+
// @filename: index.ts
11+
//// import * as ns from () with { type: "/**/" };
12+
13+
verify.completions({
14+
marker: "",
15+
exact: ["json"],
16+
isNewIdentifierLocation: false,
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @strict: true
4+
// @checkJs: true
5+
// @allowJs: true
6+
7+
// @filename: global.d.ts
8+
//// interface ImportAttributes {
9+
//// type: "json";
10+
//// }
11+
12+
// @filename: index.js
13+
//// /** @import * as ns from "" with { type: "/**/" } */
14+
15+
verify.completions({
16+
marker: "",
17+
exact: ["json"],
18+
isNewIdentifierLocation: false,
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @strict: true
4+
// @checkJs: true
5+
// @allowJs: true
6+
7+
// @filename: global.d.ts
8+
//// interface ImportAttributes {
9+
//// type: "json";
10+
//// }
11+
12+
// @filename: index.js
13+
//// /** @import * as ns from () with { type: "/**/" } */
14+
15+
verify.completions({
16+
marker: "",
17+
exact: ["json"],
18+
isNewIdentifierLocation: false,
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @strict: true
4+
// @checkJs: true
5+
// @allowJs: true
6+
// @moduleResolution: nodenext
7+
8+
// @filename: node_modules/pkg/index.d.ts
9+
//// export type MyUnion = string | number;
10+
11+
// @filename: index.js
12+
//// /** @import { MyUnion } from "/**/" */
13+
14+
verify.completions({
15+
marker: "",
16+
exact: ["pkg"],
17+
isNewIdentifierLocation: true,
18+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @strict: true
4+
// @checkJs: true
5+
// @allowJs: true
6+
7+
// @filename: index.js
8+
//// /**
9+
//// * @example
10+
//// <file name="glyphicons.css">
11+
//// @import url(//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css);
12+
//// </file>
13+
//// <example module="ngAnimate" deps="angular-animate.js" animations="true">
14+
//// <file name="animations.css">
15+
//// .animate-show.ng-hide-add.ng-hide-add-active,
16+
//// .animate-show.ng-hide-remove.ng-hide-remove-active {
17+
//// transition:all linear 0./**/5s;
18+
//// }
19+
//// </file>
20+
//// </example>
21+
//// */
22+
//// var ngShowDirective = ['$animate', function($animate) {}];
23+
24+
verify.completions({
25+
marker: "",
26+
includes: ["url"],
27+
isNewIdentifierLocation: true,
28+
preferences: {
29+
includeCompletionsWithInsertText: true
30+
}
31+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @strict: true
4+
5+
// @filename: index.ts
6+
//// /**
7+
//// * @example
8+
//// <file name="glyphicons.css">
9+
//// @import url(//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css);
10+
//// </file>
11+
//// <example module="ngAnimate" deps="angular-animate.js" animations="true">
12+
//// <file name="animations.css">
13+
//// .animate-show.ng-hide-add.ng-hide-add-active,
14+
//// .animate-show.ng-hide-remove.ng-hide-remove-active {
15+
//// transition:all linear 0./**/5s;
16+
//// }
17+
//// </file>
18+
//// </example>
19+
//// */
20+
//// var ngShowDirective = ['$animate', function($animate) {}];
21+
22+
verify.completions({
23+
marker: "",
24+
exact: completion.globalTypes,
25+
isNewIdentifierLocation: false,
26+
preferences: {
27+
includeCompletionsWithInsertText: true
28+
}
29+
});

0 commit comments

Comments
 (0)