Skip to content

Commit

Permalink
Merge branch 'master' into arrowLookAhead
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRosenwasser committed Jul 25, 2014
2 parents b76c13c + 64ab02e commit b0c59e7
Show file tree
Hide file tree
Showing 93 changed files with 867 additions and 985 deletions.
5 changes: 5 additions & 0 deletions Jakefile
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ function exec(cmd, completeHandler) {
}
complete();
});
ex.addListener("error", function(e, status) {
process.stderr.write(status);
process.stderr.write(e);
complete();
})
try{
ex.run();
} catch(e) {
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4038,7 +4038,7 @@ module ts {
function checkAndAggregateReturnExpressionTypes(body: Block, contextualType?: Type, contextualMapper?: TypeMapper): Type[] {
var aggregatedTypes: Type[] = [];

forEachReturnStatement(body, (returnStatement) => {
forEachReturnStatement(body, returnStatement => {
var expr = returnStatement.expression;
if (expr) {
var type = checkAndMarkExpression(expr, contextualType, contextualMapper);
Expand All @@ -4052,7 +4052,7 @@ module ts {
}

function bodyContainsAReturnStatement(funcBody: Block) {
return forEachReturnStatement(funcBody, (returnStatement) => {
return forEachReturnStatement(funcBody, returnStatement => {
return true;
});
}
Expand Down Expand Up @@ -5284,7 +5284,7 @@ module ts {

function checkWithStatement(node: WithStatement) {
checkExpression(node.expression);
checkSourceElement(node.statement);
error(node.expression, Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any);
}

function checkSwitchStatement(node: SwitchStatement) {
Expand Down Expand Up @@ -5343,7 +5343,7 @@ module ts {
// for interfaces property and indexer might be inherited from different bases
// check if any base class already has both property and indexer.
// check should be performed only if 'type' is the first type that brings property\indexer together
var someBaseClassHasBothPropertyAndIndexer = forEach((<InterfaceType>type).baseTypes, (base) => getPropertyOfType(base, prop.name) && getIndexTypeOfType(base, indexKind));
var someBaseClassHasBothPropertyAndIndexer = forEach((<InterfaceType>type).baseTypes, base => getPropertyOfType(base, prop.name) && getIndexTypeOfType(base, indexKind));
errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0];
}

Expand Down
1 change: 1 addition & 0 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ module ts {
Setters_cannot_return_a_value: { code: 2122, category: DiagnosticCategory.Error, key: "Setters cannot return a value." },
Invalid_left_hand_side_of_assignment_expression: { code: 2130, category: DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." },
Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2: { code: 2134, category: DiagnosticCategory.Error, key: "Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'." },
All_symbols_within_a_with_block_will_be_resolved_to_any: { code: 2135, category: DiagnosticCategory.Error, key: "All symbols within a 'with' block will be resolved to 'any'." },
The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer: { code: 2139, category: DiagnosticCategory.Error, key: "The operand of an increment or decrement operator must be a variable, property or indexer." },
Overload_signatures_must_all_be_public_or_private: { code: 2150, category: DiagnosticCategory.Error, key: "Overload signatures must all be public or private." },
Overload_signatures_must_all_be_exported_or_not_exported: { code: 2151, category: DiagnosticCategory.Error, key: "Overload signatures must all be exported or not exported." },
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@
"category": "Error",
"code": 2134
},
"All symbols within a 'with' block will be resolved to 'any'.": {
"category": "Error",
"code": 2135
},
"The operand of an increment or decrement operator must be a variable, property or indexer.": {
"category": "Error",
"code": 2139
Expand Down
18 changes: 12 additions & 6 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,12 +865,13 @@ module ts {
return createMissingList<T>();
}

function parseEntityName(): EntityName {
// The allowReservedWords parameter controls whether reserved words are permitted after the first dot
function parseEntityName(allowReservedWords: boolean): EntityName {
var entity: EntityName = parseIdentifier();
while (parseOptional(SyntaxKind.DotToken)) {
var node = <QualifiedName>createNode(SyntaxKind.QualifiedName, entity.pos);
node.left = entity;
node.right = parseIdentifier();
node.right = allowReservedWords ? parseIdentifierName() : parseIdentifier();
entity = finishNode(node);
}
return entity;
Expand Down Expand Up @@ -899,7 +900,7 @@ module ts {

function parseTypeReference(): TypeReferenceNode {
var node = <TypeReferenceNode>createNode(SyntaxKind.TypeReference);
node.typeName = parseEntityName();
node.typeName = parseEntityName(/*allowReservedWords*/ false);
if (!scanner.hasPrecedingLineBreak() && token === SyntaxKind.LessThanToken) {
node.typeArguments = parseTypeArguments();
}
Expand All @@ -909,7 +910,7 @@ module ts {
function parseTypeQuery(): TypeQueryNode {
var node = <TypeQueryNode>createNode(SyntaxKind.TypeQuery);
parseExpected(SyntaxKind.TypeOfKeyword);
node.exprName = parseEntityName();
node.exprName = parseEntityName(/*allowReservedWords*/ true);
return finishNode(node);
}

Expand Down Expand Up @@ -1873,7 +1874,12 @@ module ts {
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
var body = parseBody(/* ignoreMissingOpenBrace */ false);
node.initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, node.name, sig, body);
// do not propagate property name as name for function expression
// for scenarios like
// var x = 1;
// var y = { x() { } }
// otherwise this will bring y.x into the scope of x which is incorrect
node.initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, undefined, sig, body);
}
else {
parseExpected(SyntaxKind.ColonToken);
Expand Down Expand Up @@ -2852,7 +2858,7 @@ module ts {
parseExpected(SyntaxKind.ImportKeyword);
node.name = parseIdentifier();
parseExpected(SyntaxKind.EqualsToken);
var entityName = parseEntityName();
var entityName = parseEntityName(/*allowReservedWords*/ false);
if (entityName.kind === SyntaxKind.Identifier && (<Identifier>entityName).text === "require" && parseOptional(SyntaxKind.OpenParenToken)) {
node.externalModuleName = parseStringLiteral();
parseExpected(SyntaxKind.CloseParenToken);
Expand Down
17 changes: 12 additions & 5 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// <reference path='..\compiler\sys.ts' />
/// <reference path='external\mocha.d.ts'/>
/// <reference path='external\chai.d.ts'/>
///<reference path='sourceMapRecorder.ts'/>
/// <reference path='sourceMapRecorder.ts'/>

// this will work in the browser via browserify
var _chai: typeof chai = require('chai');
Expand Down Expand Up @@ -598,7 +598,7 @@ module Harness {
this.inputFiles.push(file);
}

public compile(options?: ts.CompilerOptions) {
public setCompilerOptions(options?: ts.CompilerOptions) {
this.compileOptions = options || { noResolve: false };
}

Expand All @@ -624,7 +624,7 @@ module Harness {
settingsCallback(null);
}

this.settings.forEach(setting => {
this.settings.forEach(setting => {
switch (setting.flag.toLowerCase()) {
// "filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve"
case "module":
Expand Down Expand Up @@ -692,6 +692,10 @@ module Harness {
case 'declaration':
options.declaration = !!setting.value;
break;
case 'newline':
case 'newlines':
sys.newLine = setting.value;
break;

case 'mapsourcefiles':
case 'maproot':
Expand Down Expand Up @@ -753,6 +757,9 @@ module Harness {
// Covert the source Map data into the baseline
result.updateSourceMapRecord(program, sourceMapData);
onComplete(result);

// reset what newline means in case the last test changed it
sys.newLine = '\r\n';
return options;
}
}
Expand Down Expand Up @@ -891,7 +898,7 @@ module Harness {
var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines

// List of allowed metadata names
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve"];
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve", "newline", "newlines"];

function extractCompilerSettings(content: string): CompilerSetting[] {

Expand Down Expand Up @@ -1119,7 +1126,7 @@ module Harness {
return filePath.indexOf('lib.d.ts') >= 0 || filePath.indexOf('lib.core.d.ts') >= 0;
}

if (Error) (<any>Error).stackTraceLimit = 100;
if (Error) (<any>Error).stackTraceLimit = 1;
}

// TODO: not sure why Utils.evalFile isn't working with this, eventually will concat it like old compiler instead of eval
Expand Down
2 changes: 2 additions & 0 deletions src/harness/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ if (runners.length === 0) {
// runners.push(new GeneratedFourslashRunner());
}

sys.newLine = '\r\n';

runTests(runners);
2 changes: 1 addition & 1 deletion src/harness/rwcRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ module RWC {
harnessCompiler.addInputFile({ unitName: resolvedPath, content: content });
});

harnessCompiler.compile();
harnessCompiler.setCompilerOptions();

// Emit the results
harnessCompiler.emitAll(emitterIOHost);
Expand Down
2 changes: 1 addition & 1 deletion src/harness/unittestrunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class UnitTestRunner extends RunnerBase {
return { unitName: test, content: Harness.IO.readFile(test) }
});
harnessCompiler.addInputFiles(toBeAdded);
harnessCompiler.compile({ noResolve: true });
harnessCompiler.setCompilerOptions({ noResolve: true });

var stdout = new Harness.Compiler.EmitterIOHost();
var emitDiagnostics = harnessCompiler.emitAll(stdout);
Expand Down
4 changes: 3 additions & 1 deletion tests/baselines/reference/ambientWithStatements.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
==== tests/cases/compiler/ambientWithStatements.ts (14 errors) ====
==== tests/cases/compiler/ambientWithStatements.ts (15 errors) ====
declare module M {
break;
~~~~~
Expand Down Expand Up @@ -52,5 +52,7 @@
with (x) {
~~~~
!!! Statements are not allowed in ambient contexts.
~
!!! All symbols within a 'with' block will be resolved to 'any'.
}
}
8 changes: 5 additions & 3 deletions tests/baselines/reference/arrowFunctionContexts.errors.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
==== tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts (9 errors) ====
==== tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts (10 errors) ====

// Arrow function used in with statement
with (window) {
~~~~~~
!!! All symbols within a 'with' block will be resolved to 'any'.
~~~~~~
!!! Cannot find name 'window'.
var p = () => this;
}
Expand Down Expand Up @@ -52,10 +54,10 @@
// Arrow function used in with statement
with (window) {
~~~~~~
!!! All symbols within a 'with' block will be resolved to 'any'.
~~~~~~
!!! Cannot find name 'window'.
var p = () => this;
~~~~
!!! 'this' cannot be referenced in a module body.
}

// Arrow function as argument to super call
Expand Down
6 changes: 2 additions & 4 deletions tests/baselines/reference/arrowFunctionContexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ var __extends = this.__extends || function (d, b) {
__.prototype = b.prototype;
d.prototype = new __();
};
var _this = this;
with (window) {
var p = function () { return _this; };
var p = function () { return this; };
}
var Base = (function () {
function Base(n) {
Expand Down Expand Up @@ -137,9 +136,8 @@ var M;
})(M || (M = {}));
var M2;
(function (M2) {
var _this = this;
with (window) {
var p = function () { return _this; };
var p = function () { return this; };
}
var Base = (function () {
function Base(n) {
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/assignEveryTypeToAny.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ var h;
x = h;
var i;
x = i;
x = { f: function f() {
x = { f: function () {
return 1;
} };
x = { f: function f(x) {
x = { f: function (x) {
return x;
} };
function j(a) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ t = { f: function (x) { return 1; } };
t = { f: function f() {
return 1;
} };
t = { f: function f(x) {
t = { f: function (x) {
return '';
} };
a = { f: function () { return 1; } };
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/assignmentToObjectAndFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var badFundule: Function = bad; // error
//// [assignmentToObjectAndFunction.js]
var errObj = { toString: 0 };
var goodObj = {
toString: function toString(x) {
toString: function (x) {
return "";
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var C = (function () {
})();
var a;
var b = {
foo: function foo(x, y) {
foo: function (x, y) {
},
a: function foo(x, y) {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var C = (function () {
})();
var a;
var b = {
foo: function foo(x, x) {
foo: function (x, x) {
},
a: function foo(x, x) {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ a(1);
a.foo();
a.foo(1);
var b = {
foo: function foo(x) {
foo: function (x) {
},
a: function foo(x, y) {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ a(1);
a.foo();
a.foo(1);
var b = {
foo: function foo(x) {
foo: function (x) {
if (x === void 0) { x = 1; }
},
a: function foo(x, y) {
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/contextualTyping.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,5 @@
interface B extends A { }
var x: B = { };
~
!!! Type '{}' is not assignable to type 'B':
!!! Property 'x' is missing in type '{}'.
!!! Type '{}' is not assignable to type 'B':\n Property 'x' is missing in type '{}'.

0 comments on commit b0c59e7

Please sign in to comment.