Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace ts {

const compilerOptions = host.getCompilerOptions();
const languageVersion = compilerOptions.target || ScriptTarget.ES3;
const modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None;
const modulekind = getEmitModuleKind(compilerOptions);
const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System;

const emitResolver = createResolver();
Expand Down
25 changes: 22 additions & 3 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace ts {
name: "module",
shortName: "m",
type: {
"none": ModuleKind.None,
"commonjs": ModuleKind.CommonJS,
"amd": ModuleKind.AMD,
"system": ModuleKind.System,
Expand All @@ -87,7 +88,7 @@ namespace ts {
},
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015,
paramType: Diagnostics.KIND,
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es2015
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_es2015_or_none
},
{
name: "newLine",
Expand Down Expand Up @@ -551,7 +552,21 @@ namespace ts {
}
else {
const filesSeen: Map<boolean> = {};
const exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;

let exclude: string[] = [];
if (json["exclude"] instanceof Array) {
exclude = json["exclude"];
}
else {
// by default exclude node_modules, and any specificied output directory
exclude = ["node_modules"];
const outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"];
if (outDir) {
exclude.push(outDir);
}
}
exclude = map(exclude, normalizeSlashes);

const supportedExtensions = getSupportedExtensions(options);
Debug.assert(indexOf(supportedExtensions, ".ts") < indexOf(supportedExtensions, ".d.ts"), "Changed priority of extensions to pick");

Expand All @@ -565,6 +580,11 @@ namespace ts {
continue;
}

// Skip over any minified JavaScript files (ending in ".min.js")
if (/\.min\.js$/.test(fileName)) {
continue;
}

// If this is one of the output extension (which would be .d.ts and .js if we are allowing compilation of js files)
// do not include this file if we included .ts or .tsx file with same base name as it could be output of the earlier compilation
if (extension === ".d.ts" || (options.allowJs && contains(supportedJavascriptExtensions, extension))) {
Expand All @@ -588,7 +608,6 @@ namespace ts {
const errors: Diagnostic[] = [];

if (configFileName && getBaseFileName(configFileName) === "jsconfig.json") {
options.module = ModuleKind.CommonJS;
options.allowJs = true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@
"category": "Error",
"code": 1147
},
"Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.": {
"Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file.": {
"category": "Error",
"code": 1148
},
Expand Down Expand Up @@ -2320,7 +2320,7 @@
"category": "Error",
"code": 6045
},
"Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es2015'.": {
"Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'none'.": {
"category": "Error",
"code": 6046
},
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ namespace ts {

const firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
if (options.isolatedModules) {
if (!options.module && languageVersion < ScriptTarget.ES6) {
if (options.module === ModuleKind.None && languageVersion < ScriptTarget.ES6) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher));
}

Expand All @@ -1662,10 +1662,10 @@ namespace ts {
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
}
}
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) {
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && options.module === ModuleKind.None) {
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
const span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file));
programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file));
}

// Cannot specify module gen target of es6 when below es6
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ namespace ts {
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
return;
}
const configParseResult = parseJsonConfigFileContent(configObject, sys, getNormalizedAbsolutePath(getDirectoryPath(configFileName), sys.getCurrentDirectory()), commandLine.options);
const configParseResult = parseJsonConfigFileContent(configObject, sys, getNormalizedAbsolutePath(getDirectoryPath(configFileName), sys.getCurrentDirectory()), commandLine.options, configFileName);
if (configParseResult.errors.length > 0) {
reportDiagnostics(configParseResult.errors, /* compilerHost */ undefined);
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2011,9 +2011,9 @@ namespace ts {
}

export function getEmitModuleKind(compilerOptions: CompilerOptions) {
return compilerOptions.module ?
return typeof compilerOptions.module === "number" ?
compilerOptions.module :
getEmitScriptTarget(compilerOptions) === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None;
getEmitScriptTarget(compilerOptions) === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.CommonJS;
}

export interface EmitFileNames {
Expand Down
1 change: 0 additions & 1 deletion src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,6 @@ namespace Harness {

const options: ts.CompilerOptions & HarnessOptions = compilerOptions ? ts.clone(compilerOptions) : { noResolve: false };
options.target = options.target || ts.ScriptTarget.ES3;
options.module = options.module || ts.ModuleKind.None;
options.newLine = options.newLine || ts.NewLineKind.CarriageReturnLineFeed;
options.noErrorTruncation = true;
options.skipDefaultLibCheck = true;
Expand Down
1 change: 0 additions & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,6 @@ namespace ts {
// Always default to "ScriptTarget.ES5" for the language service
return {
target: ScriptTarget.ES5,
module: ModuleKind.None,
jsx: JsxEmit.Preserve
};
}
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/ExportAssignment7.errors.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
tests/cases/compiler/ExportAssignment7.ts(1,14): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
tests/cases/compiler/ExportAssignment7.ts(4,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
tests/cases/compiler/ExportAssignment7.ts(4,10): error TS2304: Cannot find name 'B'.


==== tests/cases/compiler/ExportAssignment7.ts (3 errors) ====
==== tests/cases/compiler/ExportAssignment7.ts (2 errors) ====
export class C {
~
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
}

export = B;
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/ExportAssignment8.errors.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
tests/cases/compiler/ExportAssignment8.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
tests/cases/compiler/ExportAssignment8.ts(1,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
tests/cases/compiler/ExportAssignment8.ts(1,10): error TS2304: Cannot find name 'B'.


==== tests/cases/compiler/ExportAssignment8.ts (3 errors) ====
==== tests/cases/compiler/ExportAssignment8.ts (2 errors) ====
export = B;
~~~~~~~~~~~
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
~~~~~~~~~~~
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.
~
!!! error TS2304: Cannot find name 'B'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
tests/cases/conformance/internalModules/DeclarationMerging/part1.ts(1,15): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
tests/cases/conformance/internalModules/DeclarationMerging/part2.ts(3,24): error TS2304: Cannot find name 'Point'.
tests/cases/conformance/internalModules/DeclarationMerging/part2.ts(7,36): error TS2304: Cannot find name 'Point'.
tests/cases/conformance/internalModules/DeclarationMerging/part2.ts(7,54): error TS2304: Cannot find name 'Point'.


==== tests/cases/conformance/internalModules/DeclarationMerging/part1.ts (1 errors) ====
==== tests/cases/conformance/internalModules/DeclarationMerging/part1.ts (0 errors) ====
export module A {
~
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
export interface Point {
x: number;
y: number;
Expand Down
28 changes: 0 additions & 28 deletions tests/baselines/reference/ambientDeclarationsExternal.errors.txt

This file was deleted.

36 changes: 36 additions & 0 deletions tests/baselines/reference/ambientDeclarationsExternal.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
=== tests/cases/conformance/ambient/consumer.ts ===
/// <reference path="decls.ts" />
import imp1 = require('equ');
>imp1 : Symbol(imp1, Decl(consumer.ts, 0, 0))


// Ambient external module members are always exported with or without export keyword when module lacks export assignment
import imp3 = require('equ2');
>imp3 : Symbol(imp3, Decl(consumer.ts, 1, 29))

var n = imp3.x;
>n : Symbol(n, Decl(consumer.ts, 6, 3), Decl(consumer.ts, 7, 3))
>imp3.x : Symbol(imp3.x, Decl(decls.ts, 8, 7))
>imp3 : Symbol(imp3, Decl(consumer.ts, 1, 29))
>x : Symbol(imp3.x, Decl(decls.ts, 8, 7))

var n: number;
>n : Symbol(n, Decl(consumer.ts, 6, 3), Decl(consumer.ts, 7, 3))

=== tests/cases/conformance/ambient/decls.ts ===

// Ambient external module with export assignment
declare module 'equ' {
var x;
>x : Symbol(x, Decl(decls.ts, 3, 7))

export = x;
>x : Symbol(x, Decl(decls.ts, 3, 7))
}

declare module 'equ2' {
var x: number;
>x : Symbol(x, Decl(decls.ts, 8, 7))
}

// Ambient external import declaration referencing ambient external module using top level module name
36 changes: 36 additions & 0 deletions tests/baselines/reference/ambientDeclarationsExternal.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
=== tests/cases/conformance/ambient/consumer.ts ===
/// <reference path="decls.ts" />
import imp1 = require('equ');
>imp1 : any


// Ambient external module members are always exported with or without export keyword when module lacks export assignment
import imp3 = require('equ2');
>imp3 : typeof imp3

var n = imp3.x;
>n : number
>imp3.x : number
>imp3 : typeof imp3
>x : number

var n: number;
>n : number

=== tests/cases/conformance/ambient/decls.ts ===

// Ambient external module with export assignment
declare module 'equ' {
var x;
>x : any

export = x;
>x : any
}

declare module 'equ2' {
var x: number;
>x : number
}

// Ambient external import declaration referencing ambient external module using top level module name
5 changes: 1 addition & 4 deletions tests/baselines/reference/circularReference.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
tests/cases/conformance/externalModules/foo1.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
tests/cases/conformance/externalModules/foo1.ts(9,12): error TS2339: Property 'x' does not exist on type 'C1'.
tests/cases/conformance/externalModules/foo2.ts(8,12): error TS2339: Property 'y' does not exist on type 'C1'.
tests/cases/conformance/externalModules/foo2.ts(13,8): error TS2339: Property 'x' does not exist on type 'C1'.
Expand Down Expand Up @@ -26,10 +25,8 @@ tests/cases/conformance/externalModules/foo2.ts(13,8): error TS2339: Property 'x
}
}

==== tests/cases/conformance/externalModules/foo1.ts (2 errors) ====
==== tests/cases/conformance/externalModules/foo1.ts (1 errors) ====
import foo2 = require('./foo2');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
export module M1 {
export class C1 {
m1: foo2.M1.C1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(1,25): error TS1005: ';' expected.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(3,1): error TS1128: Declaration or statement expected.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(4,17): error TS1005: '=' expected.


==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts (4 errors) ====
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts (3 errors) ====
export default abstract class A {}
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
~~~~~
!!! error TS1005: ';' expected.
export abstract class B {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
tests/cases/compiler/classMemberInitializerWithLamdaScoping3_1.ts(4,14): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
tests/cases/compiler/classMemberInitializerWithLamdaScoping3_1.ts(8,21): error TS2301: Initializer of instance member variable 'messageHandler' cannot reference identifier 'field1' declared in the constructor.


==== tests/cases/compiler/classMemberInitializerWithLamdaScoping3_0.ts (0 errors) ====
var field1: string;

==== tests/cases/compiler/classMemberInitializerWithLamdaScoping3_1.ts (2 errors) ====
==== tests/cases/compiler/classMemberInitializerWithLamdaScoping3_1.ts (1 errors) ====
declare var console: {
log(msg?: any): void;
};
export class Test1 {
~~~~~
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
constructor(private field1: string) {
}
messageHandler = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
tests/cases/compiler/classMemberInitializerWithLamdaScoping3_0.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
tests/cases/compiler/classMemberInitializerWithLamdaScoping3_1.ts(8,21): error TS2304: Cannot find name 'field1'.


==== tests/cases/compiler/classMemberInitializerWithLamdaScoping3_0.ts (1 errors) ====
==== tests/cases/compiler/classMemberInitializerWithLamdaScoping3_0.ts (0 errors) ====
export var field1: string;
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.

==== tests/cases/compiler/classMemberInitializerWithLamdaScoping3_1.ts (1 errors) ====
declare var console: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
tests/cases/conformance/externalModules/foo1.ts(3,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
tests/cases/conformance/externalModules/foo1.ts(3,1): error TS2300: Duplicate identifier 'export='.
tests/cases/conformance/externalModules/foo1.ts(4,1): error TS2300: Duplicate identifier 'export='.
tests/cases/conformance/externalModules/foo2.ts(3,1): error TS2300: Duplicate identifier 'export='.
Expand All @@ -12,13 +11,11 @@ tests/cases/conformance/externalModules/foo5.ts(5,1): error TS2300: Duplicate id
tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate identifier 'export='.


==== tests/cases/conformance/externalModules/foo1.ts (3 errors) ====
==== tests/cases/conformance/externalModules/foo1.ts (2 errors) ====
var x = 10;
var y = 20;
export = x;
~~~~~~~~~~~
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
~~~~~~~~~~~
!!! error TS2300: Duplicate identifier 'export='.
export = y;
~~~~~~~~~~~
Expand Down
Loading