TypeScript/tests/baselines/reference/moduleExportWithExportPropertyAssignment2.types
Nathan Shively-Sanders aba932aefa
Create synthetic exports symbol for commonjs module (#42655)
* Commonjs module:create synthetic exports symbol

Previously, the `module` identifier in commonjs modules got a synthetic
type with a single property `exports`. The exports property reused the
file's symbol, which, for a module file, gives the correct exported
properties.

However, the name of this symbol was still the filename of the file, not
`exports`. This PR creates a synthetic symbol for `exports` by copying
in a similar way to esModuleInterop's `default` symbol in
`resolveESModuleSymbol` (although the intent there is to strip off
signatures from the symbol).

* correct parent of synthetic symbol
2021-02-05 10:56:03 -08:00

49 lines
1.2 KiB
Plaintext

=== tests/cases/conformance/salsa/a.js ===
/// <reference path='./requires.d.ts' />
var mod1 = require('./mod1')
>mod1 : number
>require('./mod1') : number
>require : (name: string) => any
>'./mod1' : "./mod1"
mod1.toFixed(12)
>mod1.toFixed(12) : string
>mod1.toFixed : (fractionDigits?: number) => string
>mod1 : number
>toFixed : (fractionDigits?: number) => string
>12 : 12
mod1.f() // error, 'f' is not a property on 'number'
>mod1.f() : any
>mod1.f : any
>mod1 : number
>f : any
=== tests/cases/conformance/salsa/requires.d.ts ===
declare var module: { exports: any };
>module : { exports: any; }
>exports : any
declare function require(name: string): any;
>require : (name: string) => any
>name : string
=== tests/cases/conformance/salsa/mod1.js ===
/// <reference path='./requires.d.ts' />
module.exports = 1
>module.exports = 1 : number
>module.exports : number
>module : { exports: number; }
>exports : number
>1 : 1
module.exports.f = function () { }
>module.exports.f = function () { } : () => void
>module.exports.f : any
>module.exports : number
>module : { exports: number; }
>exports : number
>f : any
>function () { } : () => void