Skip to content

Commit f2044a9

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript
2 parents 111fdcb + ae17c61 commit f2044a9

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/compiler/parser.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,12 +1491,20 @@ namespace ts {
14911491
switch (node.kind) {
14921492
case SyntaxKind.Constructor:
14931493
case SyntaxKind.IndexSignature:
1494-
case SyntaxKind.MethodDeclaration:
14951494
case SyntaxKind.GetAccessor:
14961495
case SyntaxKind.SetAccessor:
14971496
case SyntaxKind.PropertyDeclaration:
14981497
case SyntaxKind.SemicolonClassElement:
14991498
return true;
1499+
case SyntaxKind.MethodDeclaration:
1500+
// Method declarations are not necessarily reusable. An object-literal
1501+
// may have a method calls "constructor(...)" and we must reparse that
1502+
// into an actual .ConstructorDeclaration.
1503+
let methodDeclaration = <MethodDeclaration>node;
1504+
let nameIsConstructor = methodDeclaration.name.kind === SyntaxKind.Identifier &&
1505+
(<Identifier>methodDeclaration.name).originalKeywordKind === SyntaxKind.ConstructorKeyword;
1506+
1507+
return !nameIsConstructor;
15001508
}
15011509
}
15021510

src/services/services.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,11 +1792,6 @@ namespace ts {
17921792
sourceFile.moduleName = moduleName;
17931793
}
17941794

1795-
// Store syntactic diagnostics
1796-
if (diagnostics && sourceFile.parseDiagnostics) {
1797-
diagnostics.push(...sourceFile.parseDiagnostics);
1798-
}
1799-
18001795
let newLine = getNewLineCharacter(options);
18011796

18021797
// Output

tests/cases/unittests/incrementalParser.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,24 @@ module m3 { }\
713713
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4);
714714
});
715715

716+
it('Do not move constructors from class to object-literal.', () => {
717+
var source = "class C { public constructor() { } public constructor() { } public constructor() { } }"
718+
719+
var oldText = ScriptSnapshot.fromString(source);
720+
var newTextAndChange = withChange(oldText, 0, "class C".length, "var v =");
721+
722+
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
723+
});
724+
725+
it('Do not move methods called "constructor" from object literal to class', () => {
726+
var source = "var v = { public constructor() { } public constructor() { } public constructor() { } }"
727+
728+
var oldText = ScriptSnapshot.fromString(source);
729+
var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C");
730+
731+
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
732+
});
733+
716734
it('Moving index signatures from class to interface',() => {
717735
var source = "class C { public [a: number]: string; public [a: number]: string; public [a: number]: string }"
718736

0 commit comments

Comments
 (0)