Skip to content

Commit 090eb20

Browse files
committed
Merge pull request #5827 from Microsoft/shebangBeforeReferences
ignore all trivia except singleline comments when processing triplesl…
2 parents 2f282a7 + 9552d4d commit 090eb20

File tree

5 files changed

+89
-4
lines changed

5 files changed

+89
-4
lines changed

src/compiler/parser.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5428,11 +5428,13 @@ namespace ts {
54285428
// reference comment.
54295429
while (true) {
54305430
const kind = triviaScanner.scan();
5431-
if (kind === SyntaxKind.WhitespaceTrivia || kind === SyntaxKind.NewLineTrivia || kind === SyntaxKind.MultiLineCommentTrivia) {
5432-
continue;
5433-
}
54345431
if (kind !== SyntaxKind.SingleLineCommentTrivia) {
5435-
break;
5432+
if (isTrivia(kind)) {
5433+
continue;
5434+
}
5435+
else {
5436+
break;
5437+
}
54365438
}
54375439

54385440
const range = { pos: triviaScanner.getTokenPos(), end: triviaScanner.getTextPos(), kind: triviaScanner.getToken() };
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [tests/cases/compiler/shebangBeforeReferences.ts] ////
2+
3+
//// [f.d.ts]
4+
5+
declare module "test" {
6+
let x: number;
7+
}
8+
9+
//// [f.ts]
10+
#!/usr/bin/env node
11+
12+
/// <reference path="f.d.ts"/>
13+
14+
declare function use(f: number): void;
15+
import {x} from "test";
16+
use(x);
17+
18+
//// [f.js]
19+
#!/usr/bin/env node"use strict";
20+
var test_1 = require("test");
21+
use(test_1.x);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/compiler/f.ts ===
2+
#!/usr/bin/env node
3+
4+
/// <reference path="f.d.ts"/>
5+
6+
declare function use(f: number): void;
7+
>use : Symbol(use, Decl(f.ts, 0, 0))
8+
>f : Symbol(f, Decl(f.ts, 4, 21))
9+
10+
import {x} from "test";
11+
>x : Symbol(x, Decl(f.ts, 5, 8))
12+
13+
use(x);
14+
>use : Symbol(use, Decl(f.ts, 0, 0))
15+
>x : Symbol(x, Decl(f.ts, 5, 8))
16+
17+
=== tests/cases/compiler/f.d.ts ===
18+
19+
declare module "test" {
20+
let x: number;
21+
>x : Symbol(x, Decl(f.d.ts, 2, 7))
22+
}
23+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/compiler/f.ts ===
2+
#!/usr/bin/env node
3+
4+
/// <reference path="f.d.ts"/>
5+
6+
declare function use(f: number): void;
7+
>use : (f: number) => void
8+
>f : number
9+
10+
import {x} from "test";
11+
>x : number
12+
13+
use(x);
14+
>use(x) : void
15+
>use : (f: number) => void
16+
>x : number
17+
18+
=== tests/cases/compiler/f.d.ts ===
19+
20+
declare module "test" {
21+
let x: number;
22+
>x : number
23+
}
24+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @module: commonjs
2+
3+
// @filename: f.d.ts
4+
declare module "test" {
5+
let x: number;
6+
}
7+
8+
// @filename: f.ts
9+
#!/usr/bin/env node
10+
11+
/// <reference path="f.d.ts"/>
12+
13+
declare function use(f: number): void;
14+
import {x} from "test";
15+
use(x);

0 commit comments

Comments
 (0)