Skip to content

Commit 459dee0

Browse files
committed
Merge branch 'master' into destructuring
Move downlevel vs. ES6 emit branching into individual emit functions
2 parents b3dffff + b6f1225 commit 459dee0

File tree

209 files changed

+5509
-3471
lines changed

Some content is hidden

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

209 files changed

+5509
-3471
lines changed

Jakefile

+12-5
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ desc("Builds the test infrastructure using the built compiler");
366366
task("tests", ["local", run].concat(libraryTargets));
367367

368368
function exec(cmd, completeHandler) {
369-
var ex = jake.createExec([cmd]);
369+
var ex = jake.createExec([cmd], {windowsVerbatimArguments: true});
370370
// Add listeners for output and error
371371
ex.addListener("stdout", function(output) {
372372
process.stdout.write(output);
@@ -488,18 +488,25 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function(
488488
exec(cmd);
489489
}, {async: true});
490490

491+
function getDiffTool() {
492+
var program = process.env['DIFF']
493+
if (!program) {
494+
fail("Add the 'DIFF' environment variable to the path of the program you want to use.")
495+
}
496+
return program;
497+
}
491498

492499
// Baseline Diff
493-
desc("Diffs the compiler baselines using the diff tool specified by the %DIFF% environment variable");
500+
desc("Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable");
494501
task('diff', function () {
495-
var cmd = "%DIFF% " + refBaseline + ' ' + localBaseline;
502+
var cmd = '"' + getDiffTool() + '" ' + refBaseline + ' ' + localBaseline;
496503
console.log(cmd)
497504
exec(cmd);
498505
}, {async: true});
499506

500-
desc("Diffs the RWC baselines using the diff tool specified by the %DIFF% environment variable");
507+
desc("Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable");
501508
task('diff-rwc', function () {
502-
var cmd = "%DIFF% " + refRwcBaseline + ' ' + localRwcBaseline;
509+
var cmd = '"' + getDiffTool() + '" ' + refRwcBaseline + ' ' + localRwcBaseline;
503510
console.log(cmd)
504511
exec(cmd);
505512
}, {async: true});

src/compiler/binder.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,12 @@ module ts {
423423
bindDeclaration(<Declaration>node, SymbolFlags.Signature, 0, /*isBlockScopeContainer*/ false);
424424
break;
425425
case SyntaxKind.Method:
426-
bindDeclaration(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true);
426+
// If this is an ObjectLiteralExpression method, then it sits in the same space
427+
// as other properties in the object literal. So we use SymbolFlags.PropertyExcludes
428+
// so that it will conflict with any other object literal members with the same
429+
// name.
430+
bindDeclaration(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : 0),
431+
isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true);
427432
break;
428433
case SyntaxKind.FunctionDeclaration:
429434
bindDeclaration(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true);

src/compiler/checker.ts

+184-99
Large diffs are not rendered by default.

src/compiler/core.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ module ts {
2828
export interface StringSet extends Map<any> { }
2929

3030
export function forEach<T, U>(array: T[], callback: (element: T) => U): U {
31-
var result: U;
3231
if (array) {
3332
for (var i = 0, len = array.length; i < len; i++) {
34-
if (result = callback(array[i])) {
35-
break;
33+
var result = callback(array[i]);
34+
if (result) {
35+
return result;
3636
}
3737
}
3838
}
39-
return result;
39+
return undefined;
4040
}
4141

4242
export function contains<T>(array: T[], value: T): boolean {

src/compiler/emitter.ts

+33-44
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// <reference path="core.ts"/>
33
/// <reference path="scanner.ts"/>
44
/// <reference path="parser.ts"/>
5+
/// <reference path="binder.ts"/>
56

67
module ts {
78
interface EmitTextWriter {
@@ -2281,27 +2282,31 @@ module ts {
22812282
emit(node.expression);
22822283
write("]");
22832284
}
2284-
2285-
function emitPropertyAssignment(node: PropertyDeclaration) {
2285+
2286+
function emitMethod(node: MethodDeclaration) {
2287+
if (!isObjectLiteralMethod(node)) {
2288+
return;
2289+
}
22862290
emitLeadingComments(node);
22872291
emit(node.name);
2288-
write(": ");
2289-
emit(node.initializer);
2292+
if (compilerOptions.target < ScriptTarget.ES6) {
2293+
write(": function ");
2294+
}
2295+
emitSignatureAndBody(node);
22902296
emitTrailingComments(node);
22912297
}
22922298

2293-
function emitDownlevelShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) {
2299+
function emitPropertyAssignment(node: PropertyDeclaration) {
22942300
emitLeadingComments(node);
2295-
// Emit identifier as an identifier
22962301
emit(node.name);
22972302
write(": ");
2298-
// Even though this is stored as identifier treat it as an expression
2299-
// Short-hand, { x }, is equivalent of normal form { x: x }
2300-
emitExpressionIdentifier(node.name);
2303+
emit(node.initializer);
23012304
emitTrailingComments(node);
23022305
}
23032306

2304-
function emitShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) {
2307+
function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) {
2308+
emitLeadingComments(node);
2309+
emit(node.name);
23052310
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
23062311
// module m {
23072312
// export var y;
@@ -2310,16 +2315,14 @@ module ts {
23102315
// export var obj = { y };
23112316
// }
23122317
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
2313-
var prefix = resolver.getExpressionNamePrefix(node.name);
2314-
if (prefix) {
2315-
emitDownlevelShorthandPropertyAssignment(node);
2316-
}
2317-
// If short-hand property has no prefix, emit it as short-hand.
2318-
else {
2319-
emitLeadingComments(node);
2320-
emit(node.name);
2321-
emitTrailingComments(node);
2318+
if (compilerOptions.target < ScriptTarget.ES6 || resolver.getExpressionNamePrefix(node.name)) {
2319+
// Emit identifier as an identifier
2320+
write(": ");
2321+
// Even though this is stored as identifier treat it as an expression
2322+
// Short-hand, { x }, is equivalent of normal form { x: x }
2323+
emitExpressionIdentifier(node.name);
23222324
}
2325+
emitTrailingComments(node);
23232326
}
23242327

23252328
function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean {
@@ -2868,8 +2871,8 @@ module ts {
28682871
var p = properties[i];
28692872
if (p.kind === SyntaxKind.PropertyAssignment || p.kind === SyntaxKind.ShorthandPropertyAssignment) {
28702873
// TODO(andersh): Computed property support
2871-
var propName = <Identifier>((<PropertyDeclaration>p).name);
2872-
emitDestructuringAssignment((<PropertyDeclaration>p).initializer || propName, createPropertyAccess(value, propName));
2874+
var propName = <Identifier>((<PropertyAssignment>p).name);
2875+
emitDestructuringAssignment((<PropertyAssignment>p).initializer || propName, createPropertyAccess(value, propName));
28732876
}
28742877
}
28752878
}
@@ -3139,17 +3142,17 @@ module ts {
31393142
scopeEmitStart(node);
31403143
increaseIndent();
31413144

3142-
emitDetachedComments(node.body.kind === SyntaxKind.FunctionBlock ? (<Block>node.body).statements : node.body);
3145+
emitDetachedComments(node.body.kind === SyntaxKind.Block ? (<Block>node.body).statements : node.body);
31433146

31443147
var startIndex = 0;
3145-
if (node.body.kind === SyntaxKind.FunctionBlock) {
3148+
if (node.body.kind === SyntaxKind.Block) {
31463149
startIndex = emitDirectivePrologues((<Block>node.body).statements, /*startWithNewLine*/ true);
31473150
}
31483151
var outPos = writer.getTextPos();
31493152
emitCaptureThisForNodeIfNecessary(node);
31503153
emitDefaultValueAssignments(node);
31513154
emitRestParameter(node);
3152-
if (node.body.kind !== SyntaxKind.FunctionBlock && outPos === writer.getTextPos()) {
3155+
if (node.body.kind !== SyntaxKind.Block && outPos === writer.getTextPos()) {
31533156
decreaseIndent();
31543157
write(" ");
31553158
emitStart(node.body);
@@ -3164,7 +3167,7 @@ module ts {
31643167
emitEnd(node.body);
31653168
}
31663169
else {
3167-
if (node.body.kind === SyntaxKind.FunctionBlock) {
3170+
if (node.body.kind === SyntaxKind.Block) {
31683171
emitLinesStartingAt((<Block>node.body).statements, startIndex);
31693172
}
31703173
else {
@@ -3177,7 +3180,7 @@ module ts {
31773180
}
31783181
emitTempDeclarations(/*newLine*/ true);
31793182
writeLine();
3180-
if (node.body.kind === SyntaxKind.FunctionBlock) {
3183+
if (node.body.kind === SyntaxKind.Block) {
31813184
emitLeadingCommentsOfPosition((<Block>node.body).statements.end);
31823185
decreaseIndent();
31833186
emitToken(SyntaxKind.CloseBraceToken,(<Block>node.body).statements.end);
@@ -3812,6 +3815,8 @@ module ts {
38123815
return emitIdentifier(<Identifier>node);
38133816
case SyntaxKind.Parameter:
38143817
return emitParameter(<ParameterDeclaration>node);
3818+
case SyntaxKind.Method:
3819+
return emitMethod(<MethodDeclaration>node);
38153820
case SyntaxKind.GetAccessor:
38163821
case SyntaxKind.SetAccessor:
38173822
return emitAccessor(<AccessorDeclaration>node);
@@ -3849,6 +3854,8 @@ module ts {
38493854
return emitObjectLiteral(<ObjectLiteralExpression>node);
38503855
case SyntaxKind.PropertyAssignment:
38513856
return emitPropertyAssignment(<PropertyDeclaration>node);
3857+
case SyntaxKind.ShorthandPropertyAssignment:
3858+
return emitShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);
38523859
case SyntaxKind.ComputedPropertyName:
38533860
return emitComputedPropertyName(<ComputedPropertyName>node);
38543861
case SyntaxKind.PropertyAccessExpression:
@@ -3888,7 +3895,6 @@ module ts {
38883895
case SyntaxKind.Block:
38893896
case SyntaxKind.TryBlock:
38903897
case SyntaxKind.FinallyBlock:
3891-
case SyntaxKind.FunctionBlock:
38923898
case SyntaxKind.ModuleBlock:
38933899
return emitBlock(<Block>node);
38943900
case SyntaxKind.VariableStatement:
@@ -3944,23 +3950,6 @@ module ts {
39443950
case SyntaxKind.SourceFile:
39453951
return emitSourceFile(<SourceFile>node);
39463952
}
3947-
3948-
// Emit node which needs to be emitted differently depended on ScriptTarget
3949-
if (compilerOptions.target < ScriptTarget.ES6) {
3950-
// Emit node down-level
3951-
switch (node.kind) {
3952-
case SyntaxKind.ShorthandPropertyAssignment:
3953-
return emitDownlevelShorthandPropertyAssignment(<ShorthandPropertyDeclaration>node);
3954-
}
3955-
}
3956-
else {
3957-
// Emit node natively
3958-
Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Invalid ScriptTarget. We should emit as ES6 or above");
3959-
switch (node.kind) {
3960-
case SyntaxKind.ShorthandPropertyAssignment:
3961-
return emitShorthandPropertyAssignment(<ShorthandPropertyDeclaration>node);
3962-
}
3963-
}
39643953
}
39653954

39663955
function hasDetachedComments(pos: number) {

0 commit comments

Comments
 (0)