Fix crash on non-dts-require (#19980)
This commit is contained in:
parent
3d602936e0
commit
7d93434f2c
|
@ -17179,7 +17179,7 @@ namespace ts {
|
|||
if (targetDeclarationKind !== SyntaxKind.Unknown) {
|
||||
const decl = getDeclarationOfKind(resolvedRequire, targetDeclarationKind);
|
||||
// function/variable declaration should be ambient
|
||||
return !!(decl.flags & NodeFlags.Ambient);
|
||||
return !!decl && !!(decl.flags & NodeFlags.Ambient);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
11
tests/baselines/reference/noCrashOnParameterNamedRequire.js
Normal file
11
tests/baselines/reference/noCrashOnParameterNamedRequire.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
//// [index.js]
|
||||
(function(require, module, exports){
|
||||
const mod = require("./mod");
|
||||
mod.foo;
|
||||
})(null, null, null);
|
||||
|
||||
//// [index.js]
|
||||
(function (require, module, exports) {
|
||||
var mod = require("./mod");
|
||||
mod.foo;
|
||||
})(null, null, null);
|
|
@ -0,0 +1,14 @@
|
|||
=== tests/cases/compiler/index.js ===
|
||||
(function(require, module, exports){
|
||||
>require : Symbol(require, Decl(index.js, 0, 10))
|
||||
>module : Symbol(module, Decl(index.js, 0, 18))
|
||||
>exports : Symbol(exports, Decl(index.js, 0, 26))
|
||||
|
||||
const mod = require("./mod");
|
||||
>mod : Symbol(mod, Decl(index.js, 1, 9))
|
||||
>require : Symbol(require, Decl(index.js, 0, 10))
|
||||
|
||||
mod.foo;
|
||||
>mod : Symbol(mod, Decl(index.js, 1, 9))
|
||||
|
||||
})(null, null, null);
|
|
@ -0,0 +1,25 @@
|
|||
=== tests/cases/compiler/index.js ===
|
||||
(function(require, module, exports){
|
||||
>(function(require, module, exports){ const mod = require("./mod"); mod.foo;})(null, null, null) : void
|
||||
>(function(require, module, exports){ const mod = require("./mod"); mod.foo;}) : (require: any, module: any, exports: any) => void
|
||||
>function(require, module, exports){ const mod = require("./mod"); mod.foo;} : (require: any, module: any, exports: any) => void
|
||||
>require : any
|
||||
>module : any
|
||||
>exports : any
|
||||
|
||||
const mod = require("./mod");
|
||||
>mod : any
|
||||
>require("./mod") : any
|
||||
>require : any
|
||||
>"./mod" : "./mod"
|
||||
|
||||
mod.foo;
|
||||
>mod.foo : any
|
||||
>mod : any
|
||||
>foo : any
|
||||
|
||||
})(null, null, null);
|
||||
>null : null
|
||||
>null : null
|
||||
>null : null
|
||||
|
8
tests/cases/compiler/noCrashOnParameterNamedRequire.ts
Normal file
8
tests/cases/compiler/noCrashOnParameterNamedRequire.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @outDir: ./built
|
||||
// @filename: index.js
|
||||
(function(require, module, exports){
|
||||
const mod = require("./mod");
|
||||
mod.foo;
|
||||
})(null, null, null);
|
Loading…
Reference in a new issue