Skip to content

Commit 9dabcec

Browse files
chore: use babel for client code (#934)
1 parent 0c8a23b commit 9dabcec

File tree

5 files changed

+202
-117
lines changed

5 files changed

+202
-117
lines changed

.eslintignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/node_modules
2-
/src/runtime
1+
/coverage
32
/dist
3+
/node_modules

babel.config.js

+15
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,20 @@ module.exports = (api) => {
1515
},
1616
],
1717
],
18+
overrides: [
19+
{
20+
test: './src/runtime',
21+
presets: [
22+
[
23+
'@babel/preset-env',
24+
{
25+
targets: {
26+
node: '0.12',
27+
},
28+
},
29+
],
30+
],
31+
},
32+
],
1833
};
1934
};

src/runtime/api.js

+35-22
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,45 @@
33
Author Tobias Koppers @sokra
44
*/
55
// css base code, injected by the css-loader
6+
// eslint-disable-next-line func-names
67
module.exports = function(useSourceMap) {
7-
var list = [];
8+
const list = [];
89

910
// return the list of modules as css string
1011
list.toString = function toString() {
11-
return this.map(function(item) {
12-
var content = cssWithMappingToString(item, useSourceMap);
12+
return this.map((item) => {
13+
const content = cssWithMappingToString(item, useSourceMap);
14+
1315
if (item[2]) {
14-
return '@media ' + item[2] + '{' + content + '}';
15-
} else {
16-
return content;
16+
return `@media ${item[2]}{${content}}`;
1717
}
18+
19+
return content;
1820
}).join('');
1921
};
2022

2123
// import a list of modules into the list
24+
// eslint-disable-next-line func-names
2225
list.i = function(modules, mediaQuery) {
2326
if (typeof modules === 'string') {
27+
// eslint-disable-next-line no-param-reassign
2428
modules = [[null, modules, '']];
2529
}
26-
var alreadyImportedModules = {};
27-
for (var i = 0; i < this.length; i++) {
28-
var id = this[i][0];
30+
31+
const alreadyImportedModules = {};
32+
33+
for (let i = 0; i < this.length; i++) {
34+
// eslint-disable-next-line prefer-destructuring
35+
const id = this[i][0];
36+
2937
if (id != null) {
3038
alreadyImportedModules[id] = true;
3139
}
3240
}
33-
for (i = 0; i < modules.length; i++) {
34-
var item = modules[i];
41+
42+
for (let i = 0; i < modules.length; i++) {
43+
const item = modules[i];
44+
3545
// skip already imported module
3646
// this implementation is not 100% perfect for weird media query combinations
3747
// when a module is imported multiple times with different media queries.
@@ -40,27 +50,31 @@ module.exports = function(useSourceMap) {
4050
if (mediaQuery && !item[2]) {
4151
item[2] = mediaQuery;
4252
} else if (mediaQuery) {
43-
item[2] = '(' + item[2] + ') and (' + mediaQuery + ')';
53+
item[2] = `(${item[2]}) and (${mediaQuery})`;
4454
}
55+
4556
list.push(item);
4657
}
4758
}
4859
};
60+
4961
return list;
5062
};
5163

5264
function cssWithMappingToString(item, useSourceMap) {
53-
var content = item[1] || '';
54-
var cssMapping = item[3];
65+
const content = item[1] || '';
66+
// eslint-disable-next-line prefer-destructuring
67+
const cssMapping = item[3];
68+
5569
if (!cssMapping) {
5670
return content;
5771
}
5872

5973
if (useSourceMap && typeof btoa === 'function') {
60-
var sourceMapping = toComment(cssMapping);
61-
var sourceURLs = cssMapping.sources.map(function(source) {
62-
return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */';
63-
});
74+
const sourceMapping = toComment(cssMapping);
75+
const sourceURLs = cssMapping.sources.map(
76+
(source) => `/*# sourceURL=${cssMapping.sourceRoot}${source} */`
77+
);
6478

6579
return [content]
6680
.concat(sourceURLs)
@@ -74,9 +88,8 @@ function cssWithMappingToString(item, useSourceMap) {
7488
// Adapted from convert-source-map (MIT)
7589
function toComment(sourceMap) {
7690
// eslint-disable-next-line no-undef
77-
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
78-
var data =
79-
'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
91+
const base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
92+
const data = `sourceMappingURL=data:application/json;charset=utf-8;base64,${base64}`;
8093

81-
return '/*# ' + data + ' */';
94+
return `/*# ${data} */`;
8295
}

src/runtime/url-escape.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ module.exports = function escape(url, needQuotes) {
55

66
// If url is already wrapped in quotes, remove them
77
if (/^['"].*['"]$/.test(url)) {
8+
// eslint-disable-next-line no-param-reassign
89
url = url.slice(1, -1);
910
}
1011

1112
// Should url be wrapped?
1213
// See https://drafts.csswg.org/css-values-3/#urls
1314
if (/["'() \t\n]/.test(url) || needQuotes) {
14-
return '"' + url.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"';
15+
return `"${url.replace(/"/g, '\\"').replace(/\n/g, '\\n')}"`;
1516
}
1617

1718
return url;

0 commit comments

Comments
 (0)