8000 Merge branch 'master' into arrowLookAhead · wheercool/TypeScript@b0c59e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit b0c59e7

Browse files
Merge branch 'master' into arrowLookAhead
2 parents b76c13c + 64ab02e commit b0c59e7

File tree

93 files changed

+867
-985
lines changed
  • cases
  • Some content is hidden

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

    93 files changed

    +867
    -985
    lines changed

    Jakefile

    Lines changed: 5 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -306,6 +306,11 @@ function exec(cmd, completeHandler) {
    306306
    }
    307307
    complete();
    308308
    });
    309+
    ex.addListener("error", function(e, status) {
    310+
    process.stderr.write(status);
    311+
    process.stderr.write(e);
    312+
    complete();
    313+
    })
    309314
    try{
    310315
    ex.run();
    311316
    } catch(e) {

    src/compiler/checker.ts

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -4038,7 +4038,7 @@ module ts {
    40384038
    function checkAndAggregateReturnExpressionTypes(body: Block, contextualType?: Type, contextualMapper?: TypeMapper): Type[] {
    40394039
    var aggregatedTypes: Type[] = [];
    40404040

    4041-
    forEachReturnStatement(body, (returnStatement) => {
    4041+
    forEachReturnStatement(body, returnStatement => {
    40424042
    var expr = returnStatement.expression;
    40434043
    if (expr) {
    40444044
    var type = checkAndMarkExpression(expr, contextualType, contextualMapper);
    @@ -4052,7 +4052,7 @@ module ts {
    40524052
    }
    40534053

    40544054
    function bodyContainsAReturnStatement(funcBody: Block) {
    4055-
    return forEachReturnStatement(funcBody, (returnStatement) => {
    4055+
    return forEachReturnStatement(funcBody, returnStatement => {
    40564056
    return true;
    40574057
    });
    40584058
    }
    @@ -5284,7 +5284,7 @@ module ts {
    52845284

    52855285
    function checkWithStatement(node: WithStatement) {
    52865286
    checkExpression(node.expression);
    5287-
    checkSourceElement(node.statement);
    5287+
    error(node.expression, Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any);
    52885288
    }
    52895289

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

    src/compiler/diagnosticInformationMap.generated.ts

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -123,6 +123,7 @@ module ts {
    123123
    Setters_cannot_return_a_value: { code: 2122, category: DiagnosticCategory.Error, key: "Setters cannot return a value." },
    124124
    Invalid_left_hand_side_of_assignment_expression: { code: 2130, category: DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." },
    125125
    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}'." },
    126+
    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'." },
    126127
    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." },
    127128
    Overload_signatures_must_all_be_public_or_private: { code: 2150, category: DiagnosticCategory.Error, key: "Overload signatures must all be public or private." },
    128129
    Overload_signatures_must_all_be_exported_or_not_exported: { code: 2151, category: DiagnosticCategory.Error, key: "Overload signatures must all be exported or not exported." },

    src/compiler/diagnosticMessages.json

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -485,6 +485,10 @@
    485485
    "category": "Error",
    486486
    "code": 2134
    487487
    },
    488+
    "All symbols within a 'with' block will be resolved to 'any'.": {
    489+
    "category": "Error",
    490+
    "code": 2135
    491+
    },
    488492
    "The operand of an increment or decrement operator must be a variable, property or indexer.": {
    489493
    "category": "Error",
    490494
    "code": 2139

    src/compiler/parser.ts

    Lines changed: 12 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -865,12 +865,13 @@ module ts {
    865865
    return createMissingList<T>();
    866866
    }
    867867

    868-
    function parseEntityName(): EntityName {
    868+
    // The allowReservedWords parameter controls whether reserved words are permitted after the first dot
    869+
    function parseEntityName(allowReservedWords: boolean): EntityName {
    869870
    var entity: EntityName = parseIdentifier();
    870871
    while (parseOptional(SyntaxKind.DotToken)) {
    871872
    var node = <QualifiedName>createNode(SyntaxKind.QualifiedName, entity.pos);
    872873
    node.left = entity;
    873-
    node.right = parseIdentifier();
    874+
    node.right = allowReservedWords ? parseIdentifierName() : parseIdentifier();
    874875
    entity = finishNode(node);
    875876
    }
    876877
    return entity;
    @@ -899,7 +900,7 @@ module ts {
    899900

    900901
    function parseTypeReference(): TypeReferenceNode {
    901902
    var node = <TypeReferenceNode>createNode(SyntaxKind.TypeReference);
    902-
    node.typeName = parseEntityName();
    903+
    node.typeName = parseEntityName(/*allowReservedWords*/ false);
    903904
    if (!scanner.hasPrecedingLineBreak() && token === SyntaxKind.LessThanToken) {
    904905
    node.typeArguments = parseTypeArguments();
    905906
    }
    @@ -909,7 +910,7 @@ module ts {
    909910
    function parseTypeQuery(): TypeQueryNode {
    910911
    var node = <TypeQueryNode>createNode(SyntaxKind.TypeQuery);
    911912
    parseExpected(SyntaxKind.TypeOfKeyword);
    912-
    node.exprName = parseEntityName();
    913+
    node.exprName = parseEntityName(/*allowReservedWords*/ true);
    913914
    return finishNode(node);
    914915
    }
    915916

    @@ -1873,7 +1874,12 @@ module ts {
    18731874
    if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
    18741875
    var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
    18751876
    var body = parseBody(/* ignoreMissingOpenBrace */ false);
    1876-
    node.initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, node.name, sig, body);
    1877+
    // do not propagate property name as name for function expression
    1878+
    // for scenarios like
    1879+
    // var x = 1;
    1880+
    // var y = { x() { } }
    1881+
    // otherwise this will bring y.x into the scope of x which is incorrect
    1882+
    node.initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, undefined, sig, body);
    18771883
    }
    18781884
    else {
    18791885
    parseExpected(SyntaxKind.ColonToken);
    @@ -2852,7 +2858,7 @@ module ts {
    28522858
    parseExpected(SyntaxKind.ImportKeyword);
    28532859
    node.name = parseIdentifier();
    28542860
    parseExpected(SyntaxKind.EqualsToken);
    2855-
    var entityName = parseEntityName();
    2861+
    var entityName = parseEntityName(/*allowReservedWords*/ false);
    28562862
    if (entityName.kind === SyntaxKind.Identifier && (<Identifier>entityName).text === "require" && parseOptional(SyntaxKind.OpenParenToken)) {
    28572863
    node.externalModuleName = parseStringLiteral();
    28582864
    parseExpected(SyntaxKind.CloseParenToken);

    src/harness/harness.ts

    Lines changed: 12 additions & 5 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,7 +18,7 @@
    1818
    /// <reference path='..\compiler\sys.ts' />
    1919
    /// <reference path='external\mocha.d.ts'/>
    2020
    /// <reference path='external\chai.d.ts'/>
    21-
    ///<reference path='sourceMapRecorder.ts'/>
    21+
    /// <reference path='sourceMapRecorder.ts'/>
    2222

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

    601-
    public compile(options?: ts.CompilerOptions) {
    601+
    public setCompilerOptions(options?: ts.CompilerOptions) {
    602602
    this.compileOptions = options || { noResolve: false };
    603603
    }
    604604

    @@ -624,7 +624,7 @@ module Harness {
    624624
    settingsCallback(null);
    625625
    }
    626626

    627-
    this.settings.forEach(setting => {
    627+
    this.settings.forEach(setting => {
    628628
    switch (setting.flag.toLowerCase()) {
    629629
    // "filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve"
    630630
    case "module":
    @@ -692,6 +692,10 @@ module Harness {
    692692
    case 'declaration':
    693693
    options.declaration = !!setting.value;
    694694
    break;
    695+
    case 'newline':
    696+
    case 'newlines':
    697+
    sys.newLine = setting.value;
    698+
    break;
    695699

    696700
    case 'mapsourcefiles':
    697701
    case 'maproot':
    @@ -753,6 +757,9 @@ module Harness {
    753757
    // Covert the source Map data into the baseline
    754758
    result.updateSourceMapRecord(program, sourceMapData);
    755759
    onComplete(result);
    760+
    761+
    // reset what newline means in case the last test changed it
    762+
    sys.newLine = '\r\n';
    756763
    return options;
    757764
    }
    758765
    }
    @@ -891,7 +898,7 @@ module Harness {
    891898
    var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines
    892899

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

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

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

    1122-
    if (Error) (<any>Error).stackTraceLimit = 100;
    1129+
    if (Error) (<any>Error).stackTraceLimit = 1;
    11231130
    }
    11241131

    11251132
    // TODO: not sure why Utils.evalFile isn't working with this, eventually will concat it like old compiler instead of eval

    src/harness/runner.ts

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -104,4 +104,6 @@ if (runners.length === 0) {
    104104
    // runners.push(new GeneratedFourslashRunner());
    105105
    }
    106106

    107+
    sys.newLine = '\r\n';
    108+
    107109
    runTests(runners);

    src/harness/rwcRunner.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -143,7 +143,7 @@ module RWC {
    143143
    harnessCompiler.addInputFile({ unitName: resolvedPath, content: content });
    144144
    });
    145145

    146-
    harnessCompiler.compile();
    146+
    harnessCompiler.setCompilerOptions();
    147147

    148148
    // Emit the results
    149149
    harnessCompiler.emitAll(emitterIOHost);

    src/harness/unittestrunner.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -37,7 +37,7 @@ class UnitTestRunner extends RunnerBase {
    3737
    return { unitName: test, content: Harness.IO.readFile(test) }
    3838
    });
    3939
    harnessCompiler.addInputFiles(toBeAdded);
    40-
    harnessCompiler.compile({ noResolve: true });
    40+
    harnessCompiler.setCompilerOptions({ noResolve: true });
    4141

    4242
    var stdout = new Harness.Compiler.EmitterIOHost();
    4343
    var emitDiagnostics = harnessCompiler.emitAll(stdout);

    tests/baselines/reference/ambientWithStatements.errors.txt

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1,4 +1,4 @@
    1-
    ==== tests/cases/compiler/ambientWithStatements.ts (14 errors) ====
    1+
    ==== tests/cases/compiler/ambientWithStatements.ts (15 errors) ====
    22
    declare module M {
    33
    break;
    44
    ~~~~~
    @@ -52,5 +52,7 @@
    5252
    with (x) {
    5353
    ~~~~
    5454
    !!! Statements are not allowed in ambient contexts.
    55+
    ~
    56+
    !!! All symbols within a 'with' block will be resolved to 'any'.
    5557
    }
    5658
    }

    0 commit comments

    Comments
     (0)
    0