Initial commit

This commit is contained in:
dcodeIO
2017-09-28 13:08:25 +02:00
commit 1d53303b47
32 changed files with 8460 additions and 0 deletions

View File

@ -0,0 +1,12 @@
export class Test<T> {
instanceFunction(): void {
}
static staticFunction(): void {
}
get instanceGetter(): i32 {
}
static set staticSetter(v: i32): i32 {
}
instanceField: i32;
static staticField: i32;
}

View File

@ -0,0 +1,10 @@
export const enum A {
B = 1,
C,
D = 3
}
enum E {
F,
G = 1 + 2,
H = 3 * 4
}

View File

@ -0,0 +1,4 @@
function simple(): void {
}
function typeparams<T, V extends T>(a: V | null = null): void {
}

View File

@ -0,0 +1,171 @@
// incrementing precedence
a
=
b
?
X
:
c
||
d
&&
e
|
f
^
g
&
h
==
i
<
j
<<
k
+
l
/
++
m
++
;
// decrementing precedence
++
a
++
/
b
+
c
<<
d
<
e
==
f
&
g
^
h
|
i
&&
j
||
k
?
X
:
y
=
l
;
// assignment (right-to-left)
a
=
b
+=
c
-=
d
**=
e
*=
f
/=
g
%=
h
<<=
i
>>=
j
>>>=
k
&=
l
^=
m
|=
n
;
// equality (left-to-right)
a
==
b
!=
c
===
d
!==
e
;
// relational (left-to-right)
a
<
b
<=
c
>
d
>=
e
;
// bitwise shift (left-to-right)
a
<<
b
>>
c
>>>
d
;
// addition (left-to-right)
a
+
b
-
c
;
// exponentiation (right-to-left), multiplication (left-to-right)
a
**
b
*
c
/
d
%
e
**
f
*
g
;
// prefix (right-to-left)
delete
void
typeof
--
++
-
+
~
!
a
;
// parenthesized
(
a
+
(
b
/
c
)
-
d
)
*
e
;

46
tests/parser/index.ts Normal file
View File

@ -0,0 +1,46 @@
import * as fs from "fs";
import * as diff from "diff";
import * as chalk from "chalk";
import "../../src/glue/js";
import { NodeKind, ExpressionStatement } from "../../src/ast";
import { Parser } from "../../src/parser";
const files = fs.readdirSync(__dirname + "/fixtures");
files.forEach(filename => {
if (filename.charAt(0) == "_") return;
const isTree = filename.indexOf(".tree.") >= 0;
const parser = new Parser();
const text = fs.readFileSync(__dirname + "/fixtures/" + filename, { encoding: "utf8" }).replace(/\r?\n/g, "\n").replace(/^\/\/.*\r?\n/mg, "");
parser.parseFile(text, filename, true);
var sb: string[] = [];
if (isTree) {
const statements = parser.program.sources[0].statements;
statements.forEach(stmt => {
if (stmt.kind != NodeKind.EXPRESSION) return;
(<ExpressionStatement>stmt).expression.serializeAsTree(sb, 0);
sb.push(";\n");
});
} else
parser.program.sources[0].serialize(sb);
const actual = sb.join("");
const expected = isTree ? text : text.replace(/^\s+/mg, "");
const diffs = diff.diffLines(expected, actual);
let changed = false;
diffs.forEach(part => {
if (part.added || part.removed)
changed = true;
});
if (changed) { // print it
console.log("Differences in " + filename + ":");
diffs.forEach(part => {
if (part.added || part.removed)
changed = true;
process.stderr.write((part.added ? chalk.green : part.removed ? chalk.red : chalk.grey)(part.value));
});
} else {
console.log("No differences in " + filename + ".");
}
// parser.program.initialize();
// console.log(parser.program.names);
});