Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
fa4b68f
Initial test harness for incremental parser tests.
CyrusNajmabadi Dec 10, 2014
783b0e5
Remove unnecessary switch case.
CyrusNajmabadi Dec 10, 2014
9d45770
Add incremental test.
CyrusNajmabadi Dec 10, 2014
a268cbf
Add incremental test.
CyrusNajmabadi Dec 10, 2014
2497d9a
Add incremental test.
CyrusNajmabadi Dec 10, 2014
d8ff734
Add incremental test.
CyrusNajmabadi Dec 10, 2014
4de7fa0
Add incremental test.
CyrusNajmabadi Dec 10, 2014
bcffd53
Add incremental test.
CyrusNajmabadi Dec 10, 2014
778e180
Add incremental test.
CyrusNajmabadi Dec 10, 2014
de84ddd
Add incremental test.
CyrusNajmabadi Dec 10, 2014
45f8713
Add incremental test.
CyrusNajmabadi Dec 10, 2014
a0a8ee0
Add incremental test.
CyrusNajmabadi Dec 10, 2014
e41bed8
Add incremental test.
CyrusNajmabadi Dec 10, 2014
bb34a20
Add incremental test.
CyrusNajmabadi Dec 10, 2014
e59ba41
Add incremental test.
CyrusNajmabadi Dec 10, 2014
22f39c5
Add incremental test.
CyrusNajmabadi Dec 10, 2014
7f60533
Add incremental test.
CyrusNajmabadi Dec 10, 2014
fa86c88
Add incremental test.
CyrusNajmabadi Dec 10, 2014
d549677
Add incremental test.
CyrusNajmabadi Dec 10, 2014
82098d1
Add incremental test.
CyrusNajmabadi Dec 10, 2014
a1b8a78
Add incremental test.
CyrusNajmabadi Dec 10, 2014
d5e2ab9
Add incremental test.
CyrusNajmabadi Dec 10, 2014
6058dbb
Add incremental test.
CyrusNajmabadi Dec 10, 2014
c482a9e
Add incremental test.
CyrusNajmabadi Dec 10, 2014
1cd2fb4
Add incremental test.
CyrusNajmabadi Dec 10, 2014
c7fcbb9
Add incremental test.
CyrusNajmabadi Dec 10, 2014
c436ff4
Add incremental test.
CyrusNajmabadi Dec 10, 2014
c307d30
Add incremental test.
CyrusNajmabadi Dec 10, 2014
e564fa5
Add incremental test.
CyrusNajmabadi Dec 10, 2014
666363a
Add incremental test.
CyrusNajmabadi Dec 10, 2014
5b2778c
Add incremental test.
CyrusNajmabadi Dec 10, 2014
418c0d9
Add incremental test.
CyrusNajmabadi Dec 10, 2014
b894299
Add incremental test.
CyrusNajmabadi Dec 10, 2014
18f9acb
Add incremental test.
CyrusNajmabadi Dec 10, 2014
3e70073
Add incremental test.
CyrusNajmabadi Dec 10, 2014
ec13fbe
Add incremental test.
CyrusNajmabadi Dec 10, 2014
d6fa98d
Add incremental test.
CyrusNajmabadi Dec 10, 2014
78c4b92
Add incremental test.
CyrusNajmabadi Dec 10, 2014
025dd23
Add incremental test.
CyrusNajmabadi Dec 10, 2014
197b62e
Add incremental test.
CyrusNajmabadi Dec 10, 2014
afec0fb
Add incremental test.
CyrusNajmabadi Dec 10, 2014
9b53947
Add incremental test.
CyrusNajmabadi Dec 10, 2014
c489c4f
Add incremental test.
CyrusNajmabadi Dec 10, 2014
dad3fae
Add incremental test.
CyrusNajmabadi Dec 10, 2014
467d303
Add incremental test.
CyrusNajmabadi Dec 10, 2014
b8bb8e9
Add incremental test.
CyrusNajmabadi Dec 10, 2014
01ead47
Add incremental test.
CyrusNajmabadi Dec 10, 2014
3928f74
Add incremental test.
CyrusNajmabadi Dec 10, 2014
58d36af
Add incremental test.
CyrusNajmabadi Dec 10, 2014
3c35b90
Add incremental test.
CyrusNajmabadi Dec 10, 2014
2a84572
Add incremental test.
CyrusNajmabadi Dec 10, 2014
aa30ac8
Add incremental test.
CyrusNajmabadi Dec 10, 2014
dd2c869
Use chai asserts.
CyrusNajmabadi Dec 10, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Jakefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var harnessSources = [
].map(function (f) {
return path.join(harnessDirectory, f);
}).concat([
"incrementalParser.ts",
"services/colorization.ts",
"services/documentRegistry.ts",
"services/preProcessFile.ts"
Expand Down
57 changes: 57 additions & 0 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,63 @@ module Utils {
}
});
}

