Skip to content

Commit dc1ac13

Browse files
author
Kanchalai Tanglertsampan
committed
Emit "__esModule" before other statments
1 parent 229ba43 commit dc1ac13

File tree

1,529 files changed

+2977
-2983
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,529 files changed

+2977
-2983
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,16 @@ namespace ts {
8383

8484
const statements: Statement[] = [];
8585
const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict, sourceElementVisitor);
86-
append(statements, visitNode(currentModuleInfo.externalHelpersImportDeclaration, sourceElementVisitor, isStatement, /*optional*/ true));
87-
addRange(statements, visitNodes(node.statements, sourceElementVisitor, isStatement, statementOffset));
88-
addRange(statements, endLexicalEnvironment());
89-
addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false);
9086

9187
if (!currentModuleInfo.exportEquals) {
9288
append(statements, createUnderscoreUnderscoreESModule());
9389
}
9490

91+
append(statements, visitNode(currentModuleInfo.externalHelpersImportDeclaration, sourceElementVisitor, isStatement, /*optional*/ true));
92+
addRange(statements, visitNodes(node.statements, sourceElementVisitor, isStatement, statementOffset));
93+
addRange(statements, endLexicalEnvironment());
94+
addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false);
95+
9596
const updated = updateSourceFileNode(node, setTextRange(createNodeArray(statements), node.statements));
9697
if (currentModuleInfo.hasExportStarsToExportValues) {
9798
addEmitHelper(updated, exportStarHelper);
@@ -374,6 +375,10 @@ namespace ts {
374375
const statements: Statement[] = [];
375376
const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict, sourceElementVisitor);
376377

378+
if (!currentModuleInfo.exportEquals) {
379+
append(statements, createUnderscoreUnderscoreESModule());
380+
}
381+
377382
// Visit each statement of the module body.
378383
append(statements, visitNode(currentModuleInfo.externalHelpersImportDeclaration, sourceElementVisitor, isStatement, /*optional*/ true));
379384
addRange(statements, visitNodes(node.statements, sourceElementVisitor, isStatement, statementOffset));
@@ -385,10 +390,6 @@ namespace ts {
385390
// Append the 'export =' statement if provided.
386391
addExportEqualsIfNeeded(statements, /*emitAsReturn*/ true);
387392

388-
if (!currentModuleInfo.exportEquals) {
389-
append(statements, createUnderscoreUnderscoreESModule());
390-
}
391-
392393
const body = createBlock(statements, /*multiLine*/ true);
393394
if (currentModuleInfo.hasExportStarsToExportValues) {
394395
// If we have any `export * from ...` declarations

tests/baselines/reference/APISample_compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ compile(process.argv.slice(2), {
4141
* Please log a "breaking change" issue for any API breaking change affecting this issue
4242
*/
4343
"use strict";
44+
exports.__esModule = true;
4445
var ts = require("typescript");
4546
function compile(fileNames, options) {
4647
var program = ts.createProgram(fileNames, options);
@@ -60,4 +61,3 @@ compile(process.argv.slice(2), {
6061
noEmitOnError: true, noImplicitAny: true,
6162
target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
6263
});
63-
exports.__esModule = true;

tests/baselines/reference/APISample_linter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ fileNames.forEach(fileName => {
7171
* Please log a "breaking change" issue for any API breaking change affecting this issue
7272
*/
7373
"use strict";
74+
exports.__esModule = true;
7475
var ts = require("typescript");
7576
function delint(sourceFile) {
7677
delintNode(sourceFile);
@@ -117,4 +118,3 @@ fileNames.forEach(function (fileName) {
117118
// delint it
118119
delint(sourceFile);
119120
});
120-
exports.__esModule = true;

tests/baselines/reference/APISample_parseConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function createProgram(rootFiles: string[], compilerOptionsJson: string):
4343
* Please log a "breaking change" issue for any API breaking change affecting this issue
4444
*/
4545
"use strict";
46+
exports.__esModule = true;
4647
var ts = require("typescript");
4748
function printError(error) {
4849
if (!error) {
@@ -68,4 +69,3 @@ function createProgram(rootFiles, compilerOptionsJson) {
6869
return ts.createProgram(rootFiles, settings.options);
6970
}
7071
exports.createProgram = createProgram;
71-
exports.__esModule = true;

tests/baselines/reference/APISample_transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ console.log(JSON.stringify(result));
2323
* Please log a "breaking change" issue for any API breaking change affecting this issue
2424
*/
2525
"use strict";
26+
exports.__esModule = true;
2627
var ts = require("typescript");
2728
var source = "let x: string = 'string'";
2829
var result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
2930
console.log(JSON.stringify(result));
30-
exports.__esModule = true;

tests/baselines/reference/APISample_watcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ watch(currentDirectoryFiles, { module: ts.ModuleKind.CommonJS });
116116
* Please log a "breaking change" issue for any API breaking change affecting this issue
117117
*/
118118
"use strict";
119+
exports.__esModule = true;
119120
var ts = require("typescript");
120121
function watch(rootFileNames, options) {
121122
var files = {};
@@ -189,4 +190,3 @@ var currentDirectoryFiles = fs.readdirSync(process.cwd()).
189190
filter(function (fileName) { return fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts"; });
190191
// Start the watcher
191192
watch(currentDirectoryFiles, { module: ts.ModuleKind.CommonJS });
192-
exports.__esModule = true;

tests/baselines/reference/TwoInternalModulesThatMergeEachWithExportedLocalVarsOfTheSameName.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export module A {
3131

3232
//// [part1.js]
3333
"use strict";
34+
exports.__esModule = true;
3435
var A;
3536
(function (A) {
3637
var Utils;
@@ -42,9 +43,9 @@ var A;
4243
})(Utils = A.Utils || (A.Utils = {}));
4344
A.Origin = { x: 0, y: 0 };
4445
})(A = exports.A || (exports.A = {}));
45-
exports.__esModule = true;
4646
//// [part2.js]
4747
"use strict";
48+
exports.__esModule = true;
4849
var A;
4950
(function (A) {
5051
// collision with 'Origin' var in other part of merged module
@@ -61,4 +62,3 @@ var A;
6162
Utils.Plane = Plane;
6263
})(Utils = A.Utils || (A.Utils = {}));
6364
})(A = exports.A || (exports.A = {}));
64-
exports.__esModule = true;

tests/baselines/reference/aliasAssignments.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ y = moduleA; // should be error
1515

1616
//// [aliasAssignments_moduleA.js]
1717
"use strict";
18+
exports.__esModule = true;
1819
var someClass = (function () {
1920
function someClass() {
2021
}
2122
return someClass;
2223
}());
2324
exports.someClass = someClass;
24-
exports.__esModule = true;
2525
//// [aliasAssignments_1.js]
2626
"use strict";
27+
exports.__esModule = true;
2728
var moduleA = require("./aliasAssignments_moduleA");
2829
var x = moduleA;
2930
x = 1; // Should be error
3031
var y = 1;
3132
y = moduleA; // should be error
32-
exports.__esModule = true;

tests/baselines/reference/aliasOnMergedModuleInterface.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var x: foo.A = foo.bar("hello"); // foo.A should be ok but foo.bar should be err
2424
//// [aliasOnMergedModuleInterface_0.js]
2525
//// [aliasOnMergedModuleInterface_1.js]
2626
"use strict";
27+
exports.__esModule = true;
2728
var z;
2829
z.bar("hello"); // This should be ok
2930
var x = foo.bar("hello"); // foo.A should be ok but foo.bar should be error
30-
exports.__esModule = true;

tests/baselines/reference/aliasUsageInAccessorsOfClass.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ class C2 {
2929

3030
//// [aliasUsage1_backbone.js]
3131
"use strict";
32+
Object.defineProperty(exports, "__esModule", { value: true });
3233
var Model = (function () {
3334
function Model() {
3435
}
3536
return Model;
3637
}());
3738
exports.Model = Model;
38-
Object.defineProperty(exports, "__esModule", { value: true });
3939
//// [aliasUsage1_moduleA.js]
4040
"use strict";
4141
var __extends = (this && this.__extends) || (function () {
@@ -48,6 +48,7 @@ var __extends = (this && this.__extends) || (function () {
4848
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
4949
};
5050
})();
51+
Object.defineProperty(exports, "__esModule", { value: true });
5152
var Backbone = require("./aliasUsage1_backbone");
5253
var VisualizationModel = (function (_super) {
5354
__extends(VisualizationModel, _super);
@@ -57,9 +58,9 @@ var VisualizationModel = (function (_super) {
5758
return VisualizationModel;
5859
}(Backbone.Model));
5960
exports.VisualizationModel = VisualizationModel;
60-
Object.defineProperty(exports, "__esModule", { value: true });
6161
//// [aliasUsage1_main.js]
6262
"use strict";
63+
Object.defineProperty(exports, "__esModule", { value: true });
6364
var moduleA = require("./aliasUsage1_moduleA");
6465
var C2 = (function () {
6566
function C2() {
@@ -76,4 +77,3 @@ var C2 = (function () {
7677
});
7778
return C2;
7879
}());
79-
Object.defineProperty(exports, "__esModule", { value: true });

0 commit comments

Comments
 (0)