Skip to content

Commit

Permalink
Fix inputSourceMap Babel error (#466)
Browse files Browse the repository at this point in the history
* Replace null inputSourceMap with undefined

* Change files

* Update change message

* fix extraction loader, too

* Change files

---------

Co-authored-by: Alina Zaieva <[email protected]>
Co-authored-by: Oleksandr Fediashov <[email protected]>
  • Loading branch information
3 people authored Nov 13, 2023
1 parent 8066a39 commit dbbdcb6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: replace null inputSourceMap with undefined",
"packageName": "@griffel/webpack-extraction-plugin",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: replace null inputSourceMap with undefined",
"packageName": "@griffel/webpack-loader",
"email": "[email protected]",
"dependentChangeType": "patch"
}
6 changes: 5 additions & 1 deletion packages/webpack-extraction-plugin/src/webpackLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const virtualLoaderPath = path.resolve(__dirname, '..', 'virtual-loader', 'index
const virtualCSSFilePath = path.resolve(__dirname, '..', 'virtual-loader', 'griffel.css');

/**
* Webpack can also pass sourcemaps as a string, Babel accepts only objects.
* Webpack can also pass sourcemaps as a string or null, Babel accepts only objects, boolean and undefined.
* See https://github.com/babel/babel-loader/pull/889.
*/
function parseSourceMap(inputSourceMap: WebpackLoaderParams[1]): TransformOptions['inputSourceMap'] {
Expand All @@ -27,6 +27,10 @@ function parseSourceMap(inputSourceMap: WebpackLoaderParams[1]): TransformOption
return JSON.parse(inputSourceMap) as TransformOptions['inputSourceMap'];
}

if (inputSourceMap === null) {
return undefined;
}

return inputSourceMap as TransformOptions['inputSourceMap'];
} catch (err) {
return undefined;
Expand Down
6 changes: 5 additions & 1 deletion packages/webpack-loader/src/webpackLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function shouldTransformSourceCode(
}

/**
* Webpack can also pass sourcemaps as a string, Babel accepts only objects.
* Webpack can also pass sourcemaps as a string or null, Babel accepts only objects, boolean and undefined.
* See https://github.com/babel/babel-loader/pull/889.
*/
function parseSourceMap(inputSourceMap: WebpackLoaderParams[1]): TransformOptions['inputSourceMap'] {
Expand All @@ -38,6 +38,10 @@ function parseSourceMap(inputSourceMap: WebpackLoaderParams[1]): TransformOption
return JSON.parse(inputSourceMap) as TransformOptions['inputSourceMap'];
}

if (inputSourceMap === null) {
return undefined;
}

return inputSourceMap as TransformOptions['inputSourceMap'];
} catch (err) {
return undefined;
Expand Down

0 comments on commit dbbdcb6

Please sign in to comment.