From 318e9573779136a169dc4a7c0da3d918389d7cce Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 13 Jun 2016 23:33:23 -0700 Subject: [PATCH 1/4] Added tests. --- .../shorthandOfExportedEntity01_targetES2015_CommonJS.ts | 9 +++++++++ .../shorthandOfExportedEntity02_targetES5_CommonJS.ts | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts create mode 100644 tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts diff --git a/tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts b/tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts new file mode 100644 index 0000000000000..25328afd6ce2f --- /dev/null +++ b/tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts @@ -0,0 +1,9 @@ +// @target: ES2015 +// @module: commonjs +// @declaration: true + +export const test = "test"; + +export function foo () { + const x = { test }; +} diff --git a/tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts b/tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts new file mode 100644 index 0000000000000..c7b3a2b37ecfe --- /dev/null +++ b/tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts @@ -0,0 +1,9 @@ +// @target: ES5 +// @module: commonjs +// @declaration: true + +export const test = "test"; + +export function foo () { + const x = { test }; +} From d54094c6f7533a76c11c0bbb98148c62146f28e8 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 13 Jun 2016 23:33:36 -0700 Subject: [PATCH 2/4] Accepted baselines. --- ...fExportedEntity01_targetES2015_CommonJS.js | 21 +++++++++++++++++++ ...rtedEntity01_targetES2015_CommonJS.symbols | 13 ++++++++++++ ...portedEntity01_targetES2015_CommonJS.types | 15 +++++++++++++ ...ndOfExportedEntity02_targetES5_CommonJS.js | 21 +++++++++++++++++++ ...xportedEntity02_targetES5_CommonJS.symbols | 13 ++++++++++++ ...fExportedEntity02_targetES5_CommonJS.types | 15 +++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js create mode 100644 tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.symbols create mode 100644 tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types create mode 100644 tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js create mode 100644 tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.symbols create mode 100644 tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js new file mode 100644 index 0000000000000..dbbc72fead3ae --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js @@ -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.foo = foo; + + +//// [shorthandOfExportedEntity01_targetES2015_CommonJS.d.ts] +export declare const test: string; +export declare function foo(): void; diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.symbols b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.symbols new file mode 100644 index 0000000000000..341d40bc5429e --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.symbols @@ -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)) +} + diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types new file mode 100644 index 0000000000000..dcc04015993d3 --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types @@ -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 +} + diff --git a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js new file mode 100644 index 0000000000000..764739705c4e1 --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js @@ -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; diff --git a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.symbols b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.symbols new file mode 100644 index 0000000000000..3b0b40922c9a8 --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.symbols @@ -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)) +} + diff --git a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types new file mode 100644 index 0000000000000..27d16e2166f6e --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types @@ -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 +} + From eae289c7b7e645e14f9d1655e918d0c4660f903f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 13 Jun 2016 23:33:47 -0700 Subject: [PATCH 3/4] Emit 'exports.' if the shorthand is a general export. --- src/compiler/emitter.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 46362bd782768..411c04945463c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -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) { From e8a7e0c0d41fa524ddb7912d0b335abce7e4b1ea Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 13 Jun 2016 23:34:00 -0700 Subject: [PATCH 4/4] Accepted baselines. --- .../shorthandOfExportedEntity01_targetES2015_CommonJS.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js index dbbc72fead3ae..9e057951b3a66 100644 --- a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js @@ -11,7 +11,7 @@ export function foo () { "use strict"; exports.test = "test"; function foo() { - const x = { test }; + const x = { test: exports.test }; } exports.foo = foo;