Skip to content

Commit 4178639

Browse files
ylemkimonkevinbarabash
authored andcommitted
Upgrade to Babel 7 (KaTeX#1595)
* Upgrade to Babel 7 * Update dependencies * Remove `modules` and `useEsModules` as module support is automatically detected Target browsers supporting ESM in the ESM build. * Disable corejs aliasing (polyfill) * Fix package.json and update lockfile * Bump CircleCI cache version * Remove `Object.values()` use for Node 6 compatability * Remove redundant arguments to @babel/register * Update rollup and rollup-plugin-babel * Add ignore option to no-transform-runtime-aliasing Ignore JSON.stringify, parseInt, and ParseFloat * Upgrade babel-loader to 8.0.1 * Use api.env() in Babel configuration * Upgrade babel-loader to 8.0.2
1 parent 010dc88 commit 4178639

11 files changed

+1018
-600
lines changed

.babelrc

-37
This file was deleted.

.circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ post_checkout: &post_checkout
1818
fi
1919
2020
node_modules_cache_key: &node_modules_cache_key
21-
yarn-deps-v1-{{ checksum "yarn.lock" }}
21+
yarn-deps-v2-{{ checksum "yarn.lock" }}
2222

2323
restore_node_modules_cache: &restore_node_modules_cache
2424
restore_cache:
2525
keys:
2626
- *node_modules_cache_key
27-
- yarn-deps-v1-
27+
- yarn-deps-v2-
2828

2929
yarn_install: &yarn_install
3030
run:

.eslintrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@
8282
"excludedFiles": ["*-spec.js", "unicodeMake.js"],
8383
"rules": {
8484
"no-restricted-syntax": [2, "ForOfStatement", "ClassDeclaration[superClass]", "ClassExpression[superClass]"],
85-
"transform-runtime-aliasing/no-transform-runtime-aliasing": 2
85+
"transform-runtime-aliasing/no-transform-runtime-aliasing": [2, {
86+
"transformEnabled": false,
87+
"ignore": ["parseInt", "parseFloat", "JSON.stringify"]
88+
}]
8689
},
8790
"env": {
8891
"node": false

babel.config.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = api => {
2+
const isESMBuild = api.env("esm");
3+
4+
const presets = [
5+
["@babel/env", {
6+
targets: {
7+
esmodules: isESMBuild,
8+
},
9+
loose: true,
10+
}],
11+
"@babel/flow",
12+
];
13+
const plugins = [
14+
"@babel/transform-runtime",
15+
["@babel/proposal-class-properties", {
16+
loose: true,
17+
}],
18+
"version-inline",
19+
];
20+
21+
return {
22+
presets,
23+
plugins,
24+
};
25+
};

package.json

+16-14
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,35 @@
1616
],
1717
"license": "MIT",
1818
"devDependencies": {
19-
"babel-core": "^6.26.3",
20-
"babel-eslint": "^8.1.2",
19+
"@babel/core": "^7.0.0",
20+
"@babel/plugin-proposal-class-properties": "^7.0.0",
21+
"@babel/plugin-transform-runtime": "^7.0.0",
22+
"@babel/preset-env": "^7.0.0",
23+
"@babel/preset-flow": "^7.0.0",
24+
"@babel/register": "^7.0.0",
25+
"@babel/runtime": "^7.0.0",
26+
"babel-core": "^7.0.0-bridge.0",
27+
"babel-eslint": "^9.0.0",
2128
"babel-jest": "^23.0.1",
22-
"babel-loader": "^7.1.4",
23-
"babel-plugin-istanbul": "^4.1.6",
24-
"babel-plugin-transform-class-properties": "^6.23.0",
25-
"babel-plugin-transform-runtime": "^6.15.0",
29+
"babel-loader": "^8.0.2",
30+
"babel-plugin-istanbul": "^5.0.1",
2631
"babel-plugin-version-inline": "^1.0.0",
27-
"babel-preset-es2015": "^6.18.0",
28-
"babel-preset-flow": "^6.23.0",
29-
"babel-register": "^6.26.0",
3032
"benchmark": "^2.1.4",
3133
"codecov": "^3.0.4",
3234
"css-loader": "^1.0.0",
3335
"cssnano": "^4.0.1",
3436
"eslint": "^5.0.0",
3537
"eslint-plugin-flowtype": "^2.40.1",
3638
"eslint-plugin-react": "^7.10.0",
37-
"eslint-plugin-transform-runtime-aliasing": "^1.0.0",
39+
"eslint-plugin-transform-runtime-aliasing": "^1.2.0",
3840
"file-loader": "^1.1.11",
3941
"flow-bin": "^0.80.0",
4042
"fs-extra": "^7.0.0",
4143
"greenkeeper-lockfile": "^1.15.1",
4244
"husky": "^1.0.0-rc.8",
43-
"istanbul-api": "^1.3.1",
44-
"istanbul-lib-coverage": "^1.2.0",
45-
"jest": "^23.0.1",
45+
"istanbul-api": "^2.0.5",
46+
"istanbul-lib-coverage": "^2.0.1",
47+
"jest": "^23.5.0",
4648
"jest-serializer-html": "^5.0.0",
4749
"js-yaml": "^3.10.0",
4850
"json-stable-stringify": "^1.0.1",
@@ -56,7 +58,7 @@
5658
"query-string": "^5.1.1",
5759
"rimraf": "^2.6.2",
5860
"rollup": "^0.65.0",
59-
"rollup-plugin-babel": "^3.0.7",
61+
"rollup-plugin-babel": "^4.0.2",
6062
"selenium-webdriver": "^3.6.0",
6163
"sri-toolbox": "^0.2.0",
6264
"style-loader": "^0.22.0",

rollup.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import babel from 'rollup-plugin-babel';
22

3-
process.env.BABEL_ENV = 'esm';
3+
process.env.NODE_ENV = 'esm';
44

55
export default {
66
input: 'katex.js',
@@ -9,6 +9,6 @@ export default {
99
format: 'es',
1010
},
1111
plugins: [
12-
babel(),
12+
babel({runtimeHelpers: true}),
1313
],
1414
};

src/functions/delimsizing.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ function checkDelimiter(
6464
} else {
6565
throw new ParseError(
6666
"Invalid delimiter: '" +
67-
// $FlowFixMe, do not polyfill
68-
(symDelim ? symDelim.text : JSON["stringify"](delim)) +
67+
(symDelim ? symDelim.text : JSON.stringify(delim)) +
6968
"' after '" + context.funcName + "'", delim);
7069
}
7170
}

src/unicodeMake.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (fs.statSync(__filename).mtime <= targetMtime && fs.statSync(
1414
return;
1515
}
1616

17-
require('babel-register')({plugins: ["transform-es2015-modules-commonjs"]});
17+
require('@babel/register');
1818
const accents = require('./unicodeAccents').default;
1919

2020
const encode = function(string) {

test/perf-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* - allow users to specify a different string or strings
1111
* - provide a way to test the performance against different branches
1212
*/
13-
require('babel-register');
1413
const Benchmark = require('benchmark');
1514
const yaml = require('js-yaml');
1615
const fs = require('fs');
@@ -20,6 +19,7 @@ const filename = path.resolve(__dirname, 'screenshotter/ss_data.yaml');
2019
const data = yaml.load(fs.readFileSync(filename, 'utf-8'));
2120

2221
console.log('compiling katex...');
22+
require('@babel/register');
2323
const katex = require('../katex').default;
2424
console.log('');
2525

test/unicode-spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe("unicodeScripts", () => {
110110
const scriptNames = Object.keys(scriptRegExps);
111111

112112
const allRegExp = new RegExp(
113-
Object.values(scriptRegExps).map(re => re.source).join('|')
113+
scriptNames.map(script => scriptRegExps[script].source).join('|')
114114
);
115115

116116
it("supportedCodepoint() should return the correct values", () => {

0 commit comments

Comments
 (0)