Skip to content

Commit

Permalink
Cast style-spec types to Type
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Wipfli authored and wipfli committed Jul 18, 2021
1 parent 95781ad commit efc4b1f
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 172 deletions.
2 changes: 1 addition & 1 deletion src/style-spec/expression/definitions/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Assertion implements Expression {

const parsed = [];
for (; i < args.length; i++) {
const input = context.parse(args[i], i, ValueType);
const input = context.parse(args[i], i, ValueType as Type);
if (!input) return null;
parsed.push(input);
}
Expand Down
4 changes: 2 additions & 2 deletions src/style-spec/expression/definitions/at.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class At implements Expression {
if (args.length !== 3)
return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`) as null;

const index = context.parse(args[1], 1, NumberType);
const input = context.parse(args[2], 2, array(context.expectedType || ValueType));
const index = context.parse(args[1], 1, NumberType as Type);
const input = context.parse(args[2], 2, array((context.expectedType || ValueType) as Type));

if (!index || !input) return null;

Expand Down
2 changes: 1 addition & 1 deletion src/style-spec/expression/definitions/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Case implements Expression {

const branches = [];
for (let i = 1; i < args.length - 1; i += 2) {
const test = context.parse(args[i], i, BooleanType);
const test = context.parse(args[i], i, BooleanType as Type);
if (!test) return null;

const result = context.parse(args[i + 1], i + 1, outputType);
Expand Down
2 changes: 1 addition & 1 deletion src/style-spec/expression/definitions/coalesce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Coalesce implements Expression {
parsedArgs.some(arg => checkSubtype(expectedType, arg.type));

return needsAnnotation ?
new Coalesce(ValueType, parsedArgs) :
new Coalesce(ValueType as Type, parsedArgs) :
new Coalesce((outputType as any), parsedArgs);
}

Expand Down
2 changes: 1 addition & 1 deletion src/style-spec/expression/definitions/coercion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Coercion implements Expression {

const parsed = [];
for (let i = 1; i < args.length; i++) {
const input = context.parse(args[i], i, ValueType);
const input = context.parse(args[i], i, ValueType as Type);
if (!input) return null;
parsed.push(input);
}
Expand Down
8 changes: 4 additions & 4 deletions src/style-spec/expression/definitions/collator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class CollatorExpression implements Expression {
locale: Expression | null;

constructor(caseSensitive: Expression, diacriticSensitive: Expression, locale: Expression | null) {
this.type = CollatorType;
this.type = CollatorType as Type;
this.locale = locale;
this.caseSensitive = caseSensitive;
this.diacriticSensitive = diacriticSensitive;
Expand All @@ -28,16 +28,16 @@ export default class CollatorExpression implements Expression {
return context.error(`Collator options argument must be an object.`) as null;

const caseSensitive = context.parse(
options['case-sensitive'] === undefined ? false : options['case-sensitive'], 1, BooleanType);
options['case-sensitive'] === undefined ? false : options['case-sensitive'], 1, BooleanType as Type);
if (!caseSensitive) return null;

const diacriticSensitive = context.parse(
options['diacritic-sensitive'] === undefined ? false : options['diacritic-sensitive'], 1, BooleanType);
options['diacritic-sensitive'] === undefined ? false : options['diacritic-sensitive'], 1, BooleanType as Type);
if (!diacriticSensitive) return null;

let locale = null;
if (options['locale']) {
locale = context.parse(options['locale'], 1, StringType);
locale = context.parse(options['locale'], 1, StringType as Type);
if (!locale) return null;
}

Expand Down
8 changes: 4 additions & 4 deletions src/style-spec/expression/definitions/comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato
hasUntypedArgument: boolean;

constructor(lhs: Expression, rhs: Expression, collator?: Expression | null) {
this.type = BooleanType;
this.type = BooleanType as Type;
this.lhs = lhs;
this.rhs = rhs;
this.collator = collator;
Expand All @@ -81,12 +81,12 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato

const op: ComparisonOperator = (args[0] as any);

let lhs = context.parse(args[1], 1, ValueType);
let lhs = context.parse(args[1], 1, ValueType as Type);
if (!lhs) return null;
if (!isComparableType(op, lhs.type)) {
return context.concat(1).error(`"${op}" comparisons are not supported for type '${toString(lhs.type)}'.`) as null;
}
let rhs = context.parse(args[2], 2, ValueType);
let rhs = context.parse(args[2], 2, ValueType as Type);
if (!rhs) return null;
if (!isComparableType(op, rhs.type)) {
return context.concat(2).error(`"${op}" comparisons are not supported for type '${toString(rhs.type)}'.`) as null;
Expand Down Expand Up @@ -121,7 +121,7 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato
) {
return context.error(`Cannot use collator to compare non-string types.`) as null;
}
collator = context.parse(args[3], 3, CollatorType);
collator = context.parse(args[3], 3, CollatorType as Type);
if (!collator) return null;
}

Expand Down
10 changes: 5 additions & 5 deletions src/style-spec/expression/definitions/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class FormatExpression implements Expression {
sections: Array<FormattedSectionExpression>;

constructor(sections: Array<FormattedSectionExpression>) {
this.type = FormattedType;
this.type = FormattedType as Type;
this.sections = sections;
}

Expand All @@ -53,19 +53,19 @@ export default class FormatExpression implements Expression {

let scale = null;
if (arg['font-scale']) {
scale = context.parse(arg['font-scale'], 1, NumberType);
scale = context.parse(arg['font-scale'], 1, NumberType as Type);
if (!scale) return null;
}

let font = null;
if (arg['text-font']) {
font = context.parse(arg['text-font'], 1, array(StringType));
font = context.parse(arg['text-font'], 1, array(StringType as Type));
if (!font) return null;
}

let textColor = null;
if (arg['text-color']) {
textColor = context.parse(arg['text-color'], 1, ColorType);
textColor = context.parse(arg['text-color'], 1, ColorType as Type);
if (!textColor) return null;
}

Expand All @@ -74,7 +74,7 @@ export default class FormatExpression implements Expression {
lastExpression.font = font;
lastExpression.textColor = textColor;
} else {
const content = context.parse(args[i], 1, ValueType);
const content = context.parse(args[i], 1, ValueType as Type);
if (!content) return null;

const kind = content.type.kind;
Expand Down
4 changes: 2 additions & 2 deletions src/style-spec/expression/definitions/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class ImageExpression implements Expression {
input: Expression;

constructor(input: Expression) {
this.type = ResolvedImageType;
this.type = ResolvedImageType as Type;
this.input = input;
}

Expand All @@ -20,7 +20,7 @@ export default class ImageExpression implements Expression {
return context.error(`Expected two arguments.`) as null;
}

const name = context.parse(args[1], 1, StringType);
const name = context.parse(args[1], 1, StringType as Type);
if (!name) return context.error(`No image name provided.`) as null;

return new ImageExpression(name);
Expand Down
8 changes: 4 additions & 4 deletions src/style-spec/expression/definitions/in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class In implements Expression {
haystack: Expression;

constructor(needle: Expression, haystack: Expression) {
this.type = BooleanType;
this.type = BooleanType as Type;
this.needle = needle;
this.haystack = haystack;
}
Expand All @@ -32,13 +32,13 @@ class In implements Expression {
return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`) as null;
}

const needle = context.parse(args[1], 1, ValueType);
const needle = context.parse(args[1], 1, ValueType as Type);

const haystack = context.parse(args[2], 2, ValueType);
const haystack = context.parse(args[2], 2, ValueType as Type);

if (!needle || !haystack) return null;

if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) {
if (!isValidType(needle.type, [BooleanType as Type, StringType as Type, NumberType as Type, NullType as Type, ValueType as Type])) {
return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`) as null;
}

Expand Down
Loading

0 comments on commit efc4b1f

Please sign in to comment.