Fix crash on non-dts-require (#19980)

This commit is contained in:
Wesley Wigham 2017-11-13 16:41:29 -08:00 committed by GitHub
parent 3d602936e0
commit 7d93434f2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 1 deletions

View file

@ -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;
}

View 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);

View file

@ -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);

View file

@ -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

View 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);