mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Merge branch 'master' into formatting_space_before_comma
This commit is contained in:
commit
b40a8dc52d
@ -21,6 +21,38 @@ class Test262BaselineRunner extends RunnerBase {
|
||||
return Test262BaselineRunner.basePath + "/" + filename;
|
||||
}
|
||||
|
||||
private static checkInvariants(node: ts.Node, parent: ts.Node): void {
|
||||
if (node) {
|
||||
if (node.pos < 0) {
|
||||
throw new Error("node.pos < 0");
|
||||
}
|
||||
if (node.end < 0) {
|
||||
throw new Error("node.end < 0");
|
||||
}
|
||||
if (node.end < node.pos) {
|
||||
throw new Error("node.end < node.pos");
|
||||
}
|
||||
if (node.parent !== parent) {
|
||||
throw new Error("node.parent !== parent");
|
||||
}
|
||||
ts.forEachChild(node, child => {
|
||||
Test262BaselineRunner.checkInvariants(child, node);
|
||||
});
|
||||
|
||||
var childNodesAndArrays: any[] = [];
|
||||
ts.forEachChild(node, child => { childNodesAndArrays.push(child) }, array => { childNodesAndArrays.push(array) });
|
||||
|
||||
for (var childName in node) {
|
||||
var child = (<any>node)[childName];
|
||||
if (Test262BaselineRunner.isNodeOrArray(child)) {
|
||||
if (childNodesAndArrays.indexOf(child) < 0) {
|
||||
throw new Error("Child when forEach'ing over node. " + (<any>ts).SyntaxKind[node.kind] + "-" + childName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static serializeSourceFile(file: ts.SourceFile): string {
|
||||
function getKindName(k: number): string {
|
||||
return (<any>ts).SyntaxKind[k]
|
||||
@ -104,10 +136,14 @@ class Test262BaselineRunner extends RunnerBase {
|
||||
}
|
||||
|
||||
return JSON.stringify(file, (k, v) => {
|
||||
return (v && typeof v.pos === "number") ? serializeNode(v) : v;
|
||||
return Test262BaselineRunner.isNodeOrArray(v) ? serializeNode(v) : v;
|
||||
}, " ");
|
||||
}
|
||||
|
||||
private static isNodeOrArray(a: any): boolean {
|
||||
return a !== undefined && typeof a.pos === "number";
|
||||
}
|
||||
|
||||
private runTest(filePath: string) {
|
||||
describe('test262 test for ' + filePath, () => {
|
||||
// Mocha holds onto the closure environment of the describe callback even after the test is done.
|
||||
@ -164,6 +200,11 @@ class Test262BaselineRunner extends RunnerBase {
|
||||
}, false, Test262BaselineRunner.baselineOptions);
|
||||
});
|
||||
|
||||
it('satisfies invariants', () => {
|
||||
var sourceFile = testState.checker.getProgram().getSourceFile(Test262BaselineRunner.getTestFilePath(testState.filename));
|
||||
Test262BaselineRunner.checkInvariants(sourceFile, /*parent:*/ undefined);
|
||||
});
|
||||
|
||||
it('has the expected AST',() => {
|
||||
Harness.Baseline.runBaseline('has the expected AST', testState.filename + '.AST.txt',() => {
|
||||
var sourceFile = testState.checker.getProgram().getSourceFile(Test262BaselineRunner.getTestFilePath(testState.filename));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user