Skip to content

Commit 873c1df

Browse files
committed
Add es6 target
1 parent bdac6ca commit 873c1df

27 files changed

+602
-20
lines changed

src/compiler/commandLineParser.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ module ts {
102102
{
103103
name: "target",
104104
shortName: "t",
105-
type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 },
106-
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5,
105+
type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 , "es6": ScriptTarget.ES6 },
106+
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental,
107107
paramType: Diagnostics.VERSION,
108-
error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5
108+
error: Diagnostics.Argument_for_target_option_must_be_es3_es5_or_es6
109109
},
110110
{
111111
name: "version",

src/compiler/diagnosticInformationMap.generated.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ module ts {
357357
Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." },
358358
Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
359359
Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." },
360-
Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), or 'ES5'" },
360+
Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
361361
Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" },
362362
Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." },
363363
Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." },
@@ -379,7 +379,7 @@ module ts {
379379
Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
380380
Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
381381
Argument_for_module_option_must_be_commonjs_or_amd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." },
382-
Argument_for_target_option_must_be_es3_or_es5: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." },
382+
Argument_for_target_option_must_be_es3_es5_or_es6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3', 'es5', or 'es6'." },
383383
Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: DiagnosticCategory.Error, key: "Locale must be of the form <language> or <language>-<territory>. For example '{0}' or '{1}'." },
384384
Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },
385385
Unable_to_open_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." },

src/compiler/diagnosticMessages.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@
14241424
"category": "Message",
14251425
"code": 6009
14261426
},
1427-
"Specify ECMAScript target version: 'ES3' (default), or 'ES5'": {
1427+
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)": {
14281428
"category": "Message",
14291429
"code": 6015
14301430
},
@@ -1512,7 +1512,7 @@
15121512
"category": "Error",
15131513
"code": 6046
15141514
},
1515-
"Argument for '--target' option must be 'es3' or 'es5'.": {
1515+
"Argument for '--target' option must be 'es3', 'es5', or 'es6'.": {
15161516
"category": "Error",
15171517
"code": 6047
15181518
},

src/compiler/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,8 @@ module ts {
10621062
export enum ScriptTarget {
10631063
ES3,
10641064
ES5,
1065+
ES6,
1066+
Latest = ES6,
10651067
}
10661068

10671069
export interface ParsedCommandLine {

src/harness/fourslash.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,7 @@ module FourSlash {
21392139
var host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFilename, content: undefined },
21402140
{ unitName: fileName, content: content }],
21412141
(fn, contents) => result = contents,
2142-
ts.ScriptTarget.ES5,
2142+
ts.ScriptTarget.Latest,
21432143
sys.useCaseSensitiveFileNames);
21442144
var program = ts.createProgram([Harness.Compiler.fourslashFilename, fileName], { out: "fourslashTestOutput.js" }, host);
21452145
var checker = ts.createTypeChecker(program, /*fullTypeCheckMode*/ true);

src/harness/harness.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ module Harness {
532532
}
533533

534534
export var defaultLibFileName = 'lib.d.ts';
535-
export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.ES5, /*version:*/ "0");
535+
export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*version:*/ "0");
536536

537537
// Cache these between executions so we don't have to re-parse them for every test
538538
export var fourslashFilename = 'fourslash.ts';
@@ -685,6 +685,8 @@ module Harness {
685685
options.target = ts.ScriptTarget.ES3;
686686
} else if (setting.value.toLowerCase() === 'es5') {
687687
options.target = ts.ScriptTarget.ES5;
688+
} else if (setting.value.toLowerCase() === 'es6') {
689+
options.target = ts.ScriptTarget.ES6;
688690
} else {
689691
throw new Error('Unknown compile target ' + setting.value);
690692
}