export function assertInvariants(node: ts.Node, parent: ts.Node): void {
if (node) {
assert.isFalse(node.pos < 0, "node.pos < 0");
assert.isFalse(node.end < 0, "node.end < 0");
assert.isFalse(node.end < node.pos, "node.end < node.pos");
assert.equal(node.parent, parent, "node.parent !== parent");

if (parent) {
// Make sure each child is contained within the parent.
assert.isFalse(node.pos < parent.pos, "node.pos < parent.pos");
assert.isFalse(node.end > parent.end, "node.end > parent.end");
}

ts.forEachChild(node, child => {
assertInvariants(child, node);
});

// Make sure each of the children is in order.
var currentPos = 0;
ts.forEachChild(node,
child => {
assert.isFalse(child.pos < currentPos, "child.pos < currentPos");
currentPos = child.end;
},
(array: ts.NodeArray<ts.Node>) => {
assert.isFalse(array.pos < node.pos, "array.pos < node.pos");
assert.isFalse(array.end > node.end, "array.end > node.end");
assert.isFalse(array.pos < currentPos, "array.pos < currentPos");

for (var i = 0, n = array.length; i < n; i++) {
assert.isFalse(array[i].pos < currentPos, "array[i].pos < currentPos");
currentPos = array[i].end
}

currentPos = array.end;
});

var childNodesAndArrays: any[] = [];
ts.forEachChild(node, child => { childNodesAndArrays.push(child) }, array => { childNodesAndArrays.push(array) });

for (var childName in node) {
if (childName === "parent" || childName === "nextContainer" || childName === "modifiers" || childName === "externalModuleIndicator") {
continue;
}
var child = (<any>node)[childName];
if (isNodeOrArray(child)) {
assert.isFalse(childNodesAndArrays.indexOf(child) < 0,
"Missing child when forEach'ing over node: " + (<any>ts).SyntaxKind[node.kind] + "-" + childName);
}
}
}
}

function isNodeOrArray(a: any): boolean {
return a !== undefined && typeof a.pos === "number";
}
}

module Harness.Path {
Expand Down
77 changes: 1 addition & 76 deletions src/harness/test262Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,81 +21,6 @@ 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");
}
if (parent) {
// Make sure each child is contained within the parent.
if (node.pos < parent.pos) {
throw new Error("node.pos < parent.pos");
}
if (node.end > parent.end) {
throw new Error("node.end > parent.end");
}
}

ts.forEachChild(node, child => {
Test262BaselineRunner.checkInvariants(child, node);
});

// Make sure each of the children is in order.
var currentPos = 0;
ts.forEachChild(node,
child => {
if (child.pos < currentPos) {
throw new Error("child.pos < currentPos");
}
currentPos = child.end;
},
(array: ts.NodeArray<ts.Node>) => {
if (array.pos < node.pos) {
throw new Error("array.pos < node.pos");
}
if (array.end > node.end) {
throw new Error("array.end > node.end");
}

if (array.pos < currentPos) {
throw new Error("array.pos < currentPos");
}
for (var i = 0, n = array.length; i < n; i++) {
if (array[i].pos < currentPos) {
throw new Error("array[i].pos < currentPos");
}
currentPos = array[i].end
}

currentPos = array.end;
});

var childNodesAndArrays: any[] = [];
ts.forEachChild(node, child => { childNodesAndArrays.push(child) }, array => { childNodesAndArrays.push(array) });

for (var childName in node) {
if (childName === "parent" || childName === "nextContainer" || childName === "modifiers" || childName === "externalModuleIndicator") {
continue;
}
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]
Expand Down Expand Up @@ -264,7 +189,7 @@ class Test262BaselineRunner extends RunnerBase {

it('satisfies invariants', () => {
var sourceFile = testState.checker.getProgram().getSourceFile(Test262BaselineRunner.getTestFilePath(testState.filename));
Test262BaselineRunner.checkInvariants(sourceFile, /*parent:*/ undefined);
Utils.assertInvariants(sourceFile, /*parent:*/ undefined);
});

it('has the expected AST',() => {
Expand Down
8 changes: 4 additions & 4 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ module ts {
var scriptSnapshot = this.hostCache.getScriptSnapshot(filename);

var start = new Date().getTime();
sourceFile = createSourceFileFromScriptSnapshot(filename, scriptSnapshot, getDefaultCompilerOptions(), version, /*isOpen*/ true);
sourceFile = createLanguageServiceSourceFile(filename, scriptSnapshot, getDefaultCompilerOptions(), version, /*isOpen*/ true);
this.host.log("SyntaxTreeCache.Initialize: createSourceFile: " + (new Date().getTime() - start));

var start = new Date().getTime();
Expand All @@ -1692,7 +1692,7 @@ module ts {

var start = new Date().getTime();
sourceFile = !editRange
? createSourceFileFromScriptSnapshot(filename, scriptSnapshot, getDefaultCompilerOptions(), version, /*isOpen*/ true)
? createLanguageServiceSourceFile(filename, scriptSnapshot, getDefaultCompilerOptions(), version, /*isOpen*/ true)
: this.currentSourceFile.update(scriptSnapshot, version, /*isOpen*/ true, editRange);
this.host.log("SyntaxTreeCache.Initialize: updateSourceFile: " + (new Date().getTime() - start));

Expand All @@ -1718,7 +1718,7 @@ module ts {
}
}

function createSourceFileFromScriptSnapshot(filename: string, scriptSnapshot: IScriptSnapshot, settings: CompilerOptions, version: string, isOpen: boolean) {
export function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, settings: CompilerOptions, version: string, isOpen: boolean): SourceFile {
return SourceFileObject.createSourceFileObject(filename, scriptSnapshot, settings.target, version, isOpen);
}

Expand Down Expand Up @@ -1769,7 +1769,7 @@ module ts {
var bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true);
var entry = lookUp(bucket, filename);
if (!entry) {
var sourceFile = createSourceFileFromScriptSnapshot(filename, scriptSnapshot, compilationSettings, version, isOpen);
var sourceFile = createLanguageServiceSourceFile(filename, scriptSnapshot, compilationSettings, version, isOpen);

bucket[filename] = entry = {
sourceFile: sourceFile,
Expand Down
Loading