fix(48081): omit error on importing variables defined with require() (#48115)

This commit is contained in:
Oleksandr T 2022-03-14 18:55:12 +02:00 committed by GitHub
parent ca65a1a05b
commit 4a58fbce17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 1 deletions

View File

@ -3288,7 +3288,7 @@ namespace ts {
}
if (!isBindingPattern(node.name)) {
if (isInJSFile(node) && isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !getJSDocTypeTag(node)) {
if (isInJSFile(node) && isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !getJSDocTypeTag(node) && !(getCombinedModifierFlags(node) & ModifierFlags.Export)) {
declareSymbolAndAddToSymbolTable(node as Declaration, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
}
else if (isBlockOrCatchScoped(node)) {

View File

@ -0,0 +1,16 @@
=== /node_modules/foo/src/index.js ===
module.exports = 1;
>module.exports : Symbol(module.exports, Decl(index.js, 0, 0))
>module : Symbol(export=, Decl(index.js, 0, 0))
>exports : Symbol(export=, Decl(index.js, 0, 0))
=== /a.js ===
export const A = require("foo");
>A : Symbol(A, Decl(a.js, 0, 12))
>require : Symbol(require)
>"foo" : Symbol("/node_modules/foo/src/index", Decl(index.js, 0, 0))
=== /b.ts ===
import { A } from "./a";
>A : Symbol(A, Decl(b.ts, 0, 8))

View File

@ -0,0 +1,19 @@
=== /node_modules/foo/src/index.js ===
module.exports = 1;
>module.exports = 1 : number
>module.exports : number
>module : { exports: number; }
>exports : number
>1 : 1
=== /a.js ===
export const A = require("foo");
>A : number
>require("foo") : number
>require : any
>"foo" : "foo"
=== /b.ts ===
import { A } from "./a";
>A : number

View File

@ -0,0 +1,18 @@
// @esModuleInterop: true
// @moduleResolution: node
// @module: es2015
// @checkJs: true
// @allowJs: true
// @noEmit: true
// @Filename: /node_modules/foo/package.json
{ "name": "foo", "version": "1.2.3", "main": "src/index.js" }
// @Filename: /node_modules/foo/src/index.js
module.exports = 1;
// @filename: /a.js
export const A = require("foo");
// @filename: /b.ts
import { A } from "./a";