src/harness/harnessLanguageService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ module Harness.LanguageService {
260260

261261
/** Parse file given its source text */
262262
public parseSourceText(fileName: string, sourceText: TypeScript.IScriptSnapshot): TypeScript.SourceUnitSyntax {
263-
return TypeScript.Parser.parse(fileName, TypeScript.SimpleText.fromScriptSnapshot(sourceText), ts.ScriptTarget.ES5, TypeScript.isDTSFile(fileName)).sourceUnit();
263+
return TypeScript.Parser.parse(fileName, TypeScript.SimpleText.fromScriptSnapshot(sourceText), ts.ScriptTarget.Latest, TypeScript.isDTSFile(fileName)).sourceUnit();
264264
}
265265

266266
/** Parse a file on disk given its fileName */

src/services/compiler/precompile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ module TypeScript {
184184

185185
export function preProcessFile(fileName: string, sourceText: IScriptSnapshot, readImportFiles = true): IPreProcessedFileInfo {
186186
var text = SimpleText.fromScriptSnapshot(sourceText);
187-
var scanner = Scanner.createScanner(ts.ScriptTarget.ES5, text, reportDiagnostic);
187+
var scanner = Scanner.createScanner(ts.ScriptTarget.Latest, text, reportDiagnostic);
188188

189189
var firstToken = scanner.scan(/*allowRegularExpression:*/ false);
190190

src/services/services.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module ts {
7777
update(scriptSnapshot: TypeScript.IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TypeScript.TextChangeRange): SourceFile;
7878
}
7979

80-
var scanner: Scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ true);
80+
var scanner: Scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true);
8181

8282
var emptyArray: any[] = [];
8383

@@ -1456,9 +1456,9 @@ module ts {
14561456
}
14571457

14581458
export function getDefaultCompilerOptions(): CompilerOptions {
1459-
// Set "ES5" target by default for language service
1459+
// Set "ScriptTarget.Latest" target by default for language service
14601460
return {
1461-
target: ScriptTarget.ES5,
1461+
target: ScriptTarget.Latest,
14621462
module: ModuleKind.None,
14631463
};
14641464
}
@@ -3794,8 +3794,8 @@ module ts {
37943794
// before and after it have to be a non-identifier char).
37953795
var endPosition = position + symbolNameLength;
37963796

3797-
if ((position === 0 || !isIdentifierPart(text.charCodeAt(position - 1), ScriptTarget.ES5)) &&
3798-
(endPosition === sourceLength || !isIdentifierPart(text.charCodeAt(endPosition), ScriptTarget.ES5))) {
3797+
if ((position === 0 || !isIdentifierPart(text.charCodeAt(position - 1), ScriptTarget.Latest)) &&
3798+
(endPosition === sourceLength || !isIdentifierPart(text.charCodeAt(endPosition), ScriptTarget.Latest))) {
37993799
// Found a real match. Keep searching.
38003800
positions.push(position);
38013801
}
@@ -5217,7 +5217,7 @@ module ts {
52175217

52185218
/// Classifier
52195219
export function createClassifier(host: Logger): Classifier {
5220-
var scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ false);
5220+
var scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false);
52215221

52225222
/// We do not have a full parser support to know when we should parse a regex or not
52235223
/// If we consider every slash token to be a regex, we could be missing cases like "1/2/3", where

src/services/shims.ts

+3
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ module ts {
174174
export enum LanguageVersion {
175175
EcmaScript3 = 0,
176176
EcmaScript5 = 1,
177+
EcmaScript6 = 2,
177178
}
178179

179180
export enum ModuleGenTarget {
@@ -213,6 +214,7 @@ module ts {
213214
switch (languageVersion) {
214215
case LanguageVersion.EcmaScript3: return ScriptTarget.ES3
215216
case LanguageVersion.EcmaScript5: return ScriptTarget.ES5;
217+
case LanguageVersion.EcmaScript6: return ScriptTarget.ES6;
216218
default: throw Error("unsupported LanguageVersion value: " + languageVersion);
217219
}
218220
}
@@ -234,6 +236,7 @@ module ts {
234236
switch (scriptTarget) {
235237
case ScriptTarget.ES3: return LanguageVersion.EcmaScript3;
236238
case ScriptTarget.ES5: return LanguageVersion.EcmaScript5;
239+
case ScriptTarget.ES6: return LanguageVersion.EcmaScript6;
237240
default: throw Error("unsupported ScriptTarget value: " + scriptTarget);
238241
}
239242
}

src/services/syntax/scanner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ module TypeScript.Scanner {
186186
var lastTokenInfo = { leadingTriviaWidth: -1, width: -1 };
187187
var lastTokenInfoTokenID: number = -1;
188188

189-
var triviaScanner = createScannerInternal(ts.ScriptTarget.ES5, SimpleText.fromString(""), () => { });
189+
var triviaScanner = createScannerInternal(ts.ScriptTarget.Latest, SimpleText.fromString(""), () => { });
190190

191191
interface IScannerToken extends ISyntaxToken {
192192
}

src/services/syntax/unicode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module TypeScript {
8484
if (languageVersion === ts.ScriptTarget.ES3) {
8585
return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES3IdentifierStart);
8686
}
87-
else if (languageVersion === ts.ScriptTarget.ES5) {
87+
else if (languageVersion >= ts.ScriptTarget.ES5) {
8888
return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES5IdentifierStart);
8989
}
9090
else {
@@ -96,7 +96,7 @@ module TypeScript {
9696
if (languageVersion === ts.ScriptTarget.ES3) {
9797
return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES3IdentifierPart);
9898
}
99-
else if (languageVersion === ts.ScriptTarget.ES5) {
99+
else if (languageVersion >= ts.ScriptTarget.ES5) {
100100
return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES5IdentifierPart);
101101
}
102102
else {

tests/baselines/reference/es6-amd.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [es6-amd.ts]
2+
3+
class A
4+
{
5+
constructor ()
6+
{
7+
8+
}
9+
10+
public B()
11+
{
12+
return 42;
13+
}
14+
}
15+
16+
//// [es6-amd.js]
17+
var A = (function () {
18+
function A() {
19+
}
20+
A.prototype.B = function () {
21+
return 42;
22+
};
23+
return A;
24+
})();
25+
//# sourceMappingURL=es6-amd.js.map
26+
27+
//// [es6-amd.d.ts]
28+
declare class A {
29+
constructor();
30+
B(): number;
31+
}

tests/baselines/reference/es6-amd.js.map

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
===================================================================
2+
JsFile: es6-amd.js
3+
mapUrl: es6-amd.js.map
4+
sourceRoot:
5+
sources: es6-amd.ts
6+
===================================================================
7+
-------------------------------------------------------------------
8+
emittedFile:tests/cases/compiler/es6-amd.js
9+
sourceFile:es6-amd.ts
10+
-------------------------------------------------------------------
11+
>>>var A = (function () {
12+
1 >
13+
2 >^^^^
14+
3 > ^
15+
4 > ^^^^^^^^^^^^^^->
16+
1 >
17+
>
18+
2 >class
19+
3 > A
20+
1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0)
21+
2 >Emitted(1, 5) Source(2, 7) + SourceIndex(0)
22+
3 >Emitted(1, 6) Source(2, 8) + SourceIndex(0)
23+
---
24+
>>> function A() {
25+
1->^^^^
26+
2 > ^^^^^^^^^
27+
3 > ^
28+
1->
29+
>{
30+
>
31+
2 >
32+
3 > A
33+
1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A)
34+
2 >Emitted(2, 14) Source(2, 7) + SourceIndex(0) name (A)
35+
3 >Emitted(2, 15) Source(2, 8) + SourceIndex(0) name (A)
36+
---
37+
>>> }
38+
1 >^^^^
39+
2 > ^
40+
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
41+
1 >
42+
>{
43+
> constructor ()
44+
> {
45+
>
46+
>
47+
2 > }
48+
1 >Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor)
49+
2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor)
50+
---
51+
>>> A.prototype.B = function () {
52+
1->^^^^
53+
2 > ^^^^^^^^^^^^^
54+
3 > ^^^
55+
1->
56+
>
57+
> public
58+
2 > B
59+
3 >
60+
1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A)
61+
2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A)
62+
3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A)
63+
---
64+
>>> return 42;
65+
1 >^^^^^^^^
66+
2 > ^^^^^^
67+
3 > ^
68+
4 > ^^
69+
5 > ^
70+
1 >public B()
71+
> {
72+
>
73+
2 > return
74+
3 >
75+
4 > 42
76+
5 > ;
77+
1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B)
78+
2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B)
79+
3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B)
80+
4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B)
81+
5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B)
82+
---
83+
>>> };
84+
1 >^^^^
85+
2 > ^
86+
3 > ^^^^^^^^^->
87+
1 >
88+
>
89+
2 > }
90+
1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B)
91+
2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B)
92+
---
93+
>>> return A;
94+
1->^^^^
95+
2 > ^^^^^^^^
96+
1->
97+
>
98+
2 > }
99+
1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A)
100+
2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A)
101+
---
102+
>>>})();
103+
1 >
104+
2 >^
105+
3 >
106+
4 > ^^^^
107+
5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
108+
1 >
109+
2 >}
110+
3 >
111+
4 > class A
112+
> {
113+
> constructor ()
114+
> {
115+
>
116+
> }
117+
>
118+
> public B()
119+
> {
120+
> return 42;
121+
> }
122+
> }
123+
1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A)
124+
2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A)
125+
3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0)
126+
4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0)
127+
---
128+
>>>//# sourceMappingURL=es6-amd.js.map
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/es6-amd.ts ===
2+
3+
class A
4+
>A : A
5+
{
6+
constructor ()
7+
{
8+
9+
}
10+
11+
public B()
12+
>B : () => number
13+
{
14+
return 42;
15+
}
16+
}

0 commit comments

Comments
 (0)