Skip to content

Commit 48eed94

Browse files
committed
WIP: noImplicitAny
1 parent f26c1a7 commit 48eed94

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

src/__tests__/helpers.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import parse from '../parser'
77
import typeCheck from '../type-checker'
88
import interpret from '../interpreter'
99

10-
export function fixture (fileName) {
10+
export function fixture (fileName: string) {
1111
const filePath = join(__dirname, 'fixtures', fileName)
1212
return readFileSync(filePath, 'utf8')
1313
}
1414

15-
export function run (program) {
15+
export function run (source: string) {
1616
const env = getRootEnv()
1717
const typeEnv = getTypeEnv(env)
1818

19-
const ast = parse(program)
19+
const ast = parse(source)
2020
const [typed] = typeCheck(ast, typeEnv)
2121
return interpret(typed, getRootEnv())
2222
}
2323

24-
export function testResult (program, expectedOutput) {
25-
test(program, () => {
26-
expect(run(program)[0]).toEqual(expectedOutput)
24+
export function testResult (source: string, expectedOutput: any) {
25+
test(source, () => {
26+
expect(run(source)[0]).toEqual(expectedOutput)
2727
})
2828
}

src/__tests__/parser-tests.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { fixture } from './helpers'
66
// snapshot tests for the parser
77
//
88

9-
function testFixture (fixtureName) {
9+
function testFixture (fixtureName: string) {
1010
test(fixtureName, () => {
1111
expect(parse(fixture(fixtureName))).toMatchSnapshot()
1212
})
1313
}
1414

15-
function testParse (peachCode) {
16-
test(peachCode, () => {
17-
expect(parse(peachCode)).toMatchSnapshot()
15+
function testParse (source: string) {
16+
test(source, () => {
17+
expect(parse(source)).toMatchSnapshot()
1818
})
1919
}
2020

src/__tests__/type-checker-tests.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import typeCheck from '../type-checker'
44
import { getRootEnv, getTypeEnv } from '../env'
55
import { fixture } from './helpers'
66
import { clone } from '../util'
7+
import { Type } from '../types'
78
import { TypedNode, AstNode } from '../node-types'
89

910
import {
@@ -14,23 +15,23 @@ import {
1415
BooleanType
1516
} from '../types'
1617

17-
function testTypeCheck (code, env = getTypeEnv(getRootEnv())) {
18-
test(code, () => {
19-
const parsed = parse(code)
18+
function testTypeCheck (source: string, env = getTypeEnv(getRootEnv())) {
19+
test(source, () => {
20+
const parsed = parse(source)
2021
const [lastNode] = typeCheck(parsed, env)
2122
const type = lastNode.exprType.toString()
2223
expect(type).toMatchSnapshot()
2324
})
2425
};
2526

26-
function testFails (code, env = getTypeEnv(getRootEnv())) {
27-
test(code, () => {
28-
const parsed = parse(code)
27+
function testFails (source: string, env = getTypeEnv(getRootEnv())) {
28+
test(source, () => {
29+
const parsed = parse(source)
2930
expect(() => typeCheck(parsed, env)).toThrowErrorMatchingSnapshot()
3031
})
3132
}
3233

33-
function testFixture (fixtureName, env = getTypeEnv(getRootEnv())) {
34+
function testFixture (fixtureName: string, env = getTypeEnv(getRootEnv())) {
3435
test(fixtureName, () => {
3536
const parsed = parse(fixture(fixtureName))
3637
const [lastNode] = typeCheck(parsed, env)
@@ -86,7 +87,7 @@ testFails(`if (1) 1 else 2`)
8687

8788
// the peach type checker works over nodes with an `exprType` property.
8889
// helper for creating nodes for synthetic type tests
89-
function typed (type): TypedNode {
90+
function typed (type: Type): TypedNode {
9091
return {
9192
exprType: type,
9293
type: 'Str',
@@ -96,11 +97,11 @@ function typed (type): TypedNode {
9697

9798
// simulate a user-defined type
9899
class PairType extends TypeOperator {
99-
constructor (a, b) {
100+
constructor (a: Type, b: Type) {
100101
super('*', [a, b])
101102
}
102103

103-
static of (name, [a, b]) {
104+
static of (name: string, [a, b]: Type[]) {
104105
return new PairType(a, b)
105106
}
106107

@@ -109,9 +110,9 @@ class PairType extends TypeOperator {
109110
}
110111
}
111112

112-
const A = typed(new TypeVariable())
113-
const B = typed(new TypeVariable())
114-
const AB = typed(new PairType(A, B))
113+
const A = new TypeVariable()
114+
const B = new TypeVariable()
115+
const AB = new PairType(A, B)
115116

116117
const testEnv = () => ({
117118
// No unit type yet, so all functions take exactly one argument

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"moduleResolution": "node",
66
"outDir": "./dist",
77
"target": "es2017",
8-
"sourceMap": true
8+
"sourceMap": true,
9+
"noImplicitAny": true
910
},
1011
"include": [
1112
"./src/**/*"

0 commit comments

Comments
 (0)