No error for require, module.exports or exports in Javascript (#23743)

* No error for require

Still errors for module and exports, and require's type is now
incorreclty 'any'; I broke module resolution somehow. Needs
investigation.

* module/exports symbols+update isCommonJsRequire

Everything passes the tests but the code can be improved

* Update baselines

* Cleanup

* Update baselines of new tests

* Get rid of exports symbol

It wasn't doing anything anyway.
This commit is contained in:
Nathan Shively-Sanders
2018-04-30 15:47:59 -07:00
committed by GitHub
parent 5c8bb7c985
commit 5ea4d3b2bb
21 changed files with 90 additions and 214 deletions

View File

@@ -75,6 +75,8 @@ namespace ts {
const undefinedSymbol = createSymbol(SymbolFlags.Property, "undefined" as __String);
undefinedSymbol.declarations = [];
const argumentsSymbol = createSymbol(SymbolFlags.Property, "arguments" as __String);
const requireSymbol = createSymbol(SymbolFlags.Property, "require" as __String);
const moduleSymbol = createSymbol(SymbolFlags.Property, "module" as __String);
/** This will be set during calls to `getResolvedSignature` where services determines an apparent number of arguments greater than what is actually provided. */
let apparentArgumentCount: number | undefined;
@@ -1470,7 +1472,17 @@ namespace ts {
result = lookup(globals, name, meaning);
}
}
if (!result) {
if (originalLocation && isInJavaScriptFile(originalLocation) && originalLocation.parent) {
if (isRequireCall(originalLocation.parent, /*checkArgumentIsStringLiteralLike*/ false)) {
return requireSymbol;
}
if (isIdentifier(originalLocation) && isPropertyAccessExpression(originalLocation.parent) &&
originalLocation.escapedText === "module" && originalLocation.parent.name.escapedText === "exports") {
return moduleSymbol;
}
}
}
if (!result) {
if (nameNotFoundMessage) {
if (!errorLocation ||
@@ -4683,6 +4695,10 @@ namespace ts {
if (symbol.flags & SymbolFlags.Prototype) {
return links.type = getTypeOfPrototypeProperty(symbol);
}
// CommonsJS require/module/exports all have type any.
if (symbol === requireSymbol || symbol === moduleSymbol) {
return links.type = anyType;
}
// Handle catch clause variables
const declaration = symbol.valueDeclaration;
if (isCatchClauseVariableDeclarationOrBindingElement(declaration)) {
@@ -18856,11 +18872,10 @@ namespace ts {
// Make sure require is not a local function
if (!isIdentifier(node.expression)) return Debug.fail();
const resolvedRequire = resolveName(node.expression, node.expression.escapedText, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ true);
if (!resolvedRequire) {
// project does not contain symbol named 'require' - assume commonjs require
if (resolvedRequire === requireSymbol) {
return true;
}
// project includes symbol named 'require' - make sure that it it ambient and local non-alias
// project includes symbol named 'require' - make sure that it is ambient and local non-alias
if (resolvedRequire.flags & SymbolFlags.Alias) {
return false;
}

View File

@@ -5,5 +5,6 @@ function foo(name) {
var s = require("t/" + name)
>s : Symbol(s, Decl(a.js, 1, 7))
>require : Symbol(require)
>name : Symbol(name, Decl(a.js, 0, 13))
}

View File

@@ -1,25 +1,19 @@
tests/cases/conformance/salsa/first.js(1,11): error TS2304: Cannot find name 'require'.
tests/cases/conformance/salsa/first.js(2,9): error TS2339: Property 'formatters' does not exist on type 'typeof import("tests/cases/conformance/salsa/first")'.
tests/cases/conformance/salsa/second.js(1,11): error TS2304: Cannot find name 'require'.
tests/cases/conformance/salsa/second.js(2,9): error TS2339: Property 'formatters' does not exist on type 'typeof import("tests/cases/conformance/salsa/second")'.
==== tests/cases/conformance/salsa/mod.js (0 errors) ====
// Based on a pattern from adonis
exports.formatters = {}
==== tests/cases/conformance/salsa/first.js (2 errors) ====
==== tests/cases/conformance/salsa/first.js (1 errors) ====
exports = require('./mod')
~~~~~~~
!!! error TS2304: Cannot find name 'require'.
exports.formatters.j = function (v) {
~~~~~~~~~~
!!! error TS2339: Property 'formatters' does not exist on type 'typeof import("tests/cases/conformance/salsa/first")'.
return v
}
==== tests/cases/conformance/salsa/second.js (2 errors) ====
==== tests/cases/conformance/salsa/second.js (1 errors) ====
exports = require('./mod')
~~~~~~~
!!! error TS2304: Cannot find name 'require'.
exports.formatters.o = function (v) {
~~~~~~~~~~
!!! error TS2339: Property 'formatters' does not exist on type 'typeof import("tests/cases/conformance/salsa/second")'.

View File

@@ -8,6 +8,7 @@ exports.formatters = {}
=== tests/cases/conformance/salsa/first.js ===
exports = require('./mod')
>exports : Symbol("tests/cases/conformance/salsa/first", Decl(first.js, 0, 0))
>require : Symbol(require)
>'./mod' : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
exports.formatters.j = function (v) {
@@ -20,6 +21,7 @@ exports.formatters.j = function (v) {
=== tests/cases/conformance/salsa/second.js ===
exports = require('./mod')
>exports : Symbol("tests/cases/conformance/salsa/second", Decl(second.js, 0, 0))
>require : Symbol(require)
>'./mod' : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
exports.formatters.o = function (v) {

View File

@@ -1,11 +1,8 @@
tests/cases/compiler/a.js(1,15): error TS2304: Cannot find name 'require'.
tests/cases/compiler/a.js(4,1): error TS2686: 'Puppeteer' refers to a UMD global, but the current file is a module. Consider adding an import instead.
==== tests/cases/compiler/a.js (2 errors) ====
==== tests/cases/compiler/a.js (1 errors) ====
const other = require('./other');
~~~~~~~
!!! error TS2304: Cannot find name 'require'.
/** @type {Puppeteer.Keyboard} */
var ppk;
Puppeteer.connect;

View File

@@ -1,6 +1,7 @@
=== tests/cases/compiler/a.js ===
const other = require('./other');
>other : Symbol(other, Decl(a.js, 0, 5))
>require : Symbol(require)
>'./other' : Symbol("tests/cases/compiler/other", Decl(other.d.ts, 0, 0))
/** @type {Puppeteer.Keyboard} */

View File

@@ -1,11 +1,10 @@
tests/cases/conformance/jsdoc/use.js(3,7): error TS2345: Argument of type '"no"' is not assignable to parameter of type 'number'.
tests/cases/conformance/jsdoc/use.js(4,7): error TS2345: Argument of type '"also no"' is not assignable to parameter of type 'number'.
tests/cases/conformance/jsdoc/use.js(5,7): error TS2345: Argument of type '0' is not assignable to parameter of type 'string'.
tests/cases/conformance/jsdoc/use.js(6,7): error TS2345: Argument of type '1' is not assignable to parameter of type 'string'.
tests/cases/conformance/jsdoc/use.js(2,7): error TS2345: Argument of type '"no"' is not assignable to parameter of type 'number'.
tests/cases/conformance/jsdoc/use.js(3,7): error TS2345: Argument of type '"also no"' is not assignable to parameter of type 'number'.
tests/cases/conformance/jsdoc/use.js(4,7): error TS2345: Argument of type '0' is not assignable to parameter of type 'string'.
tests/cases/conformance/jsdoc/use.js(5,7): error TS2345: Argument of type '1' is not assignable to parameter of type 'string'.
==== tests/cases/conformance/jsdoc/use.js (4 errors) ====
/// <reference path='./types.d.ts'/>
var mod = require('./mod');
mod.f('no')
~~~~
@@ -20,13 +19,7 @@ tests/cases/conformance/jsdoc/use.js(6,7): error TS2345: Argument of type '1' is
~
!!! error TS2345: Argument of type '1' is not assignable to parameter of type 'string'.
==== tests/cases/conformance/jsdoc/types.d.ts (0 errors) ====
declare function require(name: string): any;
declare var exports: any;
declare var module: { exports: any };
==== tests/cases/conformance/jsdoc/mod.js (0 errors) ====
/// <reference path='./types.d.ts'/>
/** @param {number} n */
exports.f = exports.g = function fg(n) {
return n + 1

View File

@@ -1,73 +1,56 @@
=== tests/cases/conformance/jsdoc/use.js ===
/// <reference path='./types.d.ts'/>
var mod = require('./mod');
>mod : Symbol(mod, Decl(use.js, 1, 3))
>require : Symbol(require, Decl(types.d.ts, 0, 0))
>mod : Symbol(mod, Decl(use.js, 0, 3))
>require : Symbol(require)
>'./mod' : Symbol("tests/cases/conformance/jsdoc/mod", Decl(mod.js, 0, 0))
mod.f('no')
>mod.f : Symbol(f, Decl(mod.js, 0, 0))
>mod : Symbol(mod, Decl(use.js, 1, 3))
>mod : Symbol(mod, Decl(use.js, 0, 3))
>f : Symbol(f, Decl(mod.js, 0, 0))
mod.g('also no')
>mod.g : Symbol(g, Decl(mod.js, 3, 11))
>mod : Symbol(mod, Decl(use.js, 1, 3))
>g : Symbol(g, Decl(mod.js, 3, 11))
>mod.g : Symbol(g, Decl(mod.js, 1, 11))
>mod : Symbol(mod, Decl(use.js, 0, 3))
>g : Symbol(g, Decl(mod.js, 1, 11))
mod.h(0)
>mod.h : Symbol(h, Decl(mod.js, 5, 1))
>mod : Symbol(mod, Decl(use.js, 1, 3))
>h : Symbol(h, Decl(mod.js, 5, 1))
>mod.h : Symbol(h, Decl(mod.js, 3, 1))
>mod : Symbol(mod, Decl(use.js, 0, 3))
>h : Symbol(h, Decl(mod.js, 3, 1))
mod.i(1)
>mod.i : Symbol(i, Decl(mod.js, 7, 18))
>mod : Symbol(mod, Decl(use.js, 1, 3))
>i : Symbol(i, Decl(mod.js, 7, 18))
=== tests/cases/conformance/jsdoc/types.d.ts ===
declare function require(name: string): any;
>require : Symbol(require, Decl(types.d.ts, 0, 0))
>name : Symbol(name, Decl(types.d.ts, 0, 25))
declare var exports: any;
>exports : Symbol(exports, Decl(types.d.ts, 1, 11))
declare var module: { exports: any };
>module : Symbol(module, Decl(types.d.ts, 2, 11))
>exports : Symbol(exports, Decl(types.d.ts, 2, 21))
>mod.i : Symbol(i, Decl(mod.js, 5, 18))
>mod : Symbol(mod, Decl(use.js, 0, 3))
>i : Symbol(i, Decl(mod.js, 5, 18))
=== tests/cases/conformance/jsdoc/mod.js ===
/// <reference path='./types.d.ts'/>
/** @param {number} n */
exports.f = exports.g = function fg(n) {
>exports.f : Symbol(f, Decl(mod.js, 0, 0))
>exports : Symbol(f, Decl(mod.js, 0, 0))
>f : Symbol(f, Decl(mod.js, 0, 0))
>exports.g : Symbol(g, Decl(mod.js, 3, 11))
>exports : Symbol(g, Decl(mod.js, 3, 11))
>g : Symbol(g, Decl(mod.js, 3, 11))
>fg : Symbol(fg, Decl(mod.js, 3, 23))
>n : Symbol(n, Decl(mod.js, 3, 36))
>exports.g : Symbol(g, Decl(mod.js, 1, 11))
>exports : Symbol(g, Decl(mod.js, 1, 11))
>g : Symbol(g, Decl(mod.js, 1, 11))
>fg : Symbol(fg, Decl(mod.js, 1, 23))
>n : Symbol(n, Decl(mod.js, 1, 36))
return n + 1
>n : Symbol(n, Decl(mod.js, 3, 36))
>n : Symbol(n, Decl(mod.js, 1, 36))
}
/** @param {string} mom */
module.exports.h = module.exports.i = function hi(mom) {
>module.exports : Symbol(h, Decl(mod.js, 5, 1))
>module : Symbol(module, Decl(types.d.ts, 2, 11))
>exports : Symbol(exports, Decl(types.d.ts, 2, 21))
>h : Symbol(h, Decl(mod.js, 5, 1))
>module.exports : Symbol(i, Decl(mod.js, 7, 18))
>module : Symbol(module, Decl(types.d.ts, 2, 11))
>exports : Symbol(exports, Decl(types.d.ts, 2, 21))
>i : Symbol(i, Decl(mod.js, 7, 18))
>hi : Symbol(hi, Decl(mod.js, 7, 37))
>mom : Symbol(mom, Decl(mod.js, 7, 50))
>module.exports : Symbol(h, Decl(mod.js, 3, 1))
>module : Symbol(module)
>h : Symbol(h, Decl(mod.js, 3, 1))
>module.exports : Symbol(i, Decl(mod.js, 5, 18))
>module : Symbol(module)
>i : Symbol(i, Decl(mod.js, 5, 18))
>hi : Symbol(hi, Decl(mod.js, 5, 37))
>mom : Symbol(mom, Decl(mod.js, 5, 50))
return `hi, ${mom}!`;
>mom : Symbol(mom, Decl(mod.js, 7, 50))
>mom : Symbol(mom, Decl(mod.js, 5, 50))
}

View File

@@ -1,9 +1,8 @@
=== tests/cases/conformance/jsdoc/use.js ===
/// <reference path='./types.d.ts'/>
var mod = require('./mod');
>mod : typeof import("tests/cases/conformance/jsdoc/mod")
>require('./mod') : typeof import("tests/cases/conformance/jsdoc/mod")
>require : (name: string) => any
>require : any
>'./mod' : "./mod"
mod.f('no')
@@ -34,21 +33,7 @@ mod.i(1)
>i : (mom: string) => string
>1 : 1
=== tests/cases/conformance/jsdoc/types.d.ts ===
declare function require(name: string): any;
>require : (name: string) => any
>name : string
declare var exports: any;
>exports : any
declare var module: { exports: any };
>module : { exports: any; }
>exports : any
=== tests/cases/conformance/jsdoc/mod.js ===
/// <reference path='./types.d.ts'/>
/** @param {number} n */
exports.f = exports.g = function fg(n) {
>exports.f = exports.g = function fg(n) { return n + 1} : (n: number) => number
@@ -73,13 +58,13 @@ module.exports.h = module.exports.i = function hi(mom) {
>module.exports.h = module.exports.i = function hi(mom) { return `hi, ${mom}!`;} : (mom: string) => string
>module.exports.h : any
>module.exports : any
>module : { exports: any; }
>module : any
>exports : any
>h : any
>module.exports.i = function hi(mom) { return `hi, ${mom}!`;} : (mom: string) => string
>module.exports.i : any
>module.exports : any
>module : { exports: any; }
>module : any
>exports : any
>i : any
>function hi(mom) { return `hi, ${mom}!`;} : (mom: string) => string

View File

@@ -120,23 +120,27 @@ exports.func2 = function () { };
var moduleExportsAlias = module.exports;
>moduleExportsAlias : Symbol(moduleExportsAlias, Decl(b.js, 4, 3))
>module : Symbol(module)
moduleExportsAlias.func3 = function () { };
>moduleExportsAlias : Symbol(moduleExportsAlias, Decl(b.js, 4, 3))
module.exports.func4 = function () { };
>module.exports : Symbol(func4, Decl(b.js, 5, 43))
>module : Symbol(module)
>func4 : Symbol(func4, Decl(b.js, 5, 43))
var multipleDeclarationAlias1 = exports = module.exports;
>multipleDeclarationAlias1 : Symbol(multipleDeclarationAlias1, Decl(b.js, 8, 3))
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
>module : Symbol(module)
multipleDeclarationAlias1.func5 = function () { };
>multipleDeclarationAlias1 : Symbol(multipleDeclarationAlias1, Decl(b.js, 8, 3))
var multipleDeclarationAlias2 = module.exports = exports;
>multipleDeclarationAlias2 : Symbol(multipleDeclarationAlias2, Decl(b.js, 11, 3))
>module : Symbol(module)
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
multipleDeclarationAlias2.func6 = function () { };
@@ -160,12 +164,14 @@ multipleDeclarationAlias3.func7 = function () { };
var multipleDeclarationAlias4 = someOtherVariable = module.exports;
>multipleDeclarationAlias4 : Symbol(multipleDeclarationAlias4, Decl(b.js, 18, 3))
>someOtherVariable : Symbol(someOtherVariable, Decl(b.js, 14, 3))
>module : Symbol(module)
multipleDeclarationAlias4.func8 = function () { };
>multipleDeclarationAlias4 : Symbol(multipleDeclarationAlias4, Decl(b.js, 18, 3))
var multipleDeclarationAlias5 = module.exports = exports = {};
>multipleDeclarationAlias5 : Symbol(multipleDeclarationAlias5, Decl(b.js, 21, 3))
>module : Symbol(module)
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
multipleDeclarationAlias5.func9 = function () { };
@@ -174,12 +180,14 @@ multipleDeclarationAlias5.func9 = function () { };
var multipleDeclarationAlias6 = exports = module.exports = {};
>multipleDeclarationAlias6 : Symbol(multipleDeclarationAlias6, Decl(b.js, 24, 3))
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
>module : Symbol(module)
multipleDeclarationAlias6.func10 = function () { };
>multipleDeclarationAlias6 : Symbol(multipleDeclarationAlias6, Decl(b.js, 24, 3))
exports = module.exports = someOtherVariable = {};
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
>module : Symbol(module)
>someOtherVariable : Symbol(someOtherVariable, Decl(b.js, 14, 3))
exports.func11 = function () { };
@@ -189,10 +197,12 @@ exports.func11 = function () { };
module.exports.func12 = function () { };
>module.exports : Symbol(func12, Decl(b.js, 28, 33), Decl(b.js, 32, 33))
>module : Symbol(module)
>func12 : Symbol(func12, Decl(b.js, 28, 33), Decl(b.js, 32, 33))
exports = module.exports = someOtherVariable = {};
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
>module : Symbol(module)
>someOtherVariable : Symbol(someOtherVariable, Decl(b.js, 14, 3))
exports.func11 = function () { };
@@ -202,10 +212,12 @@ exports.func11 = function () { };
module.exports.func12 = function () { };
>module.exports : Symbol(func12, Decl(b.js, 28, 33), Decl(b.js, 32, 33))
>module : Symbol(module)
>func12 : Symbol(func12, Decl(b.js, 28, 33), Decl(b.js, 32, 33))
exports = module.exports = {};
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
>module : Symbol(module)
exports.func13 = function () { };
>exports.func13 : Symbol(func13, Decl(b.js, 35, 30))
@@ -214,10 +226,12 @@ exports.func13 = function () { };
module.exports.func14 = function () { };
>module.exports : Symbol(func14, Decl(b.js, 36, 33))
>module : Symbol(module)
>func14 : Symbol(func14, Decl(b.js, 36, 33))
exports = module.exports = {};
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
>module : Symbol(module)
exports.func15 = function () { };
>exports.func15 : Symbol(func15, Decl(b.js, 39, 30))
@@ -226,9 +240,11 @@ exports.func15 = function () { };
module.exports.func16 = function () { };
>module.exports : Symbol(func16, Decl(b.js, 40, 33))
>module : Symbol(module)
>func16 : Symbol(func16, Decl(b.js, 40, 33))
module.exports = exports = {};
>module : Symbol(module)
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
exports.func17 = function () { };
@@ -238,9 +254,12 @@ exports.func17 = function () { };
module.exports.func18 = function () { };
>module.exports : Symbol(func18, Decl(b.js, 44, 33))
>module : Symbol(module)
>func18 : Symbol(func18, Decl(b.js, 44, 33))
module.exports = {};
>module : Symbol(module)
exports.func19 = function () { };
>exports.func19 : Symbol(func19, Decl(b.js, 47, 20))
>exports : Symbol(func19, Decl(b.js, 47, 20))
@@ -248,6 +267,7 @@ exports.func19 = function () { };
module.exports.func20 = function () { };
>module.exports : Symbol(func20, Decl(b.js, 48, 33))
>module : Symbol(module)
>func20 : Symbol(func20, Decl(b.js, 48, 33))

View File

@@ -1,37 +0,0 @@
tests/cases/conformance/salsa/mod.js(1,1): error TS2304: Cannot find name 'module'.
tests/cases/conformance/salsa/mod.js(2,1): error TS2304: Cannot find name 'module'.
tests/cases/conformance/salsa/mod.js(5,1): error TS2304: Cannot find name 'module'.
==== tests/cases/conformance/salsa/mod.js (3 errors) ====
module.exports.n = {};
~~~~~~
!!! error TS2304: Cannot find name 'module'.
module.exports.n.K = function C() {
~~~~~~
!!! error TS2304: Cannot find name 'module'.
this.x = 10;
}
module.exports.Classic = class {
~~~~~~
!!! error TS2304: Cannot find name 'module'.
constructor() {
this.p = 1
}
}
==== tests/cases/conformance/salsa/use.js (0 errors) ====
import * as s from './mod'
var k = new s.n.K()
k.x
var classic = new s.Classic()
/** @param {s.n.K} c
@param {s.Classic} classic */
function f(c, classic) {
c.x
classic.p
}

View File

@@ -1,10 +1,12 @@
=== tests/cases/conformance/salsa/mod.js ===
module.exports.n = {};
>module.exports : Symbol(n, Decl(mod.js, 0, 0))
>module : Symbol(module)
>n : Symbol(n, Decl(mod.js, 0, 0))
module.exports.n.K = function C() {
>module.exports.n : Symbol(K, Decl(mod.js, 0, 22))
>module : Symbol(module)
>K : Symbol(K, Decl(mod.js, 0, 22))
>C : Symbol(C, Decl(mod.js, 1, 20))
@@ -13,6 +15,7 @@ module.exports.n.K = function C() {
}
module.exports.Classic = class {
>module.exports : Symbol(Classic, Decl(mod.js, 3, 1))
>module : Symbol(module)
>Classic : Symbol(Classic, Decl(mod.js, 3, 1))
constructor() {

View File

@@ -3,23 +3,18 @@ tests/cases/conformance/jsdoc/mod1.js(4,7): error TS2300: Duplicate identifier '
tests/cases/conformance/jsdoc/mod1.js(6,23): error TS2300: Duplicate identifier 'Bar'.
tests/cases/conformance/jsdoc/mod1.js(7,9): error TS2300: Duplicate identifier 'Bar'.
tests/cases/conformance/jsdoc/mod1.js(9,5): error TS2300: Duplicate identifier 'Baz'.
tests/cases/conformance/jsdoc/mod1.js(10,1): error TS2304: Cannot find name 'module'.
tests/cases/conformance/jsdoc/mod1.js(11,5): error TS2300: Duplicate identifier 'Baz'.
tests/cases/conformance/jsdoc/mod1.js(23,1): error TS2304: Cannot find name 'module'.
tests/cases/conformance/jsdoc/use.js(1,11): error TS2304: Cannot find name 'require'.
==== tests/cases/conformance/jsdoc/use.js (1 errors) ====
==== tests/cases/conformance/jsdoc/use.js (0 errors) ====
var mod = require('./mod1.js');
~~~~~~~
!!! error TS2304: Cannot find name 'require'.
/** @type {import("./mod1.js").Baz} */
var b;
/** @type {mod.Baz} */
var bb;
var bbb = new mod.Baz();
==== tests/cases/conformance/jsdoc/mod1.js (8 errors) ====
==== tests/cases/conformance/jsdoc/mod1.js (6 errors) ====
// error
/** @typedef {number} Foo */
@@ -40,8 +35,6 @@ tests/cases/conformance/jsdoc/use.js(1,11): error TS2304: Cannot find name 'requ
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2300: Duplicate identifier 'Baz'.
module.exports = {
~~~~~~
!!! error TS2304: Cannot find name 'module'.
Baz: class { }
~~~~~~~~~~~~~~
!!! error TS2300: Duplicate identifier 'Baz'.
@@ -57,8 +50,6 @@ tests/cases/conformance/jsdoc/use.js(1,11): error TS2304: Cannot find name 'requ
/** @typedef {number} Quack */
module.exports = {
~~~~~~
!!! error TS2304: Cannot find name 'module'.
Quack: 2
}

View File

@@ -1,6 +1,7 @@
=== tests/cases/conformance/jsdoc/use.js ===
var mod = require('./mod1.js');
>mod : Symbol(mod, Decl(use.js, 0, 3))
>require : Symbol(require)
>'./mod1.js' : Symbol("tests/cases/conformance/jsdoc/mod1", Decl(mod1.js, 0, 0))
/** @type {import("./mod1.js").Baz} */

View File

@@ -1,9 +1,8 @@
tests/cases/conformance/jsdoc/mod2.js(1,5): error TS2300: Duplicate identifier 'Foo'.
tests/cases/conformance/jsdoc/mod2.js(3,1): error TS2300: Duplicate identifier 'Foo'.
tests/cases/conformance/jsdoc/mod2.js(4,1): error TS2304: Cannot find name 'module'.
==== tests/cases/conformance/jsdoc/mod2.js (3 errors) ====
==== tests/cases/conformance/jsdoc/mod2.js (2 errors) ====
/** @typedef {number} Foo */
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2300: Duplicate identifier 'Foo'.
@@ -12,7 +11,5 @@ tests/cases/conformance/jsdoc/mod2.js(4,1): error TS2304: Cannot find name 'modu
~~~~~~
!!! error TS2300: Duplicate identifier 'Foo'.
module.exports = ns;
~~~~~~
!!! error TS2304: Cannot find name 'module'.

View File

@@ -1,16 +1,13 @@
tests/cases/conformance/jsdoc/mod3.js(1,5): error TS2300: Duplicate identifier 'Foo'.
tests/cases/conformance/jsdoc/mod3.js(3,1): error TS2304: Cannot find name 'module'.
tests/cases/conformance/jsdoc/mod3.js(3,20): error TS2300: Duplicate identifier 'Foo'.
==== tests/cases/conformance/jsdoc/mod3.js (3 errors) ====
==== tests/cases/conformance/jsdoc/mod3.js (2 errors) ====
/** @typedef {number} Foo */
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2300: Duplicate identifier 'Foo'.
class Bar { }
module.exports = { Foo: Bar };
~~~~~~
!!! error TS2304: Cannot find name 'module'.
~~~~~~~~
!!! error TS2300: Duplicate identifier 'Foo'.

View File

@@ -1,32 +0,0 @@
tests/cases/conformance/salsa/use.js(1,10): error TS2304: Cannot find name 'require'.
==== tests/cases/conformance/salsa/use.js (1 errors) ====
var ex = require('./ex')
~~~~~~~
!!! error TS2304: Cannot find name 'require'.
// values work
var crunch = new ex.Crunch(1);
crunch.n
// types work
/**
* @param {ex.Crunch} wrap
*/
function f(wrap) {
wrap.n
}
==== tests/cases/conformance/salsa/ex.js (0 errors) ====
export class Crunch {
/** @param {number} n */
constructor(n) {
this.n = n
}
m() {
return this.n
}
}

View File

@@ -1,6 +1,7 @@
=== tests/cases/conformance/salsa/use.js ===
var ex = require('./ex')
>ex : Symbol(ex, Decl(use.js, 0, 3))
>require : Symbol(require)
>'./ex' : Symbol("tests/cases/conformance/salsa/ex", Decl(ex.js, 0, 0))
// values work

View File

@@ -1,31 +0,0 @@
tests/cases/conformance/salsa/use.js(1,10): error TS2304: Cannot find name 'require'.
==== tests/cases/conformance/salsa/use.js (1 errors) ====
var ex = require('./ex')
~~~~~~~
!!! error TS2304: Cannot find name 'require'.
// values work
var crunch = new ex.Crunch(1);
crunch.n
// types work
/**
* @param {ex.Greatest} greatest
* @param {ex.Crunch} wrap
*/
function f(greatest, wrap) {
greatest.day
wrap.n
}
==== tests/cases/conformance/salsa/ex.d.ts (0 errors) ====
export type Greatest = { day: 1 }
export class Crunch {
n: number
m(): number
constructor(n: number)
}

View File

@@ -1,6 +1,7 @@
=== tests/cases/conformance/salsa/use.js ===
var ex = require('./ex')
>ex : Symbol(ex, Decl(use.js, 0, 3))
>require : Symbol(require)
>'./ex' : Symbol("tests/cases/conformance/salsa/ex", Decl(ex.d.ts, 0, 0))
// values work

View File

@@ -2,12 +2,7 @@
// @allowJs: true
// @checkJs: true
// @noImplicitAny: true
// @Filename: types.d.ts
declare function require(name: string): any;
declare var exports: any;
declare var module: { exports: any };
// @Filename: mod.js
/// <reference path='./types.d.ts'/>
/** @param {number} n */
exports.f = exports.g = function fg(n) {
@@ -19,7 +14,6 @@ module.exports.h = module.exports.i = function hi(mom) {
}
// @Filename: use.js
/// <reference path='./types.d.ts'/>
var mod = require('./mod');
mod.f('no')
mod.g('also no')