mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 02:35:48 -05:00
only emit use strict if a use strict prologue isnt found
This commit is contained in:
@@ -7383,8 +7383,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
write(`], function(${exportFunctionForFile}) {`);
|
||||
writeLine();
|
||||
increaseIndent();
|
||||
emitUseStrictPrologueDirective();
|
||||
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true);
|
||||
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
|
||||
emitEmitHelpers(node);
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitSystemModuleBody(node, dependencyGroups, startIndex);
|
||||
@@ -7494,8 +7493,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
writeModuleName(node, emitRelativePathAsModuleName);
|
||||
emitAMDDependencies(node, /*includeNonAmdDependencies*/ true, emitRelativePathAsModuleName);
|
||||
increaseIndent();
|
||||
emitUseStrictPrologueDirective();
|
||||
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true);
|
||||
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
|
||||
emitExportStarHelper();
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitLinesStartingAt(node.statements, startIndex);
|
||||
@@ -7507,8 +7505,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
|
||||
function emitCommonJSModule(node: SourceFile) {
|
||||
emitUseStrictPrologueDirective();
|
||||
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
|
||||
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ true);
|
||||
emitEmitHelpers(node);
|
||||
collectExternalModuleInfo(node);
|
||||
emitExportStarHelper();
|
||||
@@ -7518,11 +7515,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitExportEquals(/*emitAsReturn*/ false);
|
||||
}
|
||||
|
||||
function emitUseStrictPrologueDirective() {
|
||||
writeLine();
|
||||
write("\"use strict\";");
|
||||
}
|
||||
|
||||
function emitUMDModule(node: SourceFile) {
|
||||
emitEmitHelpers(node);
|
||||
collectExternalModuleInfo(node);
|
||||
@@ -7542,8 +7534,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
})(`);
|
||||
emitAMDFactoryHeader(dependencyNames);
|
||||
increaseIndent();
|
||||
emitUseStrictPrologueDirective();
|
||||
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true);
|
||||
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
|
||||
emitExportStarHelper();
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitLinesStartingAt(node.statements, startIndex);
|
||||
@@ -7685,19 +7676,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
}
|
||||
|
||||
function emitDirectivePrologues(statements: Node[], startWithNewLine: boolean): number {
|
||||
function isUseStrictPrologue(node: ExpressionStatement): boolean {
|
||||
return !!(node.expression as StringLiteral).text.match(/use strict/);
|
||||
}
|
||||
|
||||
function ensureUseStrictPrologue(startWithNewLine: boolean, writeUseStrict: boolean) {
|
||||
if (writeUseStrict) {
|
||||
if (startWithNewLine) {
|
||||
writeLine();
|
||||
}
|
||||
write("\"use strict\";");
|
||||
}
|
||||
}
|
||||
|
||||
function emitDirectivePrologues(statements: Node[], startWithNewLine: boolean, ensureUseStrict?: boolean): number {
|
||||
let foundUseStrict = false;
|
||||
for (let i = 0; i < statements.length; ++i) {
|
||||
if (isPrologueDirective(statements[i])) {
|
||||
if (isUseStrictPrologue(statements[i] as ExpressionStatement)) {
|
||||
foundUseStrict = true;
|
||||
}
|
||||
if (startWithNewLine || i > 0) {
|
||||
writeLine();
|
||||
}
|
||||
emit(statements[i]);
|
||||
}
|
||||
else {
|
||||
ensureUseStrictPrologue(startWithNewLine || i > 0, !foundUseStrict && ensureUseStrict);
|
||||
// return index of the first non prologue directive
|
||||
return i;
|
||||
}
|
||||
}
|
||||
ensureUseStrictPrologue(startWithNewLine, !foundUseStrict && ensureUseStrict);
|
||||
return statements.length;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export module M {
|
||||
}
|
||||
|
||||
//// [downlevelLetConst13.js]
|
||||
"use strict";'use strict';
|
||||
'use strict';
|
||||
// exported let\const bindings should not be renamed
|
||||
exports.foo = 10;
|
||||
exports.bar = "123";
|
||||
|
||||
@@ -5,7 +5,6 @@ export class Foo {}
|
||||
|
||||
//// [modulePrologueAMD.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
"use strict";
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
export class Foo {}
|
||||
|
||||
//// [modulePrologueCommonjs.js]
|
||||
"use strict";"use strict";
|
||||
"use strict";
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ export class Foo {}
|
||||
|
||||
//// [modulePrologueSystem.js]
|
||||
System.register([], function(exports_1) {
|
||||
"use strict";
|
||||
"use strict";
|
||||
var Foo;
|
||||
return {
|
||||
|
||||
@@ -12,7 +12,6 @@ export class Foo {}
|
||||
define(["require", "exports"], factory);
|
||||
}
|
||||
})(function (require, exports) {
|
||||
"use strict";
|
||||
"use strict";
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
|
||||
@@ -7,7 +7,7 @@ export class Logger {
|
||||
|
||||
|
||||
//// [parser509546_2.js]
|
||||
"use strict";"use strict";
|
||||
"use strict";
|
||||
var Logger = (function () {
|
||||
function Logger() {
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
import public = require("1");
|
||||
|
||||
//// [strictModeReservedWordInImportEqualDeclaration.js]
|
||||
"use strict";"use strict";
|
||||
"use strict";
|
||||
|
||||
Reference in New Issue
Block a user