@parcel/transformer-css 2.8.4-nightly.0 → 2.9.0
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.
- package/lib/CSSTransformer.js +21 -75
- package/package.json +6 -6
- package/src/CSSTransformer.js +14 -3
package/lib/CSSTransformer.js
CHANGED
|
@@ -4,93 +4,65 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _path() {
|
|
9
8
|
const data = _interopRequireDefault(require("path"));
|
|
10
|
-
|
|
11
9
|
_path = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _sourceMap() {
|
|
19
15
|
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
20
|
-
|
|
21
16
|
_sourceMap = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _plugin() {
|
|
29
22
|
const data = require("@parcel/plugin");
|
|
30
|
-
|
|
31
23
|
_plugin = function () {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _lightningcss() {
|
|
39
29
|
const data = require("lightningcss");
|
|
40
|
-
|
|
41
30
|
_lightningcss = function () {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
function _utils() {
|
|
49
36
|
const data = require("@parcel/utils");
|
|
50
|
-
|
|
51
37
|
_utils = function () {
|
|
52
38
|
return data;
|
|
53
39
|
};
|
|
54
|
-
|
|
55
40
|
return data;
|
|
56
41
|
}
|
|
57
|
-
|
|
58
42
|
function _browserslist() {
|
|
59
43
|
const data = _interopRequireDefault(require("browserslist"));
|
|
60
|
-
|
|
61
44
|
_browserslist = function () {
|
|
62
45
|
return data;
|
|
63
46
|
};
|
|
64
|
-
|
|
65
47
|
return data;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
49
|
function _nullthrows() {
|
|
69
50
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
70
|
-
|
|
71
51
|
_nullthrows = function () {
|
|
72
52
|
return data;
|
|
73
53
|
};
|
|
74
|
-
|
|
75
54
|
return data;
|
|
76
55
|
}
|
|
77
|
-
|
|
78
56
|
function _diagnostic() {
|
|
79
57
|
const data = _interopRequireWildcard(require("@parcel/diagnostic"));
|
|
80
|
-
|
|
81
58
|
_diagnostic = function () {
|
|
82
59
|
return data;
|
|
83
60
|
};
|
|
84
|
-
|
|
85
61
|
return data;
|
|
86
62
|
}
|
|
87
|
-
|
|
88
63
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
89
|
-
|
|
90
64
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
91
|
-
|
|
92
65
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
93
|
-
|
|
94
66
|
var _default = new (_plugin().Transformer)({
|
|
95
67
|
async loadConfig({
|
|
96
68
|
config,
|
|
@@ -101,7 +73,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
101
73
|
});
|
|
102
74
|
return conf === null || conf === void 0 ? void 0 : conf.contents;
|
|
103
75
|
},
|
|
104
|
-
|
|
105
76
|
async transform({
|
|
106
77
|
asset,
|
|
107
78
|
config,
|
|
@@ -123,7 +94,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
123
94
|
let [code, originalMap] = await Promise.all([asset.getBuffer(), asset.getMap()]);
|
|
124
95
|
let targets = getTargets(asset.env.engines.browsers);
|
|
125
96
|
let res;
|
|
126
|
-
|
|
127
97
|
try {
|
|
128
98
|
if (asset.meta.type === 'attr') {
|
|
129
99
|
res = (0, _lightningcss().transformStyleAttribute)({
|
|
@@ -134,19 +104,15 @@ var _default = new (_plugin().Transformer)({
|
|
|
134
104
|
});
|
|
135
105
|
} else {
|
|
136
106
|
let cssModules = false;
|
|
137
|
-
|
|
138
107
|
if (asset.meta.type !== 'tag' && asset.meta.cssModulesCompiled == null) {
|
|
139
108
|
let cssModulesConfig = config === null || config === void 0 ? void 0 : config.cssModules;
|
|
140
|
-
|
|
141
109
|
if (asset.isSource && (typeof cssModulesConfig === 'boolean' || cssModulesConfig !== null && cssModulesConfig !== void 0 && cssModulesConfig.global) || /\.module\./.test(asset.filePath)) {
|
|
142
110
|
if (cssModulesConfig !== null && cssModulesConfig !== void 0 && cssModulesConfig.dashedIdents && !asset.isSource) {
|
|
143
111
|
cssModulesConfig.dashedIdents = false;
|
|
144
112
|
}
|
|
145
|
-
|
|
146
113
|
cssModules = cssModulesConfig !== null && cssModulesConfig !== void 0 ? cssModulesConfig : true;
|
|
147
114
|
}
|
|
148
115
|
}
|
|
149
|
-
|
|
150
116
|
res = (0, _lightningcss().transform)({
|
|
151
117
|
filename: _path().default.relative(options.projectRoot, asset.filePath),
|
|
152
118
|
code,
|
|
@@ -161,23 +127,19 @@ var _default = new (_plugin().Transformer)({
|
|
|
161
127
|
}
|
|
162
128
|
} catch (err) {
|
|
163
129
|
var _err$data;
|
|
164
|
-
|
|
165
130
|
err.filePath = asset.filePath;
|
|
166
131
|
let diagnostic = (0, _diagnostic().errorToDiagnostic)(err, {
|
|
167
132
|
origin: '@parcel/transformer-css'
|
|
168
133
|
});
|
|
169
|
-
|
|
170
134
|
if (((_err$data = err.data) === null || _err$data === void 0 ? void 0 : _err$data.type) === 'AmbiguousUrlInCustomProperty' && err.data.url) {
|
|
171
135
|
let p = '/' + (0, _utils().relativePath)(options.projectRoot, _path().default.resolve(_path().default.dirname(asset.filePath), err.data.url), false);
|
|
172
136
|
diagnostic[0].hints = [`Replace with: url(${p})`];
|
|
173
137
|
diagnostic[0].documentationURL = 'https://parceljs.org/languages/css/#url()';
|
|
174
138
|
}
|
|
175
|
-
|
|
176
139
|
throw new (_diagnostic().default)({
|
|
177
140
|
diagnostic
|
|
178
141
|
});
|
|
179
142
|
}
|
|
180
|
-
|
|
181
143
|
if (res.warnings) {
|
|
182
144
|
for (let warning of res.warnings) {
|
|
183
145
|
logger.warn({
|
|
@@ -187,40 +149,33 @@ var _default = new (_plugin().Transformer)({
|
|
|
187
149
|
codeHighlights: [{
|
|
188
150
|
start: {
|
|
189
151
|
line: warning.loc.line,
|
|
190
|
-
column: warning.loc.column
|
|
152
|
+
column: warning.loc.column + 1
|
|
191
153
|
},
|
|
192
154
|
end: {
|
|
193
155
|
line: warning.loc.line,
|
|
194
|
-
column: warning.loc.column
|
|
156
|
+
column: warning.loc.column + 1
|
|
195
157
|
}
|
|
196
158
|
}]
|
|
197
159
|
}]
|
|
198
160
|
});
|
|
199
161
|
}
|
|
200
162
|
}
|
|
201
|
-
|
|
202
163
|
asset.setBuffer(res.code);
|
|
203
|
-
|
|
204
164
|
if (res.map != null) {
|
|
205
165
|
let vlqMap = JSON.parse(res.map.toString());
|
|
206
166
|
let map = new (_sourceMap().default)(options.projectRoot);
|
|
207
167
|
map.addVLQMap(vlqMap);
|
|
208
|
-
|
|
209
168
|
if (originalMap) {
|
|
210
169
|
map.extends(originalMap);
|
|
211
170
|
}
|
|
212
|
-
|
|
213
171
|
asset.setMap(map);
|
|
214
172
|
}
|
|
215
|
-
|
|
216
173
|
if (res.dependencies) {
|
|
217
174
|
for (let dep of res.dependencies) {
|
|
218
|
-
let loc = dep.loc;
|
|
219
|
-
|
|
175
|
+
let loc = convertLoc(dep.loc);
|
|
220
176
|
if (originalMap) {
|
|
221
177
|
loc = (0, _utils().remapSourceLocation)(loc, originalMap);
|
|
222
178
|
}
|
|
223
|
-
|
|
224
179
|
if (dep.type === 'import' && !res.exports) {
|
|
225
180
|
asset.addDependency({
|
|
226
181
|
specifier: dep.url,
|
|
@@ -243,9 +198,7 @@ var _default = new (_plugin().Transformer)({
|
|
|
243
198
|
}
|
|
244
199
|
}
|
|
245
200
|
}
|
|
246
|
-
|
|
247
201
|
let assets = [asset];
|
|
248
|
-
|
|
249
202
|
if (res.exports != null) {
|
|
250
203
|
let exports = res.exports;
|
|
251
204
|
asset.symbols.ensure();
|
|
@@ -255,25 +208,19 @@ var _default = new (_plugin().Transformer)({
|
|
|
255
208
|
let c = 0;
|
|
256
209
|
let depjs = '';
|
|
257
210
|
let js = '';
|
|
258
|
-
|
|
259
211
|
for (let key in exports) {
|
|
260
212
|
locals.set(exports[key].name, key);
|
|
261
213
|
}
|
|
262
|
-
|
|
263
214
|
let seen = new Set();
|
|
264
|
-
|
|
265
215
|
let add = key => {
|
|
266
216
|
if (seen.has(key)) {
|
|
267
217
|
return;
|
|
268
218
|
}
|
|
269
|
-
|
|
270
219
|
seen.add(key);
|
|
271
220
|
let e = exports[key];
|
|
272
221
|
let s = `module.exports[${JSON.stringify(key)}] = \`${e.name}`;
|
|
273
|
-
|
|
274
222
|
for (let ref of e.composes) {
|
|
275
223
|
s += ' ';
|
|
276
|
-
|
|
277
224
|
if (ref.type === 'local') {
|
|
278
225
|
add((0, _nullthrows().default)(locals.get(ref.name)));
|
|
279
226
|
s += '${' + `module.exports[${JSON.stringify((0, _nullthrows().default)(locals.get(ref.name)))}]` + '}';
|
|
@@ -281,7 +228,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
281
228
|
s += ref.name;
|
|
282
229
|
} else if (ref.type === 'dependency') {
|
|
283
230
|
let d = dependencies.get(ref.specifier);
|
|
284
|
-
|
|
285
231
|
if (d == null) {
|
|
286
232
|
d = `dep_${c++}`;
|
|
287
233
|
depjs += `import * as ${d} from ${JSON.stringify(ref.specifier)};\n`;
|
|
@@ -292,28 +238,25 @@ var _default = new (_plugin().Transformer)({
|
|
|
292
238
|
packageConditions: ['style']
|
|
293
239
|
});
|
|
294
240
|
}
|
|
295
|
-
|
|
296
241
|
s += '${' + `${d}[${JSON.stringify(ref.name)}]` + '}';
|
|
297
242
|
}
|
|
298
243
|
}
|
|
244
|
+
s += '`;\n';
|
|
299
245
|
|
|
300
|
-
|
|
246
|
+
// If the export is referenced internally (e.g. used @keyframes), add a self-reference
|
|
301
247
|
// to the JS so the symbol is retained during tree-shaking.
|
|
302
|
-
|
|
303
248
|
if (e.isReferenced) {
|
|
304
249
|
s += `module.exports[${JSON.stringify(key)}];\n`;
|
|
305
250
|
}
|
|
306
|
-
|
|
307
251
|
js += s;
|
|
308
|
-
};
|
|
309
|
-
// Sorting by key is safe as the order is irrelevant but needs to be deterministic.
|
|
310
|
-
|
|
252
|
+
};
|
|
311
253
|
|
|
254
|
+
// It's possible that the exports can be ordered differently between builds.
|
|
255
|
+
// Sorting by key is safe as the order is irrelevant but needs to be deterministic.
|
|
312
256
|
for (let key of Object.keys(exports).sort()) {
|
|
313
257
|
asset.symbols.set(key, exports[key].name);
|
|
314
258
|
add(key);
|
|
315
259
|
}
|
|
316
|
-
|
|
317
260
|
if (res.dependencies) {
|
|
318
261
|
for (let dep of res.dependencies) {
|
|
319
262
|
if (dep.type === 'import') {
|
|
@@ -325,10 +268,8 @@ var _default = new (_plugin().Transformer)({
|
|
|
325
268
|
}
|
|
326
269
|
}
|
|
327
270
|
}
|
|
328
|
-
|
|
329
271
|
if (res.references != null) {
|
|
330
272
|
let references = res.references;
|
|
331
|
-
|
|
332
273
|
for (let symbol in references) {
|
|
333
274
|
let reference = references[symbol];
|
|
334
275
|
asset.addDependency({
|
|
@@ -344,7 +285,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
344
285
|
asset.meta.hasReferences = true;
|
|
345
286
|
}
|
|
346
287
|
}
|
|
347
|
-
|
|
348
288
|
assets.push({
|
|
349
289
|
type: 'js',
|
|
350
290
|
content: depjs + js,
|
|
@@ -352,27 +292,33 @@ var _default = new (_plugin().Transformer)({
|
|
|
352
292
|
env
|
|
353
293
|
});
|
|
354
294
|
}
|
|
355
|
-
|
|
356
295
|
return assets;
|
|
357
296
|
}
|
|
358
|
-
|
|
359
297
|
});
|
|
360
|
-
|
|
361
298
|
exports.default = _default;
|
|
362
299
|
let cache = new Map();
|
|
363
|
-
|
|
364
300
|
function getTargets(browsers) {
|
|
365
301
|
if (browsers == null) {
|
|
366
302
|
return undefined;
|
|
367
303
|
}
|
|
368
|
-
|
|
369
304
|
let cached = cache.get(browsers);
|
|
370
|
-
|
|
371
305
|
if (cached != null) {
|
|
372
306
|
return cached;
|
|
373
307
|
}
|
|
374
|
-
|
|
375
308
|
let targets = (0, _lightningcss().browserslistToTargets)((0, _browserslist().default)(browsers));
|
|
376
309
|
cache.set(browsers, targets);
|
|
377
310
|
return targets;
|
|
311
|
+
}
|
|
312
|
+
function convertLoc(loc) {
|
|
313
|
+
return {
|
|
314
|
+
filePath: loc.filePath,
|
|
315
|
+
start: {
|
|
316
|
+
line: loc.start.line,
|
|
317
|
+
column: loc.start.column
|
|
318
|
+
},
|
|
319
|
+
end: {
|
|
320
|
+
line: loc.end.line,
|
|
321
|
+
column: loc.end.column + 1
|
|
322
|
+
}
|
|
323
|
+
};
|
|
378
324
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-css",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"source": "src/CSSTransformer.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "2.
|
|
20
|
+
"parcel": "^2.9.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.
|
|
24
|
-
"@parcel/plugin": "2.
|
|
23
|
+
"@parcel/diagnostic": "2.9.0",
|
|
24
|
+
"@parcel/plugin": "2.9.0",
|
|
25
25
|
"@parcel/source-map": "^2.1.1",
|
|
26
|
-
"@parcel/utils": "2.
|
|
26
|
+
"@parcel/utils": "2.9.0",
|
|
27
27
|
"browserslist": "^4.6.6",
|
|
28
28
|
"lightningcss": "^1.16.1",
|
|
29
29
|
"nullthrows": "^1.1.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "dd9435be8afed35c5ffc161cf4b586fd6c78fc1f"
|
|
32
32
|
}
|
package/src/CSSTransformer.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
2
|
|
|
3
|
+
import type {SourceLocation} from '@parcel/types';
|
|
4
|
+
|
|
3
5
|
import path from 'path';
|
|
4
6
|
import SourceMap from '@parcel/source-map';
|
|
5
7
|
import {Transformer} from '@parcel/plugin';
|
|
@@ -7,6 +9,7 @@ import {
|
|
|
7
9
|
transform,
|
|
8
10
|
transformStyleAttribute,
|
|
9
11
|
browserslistToTargets,
|
|
12
|
+
type SourceLocation as LightningSourceLocation,
|
|
10
13
|
} from 'lightningcss';
|
|
11
14
|
import {remapSourceLocation, relativePath} from '@parcel/utils';
|
|
12
15
|
import browserslist from 'browserslist';
|
|
@@ -116,11 +119,11 @@ export default (new Transformer({
|
|
|
116
119
|
{
|
|
117
120
|
start: {
|
|
118
121
|
line: warning.loc.line,
|
|
119
|
-
column: warning.loc.column,
|
|
122
|
+
column: warning.loc.column + 1,
|
|
120
123
|
},
|
|
121
124
|
end: {
|
|
122
125
|
line: warning.loc.line,
|
|
123
|
-
column: warning.loc.column,
|
|
126
|
+
column: warning.loc.column + 1,
|
|
124
127
|
},
|
|
125
128
|
},
|
|
126
129
|
],
|
|
@@ -146,7 +149,7 @@ export default (new Transformer({
|
|
|
146
149
|
|
|
147
150
|
if (res.dependencies) {
|
|
148
151
|
for (let dep of res.dependencies) {
|
|
149
|
-
let loc = dep.loc;
|
|
152
|
+
let loc = convertLoc(dep.loc);
|
|
150
153
|
if (originalMap) {
|
|
151
154
|
loc = remapSourceLocation(loc, originalMap);
|
|
152
155
|
}
|
|
@@ -309,3 +312,11 @@ function getTargets(browsers) {
|
|
|
309
312
|
cache.set(browsers, targets);
|
|
310
313
|
return targets;
|
|
311
314
|
}
|
|
315
|
+
|
|
316
|
+
function convertLoc(loc: LightningSourceLocation): SourceLocation {
|
|
317
|
+
return {
|
|
318
|
+
filePath: loc.filePath,
|
|
319
|
+
start: {line: loc.start.line, column: loc.start.column},
|
|
320
|
+
end: {line: loc.end.line, column: loc.end.column + 1},
|
|
321
|
+
};
|
|
322
|
+
}
|