@@ -10,7 +10,7 @@ const helperModuleImports = require('@babel/helper-module-imports');
10
10
11
11
module . exports = function replaceConsoleCalls ( babel ) {
12
12
let consoleErrors = new WeakMap ( ) ;
13
- function getConsoleError ( path , file , opts ) {
13
+ function getConsoleError ( path , file ) {
14
14
if ( ! consoleErrors . has ( file ) ) {
15
15
consoleErrors . set (
16
16
file ,
@@ -26,7 +26,7 @@ module.exports = function replaceConsoleCalls(babel) {
26
26
}
27
27
28
28
let consoleWarns = new WeakMap ( ) ;
29
- function getConsoleWarn ( path , file , opts ) {
29
+ function getConsoleWarn ( path , file ) {
30
30
if ( ! consoleWarns . has ( file ) ) {
31
31
consoleWarns . set (
32
32
file ,
@@ -53,11 +53,27 @@ module.exports = function replaceConsoleCalls(babel) {
53
53
return ;
54
54
}
55
55
if ( path . get ( 'callee' ) . matchesPattern ( 'console.error' ) ) {
56
- const id = getConsoleError ( path , pass . file , this . opts ) ;
56
+ if ( this . opts . shouldError ) {
57
+ throw path . buildCodeFrameError (
58
+ "This module has no access to the React object, so it can't " +
59
+ 'use console.error() with automatically appended stack. ' +
60
+ "As a workaround, you can use console['error'] which won't " +
61
+ 'be transformed.'
62
+ ) ;
63
+ }
64
+ const id = getConsoleError ( path , pass . file ) ;
57
65
path . node . callee = id ;
58
66
}
59
67
if ( path . get ( 'callee' ) . matchesPattern ( 'console.warn' ) ) {
60
- const id = getConsoleWarn ( path , pass . file , this . opts ) ;
68
+ if ( this . opts . shouldError ) {
69
+ throw path . buildCodeFrameError (
70
+ "This module has no access to the React object, so it can't " +
71
+ 'use console.warn() with automatically appended stack. ' +
72
+ "As a workaround, you can use console['warn'] which won't " +
73
+ 'be transformed.'
74
+ ) ;
75
+ }
76
+ const id = getConsoleWarn ( path , pass . file ) ;
61
77
path . node . callee = id ;
62
78
}
63
79
} ,
0 commit comments