Commit graph

6 commits

Author SHA1 Message Date
Cyrus Najmabadi 48bef4698b Provide better error recovery when we encounter merge markers in the source.
Previously we would just treat each merge marker as trivia and then continue
scanning and parsing like normal.  This worked well in some scenarios, but
fell down in others like:

```
class C {
    public foo() {
<<<<<<< HEAD
        this.bar();
    }
=======
        this.baz();
    }
>>>>>>> Branch

    public bar() { }
}
```

The problem stems from the previous approach trying to incorporate both branches of the merge into
the final tree.  In a case like this, that approach breaks down entirely.  The the parser ends up
seeing the close curly in both included sections, and it considers the class finished.  Then, it
starts erroring when it encounters "public bar()".

The fix is to only incorporate one of these sections into the tree.  Specifically, we only include
the first section.  The second sectoin is treated like trivia and does not affect the parse at all.
To make the experience more pleasant we do *lexically* classify the second section.  That way it
does not appear as just plain black text in the editor.  Instead, it will have appropriate lexicla
classifications for keywords, literals, comments, operators, punctuation, etc.  However, any syntactic
or semantic feature will not work in the second block due to this being trivia as far as any feature
is concerned.

This experience is still much better than what we had originally (where merge markers would absolutely)
destroy the parse tree.  And it is better than what we checked in last week, which could easily create
a borked tree for many types of merges.

Now, almost all merges should still leave the tree in good shape.  All LS features will work in the
first section, and lexical classification will work in the second.
2014-12-18 19:18:13 -08:00
Cyrus Najmabadi 6a08c54f42 Merge branch 'master' into sourceFileUpdate
Conflicts:
	src/compiler/checker.ts
	src/compiler/diagnosticInformationMap.generated.ts
	src/compiler/diagnosticMessages.json
	src/harness/fourslash.ts
2014-12-17 13:22:04 -08:00
Cyrus Najmabadi cd308e78ba Merge branch 'master' into sourceFileUpdate
Conflicts:
	src/compiler/checker.ts
	src/compiler/diagnosticInformationMap.generated.ts
	src/compiler/parser.ts
	tests/baselines/reference/FunctionDeclaration5_es6.errors.txt
	tests/baselines/reference/VariableDeclaration2_es6.errors.txt
	tests/baselines/reference/VariableDeclaration4_es6.errors.txt
	tests/baselines/reference/anonymousModules.errors.txt
	tests/baselines/reference/callSignaturesWithParameterInitializers2.errors.txt
	tests/baselines/reference/conflictMarkerTrivia1.errors.txt
	tests/baselines/reference/dottedModuleName.errors.txt
	tests/baselines/reference/innerModExport1.errors.txt
	tests/baselines/reference/innerModExport2.errors.txt
	tests/baselines/reference/parserAccessors10.errors.txt
	tests/baselines/reference/parserComputedPropertyName5.errors.txt
	tests/baselines/reference/parserErrantEqualsGreaterThanAfterFunction1.errors.txt
	tests/baselines/reference/parserErrantEqualsGreaterThanAfterFunction2.errors.txt
	tests/baselines/reference/parserModifierOnStatementInBlock2.errors.txt
	tests/baselines/reference/parserSkippedTokens16.errors.txt
	tests/baselines/reference/privateIndexer2.errors.txt
2014-12-16 21:50:10 -08:00
Cyrus Najmabadi f1a2e41a8a Sort diagnostics in our baseline output.
This was we don't get noisy baselines just because a different phase of the compiler reported
the diagnostic.

This helps with Yui's refactoring work to move grammar checks into the type checker.
2014-12-16 15:56:56 -08:00
Cyrus Najmabadi f218ce7684 Merge branch 'master' into sourceFileUpdate
Conflicts:
	src/compiler/diagnosticInformationMap.generated.ts
	src/compiler/diagnosticMessages.json
	src/compiler/parser.ts
	tests/baselines/reference/APISample_node_compile.js
	tests/baselines/reference/APISample_node_compile.types
	tests/baselines/reference/APISample_standalone_compile.js
	tests/baselines/reference/APISample_standalone_compile.types
2014-12-12 00:52:07 -08:00
Cyrus Najmabadi 7df3a407c2 Make the compiler resilient to encountering merge conflict markers in a source code file. 2014-12-11 16:56:10 -08:00