mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Only bind module.exports if no local definition exists (#25869)
* Only bind module.exports if no local definition exists Note that this uses `lookupSymbolForNameWorker`, which is really a best-effort check since it only knows about symbols that it has already encountered. As a side-effect, even when `module` is bound as part of a `module.exports` reference, it only declares it once instead of one declaration per reference. * Only type module.exports inside module files It is an error inside script files, but the binder sometimes creates a ModuleExports symbol because we doesn't know whether we have a commonjs module until after binding is done. * Only bind module.exports in a commonjs module Note that this, too, is a best-effort check since evidence of commonjs-ness may be found after a *reference* to module.exports. (A reference to module.exports alone is not enough evidence that a file is commonjs. It has to have an assignment to it.)
This commit is contained in:
@@ -2072,7 +2072,10 @@ namespace ts {
|
||||
if (isSpecialPropertyDeclaration(node as PropertyAccessExpression)) {
|
||||
bindSpecialPropertyDeclaration(node as PropertyAccessExpression);
|
||||
}
|
||||
if (isInJavaScriptFile(node) && isModuleExportsPropertyAccessExpression(node as PropertyAccessExpression)) {
|
||||
if (isInJavaScriptFile(node) &&
|
||||
file.commonJsModuleIndicator &&
|
||||
isModuleExportsPropertyAccessExpression(node as PropertyAccessExpression) &&
|
||||
!lookupSymbolForNameWorker(container, "module" as __String)) {
|
||||
declareSymbol(container.locals!, /*parent*/ undefined, (node as PropertyAccessExpression).expression as Identifier,
|
||||
SymbolFlags.FunctionScopedVariable | SymbolFlags.ModuleExports, SymbolFlags.FunctionScopedVariableExcludes);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
tests/cases/conformance/salsa/bug24934.js(2,1): error TS2304: Cannot find name 'module'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/salsa/bug24934.js (1 errors) ====
|
||||
export function abc(a, b, c) { return 5; }
|
||||
module.exports = { abc };
|
||||
~~~~~~
|
||||
!!! error TS2304: Cannot find name 'module'.
|
||||
==== tests/cases/conformance/salsa/use.js (0 errors) ====
|
||||
import { abc } from './bug24934';
|
||||
abc(1, 2, 3);
|
||||
|
||||
@@ -6,9 +6,6 @@ export function abc(a, b, c) { return 5; }
|
||||
>c : Symbol(c, Decl(bug24934.js, 0, 25))
|
||||
|
||||
module.exports = { abc };
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/bug24934", Decl(bug24934.js, 0, 0))
|
||||
>module : Symbol(module, Decl(bug24934.js, 0, 42))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/bug24934", Decl(bug24934.js, 0, 0))
|
||||
>abc : Symbol(abc, Decl(bug24934.js, 1, 18))
|
||||
|
||||
=== tests/cases/conformance/salsa/use.js ===
|
||||
|
||||
@@ -7,10 +7,10 @@ export function abc(a, b, c) { return 5; }
|
||||
>5 : 5
|
||||
|
||||
module.exports = { abc };
|
||||
>module.exports = { abc } : typeof import("tests/cases/conformance/salsa/bug24934")
|
||||
>module.exports : typeof import("tests/cases/conformance/salsa/bug24934")
|
||||
>module : { "tests/cases/conformance/salsa/bug24934": typeof import("tests/cases/conformance/salsa/bug24934"); }
|
||||
>exports : typeof import("tests/cases/conformance/salsa/bug24934")
|
||||
>module.exports = { abc } : any
|
||||
>module.exports : any
|
||||
>module : any
|
||||
>exports : any
|
||||
>{ abc } : { abc: (a: any, b: any, c: any) => number; }
|
||||
>abc : (a: any, b: any, c: any) => number
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ exports.x
|
||||
module.exports.y = {
|
||||
>module.exports.y : Symbol(y, Decl(test.js, 45, 9))
|
||||
>module.exports : Symbol(y, Decl(test.js, 45, 9))
|
||||
>module : Symbol(module, Decl(test.js, 45, 9), Decl(test.js, 51, 1))
|
||||
>module : Symbol(module, Decl(test.js, 45, 9))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/test", Decl(test.js, 0, 0))
|
||||
>y : Symbol(y, Decl(test.js, 45, 9))
|
||||
|
||||
@@ -116,7 +116,7 @@ module.exports.y = {
|
||||
module.exports.y
|
||||
>module.exports.y : Symbol(y, Decl(test.js, 45, 9))
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/test", Decl(test.js, 0, 0))
|
||||
>module : Symbol(module, Decl(test.js, 45, 9), Decl(test.js, 51, 1))
|
||||
>module : Symbol(module, Decl(test.js, 45, 9))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/test", Decl(test.js, 0, 0))
|
||||
>y : Symbol(y, Decl(test.js, 45, 9))
|
||||
|
||||
|
||||
@@ -43,12 +43,12 @@ exports.f = exports.g = function fg(n) {
|
||||
module.exports.h = module.exports.i = function hi(mom) {
|
||||
>module.exports.h : Symbol(h, Decl(mod.js, 3, 1))
|
||||
>module.exports : Symbol(h, Decl(mod.js, 3, 1))
|
||||
>module : Symbol(module, Decl(mod.js, 3, 1), Decl(mod.js, 5, 18))
|
||||
>module : Symbol(module, Decl(mod.js, 3, 1))
|
||||
>exports : Symbol("tests/cases/conformance/jsdoc/mod", Decl(mod.js, 0, 0))
|
||||
>h : Symbol(h, Decl(mod.js, 3, 1))
|
||||
>module.exports.i : Symbol(i, Decl(mod.js, 5, 18))
|
||||
>module.exports : Symbol(i, Decl(mod.js, 5, 18))
|
||||
>module : Symbol(module, Decl(mod.js, 3, 1), Decl(mod.js, 5, 18))
|
||||
>module : Symbol(module, Decl(mod.js, 3, 1))
|
||||
>exports : Symbol("tests/cases/conformance/jsdoc/mod", Decl(mod.js, 0, 0))
|
||||
>i : Symbol(i, Decl(mod.js, 5, 18))
|
||||
>hi : Symbol(hi, Decl(mod.js, 5, 37))
|
||||
|
||||
@@ -121,7 +121,7 @@ exports.func2 = function () { };
|
||||
var moduleExportsAlias = module.exports;
|
||||
>moduleExportsAlias : Symbol(moduleExportsAlias, Decl(b.js, 4, 3))
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
|
||||
moduleExportsAlias.func3 = function () { };
|
||||
@@ -132,7 +132,7 @@ moduleExportsAlias.func3 = function () { };
|
||||
module.exports.func4 = function () { };
|
||||
>module.exports.func4 : Symbol(func4, Decl(b.js, 5, 43))
|
||||
>module.exports : Symbol(func4, Decl(b.js, 5, 43))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>func4 : Symbol(func4, Decl(b.js, 5, 43))
|
||||
|
||||
@@ -140,7 +140,7 @@ 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.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
|
||||
multipleDeclarationAlias1.func5 = function () { };
|
||||
@@ -151,7 +151,7 @@ multipleDeclarationAlias1.func5 = function () { };
|
||||
var multipleDeclarationAlias2 = module.exports = exports;
|
||||
>multipleDeclarationAlias2 : Symbol(multipleDeclarationAlias2, Decl(b.js, 11, 3))
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
|
||||
@@ -177,7 +177,7 @@ var multipleDeclarationAlias4 = someOtherVariable = module.exports;
|
||||
>multipleDeclarationAlias4 : Symbol(multipleDeclarationAlias4, Decl(b.js, 18, 3))
|
||||
>someOtherVariable : Symbol(someOtherVariable, Decl(b.js, 14, 3))
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
|
||||
multipleDeclarationAlias4.func8 = function () { };
|
||||
@@ -188,7 +188,7 @@ multipleDeclarationAlias4.func8 = function () { };
|
||||
var multipleDeclarationAlias5 = module.exports = exports = {};
|
||||
>multipleDeclarationAlias5 : Symbol(multipleDeclarationAlias5, Decl(b.js, 21, 3))
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
|
||||
@@ -201,7 +201,7 @@ 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.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
|
||||
multipleDeclarationAlias6.func10 = function () { };
|
||||
@@ -212,7 +212,7 @@ multipleDeclarationAlias6.func10 = function () { };
|
||||
exports = module.exports = someOtherVariable = {};
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>someOtherVariable : Symbol(someOtherVariable, Decl(b.js, 14, 3))
|
||||
|
||||
@@ -224,14 +224,14 @@ exports.func11 = function () { };
|
||||
module.exports.func12 = function () { };
|
||||
>module.exports.func12 : Symbol(func12, Decl(b.js, 28, 33), Decl(b.js, 32, 33))
|
||||
>module.exports : Symbol(func12, Decl(b.js, 28, 33), Decl(b.js, 32, 33))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>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.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>someOtherVariable : Symbol(someOtherVariable, Decl(b.js, 14, 3))
|
||||
|
||||
@@ -243,14 +243,14 @@ exports.func11 = function () { };
|
||||
module.exports.func12 = function () { };
|
||||
>module.exports.func12 : Symbol(func12, Decl(b.js, 28, 33), Decl(b.js, 32, 33))
|
||||
>module.exports : Symbol(func12, Decl(b.js, 28, 33), Decl(b.js, 32, 33))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>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.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
|
||||
exports.func13 = function () { };
|
||||
@@ -261,14 +261,14 @@ exports.func13 = function () { };
|
||||
module.exports.func14 = function () { };
|
||||
>module.exports.func14 : Symbol(func14, Decl(b.js, 36, 33))
|
||||
>module.exports : Symbol(func14, Decl(b.js, 36, 33))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>func14 : Symbol(func14, Decl(b.js, 36, 33))
|
||||
|
||||
exports = module.exports = {};
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
|
||||
exports.func15 = function () { };
|
||||
@@ -279,13 +279,13 @@ exports.func15 = function () { };
|
||||
module.exports.func16 = function () { };
|
||||
>module.exports.func16 : Symbol(func16, Decl(b.js, 40, 33))
|
||||
>module.exports : Symbol(func16, Decl(b.js, 40, 33))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>func16 : Symbol(func16, Decl(b.js, 40, 33))
|
||||
|
||||
module.exports = exports = {};
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
|
||||
@@ -297,13 +297,13 @@ exports.func17 = function () { };
|
||||
module.exports.func18 = function () { };
|
||||
>module.exports.func18 : Symbol(func18, Decl(b.js, 44, 33))
|
||||
>module.exports : Symbol(func18, Decl(b.js, 44, 33))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>func18 : Symbol(func18, Decl(b.js, 44, 33))
|
||||
|
||||
module.exports = {};
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
|
||||
exports.func19 = function () { };
|
||||
@@ -314,7 +314,7 @@ exports.func19 = function () { };
|
||||
module.exports.func20 = function () { };
|
||||
>module.exports.func20 : Symbol(func20, Decl(b.js, 48, 33))
|
||||
>module.exports : Symbol(func20, Decl(b.js, 48, 33))
|
||||
>module : Symbol(module, Decl(b.js, 4, 24), Decl(b.js, 5, 43), Decl(b.js, 8, 41), Decl(b.js, 11, 31), Decl(b.js, 18, 51) ... and 14 more)
|
||||
>module : Symbol(module, Decl(b.js, 4, 24))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/b", Decl(b.js, 0, 0))
|
||||
>func20 : Symbol(func20, Decl(b.js, 48, 33))
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ module.exports = class C {}
|
||||
module.exports.D = class D { }
|
||||
>module.exports.D : Symbol(D)
|
||||
>module.exports : Symbol(D, Decl(bug24024.js, 2, 27))
|
||||
>module : Symbol(module, Decl(bug24024.js, 1, 31), Decl(bug24024.js, 2, 27))
|
||||
>module : Symbol(module, Decl(bug24024.js, 1, 31))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/bug24024", Decl(bug24024.js, 0, 0))
|
||||
>D : Symbol(D, Decl(bug24024.js, 2, 27))
|
||||
>D : Symbol(D, Decl(bug24024.js, 3, 18))
|
||||
|
||||
@@ -38,7 +38,7 @@ npmlog.on('hi') // both references should see EE.on
|
||||
module.exports.on('hi') // here too
|
||||
>module.exports.on : Symbol(EE.on, Decl(npmlog.js, 0, 10))
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/npmlog", Decl(npmlog.js, 0, 0))
|
||||
>module : Symbol(module, Decl(npmlog.js, 4, 12), Decl(npmlog.js, 6, 15), Decl(npmlog.js, 9, 12), Decl(npmlog.js, 11, 8))
|
||||
>module : Symbol(module, Decl(npmlog.js, 4, 12))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/npmlog", Decl(npmlog.js, 0, 0))
|
||||
>on : Symbol(EE.on, Decl(npmlog.js, 0, 10))
|
||||
|
||||
@@ -50,7 +50,7 @@ npmlog.x = 1
|
||||
module.exports.y = 2
|
||||
>module.exports.y : Symbol(y, Decl(npmlog.js, 9, 12))
|
||||
>module.exports : Symbol(y, Decl(npmlog.js, 9, 12))
|
||||
>module : Symbol(module, Decl(npmlog.js, 4, 12), Decl(npmlog.js, 6, 15), Decl(npmlog.js, 9, 12), Decl(npmlog.js, 11, 8))
|
||||
>module : Symbol(module, Decl(npmlog.js, 4, 12))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/npmlog", Decl(npmlog.js, 0, 0))
|
||||
>y : Symbol(y, Decl(npmlog.js, 9, 12))
|
||||
|
||||
@@ -62,7 +62,7 @@ npmlog.y
|
||||
module.exports.x
|
||||
>module.exports.x : Symbol(x, Decl(npmlog.js, 7, 23))
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/npmlog", Decl(npmlog.js, 0, 0))
|
||||
>module : Symbol(module, Decl(npmlog.js, 4, 12), Decl(npmlog.js, 6, 15), Decl(npmlog.js, 9, 12), Decl(npmlog.js, 11, 8))
|
||||
>module : Symbol(module, Decl(npmlog.js, 4, 12))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/npmlog", Decl(npmlog.js, 0, 0))
|
||||
>x : Symbol(x, Decl(npmlog.js, 7, 23))
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ var npm = module.exports = function (tree) {
|
||||
module.exports.asReadInstalled = function (tree) {
|
||||
>module.exports.asReadInstalled : Symbol(asReadInstalled, Decl(npm.js, 1, 1))
|
||||
>module.exports : Symbol(asReadInstalled, Decl(npm.js, 1, 1))
|
||||
>module : Symbol(module, Decl(npm.js, 0, 9), Decl(npm.js, 1, 1))
|
||||
>module : Symbol(module, Decl(npm.js, 0, 9))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/npm", Decl(npm.js, 0, 0))
|
||||
>asReadInstalled : Symbol(asReadInstalled, Decl(npm.js, 1, 1))
|
||||
>tree : Symbol(tree, Decl(npm.js, 2, 43))
|
||||
|
||||
@@ -16,6 +16,6 @@ module.exports = function x() { }
|
||||
|
||||
module.exports() // should be callable
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
|
||||
>module : Symbol(module, Decl(mod.js, 0, 0), Decl(mod.js, 0, 33))
|
||||
>module : Symbol(module, Decl(mod.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ module.exports = axios;
|
||||
module.exports.default = axios;
|
||||
>module.exports.default : Symbol(default, Decl(axios.js, 8, 23))
|
||||
>module.exports : Symbol(default, Decl(axios.js, 8, 23))
|
||||
>module : Symbol(module, Decl(axios.js, 7, 9), Decl(axios.js, 8, 23))
|
||||
>module : Symbol(module, Decl(axios.js, 7, 9))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/axios", Decl(axios.js, 0, 0))
|
||||
>default : Symbol(default, Decl(axios.js, 8, 23))
|
||||
>axios : Symbol(axios, Decl(axios.js, 5, 3))
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
=== tests/cases/conformance/salsa/webpackLibNormalModule.js ===
|
||||
class C {
|
||||
>C : Symbol(C, Decl(webpackLibNormalModule.js, 0, 0))
|
||||
|
||||
/** @param {number} x */
|
||||
constructor(x) {
|
||||
>x : Symbol(x, Decl(webpackLibNormalModule.js, 2, 16))
|
||||
|
||||
this.x = x
|
||||
>this.x : Symbol(C.x, Decl(webpackLibNormalModule.js, 2, 20))
|
||||
>this : Symbol(C, Decl(webpackLibNormalModule.js, 0, 0))
|
||||
>x : Symbol(C.x, Decl(webpackLibNormalModule.js, 2, 20))
|
||||
>x : Symbol(x, Decl(webpackLibNormalModule.js, 2, 16))
|
||||
|
||||
this.exports = [x]
|
||||
>this.exports : Symbol(C.exports, Decl(webpackLibNormalModule.js, 3, 18))
|
||||
>this : Symbol(C, Decl(webpackLibNormalModule.js, 0, 0))
|
||||
>exports : Symbol(C.exports, Decl(webpackLibNormalModule.js, 3, 18))
|
||||
>x : Symbol(x, Decl(webpackLibNormalModule.js, 2, 16))
|
||||
}
|
||||
/** @param {number} y */
|
||||
m(y) {
|
||||
>m : Symbol(C.m, Decl(webpackLibNormalModule.js, 5, 5))
|
||||
>y : Symbol(y, Decl(webpackLibNormalModule.js, 7, 6))
|
||||
|
||||
return this.x + y
|
||||
>this.x : Symbol(C.x, Decl(webpackLibNormalModule.js, 2, 20))
|
||||
>this : Symbol(C, Decl(webpackLibNormalModule.js, 0, 0))
|
||||
>x : Symbol(C.x, Decl(webpackLibNormalModule.js, 2, 20))
|
||||
>y : Symbol(y, Decl(webpackLibNormalModule.js, 7, 6))
|
||||
}
|
||||
}
|
||||
function exec() {
|
||||
>exec : Symbol(exec, Decl(webpackLibNormalModule.js, 10, 1))
|
||||
|
||||
const module = new C(12);
|
||||
>module : Symbol(module, Decl(webpackLibNormalModule.js, 12, 9))
|
||||
>C : Symbol(C, Decl(webpackLibNormalModule.js, 0, 0))
|
||||
|
||||
return module.exports; // should be fine because `module` is defined locally
|
||||
>module.exports : Symbol(C.exports, Decl(webpackLibNormalModule.js, 3, 18))
|
||||
>module : Symbol(module, Decl(webpackLibNormalModule.js, 12, 9))
|
||||
>exports : Symbol(C.exports, Decl(webpackLibNormalModule.js, 3, 18))
|
||||
}
|
||||
|
||||
function tricky() {
|
||||
>tricky : Symbol(tricky, Decl(webpackLibNormalModule.js, 14, 1))
|
||||
|
||||
// (a trickier variant of what webpack does)
|
||||
const module = new C(12);
|
||||
>module : Symbol(module, Decl(webpackLibNormalModule.js, 18, 9))
|
||||
>C : Symbol(C, Decl(webpackLibNormalModule.js, 0, 0))
|
||||
|
||||
return () => {
|
||||
return module.exports;
|
||||
>module.exports : Symbol(C.exports, Decl(webpackLibNormalModule.js, 3, 18))
|
||||
>module : Symbol(module, Decl(webpackLibNormalModule.js, 18, 9))
|
||||
>exports : Symbol(C.exports, Decl(webpackLibNormalModule.js, 3, 18))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
=== tests/cases/conformance/salsa/webpackLibNormalModule.js ===
|
||||
class C {
|
||||
>C : C
|
||||
|
||||
/** @param {number} x */
|
||||
constructor(x) {
|
||||
>x : number
|
||||
|
||||
this.x = x
|
||||
>this.x = x : number
|
||||
>this.x : number
|
||||
>this : this
|
||||
>x : number
|
||||
>x : number
|
||||
|
||||
this.exports = [x]
|
||||
>this.exports = [x] : number[]
|
||||
>this.exports : number[]
|
||||
>this : this
|
||||
>exports : number[]
|
||||
>[x] : number[]
|
||||
>x : number
|
||||
}
|
||||
/** @param {number} y */
|
||||
m(y) {
|
||||
>m : (y: number) => number
|
||||
>y : number
|
||||
|
||||
return this.x + y
|
||||
>this.x + y : number
|
||||
>this.x : number
|
||||
>this : this
|
||||
>x : number
|
||||
>y : number
|
||||
}
|
||||
}
|
||||
function exec() {
|
||||
>exec : () => number[]
|
||||
|
||||
const module = new C(12);
|
||||
>module : C
|
||||
>new C(12) : C
|
||||
>C : typeof C
|
||||
>12 : 12
|
||||
|
||||
return module.exports; // should be fine because `module` is defined locally
|
||||
>module.exports : number[]
|
||||
>module : C
|
||||
>exports : number[]
|
||||
}
|
||||
|
||||
function tricky() {
|
||||
>tricky : () => () => number[]
|
||||
|
||||
// (a trickier variant of what webpack does)
|
||||
const module = new C(12);
|
||||
>module : C
|
||||
>new C(12) : C
|
||||
>C : typeof C
|
||||
>12 : 12
|
||||
|
||||
return () => {
|
||||
>() => { return module.exports; } : () => number[]
|
||||
|
||||
return module.exports;
|
||||
>module.exports : number[]
|
||||
>module : C
|
||||
>exports : number[]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
module.exports.n = {};
|
||||
>module.exports.n : Symbol(n, Decl(mod.js, 0, 0), Decl(mod.js, 1, 15))
|
||||
>module.exports : Symbol(n, Decl(mod.js, 0, 0), Decl(mod.js, 1, 15))
|
||||
>module : Symbol(module, Decl(mod.js, 0, 0), Decl(mod.js, 0, 22), Decl(mod.js, 3, 1))
|
||||
>module : Symbol(module, Decl(mod.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
|
||||
>n : Symbol(n, Decl(mod.js, 0, 0), Decl(mod.js, 1, 15))
|
||||
|
||||
@@ -10,7 +10,7 @@ module.exports.n.K = function C() {
|
||||
>module.exports.n.K : Symbol(n.K, Decl(mod.js, 0, 22))
|
||||
>module.exports.n : Symbol(n.K, Decl(mod.js, 0, 22))
|
||||
>module.exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
|
||||
>module : Symbol(module, Decl(mod.js, 0, 0), Decl(mod.js, 0, 22), Decl(mod.js, 3, 1))
|
||||
>module : Symbol(module, Decl(mod.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
|
||||
>n : Symbol(n, Decl(mod.js, 0, 0), Decl(mod.js, 1, 15))
|
||||
>K : Symbol(n.K, Decl(mod.js, 0, 22))
|
||||
@@ -23,7 +23,7 @@ module.exports.n.K = function C() {
|
||||
module.exports.Classic = class {
|
||||
>module.exports.Classic : Symbol(Classic, Decl(mod.js, 3, 1))
|
||||
>module.exports : Symbol(Classic, Decl(mod.js, 3, 1))
|
||||
>module : Symbol(module, Decl(mod.js, 0, 0), Decl(mod.js, 0, 22), Decl(mod.js, 3, 1))
|
||||
>module : Symbol(module, Decl(mod.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
|
||||
>Classic : Symbol(Classic, Decl(mod.js, 3, 1))
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ module.exports = axios // both assignments should be ok
|
||||
module.exports.default = axios
|
||||
>module.exports.default : Symbol(default)
|
||||
>module.exports : Symbol(default, Decl(axios.js, 1, 22))
|
||||
>module : Symbol(module, Decl(axios.js, 0, 14), Decl(axios.js, 1, 22))
|
||||
>module : Symbol(module, Decl(axios.js, 0, 14))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/axios", Decl(axios.js, 0, 0))
|
||||
>default : Symbol(default, Decl(axios.js, 1, 22))
|
||||
>axios : Symbol(axios, Decl(axios.js, 0, 3))
|
||||
|
||||
@@ -33,7 +33,7 @@ module.exports = function () { }
|
||||
module.exports.f = function (a) { }
|
||||
>module.exports.f : Symbol(f, Decl(mod1.js, 1, 32))
|
||||
>module.exports : Symbol(f, Decl(mod1.js, 1, 32))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0), Decl(mod1.js, 1, 32))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0))
|
||||
>f : Symbol(f, Decl(mod1.js, 1, 32))
|
||||
>a : Symbol(a, Decl(mod1.js, 3, 29))
|
||||
|
||||
@@ -31,7 +31,7 @@ module.exports = 1
|
||||
|
||||
module.exports.f = function () { }
|
||||
>module.exports : Symbol(f, Decl(mod1.js, 1, 18))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0), Decl(mod1.js, 1, 18))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0))
|
||||
>f : Symbol(f, Decl(mod1.js, 1, 18))
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ declare function require(name: string): any;
|
||||
module.exports.bothBefore = 'string'
|
||||
>module.exports.bothBefore : Symbol(bothBefore)
|
||||
>module.exports : Symbol(bothBefore, Decl(mod1.js, 0, 0))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0), Decl(mod1.js, 1, 36), Decl(mod1.js, 6, 1), Decl(mod1.js, 7, 35))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0))
|
||||
>bothBefore : Symbol(bothBefore, Decl(mod1.js, 0, 0))
|
||||
|
||||
@@ -64,14 +64,14 @@ module.exports = {
|
||||
module.exports.bothAfter = 'string'
|
||||
>module.exports.bothAfter : Symbol(bothAfter)
|
||||
>module.exports : Symbol(bothAfter, Decl(mod1.js, 6, 1))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0), Decl(mod1.js, 1, 36), Decl(mod1.js, 6, 1), Decl(mod1.js, 7, 35))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0))
|
||||
>bothAfter : Symbol(bothAfter, Decl(mod1.js, 6, 1))
|
||||
|
||||
module.exports.justProperty = 'string'
|
||||
>module.exports.justProperty : Symbol(justProperty, Decl(mod1.js, 7, 35))
|
||||
>module.exports : Symbol(justProperty, Decl(mod1.js, 7, 35))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0), Decl(mod1.js, 1, 36), Decl(mod1.js, 6, 1), Decl(mod1.js, 7, 35))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0))
|
||||
>justProperty : Symbol(justProperty, Decl(mod1.js, 7, 35))
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ declare function require(name: string): any;
|
||||
module.exports.bothBefore = 'string'
|
||||
>module.exports.bothBefore : Symbol(bothBefore)
|
||||
>module.exports : Symbol(A.bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0), Decl(mod1.js, 4, 15), Decl(mod1.js, 8, 1), Decl(mod1.js, 9, 35))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0))
|
||||
>bothBefore : Symbol(A.bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0))
|
||||
|
||||
@@ -77,14 +77,14 @@ function A() {
|
||||
module.exports.bothAfter = 'string'
|
||||
>module.exports.bothAfter : Symbol(bothAfter)
|
||||
>module.exports : Symbol(A.bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0), Decl(mod1.js, 4, 15), Decl(mod1.js, 8, 1), Decl(mod1.js, 9, 35))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0))
|
||||
>bothAfter : Symbol(A.bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1))
|
||||
|
||||
module.exports.justProperty = 'string'
|
||||
>module.exports.justProperty : Symbol(justProperty)
|
||||
>module.exports : Symbol(justProperty, Decl(mod1.js, 9, 35))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0), Decl(mod1.js, 4, 15), Decl(mod1.js, 8, 1), Decl(mod1.js, 9, 35))
|
||||
>module : Symbol(module, Decl(mod1.js, 0, 0))
|
||||
>exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0))
|
||||
>justProperty : Symbol(justProperty, Decl(mod1.js, 9, 35))
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// @noEmit: true
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @Filename: webpackLibNormalModule.js
|
||||
class C {
|
||||
/** @param {number} x */
|
||||
constructor(x) {
|
||||
this.x = x
|
||||
this.exports = [x]
|
||||
}
|
||||
/** @param {number} y */
|
||||
m(y) {
|
||||
return this.x + y
|
||||
}
|
||||
}
|
||||
function exec() {
|
||||
const module = new C(12);
|
||||
return module.exports; // should be fine because `module` is defined locally
|
||||
}
|
||||
|
||||
function tricky() {
|
||||
// (a trickier variant of what webpack does)
|
||||
const module = new C(12);
|
||||
return () => {
|
||||
return module.exports;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user