Merge pull request #3565 from Microsoft/incrementalParserReuse

Fix incremental parsing issue.
This commit is contained in:
CyrusNajmabadi 2015-06-18 14:50:37 -07:00
commit ae17c61dc2
2 changed files with 27 additions and 1 deletions

View file

@ -1491,12 +1491,20 @@ namespace ts {
switch (node.kind) {
case SyntaxKind.Constructor:
case SyntaxKind.IndexSignature:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.SemicolonClassElement:
return true;
case SyntaxKind.MethodDeclaration:
// Method declarations are not necessarily reusable. An object-literal
// may have a method calls "constructor(...)" and we must reparse that
// into an actual .ConstructorDeclaration.
let methodDeclaration = <MethodDeclaration>node;
let nameIsConstructor = methodDeclaration.name.kind === SyntaxKind.Identifier &&
(<Identifier>methodDeclaration.name).originalKeywordKind === SyntaxKind.ConstructorKeyword;
return !nameIsConstructor;
}
}

View file

@ -713,6 +713,24 @@ module m3 { }\
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4);
});
it('Do not move constructors from class to object-literal.', () => {
var source = "class C { public constructor() { } public constructor() { } public constructor() { } }"
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "class C".length, "var v =");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
});
it('Do not move methods called "constructor" from object literal to class', () => {
var source = "var v = { public constructor() { } public constructor() { } public constructor() { } }"
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
});
it('Moving index signatures from class to interface',() => {
var source = "class C { public [a: number]: string; public [a: number]: string; public [a: number]: string }"