Add flag to emit modules in loose mode

This commit is contained in:
Mohamed Hegazy 2016-02-03 14:16:09 -08:00
parent 1154ab8def
commit 10522f9eee
24 changed files with 158 additions and 20 deletions

View file

@ -320,6 +320,11 @@ namespace ts {
name: "allowSyntheticDefaultImports",
type: "boolean",
description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking
},
{
name: "emitModulesInLooseMode",
type: "boolean",
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
}
];

View file

@ -1,4 +1,4 @@
{
{
"Unterminated string literal.": {
"category": "Error",
"code": 1002
@ -2187,6 +2187,7 @@
"category": "Error",
"code": 5062
},
"Concatenate and emit output to single file.": {
"category": "Message",
"code": 6001
@ -2231,10 +2232,10 @@
"category": "Message",
"code": 6011
},
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": {
"category": "Message",
"code": 6015
},
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": {
"category": "Message",
"code": 6015
},
"Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'": {
"category": "Message",
"code": 6016
@ -2571,6 +2572,11 @@
"category": "Message",
"code": 6111
},
"Do not emit 'use strict' directives in module output.": {
"category": "Message",
"code": 6112
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
@ -2757,23 +2763,23 @@
"code": 17004
},
"A constructor cannot contain a 'super' call when its class extends 'null'": {
"category": "Error",
"code": 17005
"category": "Error",
"code": 17005
},
"An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
"category": "Error",
"code": 17006
"category": "Error",
"code": 17006
},
"A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
"category": "Error",
"code": 17007
"category": "Error",
"code": 17007
},
"JSX element '{0}' has no corresponding closing tag.": {
"category": "Error",
"code": 17008
"category": "Error",
"code": 17008
},
"'super' must be called before accessing 'this' in the constructor of a derived class.": {
"category": "Error",
"code": 17009
"category": "Error",
"code": 17009
}
}
}

View file

@ -7179,7 +7179,7 @@ const _super = (function (geti, seti) {
write(`], function(${exportFunctionForFile}, ${contextObjectForFile}) {`);
writeLine();
increaseIndent();
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.emitModulesInLooseMode);
writeLine();
write(`var __moduleName = ${contextObjectForFile} && ${contextObjectForFile}.id;`);
writeLine();
@ -7285,7 +7285,7 @@ const _super = (function (geti, seti) {
writeModuleName(node, emitRelativePathAsModuleName);
emitAMDDependencies(node, /*includeNonAmdDependencies*/ true, emitRelativePathAsModuleName);
increaseIndent();
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/!compilerOptions.emitModulesInLooseMode);
emitExportStarHelper();
emitCaptureThisForNodeIfNecessary(node);
emitLinesStartingAt(node.statements, startIndex);
@ -7297,7 +7297,7 @@ const _super = (function (geti, seti) {
}
function emitCommonJSModule(node: SourceFile) {
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ true);
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ !compilerOptions.emitModulesInLooseMode);
emitEmitHelpers(node);
collectExternalModuleInfo(node);
emitExportStarHelper();
@ -7326,7 +7326,7 @@ const _super = (function (geti, seti) {
})(`);
emitAMDFactoryHeader(dependencyNames);
increaseIndent();
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.emitModulesInLooseMode);
emitExportStarHelper();
emitCaptureThisForNodeIfNecessary(node);
emitLinesStartingAt(node.statements, startIndex);

View file

@ -2422,6 +2422,7 @@ namespace ts {
traceModuleResolution?: boolean;
allowSyntheticDefaultImports?: boolean;
allowJs?: boolean;
emitModulesInLooseMode?: boolean;
/* @internal */ stripInternal?: boolean;
// Skip checking lib.d.ts to help speed up tests.

View file

@ -0,0 +1,8 @@
//// [emitModulesInLooseMode_amd.ts]
export var x = 0;
//// [emitModulesInLooseMode_amd.js]
define(["require", "exports"], function (require, exports) {
exports.x = 0;
});

View file

@ -0,0 +1,5 @@
=== tests/cases/compiler/emitModulesInLooseMode_amd.ts ===
export var x = 0;
>x : Symbol(x, Decl(emitModulesInLooseMode_amd.ts, 1, 10))

View file

@ -0,0 +1,6 @@
=== tests/cases/compiler/emitModulesInLooseMode_amd.ts ===
export var x = 0;
>x : number
>0 : number

View file

@ -0,0 +1,6 @@
//// [emitModulesInLooseMode_commonjs.ts]
export var x = 0;
//// [emitModulesInLooseMode_commonjs.js]
exports.x = 0;

View file

@ -0,0 +1,5 @@
=== tests/cases/compiler/emitModulesInLooseMode_commonjs.ts ===
export var x = 0;
>x : Symbol(x, Decl(emitModulesInLooseMode_commonjs.ts, 1, 10))

View file

@ -0,0 +1,6 @@
=== tests/cases/compiler/emitModulesInLooseMode_commonjs.ts ===
export var x = 0;
>x : number
>0 : number

View file

@ -0,0 +1,6 @@
//// [emitModulesInLooseMode_es6.ts]
export var x = 0;
//// [emitModulesInLooseMode_es6.js]
export var x = 0;

View file

@ -0,0 +1,5 @@
=== tests/cases/compiler/emitModulesInLooseMode_es6.ts ===
export var x = 0;
>x : Symbol(x, Decl(emitModulesInLooseMode_es6.ts, 1, 10))

View file

@ -0,0 +1,6 @@
=== tests/cases/compiler/emitModulesInLooseMode_es6.ts ===
export var x = 0;
>x : number
>0 : number

View file

@ -0,0 +1,15 @@
//// [emitModulesInLooseMode_system.ts]
export var x = 0;
//// [emitModulesInLooseMode_system.js]
System.register([], function(exports_1, context_1) {
var __moduleName = context_1 && context_1.id;
var x;
return {
setters:[],
execute: function() {
exports_1("x", x = 0);
}
}
});

View file

@ -0,0 +1,5 @@
=== tests/cases/compiler/emitModulesInLooseMode_system.ts ===
export var x = 0;
>x : Symbol(x, Decl(emitModulesInLooseMode_system.ts, 1, 10))

View file

@ -0,0 +1,6 @@
=== tests/cases/compiler/emitModulesInLooseMode_system.ts ===
export var x = 0;
>x : number
>0 : number

View file

@ -0,0 +1,15 @@
//// [emitModulesInLooseMode_umd.ts]
export var x = 0;
//// [emitModulesInLooseMode_umd.js]
(function (factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
}
else if (typeof define === 'function' && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
exports.x = 0;
});

View file

@ -0,0 +1,5 @@
=== tests/cases/compiler/emitModulesInLooseMode_umd.ts ===
export var x = 0;
>x : Symbol(x, Decl(emitModulesInLooseMode_umd.ts, 1, 10))

View file

@ -0,0 +1,6 @@
=== tests/cases/compiler/emitModulesInLooseMode_umd.ts ===
export var x = 0;
>x : number
>0 : number

View file

@ -0,0 +1,4 @@
// @module: amd
// @emitModulesInLooseMode: true
export var x = 0;

View file

@ -0,0 +1,4 @@
// @module: commonjs
// @emitModulesInLooseMode: true
export var x = 0;

View file

@ -0,0 +1,5 @@
// @module: es6
// @target: es6
// @emitModulesInLooseMode: true
export var x = 0;

View file

@ -0,0 +1,4 @@
// @module: system
// @emitModulesInLooseMode: true
export var x = 0;

View file

@ -0,0 +1,4 @@
// @module: umd
// @emitModulesInLooseMode: true
export var x = 0;