File tree Expand file tree Collapse file tree 4 files changed +48
-7
lines changed
Expand file tree Collapse file tree 4 files changed +48
-7
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,12 @@ export default function initialize() {
2525 configurations &&
2626 configurations . package &&
2727 configurations . package . parsed &&
28- configurations . package . parsed . dependencies
28+ configurations . package . parsed . dependencies ,
29+
30+ configurations &&
31+ configurations . package &&
32+ configurations . package . parsed &&
33+ configurations . package . parsed . devDependencies
2934 ) &&
3035 ! v2Initialized
3136 ) {
Original file line number Diff line number Diff line change 11import isESModule from '../../utils/is-es-module' ;
22
3- const JSXSyntax = / < \w ( .| \n ) * \/ ? > / ;
3+ const JSXSyntax = / ( . * ) < \w ( .| \n ) * ? \/ ? > / ;
44
55export function shouldTranspile ( code : string , path : string ) {
6- return isESModule ( code ) || JSXSyntax . test ( code ) ;
6+ if ( isESModule ( code ) ) {
7+ return true ;
8+ }
9+
10+ const match = code . match ( JSXSyntax ) ;
11+ if ( match ) {
12+ const startOfLine = match [ 1 ] ;
13+
14+ // If it's in a comment or string, we're extremely aggressive here because
15+ // transpiling is absolutely our last resort.
16+ if (
17+ startOfLine . indexOf ( '//' ) > - 1 ||
18+ startOfLine . indexOf ( '*' ) > - 1 ||
19+ startOfLine . indexOf ( "'" ) > - 1 ||
20+ startOfLine . indexOf ( '"' ) > - 1 ||
21+ startOfLine . indexOf ( '`' ) > - 1
22+ ) {
23+ return false ;
24+ }
25+
26+ return true ;
27+ }
28+ return false ;
729}
Original file line number Diff line number Diff line change 1+ import { shouldTranspile } from './check' ;
2+
3+ describe ( 'shouldTranspile' , ( ) => {
4+ it ( 'does have to transpile clear jsx' , ( ) => {
5+ const code = '<div></div>' ;
6+
7+ expect ( shouldTranspile ( code , '' ) ) . toBe ( true ) ;
8+ } ) ;
9+
10+ it ( "doesn't have to transpile comments with jsx" , ( ) => {
11+ const code = ' // Setting .type throws on non-<input> tags' ;
12+
13+ expect ( shouldTranspile ( code , '' ) ) . toBe ( false ) ;
14+ } ) ;
15+ } ) ;
Original file line number Diff line number Diff line change 11import semver from 'semver' ;
22
33function isCRAVersion2 ( dependencies , devDependencies ) {
4- const usedDeps = { ...dependencies , ...devDependencies } ;
5- if ( usedDeps [ 'react-scripts' ] ) {
6- const reactScriptsVersion = usedDeps [ 'react-scripts' ] ;
7-
4+ const reactScriptsVersion =
5+ dependencies [ 'react-scripts' ] || devDependencies [ 'react-scripts' ] ;
6+ if ( reactScriptsVersion ) {
87 return (
98 / ^ [ a - z ] / . test ( reactScriptsVersion ) ||
109 semver . intersects ( reactScriptsVersion , '^2.0.0' )
You can’t perform that action at this time.
0 commit comments