From 64d6e50b2ce7a83d476a14ede1d358912732002e Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 24 Aug 2020 15:48:47 -0700 Subject: [PATCH] Alias for `module.exports.x = x` This fixes #40155 in a surprisingly small amount of code. --- src/compiler/binder.ts | 9 +-- src/compiler/types.ts | 1 + .../commonJSImportClassTypeReference.js | 44 +++++++++++++++ .../commonJSImportClassTypeReference.symbols | 33 +++++++++++ .../commonJSImportClassTypeReference.types | 36 ++++++++++++ ...findAllRefsCommonJsRequire2.baseline.jsonc | 28 ++-------- ...arationsExportDoubleAssignmentInClosure.js | 16 ++++-- ...onsExportDoubleAssignmentInClosure.symbols | 13 ++++- ...tionsExportDoubleAssignmentInClosure.types | 13 ++++- .../reference/jsDeclarationsFunctionsCjs.js | 16 +++--- ...tAliasExposedWithinNamespaceCjs.errors.txt | 55 ------------------- ...onsImportAliasExposedWithinNamespaceCjs.js | 43 ++++++++++++++- ...ImportAliasExposedWithinNamespaceCjs.types | 18 +++--- ...jsdocImportTypeReferenceToClassAlias.types | 4 +- .../jsdocTypeFromChainedAssignment3.symbols | 2 +- .../jsdocTypeFromChainedAssignment3.types | 4 +- ...teBoundAssignmentDeclarationSupport4.types | 12 ++-- ...teBoundAssignmentDeclarationSupport5.types | 12 ++-- ...teBoundAssignmentDeclarationSupport6.types | 12 ++-- ...BoundAssignmentDeclarationSupport7.symbols | 2 +- ...teBoundAssignmentDeclarationSupport7.types | 8 +-- ...arationsExportDoubleAssignmentInClosure.ts | 7 ++- .../salsa/commonJSImportClassTypeReference.ts | 20 +++++++ .../goToDefinitionImportedNames10.ts | 4 +- .../completionEntryDetailAcrossFiles01.ts | 2 +- .../completionEntryDetailAcrossFiles02.ts | 2 +- .../syntheticImportFromBabelGeneratedFile1.ts | 4 +- .../syntheticImportFromBabelGeneratedFile2.ts | 4 +- 28 files changed, 273 insertions(+), 151 deletions(-) create mode 100644 tests/baselines/reference/commonJSImportClassTypeReference.js create mode 100644 tests/baselines/reference/commonJSImportClassTypeReference.symbols create mode 100644 tests/baselines/reference/commonJSImportClassTypeReference.types delete mode 100644 tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.errors.txt create mode 100644 tests/cases/conformance/salsa/commonJSImportClassTypeReference.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 1003b23b455ec..07476ba0eab22 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2805,10 +2805,11 @@ namespace ts { return symbol; }); if (symbol) { - const flags = isClassExpression(node.right) ? - SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.Class : - SymbolFlags.Property | SymbolFlags.ExportValue; - declareSymbol(symbol.exports!, symbol, node.left, flags, SymbolFlags.None); + const flags = isIdentifier(node.right) ? SymbolFlags.Alias + : isClassExpression(node.right) ? SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.Class + : SymbolFlags.Property | SymbolFlags.ExportValue; + const excludeFlags = isIdentifier(node.right) ? SymbolFlags.AliasExcludes : SymbolFlags.None; + declareSymbol(symbol.exports!, symbol, node.left, flags, excludeFlags); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 40f43b3ad6bbc..3fff862a5cffb 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5499,6 +5499,7 @@ namespace ts { export const enum AssignmentDeclarationKind { None, /// exports.name = expr + /// module.exports.name = expr ExportsProperty, /// module.exports = expr ModuleExports, diff --git a/tests/baselines/reference/commonJSImportClassTypeReference.js b/tests/baselines/reference/commonJSImportClassTypeReference.js new file mode 100644 index 0000000000000..df556ccc57409 --- /dev/null +++ b/tests/baselines/reference/commonJSImportClassTypeReference.js @@ -0,0 +1,44 @@ +//// [tests/cases/conformance/salsa/commonJSImportClassTypeReference.ts] //// + +//// [main.js] +const { K } = require("./mod1"); +/** @param {K} k */ +function f(k) { + k.values() +} + +//// [mod1.js] +class K { + values() { + } +} +exports.K = K; +// export { K } + + +//// [mod1.js] +"use strict"; +var K = /** @class */ (function () { + function K() { + } + K.prototype.values = function () { + }; + return K; +}()); +exports.K = K; +// export { K } +//// [main.js] +"use strict"; +var K = require("./mod1").K; +/** @param {K} k */ +function f(k) { + k.values(); +} + + +//// [mod1.d.ts] +export class K { + values(): void; +} +//// [main.d.ts] +export {}; diff --git a/tests/baselines/reference/commonJSImportClassTypeReference.symbols b/tests/baselines/reference/commonJSImportClassTypeReference.symbols new file mode 100644 index 0000000000000..6d8a63c003a9e --- /dev/null +++ b/tests/baselines/reference/commonJSImportClassTypeReference.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/salsa/main.js === +const { K } = require("./mod1"); +>K : Symbol(K, Decl(main.js, 0, 7)) +>require : Symbol(require) +>"./mod1" : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0)) + +/** @param {K} k */ +function f(k) { +>f : Symbol(f, Decl(main.js, 0, 32)) +>k : Symbol(k, Decl(main.js, 2, 11)) + + k.values() +>k.values : Symbol(K.values, Decl(mod1.js, 0, 9)) +>k : Symbol(k, Decl(main.js, 2, 11)) +>values : Symbol(K.values, Decl(mod1.js, 0, 9)) +} + +=== tests/cases/conformance/salsa/mod1.js === +class K { +>K : Symbol(K, Decl(mod1.js, 0, 0)) + + values() { +>values : Symbol(K.values, Decl(mod1.js, 0, 9)) + } +} +exports.K = K; +>exports.K : Symbol(K, Decl(mod1.js, 3, 1)) +>exports : Symbol(K, Decl(mod1.js, 3, 1)) +>K : Symbol(K, Decl(mod1.js, 3, 1)) +>K : Symbol(K, Decl(mod1.js, 0, 0)) + +// export { K } + diff --git a/tests/baselines/reference/commonJSImportClassTypeReference.types b/tests/baselines/reference/commonJSImportClassTypeReference.types new file mode 100644 index 0000000000000..6c8094de9cef5 --- /dev/null +++ b/tests/baselines/reference/commonJSImportClassTypeReference.types @@ -0,0 +1,36 @@ +=== tests/cases/conformance/salsa/main.js === +const { K } = require("./mod1"); +>K : typeof K +>require("./mod1") : typeof import("tests/cases/conformance/salsa/mod1") +>require : any +>"./mod1" : "./mod1" + +/** @param {K} k */ +function f(k) { +>f : (k: K) => void +>k : K + + k.values() +>k.values() : void +>k.values : () => void +>k : K +>values : () => void +} + +=== tests/cases/conformance/salsa/mod1.js === +class K { +>K : K + + values() { +>values : () => void + } +} +exports.K = K; +>exports.K = K : typeof K +>exports.K : typeof K +>exports : typeof import("tests/cases/conformance/salsa/mod1") +>K : typeof K +>K : typeof K + +// export { K } + diff --git a/tests/baselines/reference/findAllRefsCommonJsRequire2.baseline.jsonc b/tests/baselines/reference/findAllRefsCommonJsRequire2.baseline.jsonc index f7b3b0ca60b74..e647bf183db75 100644 --- a/tests/baselines/reference/findAllRefsCommonJsRequire2.baseline.jsonc +++ b/tests/baselines/reference/findAllRefsCommonJsRequire2.baseline.jsonc @@ -13,7 +13,7 @@ "containerName": "", "fileName": "/b.js", "kind": "alias", - "name": "(alias) (property) f: () => void\nimport f", + "name": "(alias) function f(): void\nimport f", "textSpan": { "start": 8, "length": 1 @@ -36,16 +36,8 @@ "kind": "space" }, { - "text": "(", - "kind": "punctuation" - }, - { - "text": "property", - "kind": "text" - }, - { - "text": ")", - "kind": "punctuation" + "text": "function", + "kind": "keyword" }, { "text": " ", @@ -55,14 +47,6 @@ "text": "f", "kind": "aliasName" }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, { "text": "(", "kind": "punctuation" @@ -72,11 +56,7 @@ "kind": "punctuation" }, { - "text": " ", - "kind": "space" - }, - { - "text": "=>", + "text": ":", "kind": "punctuation" }, { diff --git a/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.js b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.js index bb5a076f1bcb4..c66ea97d9ca19 100644 --- a/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.js +++ b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.js @@ -4,8 +4,12 @@ function foo() { module.exports = exports = function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); }; - exports.methods = methods; -} + const m = function () { + // I have no idea what to put here + } + exports.methods = m; +} + //// [index.js] // @ts-nocheck @@ -13,13 +17,17 @@ function foo() { module.exports = exports = function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); }; - exports.methods = methods; + var m = function () { + // I have no idea what to put here + }; + exports.methods = m; } //// [index.d.ts] declare function _exports(o: any): any; declare namespace _exports { - const methods: any; + export { m as methods }; } export = _exports; +declare function m(): void; diff --git a/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.symbols b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.symbols index 5031ff1166d3a..27d5ca6f16f57 100644 --- a/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.symbols +++ b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.symbols @@ -16,7 +16,14 @@ function foo() { >o : Symbol(o, Decl(index.js, 2, 41)) }; - exports.methods = methods; ->exports : Symbol(methods, Decl(index.js, 4, 6)) ->methods : Symbol(methods, Decl(index.js, 4, 6)) + const m = function () { +>m : Symbol(m, Decl(index.js, 5, 9)) + + // I have no idea what to put here + } + exports.methods = m; +>exports : Symbol(methods, Decl(index.js, 7, 5)) +>methods : Symbol(methods, Decl(index.js, 7, 5)) +>m : Symbol(m, Decl(index.js, 5, 9)) } + diff --git a/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.types b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.types index c58351d7a668b..dab4aaf35fcf0 100644 --- a/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.types +++ b/tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.types @@ -30,10 +30,17 @@ function foo() { >descriptors : error }; - exports.methods = methods; ->exports.methods = methods : error + const m = function () { +>m : () => void +>function () { // I have no idea what to put here } : () => void + + // I have no idea what to put here + } + exports.methods = m; +>exports.methods = m : () => void >exports.methods : any >exports : any >methods : any ->methods : error +>m : () => void } + diff --git a/tests/baselines/reference/jsDeclarationsFunctionsCjs.js b/tests/baselines/reference/jsDeclarationsFunctionsCjs.js index 41d6e017dbd58..3a7513d85ba9a 100644 --- a/tests/baselines/reference/jsDeclarationsFunctionsCjs.js +++ b/tests/baselines/reference/jsDeclarationsFunctionsCjs.js @@ -130,6 +130,12 @@ export namespace f { import self = f; export { self }; } +export function i(): void; +export function ii(): void; +export function jj(): void; +export function j(): void; +declare class Cls { +} /** * @param {{x: string}} a * @param {{y: typeof module.exports.b}} b @@ -146,7 +152,7 @@ export function g(a: { * @param {{x: string}} a * @param {{y: typeof module.exports.b}} b */ -export function h(a: { +declare function hh(a: { x: string; }, b: { y: { @@ -154,10 +160,4 @@ export function h(a: { cat: string; }; }): void; -export function i(): void; -export function ii(): void; -export function jj(): void; -export function j(): void; -declare class Cls { -} -export {}; +export { hh as h }; diff --git a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.errors.txt b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.errors.txt deleted file mode 100644 index c771f9c9d664d..0000000000000 --- a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.errors.txt +++ /dev/null @@ -1,55 +0,0 @@ -tests/cases/conformance/jsdoc/declarations/file2.js(12,31): error TS2694: Namespace '"tests/cases/conformance/jsdoc/declarations/file".myTypes' has no exported member 'typeC'. - - -==== tests/cases/conformance/jsdoc/declarations/file2.js (1 errors) ==== - const {myTypes} = require('./file.js'); - - /** - * @namespace testFnTypes - * @global - * @type {Object} - */ - const testFnTypes = { - // SOME PROPS HERE - }; - - /** @typedef {boolean|myTypes.typeC} testFnTypes.input */ - ~~~~~ -!!! error TS2694: Namespace '"tests/cases/conformance/jsdoc/declarations/file".myTypes' has no exported member 'typeC'. - - /** - * @function testFn - * @description A test function. - * @param {testFnTypes.input} input - Input. - * @returns {number|null} Result. - */ - function testFn(input) { - if (typeof input === 'number') { - return 2 * input; - } else { - return null; - } - } - - module.exports = {testFn, testFnTypes}; -==== tests/cases/conformance/jsdoc/declarations/file.js (0 errors) ==== - /** - * @namespace myTypes - * @global - * @type {Object} - */ - const myTypes = { - // SOME PROPS HERE - }; - - /** @typedef {string|RegExp|Array} myTypes.typeA */ - - /** - * @typedef myTypes.typeB - * @property {myTypes.typeA} prop1 - Prop 1. - * @property {string} prop2 - Prop 2. - */ - - /** @typedef {myTypes.typeB|Function} myTypes.typeC */ - - exports.myTypes = myTypes; \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js index 0c0e0ba34cc52..aeaa3107de27f 100644 --- a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js +++ b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js @@ -54,9 +54,28 @@ module.exports = {testFn, testFnTypes}; //// [file.d.ts] -export var myTypes: { +/** + * @namespace myTypes + * @global + * @type {Object} + */ +export const myTypes: { [x: string]: any; }; +export namespace myTypes { + type typeA = string | RegExp | (string | RegExp)[]; + type typeB = { + /** + * - Prop 1. + */ + prop1: string | RegExp | (string | RegExp)[]; + /** + * - Prop 2. + */ + prop2: string; + }; + type typeC = Function | typeB; +} //// [file2.d.ts] /** @typedef {boolean|myTypes.typeC} testFnTypes.input */ /** @@ -65,7 +84,16 @@ export var myTypes: { * @param {testFnTypes.input} input - Input. * @returns {number|null} Result. */ -export function testFn(input: any): number | null; +export function testFn(input: boolean | Function | { + /** + * - Prop 1. + */ + prop1: string | RegExp | (string | RegExp)[]; + /** + * - Prop 2. + */ + prop2: string; +}): number | null; /** * @namespace testFnTypes * @global @@ -75,5 +103,14 @@ export const testFnTypes: { [x: string]: any; }; export namespace testFnTypes { - type input = any; + type input = boolean | Function | { + /** + * - Prop 1. + */ + prop1: string | RegExp | (string | RegExp)[]; + /** + * - Prop 2. + */ + prop2: string; + }; } diff --git a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.types b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.types index fd1aae4d8ca5e..6af711dea185c 100644 --- a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.types +++ b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.types @@ -27,18 +27,18 @@ const testFnTypes = { */ function testFn(input) { >testFn : (input: testFnTypes.input) => number | null ->input : any +>input : boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; } if (typeof input === 'number') { >typeof input === 'number' : boolean >typeof input : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" ->input : any +>input : boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; } >'number' : "number" return 2 * input; >2 * input : number >2 : 2 ->input : number +>input : never } else { return null; @@ -47,12 +47,12 @@ function testFn(input) { } module.exports = {testFn, testFnTypes}; ->module.exports = {testFn, testFnTypes} : { testFn: (input: any) => number; testFnTypes: { [x: string]: any; }; } ->module.exports : { testFn: (input: any) => number; testFnTypes: { [x: string]: any; }; } ->module : { "\"tests/cases/conformance/jsdoc/declarations/file2\"": { testFn: (input: any) => number; testFnTypes: { [x: string]: any; }; }; } ->exports : { testFn: (input: any) => number; testFnTypes: { [x: string]: any; }; } ->{testFn, testFnTypes} : { testFn: (input: any) => number; testFnTypes: { [x: string]: any; }; } ->testFn : (input: any) => number +>module.exports = {testFn, testFnTypes} : { testFn: (input: boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; }) => number; testFnTypes: { [x: string]: any; }; } +>module.exports : { testFn: (input: boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; }) => number; testFnTypes: { [x: string]: any; }; } +>module : { "\"tests/cases/conformance/jsdoc/declarations/file2\"": { testFn: (input: boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; }) => number; testFnTypes: { [x: string]: any; }; }; } +>exports : { testFn: (input: boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; }) => number; testFnTypes: { [x: string]: any; }; } +>{testFn, testFnTypes} : { testFn: (input: boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; }) => number; testFnTypes: { [x: string]: any; }; } +>testFn : (input: boolean | Function | { prop1: string | RegExp | (string | RegExp)[]; prop2: string; }) => number >testFnTypes : { [x: string]: any; } === tests/cases/conformance/jsdoc/declarations/file.js === diff --git a/tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.types b/tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.types index 49b85f1f06361..0c6d7515d300e 100644 --- a/tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.types +++ b/tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.types @@ -19,11 +19,11 @@ module.exports.C = C /** @param {X} c */ function demo(c) { >demo : (c: X) => void ->c : C +>c : import("tests/cases/conformance/jsdoc/mod1").C c.s >c.s : () => void ->c : C +>c : import("tests/cases/conformance/jsdoc/mod1").C >s : () => void } diff --git a/tests/baselines/reference/jsdocTypeFromChainedAssignment3.symbols b/tests/baselines/reference/jsdocTypeFromChainedAssignment3.symbols index 33389d753639f..685009210f3ea 100644 --- a/tests/baselines/reference/jsdocTypeFromChainedAssignment3.symbols +++ b/tests/baselines/reference/jsdocTypeFromChainedAssignment3.symbols @@ -297,5 +297,5 @@ exports.wrapSync = exports.selectSeries = exports.selectLimit = exports.select = >exports.apply : Symbol(apply, Decl(a.js, 0, 1900)) >exports : Symbol(apply, Decl(a.js, 0, 1900)) >apply : Symbol(apply, Decl(a.js, 0, 1900)) ->undefined : Symbol(undefined) +>undefined : Symbol(apply) diff --git a/tests/baselines/reference/jsdocTypeFromChainedAssignment3.types b/tests/baselines/reference/jsdocTypeFromChainedAssignment3.types index 58605205ea3c9..7950174398922 100644 --- a/tests/baselines/reference/jsdocTypeFromChainedAssignment3.types +++ b/tests/baselines/reference/jsdocTypeFromChainedAssignment3.types @@ -393,8 +393,8 @@ exports.wrapSync = exports.selectSeries = exports.selectLimit = exports.select = >exports : typeof import("tests/cases/conformance/jsdoc/a") >applyEach : any >exports.apply = undefined : undefined ->exports.apply : any +>exports.apply : undefined >exports : typeof import("tests/cases/conformance/jsdoc/a") ->apply : any +>apply : undefined >undefined : undefined diff --git a/tests/baselines/reference/lateBoundAssignmentDeclarationSupport4.types b/tests/baselines/reference/lateBoundAssignmentDeclarationSupport4.types index 0c8199d0fcbab..ab76826b9a4cc 100644 --- a/tests/baselines/reference/lateBoundAssignmentDeclarationSupport4.types +++ b/tests/baselines/reference/lateBoundAssignmentDeclarationSupport4.types @@ -6,22 +6,22 @@ const x = require("./lateBoundAssignmentDeclarationSupport4.js"); >"./lateBoundAssignmentDeclarationSupport4.js" : "./lateBoundAssignmentDeclarationSupport4.js" const inst = new x.F(); ->inst : F ->new x.F() : F ->x.F : typeof F +>inst : x.F +>new x.F() : x.F +>x.F : typeof x.F >x : typeof x ->F : typeof F +>F : typeof x.F const y = inst["my-fake-sym"]; >y : any >inst["my-fake-sym"] : any ->inst : F +>inst : x.F >"my-fake-sym" : "my-fake-sym" const z = inst[x.S]; >z : any >inst[x.S] : any ->inst : F +>inst : x.F >x.S : unique symbol >x : typeof x >S : unique symbol diff --git a/tests/baselines/reference/lateBoundAssignmentDeclarationSupport5.types b/tests/baselines/reference/lateBoundAssignmentDeclarationSupport5.types index d5b65354374ca..ec6fbfadb2aac 100644 --- a/tests/baselines/reference/lateBoundAssignmentDeclarationSupport5.types +++ b/tests/baselines/reference/lateBoundAssignmentDeclarationSupport5.types @@ -6,22 +6,22 @@ const x = require("./lateBoundAssignmentDeclarationSupport5.js"); >"./lateBoundAssignmentDeclarationSupport5.js" : "./lateBoundAssignmentDeclarationSupport5.js" const inst = new x.F(); ->inst : F ->new x.F() : F ->x.F : typeof F +>inst : x.F +>new x.F() : x.F +>x.F : typeof x.F >x : typeof x ->F : typeof F +>F : typeof x.F const y = inst["my-fake-sym"]; >y : any >inst["my-fake-sym"] : any ->inst : F +>inst : x.F >"my-fake-sym" : "my-fake-sym" const z = inst[x.S]; >z : any >inst[x.S] : any ->inst : F +>inst : x.F >x.S : unique symbol >x : typeof x >S : unique symbol diff --git a/tests/baselines/reference/lateBoundAssignmentDeclarationSupport6.types b/tests/baselines/reference/lateBoundAssignmentDeclarationSupport6.types index 54d6ca94a9e1b..e25880167c6a9 100644 --- a/tests/baselines/reference/lateBoundAssignmentDeclarationSupport6.types +++ b/tests/baselines/reference/lateBoundAssignmentDeclarationSupport6.types @@ -6,22 +6,22 @@ const x = require("./lateBoundAssignmentDeclarationSupport6.js"); >"./lateBoundAssignmentDeclarationSupport6.js" : "./lateBoundAssignmentDeclarationSupport6.js" const inst = new x.F(); ->inst : F ->new x.F() : F ->x.F : typeof F +>inst : x.F +>new x.F() : x.F +>x.F : typeof x.F >x : typeof x ->F : typeof F +>F : typeof x.F const y = inst["my-fake-sym"]; >y : any >inst["my-fake-sym"] : any ->inst : F +>inst : x.F >"my-fake-sym" : "my-fake-sym" const z = inst[x.S]; >z : any >inst[x.S] : any ->inst : F +>inst : x.F >x.S : unique symbol >x : typeof x >S : unique symbol diff --git a/tests/baselines/reference/lateBoundAssignmentDeclarationSupport7.symbols b/tests/baselines/reference/lateBoundAssignmentDeclarationSupport7.symbols index 434f00ed278fe..12281050f5805 100644 --- a/tests/baselines/reference/lateBoundAssignmentDeclarationSupport7.symbols +++ b/tests/baselines/reference/lateBoundAssignmentDeclarationSupport7.symbols @@ -9,7 +9,7 @@ const y = x.F["my-fake-sym"]; >x.F : Symbol(x.F, Decl(lateBoundAssignmentDeclarationSupport7.js, 6, 15)) >x : Symbol(x, Decl(usage.js, 0, 5)) >F : Symbol(x.F, Decl(lateBoundAssignmentDeclarationSupport7.js, 6, 15)) ->"my-fake-sym" : Symbol(F.F[_str], Decl(lateBoundAssignmentDeclarationSupport7.js, 5, 15)) +>"my-fake-sym" : Symbol(x.F.F[_str], Decl(lateBoundAssignmentDeclarationSupport7.js, 5, 15)) const z = x.F[x.S]; >z : Symbol(z, Decl(usage.js, 2, 5)) diff --git a/tests/baselines/reference/lateBoundAssignmentDeclarationSupport7.types b/tests/baselines/reference/lateBoundAssignmentDeclarationSupport7.types index d0d472cb20ad4..8b0266457b6d3 100644 --- a/tests/baselines/reference/lateBoundAssignmentDeclarationSupport7.types +++ b/tests/baselines/reference/lateBoundAssignmentDeclarationSupport7.types @@ -8,17 +8,17 @@ const x = require("./lateBoundAssignmentDeclarationSupport7.js"); const y = x.F["my-fake-sym"]; >y : string >x.F["my-fake-sym"] : string ->x.F : typeof F +>x.F : typeof x.F >x : typeof x ->F : typeof F +>F : typeof x.F >"my-fake-sym" : "my-fake-sym" const z = x.F[x.S]; >z : string >x.F[x.S] : string ->x.F : typeof F +>x.F : typeof x.F >x : typeof x ->F : typeof F +>F : typeof x.F >x.S : unique symbol >x : typeof x >S : unique symbol diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportDoubleAssignmentInClosure.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportDoubleAssignmentInClosure.ts index bcb7644f8bd58..9d5b109332119 100644 --- a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportDoubleAssignmentInClosure.ts +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportDoubleAssignmentInClosure.ts @@ -8,5 +8,8 @@ function foo() { module.exports = exports = function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); }; - exports.methods = methods; -} \ No newline at end of file + const m = function () { + // I have no idea what to put here + } + exports.methods = m; +} diff --git a/tests/cases/conformance/salsa/commonJSImportClassTypeReference.ts b/tests/cases/conformance/salsa/commonJSImportClassTypeReference.ts new file mode 100644 index 0000000000000..932b73f54e647 --- /dev/null +++ b/tests/cases/conformance/salsa/commonJSImportClassTypeReference.ts @@ -0,0 +1,20 @@ +// @allowJs: true +// @checkJs: true +// @strict: true +// @outDir: out +// @declaration: true + +// @filename: main.js +const { K } = require("./mod1"); +/** @param {K} k */ +function f(k) { + k.values() +} + +// @filename: mod1.js +class K { + values() { + } +} +exports.K = K; +// export { K } diff --git a/tests/cases/fourslash/goToDefinitionImportedNames10.ts b/tests/cases/fourslash/goToDefinitionImportedNames10.ts index faa9ed745cc36..ebf2bb2f92435 100644 --- a/tests/cases/fourslash/goToDefinitionImportedNames10.ts +++ b/tests/cases/fourslash/goToDefinitionImportedNames10.ts @@ -2,10 +2,10 @@ // @allowjs: true // @Filename: a.js -//// class Class { +//// class /*classDefinition*/Class { //// f; //// } -//// module.exports./*classDefinition*/Class = Class; +//// module.exports.Class = Class; // @Filename: b.js ////const { Class } = require("./a"); diff --git a/tests/cases/fourslash/server/completionEntryDetailAcrossFiles01.ts b/tests/cases/fourslash/server/completionEntryDetailAcrossFiles01.ts index 005f42f82bceb..16b6b80c59d9e 100644 --- a/tests/cases/fourslash/server/completionEntryDetailAcrossFiles01.ts +++ b/tests/cases/fourslash/server/completionEntryDetailAcrossFiles01.ts @@ -17,5 +17,5 @@ const entry = (text: string): FourSlashInterface.ExpectedCompletionEntry => ({ name: "foo", text, documentation: "Modify the parameter", tags: [{ name: "param", text: "p1" }] }); verify.completions( { marker: "1", includes: entry("var foo: (p1: string) => void") }, - { marker: "2", exact: entry("(property) a.foo: (p1: string) => void") }, + { marker: "2", exact: entry("(alias) var foo: (p1: string) => void\nimport a.foo") }, ); diff --git a/tests/cases/fourslash/server/completionEntryDetailAcrossFiles02.ts b/tests/cases/fourslash/server/completionEntryDetailAcrossFiles02.ts index d915c55e32053..03aeee3b0ed1f 100644 --- a/tests/cases/fourslash/server/completionEntryDetailAcrossFiles02.ts +++ b/tests/cases/fourslash/server/completionEntryDetailAcrossFiles02.ts @@ -16,5 +16,5 @@ verify.completions( { marker: "1", includes: { name: "foo", text: "var foo: (p1: string) => void", documentation: "Modify the parameter", tags: [{ name: "param", text: "p1" }] } }, - { marker: "2", exact: { name: "foo", text: "(property) a.foo: (p1: string) => void", documentation: "Modify the parameter", tags: [{ name: "param", text: "p1" }] } }, + { marker: "2", exact: { name: "foo", text: "(alias) var foo: (p1: string) => void\nimport a.foo", documentation: "Modify the parameter", tags: [{ name: "param", text: "p1" }] } }, ); diff --git a/tests/cases/fourslash/syntheticImportFromBabelGeneratedFile1.ts b/tests/cases/fourslash/syntheticImportFromBabelGeneratedFile1.ts index 4dd0654a897df..9a42d0923038b 100644 --- a/tests/cases/fourslash/syntheticImportFromBabelGeneratedFile1.ts +++ b/tests/cases/fourslash/syntheticImportFromBabelGeneratedFile1.ts @@ -16,5 +16,5 @@ ////import f from "./a" /////**/f -verify.quickInfoAt("", `(alias) (property) f: (t: string) => void -import f`, "Run this function"); // Passes \ No newline at end of file +verify.quickInfoAt("", `(alias) function f(t: string): void +import f`, "Run this function"); // Passes diff --git a/tests/cases/fourslash/syntheticImportFromBabelGeneratedFile2.ts b/tests/cases/fourslash/syntheticImportFromBabelGeneratedFile2.ts index 0cfb4e684542c..3b01723109a6e 100644 --- a/tests/cases/fourslash/syntheticImportFromBabelGeneratedFile2.ts +++ b/tests/cases/fourslash/syntheticImportFromBabelGeneratedFile2.ts @@ -18,5 +18,5 @@ ////import f from "./a" /////**/f -verify.quickInfoAt("", `(alias) (property) f: (t: string) => void -import f`, "Run this function"); // Passes \ No newline at end of file +verify.quickInfoAt("", `(alias) function f(t: string): void +import f`, "Run this function"); // Passes