Skip to content

Commit

Permalink
Merge pull request #590 from eemeli/update-deps
Browse files Browse the repository at this point in the history
Update dependencies & fix minor TS issue
  • Loading branch information
eemeli committed Apr 29, 2022
2 parents 5406b34 + ebd98dc commit d101b90
Show file tree
Hide file tree
Showing 6 changed files with 3,282 additions and 3,162 deletions.
15 changes: 6 additions & 9 deletions fluent-langneg/src/negotiate_languages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {filterMatches} from "./matches.js";
import { filterMatches } from "./matches.js";

export interface NegotiateLanguagesOptions {
strategy?: "filtering" | "matching" | "lookup";
Expand Down Expand Up @@ -51,22 +51,19 @@ export interface NegotiateLanguagesOptions {
export function negotiateLanguages(
requestedLocales: Readonly<Array<string>>,
availableLocales: Readonly<Array<string>>,
{
strategy = "filtering",
defaultLocale,
}: NegotiateLanguagesOptions = {}
{ strategy = "filtering", defaultLocale }: NegotiateLanguagesOptions = {}
): Array<string> {

const supportedLocales = filterMatches(
Array.from(Object(requestedLocales)).map(String),
Array.from(Object(availableLocales)).map(String),
Array.from(requestedLocales ?? []).map(String),
Array.from(availableLocales ?? []).map(String),
strategy
);

if (strategy === "lookup") {
if (defaultLocale === undefined) {
throw new Error(
"defaultLocale cannot be undefined for strategy `lookup`");
"defaultLocale cannot be undefined for strategy `lookup`"
);
}
if (supportedLocales.length === 0) {
supportedLocales.push(defaultLocale);
Expand Down
5 changes: 3 additions & 2 deletions fluent-syntax/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export abstract class BaseNode {
return true;
}

clone(): BaseNode {
clone(): this {
function visit(value: unknown): unknown {
if (value instanceof BaseNode) {
return value.clone();
Expand All @@ -57,7 +57,8 @@ export abstract class BaseNode {
}
return value;
}
const clone = Object.create(this.constructor.prototype) as BaseNode;
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const clone = Object.create(this.constructor.prototype) as this;
for (const prop of Object.keys(this)) {
clone[prop] = visit(this[prop]);
}
Expand Down
12 changes: 7 additions & 5 deletions fluent-syntax/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export abstract class Transformer extends Visitor {
} else if (Array.isArray(prop)) {
let newVals: Array<AST.BaseNode> = [];
for (let element of prop) {
let newVal = this.visit(element);
let newVal = this.visit(element as AST.BaseNode);
if (newVal !== undefined) {
newVals.push(newVal);
}
Expand All @@ -127,10 +127,12 @@ export abstract class Transformer extends Visitor {
visitNumberLiteral?(node: AST.NumberLiteral): AST.BaseNode | undefined;
visitMessageReference?(node: AST.MessageReference): AST.BaseNode | undefined;
visitTermReference?(node: AST.TermReference): AST.BaseNode | undefined;
visitVariableReference?(node: AST.VariableReference):
AST.BaseNode | undefined;
visitFunctionReference?(node: AST.FunctionReference):
AST.BaseNode | undefined;
visitVariableReference?(
node: AST.VariableReference
): AST.BaseNode | undefined;
visitFunctionReference?(
node: AST.FunctionReference
): AST.BaseNode | undefined;
visitSelectExpression?(node: AST.SelectExpression): AST.BaseNode | undefined;
visitCallArguments?(node: AST.CallArguments): AST.BaseNode | undefined;
visitAttribute?(node: AST.Attribute): AST.BaseNode | undefined;
Expand Down
Loading

0 comments on commit d101b90

Please sign in to comment.