Feedback from PR

This commit is contained in:
Wesley Wigham 2015-09-17 13:26:04 -07:00
parent f2b901a3c7
commit 8d6cb5fbb5
3 changed files with 27 additions and 29 deletions

View File

@ -44,6 +44,7 @@ namespace ts {
let compilerOptions = host.getCompilerOptions();
let languageVersion = compilerOptions.target || ScriptTarget.ES3;
var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None;
let emitResolver = createResolver();
@ -13379,7 +13380,7 @@ namespace ts {
}
}
else {
if (compilerOptions.module === ModuleKind.ES6 && !isInAmbientContext(node)) {
if (modulekind === ModuleKind.ES6 && !isInAmbientContext(node)) {
// Import equals declaration is deprecated in es6 or above
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
}
@ -13456,11 +13457,11 @@ namespace ts {
checkExternalModuleExports(<SourceFile | ModuleDeclaration>container);
if (node.isExportEquals && !isInAmbientContext(node)) {
if (compilerOptions.module === ModuleKind.ES6) {
if (modulekind === ModuleKind.ES6) {
// export assignment is not supported in es6 modules
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead);
}
else if (compilerOptions.module === ModuleKind.System) {
else if (modulekind === ModuleKind.System) {
// system modules does not support export assignment
grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
}

View File

@ -64,6 +64,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
let compilerOptions = host.getCompilerOptions();
let languageVersion = compilerOptions.target || ScriptTarget.ES3;
var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None;
let sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined;
let diagnostics: Diagnostic[] = [];
let newLine = host.getNewLine();
@ -1501,7 +1502,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
if (container) {
if (container.kind === SyntaxKind.SourceFile) {
// Identifier references module export
if (compilerOptions.module !== ModuleKind.ES6 && compilerOptions.module !== ModuleKind.System) {
if (modulekind !== ModuleKind.ES6 && modulekind !== ModuleKind.System) {
write("exports.");
}
}
@ -1511,7 +1512,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(".");
}
}
else if (compilerOptions.module !== ModuleKind.ES6) {
else if (modulekind !== ModuleKind.ES6) {
let declaration = resolver.getReferencedImportDeclaration(node);
if (declaration) {
if (declaration.kind === SyntaxKind.ImportClause) {
@ -3057,7 +3058,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(getGeneratedNameForNode(container));
write(".");
}
else if (compilerOptions.module !== ModuleKind.ES6 && compilerOptions.module !== ModuleKind.System) {
else if (modulekind !== ModuleKind.ES6 && modulekind !== ModuleKind.System) {
write("exports.");
}
}
@ -3077,7 +3078,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
if (node.parent.kind === SyntaxKind.SourceFile) {
Debug.assert(!!(node.flags & NodeFlags.Default) || node.kind === SyntaxKind.ExportAssignment);
// only allow export default at a source file level
if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) {
if (modulekind === ModuleKind.CommonJS || modulekind === ModuleKind.AMD || modulekind === ModuleKind.UMD) {
if (!currentSourceFile.symbol.exports["___esModule"]) {
if (languageVersion === ScriptTarget.ES5) {
// default value of configurable, enumerable, writable are `false`.
@ -3099,7 +3100,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
emitStart(node);
// emit call to exporter only for top level nodes
if (compilerOptions.module === ModuleKind.System && node.parent === currentSourceFile) {
if (modulekind === ModuleKind.System && node.parent === currentSourceFile) {
// emit export default <smth> as
// export("default", <smth>)
write(`${exportFunctionForFile}("`);
@ -3135,7 +3136,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitExportMemberAssignments(name: Identifier) {
if (compilerOptions.module === ModuleKind.System) {
if (modulekind === ModuleKind.System) {
return;
}
@ -3155,7 +3156,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitExportSpecifierInSystemModule(specifier: ExportSpecifier): void {
Debug.assert(compilerOptions.module === ModuleKind.System);
Debug.assert(modulekind === ModuleKind.System);
if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier) ) {
return;
@ -3477,7 +3478,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
function isES6ExportedDeclaration(node: Node) {
return !!(node.flags & NodeFlags.Export) &&
compilerOptions.module === ModuleKind.ES6 &&
modulekind === ModuleKind.ES6 &&
node.parent.kind === SyntaxKind.SourceFile;
}
@ -5243,7 +5244,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(";");
}
if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) {
if (compilerOptions.module === ModuleKind.System && (node.flags & NodeFlags.Export)) {
if (modulekind === ModuleKind.System && (node.flags & NodeFlags.Export)) {
// write the call to exporter for enum
writeLine();
write(`${exportFunctionForFile}("`);
@ -5365,7 +5366,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(" = {}));");
emitEnd(node);
if (!isES6ExportedDeclaration(node) && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) {
if (compilerOptions.module === ModuleKind.System && (node.flags & NodeFlags.Export)) {
if (modulekind === ModuleKind.System && (node.flags & NodeFlags.Export)) {
writeLine();
write(`${exportFunctionForFile}("`);
emitDeclarationName(node);
@ -5429,7 +5430,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitImportDeclaration(node: ImportDeclaration) {
if (compilerOptions.module !== ModuleKind.ES6) {
if (modulekind !== ModuleKind.ES6) {
return emitExternalImportDeclaration(node);
}
@ -5480,7 +5481,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
let isExportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0;
let namespaceDeclaration = getNamespaceDeclarationNode(node);
if (compilerOptions.module !== ModuleKind.AMD) {
if (modulekind !== ModuleKind.AMD) {
emitLeadingComments(node);
emitStart(node);
if (namespaceDeclaration && !isDefaultImport(node)) {
@ -5592,15 +5593,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitExportDeclaration(node: ExportDeclaration) {
Debug.assert(compilerOptions.module !== ModuleKind.System);
Debug.assert(modulekind !== ModuleKind.System);
if (compilerOptions.module !== ModuleKind.ES6) {
if (modulekind !== ModuleKind.ES6) {
if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) {
emitStart(node);
let generatedName = getGeneratedNameForNode(node);
if (node.exportClause) {
// export { x, y, ... } from "foo"
if (compilerOptions.module !== ModuleKind.AMD) {
if (modulekind !== ModuleKind.AMD) {
write("var ");
write(generatedName);
write(" = ");
@ -5627,7 +5628,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
// export * from "foo"
writeLine();
write("__export(");
if (compilerOptions.module !== ModuleKind.AMD) {
if (modulekind !== ModuleKind.AMD) {
emitRequire(getExternalModuleName(node));
}
else {
@ -5660,7 +5661,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitExportOrImportSpecifierList(specifiers: ImportOrExportSpecifier[], shouldEmit: (node: Node) => boolean) {
Debug.assert(compilerOptions.module === ModuleKind.ES6);
Debug.assert(modulekind === ModuleKind.ES6);
let needsComma = false;
for (let specifier of specifiers) {
@ -5680,7 +5681,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
function emitExportAssignment(node: ExportAssignment) {
if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) {
if (compilerOptions.module === ModuleKind.ES6) {
if (modulekind === ModuleKind.ES6) {
writeLine();
emitStart(node);
write("export default ");
@ -5695,7 +5696,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
else {
writeLine();
emitStart(node);
if (compilerOptions.module === ModuleKind.System) {
if (modulekind === ModuleKind.System) {
write(`${exportFunctionForFile}("default",`);
emit(node.expression);
write(")");
@ -6141,7 +6142,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function isCurrentFileSystemExternalModule() {
return compilerOptions.module === ModuleKind.System && isExternalModule(currentSourceFile);
return modulekind === ModuleKind.System && isExternalModule(currentSourceFile);
}
function emitSystemModuleBody(node: SourceFile, dependencyGroups: DependencyGroup[], startIndex: number): void {
@ -6689,7 +6690,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
}
function emitSourceFileNode(node: SourceFile) {
function emitSourceFileNode(node: SourceFile) {
// Start new file on new line
writeLine();
emitShebang();
@ -6699,7 +6700,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
if (isExternalModule(node) || compilerOptions.isolatedModules) {
let emitModule = moduleEmitDelegates[compilerOptions.module] || moduleEmitDelegates[ModuleKind.CommonJS];
let emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[ModuleKind.CommonJS];
emitModule(node, startIndex);
}
else {

View File

@ -343,10 +343,6 @@ namespace ts {
let classifiableNames: Map<string>;
let skipDefaultLib = options.noLib;
if (options.target >= ScriptTarget.ES6 && !options.module) { // Preserve old ES6 module behavior
options.module = ModuleKind.ES6;
}
let start = new Date().getTime();