Skip to content
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

🤖 Pick PR #59026 (fix(59011): TypeScript generates in...) into release-5.5 #59039

Merged
merged 1 commit into from
Jul 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2637,7 +2637,7 @@ namespace Parser {
function createIdentifier(isIdentifier: boolean, diagnosticMessage?: DiagnosticMessage, privateIdentifierDiagnosticMessage?: DiagnosticMessage): Identifier {
if (isIdentifier) {
identifierCount++;
const pos = getNodePos();
const pos = scanner.hasLeadingAsterisks() ? scanner.getTokenStart() : getNodePos();
// Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker
const originalKeywordKind = token();
const text = internIdentifier(scanner.getTokenValue());
Expand Down
10 changes: 9 additions & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export interface Scanner {
resetTokenState(pos: number): void;
/** @internal */
setSkipJsDocLeadingAsterisks(skip: boolean): void;
/** @internal */
hasLeadingAsterisks(): boolean;
// Invokes the provided callback then unconditionally restores the scanner to the state it
// was in immediately prior to invoking the callback. The result of invoking the callback
// is returned from this function.
Expand Down Expand Up @@ -1042,6 +1044,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean

var commentDirectives: CommentDirective[] | undefined;
var skipJsDocLeadingAsterisks = 0;
var asteriskSeen = false;

var scriptKind = ScriptKind.Unknown;
var jsDocParsingMode = JSDocParsingMode.ParseAll;
Expand Down Expand Up @@ -1096,6 +1099,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
resetTokenState,
setTextPos: resetTokenState,
setSkipJsDocLeadingAsterisks,
hasLeadingAsterisks,
tryScan,
lookAhead,
scanRange,
Expand Down Expand Up @@ -1877,7 +1881,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
function scan(): SyntaxKind {
fullStartPos = pos;
tokenFlags = TokenFlags.None;
let asteriskSeen = false;
asteriskSeen = false;
while (true) {
tokenStart = pos;
if (pos >= end) {
Expand Down Expand Up @@ -4004,6 +4008,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
function setSkipJsDocLeadingAsterisks(skip: boolean) {
skipJsDocLeadingAsterisks += skip ? 1 : -1;
}

function hasLeadingAsterisks() {
return asteriskSeen;
}
}

function codePointAt(s: string, i: number): number {
Expand Down
34 changes: 34 additions & 0 deletions tests/baselines/reference/importTag18.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//// [tests/cases/conformance/jsdoc/importTag18.ts] ////

//// [a.ts]
export interface Foo {}

//// [b.js]
/**
* @import {
* Foo
* } from "./a"
*/

/**
* @param {Foo} a
*/
export function foo(a) {}




//// [a.d.ts]
export interface Foo {
}
//// [b.d.ts]
/**
* @import {
* Foo
* } from "./a"
*/
/**
* @param {Foo} a
*/
export function foo(a: Foo): void;
import type { Foo } from "./a";
20 changes: 20 additions & 0 deletions tests/baselines/reference/importTag18.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//// [tests/cases/conformance/jsdoc/importTag18.ts] ////

=== a.ts ===
export interface Foo {}
>Foo : Symbol(Foo, Decl(a.ts, 0, 0))

=== b.js ===
/**
* @import {
* Foo
* } from "./a"
*/

/**
* @param {Foo} a
*/
export function foo(a) {}
>foo : Symbol(foo, Decl(b.js, 0, 0))
>a : Symbol(a, Decl(b.js, 9, 20))

22 changes: 22 additions & 0 deletions tests/baselines/reference/importTag18.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//// [tests/cases/conformance/jsdoc/importTag18.ts] ////

=== a.ts ===

export interface Foo {}

=== b.js ===
/**
* @import {
* Foo
* } from "./a"
*/

/**
* @param {Foo} a
*/
export function foo(a) {}
>foo : (a: Foo) => void
> : ^ ^^^^^^^^^^^^^^
>a : Foo
> : ^^^

12 changes: 6 additions & 6 deletions tests/baselines/reference/importTag6.types
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export interface B {
* @param { B } b
*/
function f(a, b) {}
>f : (a: * A, b: * B) => void
> : ^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>a : * A
> : ^^^^^^^
>b : * B
> : ^^^^^^^
>f : (a: A, b: B) => void
> : ^ ^^^^^ ^^^^^^^^^^^^
>a : A
> : ^
>b : B
> : ^

12 changes: 6 additions & 6 deletions tests/baselines/reference/importTag7.types
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export interface B {
* @param { B } b
*/
function f(a, b) {}
>f : (a: * A, b: * B) => void
> : ^ ^^^^^^^ ^^^^^^^^^^^^^^
>a : * A
> : ^^^
>b : * B
> : ^^^
>f : (a: A, b: B) => void
> : ^ ^^^^^ ^^^^^^^^^^^^
>a : A
> : ^
>b : B
> : ^

19 changes: 19 additions & 0 deletions tests/cases/conformance/jsdoc/importTag18.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @declaration: true
// @emitDeclarationOnly: true
// @checkJs: true
// @allowJs: true

// @filename: a.ts
export interface Foo {}

// @filename: b.js
/**
* @import {
* Foo
* } from "./a"
*/

/**
* @param {Foo} a
*/
export function foo(a) {}