Skip to content

Commit b3a0f14

Browse files
Andaristemmatown
authored andcommittedOct 26, 2019
Fix babel plugin crashing when called programmatically without providing a filename (#1574)
1 parent 3927293 commit b3a0f14

File tree

7 files changed

+17
-7
lines changed

7 files changed

+17
-7
lines changed
 

‎.changeset/slimy-dancers-wonder.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'babel-plugin-emotion': patch
3+
---
4+
5+
Fix babel plugin crashing when called programmatically without providing a filename

‎packages/babel-plugin-emotion/__tests__/__snapshots__/styled-requires-options.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exports[`styled inline babel 7 hash generation no file system 1`] = `
1515
"import _styled from \\"@emotion/styled-base\\";
1616
1717
_styled(\\"h1\\", {
18-
target: \\"e1i8mfxi0\\"
18+
target: \\"e1vqloan0\\"
1919
})({
2020
name: \\"14ksm7b\\",
2121
styles: \\"color:blue;\\"

‎packages/babel-plugin-emotion/__tests__/styled-requires-options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createInlineTests } from 'old-babel-tester'
44
const cases = {
55
'hash generation no file system': {
66
code: 'import styled from "@emotion/styled";\nstyled.h1`color:blue;`',
7-
filename: ''
7+
filename: undefined
88
}
99
}
1010

‎packages/babel-plugin-emotion/src/utils/get-target-class-name.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export function getTargetClassName(state: *, t: *) {
2020
state.emotionTargetClassNameCount = 0
2121
}
2222

23-
const filename = state.file.opts.filename
23+
const hasFilepath =
24+
state.file.opts.filename && state.file.opts.filename !== 'unknown'
25+
const filename = hasFilepath ? state.file.opts.filename : ''
2426
// normalize the file path to ignore folder structure
2527
// outside the current node project and arch-specific delimiters
2628
let moduleName = ''

‎packages/babel-plugin-emotion/src/utils/source-maps.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export function getSourceMap(
2727
): string {
2828
const generator = makeSourceMapGenerator(state.file)
2929
const generatorOpts = getGeneratorOpts(state.file)
30-
if (generatorOpts.sourceFileName) {
30+
if (
31+
generatorOpts.sourceFileName &&
32+
generatorOpts.sourceFileName !== 'unknown'
33+
) {
3134
generator.addMapping({
3235
generated: {
3336
line: 1,

‎scripts/old-babel-tester/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const createInlineTester = babel => opts => {
3838
}
3939
]
4040
],
41-
filename: opts.filename !== undefined ? opts.filename : 'emotion.js',
41+
filename: 'filename' in opts ? opts.filename : 'emotion.js',
4242
babelrc: false,
4343
ast: true,
4444
...(isBabel7(babel)

‎yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -8758,7 +8758,7 @@ expand-template@^2.0.3:
87588758
resolved "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz#6e14b3fcee0f3a6340ecb57d2e8918692052a47c"
87598759
integrity sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==
87608760

8761-
expand-tilde@^2.0.0:
8761+
expand-tilde@^2.0.0, expand-tilde@^2.0.2:
87628762
version "2.0.2"
87638763
resolved "https://registry.npmjs.org/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502"
87648764
integrity sha1-l+gBqgUt8CRU3kawK/YhZCzchQI=
@@ -23952,7 +23952,7 @@ which-pm-runs@^1.0.0:
2395223952
resolved "https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.0.0.tgz#670b3afbc552e0b55df6b7780ca74615f23ad1cb"
2395323953
integrity sha1-Zws6+8VS4LVd9rd4DKdGFfI60cs=
2395423954

23955-
which@1, which@^1.2.10, which@^1.2.12, which@^1.2.9, which@^1.3.0, which@^1.3.1:
23955+
which@1, which@^1.2.10, which@^1.2.12, which@^1.2.14, which@^1.2.9, which@^1.3.0, which@^1.3.1:
2395623956
version "1.3.1"
2395723957
resolved "https://registry.npmjs.org/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
2395823958
integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==

0 commit comments

Comments
 (0)
Please sign in to comment.