Skip to content

Commit

Permalink
Merge pull request #764 from uzmoi/fix-types
Browse files Browse the repository at this point in the history
Fix types
  • Loading branch information
uzmoi authored Aug 26, 2024
2 parents 57d3fb3 + a7aa1e9 commit c73ec97
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion etc/aiscript.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export class Interpreter {
// (undocumented)
abort(): void;
// (undocumented)
static collectMetadata(script?: Ast.Node[]): Map<string, JsValue> | undefined;
static collectMetadata(script?: Ast.Node[]): Map<string | null, JsValue> | undefined;
// (undocumented)
exec(script?: Ast.Node[]): Promise<void>;
execFn(fn: VFn, args: Value[]): Promise<Value>;
Expand Down
10 changes: 5 additions & 5 deletions src/interpreter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class Interpreter {
}

@autobind
public static collectMetadata(script?: Ast.Node[]): Map<string, JsValue> | undefined {
public static collectMetadata(script?: Ast.Node[]): Map<string | null, JsValue> | undefined {
if (script == null || script.length === 0) return;

function nodeToJs(node: Ast.Node): JsValue {
Expand All @@ -134,7 +134,7 @@ export class Interpreter {
}
}

const meta = new Map();
const meta = new Map<string | null, JsValue>();

for (const node of script) {
switch (node.type) {
Expand Down Expand Up @@ -446,9 +446,9 @@ export class Interpreter {
case 'arr': return ARR(await Promise.all(node.value.map(item => this._eval(item, scope))));

case 'obj': {
const obj = new Map() as Map<string, Value>;
for (const k of node.value.keys()) {
obj.set(k, await this._eval(node.value.get(k)!, scope));
const obj = new Map<string, Value>();
for (const [key, value] of node.value) {
obj.set(key, await this._eval(value, scope));
}
return OBJ(obj);
}
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function jsToVal(val: unknown): Value {
if (typeof val === 'number') return NUM(val);
if (Array.isArray(val)) return ARR(val.map(item => jsToVal(item)));
if (typeof val === 'object') {
const obj = new Map();
const obj: VObj['value'] = new Map();
for (const [k, v] of Object.entries(val)) {
obj.set(k, jsToVal(v));
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/syntaxes/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ function parseObject(s: ITokenStream, isStatic: boolean): Ast.Obj {
s.next();
}

const map = new Map();
const map = new Map<string, Ast.Expression>();
while (!s.is(TokenKind.CloseBrace)) {
s.expect(TokenKind.Identifier);
const k = s.getTokenValue();
Expand Down

0 comments on commit c73ec97

Please sign in to comment.