--moduleResoltuion bunlder: Allow import assignment in ambient contexts (#51971)

This commit is contained in:
Andrew Branch 2022-12-19 17:03:50 -08:00 committed by GitHub
parent 5951ee9cff
commit 714d7341cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 1 deletions

View File

@ -42778,7 +42778,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// Import equals declaration is deprecated in es6 or above
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
}
else if (getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Bundler) {
else if (!(node.flags & NodeFlags.Ambient) && getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Bundler) {
grammarErrorOnNode(node, Diagnostics.Import_assignment_is_not_allowed_when_moduleResolution_is_set_to_bundler_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
}
}

View File

@ -8,6 +8,18 @@ error TS2468: Cannot find global value 'Promise'.
==== /node_modules/@types/node/index.d.ts (0 errors) ====
declare var require: (...args: any[]) => any;
==== /ambient.d.ts (0 errors) ====
declare module "fs" {
export function readFileSync(path: string, encoding?: string): string;
}
declare module "path" {
import fs = require("fs"); // ok
namespace path {
export const sep: string;
}
export = path; // ok
}
==== /mainJs.js (1 errors) ====
import {} from "./a";
import("./a");

View File

@ -3,6 +3,18 @@
//// [index.d.ts]
declare var require: (...args: any[]) => any;
//// [ambient.d.ts]
declare module "fs" {
export function readFileSync(path: string, encoding?: string): string;
}
declare module "path" {
import fs = require("fs"); // ok
namespace path {
export const sep: string;
}
export = path; // ok
}
//// [mainJs.js]
import {} from "./a";
import("./a");

View File

@ -3,6 +3,31 @@ declare var require: (...args: any[]) => any;
>require : Symbol(require, Decl(index.d.ts, 0, 11))
>args : Symbol(args, Decl(index.d.ts, 0, 22))
=== /ambient.d.ts ===
declare module "fs" {
>"fs" : Symbol("fs", Decl(ambient.d.ts, 0, 0))
export function readFileSync(path: string, encoding?: string): string;
>readFileSync : Symbol(readFileSync, Decl(ambient.d.ts, 0, 21))
>path : Symbol(path, Decl(ambient.d.ts, 1, 33))
>encoding : Symbol(encoding, Decl(ambient.d.ts, 1, 46))
}
declare module "path" {
>"path" : Symbol("path", Decl(ambient.d.ts, 2, 1))
import fs = require("fs"); // ok
>fs : Symbol(fs, Decl(ambient.d.ts, 3, 23))
namespace path {
>path : Symbol(path, Decl(ambient.d.ts, 4, 30))
export const sep: string;
>sep : Symbol(sep, Decl(ambient.d.ts, 6, 20))
}
export = path; // ok
>path : Symbol(path, Decl(ambient.d.ts, 4, 30))
}
=== /mainJs.js ===
import {} from "./a";
import("./a");

View File

@ -3,6 +3,31 @@ declare var require: (...args: any[]) => any;
>require : (...args: any[]) => any
>args : any[]
=== /ambient.d.ts ===
declare module "fs" {
>"fs" : typeof import("fs")
export function readFileSync(path: string, encoding?: string): string;
>readFileSync : (path: string, encoding?: string) => string
>path : string
>encoding : string
}
declare module "path" {
>"path" : typeof import("path")
import fs = require("fs"); // ok
>fs : typeof fs
namespace path {
>path : typeof path
export const sep: string;
>sep : string
}
export = path; // ok
>path : typeof path
}
=== /mainJs.js ===
import {} from "./a";
import("./a");

View File

@ -6,6 +6,18 @@
// @Filename: /node_modules/@types/node/index.d.ts
declare var require: (...args: any[]) => any;
// @Filename: /ambient.d.ts
declare module "fs" {
export function readFileSync(path: string, encoding?: string): string;
}
declare module "path" {
import fs = require("fs"); // ok
namespace path {
export const sep: string;
}
export = path; // ok
}
// @Filename: /mainJs.js
import {} from "./a";
import("./a");