Skip to content

Commit

Permalink
refactor: remove unneeded index access
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Jun 21, 2024
1 parent 16699df commit 64d6392
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/ast/bare-configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ export function configure(schema: ast.Ast, config: Config): ast.Ast {
aliasesInFlatUnion: new Set(),
symbols: ast.symbols(schema),
}
const defs = schema.defs.slice()
for (let i = 0; i < defs.length; i++) {
const type = configureType(c, defs[i].type, true)
if (defs[i].type !== type) {
const { alias, internal, comment, offset } = defs[i]
defs[i] = { alias, internal, type, comment, offset }
const defs: ast.AliasedType[] = []
for (let def of schema.defs) {
const type = configureType(c, def.type, true)
if (def.type !== type) {
const { alias, internal, comment, offset } = def
def = { alias, internal, type, comment, offset }
}
defs.push(def)
}
for (let i = 0; i < defs.length; i++) {
let type = defs[i].type
Expand Down
9 changes: 4 additions & 5 deletions src/ast/bare-semantic-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Checker = {

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

function checkUnionInvariants(c: Checker, type: ast.UnionType): void {
const tags = type.data
// check type uniqueness
const stringifiedTypes = new Set()
for (let i = 0; i < tags.length; i++) {
const stringifiedType = JSON.stringify(ast.withoutExtra(type.types[i]))
for (const ty of type.types) {
const stringifiedType = JSON.stringify(ast.withoutExtra(ty))
// NOTE: this dirty check is ok because we initialize
// every object in the same way (properties are in the same order)
if (stringifiedTypes.has(stringifiedType)) {
throw new CompilerError(
"a type cannot be repeated in an union.",
type.types[i].offset,
ty.offset,
)
}
stringifiedTypes.add(stringifiedType)
Expand Down
2 changes: 1 addition & 1 deletion src/parser/bare-lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function nextToken(lex: Lexer): void {
offset += token.length
token = ""
while (offset < content.length) {
const c = content[offset]
const c = content[offset] as string
if (c === "#") {
// comment
let index = content.indexOf("\n", offset + 1)
Expand Down

0 comments on commit 64d6392

Please sign in to comment.