Skip to content

Commit 79f9061

Browse files
committed
refactor: remove unneeded index access
1 parent 2bd3656 commit 79f9061

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/ast/bare-configure.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ export function configure(schema: ast.Ast, config: Config): ast.Ast {
1010
aliasesInFlatUnion: new Set(),
1111
symbols: ast.symbols(schema),
1212
}
13-
const defs = schema.defs.slice()
14-
for (let i = 0; i < defs.length; i++) {
15-
const type = configureType(c, defs[i].type, true)
16-
if (defs[i].type !== type) {
17-
const { alias, internal, comment, offset } = defs[i]
18-
defs[i] = { alias, internal, type, comment, offset }
13+
const defs: ast.AliasedType[] = []
14+
for (let def of schema.defs) {
15+
const type = configureType(c, def.type, true)
16+
if (def.type !== type) {
17+
const { alias, internal, comment, offset } = def
18+
def = { alias, internal, type, comment, offset }
1919
}
20+
defs.push(def)
2021
}
2122
for (let i = 0; i < defs.length; i++) {
2223
let type = defs[i].type

src/ast/bare-semantic-checker.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Checker = {
4646

4747
function checkTypeName(aliased: ast.AliasedType): void {
4848
const { alias, internal } = aliased
49-
if (alias.length !== 0 && /^\d/.test(alias[0])) {
49+
if (/^\d/.test(alias)) {
5050
if (!internal) {
5151
throw new CompilerError(
5252
`the type name '${alias}' must not start with a figure or must be internal.`,
@@ -235,17 +235,16 @@ function checkNonVoid(c: Checker, type: ast.Type): void {
235235
}
236236

237237
function checkUnionInvariants(c: Checker, type: ast.UnionType): void {
238-
const tags = type.data
239238
// check type uniqueness
240239
const stringifiedTypes = new Set()
241-
for (let i = 0; i < tags.length; i++) {
242-
const stringifiedType = JSON.stringify(ast.withoutExtra(type.types[i]))
240+
for (const ty of type.types) {
241+
const stringifiedType = JSON.stringify(ast.withoutExtra(ty))
243242
// NOTE: this dirty check is ok because we initialize
244243
// every object in the same way (properties are in the same order)
245244
if (stringifiedTypes.has(stringifiedType)) {
246245
throw new CompilerError(
247246
"a type cannot be repeated in an union.",
248-
type.types[i].offset,
247+
ty.offset,
249248
)
250249
}
251250
stringifiedTypes.add(stringifiedType)

src/parser/bare-lexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function nextToken(lex: Lexer): void {
5656
offset += token.length
5757
token = ""
5858
while (offset < content.length) {
59-
const c = content[offset]
59+
const c = content[offset] as string
6060
if (c === "#") {
6161
// comment
6262
let index = content.indexOf("\n", offset + 1)

0 commit comments

Comments
 (0)