Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies & fix minor TS issue #590

Merged
merged 5 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Comment on lines -61 to +58
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the same effect of avoiding throws for nullish inputs as before, but is clearer & type-friendlier about it.

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