Skip to content

Commit b52d9ec

Browse files
committed
Report error if module gen target is specified in es6
Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/program.ts tests/baselines/reference/constDeclarations-access5.errors.txt tests/baselines/reference/es6ExportAssignment.errors.txt tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt tests/cases/compiler/es6ImportDefaultBinding.ts tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts tests/cases/compiler/es6ImportNameSpaceImport.ts tests/cases/compiler/es6ImportNamedImport.ts tests/cases/compiler/es6ImportNamedImportMergeErrors.ts tests/cases/compiler/es6ImportNamedImportNoExportMember.ts tests/cases/compiler/es6ImportWithoutFromClause.ts tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts
1 parent 04ea7fe commit b52d9ec

46 files changed

Lines changed: 416 additions & 47 deletions

File tree

Some content is hidden

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

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ module ts {
159159
Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." },
160160
Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1200, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." },
161161
Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1201, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." },
162+
Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1202, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." },
162163
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
163164
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
164165
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,10 @@
627627
"category": "Error",
628628
"code": 1201
629629
},
630+
"Cannot compile external modules into amd or commonjs when targeting es6 or higher.": {
631+
"category": "Error",
632+
"code": 1202
633+
},
630634

631635
"Duplicate identifier '{0}'.": {
632636
"category": "Error",

src/compiler/program.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,16 @@ module ts {
428428

429429
var firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
430430
if (firstExternalModuleSourceFile && !options.module) {
431-
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
432-
var span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
433-
diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
431+
if (!options.module && options.target < ScriptTarget.ES6) {
432+
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
433+
var span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
434+
diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
435+
}
436+
}
437+
438+
// Cannot specify module gen target when in es6 or above
439+
if (options.module && options.target >= ScriptTarget.ES6) {
440+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher));
434441
}
435442

436443
// there has to be common source directory if user specified --outdir || --sourcRoot

tests/baselines/reference/constDeclarations-access5.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher.
12
tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead.
23
tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
34
tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
@@ -19,6 +20,7 @@ tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The oper
1920
tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
2021

2122

23+
!!! error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher.
2224
==== tests/cases/compiler/constDeclarations_access_2.ts (19 errors) ====
2325
///<reference path='constDeclarations_access_1.ts'/>
2426
import m = require('constDeclarations_access_1');
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [es5ModuleWithModuleGenAmd.ts]
2+
export class A
3+
{
4+
constructor ()
5+
{
6+
}
7+
8+
public B()
9+
{
10+
return 42;
11+
}
12+
}
13+
14+
//// [es5ModuleWithModuleGenAmd.js]
15+
define(["require", "exports"], function (require, exports) {
16+
var A = (function () {
17+
function A() {
18+
}
19+
A.prototype.B = function () {
20+
return 42;
21+
};
22+
return A;
23+
})();
24+
exports.A = A;
25+
});

tests/baselines/reference/es6-declaration-amd.types renamed to tests/baselines/reference/es5ModuleWithModuleGenAmd.types

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
=== tests/cases/compiler/es6-declaration-amd.ts ===
2-
3-
class A
1+
=== tests/cases/compiler/es5ModuleWithModuleGenAmd.ts ===
2+
export class A
43
>A : A
54
{
65
constructor ()
76
{
8-
97
}
108

119
public B()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [es5ModuleWithModuleGenCommonjs.ts]
2+
export class A
3+
{
4+
constructor ()
5+
{
6+
}
7+
8+
public B()
9+
{
10+
return 42;
11+
}
12+
}
13+
14+
//// [es5ModuleWithModuleGenCommonjs.js]
15+
var A = (function () {
16+
function A() {
17+
}
18+
A.prototype.B = function () {
19+
return 42;
20+
};
21+
return A;
22+
})();
23+
exports.A = A;

tests/baselines/reference/es6-sourcemap-amd.types renamed to tests/baselines/reference/es5ModuleWithModuleGenCommonjs.types

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
=== tests/cases/compiler/es6-sourcemap-amd.ts ===
2-
3-
class A
1+
=== tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts ===
2+
export class A
43
>A : A
54
{
65
constructor ()
76
{
8-
97
}
108

119
public B()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
2+
3+
4+
==== tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts (1 errors) ====
5+
export class A
6+
~
7+
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
8+
{
9+
constructor ()
10+
{
11+
}
12+
13+
public B()
14+
{
15+
return 42;
16+
}
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [es5ModuleWithoutModuleGenTarget.ts]
2+
export class A
3+
{
4+
constructor ()
5+
{
6+
}
7+
8+
public B()
9+
{
10+
return 42;
11+
}
12+
}
13+
14+
//// [es5ModuleWithoutModuleGenTarget.js]
15+
var A = (function () {
16+
function A() {
17+
}
18+
A.prototype.B = function () {
19+
return 42;
20+
};
21+
return A;
22+
})();
23+
exports.A = A;

0 commit comments

Comments
 (0)