FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Cherry-pick #58966 to release-5.5 by jakebailey · Pull Request #59002 · microsoft/TypeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .symbols  (1) .ts  (4) .txt  (1) .types  (1) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4590,7 +4590,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
if (moduleResolutionKind === ModuleResolutionKind.Node16 || moduleResolutionKind === ModuleResolutionKind.NodeNext) {
const isSyncImport = (currentSourceFile.impliedNodeFormat === ModuleKind.CommonJS && !findAncestor(location, isImportCall)) || !!findAncestor(location, isImportEqualsDeclaration);
const overrideHost = findAncestor(location, l => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l)) as ImportTypeNode | ImportDeclaration | ExportDeclaration | undefined;
const overrideHost = findAncestor(location, l => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l) || isJSDocImportTag(l)) as ImportTypeNode | ImportDeclaration | ExportDeclaration | JSDocImportTag | undefined;
// An override clause will take effect for type-only imports and import types, and allows importing the types across formats, regardless of
// normal mode restrictions
if (isSyncImport && sourceFile.impliedNodeFormat === ModuleKind.ESNext && !hasResolutionModeOverride(overrideHost)) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ export function getModeForUsageLocation(file: { impliedNodeFormat?: ResolutionMo
}

function getModeForUsageLocationWorker(file: { impliedNodeFormat?: ResolutionMode; }, usage: StringLiteralLike, compilerOptions?: CompilerOptions) {
if ((isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent))) {
if (isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent) || isJSDocImportTag(usage.parent)) {
const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent);
if (isTypeOnly) {
const override = getResolutionModeOverride(usage.parent.attributes);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10850,7 +10850,7 @@ export function isExpandoPropertyDeclaration(declaration: Declaration | undefine
}

/** @internal */
export function hasResolutionModeOverride(node: ImportTypeNode | ImportDeclaration | ExportDeclaration | undefined) {
export function hasResolutionModeOverride(node: ImportTypeNode | ImportDeclaration | ExportDeclaration | JSDocImportTag | undefined) {
if (node === undefined) {
return false;
}
Expand Down
44 changes: 44 additions & 0 deletions tests/baselines/reference/importTag17.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/a.js(8,5): error TS2322: Type '1' is not assignable to type '"module"'.
/a.js(15,5): error TS2322: Type '1' is not assignable to type '"script"'.


==== /node_modules/@types/foo/package.json (0 errors) ====
{
"name": "@types/foo",
"version": "1.0.0",
"exports": {
".": {
"import": "./index.d.mts",
"require": "./index.d.cts"
}
}
}

==== /node_modules/@types/foo/index.d.mts (0 errors) ====
export declare const Import: "module";

==== /node_modules/@types/foo/index.d.cts (0 errors) ====
export declare const Require: "script";

==== /a.js (2 errors) ====
/** @import { Import } from 'foo' with { 'resolution-mode': 'import' } */
/** @import { Require } from 'foo' with { 'resolution-mode': 'require' } */

/**
* @returns { Import }
*/
export function f1() {
return 1;
~~~~~~
!!! error TS2322: Type '1' is not assignable to type '"module"'.
}

/**
* @returns { Require }
*/
export function f2() {
return 1;
~~~~~~
!!! error TS2322: Type '1' is not assignable to type '"script"'.
}

32 changes: 32 additions & 0 deletions tests/baselines/reference/importTag17.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//// [tests/cases/conformance/jsdoc/importTag17.ts] ////

=== /node_modules/@types/foo/index.d.mts ===
export declare const Import: "module";
>Import : Symbol(Import, Decl(index.d.mts, 0, 20))

=== /node_modules/@types/foo/index.d.cts ===
export declare const Require: "script";
>Require : Symbol(Require, Decl(index.d.cts, 0, 20))

=== /a.js ===
/** @import { Import } from 'foo' with { 'resolution-mode': 'import' } */
/** @import { Require } from 'foo' with { 'resolution-mode': 'require' } */

/**
* @returns { Import }
*/
export function f1() {
>f1 : Symbol(f1, Decl(a.js, 0, 0))

return 1;
}

/**
* @returns { Require }
*/
export function f2() {
>f2 : Symbol(f2, Decl(a.js, 8, 1))

return 1;
}

40 changes: 40 additions & 0 deletions tests/baselines/reference/importTag17.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//// [tests/cases/conformance/jsdoc/importTag17.ts] ////

=== /node_modules/@types/foo/index.d.mts ===
export declare const Import: "module";
>Import : "module"
> : ^^^^^^^^

=== /node_modules/@types/foo/index.d.cts ===
export declare const Require: "script";
>Require : "script"
> : ^^^^^^^^

=== /a.js ===
/** @import { Import } from 'foo' with { 'resolution-mode': 'import' } */
/** @import { Require } from 'foo' with { 'resolution-mode': 'require' } */

/**
* @returns { Import }
*/
export function f1() {
>f1 : () => "module"
> : ^^^^^^^^^^^^^^

return 1;
>1 : 1
> : ^
}

/**
* @returns { Require }
*/
export function f2() {
>f2 : () => "script"
> : ^^^^^^^^^^^^^^

return 1;
>1 : 1
> : ^
}

40 changes: 40 additions & 0 deletions tests/cases/conformance/jsdoc/importTag17.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @module: node16
// @checkJs: true
// @allowJs: true
// @noEmit: true

// @Filename: /node_modules/@types/foo/package.json
{
"name": "@types/foo",
"version": "1.0.0",
"exports": {
".": {
"import": "./index.d.mts",
"require": "./index.d.cts"
}
}
}

// @Filename: /node_modules/@types/foo/index.d.mts
export declare const Import: "module";

// @Filename: /node_modules/@types/foo/index.d.cts
export declare const Require: "script";

// @Filename: /a.js
/** @import { Import } from 'foo' with { 'resolution-mode': 'import' } */
/** @import { Require } from 'foo' with { 'resolution-mode': 'require' } */

/**
* @returns { Import }
*/
export function f1() {
return 1;
}

/**
* @returns { Require }
*/
export function f2() {
return 1;
}

Back | FazBrowse Home | New Git URL