mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 12:15:34 -06:00
Merge pull request #9151 from Microsoft/commonjsShorthands
Fix emit for shorthand properties when they refer to CommonJS exports.
This commit is contained in:
commit
8917ddf8a1
@ -2150,9 +2150,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
}
|
||||
|
||||
// Return true if identifier resolves to an exported member of a namespace
|
||||
function isNamespaceExportReference(node: Identifier) {
|
||||
function isExportReference(node: Identifier) {
|
||||
const container = resolver.getReferencedExportContainer(node);
|
||||
return container && container.kind !== SyntaxKind.SourceFile;
|
||||
return !!container;
|
||||
}
|
||||
|
||||
// Return true if identifier resolves to an imported identifier
|
||||
@ -2185,10 +2185,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
// const foo_1 = require('./foo');
|
||||
// exports.baz = { foo: foo_1.foo };
|
||||
//
|
||||
if (languageVersion < ScriptTarget.ES6 || (modulekind !== ModuleKind.ES6 && isImportedReference(node.name)) || isNamespaceExportReference(node.name) ) {
|
||||
if (languageVersion < ScriptTarget.ES6 || (modulekind !== ModuleKind.ES6 && isImportedReference(node.name)) || isExportReference(node.name)) {
|
||||
// Emit identifier as an identifier
|
||||
write(": ");
|
||||
emit(node.name);
|
||||
emitExpressionIdentifier(node.name);
|
||||
}
|
||||
|
||||
if (languageVersion >= ScriptTarget.ES6 && node.objectAssignmentInitializer) {
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
//// [shorthandOfExportedEntity01_targetES2015_CommonJS.ts]
|
||||
|
||||
export const test = "test";
|
||||
|
||||
export function foo () {
|
||||
const x = { test };
|
||||
}
|
||||
|
||||
|
||||
//// [shorthandOfExportedEntity01_targetES2015_CommonJS.js]
|
||||
"use strict";
|
||||
exports.test = "test";
|
||||
function foo() {
|
||||
const x = { test: exports.test };
|
||||
}
|
||||
exports.foo = foo;
|
||||
|
||||
|
||||
//// [shorthandOfExportedEntity01_targetES2015_CommonJS.d.ts]
|
||||
export declare const test: string;
|
||||
export declare function foo(): void;
|
||||
@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts ===
|
||||
|
||||
export const test = "test";
|
||||
>test : Symbol(test, Decl(shorthandOfExportedEntity01_targetES2015_CommonJS.ts, 1, 12))
|
||||
|
||||
export function foo () {
|
||||
>foo : Symbol(foo, Decl(shorthandOfExportedEntity01_targetES2015_CommonJS.ts, 1, 27))
|
||||
|
||||
const x = { test };
|
||||
>x : Symbol(x, Decl(shorthandOfExportedEntity01_targetES2015_CommonJS.ts, 4, 7))
|
||||
>test : Symbol(test, Decl(shorthandOfExportedEntity01_targetES2015_CommonJS.ts, 4, 13))
|
||||
}
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts ===
|
||||
|
||||
export const test = "test";
|
||||
>test : string
|
||||
>"test" : string
|
||||
|
||||
export function foo () {
|
||||
>foo : () => void
|
||||
|
||||
const x = { test };
|
||||
>x : { test: string; }
|
||||
>{ test } : { test: string; }
|
||||
>test : string
|
||||
}
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
//// [shorthandOfExportedEntity02_targetES5_CommonJS.ts]
|
||||
|
||||
export const test = "test";
|
||||
|
||||
export function foo () {
|
||||
const x = { test };
|
||||
}
|
||||
|
||||
|
||||
//// [shorthandOfExportedEntity02_targetES5_CommonJS.js]
|
||||
"use strict";
|
||||
exports.test = "test";
|
||||
function foo() {
|
||||
var x = { test: exports.test };
|
||||
}
|
||||
exports.foo = foo;
|
||||
|
||||
|
||||
//// [shorthandOfExportedEntity02_targetES5_CommonJS.d.ts]
|
||||
export declare const test: string;
|
||||
export declare function foo(): void;
|
||||
@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts ===
|
||||
|
||||
export const test = "test";
|
||||
>test : Symbol(test, Decl(shorthandOfExportedEntity02_targetES5_CommonJS.ts, 1, 12))
|
||||
|
||||
export function foo () {
|
||||
>foo : Symbol(foo, Decl(shorthandOfExportedEntity02_targetES5_CommonJS.ts, 1, 27))
|
||||
|
||||
const x = { test };
|
||||
>x : Symbol(x, Decl(shorthandOfExportedEntity02_targetES5_CommonJS.ts, 4, 7))
|
||||
>test : Symbol(test, Decl(shorthandOfExportedEntity02_targetES5_CommonJS.ts, 4, 13))
|
||||
}
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts ===
|
||||
|
||||
export const test = "test";
|
||||
>test : string
|
||||
>"test" : string
|
||||
|
||||
export function foo () {
|
||||
>foo : () => void
|
||||
|
||||
const x = { test };
|
||||
>x : { test: string; }
|
||||
>{ test } : { test: string; }
|
||||
>test : string
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
// @target: ES2015
|
||||
// @module: commonjs
|
||||
// @declaration: true
|
||||
|
||||
export const test = "test";
|
||||
|
||||
export function foo () {
|
||||
const x = { test };
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
// @target: ES5
|
||||
// @module: commonjs
|
||||
// @declaration: true
|
||||
|
||||
export const test = "test";
|
||||
|
||||
export function foo () {
|
||||
const x = { test };
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user