Skip to content

Commit 842454a

Browse files
committedMay 2, 2019
fix: Handle legacy type definition for sourcemap's RawSourceMap.
1 parent 8427925 commit 842454a

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed
 

‎packages/@css-blocks/core/src/BlockParser/BlockFactory.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ObjectDictionary, isString } from "@opticss/util";
22
import * as debugGenerator from "debug";
3-
import { postcss } from "opticss";
3+
import { LegacyRawSourceMap, adaptFromLegacySourceMap, postcss } from "opticss";
44
import * as path from "path";
55
import { RawSourceMap } from "source-map";
66

@@ -262,9 +262,13 @@ export class BlockFactory {
262262
}
263263

264264
function sourceMapFromProcessedFile(result: ProcessedFile): RawSourceMap | string | undefined {
265-
let sourceMap: RawSourceMap | string | undefined = result.sourceMap;
265+
let sourceMap: LegacyRawSourceMap | RawSourceMap | string | undefined = result.sourceMap;
266266
if (!sourceMap && !isString(result.content) && result.content.map) {
267267
sourceMap = result.content.map.toJSON();
268268
}
269-
return sourceMap;
269+
if (typeof sourceMap === "object") {
270+
return adaptFromLegacySourceMap(sourceMap);
271+
} else {
272+
return sourceMap;
273+
}
270274
}

‎packages/@css-blocks/webpack/src/CssAssets.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as async from "async";
33
import * as convertSourceMap from "convert-source-map";
44
import * as debugGenerator from "debug";
55
import * as fs from "fs";
6-
import { postcss } from "opticss";
6+
import { adaptFromLegacySourceMap, adaptToLegacySourceMap, postcss } from "opticss";
77
import * as path from "path";
88
import { RawSourceMap } from "source-map";
99
import { Compiler as WebpackCompiler } from "webpack";
@@ -259,7 +259,7 @@ function assetAsSource(contents: string, filename: string): Source {
259259
let sm: RawSourceMap = sourcemap.toObject();
260260
contents = convertSourceMap.removeComments(contents);
261261
contents = convertSourceMap.removeMapFileComments(contents);
262-
return new SourceMapSource(contents, filename, sm);
262+
return new SourceMapSource(contents, filename, adaptToLegacySourceMap(sm));
263263
} else {
264264
return new RawSource(contents);
265265
}
@@ -315,7 +315,8 @@ function assetFileAsSource(sourcePath: string, callback: (err: Error | undefined
315315
function sourceAndMap(asset: Source): SourceAndMap {
316316
// sourceAndMap is supposedly more efficient when implemented.
317317
if (asset.sourceAndMap) {
318-
return asset.sourceAndMap();
318+
let {source, map} = asset.sourceAndMap();
319+
return {source, map: adaptFromLegacySourceMap(map)};
319320
} else {
320321
let source = asset.source();
321322
let map: RawSourceMap | undefined = undefined;
@@ -349,7 +350,7 @@ function makePostcssProcessor (
349350
});
350351

351352
return result.then((result) => {
352-
return new SourceMapSource(result.css, assetPath, result.map.toJSON(), source, map);
353+
return new SourceMapSource(result.css, assetPath, result.map.toJSON(), source, map && adaptToLegacySourceMap(map));
353354
});
354355
});
355356
};

‎packages/@css-blocks/webpack/src/Plugin.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TemplateTypes } from "@opticss/template-api";
22
import { ObjectDictionary, flatten, objectValues } from "@opticss/util";
33
import * as debugGenerator from "debug";
4-
import { postcss } from "opticss";
4+
import { LegacyRawSourceMap, adaptToLegacySourceMap, postcss } from "opticss";
55
import * as path from "path";
66
import { RawSourceMap } from "source-map";
77
import * as Tapable from "tapable";
@@ -138,7 +138,7 @@ export class CssBlocksPlugin
138138
let source: Source;
139139
if (result.optimizationResult.output.sourceMap) {
140140
let resultMap = result.optimizationResult.output.sourceMap;
141-
let rawSourceMap: RawSourceMap;
141+
let rawSourceMap: LegacyRawSourceMap | RawSourceMap;
142142
if (typeof resultMap === "string") {
143143
rawSourceMap = JSON.parse(resultMap);
144144
} else {
@@ -147,7 +147,7 @@ export class CssBlocksPlugin
147147
source = new SourceMapSource(
148148
result.optimizationResult.output.content.toString(),
149149
"optimized css",
150-
rawSourceMap);
150+
adaptToLegacySourceMap(rawSourceMap));
151151
} else {
152152
source = new RawSource(result.optimizationResult.output.content.toString());
153153
}

0 commit comments

Comments
 (0)