From bcf64fc2ac5a29fb2e54493b311f59fa9687e248 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Fri, 15 Nov 2024 14:50:55 +0100 Subject: [PATCH 01/19] named validate --- bin/gl-style-validate.ts | 2 +- src/index.ts | 2 +- src/migrate.test.ts | 2 +- src/validate/validate.ts | 2 +- src/validate/validate_padding.test.ts | 2 +- src/validate/validate_projection.test.ts | 2 +- src/validate/validate_raster_dem_source.test.ts | 2 +- src/validate/validate_sky.test.ts | 2 +- src/validate/validate_sprite.test.ts | 2 +- src/validate/validate_terrain.test.ts | 2 +- src/validate/validate_variable_anchor_offset_collection.test.ts | 2 +- src/validate_style.min.ts | 2 +- src/validate_style.ts | 2 +- test/integration/style-spec/validate_spec.test.ts | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bin/gl-style-validate.ts b/bin/gl-style-validate.ts index df9536588..1ca81a123 100644 --- a/bin/gl-style-validate.ts +++ b/bin/gl-style-validate.ts @@ -2,7 +2,7 @@ import minimist from 'minimist'; import rw from 'rw'; -import validate from '../src/validate_style'; +import {validateStyle as validate} from '../src/validate_style'; const argv = minimist(process.argv.slice(2), { boolean: 'json', diff --git a/src/index.ts b/src/index.ts index 8d8e2729b..a9174947a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,7 +36,7 @@ import Literal from './expression/definitions/literal'; import CompoundExpression from './expression/compound_expression'; import {VariableAnchorOffsetCollectionSpecification} from './types.g'; import format from './format'; -import validate from './validate/validate'; +import {validate} from './validate/validate'; import migrate from './migrate'; import {classifyRings} from './util/classify_rings'; diff --git a/src/migrate.test.ts b/src/migrate.test.ts index fe5b6522a..963eb9be8 100644 --- a/src/migrate.test.ts +++ b/src/migrate.test.ts @@ -1,7 +1,7 @@ import migrate from './migrate'; import * as spec from '.'; import v8 from './reference/v8.json' with {type: 'json'}; -import validate from './validate_style'; +import {validateStyle as validate} from './validate_style'; describe('migrate', () => { test('does not migrate from version 5', () => { diff --git a/src/validate/validate.ts b/src/validate/validate.ts index e400098de..2ea979695 100644 --- a/src/validate/validate.ts +++ b/src/validate/validate.ts @@ -71,7 +71,7 @@ const VALIDATORS = { * @param options.objectElementValidators - optional object of functions that will be called * @returns an array of errors, or an empty array if no errors are found. */ -export default function validate(options: { +export function validate(options: { key: any; value: any; valueSpec: any; diff --git a/src/validate/validate_padding.test.ts b/src/validate/validate_padding.test.ts index b4003931f..9230e7672 100644 --- a/src/validate/validate_padding.test.ts +++ b/src/validate/validate_padding.test.ts @@ -1,4 +1,4 @@ -import validateSpec from './validate'; +import {validate as validateSpec} from './validate'; import validatePadding from './validate_padding'; describe('Validate Padding', () => { diff --git a/src/validate/validate_projection.test.ts b/src/validate/validate_projection.test.ts index 454a4adf3..82212c757 100644 --- a/src/validate/validate_projection.test.ts +++ b/src/validate/validate_projection.test.ts @@ -1,5 +1,5 @@ import validateProjection from './validate_projection'; -import validateSpec from './validate'; +import {validate as validateSpec} from './validate'; import v8 from '../reference/v8.json' with {type: 'json'}; import {ProjectionSpecification} from '../types.g'; diff --git a/src/validate/validate_raster_dem_source.test.ts b/src/validate/validate_raster_dem_source.test.ts index aeb8c4415..afb804682 100644 --- a/src/validate/validate_raster_dem_source.test.ts +++ b/src/validate/validate_raster_dem_source.test.ts @@ -1,4 +1,4 @@ -import validateSpec from './validate'; +import {validate as validateSpec} from './validate'; import v8 from '../reference/v8.json' with {type: 'json'}; import validateRasterDEMSource from './validate_raster_dem_source'; import {RasterDEMSourceSpecification} from '../types.g'; diff --git a/src/validate/validate_sky.test.ts b/src/validate/validate_sky.test.ts index e1e8aa899..497e1cd1f 100644 --- a/src/validate/validate_sky.test.ts +++ b/src/validate/validate_sky.test.ts @@ -1,5 +1,5 @@ import validateSky from './validate_sky'; -import validateSpec from './validate'; +import {validate as validateSpec} from './validate'; import v8 from '../reference/v8.json' with {type: 'json'}; import {SkySpecification} from '../types.g'; diff --git a/src/validate/validate_sprite.test.ts b/src/validate/validate_sprite.test.ts index 400d8ac8f..2bc811e87 100644 --- a/src/validate/validate_sprite.test.ts +++ b/src/validate/validate_sprite.test.ts @@ -1,5 +1,5 @@ import validateSprite from './validate_sprite'; -import validateSpec from './validate'; +import {validate as validateSpec} from './validate'; describe('Validate Sprite', () => { test('Should return error if type is not string or array', () => { diff --git a/src/validate/validate_terrain.test.ts b/src/validate/validate_terrain.test.ts index ba204e2bd..d4e43b37c 100644 --- a/src/validate/validate_terrain.test.ts +++ b/src/validate/validate_terrain.test.ts @@ -1,4 +1,4 @@ -import validateSpec from './validate'; +import {validate as validateSpec} from './validate'; import validateTerrain from './validate_terrain'; import v8 from '../reference/v8.json' with {type: 'json'}; diff --git a/src/validate/validate_variable_anchor_offset_collection.test.ts b/src/validate/validate_variable_anchor_offset_collection.test.ts index 049b07bd9..c485e79f3 100644 --- a/src/validate/validate_variable_anchor_offset_collection.test.ts +++ b/src/validate/validate_variable_anchor_offset_collection.test.ts @@ -1,4 +1,4 @@ -import validate from './validate'; +import {validate} from './validate'; import validateVariableAnchorOffsetCollection from './validate_variable_anchor_offset_collection'; import latestStyleSpec from '../reference/latest'; diff --git a/src/validate_style.min.ts b/src/validate_style.min.ts index ca6d67577..5412926a5 100644 --- a/src/validate_style.min.ts +++ b/src/validate_style.min.ts @@ -1,6 +1,6 @@ import validateConstants from './validate/validate_constants'; -import validate from './validate/validate'; +import {validateStyle as validate} from './validate/validate'; import latestStyleSpec from './reference/latest'; import validateSource from './validate/validate_source'; diff --git a/src/validate_style.ts b/src/validate_style.ts index 7ab36e32e..de31ecd83 100644 --- a/src/validate_style.ts +++ b/src/validate_style.ts @@ -18,7 +18,7 @@ import type {StyleSpecification} from './types.g'; * const errors = validate(style); */ -export default function validateStyle(style: StyleSpecification | string | Buffer, styleSpec = v8): Array { +export function validateStyle(style: StyleSpecification | string | Buffer, styleSpec = v8): Array { let s = style; try { diff --git a/test/integration/style-spec/validate_spec.test.ts b/test/integration/style-spec/validate_spec.test.ts index 0604feda6..953c2a017 100644 --- a/test/integration/style-spec/validate_spec.test.ts +++ b/test/integration/style-spec/validate_spec.test.ts @@ -1,7 +1,7 @@ import {globSync} from 'glob'; import fs from 'fs'; import path from 'path'; -import validate from '../../../src/validate_style'; +import {validateStyle as validate} from '../../../src/validate_style'; import reference from '../../../src/reference/latest'; const UPDATE = !!process.env.UPDATE; From 251a95134f816cdee1c7ba00597658dc2c7656cc Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Fri, 15 Nov 2024 14:56:16 +0100 Subject: [PATCH 02/19] validate --- src/diff.ts | 4 +- src/empty.test.ts | 4 +- src/empty.ts | 2 +- src/error/validation_error.ts | 2 +- src/index.ts | 8 ++-- src/validate/validate.ts | 46 +++++++++---------- src/validate/validate_array.ts | 2 +- src/validate/validate_boolean.ts | 2 +- src/validate/validate_color.test.ts | 2 +- src/validate/validate_color.ts | 2 +- src/validate/validate_constants.ts | 2 +- src/validate/validate_enum.ts | 2 +- src/validate/validate_expression.ts | 2 +- src/validate/validate_filter.ts | 8 ++-- src/validate/validate_formatted.ts | 6 +-- src/validate/validate_function.ts | 10 ++-- src/validate/validate_glyphs_url.ts | 6 +-- src/validate/validate_image.ts | 6 +-- src/validate/validate_layer.ts | 12 ++--- src/validate/validate_layout_property.ts | 4 +- src/validate/validate_light.ts | 2 +- src/validate/validate_number.ts | 2 +- src/validate/validate_object.ts | 2 +- src/validate/validate_padding.test.ts | 2 +- src/validate/validate_padding.ts | 6 +-- src/validate/validate_paint_property.ts | 4 +- src/validate/validate_projection.test.ts | 2 +- src/validate/validate_projection.ts | 2 +- src/validate/validate_property.ts | 2 +- .../validate_raster_dem_source.test.ts | 2 +- src/validate/validate_raster_dem_source.ts | 2 +- src/validate/validate_sky.test.ts | 2 +- src/validate/validate_sky.ts | 2 +- src/validate/validate_source.ts | 14 +++--- src/validate/validate_sprite.test.ts | 2 +- src/validate/validate_sprite.ts | 8 ++-- src/validate/validate_string.ts | 2 +- src/validate/validate_terrain.test.ts | 2 +- src/validate/validate_terrain.ts | 2 +- ..._variable_anchor_offset_collection.test.ts | 2 +- ...idate_variable_anchor_offset_collection.ts | 8 ++-- src/validate_style.min.ts | 30 ++++++------ src/validate_style.ts | 2 +- 43 files changed, 117 insertions(+), 119 deletions(-) diff --git a/src/diff.ts b/src/diff.ts index c5f3cbe7a..f088c9212 100644 --- a/src/diff.ts +++ b/src/diff.ts @@ -267,7 +267,7 @@ function diffLayers(before: LayerSpecification[], after: LayerSpecification[], c * @param {*} after stylesheet to compare to * @returns Array list of changes */ -function diffStyles(before: StyleSpecification, after: StyleSpecification): DiffCommand[] { +export function diffStyles(before: StyleSpecification, after: StyleSpecification): DiffCommand[] { if (!before) return [{command: 'setStyle', args: [after]}]; let commands: DiffCommand[] = []; @@ -355,4 +355,4 @@ function diffStyles(before: StyleSpecification, after: StyleSpecification): Diff return commands; } -export default diffStyles; + diff --git a/src/empty.test.ts b/src/empty.test.ts index c8972af94..d5cbb9773 100644 --- a/src/empty.test.ts +++ b/src/empty.test.ts @@ -1,5 +1,5 @@ -import emptyStyle from './empty'; -import validateStyleMin from './validate_style.min'; +import {emptyStyle} from './empty'; +import {validateStyleMin} from './validate_style.min'; describe('empty', () => { test('it generates something', () => { diff --git a/src/empty.ts b/src/empty.ts index 6a9746874..40e18887e 100644 --- a/src/empty.ts +++ b/src/empty.ts @@ -1,7 +1,7 @@ import latest from './reference/latest'; import {StyleSpecification} from './types.g'; -export default function emptyStyle(): StyleSpecification { +export function emptyStyle(): StyleSpecification { const style = {}; const version = latest['$version']; diff --git a/src/error/validation_error.ts b/src/error/validation_error.ts index 0c489cc39..cd958cf34 100644 --- a/src/error/validation_error.ts +++ b/src/error/validation_error.ts @@ -1,6 +1,6 @@ // Note: Do not inherit from Error. It breaks when transpiling to ES5. -export default class ValidationError { +export class ValidationError { message: string; identifier: string; line: number; diff --git a/src/index.ts b/src/index.ts index a9174947a..c7902f544 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,8 +2,8 @@ import v8Spec from './reference/v8.json' with {type: 'json'}; const v8 = v8Spec as any; import latest from './reference/latest'; import derefLayers from './deref'; -import diff from './diff'; -import ValidationError from './error/validation_error'; +import {diffStyles as diff} from './diff'; +import {ValidationError} from './error/validation_error'; import ParsingError from './error/parsing_error'; import {FeatureState, StyleExpression, isExpression, isZoomExpression, createExpression, createPropertyExpression, normalizePropertyExpression, ZoomConstantExpression, ZoomDependentExpression, StylePropertyFunction, Feature, GlobalProperties, SourceExpression, CompositeExpression, StylePropertyExpression} from './expression'; import featureFilter, {isExpressionFilter} from './feature_filter'; @@ -27,8 +27,8 @@ import Interpolate from './expression/definitions/interpolate'; import {interpolateFactory, type InterpolationType} from './expression/definitions/interpolate'; import groupByLayout from './group_by_layout'; -import emptyStyle from './empty'; -import validateStyleMin from './validate_style.min'; +import {emptyStyle} from './empty'; +import {validateStyleMin} from './validate_style.min'; import Step from './expression/definitions/step'; import {typeOf} from './expression/values'; import FormatExpression from './expression/definitions/format'; diff --git a/src/validate/validate.ts b/src/validate/validate.ts index 2ea979695..0e8b8f403 100644 --- a/src/validate/validate.ts +++ b/src/validate/validate.ts @@ -4,29 +4,29 @@ import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; import {isExpression} from '../expression'; import {isFunction} from '../function'; -import validateFunction from './validate_function'; -import validateExpression from './validate_expression'; -import validateObject from './validate_object'; -import validateArray from './validate_array'; -import validateBoolean from './validate_boolean'; -import validateNumber from './validate_number'; -import validateColor from './validate_color'; -import validateConstants from './validate_constants'; -import validateEnum from './validate_enum'; -import validateFilter from './validate_filter'; -import validateLayer from './validate_layer'; -import validateSource from './validate_source'; -import validateLight from './validate_light'; -import validateSky from './validate_sky'; -import validateTerrain from './validate_terrain'; -import validateString from './validate_string'; -import validateFormatted from './validate_formatted'; -import validateImage from './validate_image'; -import validatePadding from './validate_padding'; -import validateVariableAnchorOffsetCollection from './validate_variable_anchor_offset_collection'; -import validateSprite from './validate_sprite'; -import ValidationError from '../error/validation_error'; -import validateProjection from './validate_projection'; +import {validateFunction} from './validate_function'; +import {validateExpression} from './validate_expression'; +import {validateObject} from './validate_object'; +import {validateArray} from './validate_array'; +import {validateBoolean} from './validate_boolean'; +import {validateNumber} from './validate_number'; +import {validateColor} from './validate_color'; +import {validateConstants} from './validate_constants'; +import {validateEnum} from './validate_enum'; +import {validateFilter} from './validate_filter'; +import {validateLayer} from './validate_layer'; +import {validateSource} from './validate_source'; +import {validateLight} from './validate_light'; +import {validateSky} from './validate_sky'; +import {validateTerrain} from './validate_terrain'; +import {validateString} from './validate_string'; +import {validateFormatted} from './validate_formatted'; +import {validateImage} from './validate_image'; +import {validatePadding} from './validate_padding'; +import {validateVariableAnchorOffsetCollection} from './validate_variable_anchor_offset_collection'; +import {validateSprite} from './validate_sprite'; +import {ValidationError} from '../error/validation_error'; +import {validateProjection} from './validate_projection'; const VALIDATORS = { '*'() { diff --git a/src/validate/validate_array.ts b/src/validate/validate_array.ts index b27db20e1..03f358a78 100644 --- a/src/validate/validate_array.ts +++ b/src/validate/validate_array.ts @@ -1,7 +1,7 @@ import getType from '../util/get_type'; import ValidationError from '../error/validation_error'; -export default function validateArray(options) { +export function validateArray(options) { const array = options.value; const arraySpec = options.valueSpec; const validateSpec = options.validateSpec; diff --git a/src/validate/validate_boolean.ts b/src/validate/validate_boolean.ts index 5412b23d2..950e016dc 100644 --- a/src/validate/validate_boolean.ts +++ b/src/validate/validate_boolean.ts @@ -2,7 +2,7 @@ import getType from '../util/get_type'; import ValidationError from '../error/validation_error'; -export default function validateBoolean(options) { +export function validateBoolean(options) { const value = options.value; const key = options.key; const type = getType(value); diff --git a/src/validate/validate_color.test.ts b/src/validate/validate_color.test.ts index 737392979..ea938fbf7 100644 --- a/src/validate/validate_color.test.ts +++ b/src/validate/validate_color.test.ts @@ -1,4 +1,4 @@ -import validateColor from './validate_color'; +import {validateColor} from './validate_color'; describe('validateColor function', () => { diff --git a/src/validate/validate_color.ts b/src/validate/validate_color.ts index feae4ba84..71a742909 100644 --- a/src/validate/validate_color.ts +++ b/src/validate/validate_color.ts @@ -2,7 +2,7 @@ import ValidationError from '../error/validation_error'; import getType from '../util/get_type'; import Color from '../expression/types/color'; -export default function validateColor(options) { +export function validateColor(options) { const key = options.key; const value = options.value; const type = getType(value); diff --git a/src/validate/validate_constants.ts b/src/validate/validate_constants.ts index 7888bb326..8d13e25cd 100644 --- a/src/validate/validate_constants.ts +++ b/src/validate/validate_constants.ts @@ -1,7 +1,7 @@ import ValidationError from '../error/validation_error'; -export default function validateConstants(options) { +export function validateConstants(options) { const key = options.key; const constants = options.value; diff --git a/src/validate/validate_enum.ts b/src/validate/validate_enum.ts index 66b9cb386..64495158d 100644 --- a/src/validate/validate_enum.ts +++ b/src/validate/validate_enum.ts @@ -2,7 +2,7 @@ import ValidationError from '../error/validation_error'; import {unbundle} from '../util/unbundle_jsonlint'; -export default function validateEnum(options) { +export function validateEnum(options) { const key = options.key; const value = options.value; const valueSpec = options.valueSpec; diff --git a/src/validate/validate_expression.ts b/src/validate/validate_expression.ts index 2ab2012f9..093452af5 100644 --- a/src/validate/validate_expression.ts +++ b/src/validate/validate_expression.ts @@ -9,7 +9,7 @@ import {isFeatureConstant, import {Expression} from '../expression/expression'; -export default function validateExpression(options: any): Array { +export function validateExpression(options: any): Array { const expression = (options.expressionContext === 'property' ? createPropertyExpression : createExpression)(deepUnbundle(options.value), options.valueSpec); if (expression.result === 'error') { return expression.value.map((error) => { diff --git a/src/validate/validate_filter.ts b/src/validate/validate_filter.ts index 659173c01..cb2fddd47 100644 --- a/src/validate/validate_filter.ts +++ b/src/validate/validate_filter.ts @@ -1,13 +1,13 @@ -import ValidationError from '../error/validation_error'; -import validateExpression from './validate_expression'; -import validateEnum from './validate_enum'; +import {ValidationError} from '../error/validation_error'; +import {validateExpression} from './validate_expression'; +import {validateEnum} from './validate_enum'; import getType from '../util/get_type'; import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; import extend from '../util/extend'; import {isExpressionFilter} from '../feature_filter'; -export default function validateFilter(options) { +export function validateFilter(options) { if (isExpressionFilter(deepUnbundle(options.value))) { return validateExpression(extend({}, options, { expressionContext: 'filter', diff --git a/src/validate/validate_formatted.ts b/src/validate/validate_formatted.ts index 3b622a681..44460f542 100644 --- a/src/validate/validate_formatted.ts +++ b/src/validate/validate_formatted.ts @@ -1,7 +1,7 @@ -import validateExpression from './validate_expression'; -import validateString from './validate_string'; +import {validateExpression} from './validate_expression'; +import {validateString} from './validate_string'; -export default function validateFormatted(options: any) { +export function validateFormatted(options: any) { if (validateString(options).length === 0) { return []; } diff --git a/src/validate/validate_function.ts b/src/validate/validate_function.ts index 8bd54e7f4..7f6e206d6 100644 --- a/src/validate/validate_function.ts +++ b/src/validate/validate_function.ts @@ -1,9 +1,9 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; -import validateObject from './validate_object'; -import validateArray from './validate_array'; -import validateNumber from './validate_number'; +import {validateObject} from './validate_object'; +import {validateArray} from './validate_array'; +import {validateNumber} from './validate_number'; import {isExpression} from '../expression'; import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; import { @@ -12,7 +12,7 @@ import { supportsInterpolation } from '../util/properties'; -export default function validateFunction(options): Array { +export function validateFunction(options): Array { const functionValueSpec = options.valueSpec; const functionType = unbundle(options.value.type); let stopKeyType; diff --git a/src/validate/validate_glyphs_url.ts b/src/validate/validate_glyphs_url.ts index 0b01492b1..4581edf2f 100644 --- a/src/validate/validate_glyphs_url.ts +++ b/src/validate/validate_glyphs_url.ts @@ -1,8 +1,8 @@ -import ValidationError from '../error/validation_error'; -import validateString from './validate_string'; +import {ValidationError} from '../error/validation_error'; +import {validateString} from './validate_string'; -export default function validateGlyphsUrl(options) { +export function validateGlyphsUrl(options) { const value = options.value; const key = options.key; diff --git a/src/validate/validate_image.ts b/src/validate/validate_image.ts index 6bc72596b..950947434 100644 --- a/src/validate/validate_image.ts +++ b/src/validate/validate_image.ts @@ -1,7 +1,7 @@ -import validateExpression from './validate_expression'; -import validateString from './validate_string'; +import {validateExpression} from './validate_expression'; +import {validateString} from './validate_string'; -export default function validateImage(options: any) { +export function validateImage(options: any) { if (validateString(options).length === 0) { return []; } diff --git a/src/validate/validate_layer.ts b/src/validate/validate_layer.ts index 136ca06c9..f5a0cc4d4 100644 --- a/src/validate/validate_layer.ts +++ b/src/validate/validate_layer.ts @@ -1,13 +1,13 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import {unbundle} from '../util/unbundle_jsonlint'; -import validateObject from './validate_object'; -import validateFilter from './validate_filter'; -import validatePaintProperty from './validate_paint_property'; -import validateLayoutProperty from './validate_layout_property'; +import {validateObject} from './validate_object'; +import {validateFilter} from './validate_filter'; +import {validatePaintProperty} from './validate_paint_property'; +import {validateLayoutProperty} from './validate_layout_property'; import extend from '../util/extend'; -export default function validateLayer(options) { +export function validateLayer(options) { let errors = []; const layer = options.value; diff --git a/src/validate/validate_layout_property.ts b/src/validate/validate_layout_property.ts index da4151a0b..ab18260fa 100644 --- a/src/validate/validate_layout_property.ts +++ b/src/validate/validate_layout_property.ts @@ -1,6 +1,6 @@ -import validateProperty from './validate_property'; +import {validateProperty} from './validate_property'; -export default function validateLayoutProperty(options) { +export function validateLayoutProperty(options) { return validateProperty(options, 'layout'); } diff --git a/src/validate/validate_light.ts b/src/validate/validate_light.ts index e9f92a84e..ab85a8b4d 100644 --- a/src/validate/validate_light.ts +++ b/src/validate/validate_light.ts @@ -1,7 +1,7 @@ import ValidationError from '../error/validation_error'; import getType from '../util/get_type'; -export default function validateLight(options) { +export function validateLight(options) { const light = options.value; const styleSpec = options.styleSpec; const lightSpec = styleSpec.light; diff --git a/src/validate/validate_number.ts b/src/validate/validate_number.ts index 50bddd62e..4362f4fc2 100644 --- a/src/validate/validate_number.ts +++ b/src/validate/validate_number.ts @@ -2,7 +2,7 @@ import getType from '../util/get_type'; import ValidationError from '../error/validation_error'; -export default function validateNumber(options) { +export function validateNumber(options) { const key = options.key; const value = options.value; const valueSpec = options.valueSpec; diff --git a/src/validate/validate_object.ts b/src/validate/validate_object.ts index 992bb100a..47d326d06 100644 --- a/src/validate/validate_object.ts +++ b/src/validate/validate_object.ts @@ -2,7 +2,7 @@ import ValidationError from '../error/validation_error'; import getType from '../util/get_type'; -export default function validateObject(options): Array { +export function validateObject(options): Array { const key = options.key; const object = options.value; const elementSpecs = options.valueSpec || {}; diff --git a/src/validate/validate_padding.test.ts b/src/validate/validate_padding.test.ts index 9230e7672..4d38d05ca 100644 --- a/src/validate/validate_padding.test.ts +++ b/src/validate/validate_padding.test.ts @@ -1,5 +1,5 @@ import {validate as validateSpec} from './validate'; -import validatePadding from './validate_padding'; +import {validatePadding} from './validate_padding'; describe('Validate Padding', () => { test('Should return error if type is not number or array', () => { diff --git a/src/validate/validate_padding.ts b/src/validate/validate_padding.ts index ac203b2c1..129b83442 100644 --- a/src/validate/validate_padding.ts +++ b/src/validate/validate_padding.ts @@ -1,8 +1,8 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; -import validateNumber from './validate_number'; +import {validateNumber} from './validate_number'; -export default function validatePadding(options) { +export function validatePadding(options) { const key = options.key; const value = options.value; const type = getType(value); diff --git a/src/validate/validate_paint_property.ts b/src/validate/validate_paint_property.ts index bafe9bbca..74e62ffd3 100644 --- a/src/validate/validate_paint_property.ts +++ b/src/validate/validate_paint_property.ts @@ -1,6 +1,6 @@ -import validateProperty from './validate_property'; +import {validateProperty} from './validate_property'; -export default function validatePaintProperty(options) { +export function validatePaintProperty(options) { return validateProperty(options, 'paint'); } diff --git a/src/validate/validate_projection.test.ts b/src/validate/validate_projection.test.ts index 82212c757..019d58abc 100644 --- a/src/validate/validate_projection.test.ts +++ b/src/validate/validate_projection.test.ts @@ -1,4 +1,4 @@ -import validateProjection from './validate_projection'; +import {validateProjection} from './validate_projection'; import {validate as validateSpec} from './validate'; import v8 from '../reference/v8.json' with {type: 'json'}; import {ProjectionSpecification} from '../types.g'; diff --git a/src/validate/validate_projection.ts b/src/validate/validate_projection.ts index 891da7cd8..b3ce297e6 100644 --- a/src/validate/validate_projection.ts +++ b/src/validate/validate_projection.ts @@ -11,7 +11,7 @@ interface ValidateProjectionOptions { validateSpec: Function; } -export default function validateProjection(options: ValidateProjectionOptions) { +export function validateProjection(options: ValidateProjectionOptions) { const projection = options.value; const styleSpec = options.styleSpec; const projectionSpec = styleSpec.projection; diff --git a/src/validate/validate_property.ts b/src/validate/validate_property.ts index 4eeb09110..1c8959e54 100644 --- a/src/validate/validate_property.ts +++ b/src/validate/validate_property.ts @@ -5,7 +5,7 @@ import {isFunction} from '../function'; import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; import {supportsPropertyExpression} from '../util/properties'; -export default function validateProperty(options, propertyType) { +export function validateProperty(options, propertyType) { const key = options.key; const validateSpec = options.validateSpec; const style = options.style; diff --git a/src/validate/validate_raster_dem_source.test.ts b/src/validate/validate_raster_dem_source.test.ts index afb804682..c49ba9b36 100644 --- a/src/validate/validate_raster_dem_source.test.ts +++ b/src/validate/validate_raster_dem_source.test.ts @@ -1,6 +1,6 @@ import {validate as validateSpec} from './validate'; import v8 from '../reference/v8.json' with {type: 'json'}; -import validateRasterDEMSource from './validate_raster_dem_source'; +import {validateRasterDEMSource} from './validate_raster_dem_source'; import {RasterDEMSourceSpecification} from '../types.g'; function checkErrorMessage(message: string, key: string, expectedType: string, foundType: string) { diff --git a/src/validate/validate_raster_dem_source.ts b/src/validate/validate_raster_dem_source.ts index b0679f1f7..e993e7bf0 100644 --- a/src/validate/validate_raster_dem_source.ts +++ b/src/validate/validate_raster_dem_source.ts @@ -12,7 +12,7 @@ interface ValidateRasterDENSourceOptions { validateSpec: Function; } -export default function validateRasterDEMSource( +export function validateRasterDEMSource( options: ValidateRasterDENSourceOptions ): ValidationError[] { diff --git a/src/validate/validate_sky.test.ts b/src/validate/validate_sky.test.ts index 497e1cd1f..5d297212f 100644 --- a/src/validate/validate_sky.test.ts +++ b/src/validate/validate_sky.test.ts @@ -1,4 +1,4 @@ -import validateSky from './validate_sky'; +import {validateSky} from './validate_sky'; import {validate as validateSpec} from './validate'; import v8 from '../reference/v8.json' with {type: 'json'}; import {SkySpecification} from '../types.g'; diff --git a/src/validate/validate_sky.ts b/src/validate/validate_sky.ts index f6e7bc555..d24496793 100644 --- a/src/validate/validate_sky.ts +++ b/src/validate/validate_sky.ts @@ -11,7 +11,7 @@ interface ValidateSkyOptions { validateSpec: Function; } -export default function validateSky(options: ValidateSkyOptions) { +export function validateSky(options: ValidateSkyOptions) { const sky = options.value; const styleSpec = options.styleSpec; const skySpec = styleSpec.sky; diff --git a/src/validate/validate_source.ts b/src/validate/validate_source.ts index a3ff80244..c56288e31 100644 --- a/src/validate/validate_source.ts +++ b/src/validate/validate_source.ts @@ -1,18 +1,18 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import {unbundle} from '../util/unbundle_jsonlint'; -import validateObject from './validate_object'; -import validateEnum from './validate_enum'; -import validateExpression from './validate_expression'; -import validateString from './validate_string'; +import {validateObject} from './validate_object'; +import {validateEnum} from './validate_enum'; +import {validateExpression} from './validate_expression'; +import {validateString} from './validate_string'; import getType from '../util/get_type'; -import validateRasterDEMSource from './validate_raster_dem_source'; +import {validateRasterDEMSource} from './validate_raster_dem_source'; const objectElementValidators = { promoteId: validatePromoteId }; -export default function validateSource(options) { +export function validateSource(options) { const value = options.value; const key = options.key; const styleSpec = options.styleSpec; diff --git a/src/validate/validate_sprite.test.ts b/src/validate/validate_sprite.test.ts index 2bc811e87..479041877 100644 --- a/src/validate/validate_sprite.test.ts +++ b/src/validate/validate_sprite.test.ts @@ -1,4 +1,4 @@ -import validateSprite from './validate_sprite'; +import {validateSprite} from './validate_sprite'; import {validate as validateSpec} from './validate'; describe('Validate Sprite', () => { diff --git a/src/validate/validate_sprite.ts b/src/validate/validate_sprite.ts index c77609e5c..4ff67d84f 100644 --- a/src/validate/validate_sprite.ts +++ b/src/validate/validate_sprite.ts @@ -1,6 +1,6 @@ -import validateObject from './validate_object'; -import validateString from './validate_string'; -import ValidationError from '../error/validation_error'; +import {validateObject} from './validate_object'; +import {validateString} from './validate_string'; +import {ValidationError} from '../error/validation_error'; interface ValidateSpriteOptions { key: 'sprite'; @@ -8,7 +8,7 @@ interface ValidateSpriteOptions { validateSpec: Function; } -export default function validateSprite(options: ValidateSpriteOptions) { +export function validateSprite(options: ValidateSpriteOptions) { let errors = []; const sprite = options.value; diff --git a/src/validate/validate_string.ts b/src/validate/validate_string.ts index c3353fdc5..f707199e1 100644 --- a/src/validate/validate_string.ts +++ b/src/validate/validate_string.ts @@ -2,7 +2,7 @@ import getType from '../util/get_type'; import ValidationError from '../error/validation_error'; -export default function validateString(options) { +export function validateString(options) { const value = options.value; const key = options.key; const type = getType(value); diff --git a/src/validate/validate_terrain.test.ts b/src/validate/validate_terrain.test.ts index d4e43b37c..3b52c0143 100644 --- a/src/validate/validate_terrain.test.ts +++ b/src/validate/validate_terrain.test.ts @@ -1,5 +1,5 @@ import {validate as validateSpec} from './validate'; -import validateTerrain from './validate_terrain'; +import {validateTerrain} from './validate_terrain'; import v8 from '../reference/v8.json' with {type: 'json'}; describe('Validate Terrain', () => { diff --git a/src/validate/validate_terrain.ts b/src/validate/validate_terrain.ts index ad6a5c91b..37ea0e148 100644 --- a/src/validate/validate_terrain.ts +++ b/src/validate/validate_terrain.ts @@ -3,7 +3,7 @@ import getType from '../util/get_type'; import type {StyleSpecification, TerrainSpecification} from '../types.g'; import v8 from '../reference/v8.json' with {type: 'json'}; -export default function validateTerrain( +export function validateTerrain( options: {value: TerrainSpecification; styleSpec: typeof v8; style: StyleSpecification; validateSpec: Function} ): ValidationError[] { diff --git a/src/validate/validate_variable_anchor_offset_collection.test.ts b/src/validate/validate_variable_anchor_offset_collection.test.ts index c485e79f3..f5974cb75 100644 --- a/src/validate/validate_variable_anchor_offset_collection.test.ts +++ b/src/validate/validate_variable_anchor_offset_collection.test.ts @@ -1,5 +1,5 @@ import {validate} from './validate'; -import validateVariableAnchorOffsetCollection from './validate_variable_anchor_offset_collection'; +import {validateVariableAnchorOffsetCollection} from './validate_variable_anchor_offset_collection'; import latestStyleSpec from '../reference/latest'; describe('Validate variableAnchorOffsetCollection', () => { diff --git a/src/validate/validate_variable_anchor_offset_collection.ts b/src/validate/validate_variable_anchor_offset_collection.ts index 28258fd4b..c7958b540 100644 --- a/src/validate/validate_variable_anchor_offset_collection.ts +++ b/src/validate/validate_variable_anchor_offset_collection.ts @@ -1,9 +1,9 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; -import validateArray from './validate_array'; -import validateEnum from './validate_enum'; +import {validateArray} from './validate_array'; +import {validateEnum} from './validate_enum'; -export default function validateVariableAnchorOffsetCollection(options): ValidationError[] { +export function validateVariableAnchorOffsetCollection(options): ValidationError[] { const key = options.key; const value = options.value; const type = getType(value); diff --git a/src/validate_style.min.ts b/src/validate_style.min.ts index 5412926a5..f825f1b6d 100644 --- a/src/validate_style.min.ts +++ b/src/validate_style.min.ts @@ -1,19 +1,19 @@ -import validateConstants from './validate/validate_constants'; -import {validateStyle as validate} from './validate/validate'; +import {validateConstants} from './validate/validate_constants'; +import {validate} from './validate/validate'; import latestStyleSpec from './reference/latest'; -import validateSource from './validate/validate_source'; -import validateLight from './validate/validate_light'; -import validateSky from './validate/validate_sky'; -import validateTerrain from './validate/validate_terrain'; -import validateLayer from './validate/validate_layer'; -import validateFilter from './validate/validate_filter'; -import validatePaintProperty from './validate/validate_paint_property'; -import validateLayoutProperty from './validate/validate_layout_property'; -import validateSprite from './validate/validate_sprite'; -import validateGlyphsUrl from './validate/validate_glyphs_url'; -import ValidationError from './error/validation_error'; +import {validateSource} from './validate/validate_source'; +import {validateLight} from './validate/validate_light'; +import {validateSky} from './validate/validate_sky'; +import {validateTerrain} from './validate/validate_terrain'; +import {validateLayer} from './validate/validate_layer'; +import {validateFilter} from './validate/validate_filter'; +import {validatePaintProperty} from './validate/validate_paint_property'; +import {validateLayoutProperty} from './validate/validate_layout_property'; +import {validateSprite} from './validate/validate_sprite'; +import {validateGlyphsUrl} from './validate/validate_glyphs_url'; +import {ValidationError} from './error/validation_error'; import type {StyleSpecification} from './types.g'; /** @@ -28,7 +28,7 @@ import type {StyleSpecification} from './types.g'; * const validate = require('@maplibre/maplibre-gl-style-spec/').validateStyleMin; * const errors = validate(style); */ -function validateStyleMin(style: StyleSpecification, styleSpec = latestStyleSpec): Array { +export function validateStyleMin(style: StyleSpecification, styleSpec = latestStyleSpec): Array { let errors: ValidationError[] = []; @@ -91,5 +91,3 @@ function wrapCleanErrors(inner) { return sortErrors(inner.apply(this, args)); }; } - -export default validateStyleMin; diff --git a/src/validate_style.ts b/src/validate_style.ts index de31ecd83..e29c1b499 100644 --- a/src/validate_style.ts +++ b/src/validate_style.ts @@ -1,5 +1,5 @@ -import validateStyleMin from './validate_style.min'; +import {validateStyleMin} from './validate_style.min'; import {v8, ValidationError} from '.'; import readStyle from './read_style'; import type {StyleSpecification} from './types.g'; From d3e664ef887cc9656778ccd4d07c8981cc19bde3 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Fri, 15 Nov 2024 14:57:08 +0100 Subject: [PATCH 03/19] validate --- src/diff.test.ts | 2 +- src/validate/validate_array.ts | 2 +- src/validate/validate_boolean.ts | 2 +- src/validate/validate_color.ts | 2 +- src/validate/validate_constants.ts | 2 +- src/validate/validate_enum.ts | 2 +- src/validate/validate_expression.ts | 2 +- src/validate/validate_light.ts | 2 +- src/validate/validate_number.ts | 2 +- src/validate/validate_object.ts | 2 +- src/validate/validate_projection.ts | 2 +- src/validate/validate_property.ts | 2 +- src/validate/validate_raster_dem_source.ts | 2 +- src/validate/validate_sky.ts | 2 +- src/validate/validate_string.ts | 2 +- src/validate/validate_terrain.ts | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/diff.test.ts b/src/diff.test.ts index 3a35fdb92..66a030388 100644 --- a/src/diff.test.ts +++ b/src/diff.test.ts @@ -1,4 +1,4 @@ -import diffStyles from './diff'; +import {diffStyles} from './diff'; import {StyleSpecification} from './types.g'; describe('diff', () => { diff --git a/src/validate/validate_array.ts b/src/validate/validate_array.ts index 03f358a78..2888af8dc 100644 --- a/src/validate/validate_array.ts +++ b/src/validate/validate_array.ts @@ -1,5 +1,5 @@ import getType from '../util/get_type'; -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; export function validateArray(options) { const array = options.value; diff --git a/src/validate/validate_boolean.ts b/src/validate/validate_boolean.ts index 950e016dc..55e262d5e 100644 --- a/src/validate/validate_boolean.ts +++ b/src/validate/validate_boolean.ts @@ -1,6 +1,6 @@ import getType from '../util/get_type'; -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; export function validateBoolean(options) { const value = options.value; diff --git a/src/validate/validate_color.ts b/src/validate/validate_color.ts index 71a742909..c5d2d1396 100644 --- a/src/validate/validate_color.ts +++ b/src/validate/validate_color.ts @@ -1,4 +1,4 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; import Color from '../expression/types/color'; diff --git a/src/validate/validate_constants.ts b/src/validate/validate_constants.ts index 8d13e25cd..9e27f4bf4 100644 --- a/src/validate/validate_constants.ts +++ b/src/validate/validate_constants.ts @@ -1,5 +1,5 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; export function validateConstants(options) { const key = options.key; diff --git a/src/validate/validate_enum.ts b/src/validate/validate_enum.ts index 64495158d..843556fb4 100644 --- a/src/validate/validate_enum.ts +++ b/src/validate/validate_enum.ts @@ -1,5 +1,5 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import {unbundle} from '../util/unbundle_jsonlint'; export function validateEnum(options) { diff --git a/src/validate/validate_expression.ts b/src/validate/validate_expression.ts index 093452af5..652afc05a 100644 --- a/src/validate/validate_expression.ts +++ b/src/validate/validate_expression.ts @@ -1,4 +1,4 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import {createExpression, createPropertyExpression} from '../expression'; import {deepUnbundle} from '../util/unbundle_jsonlint'; diff --git a/src/validate/validate_light.ts b/src/validate/validate_light.ts index ab85a8b4d..4cd06c4b8 100644 --- a/src/validate/validate_light.ts +++ b/src/validate/validate_light.ts @@ -1,4 +1,4 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; export function validateLight(options) { diff --git a/src/validate/validate_number.ts b/src/validate/validate_number.ts index 4362f4fc2..a922febdb 100644 --- a/src/validate/validate_number.ts +++ b/src/validate/validate_number.ts @@ -1,6 +1,6 @@ import getType from '../util/get_type'; -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; export function validateNumber(options) { const key = options.key; diff --git a/src/validate/validate_object.ts b/src/validate/validate_object.ts index 47d326d06..7bd9cfa84 100644 --- a/src/validate/validate_object.ts +++ b/src/validate/validate_object.ts @@ -1,5 +1,5 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; export function validateObject(options): Array { diff --git a/src/validate/validate_projection.ts b/src/validate/validate_projection.ts index b3ce297e6..3062541ed 100644 --- a/src/validate/validate_projection.ts +++ b/src/validate/validate_projection.ts @@ -1,4 +1,4 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; import v8 from '../reference/v8.json' with {type: 'json'}; import {ProjectionSpecification, StyleSpecification} from '../types.g'; diff --git a/src/validate/validate_property.ts b/src/validate/validate_property.ts index 1c8959e54..cdca4df36 100644 --- a/src/validate/validate_property.ts +++ b/src/validate/validate_property.ts @@ -1,5 +1,5 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; import {isFunction} from '../function'; import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; diff --git a/src/validate/validate_raster_dem_source.ts b/src/validate/validate_raster_dem_source.ts index e993e7bf0..a7c3623d9 100644 --- a/src/validate/validate_raster_dem_source.ts +++ b/src/validate/validate_raster_dem_source.ts @@ -1,4 +1,4 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; import type {RasterDEMSourceSpecification, StyleSpecification} from '../types.g'; import v8 from '../reference/v8.json' with {type: 'json'}; diff --git a/src/validate/validate_sky.ts b/src/validate/validate_sky.ts index d24496793..4e33cf3fc 100644 --- a/src/validate/validate_sky.ts +++ b/src/validate/validate_sky.ts @@ -1,4 +1,4 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; import v8 from '../reference/v8.json' with {type: 'json'}; import {SkySpecification, StyleSpecification} from '../types.g'; diff --git a/src/validate/validate_string.ts b/src/validate/validate_string.ts index f707199e1..0801d4670 100644 --- a/src/validate/validate_string.ts +++ b/src/validate/validate_string.ts @@ -1,6 +1,6 @@ import getType from '../util/get_type'; -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; export function validateString(options) { const value = options.value; diff --git a/src/validate/validate_terrain.ts b/src/validate/validate_terrain.ts index 37ea0e148..4e6ea40b2 100644 --- a/src/validate/validate_terrain.ts +++ b/src/validate/validate_terrain.ts @@ -1,4 +1,4 @@ -import ValidationError from '../error/validation_error'; +import {ValidationError} from '../error/validation_error'; import getType from '../util/get_type'; import type {StyleSpecification, TerrainSpecification} from '../types.g'; import v8 from '../reference/v8.json' with {type: 'json'}; From b54c09d4565f83274a74eca6f0cdfbd0ddc9bb79 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 17:03:34 +0100 Subject: [PATCH 04/19] named validators --- src/declass.test.ts | 2 +- src/declass.ts | 6 ++---- src/deref.ts | 6 ++---- src/expression/index.ts | 2 +- src/function/index.ts | 4 ++-- src/group_by_layout.ts | 2 +- src/util/extend.ts | 2 +- src/util/get_type.ts | 2 +- src/util/ref_properties.ts | 3 +-- src/validate/validate.ts | 2 +- src/validate/validate_array.ts | 2 +- src/validate/validate_boolean.ts | 2 +- src/validate/validate_color.ts | 2 +- src/validate/validate_filter.ts | 4 ++-- src/validate/validate_function.ts | 2 +- src/validate/validate_layer.ts | 2 +- src/validate/validate_light.ts | 2 +- src/validate/validate_number.ts | 2 +- src/validate/validate_object.ts | 2 +- src/validate/validate_padding.ts | 2 +- src/validate/validate_projection.ts | 2 +- src/validate/validate_property.ts | 2 +- src/validate/validate_raster_dem_source.ts | 2 +- src/validate/validate_sky.ts | 2 +- src/validate/validate_source.ts | 2 +- src/validate/validate_string.ts | 2 +- src/validate/validate_terrain.ts | 2 +- src/validate/validate_variable_anchor_offset_collection.ts | 2 +- 28 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/declass.test.ts b/src/declass.test.ts index 57b845c2e..822c7cbce 100644 --- a/src/declass.test.ts +++ b/src/declass.test.ts @@ -1,4 +1,4 @@ -import declass from './declass'; +import {declassStyle as declass} from './declass'; describe('declass', () => { test('declass a style, one class', () => { diff --git a/src/declass.ts b/src/declass.ts index 7e4987098..4b6bfbe81 100644 --- a/src/declass.ts +++ b/src/declass.ts @@ -1,7 +1,5 @@ -import extend from './util/extend'; - -export default declassStyle; +import {extendBy as extend} from './util/extend'; /** * Returns a new style with the given 'paint classes' merged into each layer's @@ -18,7 +16,7 @@ export default declassStyle; * // nightStyle now has each layer's `paint.night` properties merged in to the * // main `paint` property. */ -function declassStyle(style, classes) { +export function declassStyle(style, classes) { return extend({}, style, { layers: style.layers.map((layer) => { const result = classes.reduce(declassLayer, layer); diff --git a/src/deref.ts b/src/deref.ts index 729c9c923..fbcc94ac8 100644 --- a/src/deref.ts +++ b/src/deref.ts @@ -1,7 +1,7 @@ -import refProperties from './util/ref_properties'; +import {refProperties} from './util/ref_properties'; -function deref(layer, parent) { +export default function deref(layer, parent) { const result = {}; for (const k in layer) { @@ -19,8 +19,6 @@ function deref(layer, parent) { return result; } -export default derefLayers; - /** * Given an array of layers, some of which may contain `ref` properties * whose value is the `id` of another property, return a new array where diff --git a/src/expression/index.ts b/src/expression/index.ts index 8234c0e8f..821b48d8d 100644 --- a/src/expression/index.ts +++ b/src/expression/index.ts @@ -1,5 +1,5 @@ -import extend from '../util/extend'; +import {extendBy as extend} from '../util/extend'; import ExpressionParsingError from './parsing_error'; import ParsingContext from './parsing_context'; import EvaluationContext from './evaluation_context'; diff --git a/src/function/index.ts b/src/function/index.ts index 1106594e9..d54fc34cd 100644 --- a/src/function/index.ts +++ b/src/function/index.ts @@ -1,6 +1,6 @@ import Color, {isSupportedInterpolationColorSpace} from '../expression/types/color'; -import extend from '../util/extend'; -import getType from '../util/get_type'; +import {extendBy as extend} from '../util/extend'; +import {getType} from '../util/get_type'; import Interpolate, {interpolateFactory} from '../expression/definitions/interpolate'; import Formatted from '../expression/types/formatted'; import ResolvedImage from '../expression/types/resolved_image'; diff --git a/src/group_by_layout.ts b/src/group_by_layout.ts index 73238a87c..58b1677a2 100644 --- a/src/group_by_layout.ts +++ b/src/group_by_layout.ts @@ -1,5 +1,5 @@ -import refProperties from './util/ref_properties'; +import {refProperties} from './util/ref_properties'; function stringify(obj) { const type = typeof obj; diff --git a/src/util/extend.ts b/src/util/extend.ts index 0a23eaf92..50e80b34a 100644 --- a/src/util/extend.ts +++ b/src/util/extend.ts @@ -1,4 +1,4 @@ -export default function extendBy(output: any, ...inputs: Array) { +export function extendBy(output: any, ...inputs: Array) { for (const input of inputs) { for (const k in input) { output[k] = input[k]; diff --git a/src/util/get_type.ts b/src/util/get_type.ts index 4cf28f488..793942fbe 100644 --- a/src/util/get_type.ts +++ b/src/util/get_type.ts @@ -1,4 +1,4 @@ -export default function getType(val: unknown): string { +export function getType(val: unknown): string { if (val instanceof Number) { return 'number'; } else if (val instanceof String) { diff --git a/src/util/ref_properties.ts b/src/util/ref_properties.ts index 4f6fcb3a1..ce2cc3518 100644 --- a/src/util/ref_properties.ts +++ b/src/util/ref_properties.ts @@ -1,3 +1,2 @@ -const refProperties = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout']; -export default refProperties; +export const refProperties = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout']; diff --git a/src/validate/validate.ts b/src/validate/validate.ts index 0e8b8f403..65a39ac2e 100644 --- a/src/validate/validate.ts +++ b/src/validate/validate.ts @@ -1,5 +1,5 @@ -import extend from '../util/extend'; +import {extendBy as extend} from '../util/extend'; import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; import {isExpression} from '../expression'; import {isFunction} from '../function'; diff --git a/src/validate/validate_array.ts b/src/validate/validate_array.ts index 2888af8dc..782577ff5 100644 --- a/src/validate/validate_array.ts +++ b/src/validate/validate_array.ts @@ -1,4 +1,4 @@ -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import {ValidationError} from '../error/validation_error'; export function validateArray(options) { diff --git a/src/validate/validate_boolean.ts b/src/validate/validate_boolean.ts index 55e262d5e..17916afd4 100644 --- a/src/validate/validate_boolean.ts +++ b/src/validate/validate_boolean.ts @@ -1,5 +1,5 @@ -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import {ValidationError} from '../error/validation_error'; export function validateBoolean(options) { diff --git a/src/validate/validate_color.ts b/src/validate/validate_color.ts index c5d2d1396..691b80d34 100644 --- a/src/validate/validate_color.ts +++ b/src/validate/validate_color.ts @@ -1,5 +1,5 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import Color from '../expression/types/color'; export function validateColor(options) { diff --git a/src/validate/validate_filter.ts b/src/validate/validate_filter.ts index cb2fddd47..544841291 100644 --- a/src/validate/validate_filter.ts +++ b/src/validate/validate_filter.ts @@ -2,9 +2,9 @@ import {ValidationError} from '../error/validation_error'; import {validateExpression} from './validate_expression'; import {validateEnum} from './validate_enum'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; -import extend from '../util/extend'; +import {extendBy as extend} from '../util/extend'; import {isExpressionFilter} from '../feature_filter'; export function validateFilter(options) { diff --git a/src/validate/validate_function.ts b/src/validate/validate_function.ts index 7f6e206d6..b81344918 100644 --- a/src/validate/validate_function.ts +++ b/src/validate/validate_function.ts @@ -1,6 +1,6 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import {validateObject} from './validate_object'; import {validateArray} from './validate_array'; import {validateNumber} from './validate_number'; diff --git a/src/validate/validate_layer.ts b/src/validate/validate_layer.ts index f5a0cc4d4..876c8eed9 100644 --- a/src/validate/validate_layer.ts +++ b/src/validate/validate_layer.ts @@ -5,7 +5,7 @@ import {validateObject} from './validate_object'; import {validateFilter} from './validate_filter'; import {validatePaintProperty} from './validate_paint_property'; import {validateLayoutProperty} from './validate_layout_property'; -import extend from '../util/extend'; +import {extendBy as extend} from '../util/extend'; export function validateLayer(options) { let errors = []; diff --git a/src/validate/validate_light.ts b/src/validate/validate_light.ts index 4cd06c4b8..453cd89f0 100644 --- a/src/validate/validate_light.ts +++ b/src/validate/validate_light.ts @@ -1,5 +1,5 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; export function validateLight(options) { const light = options.value; diff --git a/src/validate/validate_number.ts b/src/validate/validate_number.ts index a922febdb..44394707e 100644 --- a/src/validate/validate_number.ts +++ b/src/validate/validate_number.ts @@ -1,5 +1,5 @@ -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import {ValidationError} from '../error/validation_error'; export function validateNumber(options) { diff --git a/src/validate/validate_object.ts b/src/validate/validate_object.ts index 7bd9cfa84..dc09a179f 100644 --- a/src/validate/validate_object.ts +++ b/src/validate/validate_object.ts @@ -1,6 +1,6 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; export function validateObject(options): Array { const key = options.key; diff --git a/src/validate/validate_padding.ts b/src/validate/validate_padding.ts index 129b83442..9f4989755 100644 --- a/src/validate/validate_padding.ts +++ b/src/validate/validate_padding.ts @@ -1,5 +1,5 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import {validateNumber} from './validate_number'; export function validatePadding(options) { diff --git a/src/validate/validate_projection.ts b/src/validate/validate_projection.ts index 3062541ed..4f216baa2 100644 --- a/src/validate/validate_projection.ts +++ b/src/validate/validate_projection.ts @@ -1,5 +1,5 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import v8 from '../reference/v8.json' with {type: 'json'}; import {ProjectionSpecification, StyleSpecification} from '../types.g'; diff --git a/src/validate/validate_property.ts b/src/validate/validate_property.ts index cdca4df36..916222a9e 100644 --- a/src/validate/validate_property.ts +++ b/src/validate/validate_property.ts @@ -1,6 +1,6 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import {isFunction} from '../function'; import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; import {supportsPropertyExpression} from '../util/properties'; diff --git a/src/validate/validate_raster_dem_source.ts b/src/validate/validate_raster_dem_source.ts index a7c3623d9..fe0a7fcc2 100644 --- a/src/validate/validate_raster_dem_source.ts +++ b/src/validate/validate_raster_dem_source.ts @@ -1,5 +1,5 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import type {RasterDEMSourceSpecification, StyleSpecification} from '../types.g'; import v8 from '../reference/v8.json' with {type: 'json'}; import {unbundle} from '../util/unbundle_jsonlint'; diff --git a/src/validate/validate_sky.ts b/src/validate/validate_sky.ts index 4e33cf3fc..a4fb22345 100644 --- a/src/validate/validate_sky.ts +++ b/src/validate/validate_sky.ts @@ -1,5 +1,5 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import v8 from '../reference/v8.json' with {type: 'json'}; import {SkySpecification, StyleSpecification} from '../types.g'; diff --git a/src/validate/validate_source.ts b/src/validate/validate_source.ts index c56288e31..c4281adf8 100644 --- a/src/validate/validate_source.ts +++ b/src/validate/validate_source.ts @@ -5,7 +5,7 @@ import {validateObject} from './validate_object'; import {validateEnum} from './validate_enum'; import {validateExpression} from './validate_expression'; import {validateString} from './validate_string'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import {validateRasterDEMSource} from './validate_raster_dem_source'; const objectElementValidators = { diff --git a/src/validate/validate_string.ts b/src/validate/validate_string.ts index 0801d4670..493bb064a 100644 --- a/src/validate/validate_string.ts +++ b/src/validate/validate_string.ts @@ -1,5 +1,5 @@ -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import {ValidationError} from '../error/validation_error'; export function validateString(options) { diff --git a/src/validate/validate_terrain.ts b/src/validate/validate_terrain.ts index 4e6ea40b2..c37552d0f 100644 --- a/src/validate/validate_terrain.ts +++ b/src/validate/validate_terrain.ts @@ -1,5 +1,5 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import type {StyleSpecification, TerrainSpecification} from '../types.g'; import v8 from '../reference/v8.json' with {type: 'json'}; diff --git a/src/validate/validate_variable_anchor_offset_collection.ts b/src/validate/validate_variable_anchor_offset_collection.ts index c7958b540..cd26486f2 100644 --- a/src/validate/validate_variable_anchor_offset_collection.ts +++ b/src/validate/validate_variable_anchor_offset_collection.ts @@ -1,5 +1,5 @@ import {ValidationError} from '../error/validation_error'; -import getType from '../util/get_type'; +import {getType} from '../util/get_type'; import {validateArray} from './validate_array'; import {validateEnum} from './validate_enum'; From f8c1964bb029509215ef5f1447f8ada4044db616 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 17:26:03 +0100 Subject: [PATCH 05/19] expression definitions --- src/expression/definitions/assertion.ts | 4 +- src/expression/definitions/at.ts | 3 +- src/expression/definitions/case.ts | 3 +- src/expression/definitions/coalesce.ts | 3 +- src/expression/definitions/coercion.ts | 3 +- src/expression/definitions/collator.ts | 2 +- src/expression/definitions/comparison.ts | 2 +- src/expression/definitions/distance.ts | 4 +- src/expression/definitions/format.ts | 2 +- src/expression/definitions/image.ts | 2 +- src/expression/definitions/in.ts | 3 +- src/expression/definitions/index.ts | 44 ++++++++++----------- src/expression/definitions/index_of.ts | 3 +- src/expression/definitions/interpolate.ts | 4 +- src/expression/definitions/length.ts | 3 +- src/expression/definitions/let.ts | 4 +- src/expression/definitions/literal.ts | 3 +- src/expression/definitions/match.ts | 3 +- src/expression/definitions/number_format.ts | 2 +- src/expression/definitions/slice.ts | 3 +- src/expression/definitions/step.ts | 3 +- src/expression/definitions/var.ts | 3 +- src/expression/definitions/within.ts | 4 +- 23 files changed, 43 insertions(+), 67 deletions(-) diff --git a/src/expression/definitions/assertion.ts b/src/expression/definitions/assertion.ts index a51e4a8f6..e48c0505a 100644 --- a/src/expression/definitions/assertion.ts +++ b/src/expression/definitions/assertion.ts @@ -24,7 +24,7 @@ const types = { object: ObjectType }; -class Assertion implements Expression { +export class Assertion implements Expression { type: Type; args: Array; @@ -104,5 +104,3 @@ class Assertion implements Expression { return this.args.every(arg => arg.outputDefined()); } } - -export default Assertion; diff --git a/src/expression/definitions/at.ts b/src/expression/definitions/at.ts index d5cf0da0a..c94e22f23 100644 --- a/src/expression/definitions/at.ts +++ b/src/expression/definitions/at.ts @@ -8,7 +8,7 @@ import type EvaluationContext from '../evaluation_context'; import type {Type, ArrayType} from '../types'; import type {Value} from '../values'; -class At implements Expression { +export class At implements Expression { type: Type; index: Expression; input: Expression; @@ -61,4 +61,3 @@ class At implements Expression { } } -export default At; diff --git a/src/expression/definitions/case.ts b/src/expression/definitions/case.ts index f8f4622f9..44eb1deea 100644 --- a/src/expression/definitions/case.ts +++ b/src/expression/definitions/case.ts @@ -8,7 +8,7 @@ import type {Type} from '../types'; type Branches = Array<[Expression, Expression]>; -class Case implements Expression { +export class Case implements Expression { type: Type; branches: Branches; @@ -73,4 +73,3 @@ class Case implements Expression { } } -export default Case; diff --git a/src/expression/definitions/coalesce.ts b/src/expression/definitions/coalesce.ts index cb2bbe5bc..b97e27607 100644 --- a/src/expression/definitions/coalesce.ts +++ b/src/expression/definitions/coalesce.ts @@ -6,7 +6,7 @@ import type ParsingContext from '../parsing_context'; import type EvaluationContext from '../evaluation_context'; import type {Type} from '../types'; -class Coalesce implements Expression { +export class Coalesce implements Expression { type: Type; args: Array; @@ -80,4 +80,3 @@ class Coalesce implements Expression { } } -export default Coalesce; diff --git a/src/expression/definitions/coercion.ts b/src/expression/definitions/coercion.ts index 04b693c50..ecf241767 100644 --- a/src/expression/definitions/coercion.ts +++ b/src/expression/definitions/coercion.ts @@ -26,7 +26,7 @@ const types = { * * @private */ -class Coercion implements Expression { +export class Coercion implements Expression { type: Type; args: Array; @@ -140,4 +140,3 @@ class Coercion implements Expression { } } -export default Coercion; diff --git a/src/expression/definitions/collator.ts b/src/expression/definitions/collator.ts index 43e18d315..4efd45af9 100644 --- a/src/expression/definitions/collator.ts +++ b/src/expression/definitions/collator.ts @@ -6,7 +6,7 @@ import type EvaluationContext from '../evaluation_context'; import type ParsingContext from '../parsing_context'; import type {Type} from '../types'; -export default class CollatorExpression implements Expression { +export class CollatorExpression implements Expression { type: Type; caseSensitive: Expression; diacriticSensitive: Expression; diff --git a/src/expression/definitions/comparison.ts b/src/expression/definitions/comparison.ts index df9cb6afd..22d3c900d 100644 --- a/src/expression/definitions/comparison.ts +++ b/src/expression/definitions/comparison.ts @@ -1,5 +1,5 @@ import {toString, ValueType, BooleanType, CollatorType} from '../types'; -import Assertion from './assertion'; +import {Assertion} from './assertion'; import {typeOf} from '../values'; import RuntimeError from '../runtime_error'; diff --git a/src/expression/definitions/distance.ts b/src/expression/definitions/distance.ts index b16d2b5bd..1bc66cef1 100644 --- a/src/expression/definitions/distance.ts +++ b/src/expression/definitions/distance.ts @@ -532,7 +532,7 @@ function toSimpleGeometry(geometry: Exclude; diff --git a/src/expression/definitions/image.ts b/src/expression/definitions/image.ts index 4521990e4..99b732f57 100644 --- a/src/expression/definitions/image.ts +++ b/src/expression/definitions/image.ts @@ -6,7 +6,7 @@ import type EvaluationContext from '../evaluation_context'; import type ParsingContext from '../parsing_context'; import type {Type} from '../types'; -export default class ImageExpression implements Expression { +export class ImageExpression implements Expression { type: Type; input: Expression; diff --git a/src/expression/definitions/in.ts b/src/expression/definitions/in.ts index 63b2dde57..1c76d3269 100644 --- a/src/expression/definitions/in.ts +++ b/src/expression/definitions/in.ts @@ -16,7 +16,7 @@ import type ParsingContext from '../parsing_context'; import type EvaluationContext from '../evaluation_context'; import type {Type} from '../types'; -class In implements Expression { +export class In implements Expression { type: Type; needle: Expression; haystack: Expression; @@ -72,4 +72,3 @@ class In implements Expression { } } -export default In; diff --git a/src/expression/definitions/index.ts b/src/expression/definitions/index.ts index 8832a0a90..e00374024 100644 --- a/src/expression/definitions/index.ts +++ b/src/expression/definitions/index.ts @@ -1,18 +1,18 @@ -import Let from './let'; -import Var from './var'; -import Literal from './literal'; -import Assertion from './assertion'; -import Coercion from './coercion'; -import At from './at'; -import In from './in'; -import IndexOf from './index_of'; -import Match from './match'; -import Case from './case'; -import Slice from './slice'; -import Step from './step'; -import Interpolate from './interpolate'; -import Coalesce from './coalesce'; +import {Let} from './let'; +import {Var} from './var'; +import {Literal} from './literal'; +import {Assertion} from './assertion'; +import {Coercion} from './coercion'; +import {At} from './at'; +import {In} from './in'; +import {IndexOf} from './index_of'; +import {Match} from './match'; +import {Case} from './case'; +import {Slice} from './slice'; +import {Step} from './step'; +import {Interpolate} from './interpolate'; +import {Coalesce} from './coalesce'; import { Equals, NotEquals, @@ -21,13 +21,13 @@ import { LessThanOrEqual, GreaterThanOrEqual } from './comparison'; -import CollatorExpression from './collator'; -import NumberFormat from './number_format'; -import FormatExpression from './format'; -import ImageExpression from './image'; -import Length from './length'; -import Within from './within'; -import Distance from './distance'; +import {CollatorExpression} from './collator'; +import {NumberFormat} from './number_format'; +import {FormatExpression} from './format'; +import {ImageExpression} from './image'; +import {Length} from './length'; +import {Within} from './within'; +import {Distance} from './distance'; import type {ExpressionRegistry} from '../expression'; @@ -70,5 +70,3 @@ export const expressions: ExpressionRegistry = { 'within': Within, 'distance': Distance }; - -export default expressions; diff --git a/src/expression/definitions/index_of.ts b/src/expression/definitions/index_of.ts index a8202ad0f..e7a651634 100644 --- a/src/expression/definitions/index_of.ts +++ b/src/expression/definitions/index_of.ts @@ -16,7 +16,7 @@ import type ParsingContext from '../parsing_context'; import type EvaluationContext from '../evaluation_context'; import type {Type} from '../types'; -class IndexOf implements Expression { +export class IndexOf implements Expression { type: Type; needle: Expression; haystack: Expression; @@ -93,4 +93,3 @@ class IndexOf implements Expression { } } -export default IndexOf; diff --git a/src/expression/definitions/interpolate.ts b/src/expression/definitions/interpolate.ts index 9182899b6..8d9e80272 100644 --- a/src/expression/definitions/interpolate.ts +++ b/src/expression/definitions/interpolate.ts @@ -24,7 +24,7 @@ export type InterpolationType = { }; type InterpolatedValueType = NumberTypeT | ColorTypeT | PaddingTypeT | VariableAnchorOffsetCollectionTypeT | ArrayType; -class Interpolate implements Expression { +export class Interpolate implements Expression { type: InterpolatedValueType; operator: 'interpolate' | 'interpolate-hcl' | 'interpolate-lab'; @@ -255,8 +255,6 @@ function exponentialInterpolation(input, base, lowerValue, upperValue) { } } -export default Interpolate; - export const interpolateFactory = { color: Color.interpolate, number: interpolateNumber, diff --git a/src/expression/definitions/length.ts b/src/expression/definitions/length.ts index ba5ec56c3..9dadb5dbb 100644 --- a/src/expression/definitions/length.ts +++ b/src/expression/definitions/length.ts @@ -8,7 +8,7 @@ import type ParsingContext from '../parsing_context'; import type EvaluationContext from '../evaluation_context'; import type {Type} from '../types'; -class Length implements Expression { +export class Length implements Expression { type: Type; input: Expression; @@ -51,4 +51,3 @@ class Length implements Expression { } } -export default Length; diff --git a/src/expression/definitions/let.ts b/src/expression/definitions/let.ts index de34f1ec5..a628e94a4 100644 --- a/src/expression/definitions/let.ts +++ b/src/expression/definitions/let.ts @@ -3,7 +3,7 @@ import type {Expression} from '../expression'; import type ParsingContext from '../parsing_context'; import type EvaluationContext from '../evaluation_context'; -class Let implements Expression { +export class Let implements Expression { type: Type; bindings: Array<[string, Expression]>; result: Expression; @@ -57,5 +57,3 @@ class Let implements Expression { return this.result.outputDefined(); } } - -export default Let; diff --git a/src/expression/definitions/literal.ts b/src/expression/definitions/literal.ts index 95f7f655c..a4202669b 100644 --- a/src/expression/definitions/literal.ts +++ b/src/expression/definitions/literal.ts @@ -5,7 +5,7 @@ import type {Value} from '../values'; import type {Expression} from '../expression'; import type ParsingContext from '../parsing_context'; -class Literal implements Expression { +export class Literal implements Expression { type: Type; value: Value; @@ -50,4 +50,3 @@ class Literal implements Expression { } } -export default Literal; diff --git a/src/expression/definitions/match.ts b/src/expression/definitions/match.ts index 96bd712ea..c2b38a4e3 100644 --- a/src/expression/definitions/match.ts +++ b/src/expression/definitions/match.ts @@ -13,7 +13,7 @@ type Cases = { [k in number | string]: number; }; -class Match implements Expression { +export class Match implements Expression { type: Type; inputType: Type; @@ -115,4 +115,3 @@ class Match implements Expression { } } -export default Match; diff --git a/src/expression/definitions/number_format.ts b/src/expression/definitions/number_format.ts index 0c66b9eb6..5126cb03a 100644 --- a/src/expression/definitions/number_format.ts +++ b/src/expression/definitions/number_format.ts @@ -24,7 +24,7 @@ type NumberFormatOptions = { maximumFractionDigits?: null | string; }; -export default class NumberFormat implements Expression { +export class NumberFormat implements Expression { type: Type; number: Expression; locale: Expression | null; // BCP 47 language tag diff --git a/src/expression/definitions/slice.ts b/src/expression/definitions/slice.ts index 94f92371d..b9d4f9290 100644 --- a/src/expression/definitions/slice.ts +++ b/src/expression/definitions/slice.ts @@ -15,7 +15,7 @@ import type ParsingContext from '../parsing_context'; import type EvaluationContext from '../evaluation_context'; import type {Type} from '../types'; -class Slice implements Expression { +export class Slice implements Expression { type: Type; input: Expression; beginIndex: Expression; @@ -84,4 +84,3 @@ class Slice implements Expression { } } -export default Slice; diff --git a/src/expression/definitions/step.ts b/src/expression/definitions/step.ts index 5389c96d5..b71f66e6b 100644 --- a/src/expression/definitions/step.ts +++ b/src/expression/definitions/step.ts @@ -8,7 +8,7 @@ import type ParsingContext from '../parsing_context'; import type EvaluationContext from '../evaluation_context'; import type {Type} from '../types'; -class Step implements Expression { +export class Step implements Expression { type: Type; input: Expression; @@ -104,4 +104,3 @@ class Step implements Expression { } } -export default Step; diff --git a/src/expression/definitions/var.ts b/src/expression/definitions/var.ts index 7efc4fe7b..87679d8c3 100644 --- a/src/expression/definitions/var.ts +++ b/src/expression/definitions/var.ts @@ -3,7 +3,7 @@ import type {Expression} from '../expression'; import type ParsingContext from '../parsing_context'; import type EvaluationContext from '../evaluation_context'; -class Var implements Expression { +export class Var implements Expression { type: Type; name: string; boundExpression: Expression; @@ -37,4 +37,3 @@ class Var implements Expression { } } -export default Var; diff --git a/src/expression/definitions/within.ts b/src/expression/definitions/within.ts index f3160c86a..1fbe0516f 100644 --- a/src/expression/definitions/within.ts +++ b/src/expression/definitions/within.ts @@ -143,7 +143,7 @@ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPol return true; } -class Within implements Expression { +export class Within implements Expression { type: Type; geojson: GeoJSON.GeoJSON; geometries: GeoJSONPolygons; @@ -207,5 +207,3 @@ class Within implements Expression { return true; } } - -export default Within; From c7578805821b40dbe976579351ea8a2e81ac919d Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 18:17:37 +0100 Subject: [PATCH 06/19] named --- src/deref.test.ts | 2 +- src/deref.ts | 2 +- src/diff.ts | 2 +- src/expression/compound_expression.ts | 25 +++++++++--------- src/expression/definitions/assertion.ts | 6 ++--- src/expression/definitions/at.ts | 6 ++--- src/expression/definitions/case.ts | 4 +-- src/expression/definitions/coalesce.ts | 6 ++--- src/expression/definitions/coercion.ts | 16 ++++++------ src/expression/definitions/collator.ts | 6 ++--- src/expression/definitions/comparison.ts | 6 ++--- src/expression/definitions/distance.ts | 4 +-- src/expression/definitions/format.ts | 6 ++--- src/expression/definitions/image.ts | 6 ++--- src/expression/definitions/in.ts | 6 ++--- src/expression/definitions/index_of.ts | 6 ++--- src/expression/definitions/interpolate.ts | 10 +++---- src/expression/definitions/length.ts | 6 ++--- src/expression/definitions/let.ts | 4 +-- src/expression/definitions/literal.ts | 2 +- src/expression/definitions/match.ts | 4 +-- src/expression/definitions/number_format.ts | 4 +-- src/expression/definitions/slice.ts | 6 ++--- src/expression/definitions/step.ts | 4 +-- src/expression/definitions/var.ts | 4 +-- src/expression/definitions/within.ts | 4 +-- src/expression/evaluation_context.ts | 6 ++--- src/expression/expression.test.ts | 6 ++--- src/expression/expression.ts | 4 +-- src/expression/index.ts | 26 +++++++++---------- src/expression/parsing_context.ts | 15 +++++------ src/expression/parsing_error.ts | 4 +-- src/expression/runtime_error.ts | 4 +-- src/expression/scope.ts | 4 +-- src/expression/stops.ts | 2 +- src/expression/types/collator.ts | 2 +- src/expression/types/color.test.ts | 2 +- src/expression/types/color.ts | 16 ++++-------- src/expression/types/formatted.ts | 6 ++--- src/expression/types/padding.test.ts | 2 +- src/expression/types/padding.ts | 4 +-- src/expression/types/resolved_image.ts | 2 +- .../variable_anchor_offset_collection.test.ts | 2 +- .../variable_anchor_offset_collection.ts | 6 ++--- src/expression/values.ts | 12 ++++----- src/function/index.test.ts | 6 ++--- src/function/index.ts | 10 +++---- src/index.ts | 24 ++++++++--------- src/util/deep_equal.ts | 7 +++-- src/validate/validate_color.ts | 2 +- .../integration/expression/expression.test.ts | 2 +- test/lib/util.ts | 2 +- 52 files changed, 157 insertions(+), 178 deletions(-) diff --git a/src/deref.test.ts b/src/deref.test.ts index c894c5a66..cf389fe13 100644 --- a/src/deref.test.ts +++ b/src/deref.test.ts @@ -1,4 +1,4 @@ -import deref from './deref'; +import {deref} from './deref'; describe('deref', () => { test('derefs a ref layer which follows its parent', () => { diff --git a/src/deref.ts b/src/deref.ts index fbcc94ac8..bb54c57df 100644 --- a/src/deref.ts +++ b/src/deref.ts @@ -1,7 +1,7 @@ import {refProperties} from './util/ref_properties'; -export default function deref(layer, parent) { +export function deref(layer, parent) { const result = {}; for (const k in layer) { diff --git a/src/diff.ts b/src/diff.ts index f088c9212..e3b32c34e 100644 --- a/src/diff.ts +++ b/src/diff.ts @@ -1,6 +1,6 @@ import {GeoJSONSourceSpecification, LayerSpecification, LightSpecification, ProjectionSpecification, SkySpecification, SourceSpecification, SpriteSpecification, StyleSpecification, TerrainSpecification, TransitionSpecification} from './types.g'; -import isEqual from './util/deep_equal'; +import {deepEqual as isEqual} from './util/deep_equal'; /** * Operations that can be performed by the diff. diff --git a/src/expression/compound_expression.ts b/src/expression/compound_expression.ts index 7f27ca3af..16f9a7f28 100644 --- a/src/expression/compound_expression.ts +++ b/src/expression/compound_expression.ts @@ -11,25 +11,25 @@ import {toString, toString as typeToString, } from './types'; -import ParsingContext from './parsing_context'; -import EvaluationContext from './evaluation_context'; +import {ParsingContext} from './parsing_context'; +import {EvaluationContext} from './evaluation_context'; import {expressions} from './definitions/index'; -import CollatorExpression from './definitions/collator'; -import Within from './definitions/within'; -import Literal from './definitions/literal'; -import Assertion from './definitions/assertion'; -import Coercion from './definitions/coercion'; -import Var from './definitions/var'; -import Distance from './definitions/distance'; +import {CollatorExpression} from './definitions/collator'; +import {Within} from './definitions/within'; +import {Literal} from './definitions/literal'; +import {Assertion} from './definitions/assertion'; +import {Coercion} from './definitions/coercion'; +import {Var} from './definitions/var'; +import {Distance} from './definitions/distance'; import type {Expression, ExpressionRegistry} from './expression'; import type {Value} from './values'; import type {Type} from './types'; import {typeOf, validateRGBA, toString as valueToString} from './values'; -import RuntimeError from './runtime_error'; -import Color from './types/color'; +import {RuntimeError} from './runtime_error'; +import {Color} from './types/color'; export type Varargs = { type: Type; @@ -42,7 +42,7 @@ type Definition = [Type, Signature, Evaluate] | { overloads: Array<[Signature, Evaluate]>; }; -class CompoundExpression implements Expression { +export class CompoundExpression implements Expression { name: string; type: Type; _evaluate: Evaluate; @@ -752,4 +752,3 @@ function isGlobalPropertyConstant(e: Expression, properties: Array) { } export {isFeatureConstant, isGlobalPropertyConstant, isStateConstant, isExpressionConstant}; -export default CompoundExpression; diff --git a/src/expression/definitions/assertion.ts b/src/expression/definitions/assertion.ts index e48c0505a..7a08d92ee 100644 --- a/src/expression/definitions/assertion.ts +++ b/src/expression/definitions/assertion.ts @@ -9,12 +9,12 @@ import { toString, array } from '../types'; -import RuntimeError from '../runtime_error'; +import {RuntimeError} from '../runtime_error'; import {typeOf} from '../values'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type} from '../types'; const types = { diff --git a/src/expression/definitions/at.ts b/src/expression/definitions/at.ts index c94e22f23..7b902dac8 100644 --- a/src/expression/definitions/at.ts +++ b/src/expression/definitions/at.ts @@ -1,10 +1,10 @@ import {array, ValueType, NumberType} from '../types'; -import RuntimeError from '../runtime_error'; +import {RuntimeError} from '../runtime_error'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type, ArrayType} from '../types'; import type {Value} from '../values'; diff --git a/src/expression/definitions/case.ts b/src/expression/definitions/case.ts index 44eb1deea..422684124 100644 --- a/src/expression/definitions/case.ts +++ b/src/expression/definitions/case.ts @@ -2,8 +2,8 @@ import {BooleanType} from '../types'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type} from '../types'; type Branches = Array<[Expression, Expression]>; diff --git a/src/expression/definitions/coalesce.ts b/src/expression/definitions/coalesce.ts index b97e27607..3e615d01d 100644 --- a/src/expression/definitions/coalesce.ts +++ b/src/expression/definitions/coalesce.ts @@ -1,9 +1,9 @@ import {checkSubtype, ValueType} from '../types'; -import ResolvedImage from '../types/resolved_image'; +import {ResolvedImage} from '../types/resolved_image'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type} from '../types'; export class Coalesce implements Expression { diff --git a/src/expression/definitions/coercion.ts b/src/expression/definitions/coercion.ts index ecf241767..d25b7365e 100644 --- a/src/expression/definitions/coercion.ts +++ b/src/expression/definitions/coercion.ts @@ -1,15 +1,15 @@ import {BooleanType, ColorType, NumberType, StringType, ValueType} from '../types'; import {toString as valueToString, validateRGBA} from '../values'; -import RuntimeError from '../runtime_error'; -import Formatted from '../types/formatted'; -import ResolvedImage from '../types/resolved_image'; -import Color from '../types/color'; -import Padding from '../types/padding'; -import VariableAnchorOffsetCollection from '../types/variable_anchor_offset_collection'; +import {RuntimeError} from '../runtime_error'; +import {Formatted} from '../types/formatted'; +import {ResolvedImage} from '../types/resolved_image'; +import {Color} from '../types/color'; +import {Padding} from '../types/padding'; +import {VariableAnchorOffsetCollection} from '../types/variable_anchor_offset_collection'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type} from '../types'; const types = { diff --git a/src/expression/definitions/collator.ts b/src/expression/definitions/collator.ts index 4efd45af9..050f87c58 100644 --- a/src/expression/definitions/collator.ts +++ b/src/expression/definitions/collator.ts @@ -1,9 +1,9 @@ import {StringType, BooleanType, CollatorType} from '../types'; -import Collator from '../types/collator'; +import {Collator} from '../types/collator'; import type {Expression} from '../expression'; -import type EvaluationContext from '../evaluation_context'; -import type ParsingContext from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; import type {Type} from '../types'; export class CollatorExpression implements Expression { diff --git a/src/expression/definitions/comparison.ts b/src/expression/definitions/comparison.ts index 22d3c900d..a5cb660cb 100644 --- a/src/expression/definitions/comparison.ts +++ b/src/expression/definitions/comparison.ts @@ -1,11 +1,11 @@ import {toString, ValueType, BooleanType, CollatorType} from '../types'; import {Assertion} from './assertion'; import {typeOf} from '../values'; -import RuntimeError from '../runtime_error'; +import {RuntimeError} from '../runtime_error'; import type {Expression} from '../expression'; -import type EvaluationContext from '../evaluation_context'; -import type ParsingContext from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; import type {Type} from '../types'; type ComparisonOperator = '==' | '!=' | '<' | '>' | '<=' | '>='; diff --git a/src/expression/definitions/distance.ts b/src/expression/definitions/distance.ts index 1bc66cef1..683290c61 100644 --- a/src/expression/definitions/distance.ts +++ b/src/expression/definitions/distance.ts @@ -1,9 +1,9 @@ import TinyQueue from 'tinyqueue'; import {Expression} from '../expression'; -import ParsingContext from '../parsing_context'; +import {ParsingContext} from '../parsing_context'; import {NumberType, Type} from '../types'; import {isValue} from '../values'; -import EvaluationContext from '../evaluation_context'; +import {EvaluationContext} from '../evaluation_context'; import {BBox, boxWithinBox, getLngLatFromTileCoord, pointWithinPolygon, segmentIntersectSegment, updateBBox} from '../../util/geometry_util'; import {classifyRings} from '../../util/classify_rings'; import CheapRuler from '../../util/cheap_ruler'; diff --git a/src/expression/definitions/format.ts b/src/expression/definitions/format.ts index cd180276c..78f89fc83 100644 --- a/src/expression/definitions/format.ts +++ b/src/expression/definitions/format.ts @@ -7,12 +7,12 @@ import { ColorType, ResolvedImageType, } from '../types'; -import Formatted, {FormattedSection} from '../types/formatted'; +import {Formatted, FormattedSection} from '../types/formatted'; import {toString, typeOf} from '../values'; import type {Expression} from '../expression'; -import type EvaluationContext from '../evaluation_context'; -import type ParsingContext from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; import type {Type} from '../types'; type FormattedSectionExpression = { diff --git a/src/expression/definitions/image.ts b/src/expression/definitions/image.ts index 99b732f57..6ddecaf32 100644 --- a/src/expression/definitions/image.ts +++ b/src/expression/definitions/image.ts @@ -1,9 +1,9 @@ import {ResolvedImageType, StringType} from '../types'; -import ResolvedImage from '../types/resolved_image'; +import {ResolvedImage} from '../types/resolved_image'; import type {Expression} from '../expression'; -import type EvaluationContext from '../evaluation_context'; -import type ParsingContext from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; import type {Type} from '../types'; export class ImageExpression implements Expression { diff --git a/src/expression/definitions/in.ts b/src/expression/definitions/in.ts index 1c76d3269..21ecec249 100644 --- a/src/expression/definitions/in.ts +++ b/src/expression/definitions/in.ts @@ -8,12 +8,12 @@ import { isValidType, isValidNativeType, } from '../types'; -import RuntimeError from '../runtime_error'; +import {RuntimeError} from '../runtime_error'; import {typeOf} from '../values'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type} from '../types'; export class In implements Expression { diff --git a/src/expression/definitions/index_of.ts b/src/expression/definitions/index_of.ts index e7a651634..523359849 100644 --- a/src/expression/definitions/index_of.ts +++ b/src/expression/definitions/index_of.ts @@ -8,12 +8,12 @@ import { isValidType, isValidNativeType, } from '../types'; -import RuntimeError from '../runtime_error'; +import {RuntimeError} from '../runtime_error'; import {typeOf} from '../values'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type} from '../types'; export class IndexOf implements Expression { diff --git a/src/expression/definitions/interpolate.ts b/src/expression/definitions/interpolate.ts index 8d9e80272..f77537cdb 100644 --- a/src/expression/definitions/interpolate.ts +++ b/src/expression/definitions/interpolate.ts @@ -5,13 +5,13 @@ import {findStopLessThanOrEqualTo} from '../stops'; import type {Stops} from '../stops'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type} from '../types'; -import Color from '../types/color'; +import {Color} from '../types/color'; import {interpolateArray, interpolateNumber} from '../../util/interpolate-primitives'; -import Padding from '../types/padding'; -import VariableAnchorOffsetCollection from '../types/variable_anchor_offset_collection'; +import {Padding} from '../types/padding'; +import {VariableAnchorOffsetCollection} from '../types/variable_anchor_offset_collection'; export type InterpolationType = { name: 'linear'; diff --git a/src/expression/definitions/length.ts b/src/expression/definitions/length.ts index 9dadb5dbb..78b8f9a85 100644 --- a/src/expression/definitions/length.ts +++ b/src/expression/definitions/length.ts @@ -1,11 +1,11 @@ import {NumberType, toString} from '../types'; import {typeOf} from '../values'; -import RuntimeError from '../runtime_error'; +import {RuntimeError} from '../runtime_error'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type} from '../types'; export class Length implements Expression { diff --git a/src/expression/definitions/let.ts b/src/expression/definitions/let.ts index a628e94a4..7617bbec5 100644 --- a/src/expression/definitions/let.ts +++ b/src/expression/definitions/let.ts @@ -1,7 +1,7 @@ import type {Type} from '../types'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; export class Let implements Expression { type: Type; diff --git a/src/expression/definitions/literal.ts b/src/expression/definitions/literal.ts index a4202669b..0e40f25ba 100644 --- a/src/expression/definitions/literal.ts +++ b/src/expression/definitions/literal.ts @@ -3,7 +3,7 @@ import {isValue, typeOf} from '../values'; import type {Type} from '../types'; import type {Value} from '../values'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; +import type {ParsingContext} from '../parsing_context'; export class Literal implements Expression { type: Type; diff --git a/src/expression/definitions/match.ts b/src/expression/definitions/match.ts index c2b38a4e3..ae9bd5f86 100644 --- a/src/expression/definitions/match.ts +++ b/src/expression/definitions/match.ts @@ -5,8 +5,8 @@ import {ValueType} from '../types'; import type {Type} from '../types'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; // Map input label values to output expression index type Cases = { diff --git a/src/expression/definitions/number_format.ts b/src/expression/definitions/number_format.ts index 5126cb03a..9f2b0769e 100644 --- a/src/expression/definitions/number_format.ts +++ b/src/expression/definitions/number_format.ts @@ -1,8 +1,8 @@ import {StringType, NumberType} from '../types'; import type {Expression} from '../expression'; -import type EvaluationContext from '../evaluation_context'; -import type ParsingContext from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; import type {Type} from '../types'; declare let Intl: { diff --git a/src/expression/definitions/slice.ts b/src/expression/definitions/slice.ts index b9d4f9290..7dfee20c6 100644 --- a/src/expression/definitions/slice.ts +++ b/src/expression/definitions/slice.ts @@ -7,12 +7,12 @@ import { isValidType, isValidNativeType, } from '../types'; -import RuntimeError from '../runtime_error'; +import {RuntimeError} from '../runtime_error'; import {typeOf} from '../values'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type} from '../types'; export class Slice implements Expression { diff --git a/src/expression/definitions/step.ts b/src/expression/definitions/step.ts index b71f66e6b..f9c2c1b7e 100644 --- a/src/expression/definitions/step.ts +++ b/src/expression/definitions/step.ts @@ -4,8 +4,8 @@ import {findStopLessThanOrEqualTo} from '../stops'; import type {Stops} from '../stops'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import type {Type} from '../types'; export class Step implements Expression { diff --git a/src/expression/definitions/var.ts b/src/expression/definitions/var.ts index 87679d8c3..73a3d8647 100644 --- a/src/expression/definitions/var.ts +++ b/src/expression/definitions/var.ts @@ -1,7 +1,7 @@ import type {Type} from '../types'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; export class Var implements Expression { type: Type; diff --git a/src/expression/definitions/within.ts b/src/expression/definitions/within.ts index 1fbe0516f..e7e875c27 100644 --- a/src/expression/definitions/within.ts +++ b/src/expression/definitions/within.ts @@ -2,8 +2,8 @@ import {isValue} from '../values'; import type {Type} from '../types'; import {BooleanType} from '../types'; import type {Expression} from '../expression'; -import type ParsingContext from '../parsing_context'; -import type EvaluationContext from '../evaluation_context'; +import type {ParsingContext} from '../parsing_context'; +import type {EvaluationContext} from '../evaluation_context'; import {ICanonicalTileID} from '../../tiles_and_coordinates'; import {BBox, EXTENT, boxWithinBox, getTileCoordinates, lineStringWithinPolygon, lineStringWithinPolygons, pointWithinPolygon, pointWithinPolygons, updateBBox} from '../../util/geometry_util'; import {Point2D} from '../../point2d'; diff --git a/src/expression/evaluation_context.ts b/src/expression/evaluation_context.ts index 1695964b6..11fde481a 100644 --- a/src/expression/evaluation_context.ts +++ b/src/expression/evaluation_context.ts @@ -2,7 +2,7 @@ import type {FormattedSection} from './types/formatted'; import type {GlobalProperties, Feature, FeatureState} from './index'; import {ICanonicalTileID} from '../tiles_and_coordinates'; import {hasMultipleOuterRings} from '../util/classify_rings'; -import Color from './types/color'; +import {Color} from './types/color'; const geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon']; const simpleGeometryType = { @@ -15,7 +15,7 @@ const simpleGeometryType = { 'MultiPolygon': 'Polygon' }; -class EvaluationContext { +export class EvaluationContext { globals: GlobalProperties; feature: Feature; featureState: FeatureState; @@ -89,5 +89,3 @@ class EvaluationContext { return cached; } } - -export default EvaluationContext; diff --git a/src/expression/expression.test.ts b/src/expression/expression.test.ts index 311902d4b..225bd837e 100644 --- a/src/expression/expression.test.ts +++ b/src/expression/expression.test.ts @@ -1,10 +1,10 @@ import {createPropertyExpression, Feature, GlobalProperties, StylePropertyExpression} from '../expression'; -import definitions from './definitions'; +import {expressions as definitions} from './definitions'; import v8 from '../reference/v8.json' with {type: 'json'}; import {createExpression, ICanonicalTileID, StyleExpression, StylePropertySpecification} from '..'; -import ParsingError from './parsing_error'; +import {ExpressionParsingError as ParsingError} from './parsing_error'; import {getGeometry} from '../../test/lib/geometry'; -import VariableAnchorOffsetCollection from './types/variable_anchor_offset_collection'; +import {VariableAnchorOffsetCollection} from './types/variable_anchor_offset_collection'; // filter out internal "error" and "filter-*" expressions from definition list const filterExpressionRegex = /filter-/; diff --git a/src/expression/expression.ts b/src/expression/expression.ts index 76d367ccf..0e62c4a49 100644 --- a/src/expression/expression.ts +++ b/src/expression/expression.ts @@ -1,6 +1,6 @@ import type {Type} from './types'; -import type ParsingContext from './parsing_context'; -import type EvaluationContext from './evaluation_context'; +import type {ParsingContext} from './parsing_context'; +import type {EvaluationContext} from './evaluation_context'; /** * Expression diff --git a/src/expression/index.ts b/src/expression/index.ts index 821b48d8d..b8b73094c 100644 --- a/src/expression/index.ts +++ b/src/expression/index.ts @@ -1,22 +1,22 @@ import {extendBy as extend} from '../util/extend'; -import ExpressionParsingError from './parsing_error'; -import ParsingContext from './parsing_context'; -import EvaluationContext from './evaluation_context'; +import {ExpressionParsingError} from './parsing_error'; +import {ParsingContext} from './parsing_context'; +import {EvaluationContext} from './evaluation_context'; -import CompoundExpression, {isFeatureConstant, +import {CompoundExpression, isFeatureConstant, isGlobalPropertyConstant, isStateConstant, isExpressionConstant } from './compound_expression'; -import Step from './definitions/step'; -import Interpolate from './definitions/interpolate'; -import Coalesce from './definitions/coalesce'; -import Let from './definitions/let'; -import definitions from './definitions'; +import {Step} from './definitions/step'; +import {Interpolate} from './definitions/interpolate'; +import {Coalesce} from './definitions/coalesce'; +import {Let} from './definitions/let'; +import {expressions as definitions} from './definitions'; -import RuntimeError from './runtime_error'; +import {RuntimeError} from './runtime_error'; import {success, error} from '../util/result'; import {supportsPropertyExpression, supportsZoomExpression, supportsInterpolation} from '../util/properties'; @@ -32,9 +32,9 @@ import type {Point2D} from '../point2d'; import {ICanonicalTileID} from '../tiles_and_coordinates'; import {isFunction, createFunction} from '../function'; -import Color from './types/color'; -import Padding from './types/padding'; -import VariableAnchorOffsetCollection from './types/variable_anchor_offset_collection'; +import {Color} from './types/color'; +import {Padding} from './types/padding'; +import {VariableAnchorOffsetCollection} from './types/variable_anchor_offset_collection'; export type Feature = { readonly type: 0 | 1 | 2 | 3 | 'Unknown' | 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon'; diff --git a/src/expression/parsing_context.ts b/src/expression/parsing_context.ts index ada289e4e..11be4f5a3 100644 --- a/src/expression/parsing_context.ts +++ b/src/expression/parsing_context.ts @@ -1,10 +1,10 @@ -import Scope from './scope'; +import {Scope} from './scope'; import {checkSubtype} from './types'; -import ExpressionParsingError from './parsing_error'; -import Literal from './definitions/literal'; -import Assertion from './definitions/assertion'; -import Coercion from './definitions/coercion'; -import EvaluationContext from './evaluation_context'; +import {ExpressionParsingError} from './parsing_error'; +import {Literal} from './definitions/literal'; +import {Assertion} from './definitions/assertion'; +import {Coercion} from './definitions/coercion'; +import {EvaluationContext} from './evaluation_context'; import type {Expression, ExpressionRegistry} from './expression'; import type {Type} from './types'; @@ -13,7 +13,7 @@ import type {Type} from './types'; * State associated parsing at a given point in an expression tree. * @private */ -class ParsingContext { +export class ParsingContext { registry: ExpressionRegistry; path: Array; key: string; @@ -205,4 +205,3 @@ class ParsingContext { } } -export default ParsingContext; diff --git a/src/expression/parsing_error.ts b/src/expression/parsing_error.ts index 1c3ccba49..eae417dc7 100644 --- a/src/expression/parsing_error.ts +++ b/src/expression/parsing_error.ts @@ -1,4 +1,4 @@ -class ExpressionParsingError extends Error { +export class ExpressionParsingError extends Error { key: string; message: string; constructor(key: string, message: string) { @@ -7,5 +7,3 @@ class ExpressionParsingError extends Error { this.key = key; } } - -export default ExpressionParsingError; diff --git a/src/expression/runtime_error.ts b/src/expression/runtime_error.ts index 5dd906444..4580455e7 100644 --- a/src/expression/runtime_error.ts +++ b/src/expression/runtime_error.ts @@ -1,4 +1,4 @@ -class RuntimeError { +export class RuntimeError { name: string; message: string; @@ -11,5 +11,3 @@ class RuntimeError { return this.message; } } - -export default RuntimeError; diff --git a/src/expression/scope.ts b/src/expression/scope.ts index 76c683393..843f9e8f5 100644 --- a/src/expression/scope.ts +++ b/src/expression/scope.ts @@ -4,7 +4,7 @@ import type {Expression} from './expression'; * Tracks `let` bindings during expression parsing. * @private */ -class Scope { +export class Scope { parent: Scope; bindings: {[_: string]: Expression}; constructor(parent?: Scope, bindings: Array<[string, Expression]> = []) { @@ -30,5 +30,3 @@ class Scope { return this.parent ? this.parent.has(name) : false; } } - -export default Scope; diff --git a/src/expression/stops.ts b/src/expression/stops.ts index b9f00f0ff..27f2f9903 100644 --- a/src/expression/stops.ts +++ b/src/expression/stops.ts @@ -1,4 +1,4 @@ -import RuntimeError from './runtime_error'; +import {RuntimeError} from './runtime_error'; import type {Expression} from './expression'; diff --git a/src/expression/types/collator.ts b/src/expression/types/collator.ts index 30d020fe5..78318f4f8 100644 --- a/src/expression/types/collator.ts +++ b/src/expression/types/collator.ts @@ -22,7 +22,7 @@ type CollatorOptions = { caseFirst?: 'upper' | 'lower' | 'false'; }; -export default class Collator { +export class Collator { locale: string | null; sensitivity: 'base' | 'accent' | 'case' | 'variant'; collator: Intl$Collator; diff --git a/src/expression/types/color.test.ts b/src/expression/types/color.test.ts index 4062dee13..80adf860e 100644 --- a/src/expression/types/color.test.ts +++ b/src/expression/types/color.test.ts @@ -1,5 +1,5 @@ import {expectCloseToArray, expectToMatchColor} from '../../../test/lib/util'; -import Color, {isSupportedInterpolationColorSpace} from './color'; +import {Color, isSupportedInterpolationColorSpace} from './color'; describe('Color class', () => { diff --git a/src/expression/types/color.ts b/src/expression/types/color.ts index 6da5786a4..7d0f72d03 100644 --- a/src/expression/types/color.ts +++ b/src/expression/types/color.ts @@ -20,7 +20,7 @@ export function isSupportedInterpolationColorSpace(colorSpace: string): colorSpa * Defined in sRGB color space and pre-blended with alpha. * @private */ -class Color { +export class Color { readonly r: number; readonly g: number; @@ -56,10 +56,10 @@ class Color { } } - static black: Color; - static white: Color; - static transparent: Color; - static red: Color; + static black = new Color(0, 0, 0, 1); + static white = new Color(1, 1, 1, 1); + static transparent = new Color(0, 0, 0, 0); + static red = new Color(1, 0, 0, 1); /** * Parses CSS color strings and converts colors to sRGB color space if needed. @@ -206,9 +206,3 @@ class Color { } -Color.black = new Color(0, 0, 0, 1); -Color.white = new Color(1, 1, 1, 1); -Color.transparent = new Color(0, 0, 0, 0); -Color.red = new Color(1, 0, 0, 1); - -export default Color; diff --git a/src/expression/types/formatted.ts b/src/expression/types/formatted.ts index 352114726..0c5c283c8 100644 --- a/src/expression/types/formatted.ts +++ b/src/expression/types/formatted.ts @@ -1,5 +1,5 @@ -import type Color from '../../expression/types/color'; -import type ResolvedImage from '../types/resolved_image'; +import type {Color} from '../../expression/types/color'; +import type {ResolvedImage} from '../types/resolved_image'; export class FormattedSection { text: string; @@ -17,7 +17,7 @@ export class FormattedSection { } } -export default class Formatted { +export class Formatted { sections: Array; constructor(sections: Array) { diff --git a/src/expression/types/padding.test.ts b/src/expression/types/padding.test.ts index b450df6a6..7786f8023 100644 --- a/src/expression/types/padding.test.ts +++ b/src/expression/types/padding.test.ts @@ -1,4 +1,4 @@ -import Padding from './padding'; +import {Padding} from './padding'; describe('Padding', () => { test('Padding.parse', () => { diff --git a/src/expression/types/padding.ts b/src/expression/types/padding.ts index 1e60a86f0..888af7935 100644 --- a/src/expression/types/padding.ts +++ b/src/expression/types/padding.ts @@ -5,7 +5,7 @@ import {interpolateArray} from '../../util/interpolate-primitives'; * bare arrays or numeric values using the static method `Padding.parse`. * @private */ -class Padding { +export class Padding { /** Padding values are in CSS order: top, right, bottom, left */ values: [number, number, number, number]; @@ -67,5 +67,3 @@ class Padding { return new Padding(interpolateArray(from.values, to.values, t)); } } - -export default Padding; diff --git a/src/expression/types/resolved_image.ts b/src/expression/types/resolved_image.ts index cc8472aff..470ce72b7 100644 --- a/src/expression/types/resolved_image.ts +++ b/src/expression/types/resolved_image.ts @@ -3,7 +3,7 @@ export type ResolvedImageOptions = { available: boolean; }; -export default class ResolvedImage { +export class ResolvedImage { name: string; available: boolean; diff --git a/src/expression/types/variable_anchor_offset_collection.test.ts b/src/expression/types/variable_anchor_offset_collection.test.ts index 7ae2ce184..d7b21e01e 100644 --- a/src/expression/types/variable_anchor_offset_collection.test.ts +++ b/src/expression/types/variable_anchor_offset_collection.test.ts @@ -1,4 +1,4 @@ -import VariableAnchorOffsetCollection from './variable_anchor_offset_collection'; +import {VariableAnchorOffsetCollection} from './variable_anchor_offset_collection'; describe('VariableAnchorOffsetCollection', () => { test('VariableAnchorOffsetCollection.parse', () => { diff --git a/src/expression/types/variable_anchor_offset_collection.ts b/src/expression/types/variable_anchor_offset_collection.ts index 532b5f7c0..72685ce57 100644 --- a/src/expression/types/variable_anchor_offset_collection.ts +++ b/src/expression/types/variable_anchor_offset_collection.ts @@ -1,4 +1,4 @@ -import RuntimeError from '../runtime_error'; +import {RuntimeError} from '../runtime_error'; import {interpolateNumber} from '../../util/interpolate-primitives'; import type {VariableAnchorOffsetCollectionSpecification} from '../../types.g'; @@ -10,7 +10,7 @@ const anchors = new Set(['center', 'left', 'right', 'top', 'bottom', 'top-left', * bare arrays using the static method `VariableAnchorOffsetCollection.parse`. * @private */ -class VariableAnchorOffsetCollection { +export class VariableAnchorOffsetCollection { /** Series of paired of anchor (string) and offset (point) values */ values: VariableAnchorOffsetCollectionSpecification; @@ -76,5 +76,3 @@ class VariableAnchorOffsetCollection { return new VariableAnchorOffsetCollection(output); } } - -export default VariableAnchorOffsetCollection; diff --git a/src/expression/values.ts b/src/expression/values.ts index 18661acfd..bb570bc83 100644 --- a/src/expression/values.ts +++ b/src/expression/values.ts @@ -1,10 +1,10 @@ -import Color from './types/color'; -import Collator from './types/collator'; -import Formatted from './types/formatted'; -import Padding from './types/padding'; -import VariableAnchorOffsetCollection from './types/variable_anchor_offset_collection'; -import ResolvedImage from './types/resolved_image'; +import {Color} from './types/color'; +import {Collator} from './types/collator'; +import {Formatted} from './types/formatted'; +import {Padding} from './types/padding'; +import {VariableAnchorOffsetCollection} from './types/variable_anchor_offset_collection'; +import {ResolvedImage} from './types/resolved_image'; import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array, PaddingType, VariableAnchorOffsetCollectionType} from './types'; import type {Type} from './types'; diff --git a/src/function/index.test.ts b/src/function/index.test.ts index 9ee59adc2..cf1edb461 100644 --- a/src/function/index.test.ts +++ b/src/function/index.test.ts @@ -1,8 +1,8 @@ import {expectToMatchColor} from '../../test/lib/util'; import {createFunction} from './index'; -import Color from '../expression/types/color'; -import Formatted from '../expression/types/formatted'; -import Padding from '../expression/types/padding'; +import {Color} from '../expression/types/color'; +import {Formatted} from '../expression/types/formatted'; +import {Padding} from '../expression/types/padding'; describe('binary search', () => { test('will eventually terminate.', () => { diff --git a/src/function/index.ts b/src/function/index.ts index d54fc34cd..5974c75c3 100644 --- a/src/function/index.ts +++ b/src/function/index.ts @@ -1,12 +1,12 @@ -import Color, {isSupportedInterpolationColorSpace} from '../expression/types/color'; +import {Color, isSupportedInterpolationColorSpace} from '../expression/types/color'; import {extendBy as extend} from '../util/extend'; import {getType} from '../util/get_type'; -import Interpolate, {interpolateFactory} from '../expression/definitions/interpolate'; -import Formatted from '../expression/types/formatted'; -import ResolvedImage from '../expression/types/resolved_image'; +import {Interpolate, interpolateFactory} from '../expression/definitions/interpolate'; +import {Formatted} from '../expression/types/formatted'; +import {ResolvedImage} from '../expression/types/resolved_image'; import {supportsInterpolation} from '../util/properties'; import {findStopLessThanOrEqualTo} from '../expression/stops'; -import Padding from '../expression/types/padding'; +import {Padding} from '../expression/types/padding'; export function isFunction(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); diff --git a/src/index.ts b/src/index.ts index c7902f544..64c12291d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import v8Spec from './reference/v8.json' with {type: 'json'}; const v8 = v8Spec as any; import latest from './reference/latest'; -import derefLayers from './deref'; +import {deref as derefLayers} from './deref'; import {diffStyles as diff} from './diff'; import {ValidationError} from './error/validation_error'; import ParsingError from './error/parsing_error'; @@ -9,31 +9,31 @@ import {FeatureState, StyleExpression, isExpression, isZoomExpression, createExp import featureFilter, {isExpressionFilter} from './feature_filter'; import convertFilter from './feature_filter/convert'; -import Color from './expression/types/color'; -import Padding from './expression/types/padding'; -import VariableAnchorOffsetCollection from './expression/types/variable_anchor_offset_collection'; -import Formatted, {FormattedSection} from './expression/types/formatted'; +import {Color} from './expression/types/color'; +import {Padding} from './expression/types/padding'; +import {VariableAnchorOffsetCollection} from './expression/types/variable_anchor_offset_collection'; +import {Formatted, FormattedSection} from './expression/types/formatted'; import {createFunction, isFunction} from './function'; import convertFunction from './function/convert'; import {eachSource, eachLayer, eachProperty} from './visit'; -import ResolvedImage from './expression/types/resolved_image'; +import {ResolvedImage} from './expression/types/resolved_image'; import {supportsPropertyExpression} from './util/properties'; import {IMercatorCoordinate, ICanonicalTileID, ILngLat, ILngLatLike} from './tiles_and_coordinates'; -import EvaluationContext from './expression/evaluation_context'; +import {EvaluationContext} from './expression/evaluation_context'; import {FormattedType, NullType, Type, toString, ColorType} from './expression/types'; import {expressions} from './expression/definitions'; -import Interpolate from './expression/definitions/interpolate'; +import {Interpolate} from './expression/definitions/interpolate'; import {interpolateFactory, type InterpolationType} from './expression/definitions/interpolate'; import groupByLayout from './group_by_layout'; import {emptyStyle} from './empty'; import {validateStyleMin} from './validate_style.min'; -import Step from './expression/definitions/step'; +import {Step} from './expression/definitions/step'; import {typeOf} from './expression/values'; -import FormatExpression from './expression/definitions/format'; -import Literal from './expression/definitions/literal'; -import CompoundExpression from './expression/compound_expression'; +import {FormatExpression} from './expression/definitions/format'; +import {Literal} from './expression/definitions/literal'; +import {CompoundExpression} from './expression/compound_expression'; import {VariableAnchorOffsetCollectionSpecification} from './types.g'; import format from './format'; import {validate} from './validate/validate'; diff --git a/src/util/deep_equal.ts b/src/util/deep_equal.ts index 1ea97d1f7..765c7fd8c 100644 --- a/src/util/deep_equal.ts +++ b/src/util/deep_equal.ts @@ -3,7 +3,8 @@ * * @private */ -function deepEqual(a?: unknown | null, b?: unknown | null): boolean { + +export function deepEqual(a?: unknown | null, b?: unknown | null): boolean { if (Array.isArray(a)) { if (!Array.isArray(b) || a.length !== b.length) return false; for (let i = 0; i < a.length; i++) { @@ -21,6 +22,4 @@ function deepEqual(a?: unknown | null, b?: unknown | null): boolean { return true; } return a === b; -} - -export default deepEqual; +} \ No newline at end of file diff --git a/src/validate/validate_color.ts b/src/validate/validate_color.ts index 691b80d34..4279f5e03 100644 --- a/src/validate/validate_color.ts +++ b/src/validate/validate_color.ts @@ -1,6 +1,6 @@ import {ValidationError} from '../error/validation_error'; import {getType} from '../util/get_type'; -import Color from '../expression/types/color'; +import {Color} from '../expression/types/color'; export function validateColor(options) { const key = options.key; diff --git a/test/integration/expression/expression.test.ts b/test/integration/expression/expression.test.ts index e51ccc6da..2a01e3092 100644 --- a/test/integration/expression/expression.test.ts +++ b/test/integration/expression/expression.test.ts @@ -9,7 +9,7 @@ import { ICanonicalTileID, StylePropertyExpression } from '../../../src/index'; -import ExpressionParsingError from '../../../src/expression/parsing_error'; +import {ExpressionParsingError} from '../../../src/expression/parsing_error'; import {Result} from '../../../src/util/result'; import {getGeometry} from '../../lib/geometry'; import {deepEqual, stripPrecision} from '../../lib/json-diff'; diff --git a/test/lib/util.ts b/test/lib/util.ts index 18a7cde7f..86cf4c454 100644 --- a/test/lib/util.ts +++ b/test/lib/util.ts @@ -1,4 +1,4 @@ -import Color from '../../src/expression/types/color'; +import {Color} from '../../src/expression/types/color'; /** * @param toTest Color instance to test From f9696cbe1d659bf7f76055d2c347fdcb3adbcbaa Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 18:44:47 +0100 Subject: [PATCH 07/19] named imports --- bin/gl-style-format.ts | 2 +- bin/gl-style-migrate.ts | 4 ++-- src/deref.test.ts | 2 +- src/deref.ts | 4 ++-- src/error/parsing_error.ts | 2 +- src/expression/definitions/distance.ts | 2 +- src/feature_filter/convert.ts | 2 +- src/feature_filter/feature_filter.test.ts | 4 ++-- src/feature_filter/index.ts | 7 ++----- src/format.test.ts | 2 +- src/format.ts | 3 +-- src/function/convert.ts | 4 +--- src/group_by_layout.test.ts | 2 +- src/group_by_layout.ts | 4 +--- src/index.ts | 14 +++++++------- src/migrate.test.ts | 2 +- src/migrate.ts | 8 ++++---- src/migrate/expressions.ts | 6 +++--- src/migrate/migrate_colors.test.ts | 2 +- src/migrate/migrate_colors.ts | 2 +- src/migrate/v8.test.ts | 2 +- src/migrate/v8.ts | 2 +- src/read_style.ts | 2 +- src/reference/latest.ts | 2 +- src/util/cheap_ruler.ts | 2 +- 25 files changed, 40 insertions(+), 48 deletions(-) diff --git a/bin/gl-style-format.ts b/bin/gl-style-format.ts index d994decb3..c9f6f51d7 100644 --- a/bin/gl-style-format.ts +++ b/bin/gl-style-format.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import minimist from 'minimist'; -import format from '../src/format'; +import {format} from '../src/format'; const argv = minimist(process.argv.slice(2)); if (argv.help || argv.h || (!argv._.length && process.stdin.isTTY)) { diff --git a/bin/gl-style-migrate.ts b/bin/gl-style-migrate.ts index ccc5023ca..2b4fa65f4 100644 --- a/bin/gl-style-migrate.ts +++ b/bin/gl-style-migrate.ts @@ -2,8 +2,8 @@ import fs from 'fs'; import minimist from 'minimist'; -import format from '../src/format'; -import migrate from '../src/migrate'; +import {format} from '../src/format'; +import {migrate} from '../src/migrate'; const argv = minimist(process.argv.slice(2)); if (argv.help || argv.h || (!argv._.length && process.stdin.isTTY)) { diff --git a/src/deref.test.ts b/src/deref.test.ts index cf389fe13..411bb13a7 100644 --- a/src/deref.test.ts +++ b/src/deref.test.ts @@ -1,4 +1,4 @@ -import {deref} from './deref'; +import {derefLayers as deref} from './deref'; describe('deref', () => { test('derefs a ref layer which follows its parent', () => { diff --git a/src/deref.ts b/src/deref.ts index bb54c57df..39b66af1e 100644 --- a/src/deref.ts +++ b/src/deref.ts @@ -1,7 +1,7 @@ import {refProperties} from './util/ref_properties'; -export function deref(layer, parent) { +function deref(layer, parent) { const result = {}; for (const k in layer) { @@ -32,7 +32,7 @@ export function deref(layer, parent) { * @param {Array} layers * @returns {Array} */ -function derefLayers(layers) { +export function derefLayers(layers) { layers = layers.slice(); const map = Object.create(null); diff --git a/src/error/parsing_error.ts b/src/error/parsing_error.ts index 1e08c64b5..e18193b12 100644 --- a/src/error/parsing_error.ts +++ b/src/error/parsing_error.ts @@ -1,6 +1,6 @@ // Note: Do not inherit from Error. It breaks when transpiling to ES5. -export default class ParsingError { +export class ParsingError { message: string; error: Error; line: number; diff --git a/src/expression/definitions/distance.ts b/src/expression/definitions/distance.ts index 683290c61..3d1f6d107 100644 --- a/src/expression/definitions/distance.ts +++ b/src/expression/definitions/distance.ts @@ -6,7 +6,7 @@ import {isValue} from '../values'; import {EvaluationContext} from '../evaluation_context'; import {BBox, boxWithinBox, getLngLatFromTileCoord, pointWithinPolygon, segmentIntersectSegment, updateBBox} from '../../util/geometry_util'; import {classifyRings} from '../../util/classify_rings'; -import CheapRuler from '../../util/cheap_ruler'; +import {CheapRuler} from '../../util/cheap_ruler'; type SimpleGeometry = GeoJSON.Polygon | GeoJSON.LineString | GeoJSON.Point; diff --git a/src/feature_filter/convert.ts b/src/feature_filter/convert.ts index 37d246b8f..65b926b3e 100644 --- a/src/feature_filter/convert.ts +++ b/src/feature_filter/convert.ts @@ -52,7 +52,7 @@ type ExpectedTypes = {[_: string]: ExpressionInputType}; * false (legacy filter semantics) are equivalent: they cause the filter to * produce a `false` result. */ -export default function convertFilter(filter: FilterSpecification, expectedTypes: ExpectedTypes = {}): ExpressionFilterSpecification { +export function convertFilter(filter: FilterSpecification, expectedTypes: ExpectedTypes = {}): ExpressionFilterSpecification { if (isExpressionFilter(filter)) return filter; if (!filter) return true; diff --git a/src/feature_filter/feature_filter.test.ts b/src/feature_filter/feature_filter.test.ts index 0525e1116..3bed825fb 100644 --- a/src/feature_filter/feature_filter.test.ts +++ b/src/feature_filter/feature_filter.test.ts @@ -1,6 +1,6 @@ -import {default as createFilter, isExpressionFilter} from '.'; +import {createFilter, isExpressionFilter} from '.'; -import convertFilter from './convert'; +import {convertFilter} from './convert'; import {ICanonicalTileID} from '../tiles_and_coordinates'; import {ExpressionFilterSpecification, ExpressionInputType, ExpressionSpecification, FilterSpecification} from '../types.g'; import {Feature} from '../expression'; diff --git a/src/feature_filter/index.ts b/src/feature_filter/index.ts index 88cbe2149..41309bc44 100644 --- a/src/feature_filter/index.ts +++ b/src/feature_filter/index.ts @@ -15,10 +15,7 @@ export type FeatureFilter = { needGeometry: boolean; }; -export default createFilter; -export {isExpressionFilter}; - -function isExpressionFilter(filter: any): filter is ExpressionFilterSpecification { +export function isExpressionFilter(filter: any): filter is ExpressionFilterSpecification { if (filter === true || filter === false) { return true; } @@ -80,7 +77,7 @@ const filterSpec = { * @param {Array} filter MapLibre filter * @returns {Function} filter-evaluating function */ -function createFilter(filter: any): FeatureFilter { +export function createFilter(filter: any): FeatureFilter { if (filter === null || filter === undefined) { return {filter: () => true, needGeometry: false}; } diff --git a/src/format.test.ts b/src/format.test.ts index 0c0e266b9..6a9215516 100644 --- a/src/format.test.ts +++ b/src/format.test.ts @@ -1,4 +1,4 @@ -import format from './format'; +import {format} from './format'; function roundtrip(style) { return JSON.parse(format(style)); diff --git a/src/format.ts b/src/format.ts index 92b9d50b5..ae08c7ddd 100644 --- a/src/format.ts +++ b/src/format.ts @@ -38,7 +38,7 @@ function sortKeysBy(obj, reference) { * fs.writeFileSync('./dest.json', format(style)); * fs.writeFileSync('./dest.min.json', format(style, 0)); */ -function format(style, space = 2) { +export function format(style, space = 2) { style = sortKeysBy(style, reference.$root); if (style.layers) { @@ -48,4 +48,3 @@ function format(style, space = 2) { return stringifyPretty(style, {indent: space}); } -export default format; diff --git a/src/function/convert.ts b/src/function/convert.ts index 2ca0ae25b..896ae46ed 100644 --- a/src/function/convert.ts +++ b/src/function/convert.ts @@ -1,13 +1,11 @@ import type {StylePropertySpecification} from '..'; -export default convertFunction; - function convertLiteral(value) { return typeof value === 'object' ? ['literal', value] : value; } -function convertFunction(parameters: any, propertySpec: StylePropertySpecification) { +export function convertFunction(parameters: any, propertySpec: StylePropertySpecification) { let stops = parameters.stops; if (!stops) { // identity function diff --git a/src/group_by_layout.test.ts b/src/group_by_layout.test.ts index 2fd976e74..75fc9e6fa 100644 --- a/src/group_by_layout.test.ts +++ b/src/group_by_layout.test.ts @@ -1,4 +1,4 @@ -import group from './group_by_layout'; +import {groupByLayout as group} from './group_by_layout'; describe('group by layout', () => { test('group layers whose ref properties are identical', () => { diff --git a/src/group_by_layout.ts b/src/group_by_layout.ts index 58b1677a2..0bad8561a 100644 --- a/src/group_by_layout.ts +++ b/src/group_by_layout.ts @@ -31,8 +31,6 @@ function getKey(layer) { return key; } -export default groupByLayout; - /** * Given an array of layers, return an array of arrays of layers where all * layers in each group have identical layout-affecting properties. These @@ -48,7 +46,7 @@ export default groupByLayout; * @param {Object} [cachedKeys] - an object to keep already calculated keys. * @returns {Array>} */ -function groupByLayout(layers, cachedKeys) { +export function groupByLayout(layers, cachedKeys) { const groups = {}; for (let i = 0; i < layers.length; i++) { diff --git a/src/index.ts b/src/index.ts index 64c12291d..a5aabdc8d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,17 +4,17 @@ import latest from './reference/latest'; import {deref as derefLayers} from './deref'; import {diffStyles as diff} from './diff'; import {ValidationError} from './error/validation_error'; -import ParsingError from './error/parsing_error'; +import {ParsingError} from './error/parsing_error'; import {FeatureState, StyleExpression, isExpression, isZoomExpression, createExpression, createPropertyExpression, normalizePropertyExpression, ZoomConstantExpression, ZoomDependentExpression, StylePropertyFunction, Feature, GlobalProperties, SourceExpression, CompositeExpression, StylePropertyExpression} from './expression'; -import featureFilter, {isExpressionFilter} from './feature_filter'; +import {createFilter as featureFilter, isExpressionFilter} from './feature_filter'; -import convertFilter from './feature_filter/convert'; +import {convertFilter} from './feature_filter/convert'; import {Color} from './expression/types/color'; import {Padding} from './expression/types/padding'; import {VariableAnchorOffsetCollection} from './expression/types/variable_anchor_offset_collection'; import {Formatted, FormattedSection} from './expression/types/formatted'; import {createFunction, isFunction} from './function'; -import convertFunction from './function/convert'; +import {convertFunction} from './function/convert'; import {eachSource, eachLayer, eachProperty} from './visit'; import {ResolvedImage} from './expression/types/resolved_image'; import {supportsPropertyExpression} from './util/properties'; @@ -26,7 +26,7 @@ import {expressions} from './expression/definitions'; import {Interpolate} from './expression/definitions/interpolate'; import {interpolateFactory, type InterpolationType} from './expression/definitions/interpolate'; -import groupByLayout from './group_by_layout'; +import {groupByLayout} from './group_by_layout'; import {emptyStyle} from './empty'; import {validateStyleMin} from './validate_style.min'; import {Step} from './expression/definitions/step'; @@ -35,9 +35,9 @@ import {FormatExpression} from './expression/definitions/format'; import {Literal} from './expression/definitions/literal'; import {CompoundExpression} from './expression/compound_expression'; import {VariableAnchorOffsetCollectionSpecification} from './types.g'; -import format from './format'; +import {format} from './format'; import {validate} from './validate/validate'; -import migrate from './migrate'; +import {migrate} from './migrate'; import {classifyRings} from './util/classify_rings'; type ExpressionType = 'data-driven' | 'cross-faded' | 'cross-faded-data-driven' | 'color-ramp' | 'data-constant' | 'constant'; diff --git a/src/migrate.test.ts b/src/migrate.test.ts index 963eb9be8..3fd63a826 100644 --- a/src/migrate.test.ts +++ b/src/migrate.test.ts @@ -1,4 +1,4 @@ -import migrate from './migrate'; +import {migrate} from './migrate'; import * as spec from '.'; import v8 from './reference/v8.json' with {type: 'json'}; import {validateStyle as validate} from './validate_style'; diff --git a/src/migrate.ts b/src/migrate.ts index 0b00d80d9..c7ef1a6e1 100644 --- a/src/migrate.ts +++ b/src/migrate.ts @@ -1,7 +1,7 @@ -import migrateToV8 from './migrate/v8'; -import migrateToExpressions from './migrate/expressions'; -import migrateColors from './migrate/migrate_colors'; +import {migrateV8 as migrateToV8} from './migrate/v8'; +import {expressions as migrateToExpressions} from './migrate/expressions'; +import {migrateColors} from './migrate/migrate_colors'; import {eachProperty} from './visit'; import type {StyleSpecification} from './types.g'; @@ -16,7 +16,7 @@ import type {StyleSpecification} from './types.g'; * const style = fs.readFileSync('./style.json', 'utf8'); * fs.writeFileSync('./style.json', JSON.stringify(migrate(style))); */ -export default function migrate(style: StyleSpecification): StyleSpecification { +export function migrate(style: StyleSpecification): StyleSpecification { let migrated = false; if (style.version as any === 7) { diff --git a/src/migrate/expressions.ts b/src/migrate/expressions.ts index d70ec8440..8a13dcea9 100644 --- a/src/migrate/expressions.ts +++ b/src/migrate/expressions.ts @@ -1,7 +1,7 @@ import {eachLayer, eachProperty} from '../visit'; import {isExpression} from '../expression'; -import convertFunction, {convertTokenString} from '../function/convert'; -import convertFilter from '../feature_filter/convert'; +import {convertFunction, convertTokenString} from '../function/convert'; +import {convertFilter} from '../feature_filter/convert'; import type {FilterSpecification, LayerSpecification, StyleSpecification} from '../types.g'; @@ -12,7 +12,7 @@ import type {FilterSpecification, LayerSpecification, StyleSpecification} from ' * @param style The style object to migrate. * @returns The migrated style object. */ -export default function expressions(style: StyleSpecification) { +export function expressions(style: StyleSpecification) { const converted = []; eachLayer(style, (layer: LayerSpecification & { filter?: FilterSpecification }) => { diff --git a/src/migrate/migrate_colors.test.ts b/src/migrate/migrate_colors.test.ts index d5b654871..98f119823 100644 --- a/src/migrate/migrate_colors.test.ts +++ b/src/migrate/migrate_colors.test.ts @@ -1,4 +1,4 @@ -import migrateColors from './migrate_colors'; +import {migrateColors} from './migrate_colors'; describe('migrate colors', () => { diff --git a/src/migrate/migrate_colors.ts b/src/migrate/migrate_colors.ts index 670a3b290..64649d9cd 100644 --- a/src/migrate/migrate_colors.ts +++ b/src/migrate/migrate_colors.ts @@ -4,7 +4,7 @@ * @param colorToMigrate Color value to migrate, could be a string or an expression. * @returns Color style value in supported format. */ -export default function migrateColors(colorToMigrate: T): T { +export function migrateColors(colorToMigrate: T): T { return JSON.parse(migrateHslColors(JSON.stringify(colorToMigrate))); } diff --git a/src/migrate/v8.test.ts b/src/migrate/v8.test.ts index 857aaec4c..cf74465d0 100644 --- a/src/migrate/v8.test.ts +++ b/src/migrate/v8.test.ts @@ -1,4 +1,4 @@ -import migrate from './v8'; +import {migrateV8 as migrate} from './v8'; describe('migrate v8', () => { test('split text-font', () => { diff --git a/src/migrate/v8.ts b/src/migrate/v8.ts index 921ce8568..b763d6d3a 100644 --- a/src/migrate/v8.ts +++ b/src/migrate/v8.ts @@ -34,7 +34,7 @@ function renameProperty(obj: Object, from: string, to: string) { obj[to] = obj[from]; delete obj[from]; } -export default function migrateV8(style: StyleSpecification) { +export function migrateV8(style: StyleSpecification) { style.version = 8; // Rename properties, reverse coordinates in source and layers diff --git a/src/read_style.ts b/src/read_style.ts index 3ceea7743..4cf830d25 100644 --- a/src/read_style.ts +++ b/src/read_style.ts @@ -1,4 +1,4 @@ -import ParsingError from './error/parsing_error'; +import {ParsingError} from './error/parsing_error'; import jsonlint from '@mapbox/jsonlint-lines-primitives'; import type {StyleSpecification} from './types.g'; diff --git a/src/reference/latest.ts b/src/reference/latest.ts index bfd17bd5d..c4b0b4f47 100644 --- a/src/reference/latest.ts +++ b/src/reference/latest.ts @@ -1,3 +1,3 @@ -import spec from './v8.json' with { type: 'json' }; +import spec from './v8.json' with { type: 'json' }; export default spec as any; diff --git a/src/util/cheap_ruler.ts b/src/util/cheap_ruler.ts index 775be7ba8..3a27add76 100644 --- a/src/util/cheap_ruler.ts +++ b/src/util/cheap_ruler.ts @@ -7,7 +7,7 @@ const FE = 1 / 298.257223563; // flattening const E2 = FE * (2 - FE); const RAD = Math.PI / 180; -export default class CheapRuler { +export class CheapRuler { private kx: number; private ky: number; From 6c6bbabfc530e9a5d2e889b85848c593ddefe7e1 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 18:45:32 +0100 Subject: [PATCH 08/19] named imports --- src/index.ts | 2 +- src/read_style.ts | 2 +- src/validate_style.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index a5aabdc8d..461134482 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import v8Spec from './reference/v8.json' with {type: 'json'}; const v8 = v8Spec as any; import latest from './reference/latest'; -import {deref as derefLayers} from './deref'; +import {derefLayers} from './deref'; import {diffStyles as diff} from './diff'; import {ValidationError} from './error/validation_error'; import {ParsingError} from './error/parsing_error'; diff --git a/src/read_style.ts b/src/read_style.ts index 4cf830d25..9906f0538 100644 --- a/src/read_style.ts +++ b/src/read_style.ts @@ -2,7 +2,7 @@ import {ParsingError} from './error/parsing_error'; import jsonlint from '@mapbox/jsonlint-lines-primitives'; import type {StyleSpecification} from './types.g'; -export default function readStyle(style: StyleSpecification | string | Buffer): StyleSpecification { +export function readStyle(style: StyleSpecification | string | Buffer): StyleSpecification { if (style instanceof String || typeof style === 'string' || style instanceof Buffer) { try { return jsonlint.parse(style.toString()); diff --git a/src/validate_style.ts b/src/validate_style.ts index e29c1b499..6b2c7a9aa 100644 --- a/src/validate_style.ts +++ b/src/validate_style.ts @@ -1,7 +1,7 @@ import {validateStyleMin} from './validate_style.min'; import {v8, ValidationError} from '.'; -import readStyle from './read_style'; +import {readStyle} from './read_style'; import type {StyleSpecification} from './types.g'; /** From e4bb68992567b900f7b646da9f0a0f3e16ba9f7c Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 18:50:04 +0100 Subject: [PATCH 09/19] named spec --- src/empty.ts | 2 +- src/format.ts | 2 +- src/index.ts | 2 +- src/reference/latest.ts | 2 +- src/validate/validate_variable_anchor_offset_collection.test.ts | 2 +- src/validate_style.min.ts | 2 +- test/build/style-spec.test.ts | 2 +- test/integration/style-spec/validate_spec.test.ts | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/empty.ts b/src/empty.ts index 40e18887e..e8a2183fc 100644 --- a/src/empty.ts +++ b/src/empty.ts @@ -1,4 +1,4 @@ -import latest from './reference/latest'; +import {spec as latest} from './reference/latest'; import {StyleSpecification} from './types.g'; export function emptyStyle(): StyleSpecification { diff --git a/src/format.ts b/src/format.ts index ae08c7ddd..37525828a 100644 --- a/src/format.ts +++ b/src/format.ts @@ -1,5 +1,5 @@ -import reference from './reference/latest'; +import {spec as reference} from './reference/latest'; import stringifyPretty from 'json-stringify-pretty-compact'; function sortKeysBy(obj, reference) { diff --git a/src/index.ts b/src/index.ts index 461134482..619643abf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import v8Spec from './reference/v8.json' with {type: 'json'}; const v8 = v8Spec as any; -import latest from './reference/latest'; +import {spec as latest} from './reference/latest'; import {derefLayers} from './deref'; import {diffStyles as diff} from './diff'; import {ValidationError} from './error/validation_error'; diff --git a/src/reference/latest.ts b/src/reference/latest.ts index c4b0b4f47..450670975 100644 --- a/src/reference/latest.ts +++ b/src/reference/latest.ts @@ -1,3 +1,3 @@ import spec from './v8.json' with { type: 'json' }; -export default spec as any; +export {spec} diff --git a/src/validate/validate_variable_anchor_offset_collection.test.ts b/src/validate/validate_variable_anchor_offset_collection.test.ts index f5974cb75..489858d03 100644 --- a/src/validate/validate_variable_anchor_offset_collection.test.ts +++ b/src/validate/validate_variable_anchor_offset_collection.test.ts @@ -1,6 +1,6 @@ import {validate} from './validate'; import {validateVariableAnchorOffsetCollection} from './validate_variable_anchor_offset_collection'; -import latestStyleSpec from '../reference/latest'; +import {spec as latestStyleSpec} from '../reference/latest'; describe('Validate variableAnchorOffsetCollection', () => { const validateOpts = { diff --git a/src/validate_style.min.ts b/src/validate_style.min.ts index f825f1b6d..23246ec6a 100644 --- a/src/validate_style.min.ts +++ b/src/validate_style.min.ts @@ -1,7 +1,7 @@ import {validateConstants} from './validate/validate_constants'; import {validate} from './validate/validate'; -import latestStyleSpec from './reference/latest'; +import {spec as latestStyleSpec} from './reference/latest'; import {validateSource} from './validate/validate_source'; import {validateLight} from './validate/validate_light'; diff --git a/test/build/style-spec.test.ts b/test/build/style-spec.test.ts index f7503c4b2..edafe073f 100644 --- a/test/build/style-spec.test.ts +++ b/test/build/style-spec.test.ts @@ -1,5 +1,5 @@ import {readdir} from 'fs/promises'; -import reference from '../../src/reference/latest'; +import {spec as reference} from '../../src/reference/latest'; import fs from 'fs'; const minBundle = fs.readFileSync('dist/index.mjs', 'utf8'); diff --git a/test/integration/style-spec/validate_spec.test.ts b/test/integration/style-spec/validate_spec.test.ts index 953c2a017..52115714b 100644 --- a/test/integration/style-spec/validate_spec.test.ts +++ b/test/integration/style-spec/validate_spec.test.ts @@ -2,7 +2,7 @@ import {globSync} from 'glob'; import fs from 'fs'; import path from 'path'; import {validateStyle as validate} from '../../../src/validate_style'; -import reference from '../../../src/reference/latest'; +import {spec as reference} from '../../../src/reference/latest'; const UPDATE = !!process.env.UPDATE; From 9ff94ce213b26e0fae6e6f43b162b87257e13925 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 18:52:31 +0100 Subject: [PATCH 10/19] lint --- src/diff.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/diff.ts b/src/diff.ts index e3b32c34e..b6e677372 100644 --- a/src/diff.ts +++ b/src/diff.ts @@ -354,5 +354,3 @@ export function diffStyles(before: StyleSpecification, after: StyleSpecification return commands; } - - From 2e69f10d4d941329261441373b8e236a49d6f220 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 19:04:07 +0100 Subject: [PATCH 11/19] test static color --- src/expression/types/color.test.ts | 6 ++++++ src/expression/types/color.ts | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/expression/types/color.test.ts b/src/expression/types/color.test.ts index 80adf860e..13f31e562 100644 --- a/src/expression/types/color.test.ts +++ b/src/expression/types/color.test.ts @@ -37,6 +37,12 @@ describe('Color class', () => { expectCloseToArray(color.rgb, [0, 0, 0.5, 0]); }); + test('should have static properties, black', () => { + const color = Color.black; + expect(color).toMatchObject({r: 0, g: 0, b: 0, a: 1}); + expectCloseToArray(color.rgb, [0, 0, 0, 1]); + }); + test('should not keep a reference to the original color when alpha!=0', () => { const color = new Color(0, 0, 0.5, 0.001, false); expect(color).toMatchObject({r: 0, g: 0, b: expect.closeTo(0.5 * 0.001, 5), a: 0.001}); diff --git a/src/expression/types/color.ts b/src/expression/types/color.ts index 7d0f72d03..988a0c322 100644 --- a/src/expression/types/color.ts +++ b/src/expression/types/color.ts @@ -205,4 +205,3 @@ export class Color { } } - From 24a54b2614b907c6544156e58709d2be22050dd3 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 20:11:57 +0100 Subject: [PATCH 12/19] remove renaming --- src/declass.test.ts | 10 ++--- src/declass.ts | 8 ++-- src/deref.test.ts | 6 +-- src/diff.ts | 52 +++++++++++------------ src/empty.ts | 12 +++--- src/expression/compound_expression.ts | 11 +++-- src/expression/definitions/assertion.ts | 4 +- src/expression/definitions/coercion.ts | 2 +- src/expression/definitions/comparison.ts | 8 ++-- src/expression/definitions/format.ts | 4 +- src/expression/definitions/in.ts | 8 ++-- src/expression/definitions/index_of.ts | 8 ++-- src/expression/definitions/interpolate.ts | 4 +- src/expression/definitions/length.ts | 6 +-- src/expression/definitions/slice.ts | 6 +-- src/expression/expression.test.ts | 8 ++-- src/expression/index.ts | 10 ++--- src/expression/types.ts | 6 +-- src/expression/values.ts | 2 +- src/format.ts | 6 +-- src/function/index.ts | 4 +- src/group_by_layout.test.ts | 12 +++--- src/index.ts | 4 +- src/migrate.test.ts | 4 +- src/migrate.ts | 8 ++-- src/validate_style.min.ts | 4 +- 26 files changed, 108 insertions(+), 109 deletions(-) diff --git a/src/declass.test.ts b/src/declass.test.ts index 822c7cbce..ce26edb9b 100644 --- a/src/declass.test.ts +++ b/src/declass.test.ts @@ -1,4 +1,4 @@ -import {declassStyle as declass} from './declass'; +import {declassStyle} from './declass'; describe('declass', () => { test('declass a style, one class', () => { @@ -16,7 +16,7 @@ describe('declass', () => { }] }; - const declassed = declass(style, ['one']); + const declassed = declassStyle(style, ['one']); expect(declassed).not.toBe(style); expect(declassed.layers).not.toBe(style.layers); @@ -47,7 +47,7 @@ describe('declass', () => { }] }; - expect(declass(style, ['one'])).toEqual({ + expect(declassStyle(style, ['one'])).toEqual({ layers: [{ id: 'a', paint: { @@ -78,7 +78,7 @@ describe('declass', () => { }] }; - expect(declass(style, ['one', 'two'])).toEqual({ + expect(declassStyle(style, ['one', 'two'])).toEqual({ layers: [{ id: 'a', paint: { @@ -104,7 +104,7 @@ describe('declass', () => { }] }; - expect(declass(style, ['one'])).toEqual({ + expect(declassStyle(style, ['one'])).toEqual({ layers: [{ id: 'a', paint: { diff --git a/src/declass.ts b/src/declass.ts index 4b6bfbe81..a512b4ec8 100644 --- a/src/declass.ts +++ b/src/declass.ts @@ -1,5 +1,5 @@ -import {extendBy as extend} from './util/extend'; +import {extendBy} from './util/extend'; /** * Returns a new style with the given 'paint classes' merged into each layer's @@ -17,7 +17,7 @@ import {extendBy as extend} from './util/extend'; * // main `paint` property. */ export function declassStyle(style, classes) { - return extend({}, style, { + return extendBy({}, style, { layers: style.layers.map((layer) => { const result = classes.reduce(declassLayer, layer); @@ -34,7 +34,7 @@ export function declassStyle(style, classes) { } function declassLayer(layer, klass) { - return extend({}, layer, { - paint: extend({}, layer.paint, layer[`paint.${klass}`]) + return extendBy({}, layer, { + paint: extendBy({}, layer.paint, layer[`paint.${klass}`]) }); } diff --git a/src/deref.test.ts b/src/deref.test.ts index 411bb13a7..6d6c21c87 100644 --- a/src/deref.test.ts +++ b/src/deref.test.ts @@ -1,8 +1,8 @@ -import {derefLayers as deref} from './deref'; +import {derefLayers} from './deref'; describe('deref', () => { test('derefs a ref layer which follows its parent', () => { - expect(deref([ + expect(derefLayers([ { 'id': 'parent', 'type': 'line' @@ -24,7 +24,7 @@ describe('deref', () => { }); test('derefs a ref layer which precedes its parent', () => { - expect(deref([ + expect(derefLayers([ { 'id': 'child', 'ref': 'parent' diff --git a/src/diff.ts b/src/diff.ts index b6e677372..9e2bff9d8 100644 --- a/src/diff.ts +++ b/src/diff.ts @@ -1,6 +1,6 @@ import {GeoJSONSourceSpecification, LayerSpecification, LightSpecification, ProjectionSpecification, SkySpecification, SourceSpecification, SpriteSpecification, StyleSpecification, TerrainSpecification, TransitionSpecification} from './types.g'; -import {deepEqual as isEqual} from './util/deep_equal'; +import {deepEqual} from './util/deep_equal'; /** * Operations that can be performed by the diff. @@ -67,13 +67,13 @@ function canUpdateGeoJSON(before: {[key: string]: SourceSpecification}, after: { let prop; for (prop in before[sourceId]) { if (!Object.prototype.hasOwnProperty.call(before[sourceId], prop)) continue; - if (prop !== 'data' && !isEqual(before[sourceId][prop], after[sourceId][prop])) { + if (prop !== 'data' && !deepEqual(before[sourceId][prop], after[sourceId][prop])) { return false; } } for (prop in after[sourceId]) { if (!Object.prototype.hasOwnProperty.call(after[sourceId], prop)) continue; - if (prop !== 'data' && !isEqual(before[sourceId][prop], after[sourceId][prop])) { + if (prop !== 'data' && !deepEqual(before[sourceId][prop], after[sourceId][prop])) { return false; } } @@ -99,7 +99,7 @@ function diffSources(before: {[key: string]: SourceSpecification}, after: {[key: if (!Object.prototype.hasOwnProperty.call(after, sourceId)) continue; if (!Object.prototype.hasOwnProperty.call(before, sourceId)) { addSource(sourceId, after, commands); - } else if (!isEqual(before[sourceId], after[sourceId])) { + } else if (!deepEqual(before[sourceId], after[sourceId])) { if (before[sourceId].type === 'geojson' && after[sourceId].type === 'geojson' && canUpdateGeoJSON(before, after, sourceId)) { addCommand(commands, {command: 'setGeoJSONSourceData', args: [sourceId, (after[sourceId] as GeoJSONSourceSpecification).data]}); } else { @@ -116,13 +116,13 @@ function diffLayerPropertyChanges(before: LayerSpecification['layout'] | LayerSp for (const prop in before) { if (!Object.prototype.hasOwnProperty.call(before, prop)) continue; - if (!isEqual(before[prop], after[prop])) { + if (!deepEqual(before[prop], after[prop])) { commands.push({command, args: [layerId, prop, after[prop], klass]}); } } for (const prop in after) { if (!Object.prototype.hasOwnProperty.call(after, prop) || Object.prototype.hasOwnProperty.call(before, prop)) continue; - if (!isEqual(before[prop], after[prop])) { + if (!deepEqual(before[prop], after[prop])) { commands.push({command, args: [layerId, prop, after[prop], klass]}); } } @@ -202,11 +202,11 @@ function diffLayers(before: LayerSpecification[], after: LayerSpecification[], c afterLayer = afterIndex[layerId]; // no need to update if previously added (new or moved) - if (clean[layerId] || isEqual(beforeLayer, afterLayer)) continue; + if (clean[layerId] || deepEqual(beforeLayer, afterLayer)) continue; // If source, source-layer, or type have changes, then remove the layer // and add it back 'from scratch'. - if (!isEqual(beforeLayer.source, afterLayer.source) || !isEqual(beforeLayer['source-layer'], afterLayer['source-layer']) || !isEqual(beforeLayer.type, afterLayer.type)) { + if (!deepEqual(beforeLayer.source, afterLayer.source) || !deepEqual(beforeLayer['source-layer'], afterLayer['source-layer']) || !deepEqual(beforeLayer.type, afterLayer.type)) { addCommand(commands, {command: 'removeLayer', args: [layerId]}); // we add the layer back at the same position it was already in, so // there's no need to update the `tracker` @@ -218,10 +218,10 @@ function diffLayers(before: LayerSpecification[], after: LayerSpecification[], c // layout, paint, filter, minzoom, maxzoom diffLayerPropertyChanges(beforeLayer.layout, afterLayer.layout, commands, layerId, null, 'setLayoutProperty'); diffLayerPropertyChanges(beforeLayer.paint, afterLayer.paint, commands, layerId, null, 'setPaintProperty'); - if (!isEqual(beforeLayer.filter, afterLayer.filter)) { + if (!deepEqual(beforeLayer.filter, afterLayer.filter)) { addCommand(commands, {command: 'setFilter', args: [layerId, afterLayer.filter]}); } - if (!isEqual(beforeLayer.minzoom, afterLayer.minzoom) || !isEqual(beforeLayer.maxzoom, afterLayer.maxzoom)) { + if (!deepEqual(beforeLayer.minzoom, afterLayer.minzoom) || !deepEqual(beforeLayer.maxzoom, afterLayer.maxzoom)) { addCommand(commands, {command: 'setLayerZoomRange', args: [layerId, afterLayer.minzoom, afterLayer.maxzoom]}); } @@ -232,7 +232,7 @@ function diffLayers(before: LayerSpecification[], after: LayerSpecification[], c prop === 'metadata' || prop === 'minzoom' || prop === 'maxzoom') continue; if (prop.indexOf('paint.') === 0) { diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), 'setPaintProperty'); - } else if (!isEqual(beforeLayer[prop], afterLayer[prop])) { + } else if (!deepEqual(beforeLayer[prop], afterLayer[prop])) { addCommand(commands, {command: 'setLayerProperty', args: [layerId, prop, afterLayer[prop]]}); } } @@ -242,7 +242,7 @@ function diffLayers(before: LayerSpecification[], after: LayerSpecification[], c prop === 'metadata' || prop === 'minzoom' || prop === 'maxzoom') continue; if (prop.indexOf('paint.') === 0) { diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), 'setPaintProperty'); - } else if (!isEqual(beforeLayer[prop], afterLayer[prop])) { + } else if (!deepEqual(beforeLayer[prop], afterLayer[prop])) { addCommand(commands, {command: 'setLayerProperty', args: [layerId, prop, afterLayer[prop]]}); } } @@ -274,46 +274,46 @@ export function diffStyles(before: StyleSpecification, after: StyleSpecification try { // Handle changes to top-level properties - if (!isEqual(before.version, after.version)) { + if (!deepEqual(before.version, after.version)) { return [{command: 'setStyle', args: [after]}]; } - if (!isEqual(before.center, after.center)) { + if (!deepEqual(before.center, after.center)) { commands.push({command: 'setCenter', args: [after.center]}); } - if (!isEqual(before.centerAltitude, after.centerAltitude)) { + if (!deepEqual(before.centerAltitude, after.centerAltitude)) { commands.push({command: 'setCenterAltitude', args: [after.centerAltitude]}); } - if (!isEqual(before.zoom, after.zoom)) { + if (!deepEqual(before.zoom, after.zoom)) { commands.push({command: 'setZoom', args: [after.zoom]}); } - if (!isEqual(before.bearing, after.bearing)) { + if (!deepEqual(before.bearing, after.bearing)) { commands.push({command: 'setBearing', args: [after.bearing]}); } - if (!isEqual(before.pitch, after.pitch)) { + if (!deepEqual(before.pitch, after.pitch)) { commands.push({command: 'setPitch', args: [after.pitch]}); } - if (!isEqual(before.roll, after.roll)) { + if (!deepEqual(before.roll, after.roll)) { commands.push({command: 'setRoll', args: [after.roll]}); } - if (!isEqual(before.sprite, after.sprite)) { + if (!deepEqual(before.sprite, after.sprite)) { commands.push({command: 'setSprite', args: [after.sprite]}); } - if (!isEqual(before.glyphs, after.glyphs)) { + if (!deepEqual(before.glyphs, after.glyphs)) { commands.push({command: 'setGlyphs', args: [after.glyphs]}); } - if (!isEqual(before.transition, after.transition)) { + if (!deepEqual(before.transition, after.transition)) { commands.push({command: 'setTransition', args: [after.transition]}); } - if (!isEqual(before.light, after.light)) { + if (!deepEqual(before.light, after.light)) { commands.push({command: 'setLight', args: [after.light]}); } - if (!isEqual(before.terrain, after.terrain)) { + if (!deepEqual(before.terrain, after.terrain)) { commands.push({command: 'setTerrain', args: [after.terrain]}); } - if (!isEqual(before.sky, after.sky)) { + if (!deepEqual(before.sky, after.sky)) { commands.push({command: 'setSky', args: [after.sky]}); } - if (!isEqual(before.projection, after.projection)) { + if (!deepEqual(before.projection, after.projection)) { commands.push({command: 'setProjection', args: [after.projection]}); } diff --git a/src/empty.ts b/src/empty.ts index e8a2183fc..3e04844bf 100644 --- a/src/empty.ts +++ b/src/empty.ts @@ -1,19 +1,19 @@ -import {spec as latest} from './reference/latest'; +import {spec} from './reference/latest'; import {StyleSpecification} from './types.g'; export function emptyStyle(): StyleSpecification { const style = {}; - const version = latest['$version']; - for (const styleKey in latest['$root']) { - const spec = latest['$root'][styleKey]; + const version = spec['$version']; + for (const styleKey in spec['$root']) { + const specification = spec['$root'][styleKey]; - if (spec.required) { + if (specification.required) { let value = null; if (styleKey === 'version') { value = version; } else { - if (spec.type === 'array') { + if (specification.type === 'array') { value = []; } else { value = {}; diff --git a/src/expression/compound_expression.ts b/src/expression/compound_expression.ts index 16f9a7f28..152d77680 100644 --- a/src/expression/compound_expression.ts +++ b/src/expression/compound_expression.ts @@ -1,4 +1,4 @@ -import {toString, +import {typeToString, NumberType, StringType, BooleanType, @@ -8,7 +8,6 @@ import {toString, ErrorType, CollatorType, array, - toString as typeToString, } from './types'; import {ParsingContext} from './parsing_context'; @@ -27,7 +26,7 @@ import type {Expression, ExpressionRegistry} from './expression'; import type {Value} from './values'; import type {Type} from './types'; -import {typeOf, validateRGBA, toString as valueToString} from './values'; +import {typeOf, validateRGBA, valueToString} from './values'; import {RuntimeError} from './runtime_error'; import {Color} from './types/color'; @@ -151,7 +150,7 @@ export class CompoundExpression implements Expression { for (let i = 1; i < args.length; i++) { const parsed = context.parse(args[i], 1 + actualTypes.length); if (!parsed) return null; - actualTypes.push(toString(parsed.type)); + actualTypes.push(typeToString(parsed.type)); } context.error(`Expected arguments of type ${signatures}, but found (${actualTypes.join(', ')}) instead.`); } @@ -647,9 +646,9 @@ CompoundExpression.register(expressions, { function stringifySignature(signature: Signature): string { if (Array.isArray(signature)) { - return `(${signature.map(toString).join(', ')})`; + return `(${signature.map(typeToString).join(', ')})`; } else { - return `(${toString(signature.type)}...)`; + return `(${typeToString(signature.type)}...)`; } } diff --git a/src/expression/definitions/assertion.ts b/src/expression/definitions/assertion.ts index 7a08d92ee..2db761480 100644 --- a/src/expression/definitions/assertion.ts +++ b/src/expression/definitions/assertion.ts @@ -6,7 +6,7 @@ import { NumberType, BooleanType, checkSubtype, - toString, + typeToString, array } from '../types'; import {RuntimeError} from '../runtime_error'; @@ -89,7 +89,7 @@ export class Assertion implements Expression { if (!error) { return value; } else if (i === this.args.length - 1) { - throw new RuntimeError(`Expected value to be of type ${toString(this.type)}, but found ${toString(typeOf(value))} instead.`); + throw new RuntimeError(`Expected value to be of type ${typeToString(this.type)}, but found ${typeToString(typeOf(value))} instead.`); } } diff --git a/src/expression/definitions/coercion.ts b/src/expression/definitions/coercion.ts index d25b7365e..f118ad960 100644 --- a/src/expression/definitions/coercion.ts +++ b/src/expression/definitions/coercion.ts @@ -1,5 +1,5 @@ import {BooleanType, ColorType, NumberType, StringType, ValueType} from '../types'; -import {toString as valueToString, validateRGBA} from '../values'; +import {valueToString, validateRGBA} from '../values'; import {RuntimeError} from '../runtime_error'; import {Formatted} from '../types/formatted'; import {ResolvedImage} from '../types/resolved_image'; diff --git a/src/expression/definitions/comparison.ts b/src/expression/definitions/comparison.ts index a5cb660cb..de32d1352 100644 --- a/src/expression/definitions/comparison.ts +++ b/src/expression/definitions/comparison.ts @@ -1,4 +1,4 @@ -import {toString, ValueType, BooleanType, CollatorType} from '../types'; +import {typeToString, ValueType, BooleanType, CollatorType} from '../types'; import {Assertion} from './assertion'; import {typeOf} from '../values'; import {RuntimeError} from '../runtime_error'; @@ -84,12 +84,12 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato let lhs = context.parse(args[1], 1, ValueType); 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; + return context.concat(1).error(`"${op}" comparisons are not supported for type '${typeToString(lhs.type)}'.`) as null; } let rhs = context.parse(args[2], 2, ValueType); 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; + return context.concat(2).error(`"${op}" comparisons are not supported for type '${typeToString(rhs.type)}'.`) as null; } if ( @@ -97,7 +97,7 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato lhs.type.kind !== 'value' && rhs.type.kind !== 'value' ) { - return context.error(`Cannot compare types '${toString(lhs.type)}' and '${toString(rhs.type)}'.`) as null; + return context.error(`Cannot compare types '${typeToString(lhs.type)}' and '${typeToString(rhs.type)}'.`) as null; } if (isOrderComparison) { diff --git a/src/expression/definitions/format.ts b/src/expression/definitions/format.ts index 78f89fc83..1d340c0ad 100644 --- a/src/expression/definitions/format.ts +++ b/src/expression/definitions/format.ts @@ -8,7 +8,7 @@ import { ResolvedImageType, } from '../types'; import {Formatted, FormattedSection} from '../types/formatted'; -import {toString, typeOf} from '../values'; +import {valueToString, typeOf} from '../values'; import type {Expression} from '../expression'; import type {EvaluationContext} from '../evaluation_context'; @@ -97,7 +97,7 @@ export class FormatExpression implements Expression { } return new FormattedSection( - toString(evaluatedContent), + valueToString(evaluatedContent), null, section.scale ? section.scale.evaluate(ctx) : null, section.font ? section.font.evaluate(ctx).join(',') : null, diff --git a/src/expression/definitions/in.ts b/src/expression/definitions/in.ts index 21ecec249..ff73a6dc4 100644 --- a/src/expression/definitions/in.ts +++ b/src/expression/definitions/in.ts @@ -3,7 +3,7 @@ import { StringType, ValueType, NullType, - toString, + typeToString, NumberType, isValidType, isValidNativeType, @@ -39,7 +39,7 @@ export class In implements Expression { if (!needle || !haystack) return null; if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) { - return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`) as null; + return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${typeToString(needle.type)} instead`) as null; } return new In(needle, haystack); @@ -52,11 +52,11 @@ export class In implements Expression { if (!haystack) return false; if (!isValidNativeType(needle, ['boolean', 'string', 'number', 'null'])) { - throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${toString(typeOf(needle))} instead.`); + throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${typeToString(typeOf(needle))} instead.`); } if (!isValidNativeType(haystack, ['string', 'array'])) { - throw new RuntimeError(`Expected second argument to be of type array or string, but found ${toString(typeOf(haystack))} instead.`); + throw new RuntimeError(`Expected second argument to be of type array or string, but found ${typeToString(typeOf(haystack))} instead.`); } return haystack.indexOf(needle) >= 0; diff --git a/src/expression/definitions/index_of.ts b/src/expression/definitions/index_of.ts index 523359849..db845de4d 100644 --- a/src/expression/definitions/index_of.ts +++ b/src/expression/definitions/index_of.ts @@ -3,7 +3,7 @@ import { StringType, ValueType, NullType, - toString, + typeToString, NumberType, isValidType, isValidNativeType, @@ -40,7 +40,7 @@ export class IndexOf implements Expression { if (!needle || !haystack) return null; if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) { - return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`) as null; + return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${typeToString(needle.type)} instead`) as null; } if (args.length === 4) { @@ -57,7 +57,7 @@ export class IndexOf implements Expression { const haystack = (this.haystack.evaluate(ctx) as any); if (!isValidNativeType(needle, ['boolean', 'string', 'number', 'null'])) { - throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${toString(typeOf(needle))} instead.`); + throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${typeToString(typeOf(needle))} instead.`); } let fromIndex; @@ -76,7 +76,7 @@ export class IndexOf implements Expression { } else if (isValidNativeType(haystack, ['array'])) { return haystack.indexOf(needle, fromIndex); } else { - throw new RuntimeError(`Expected second argument to be of type array or string, but found ${toString(typeOf(haystack))} instead.`); + throw new RuntimeError(`Expected second argument to be of type array or string, but found ${typeToString(typeOf(haystack))} instead.`); } } diff --git a/src/expression/definitions/interpolate.ts b/src/expression/definitions/interpolate.ts index f77537cdb..a4326c696 100644 --- a/src/expression/definitions/interpolate.ts +++ b/src/expression/definitions/interpolate.ts @@ -1,6 +1,6 @@ import UnitBezier from '@mapbox/unitbezier'; -import {array, ArrayType, ColorType, ColorTypeT, NumberType, NumberTypeT, PaddingType, PaddingTypeT, VariableAnchorOffsetCollectionType, VariableAnchorOffsetCollectionTypeT, toString, verifyType} from '../types'; +import {array, ArrayType, ColorType, ColorTypeT, NumberType, NumberTypeT, PaddingType, PaddingTypeT, VariableAnchorOffsetCollectionType, VariableAnchorOffsetCollectionTypeT, typeToString, verifyType} from '../types'; import {findStopLessThanOrEqualTo} from '../stops'; import type {Stops} from '../stops'; @@ -142,7 +142,7 @@ export class Interpolate implements Expression { !verifyType(outputType, VariableAnchorOffsetCollectionType) && !verifyType(outputType, array(NumberType)) ) { - return context.error(`Type ${toString(outputType)} is not interpolatable.`) as null; + return context.error(`Type ${typeToString(outputType)} is not interpolatable.`) as null; } return new Interpolate(outputType, (operator as any), interpolation as InterpolationType, input as Expression, stops); diff --git a/src/expression/definitions/length.ts b/src/expression/definitions/length.ts index 78b8f9a85..198c739f6 100644 --- a/src/expression/definitions/length.ts +++ b/src/expression/definitions/length.ts @@ -1,4 +1,4 @@ -import {NumberType, toString} from '../types'; +import {NumberType, typeToString} from '../types'; import {typeOf} from '../values'; import {RuntimeError} from '../runtime_error'; @@ -25,7 +25,7 @@ export class Length implements Expression { if (!input) return null; if (input.type.kind !== 'array' && input.type.kind !== 'string' && input.type.kind !== 'value') - return context.error(`Expected argument of type string or array, but found ${toString(input.type)} instead.`) as null; + return context.error(`Expected argument of type string or array, but found ${typeToString(input.type)} instead.`) as null; return new Length(input); } @@ -38,7 +38,7 @@ export class Length implements Expression { } else if (Array.isArray(input)) { return input.length; } else { - throw new RuntimeError(`Expected value to be of type string or array, but found ${toString(typeOf(input))} instead.`); + throw new RuntimeError(`Expected value to be of type string or array, but found ${typeToString(typeOf(input))} instead.`); } } diff --git a/src/expression/definitions/slice.ts b/src/expression/definitions/slice.ts index 7dfee20c6..b66c8e7f2 100644 --- a/src/expression/definitions/slice.ts +++ b/src/expression/definitions/slice.ts @@ -3,7 +3,7 @@ import { NumberType, StringType, array, - toString, + typeToString, isValidType, isValidNativeType, } from '../types'; @@ -40,7 +40,7 @@ export class Slice implements Expression { if (!input || !beginIndex) return null; if (!isValidType(input.type, [array(ValueType), StringType, ValueType])) { - return context.error(`Expected first argument to be of type array or string, but found ${toString(input.type)} instead`) as null; + return context.error(`Expected first argument to be of type array or string, but found ${typeToString(input.type)} instead`) as null; } if (args.length === 4) { @@ -67,7 +67,7 @@ export class Slice implements Expression { } else if (isValidNativeType(input, ['array'])) { return input.slice(beginIndex, endIndex); } else { - throw new RuntimeError(`Expected first argument to be of type array or string, but found ${toString(typeOf(input))} instead.`); + throw new RuntimeError(`Expected first argument to be of type array or string, but found ${typeToString(typeOf(input))} instead.`); } } diff --git a/src/expression/expression.test.ts b/src/expression/expression.test.ts index 225bd837e..33d660a74 100644 --- a/src/expression/expression.test.ts +++ b/src/expression/expression.test.ts @@ -1,14 +1,14 @@ import {createPropertyExpression, Feature, GlobalProperties, StylePropertyExpression} from '../expression'; -import {expressions as definitions} from './definitions'; +import {expressions} from './definitions'; import v8 from '../reference/v8.json' with {type: 'json'}; import {createExpression, ICanonicalTileID, StyleExpression, StylePropertySpecification} from '..'; -import {ExpressionParsingError as ParsingError} from './parsing_error'; +import {ExpressionParsingError} from './parsing_error'; import {getGeometry} from '../../test/lib/geometry'; import {VariableAnchorOffsetCollection} from './types/variable_anchor_offset_collection'; // filter out internal "error" and "filter-*" expressions from definition list const filterExpressionRegex = /filter-/; -const definitionList = Object.keys(definitions).filter((expression) => { +const definitionList = Object.keys(expressions).filter((expression) => { return expression !== 'error' && !filterExpressionRegex.exec(expression); }).sort(); @@ -34,7 +34,7 @@ describe('createPropertyExpression', () => { } } as StylePropertySpecification); expect(result).toBe('error'); - expect((value as ParsingError[])).toHaveLength(1); + expect((value as ExpressionParsingError[])).toHaveLength(1); expect(value[0].message).toBe('"interpolate" expressions cannot be used with this property'); }); diff --git a/src/expression/index.ts b/src/expression/index.ts index b8b73094c..f820549a5 100644 --- a/src/expression/index.ts +++ b/src/expression/index.ts @@ -1,5 +1,5 @@ -import {extendBy as extend} from '../util/extend'; +import {extendBy} from '../util/extend'; import {ExpressionParsingError} from './parsing_error'; import {ParsingContext} from './parsing_context'; import {EvaluationContext} from './evaluation_context'; @@ -14,7 +14,7 @@ import {Step} from './definitions/step'; import {Interpolate} from './definitions/interpolate'; import {Coalesce} from './definitions/coalesce'; import {Let} from './definitions/let'; -import {expressions as definitions} from './definitions'; +import {expressions} from './definitions'; import {RuntimeError} from './runtime_error'; import {success, error} from '../util/result'; @@ -132,7 +132,7 @@ export class StyleExpression { export function isExpression(expression: unknown) { return Array.isArray(expression) && expression.length > 0 && - typeof expression[0] === 'string' && expression[0] in definitions; + typeof expression[0] === 'string' && expression[0] in expressions; } /** @@ -145,7 +145,7 @@ export function isExpression(expression: unknown) { * @private */ export function createExpression(expression: unknown, propertySpec?: StylePropertySpecification | null): Result> { - const parser = new ParsingContext(definitions, isExpressionConstant, [], propertySpec ? getExpectedType(propertySpec) : undefined); + const parser = new ParsingContext(expressions, isExpressionConstant, [], propertySpec ? getExpectedType(propertySpec) : undefined); // For string-valued properties, coerce to string at the top level rather than asserting. const parsed = parser.parse(expression, undefined, undefined, undefined, @@ -353,7 +353,7 @@ export class StylePropertyFunction { constructor(parameters: PropertyValueSpecification, specification: StylePropertySpecification) { this._parameters = parameters; this._specification = specification; - extend(this, createFunction(this._parameters, this._specification)); + extendBy(this, createFunction(this._parameters, this._specification)); } static deserialize(serialized: { diff --git a/src/expression/types.ts b/src/expression/types.ts index f001e66c1..ab7ac672a 100644 --- a/src/expression/types.ts +++ b/src/expression/types.ts @@ -73,9 +73,9 @@ export function array(itemType: T, N?: number | null): ArrayType }; } -export function toString(type: Type): string { +export function typeToString(type: Type): string { if (type.kind === 'array') { - const itemType = toString(type.itemType); + const itemType = typeToString(type.itemType); return typeof type.N === 'number' ? `array<${itemType}, ${type.N}>` : type.itemType.kind === 'value' ? 'array' : `array<${itemType}>`; @@ -123,7 +123,7 @@ export function checkSubtype(expected: Type, t: Type): string { } } - return `Expected ${toString(expected)} but found ${toString(t)} instead.`; + return `Expected ${typeToString(expected)} but found ${typeToString(t)} instead.`; } export function isValidType(provided: Type, allowedTypes: Array): boolean { diff --git a/src/expression/values.ts b/src/expression/values.ts index bb570bc83..fb6034c29 100644 --- a/src/expression/values.ts +++ b/src/expression/values.ts @@ -106,7 +106,7 @@ export function typeOf(value: Value): Type { } } -export function toString(value: Value) { +export function valueToString(value: Value) { const type = typeof value; if (value === null) { return ''; diff --git a/src/format.ts b/src/format.ts index 37525828a..fc78ac9be 100644 --- a/src/format.ts +++ b/src/format.ts @@ -1,5 +1,5 @@ -import {spec as reference} from './reference/latest'; +import {spec} from './reference/latest'; import stringifyPretty from 'json-stringify-pretty-compact'; function sortKeysBy(obj, reference) { @@ -39,10 +39,10 @@ function sortKeysBy(obj, reference) { * fs.writeFileSync('./dest.min.json', format(style, 0)); */ export function format(style, space = 2) { - style = sortKeysBy(style, reference.$root); + style = sortKeysBy(style, spec.$root); if (style.layers) { - style.layers = style.layers.map((layer) => sortKeysBy(layer, reference.layer)); + style.layers = style.layers.map((layer) => sortKeysBy(layer, spec.layer)); } return stringifyPretty(style, {indent: space}); diff --git a/src/function/index.ts b/src/function/index.ts index 5974c75c3..1c5042574 100644 --- a/src/function/index.ts +++ b/src/function/index.ts @@ -1,5 +1,5 @@ import {Color, isSupportedInterpolationColorSpace} from '../expression/types/color'; -import {extendBy as extend} from '../util/extend'; +import {extendBy} from '../util/extend'; import {getType} from '../util/get_type'; import {Interpolate, interpolateFactory} from '../expression/definitions/interpolate'; import {Formatted} from '../expression/types/formatted'; @@ -26,7 +26,7 @@ export function createFunction(parameters, propertySpec) { if (isColor || propertySpec.type === 'padding') { const parseFn = isColor ? Color.parse : Padding.parse; - parameters = extend({}, parameters); + parameters = extendBy({}, parameters); if (parameters.stops) { parameters.stops = parameters.stops.map((stop) => { diff --git a/src/group_by_layout.test.ts b/src/group_by_layout.test.ts index 75fc9e6fa..96a9ef13a 100644 --- a/src/group_by_layout.test.ts +++ b/src/group_by_layout.test.ts @@ -1,4 +1,4 @@ -import {groupByLayout as group} from './group_by_layout'; +import {groupByLayout} from './group_by_layout'; describe('group by layout', () => { test('group layers whose ref properties are identical', () => { @@ -10,13 +10,13 @@ describe('group by layout', () => { 'id': 'child', 'type': 'line' }; - expect(group([a, b], {})).toEqual([[a, b]]); - expect(group([a, b], {})[0][0]).toBe(a); - expect(group([a, b], {})[0][1]).toBe(b); + expect(groupByLayout([a, b], {})).toEqual([[a, b]]); + expect(groupByLayout([a, b], {})[0][0]).toBe(a); + expect(groupByLayout([a, b], {})[0][1]).toBe(b); }); test('group does not group unrelated layers', () => { - expect(group([ + expect(groupByLayout([ { 'id': 'parent', 'type': 'line' @@ -37,7 +37,7 @@ describe('group by layout', () => { }); test('group works even for differing layout key orders', () => { - expect(group([ + expect(groupByLayout([ { 'id': 'parent', 'type': 'line', diff --git a/src/index.ts b/src/index.ts index 619643abf..4a49530aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,7 @@ import {ResolvedImage} from './expression/types/resolved_image'; import {supportsPropertyExpression} from './util/properties'; import {IMercatorCoordinate, ICanonicalTileID, ILngLat, ILngLatLike} from './tiles_and_coordinates'; import {EvaluationContext} from './expression/evaluation_context'; -import {FormattedType, NullType, Type, toString, ColorType} from './expression/types'; +import {FormattedType, NullType, Type, typeToString, ColorType} from './expression/types'; import {expressions} from './expression/definitions'; import {Interpolate} from './expression/definitions/interpolate'; @@ -182,7 +182,7 @@ export { convertFilter, featureFilter, typeOf, - toString, + typeToString as toString, format, validate, migrate, diff --git a/src/migrate.test.ts b/src/migrate.test.ts index 3fd63a826..6d0c90891 100644 --- a/src/migrate.test.ts +++ b/src/migrate.test.ts @@ -1,7 +1,7 @@ import {migrate} from './migrate'; import * as spec from '.'; import v8 from './reference/v8.json' with {type: 'json'}; -import {validateStyle as validate} from './validate_style'; +import {validateStyle} from './validate_style'; describe('migrate', () => { test('does not migrate from version 5', () => { @@ -107,7 +107,7 @@ describe('migrate', () => { 'some-icon', '' ]); - expect(validate(migrated, v8)).toEqual([]); + expect(validateStyle(migrated, v8)).toEqual([]); }); test('converts colors to supported format', () => { diff --git a/src/migrate.ts b/src/migrate.ts index c7ef1a6e1..3c44ecc5c 100644 --- a/src/migrate.ts +++ b/src/migrate.ts @@ -1,6 +1,6 @@ -import {migrateV8 as migrateToV8} from './migrate/v8'; -import {expressions as migrateToExpressions} from './migrate/expressions'; +import {migrateV8} from './migrate/v8'; +import {expressions} from './migrate/expressions'; import {migrateColors} from './migrate/migrate_colors'; import {eachProperty} from './visit'; import type {StyleSpecification} from './types.g'; @@ -20,12 +20,12 @@ export function migrate(style: StyleSpecification): StyleSpecification { let migrated = false; if (style.version as any === 7) { - style = migrateToV8(style); + style = migrateV8(style); migrated = true; } if (style.version === 8) { - migrated = !!migrateToExpressions(style); + migrated = !!expressions(style); migrated = true; } diff --git a/src/validate_style.min.ts b/src/validate_style.min.ts index 23246ec6a..56e4cc53f 100644 --- a/src/validate_style.min.ts +++ b/src/validate_style.min.ts @@ -1,7 +1,7 @@ import {validateConstants} from './validate/validate_constants'; import {validate} from './validate/validate'; -import {spec as latestStyleSpec} from './reference/latest'; +import {spec} from './reference/latest'; import {validateSource} from './validate/validate_source'; import {validateLight} from './validate/validate_light'; @@ -28,7 +28,7 @@ import type {StyleSpecification} from './types.g'; * const validate = require('@maplibre/maplibre-gl-style-spec/').validateStyleMin; * const errors = validate(style); */ -export function validateStyleMin(style: StyleSpecification, styleSpec = latestStyleSpec): Array { +export function validateStyleMin(style: StyleSpecification, styleSpec = spec): Array { let errors: ValidationError[] = []; From 4db0779a37b97105cce1682366e03391e3e563f1 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 20:14:16 +0100 Subject: [PATCH 13/19] remove rename --- src/validate/validate.ts | 4 +- src/validate/validate_padding.test.ts | 40 +++++++++---------- src/validate/validate_projection.test.ts | 14 +++---- .../validate_raster_dem_source.test.ts | 18 ++++----- src/validate/validate_sky.test.ts | 12 +++--- src/validate/validate_sprite.test.ts | 30 +++++++------- src/validate/validate_terrain.test.ts | 12 +++--- ..._variable_anchor_offset_collection.test.ts | 4 +- 8 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/validate/validate.ts b/src/validate/validate.ts index 65a39ac2e..6cd68d34b 100644 --- a/src/validate/validate.ts +++ b/src/validate/validate.ts @@ -1,5 +1,5 @@ -import {extendBy as extend} from '../util/extend'; +import {extendBy} from '../util/extend'; import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; import {isExpression} from '../expression'; import {isFunction} from '../function'; @@ -94,7 +94,7 @@ export function validate(options: { return VALIDATORS[valueSpec.type](options); } else { - const valid = validateObject(extend({}, options, { + const valid = validateObject(extendBy({}, options, { valueSpec: valueSpec.type ? styleSpec[valueSpec.type] : valueSpec })); return valid; diff --git a/src/validate/validate_padding.test.ts b/src/validate/validate_padding.test.ts index 4d38d05ca..ca1284ae9 100644 --- a/src/validate/validate_padding.test.ts +++ b/src/validate/validate_padding.test.ts @@ -1,83 +1,83 @@ -import {validate as validateSpec} from './validate'; +import {validate} from './validate'; import {validatePadding} from './validate_padding'; describe('Validate Padding', () => { test('Should return error if type is not number or array', () => { - let errors = validatePadding({validateSpec, key: 'padding', value: '3'}); + let errors = validatePadding({validateSpec: validate, key: 'padding', value: '3'}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding: number expected, string found'); - errors = validatePadding({validateSpec, key: 'padding', value: true}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: true}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding: number expected, boolean found'); - errors = validatePadding({validateSpec, key: 'padding', value: null}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: null}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding: number expected, null found'); - errors = validatePadding({validateSpec, key: 'padding', value: {x: 1, y: 1}}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: {x: 1, y: 1}}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding: number expected, object found'); - errors = validatePadding({validateSpec, key: 'padding', value: NaN}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: NaN}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding: number expected, NaN found'); }); test('Should pass if type is number', () => { - const errors = validatePadding({validateSpec, key: 'padding', value: 1}); + const errors = validatePadding({validateSpec: validate, key: 'padding', value: 1}); expect(errors).toHaveLength(0); }); test('Should return error if array length is invalid', () => { - let errors = validatePadding({validateSpec, key: 'padding', value: []}); + let errors = validatePadding({validateSpec: validate, key: 'padding', value: []}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding: padding requires 1 to 4 values; 0 values found'); - errors = validatePadding({validateSpec, key: 'padding', value: [1, 1, 1, 1, 1]}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 1, 1, 1, 1]}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding: padding requires 1 to 4 values; 5 values found'); - errors = validatePadding({validateSpec, key: 'padding', value: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding: padding requires 1 to 4 values; 12 values found'); }); test('Should return error if array contains non-numeric values', () => { - let errors = validatePadding({validateSpec, key: 'padding', value: ['1']}); + let errors = validatePadding({validateSpec: validate, key: 'padding', value: ['1']}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding[0]: number expected, string found'); - errors = validatePadding({validateSpec, key: 'padding', value: [true]}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: [true]}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding[0]: number expected, boolean found'); - errors = validatePadding({validateSpec, key: 'padding', value: [NaN]}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: [NaN]}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding[0]: number expected, NaN found'); - errors = validatePadding({validateSpec, key: 'padding', value: [{x: 1}]}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: [{x: 1}]}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding[0]: number expected, object found'); - errors = validatePadding({validateSpec, key: 'padding', value: [1, 3, false]}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 3, false]}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('padding[2]: number expected, boolean found'); - errors = validatePadding({validateSpec, key: 'padding', value: ['1', 3, false]}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: ['1', 3, false]}); expect(errors).toHaveLength(2); expect(errors[0].message).toBe('padding[0]: number expected, string found'); expect(errors[1].message).toBe('padding[2]: number expected, boolean found'); }); test('Should pass if type is numeric array', () => { - let errors = validatePadding({validateSpec, key: 'padding', value: [1]}); + let errors = validatePadding({validateSpec: validate, key: 'padding', value: [1]}); expect(errors).toHaveLength(0); - errors = validatePadding({validateSpec, key: 'padding', value: [1, 1]}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 1]}); expect(errors).toHaveLength(0); - errors = validatePadding({validateSpec, key: 'padding', value: [1, 1, 1]}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 1, 1]}); expect(errors).toHaveLength(0); - errors = validatePadding({validateSpec, key: 'padding', value: [1, 1, 1, 1]}); + errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 1, 1, 1]}); expect(errors).toHaveLength(0); }); }); diff --git a/src/validate/validate_projection.test.ts b/src/validate/validate_projection.test.ts index 019d58abc..c2c4d8339 100644 --- a/src/validate/validate_projection.test.ts +++ b/src/validate/validate_projection.test.ts @@ -1,38 +1,38 @@ import {validateProjection} from './validate_projection'; -import {validate as validateSpec} from './validate'; +import {validate} from './validate'; import v8 from '../reference/v8.json' with {type: 'json'}; import {ProjectionSpecification} from '../types.g'; describe('Validate projection', () => { it('Should pass when value is undefined', () => { - const errors = validateProjection({validateSpec, value: undefined, styleSpec: v8, style: {} as any}); + const errors = validateProjection({validateSpec: validate, value: undefined, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0); }); test('Should return error when value is not an object', () => { - const errors = validateProjection({validateSpec, value: '' as unknown as ProjectionSpecification, styleSpec: v8, style: {} as any}); + const errors = validateProjection({validateSpec: validate, value: '' as unknown as ProjectionSpecification, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); expect(errors[0].message).toContain('object'); expect(errors[0].message).toContain('expected'); }); test('Should return error in case of unknown property', () => { - const errors = validateProjection({validateSpec, value: {a: 1} as any, styleSpec: v8, style: {} as any}); + const errors = validateProjection({validateSpec: validate, value: {a: 1} as any, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); expect(errors[0].message).toContain('a'); expect(errors[0].message).toContain('unknown'); }); test('Should return errors according to spec violations', () => { - const errors = validateProjection({validateSpec, value: {type: 1 as any}, styleSpec: v8, style: {} as any}); + const errors = validateProjection({validateSpec: validate, value: {type: 1 as any}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('type: expected one of [mercator, globe, vertical-perspective], 1 found'); }); test('Should pass if everything is according to spec', () => { - let errors = validateProjection({validateSpec, value: {type: 'globe'}, styleSpec: v8, style: {} as any}); + let errors = validateProjection({validateSpec: validate, value: {type: 'globe'}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0); - errors = validateProjection({validateSpec, value: {type: 'mercator'}, styleSpec: v8, style: {} as any}); + errors = validateProjection({validateSpec: validate, value: {type: 'mercator'}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0); }); }); diff --git a/src/validate/validate_raster_dem_source.test.ts b/src/validate/validate_raster_dem_source.test.ts index c49ba9b36..c3b908fc1 100644 --- a/src/validate/validate_raster_dem_source.test.ts +++ b/src/validate/validate_raster_dem_source.test.ts @@ -1,4 +1,4 @@ -import {validate as validateSpec} from './validate'; +import {validate} from './validate'; import v8 from '../reference/v8.json' with {type: 'json'}; import {validateRasterDEMSource} from './validate_raster_dem_source'; import {RasterDEMSourceSpecification} from '../types.g'; @@ -11,26 +11,26 @@ function checkErrorMessage(message: string, key: string, expectedType: string, f describe('Validate source_raster_dem', () => { test('Should pass when value is undefined', () => { - const errors = validateRasterDEMSource({validateSpec, value: undefined, styleSpec: v8, style: {} as any}); + const errors = validateRasterDEMSource({validateSpec: validate, value: undefined, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0); }); test('Should return error when value is not an object', () => { - const errors = validateRasterDEMSource({validateSpec, value: '' as unknown as RasterDEMSourceSpecification, styleSpec: v8, style: {} as any}); + const errors = validateRasterDEMSource({validateSpec: validate, value: '' as unknown as RasterDEMSourceSpecification, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); expect(errors[0].message).toContain('object'); expect(errors[0].message).toContain('expected'); }); test('Should return error in case of unknown property', () => { - const errors = validateRasterDEMSource({validateSpec, value: {a: 1} as any, styleSpec: v8, style: {} as any}); + const errors = validateRasterDEMSource({validateSpec: validate, value: {a: 1} as any, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); expect(errors[0].message).toContain('a'); expect(errors[0].message).toContain('unknown'); }); test('Should return errors according to spec violations', () => { - const errors = validateRasterDEMSource({validateSpec, value: {type: 'raster-dem', url: {} as any, tiles: {} as any, encoding: 'foo' as any}, styleSpec: v8, style: {} as any}); + const errors = validateRasterDEMSource({validateSpec: validate, value: {type: 'raster-dem', url: {} as any, tiles: {} as any, encoding: 'foo' as any}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(3); checkErrorMessage(errors[0].message, 'url', 'string', 'object'); checkErrorMessage(errors[1].message, 'tiles', 'array', 'object'); @@ -38,7 +38,7 @@ describe('Validate source_raster_dem', () => { }); test('Should return errors when custom encoding values are set but encoding is "mapbox"', () => { - const errors = validateRasterDEMSource({validateSpec, value: {type: 'raster-dem', encoding: 'mapbox', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); + const errors = validateRasterDEMSource({validateSpec: validate, value: {type: 'raster-dem', encoding: 'mapbox', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(4); checkErrorMessage(errors[0].message, 'redFactor', 'custom', 'mapbox'); checkErrorMessage(errors[1].message, 'greenFactor', 'custom', 'mapbox'); @@ -47,7 +47,7 @@ describe('Validate source_raster_dem', () => { }); test('Should return errors when custom encoding values are set but encoding is "terrarium"', () => { - const errors = validateRasterDEMSource({validateSpec, value: {type: 'raster-dem', encoding: 'terrarium', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); + const errors = validateRasterDEMSource({validateSpec: validate, value: {type: 'raster-dem', encoding: 'terrarium', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(4); checkErrorMessage(errors[0].message, 'redFactor', 'custom', 'terrarium'); checkErrorMessage(errors[1].message, 'greenFactor', 'custom', 'terrarium'); @@ -56,12 +56,12 @@ describe('Validate source_raster_dem', () => { }); test('Should pass when custom encoding values are set and encoding is "custom"', () => { - const errors = validateRasterDEMSource({validateSpec, value: {type: 'raster-dem', encoding: 'custom', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); + const errors = validateRasterDEMSource({validateSpec: validate, value: {type: 'raster-dem', encoding: 'custom', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0); }); test('Should pass if everything is according to spec', () => { - const errors = validateRasterDEMSource({validateSpec, value: {type: 'raster-dem'}, styleSpec: v8, style: {} as any}); + const errors = validateRasterDEMSource({validateSpec: validate, value: {type: 'raster-dem'}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0); }); }); diff --git a/src/validate/validate_sky.test.ts b/src/validate/validate_sky.test.ts index 5d297212f..ff6ae19e4 100644 --- a/src/validate/validate_sky.test.ts +++ b/src/validate/validate_sky.test.ts @@ -1,30 +1,30 @@ import {validateSky} from './validate_sky'; -import {validate as validateSpec} from './validate'; +import {validate} from './validate'; import v8 from '../reference/v8.json' with {type: 'json'}; import {SkySpecification} from '../types.g'; describe('Validate sky', () => { it('Should pass when value is undefined', () => { - const errors = validateSky({validateSpec, value: undefined, styleSpec: v8, style: {} as any}); + const errors = validateSky({validateSpec: validate, value: undefined, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0); }); test('Should return error when value is not an object', () => { - const errors = validateSky({validateSpec, value: '' as unknown as SkySpecification, styleSpec: v8, style: {} as any}); + const errors = validateSky({validateSpec: validate, value: '' as unknown as SkySpecification, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); expect(errors[0].message).toContain('object'); expect(errors[0].message).toContain('expected'); }); test('Should return error in case of unknown property', () => { - const errors = validateSky({validateSpec, value: {a: 1} as any, styleSpec: v8, style: {} as any}); + const errors = validateSky({validateSpec: validate, value: {a: 1} as any, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); expect(errors[0].message).toContain('a'); expect(errors[0].message).toContain('unknown'); }); test('Should return errors according to spec violations', () => { - const errors = validateSky({validateSpec, value: {'sky-color': 1 as any, 'fog-color': 2 as any, 'horizon-fog-blend': {} as any, 'fog-ground-blend': 'foo' as any}, styleSpec: v8, style: {} as any}); + const errors = validateSky({validateSpec: validate, value: {'sky-color': 1 as any, 'fog-color': 2 as any, 'horizon-fog-blend': {} as any, 'fog-ground-blend': 'foo' as any}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(4); expect(errors[0].message).toBe('sky-color: color expected, number found'); expect(errors[1].message).toBe('fog-color: color expected, number found'); @@ -33,7 +33,7 @@ describe('Validate sky', () => { }); test('Should pass if everything is according to spec', () => { - const errors = validateSky({validateSpec, value: {'sky-color': 'red', 'fog-color': '#123456', 'horizon-fog-blend': 1, 'fog-ground-blend': 0}, styleSpec: v8, style: {} as any}); + const errors = validateSky({validateSpec: validate, value: {'sky-color': 'red', 'fog-color': '#123456', 'horizon-fog-blend': 1, 'fog-ground-blend': 0}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0); }); }); diff --git a/src/validate/validate_sprite.test.ts b/src/validate/validate_sprite.test.ts index 479041877..2afecd198 100644 --- a/src/validate/validate_sprite.test.ts +++ b/src/validate/validate_sprite.test.ts @@ -1,60 +1,60 @@ import {validateSprite} from './validate_sprite'; -import {validate as validateSpec} from './validate'; +import {validate} from './validate'; describe('Validate Sprite', () => { test('Should return error if type is not string or array', () => { - let errors = validateSprite({validateSpec, key: 'sprite', value: 3}); + let errors = validateSprite({validateSpec: validate, key: 'sprite', value: 3}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('sprite: string expected, number found'); - errors = validateSprite({validateSpec, key: 'sprite', value: true}); + errors = validateSprite({validateSpec: validate, key: 'sprite', value: true}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('sprite: string expected, boolean found'); - errors = validateSprite({validateSpec, key: 'sprite', value: null}); + errors = validateSprite({validateSpec: validate, key: 'sprite', value: null}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('sprite: string expected, null found'); - errors = validateSprite({validateSpec, key: 'sprite', value: {x: 1, y: 1}}); + errors = validateSprite({validateSpec: validate, key: 'sprite', value: {x: 1, y: 1}}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('sprite: string expected, object found'); }); test('Should pass if type is string', () => { - const errors = validateSprite({validateSpec, key: 'sprite', value: 'url'}); + const errors = validateSprite({validateSpec: validate, key: 'sprite', value: 'url'}); expect(errors).toHaveLength(0); }); test('Should return error if array contains non-object values', () => { - let errors = validateSprite({validateSpec, key: 'sprite', value: ['1']}); + let errors = validateSprite({validateSpec: validate, key: 'sprite', value: ['1']}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('sprite[0]: object expected, string found'); - errors = validateSprite({validateSpec, key: 'sprite', value: [true]}); + errors = validateSprite({validateSpec: validate, key: 'sprite', value: [true]}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('sprite[0]: object expected, boolean found'); - errors = validateSprite({validateSpec, key: 'sprite', value: [3]}); + errors = validateSprite({validateSpec: validate, key: 'sprite', value: [3]}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('sprite[0]: object expected, number found'); - errors = validateSprite({validateSpec, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, false]}); + errors = validateSprite({validateSpec: validate, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, false]}); expect(errors).toHaveLength(1); expect(errors[0].message).toBe('sprite[2]: object expected, boolean found'); - errors = validateSprite({validateSpec, key: 'sprite', value: ['string', {id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, false]}); + errors = validateSprite({validateSpec: validate, key: 'sprite', value: ['string', {id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, false]}); expect(errors).toHaveLength(2); expect(errors[0].message).toBe('sprite[0]: object expected, string found'); expect(errors[1].message).toBe('sprite[3]: object expected, boolean found'); }); test('Should return error if array\'s objects are not of form {id: string, url: string}', () => { - let errors = validateSprite({validateSpec, key: 'sprite', value: [{id: 2, url: 2}]}); + let errors = validateSprite({validateSpec: validate, key: 'sprite', value: [{id: 2, url: 2}]}); expect(errors).toHaveLength(2); expect(errors[0].message).toBe('sprite[0].id: string expected, number found'); expect(errors[1].message).toBe('sprite[0].url: string expected, number found'); - errors = validateSprite({validateSpec, key: 'sprite', value: [{test: 'string'}]}); + errors = validateSprite({validateSpec: validate, key: 'sprite', value: [{test: 'string'}]}); expect(errors).toHaveLength(3); expect(errors[0].message).toBe('sprite[0]: unknown property "test"'); expect(errors[1].message).toBe('sprite[0]: missing required property "id"'); @@ -62,14 +62,14 @@ describe('Validate Sprite', () => { }); test('Should return error if array\'s objects contain duplicated IDs or URLs', () => { - const errors = validateSprite({validateSpec, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id1', url: 'url1'}]}); + const errors = validateSprite({validateSpec: validate, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id1', url: 'url1'}]}); expect(errors).toHaveLength(2); expect(errors[0].message).toBe('sprite: all the sprites\' ids must be unique, but id1 is duplicated'); expect(errors[1].message).toBe('sprite: all the sprites\' URLs must be unique, but url1 is duplicated'); }); test('Should pass if correct array of objects', () => { - const errors = validateSprite({validateSpec, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, {id: 'id3', url: 'url3'}]}); + const errors = validateSprite({validateSpec: validate, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, {id: 'id3', url: 'url3'}]}); expect(errors).toHaveLength(0); }); }); diff --git a/src/validate/validate_terrain.test.ts b/src/validate/validate_terrain.test.ts index 3b52c0143..5f103173d 100644 --- a/src/validate/validate_terrain.test.ts +++ b/src/validate/validate_terrain.test.ts @@ -1,10 +1,10 @@ -import {validate as validateSpec} from './validate'; +import {validate} from './validate'; import {validateTerrain} from './validate_terrain'; import v8 from '../reference/v8.json' with {type: 'json'}; describe('Validate Terrain', () => { test('Should return error in case terrain is not an object', () => { - const errors = validateTerrain({validateSpec, value: 1 as any, styleSpec: v8, style: {} as any}); + const errors = validateTerrain({validateSpec: validate, value: 1 as any, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); expect(errors[0].message).toContain('number'); expect(errors[0].message).toContain('object'); @@ -12,7 +12,7 @@ describe('Validate Terrain', () => { }); test('Should return error in case terrain source is not a string', () => { - const errors = validateTerrain({validateSpec, value: {source: 1 as any}, styleSpec: v8, style: {} as any}); + const errors = validateTerrain({validateSpec: validate, value: {source: 1 as any}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); expect(errors[0].message).toContain('number'); expect(errors[0].message).toContain('string'); @@ -20,14 +20,14 @@ describe('Validate Terrain', () => { }); test('Should return error in case of unknown property', () => { - const errors = validateTerrain({validateSpec, value: {a: 1} as any, styleSpec: v8, style: {} as any}); + const errors = validateTerrain({validateSpec: validate, value: {a: 1} as any, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); expect(errors[0].message).toContain('a'); expect(errors[0].message).toContain('unknown'); }); test('Should return errors according to spec violations', () => { - const errors = validateTerrain({validateSpec, value: {source: 1 as any, exaggeration: {} as any}, styleSpec: v8, style: {} as any}); + const errors = validateTerrain({validateSpec: validate, value: {source: 1 as any, exaggeration: {} as any}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(2); expect(errors[0].message).toContain('number'); expect(errors[0].message).toContain('string'); @@ -38,7 +38,7 @@ describe('Validate Terrain', () => { }); test('Should pass if everything is according to spec', () => { - const errors = validateTerrain({validateSpec, value: {source: 'source-id', exaggeration: 0.2}, styleSpec: v8, style: {} as any}); + const errors = validateTerrain({validateSpec: validate, value: {source: 'source-id', exaggeration: 0.2}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0); }); }); diff --git a/src/validate/validate_variable_anchor_offset_collection.test.ts b/src/validate/validate_variable_anchor_offset_collection.test.ts index 489858d03..4cbb6c340 100644 --- a/src/validate/validate_variable_anchor_offset_collection.test.ts +++ b/src/validate/validate_variable_anchor_offset_collection.test.ts @@ -1,11 +1,11 @@ import {validate} from './validate'; import {validateVariableAnchorOffsetCollection} from './validate_variable_anchor_offset_collection'; -import {spec as latestStyleSpec} from '../reference/latest'; +import {spec} from '../reference/latest'; describe('Validate variableAnchorOffsetCollection', () => { const validateOpts = { validateSpec: validate, - styleSpec: latestStyleSpec, + styleSpec: spec, key: 'myProp', }; test('Should return error if type is not array', () => { From 940d317740f3a7bd54a5b10c57b7b69ba5132beb Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 20:15:52 +0100 Subject: [PATCH 14/19] remove renaming --- src/diff.test.ts | 98 +++++++++---------- src/diff.ts | 2 +- src/empty.ts | 8 +- src/feature_filter/feature_filter.test.ts | 46 ++++----- src/feature_filter/index.ts | 2 +- src/format.ts | 6 +- src/index.ts | 6 +- src/reference/latest.ts | 4 +- ..._variable_anchor_offset_collection.test.ts | 4 +- src/validate_style.min.ts | 4 +- 10 files changed, 90 insertions(+), 90 deletions(-) diff --git a/src/diff.test.ts b/src/diff.test.ts index 66a030388..e2fdee07d 100644 --- a/src/diff.test.ts +++ b/src/diff.test.ts @@ -1,9 +1,9 @@ -import {diffStyles} from './diff'; +import {diff} from './diff'; import {StyleSpecification} from './types.g'; describe('diff', () => { test('layers id equal', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a'}] } as StyleSpecification, { layers: [{id: 'a'}] @@ -11,7 +11,7 @@ describe('diff', () => { }); test('version not equal', () => { - expect(diffStyles({ + expect(diff({ version: 7, layers: [{id: 'a'}] } as any as StyleSpecification, { @@ -23,7 +23,7 @@ describe('diff', () => { }); test('add layer at the end', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a'}] } as StyleSpecification, { layers: [{id: 'a'}, {id: 'b'}] @@ -33,7 +33,7 @@ describe('diff', () => { }); test('add layer at the beginning', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'b'}] } as StyleSpecification, { layers: [{id: 'a'}, {id: 'b'}] @@ -43,7 +43,7 @@ describe('diff', () => { }); test('remove layer', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a'}, {id: 'b', source: 'foo', nested: [1]}] } as StyleSpecification, { layers: [{id: 'a'}] @@ -53,7 +53,7 @@ describe('diff', () => { }); test('remove and add layer', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a'}, {id: 'b'}] } as StyleSpecification, { layers: [{id: 'b'}, {id: 'a'}] @@ -64,7 +64,7 @@ describe('diff', () => { }); test('set paint property', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a', paint: {foo: 1}}] } as any as StyleSpecification, { layers: [{id: 'a', paint: {foo: 2}}] @@ -74,7 +74,7 @@ describe('diff', () => { }); test('set paint property with light', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a', 'paint.light': {foo: 1}}] } as any as StyleSpecification, { layers: [{id: 'a', 'paint.light': {foo: 2}}] @@ -84,7 +84,7 @@ describe('diff', () => { }); test('set paint property with ramp', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a', paint: {foo: {ramp: [1, 2]}}}] } as any as StyleSpecification, { layers: [{id: 'a', paint: {foo: {ramp: [1]}}}] @@ -94,7 +94,7 @@ describe('diff', () => { }); test('set layout property', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a', layout: {foo: 1}}] } as any as StyleSpecification, { layers: [{id: 'a', layout: {foo: 2}}] @@ -104,7 +104,7 @@ describe('diff', () => { }); test('set filter', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a', filter: ['==', 'foo', 'bar']}] } as StyleSpecification, { layers: [{id: 'a', filter: ['==', 'foo', 'baz']}] @@ -114,7 +114,7 @@ describe('diff', () => { }); test('remove source', () => { - expect(diffStyles({ + expect(diff({ sources: {foo: 1} } as any as StyleSpecification, { sources: {} @@ -124,7 +124,7 @@ describe('diff', () => { }); test('add source', () => { - expect(diffStyles({ + expect(diff({ sources: {} } as StyleSpecification, { sources: {foo: 1} @@ -134,7 +134,7 @@ describe('diff', () => { }); test('set goejson source data', () => { - expect(diffStyles({ + expect(diff({ sources: { foo: { type: 'geojson', @@ -166,7 +166,7 @@ describe('diff', () => { }); test('remove and add source', () => { - expect(diffStyles({ + expect(diff({ sources: { foo: { type: 'geojson', @@ -192,7 +192,7 @@ describe('diff', () => { }); test('remove and add source with clusterRadius', () => { - expect(diffStyles({ + expect(diff({ sources: { foo: { type: 'geojson', @@ -221,7 +221,7 @@ describe('diff', () => { }); test('remove and add source without clusterRadius', () => { - expect(diffStyles({ + expect(diff({ sources: { foo: { type: 'geojson', @@ -249,13 +249,13 @@ describe('diff', () => { }); test('global metadata', () => { - expect(diffStyles({} as StyleSpecification, { + expect(diff({} as StyleSpecification, { metadata: {'maplibre:author': 'nobody'} } as StyleSpecification)).toEqual([]); }); test('layer metadata', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a', metadata: {'maplibre:group': 'Group Name'}}] } as StyleSpecification, { layers: [{id: 'a', metadata: {'maplibre:group': 'Another Name'}}] @@ -263,7 +263,7 @@ describe('diff', () => { }); test('set center', () => { - expect(diffStyles({ + expect(diff({ center: [0, 0] } as StyleSpecification, { center: [1, 1] @@ -273,7 +273,7 @@ describe('diff', () => { }); test('set centerAltitude to undefined', () => { - expect(diffStyles({ + expect(diff({ centerAltitude: 1 } as StyleSpecification, { } as StyleSpecification)).toEqual([ @@ -282,7 +282,7 @@ describe('diff', () => { }); test('set centerAltitude', () => { - expect(diffStyles({ + expect(diff({ centerAltitude: 0 } as StyleSpecification, { centerAltitude: 1 @@ -292,7 +292,7 @@ describe('diff', () => { }); test('set zoom', () => { - expect(diffStyles({ + expect(diff({ zoom: 12 } as StyleSpecification, { zoom: 15 @@ -302,7 +302,7 @@ describe('diff', () => { }); test('set bearing', () => { - expect(diffStyles({ + expect(diff({ bearing: 0 } as StyleSpecification, { bearing: 180 @@ -312,7 +312,7 @@ describe('diff', () => { }); test('set pitch', () => { - expect(diffStyles({ + expect(diff({ pitch: 0 } as StyleSpecification, { pitch: 1 @@ -322,7 +322,7 @@ describe('diff', () => { }); test('set roll to undefined', () => { - expect(diffStyles({ + expect(diff({ roll: 1 } as StyleSpecification, { } as StyleSpecification)).toEqual([ @@ -331,7 +331,7 @@ describe('diff', () => { }); test('set roll', () => { - expect(diffStyles({ + expect(diff({ roll: 0 } as StyleSpecification, { roll: 1 @@ -341,7 +341,7 @@ describe('diff', () => { }); test('no changes in light', () => { - expect(diffStyles({ + expect(diff({ light: { anchor: 'map', color: 'white', @@ -360,7 +360,7 @@ describe('diff', () => { }); test('set light anchor', () => { - expect(diffStyles({ + expect(diff({ light: {anchor: 'map'} } as StyleSpecification, { light: {anchor: 'viewport'} @@ -370,7 +370,7 @@ describe('diff', () => { }); test('set light color', () => { - expect(diffStyles({ + expect(diff({ light: {color: 'white'} } as StyleSpecification, { light: {color: 'red'} @@ -380,7 +380,7 @@ describe('diff', () => { }); test('set light position', () => { - expect(diffStyles({ + expect(diff({ light: {position: [0, 1, 0]} } as StyleSpecification, { light: {position: [1, 0, 0]} @@ -390,7 +390,7 @@ describe('diff', () => { }); test('set light intensity', () => { - expect(diffStyles({ + expect(diff({ light: {intensity: 1} } as StyleSpecification, { light: {intensity: 10} @@ -400,7 +400,7 @@ describe('diff', () => { }); test('set light anchor and color', () => { - expect(diffStyles({ + expect(diff({ light: { anchor: 'map', color: 'orange', @@ -425,7 +425,7 @@ describe('diff', () => { }); test('add and remove layer on source change', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a', source: 'source-one'}] } as StyleSpecification, { layers: [{id: 'a', source: 'source-two'}] @@ -436,7 +436,7 @@ describe('diff', () => { }); test('add and remove layer on type change', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a', type: 'fill'}] } as StyleSpecification, { layers: [{id: 'a', type: 'line'}] @@ -447,7 +447,7 @@ describe('diff', () => { }); test('add and remove layer on source-layer change', () => { - expect(diffStyles({ + expect(diff({ layers: [{id: 'a', source: 'a', 'source-layer': 'layer-one'}] } as StyleSpecification, { layers: [{id: 'a', source: 'a', 'source-layer': 'layer-two'}] @@ -458,7 +458,7 @@ describe('diff', () => { }); test('add and remove layers on different order and type', () => { - expect(diffStyles({ + expect(diff({ layers: [ {id: 'b'}, {id: 'c'}, @@ -479,7 +479,7 @@ describe('diff', () => { }); test('add and remove layer and source on source data change', () => { - expect(diffStyles({ + expect(diff({ sources: {foo: {data: 1}, bar: {}}, layers: [ {id: 'a', source: 'bar'}, @@ -502,7 +502,7 @@ describe('diff', () => { }); test('set transition', () => { - expect(diffStyles({ + expect(diff({ sources: {foo: {data: 1}, bar: {}}, layers: [ {id: 'a', source: 'bar'} @@ -519,7 +519,7 @@ describe('diff', () => { }); test('no sprite change', () => { - expect(diffStyles({ + expect(diff({ sprite: 'a' } as StyleSpecification, { sprite: 'a' @@ -527,7 +527,7 @@ describe('diff', () => { }); test('set sprite', () => { - expect(diffStyles({ + expect(diff({ sprite: 'a' } as StyleSpecification, { sprite: 'b' @@ -537,7 +537,7 @@ describe('diff', () => { }); test('set sprite for multiple sprites', () => { - expect(diffStyles({ + expect(diff({ sprite: 'a' } as StyleSpecification, { sprite: [{'id': 'default', 'url': 'b'}] @@ -547,7 +547,7 @@ describe('diff', () => { }); test('no glyphs change', () => { - expect(diffStyles({ + expect(diff({ glyphs: 'a' } as StyleSpecification, { glyphs: 'a' @@ -555,7 +555,7 @@ describe('diff', () => { }); test('set glyphs', () => { - expect(diffStyles({ + expect(diff({ glyphs: 'a' } as StyleSpecification, { glyphs: 'b' @@ -565,7 +565,7 @@ describe('diff', () => { }); test('remove terrain', () => { - expect(diffStyles({ + expect(diff({ terrain: { source: 'maplibre-dem', exaggeration: 1.5 @@ -577,7 +577,7 @@ describe('diff', () => { }); test('add terrain', () => { - expect(diffStyles({ + expect(diff({ } as StyleSpecification, { terrain: { @@ -590,7 +590,7 @@ describe('diff', () => { }); test('set sky', () => { - expect(diffStyles({ + expect(diff({ } as StyleSpecification, { sky: { @@ -603,7 +603,7 @@ describe('diff', () => { }); test('set projection', () => { - expect(diffStyles({ + expect(diff({ } as StyleSpecification, { projection: { diff --git a/src/diff.ts b/src/diff.ts index 9e2bff9d8..8a96b7d96 100644 --- a/src/diff.ts +++ b/src/diff.ts @@ -267,7 +267,7 @@ function diffLayers(before: LayerSpecification[], after: LayerSpecification[], c * @param {*} after stylesheet to compare to * @returns Array list of changes */ -export function diffStyles(before: StyleSpecification, after: StyleSpecification): DiffCommand[] { +export function diff(before: StyleSpecification, after: StyleSpecification): DiffCommand[] { if (!before) return [{command: 'setStyle', args: [after]}]; let commands: DiffCommand[] = []; diff --git a/src/empty.ts b/src/empty.ts index 3e04844bf..6ef0c8022 100644 --- a/src/empty.ts +++ b/src/empty.ts @@ -1,12 +1,12 @@ -import {spec} from './reference/latest'; +import {latest} from './reference/latest'; import {StyleSpecification} from './types.g'; export function emptyStyle(): StyleSpecification { const style = {}; - const version = spec['$version']; - for (const styleKey in spec['$root']) { - const specification = spec['$root'][styleKey]; + const version = latest['$version']; + for (const styleKey in latest['$root']) { + const specification = latest['$root'][styleKey]; if (specification.required) { let value = null; diff --git a/src/feature_filter/feature_filter.test.ts b/src/feature_filter/feature_filter.test.ts index 3bed825fb..743b16fce 100644 --- a/src/feature_filter/feature_filter.test.ts +++ b/src/feature_filter/feature_filter.test.ts @@ -1,4 +1,4 @@ -import {createFilter, isExpressionFilter} from '.'; +import {featureFilter, isExpressionFilter} from '.'; import {convertFilter} from './convert'; import {ICanonicalTileID} from '../tiles_and_coordinates'; @@ -83,7 +83,7 @@ describe('filter', () => { }); test('expression, zoom', () => { - const f = createFilter(['>=', ['number', ['get', 'x']], ['zoom']]).filter; + const f = featureFilter(['>=', ['number', ['get', 'x']], ['zoom']]).filter; expect(f({zoom: 1}, {properties: {x: 0}} as any as Feature)).toBe(false); expect(f({zoom: 1}, {properties: {x: 1.5}} as any as Feature)).toBe(true); expect(f({zoom: 1}, {properties: {x: 2.5}} as any as Feature)).toBe(true); @@ -94,7 +94,7 @@ describe('filter', () => { test('expression, compare two properties', () => { jest.spyOn(console, 'warn').mockImplementation(() => { }); - const f = createFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']]]).filter; + const f = featureFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']]]).filter; expect(f({zoom: 0}, {properties: {x: 1, y: 1}} as any as Feature)).toBe(false); expect(f({zoom: 0}, {properties: {x: '1', y: '1'}} as any as Feature)).toBe(true); expect(f({zoom: 0}, {properties: {x: 'same', y: 'same'}} as any as Feature)).toBe(true); @@ -103,35 +103,35 @@ describe('filter', () => { }); test('expression, collator comparison', () => { - const caseSensitive = createFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']], ['collator', {'case-sensitive': true}]]).filter; + const caseSensitive = featureFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']], ['collator', {'case-sensitive': true}]]).filter; expect(caseSensitive({zoom: 0}, {properties: {x: 'a', y: 'b'}} as any as Feature)).toBe(false); expect(caseSensitive({zoom: 0}, {properties: {x: 'a', y: 'A'}} as any as Feature)).toBe(false); expect(caseSensitive({zoom: 0}, {properties: {x: 'a', y: 'a'}} as any as Feature)).toBe(true); - const caseInsensitive = createFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']], ['collator', {'case-sensitive': false}]]).filter; + const caseInsensitive = featureFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']], ['collator', {'case-sensitive': false}]]).filter; expect(caseInsensitive({zoom: 0}, {properties: {x: 'a', y: 'b'}} as any as Feature)).toBe(false); expect(caseInsensitive({zoom: 0}, {properties: {x: 'a', y: 'A'}} as any as Feature)).toBe(true); expect(caseInsensitive({zoom: 0}, {properties: {x: 'a', y: 'a'}} as any as Feature)).toBe(true); }); test('expression, any/all', () => { - expect(createFilter(['all']).filter(undefined, undefined)).toBe(true); - expect(createFilter(['all', true]).filter(undefined, undefined)).toBe(true); - expect(createFilter(['all', true, false]).filter(undefined, undefined)).toBe(false); - expect(createFilter(['all', true, true]).filter(undefined, undefined)).toBe(true); - expect(createFilter(['any']).filter(undefined, undefined)).toBe(false); - expect(createFilter(['any', true]).filter(undefined, undefined)).toBe(true); - expect(createFilter(['any', true, false]).filter(undefined, undefined)).toBe(true); - expect(createFilter(['any', false, false]).filter(undefined, undefined)).toBe(false); + expect(featureFilter(['all']).filter(undefined, undefined)).toBe(true); + expect(featureFilter(['all', true]).filter(undefined, undefined)).toBe(true); + expect(featureFilter(['all', true, false]).filter(undefined, undefined)).toBe(false); + expect(featureFilter(['all', true, true]).filter(undefined, undefined)).toBe(true); + expect(featureFilter(['any']).filter(undefined, undefined)).toBe(false); + expect(featureFilter(['any', true]).filter(undefined, undefined)).toBe(true); + expect(featureFilter(['any', true, false]).filter(undefined, undefined)).toBe(true); + expect(featureFilter(['any', false, false]).filter(undefined, undefined)).toBe(false); }); test('expression, literal', () => { - expect(createFilter(['literal', true]).filter(undefined, undefined)).toBe(true); - expect(createFilter(['literal', false]).filter(undefined, undefined)).toBe(false); + expect(featureFilter(['literal', true]).filter(undefined, undefined)).toBe(true); + expect(featureFilter(['literal', false]).filter(undefined, undefined)).toBe(false); }); test('expression, match', () => { - const match = createFilter(['match', ['get', 'x'], ['a', 'b', 'c'], true, false]).filter; + const match = featureFilter(['match', ['get', 'x'], ['a', 'b', 'c'], true, false]).filter; expect(match(undefined, {properties: {x: 'a'}} as any as Feature)).toBe(true); expect(match(undefined, {properties: {x: 'c'}} as any as Feature)).toBe(true); expect(match(undefined, {properties: {x: 'd'}} as any as Feature)).toBe(false); @@ -139,21 +139,21 @@ describe('filter', () => { test('expression, type error', () => { expect(() => { - createFilter(['==', ['number', ['get', 'x']], ['string', ['get', 'y']]]); + featureFilter(['==', ['number', ['get', 'x']], ['string', ['get', 'y']]]); }).toThrow(); expect(() => { - createFilter(['number', ['get', 'x']]); + featureFilter(['number', ['get', 'x']]); }).toThrow(); expect(() => { - createFilter(['boolean', ['get', 'x']]); + featureFilter(['boolean', ['get', 'x']]); }).not.toThrow(); }); test('expression, within', () => { - const withinFilter = createFilter(['within', {'type': 'Polygon', 'coordinates': [[[0, 0], [5, 0], [5, 5], [0, 5], [0, 0]]]}]); + const withinFilter = featureFilter(['within', {'type': 'Polygon', 'coordinates': [[[0, 0], [5, 0], [5, 5], [0, 5], [0, 0]]]}]); expect(withinFilter.needGeometry).toBe(true); const canonical = {z: 3, x: 3, y: 3} as ICanonicalTileID; const featureInTile = {} as Feature; @@ -171,7 +171,7 @@ describe('filter', () => { expect(withinFilter.filter({zoom: 3}, featureInTile, canonical)).toBe(false); }); - legacyFilterTests(createFilter); + legacyFilterTests(featureFilter); }); @@ -208,7 +208,7 @@ describe('convert legacy filters to expressions', () => { legacyFilterTests(f => { const converted = convertFilter(f); - return createFilter(converted); + return featureFilter(converted); }); test('mimic legacy type mismatch semantics', () => { @@ -218,7 +218,7 @@ describe('convert legacy filters to expressions', () => { ] as FilterSpecification; const converted = convertFilter(filter); - const f = createFilter(converted).filter; + const f = featureFilter(converted).filter; expect(f({zoom: 0}, {properties: {x: 0, y: 1, z: 1}} as any as Feature)).toBe(true); expect(f({zoom: 0}, {properties: {x: 1, y: 0, z: 1}} as any as Feature)).toBe(true); diff --git a/src/feature_filter/index.ts b/src/feature_filter/index.ts index 41309bc44..2a652e148 100644 --- a/src/feature_filter/index.ts +++ b/src/feature_filter/index.ts @@ -77,7 +77,7 @@ const filterSpec = { * @param {Array} filter MapLibre filter * @returns {Function} filter-evaluating function */ -export function createFilter(filter: any): FeatureFilter { +export function featureFilter(filter: any): FeatureFilter { if (filter === null || filter === undefined) { return {filter: () => true, needGeometry: false}; } diff --git a/src/format.ts b/src/format.ts index fc78ac9be..41dd03d5c 100644 --- a/src/format.ts +++ b/src/format.ts @@ -1,5 +1,5 @@ -import {spec} from './reference/latest'; +import {latest} from './reference/latest'; import stringifyPretty from 'json-stringify-pretty-compact'; function sortKeysBy(obj, reference) { @@ -39,10 +39,10 @@ function sortKeysBy(obj, reference) { * fs.writeFileSync('./dest.min.json', format(style, 0)); */ export function format(style, space = 2) { - style = sortKeysBy(style, spec.$root); + style = sortKeysBy(style, latest.$root); if (style.layers) { - style.layers = style.layers.map((layer) => sortKeysBy(layer, spec.layer)); + style.layers = style.layers.map((layer) => sortKeysBy(layer, latest.layer)); } return stringifyPretty(style, {indent: space}); diff --git a/src/index.ts b/src/index.ts index 4a49530aa..81e7fabe4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,12 @@ import v8Spec from './reference/v8.json' with {type: 'json'}; const v8 = v8Spec as any; -import {spec as latest} from './reference/latest'; +import {latest} from './reference/latest'; import {derefLayers} from './deref'; -import {diffStyles as diff} from './diff'; +import {diff} from './diff'; import {ValidationError} from './error/validation_error'; import {ParsingError} from './error/parsing_error'; import {FeatureState, StyleExpression, isExpression, isZoomExpression, createExpression, createPropertyExpression, normalizePropertyExpression, ZoomConstantExpression, ZoomDependentExpression, StylePropertyFunction, Feature, GlobalProperties, SourceExpression, CompositeExpression, StylePropertyExpression} from './expression'; -import {createFilter as featureFilter, isExpressionFilter} from './feature_filter'; +import {featureFilter, isExpressionFilter} from './feature_filter'; import {convertFilter} from './feature_filter/convert'; import {Color} from './expression/types/color'; diff --git a/src/reference/latest.ts b/src/reference/latest.ts index 450670975..e3b39df68 100644 --- a/src/reference/latest.ts +++ b/src/reference/latest.ts @@ -1,3 +1,3 @@ -import spec from './v8.json' with { type: 'json' }; -export {spec} +import latest from './v8.json' with { type: 'json' }; +export {latest} diff --git a/src/validate/validate_variable_anchor_offset_collection.test.ts b/src/validate/validate_variable_anchor_offset_collection.test.ts index 4cbb6c340..e34670d74 100644 --- a/src/validate/validate_variable_anchor_offset_collection.test.ts +++ b/src/validate/validate_variable_anchor_offset_collection.test.ts @@ -1,11 +1,11 @@ import {validate} from './validate'; import {validateVariableAnchorOffsetCollection} from './validate_variable_anchor_offset_collection'; -import {spec} from '../reference/latest'; +import {latest} from '../reference/latest'; describe('Validate variableAnchorOffsetCollection', () => { const validateOpts = { validateSpec: validate, - styleSpec: spec, + styleSpec: latest, key: 'myProp', }; test('Should return error if type is not array', () => { diff --git a/src/validate_style.min.ts b/src/validate_style.min.ts index 56e4cc53f..a8a028d15 100644 --- a/src/validate_style.min.ts +++ b/src/validate_style.min.ts @@ -1,7 +1,7 @@ import {validateConstants} from './validate/validate_constants'; import {validate} from './validate/validate'; -import {spec} from './reference/latest'; +import {latest} from './reference/latest'; import {validateSource} from './validate/validate_source'; import {validateLight} from './validate/validate_light'; @@ -28,7 +28,7 @@ import type {StyleSpecification} from './types.g'; * const validate = require('@maplibre/maplibre-gl-style-spec/').validateStyleMin; * const errors = validate(style); */ -export function validateStyleMin(style: StyleSpecification, styleSpec = spec): Array { +export function validateStyleMin(style: StyleSpecification, styleSpec = latest): Array { let errors: ValidationError[] = []; From d4e4ba1f7c6585ebbf341eb351025ae666b6dd07 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 20:18:18 +0100 Subject: [PATCH 15/19] fix test --- test/integration/style-spec/validate_spec.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/style-spec/validate_spec.test.ts b/test/integration/style-spec/validate_spec.test.ts index 52115714b..2e262316b 100644 --- a/test/integration/style-spec/validate_spec.test.ts +++ b/test/integration/style-spec/validate_spec.test.ts @@ -2,7 +2,7 @@ import {globSync} from 'glob'; import fs from 'fs'; import path from 'path'; import {validateStyle as validate} from '../../../src/validate_style'; -import {spec as reference} from '../../../src/reference/latest'; +import {latest} from '../../../src/reference/latest'; const UPDATE = !!process.env.UPDATE; @@ -21,7 +21,7 @@ describe('validate_spec', () => { test('errors from validate do not contain line numbers', () => { const style = JSON.parse(fs.readFileSync('test/integration/style-spec/tests/bad-color.input.json', 'utf8')); - const result = validate(style, reference); + const result = validate(style, latest); expect(result[0].line).toBeUndefined(); }); }); @@ -92,5 +92,5 @@ describe('Validate sdk-support in spec', () => { }); } - checkRoot(reference, []); + checkRoot(latest, []); }); From e86c10390449021ca60f3a74ddb44d457e078852 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 20:24:31 +0100 Subject: [PATCH 16/19] fix test --- test/build/style-spec.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/build/style-spec.test.ts b/test/build/style-spec.test.ts index edafe073f..0731d37bc 100644 --- a/test/build/style-spec.test.ts +++ b/test/build/style-spec.test.ts @@ -1,5 +1,5 @@ import {readdir} from 'fs/promises'; -import {spec as reference} from '../../src/reference/latest'; +import {latest} from '../../src/reference/latest'; import fs from 'fs'; const minBundle = fs.readFileSync('dist/index.mjs', 'utf8'); @@ -34,7 +34,7 @@ describe('@maplibre/maplibre-gl-style-spec npm package', () => { }); test('trims reference.json fields', () => { - expect(reference.$root.version.doc).toBeTruthy(); - expect(minBundle.includes(reference.$root.version.doc)).toBeFalsy(); + expect(latest.$root.version.doc).toBeTruthy(); + expect(minBundle.includes(latest.$root.version.doc)).toBeFalsy(); }); }); From 3a8af204656a6658dbe2b792a27b90dc384a960d Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 20:26:48 +0100 Subject: [PATCH 17/19] remove few import * from --- build/bump-version-changelog.js | 6 +++--- build/generate-style-spec.ts | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/build/bump-version-changelog.js b/build/bump-version-changelog.js index a63aabe71..df01835ac 100755 --- a/build/bump-version-changelog.js +++ b/build/bump-version-changelog.js @@ -7,10 +7,10 @@ * And adds on top a ## main with add stuff here. */ -import * as fs from 'fs'; +import {readFileSync, writeFileSync} from 'fs'; const changelogPath = 'CHANGELOG.md'; -let changelog = fs.readFileSync(changelogPath, 'utf8'); +let changelog = readFileSync(changelogPath, 'utf8'); changelog = changelog.replace('## main', `## ${process.argv[2]}`); changelog = changelog.replaceAll('- _...Add new stuff here..._\n', ''); changelog = `## main @@ -23,4 +23,4 @@ changelog = `## main ` + changelog; -fs.writeFileSync(changelogPath, changelog, 'utf8'); +writeFileSync(changelogPath, changelog, 'utf8'); diff --git a/build/generate-style-spec.ts b/build/generate-style-spec.ts index 5d22b4c4d..1f45a38d7 100644 --- a/build/generate-style-spec.ts +++ b/build/generate-style-spec.ts @@ -1,7 +1,6 @@ -import * as fs from 'fs'; -import * as properties from '../src/util/properties'; - +import {writeFileSync} from 'fs'; import spec from '../src/reference/v8.json' with {type: 'json'}; +import {supportsPropertyExpression, supportsZoomExpression} from '../src/util/properties'; function unionType(values) { if (Array.isArray(values)) { @@ -45,9 +44,9 @@ function propertyType(property) { } })(); - if (properties.supportsPropertyExpression(property)) { + if (supportsPropertyExpression(property)) { return `DataDrivenPropertyValueSpecification<${baseType}>`; - } else if (properties.supportsZoomExpression(property)) { + } else if (supportsZoomExpression(property)) { return `PropertyValueSpecification<${baseType}>`; } else if (property.expression) { return 'ExpressionSpecification'; @@ -116,7 +115,7 @@ function layerType(key) { const layerTypes = Object.keys(spec.layer.type.values); -fs.writeFileSync('src/types.g.ts', +writeFileSync('src/types.g.ts', `// Generated code; do not edit. Edit build/generate-style-spec.ts instead. /* eslint-disable */ From d76ff6f4a9ad6df5b6b4edb3af63cfb8174aab8c Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 20:27:47 +0100 Subject: [PATCH 18/19] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a16deef8..a9bfb0e46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## main ### ✨ Features and improvements +- Use named imports internally - no package entrypoints changed ([#904](https://github.com/maplibre/maplibre-style-spec/pull/904)) - _...Add new stuff here..._ ### 🐞 Bug fixes From 1b2dec0b7db8bb3bf1192312267d6884ac748b1a Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sat, 16 Nov 2024 20:29:13 +0100 Subject: [PATCH 19/19] remove * as --- build/release-notes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/release-notes.js b/build/release-notes.js index 6eb24b39e..89c1df6f4 100755 --- a/build/release-notes.js +++ b/build/release-notes.js @@ -1,10 +1,10 @@ #!/usr/bin/env node -import * as fs from 'fs'; +import {readFileSync} from 'fs'; import semver from 'semver'; const changelogPath = 'CHANGELOG.md'; -const changelog = fs.readFileSync(changelogPath, 'utf8'); +const changelog = readFileSync(changelogPath, 'utf8'); /* Parse the raw changelog text and split it into individual releases.