Skip to content

Commit 3ab92ba

Browse files
committed
Fix more type errors
1 parent 6e252b6 commit 3ab92ba

File tree

6 files changed

+36
-22
lines changed

6 files changed

+36
-22
lines changed

src/editors/ace/modes/source.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function HighlightRulesSelector(
3737
}
3838
)[] = []
3939
) {
40-
// @ts-ignore
40+
// @ts-expect-error implicit any
4141
function _SourceHighlightRules(acequire, exports, _module) {
4242
'use strict'
4343

@@ -49,7 +49,8 @@ export function HighlightRulesSelector(
4949
const identifierRegex = '[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*'
5050

5151
const chapter = variant === Variant.DEFAULT ? id.toString() : id.toString() + '_' + variant
52-
const builtin_lib = SourceDocumentation.builtins[chapter]
52+
const builtin_lib =
53+
SourceDocumentation.builtins[chapter as keyof typeof SourceDocumentation.builtins]
5354

5455
function addFromBuiltinLibrary(meta: string) {
5556
if (builtin_lib === null) {

src/parser/__tests__/disallowed-syntax.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ test('Cannot use function expressions', () => {
446446
stripIndent`
447447
(function fib(x) { return x <= 1 ? x : fib(x-1) + fib(x-2); })(4);
448448
`,
449-
{ chapter: 5 }
449+
{ chapter: 5 as Chapter }
450450
).toMatchInlineSnapshot(`"Line 1: Function expressions are not allowed"`)
451451
})
452452

@@ -456,7 +456,7 @@ test('Cannot use function expressions - verbose', () => {
456456
"enable verbose";
457457
(function fib(x) { return x <= 1 ? x : fib(x-1) + fib(x-2); })(4);
458458
`,
459-
{ chapter: 5 }
459+
{ chapter: 5 as Chapter }
460460
).toMatchInlineSnapshot(`
461461
"Line 2, Column 1: Function expressions are not allowed
462462
You are trying to use Function expressions, which is not allowed (yet).
@@ -469,7 +469,7 @@ test('Cannot use function expressions', () => {
469469
stripIndent`
470470
(function(x) { return x + 1; })(4);
471471
`,
472-
{ chapter: 5 }
472+
{ chapter: 5 as Chapter }
473473
).toMatchInlineSnapshot(`"Line 1: Function expressions are not allowed"`)
474474
})
475475

@@ -479,7 +479,7 @@ test('Cannot use function expressions - verbose', () => {
479479
"enable verbose";
480480
(function(x) { return x + 1; })(4);
481481
`,
482-
{ chapter: 5 }
482+
{ chapter: 5 as Chapter }
483483
).toMatchInlineSnapshot(`
484484
"Line 2, Column 1: Function expressions are not allowed
485485
You are trying to use Function expressions, which is not allowed (yet).
@@ -852,7 +852,7 @@ test('No classes', () => {
852852
class Box {
853853
}
854854
`,
855-
{ chapter: 5 }
855+
{ chapter: 5 as Chapter }
856856
).toMatchInlineSnapshot(`
857857
"Line 1: Class bodys are not allowed
858858
Line 1: Class declarations are not allowed"
@@ -866,7 +866,7 @@ test('No classes - verbose', () => {
866866
class Box {
867867
}
868868
`,
869-
{ chapter: 5 }
869+
{ chapter: 5 as Chapter }
870870
).toMatchInlineSnapshot(`
871871
"Line 2, Column 10: Class bodys are not allowed
872872
You are trying to use Class bodys, which is not allowed (yet).
@@ -886,7 +886,7 @@ test('No super', () => {
886886
}
887887
}
888888
`,
889-
{ chapter: 5 }
889+
{ chapter: 5 as Chapter }
890890
).toMatchInlineSnapshot(`
891891
"Line 3: Supers are not allowed
892892
Line 2: Function expressions are not allowed
@@ -906,7 +906,7 @@ test('No super - verbose', () => {
906906
}
907907
}
908908
`,
909-
{ chapter: 5 }
909+
{ chapter: 5 as Chapter }
910910
).toMatchInlineSnapshot(`
911911
"Line 4, Column 4: Supers are not allowed
912912
You are trying to use Supers, which is not allowed (yet).

src/parser/source/typed/typeParser.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ const tsPlugin = (BaseParser: any) => {
395395
let node
396396
switch (this.type) {
397397
case tokTypes.name:
398-
switch (tsTypeOperator[this.value]) {
398+
switch (tsTypeOperator[this.value as keyof typeof tsTypeOperator]) {
399399
case tsTypeOperator.infer:
400400
node = this.parseTSInferType()
401401
break
@@ -431,7 +431,7 @@ const tsPlugin = (BaseParser: any) => {
431431
}
432432

433433
_parseTSDeclaration(node: any, expr: { name: string | number }) {
434-
const val = tsDeclaration[expr.name]
434+
const val = tsDeclaration[expr.name as keyof typeof tsDeclaration]
435435
switch (val) {
436436
case tsDeclaration.interface:
437437
if (this.type === tokTypes.name) {
@@ -467,7 +467,7 @@ const tsPlugin = (BaseParser: any) => {
467467
const node = this.startNode()
468468
const keyword = this.value
469469
this.next()
470-
this.finishNode(node, tsPredefinedType[keyword])
470+
this.finishNode(node, tsPredefinedType[keyword as keyof typeof tsPredefinedType])
471471
return node
472472
}
473473

@@ -1028,18 +1028,27 @@ const tsPlugin = (BaseParser: any) => {
10281028
}
10291029

10301030
_parseMaybeTSExpression(node: any) {
1031-
if (this.type === tokTypes.prefix && tsExprMarkup[this.value] === tsExprMarkup['!']) {
1031+
if (
1032+
this.type === tokTypes.prefix &&
1033+
tsExprMarkup[this.value as keyof typeof tsExprMarkup] === tsExprMarkup['!']
1034+
) {
10321035
node = this.parseTSNonNullExpression(node)
10331036
}
1034-
if (this.type === tokTypes.name && tsExprMarkup[this.value] === tsExprMarkup.as) {
1037+
if (
1038+
this.type === tokTypes.name &&
1039+
tsExprMarkup[this.value as keyof typeof tsExprMarkup] === tsExprMarkup.as
1040+
) {
10351041
node = this.parseTSAsExpression(node)
10361042
}
10371043
return node
10381044
}
10391045

10401046
parseTSAsExpression(expression: any) {
10411047
let node = expression
1042-
while (this.type === tokTypes.name && tsExprMarkup[this.value] === tsExprMarkup.as) {
1048+
while (
1049+
this.type === tokTypes.name &&
1050+
tsExprMarkup[this.value as keyof typeof tsExprMarkup] === tsExprMarkup.as
1051+
) {
10431052
const _node = this.startNodeAtNode(node)
10441053
this.next()
10451054
_node.expression = node
@@ -1051,7 +1060,10 @@ const tsPlugin = (BaseParser: any) => {
10511060

10521061
parseTSNonNullExpression(expression: any) {
10531062
let node = expression
1054-
while (this.type === tokTypes.prefix && tsExprMarkup[this.value] === tsExprMarkup['!']) {
1063+
while (
1064+
this.type === tokTypes.prefix &&
1065+
tsExprMarkup[this.value as keyof typeof tsExprMarkup] === tsExprMarkup['!']
1066+
) {
10551067
const _node = this.startNodeAtNode(node)
10561068
_node.expression = node
10571069
this.next()

src/stepper/converter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ function evaluateFunctionObject(node: substituterNodes, context: Context) {
7979
if (node.type === 'Identifier' && builtinFunctions[node.name]) {
8080
;(global as any)[node.name] = builtinFunctions[node.name]
8181
}
82-
for (const key in node) {
83-
if (node[key as keyof typeof node] && typeof node[key as keyof typeof node] === 'object') {
84-
lookUpIdentifiers(node[key as keyof typeof node] as unknown as substituterNodes, visited)
82+
for (const k in node) {
83+
const key = k as keyof typeof node
84+
if (node[key] && typeof node[key] === 'object') {
85+
lookUpIdentifiers(node[key] as unknown as substituterNodes, visited)
8586
}
8687
}
8788
}

src/transpiler/transpiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { NATIVE_STORAGE_ID, UNKNOWN_LOCATION } from '../constants'
77
import { Chapter, type Context, type NativeStorage, type Node, Variant } from '../types'
88
import * as create from '../utils/ast/astCreator'
99
import { filterImportDeclarations, getImportedName } from '../utils/ast/helpers'
10+
import { isNamespaceSpecifier } from '../utils/ast/typeGuards'
1011
import {
1112
getFunctionDeclarationNamesInProgram,
1213
getIdentifiersInNativeStorage,
@@ -17,7 +18,6 @@ import {
1718
} from '../utils/uniqueIds'
1819
import { simple } from '../utils/walkers'
1920
import { checkForUndefinedVariables } from '../validator/validator'
20-
import { isNamespaceSpecifier } from '../utils/ast/typeGuards'
2121

2222
/**
2323
* This whole transpiler includes many many many many hacks to get stuff working.

src/utils/uniqueIds.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const globalIdNames = [
2020
export type NativeIds = Record<(typeof globalIdNames)[number], es.Identifier>
2121

2222
export function getNativeIds(program: es.Program, usedIdentifiers: Set<string>): NativeIds {
23-
const globalIds = {}
23+
const globalIds: Partial<NativeIds> = {}
2424
for (const identifier of globalIdNames) {
2525
globalIds[identifier] = create.identifier(getUniqueId(usedIdentifiers, identifier))
2626
}

0 commit comments

Comments
 (0)