Skip to content

Commit

Permalink
Use named exports in style-spec.js (#6602)
Browse files Browse the repository at this point in the history
Fixes #6601
  • Loading branch information
anandthakker committed May 3, 2018
1 parent 4761e0b commit 535ba4a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"watch-dev": "rollup -c --environment BUILD:dev --watch",
"build-min": "rollup -c --environment BUILD:production",
"build-css": "postcss -o dist/mapbox-gl.css src/css/mapbox-gl.css",
"build-style-spec": "cd src/style-spec && npm run build && cd ../.. && cp -R src/style-spec/dist dist/style-spec",
"build-style-spec": "cd src/style-spec && npm run build && cd ../.. && mkdir -p dist/style-spec && cp src/style-spec/dist/* dist/style-spec",
"watch-css": "postcss --watch -o dist/mapbox-gl.css src/css/mapbox-gl.css",
"build-token": "node build/generate-access-token-script.js",
"build-benchmarks": "BENCHMARK_VERSION=${BENCHMARK_VERSION:-\"$(git rev-parse --abbrev-ref HEAD) $(git rev-parse --short=7 HEAD)\"} rollup -c bench/rollup_config_benchmarks.js",
Expand Down
41 changes: 21 additions & 20 deletions src/style-spec/style-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ export type StylePropertySpecification = {
};

import v8 from './reference/v8.json';
export {v8};

import latest from './reference/latest';
import format from './format';
import migrate from './migrate';
Expand All @@ -75,35 +73,38 @@ import convertFunction from './function/convert';

import validate from './validate_style';

const exported = {
const expression = {
StyleExpression,
isExpression,
createExpression,
createPropertyExpression,
normalizePropertyExpression,
ZoomConstantExpression,
ZoomDependentExpression,
StylePropertyFunction
};

const styleFunction = {
convertFunction,
createFunction,
isFunction
};

export {
v8,
latest,
format,
migrate,
composite,
diff,
ValidationError,
ParsingError,
expression: {
StyleExpression,
isExpression,
createExpression,
createPropertyExpression,
normalizePropertyExpression,
ZoomConstantExpression,
ZoomDependentExpression,
StylePropertyFunction
},
expression,
featureFilter,
Color,
function: {
convertFunction,
createFunction,
isFunction
},
styleFunction as function,
validate
};

export default exported;

validate.parsed = validate;
validate.latest = validate;
7 changes: 7 additions & 0 deletions test/build/style-spec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,12 @@ test('@mapbox/mapbox-gl-style-spec npm package', (t) => {
});
});

t.test('exports components directly, not behind `default` - https://github.com/mapbox/mapbox-gl-js/issues/6601', (t) => {
const spec = require('../../dist/style-spec/index.js');
t.ok(spec.validate);
t.notOk(spec.default && spec.default.validate);
t.end();
});

t.end();
});
4 changes: 3 additions & 1 deletion test/unit/style-spec/migrate.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { test as t } from 'mapbox-gl-js-test';
import fs from 'fs';
import glob from 'glob';
import spec from '../../../src/style-spec/style-spec';
import path from 'path';
import validate from '../../../src/style-spec/validate_style';
import v8 from '../../../src/style-spec/reference/v8';
import migrate from '../../../src/style-spec/migrate';

/* eslint-disable import/namespace */
import * as spec from '../../../src/style-spec/style-spec';

const UPDATE = !!process.env.UPDATE;

t('does not migrate from version 5', (t) => {
Expand Down
4 changes: 3 additions & 1 deletion test/unit/style-spec/spec.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { test } from 'mapbox-gl-js-test';
import spec from '../../../src/style-spec/style-spec';

/* eslint-disable import/namespace */
import * as spec from '../../../src/style-spec/style-spec';

['v8', 'latest'].forEach((version) => {
['', 'min'].forEach((kind) => {
Expand Down

0 comments on commit 535ba4a

Please sign in to comment.