@mapbox/mapbox-gl-style-spec 14.26.0 → 14.27.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,13 +61,13 @@ export default class NumberFormat implements Expression {
61
61
  }
62
62
 
63
63
  let minFractionDigits = null;
64
- if (options['min-fraction-digits']) {
64
+ if (options['min-fraction-digits'] !== undefined) {
65
65
  minFractionDigits = context.parseObjectValue(options['min-fraction-digits'], 2, 'min-fraction-digits', NumberType);
66
66
  if (!minFractionDigits) return null;
67
67
  }
68
68
 
69
69
  let maxFractionDigits = null;
70
- if (options['max-fraction-digits']) {
70
+ if (options['max-fraction-digits'] !== undefined) {
71
71
  maxFractionDigits = context.parseObjectValue(options['max-fraction-digits'], 2, 'max-fraction-digits', NumberType);
72
72
  if (!maxFractionDigits) return null;
73
73
  }
@@ -164,7 +164,7 @@ export class StyleExpression {
164
164
 
165
165
  export function isExpression(expression: unknown): boolean {
166
166
  return Array.isArray(expression) && expression.length > 0 &&
167
- typeof expression[0] === 'string' && expression[0] in definitions;
167
+ typeof expression[0] === 'string' && Object.hasOwn(definitions, expression[0]);
168
168
  }
169
169
 
170
170
  /**
@@ -144,7 +144,7 @@ class ParsingContext {
144
144
  return this.error(`Expected an array with at least one element. If you wanted a literal array, use ["literal", []].`);
145
145
  }
146
146
 
147
- const Expr = typeof expr[0] === 'string' ? this.registry[expr[0]] : undefined;
147
+ const Expr = typeof expr[0] === 'string' && Object.hasOwn(this.registry, expr[0]) ? this.registry[expr[0]] : undefined;
148
148
  if (Expr) {
149
149
  let parsed = Expr.parse(expr, this);
150
150
  if (!parsed) return null;
@@ -6,12 +6,10 @@ import type {Expression} from './expression';
6
6
  */
7
7
  class Scope {
8
8
  parent: Scope | null | undefined;
9
- bindings: {
10
- [_: string]: Expression;
11
- };
9
+ bindings: Record<string, Expression>;
12
10
  constructor(parent?: Scope, bindings: Array<[string, Expression]> = []) {
13
11
  this.parent = parent;
14
- this.bindings = {};
12
+ this.bindings = Object.create(null) as Record<string, Expression>;
15
13
  for (const [name, expression] of bindings) {
16
14
  this.bindings[name] = expression;
17
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapbox/mapbox-gl-style-spec",
3
- "version": "14.26.0",
3
+ "version": "14.27.0-rc.1",
4
4
  "description": "a specification for mapbox gl styles",
5
5
  "author": "Mapbox",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -32,7 +32,7 @@
32
32
  "pretest": "npm run build",
33
33
  "test": "node ./test.js",
34
34
  "build": "npm run build-spec && npm run build-dts",
35
- "build-dts": "dts-bundle-generator --no-banner --export-referenced-types=false --project ../../tsconfig.browser.json -o ./dist/index.d.ts ./style-spec.ts",
35
+ "build-dts": "rollup -c rollup.config.dts.ts",
36
36
  "build-spec": "rollup -c && rollup -c --environment esm",
37
37
  "prepublishOnly": "npm run build",
38
38
  "postpublish": "rm dist/index.cjs dist/index.d.ts"
@@ -0,0 +1,17 @@
1
+ import {dts} from 'rollup-plugin-dts';
2
+
3
+ import type {RollupOptions} from 'rollup';
4
+
5
+ // Bundles the style-spec type declarations into a single `dist/index.d.ts`.
6
+ // Unlike the main library, style-spec has real runtime `dependencies`, so their
7
+ // types stay external `import`s (consumers install them) rather than being inlined.
8
+ export default (): RollupOptions => ({
9
+ input: './style-spec.ts',
10
+ output: {
11
+ file: './dist/index.d.ts',
12
+ format: 'es',
13
+ },
14
+ plugins: [
15
+ dts({tsconfig: '../../tsconfig.browser.json'}),
16
+ ],
17
+ });
@@ -43,11 +43,11 @@ export default function validateImport(options: ImportValidatorOptions): Validat
43
43
  errors.push(new ValidationError(key, importSpec, `import id can't be an empty string`));
44
44
  }
45
45
 
46
- // Reject reserved prototype-pollution key — the import id is used as a scope
47
- // string that becomes a dictionary key in several runtime caches.
48
- if (unbundle(importSpec.id) === '__proto__') {
46
+ // Reject reserved prototype-pollution keys
47
+ const importId = unbundle(importSpec.id);
48
+ if (importId === '__proto__' || importId === 'constructor' || importId === 'prototype') {
49
49
  const key = `${options.key}.id`;
50
- errors.push(new ValidationError(key, importSpec, `import id can't be "__proto__"`));
50
+ errors.push(new ValidationError(key, importSpec, `import id can't be "${String(importId)}"`));
51
51
  }
52
52
 
53
53
  if (data) {