@@ -2076,6 +2076,69 @@ describe("SourceCode", () => {
20762076 } ) ;
20772077 } ) ;
20782078 } ) ;
2079+
2080+ it ( "JSXText tokens that contain only whitespaces should NOT be handled as space" , ( ) => {
2081+ const code = "let jsx = <div>\n {content}\n</div>" ;
2082+ const ast = espree . parse ( code , { ...DEFAULT_CONFIG , ecmaFeatures : { jsx : true } } ) ;
2083+ const sourceCode = new SourceCode ( code , ast ) ;
2084+ const jsx = ast . body [ 0 ] . declarations [ 0 ] . init ;
2085+ const interpolation = jsx . children [ 1 ] ;
2086+
2087+ assert . strictEqual (
2088+ sourceCode . isSpaceBetween ( jsx . openingElement , interpolation ) ,
2089+ false
2090+ ) ;
2091+ assert . strictEqual (
2092+ sourceCode . isSpaceBetween ( interpolation , jsx . closingElement ) ,
2093+ false
2094+ ) ;
2095+
2096+ // Reversed order
2097+ assert . strictEqual (
2098+ sourceCode . isSpaceBetween ( interpolation , jsx . openingElement ) ,
2099+ false
2100+ ) ;
2101+ assert . strictEqual (
2102+ sourceCode . isSpaceBetween ( jsx . closingElement , interpolation ) ,
2103+ false
2104+ ) ;
2105+ } ) ;
2106+
2107+ it ( "JSXText tokens that contain both letters and whitespaces should NOT be handled as space" , ( ) => {
2108+ const code = "let jsx = <div>\n Hello\n</div>" ;
2109+ const ast = espree . parse ( code , { ...DEFAULT_CONFIG , ecmaFeatures : { jsx : true } } ) ;
2110+ const sourceCode = new SourceCode ( code , ast ) ;
2111+ const jsx = ast . body [ 0 ] . declarations [ 0 ] . init ;
2112+
2113+ assert . strictEqual (
2114+ sourceCode . isSpaceBetween ( jsx . openingElement , jsx . closingElement ) ,
2115+ false
2116+ ) ;
2117+
2118+ // Reversed order
2119+ assert . strictEqual (
2120+ sourceCode . isSpaceBetween ( jsx . closingElement , jsx . openingElement ) ,
2121+ false
2122+ ) ;
2123+ } ) ;
2124+
2125+ it ( "JSXText tokens that contain only letters should NOT be handled as space" , ( ) => {
2126+ const code = "let jsx = <div>Hello</div>" ;
2127+ const ast = espree . parse ( code , { ...DEFAULT_CONFIG , ecmaFeatures : { jsx : true } } ) ;
2128+ const sourceCode = new SourceCode ( code , ast ) ;
2129+ const jsx = ast . body [ 0 ] . declarations [ 0 ] . init ;
2130+
2131+ assert . strictEqual (
2132+ sourceCode . isSpaceBetween ( jsx . openingElement , jsx . closingElement ) ,
2133+ false
2134+ ) ;
2135+
2136+ // Reversed order
2137+ assert . strictEqual (
2138+ sourceCode . isSpaceBetween ( jsx . closingElement , jsx . openingElement ) ,
2139+ false
2140+ ) ;
2141+ } ) ;
20792142 } ) ;
20802143
20812144 describe ( "should return false either of the arguments' location is inside the other one" , ( ) => {
@@ -2409,6 +2472,69 @@ describe("SourceCode", () => {
24092472 } ) ;
24102473 } ) ;
24112474 } ) ;
2475+
2476+ it ( "JSXText tokens that contain only whitespaces should be handled as space" , ( ) => {
2477+ const code = "let jsx = <div>\n {content}\n</div>" ;
2478+ const ast = espree . parse ( code , { ...DEFAULT_CONFIG , ecmaFeatures : { jsx : true } } ) ;
2479+ const sourceCode = new SourceCode ( code , ast ) ;
2480+ const jsx = ast . body [ 0 ] . declarations [ 0 ] . init ;
2481+ const interpolation = jsx . children [ 1 ] ;
2482+
2483+ assert . strictEqual (
2484+ sourceCode . isSpaceBetweenTokens ( jsx . openingElement , interpolation ) ,
2485+ true
2486+ ) ;
2487+ assert . strictEqual (
2488+ sourceCode . isSpaceBetweenTokens ( interpolation , jsx . closingElement ) ,
2489+ true
2490+ ) ;
2491+
2492+ // Reversed order
2493+ assert . strictEqual (
2494+ sourceCode . isSpaceBetweenTokens ( interpolation , jsx . openingElement ) ,
2495+ true
2496+ ) ;
2497+ assert . strictEqual (
2498+ sourceCode . isSpaceBetweenTokens ( jsx . closingElement , interpolation ) ,
2499+ true
2500+ ) ;
2501+ } ) ;
2502+
2503+ it ( "JSXText tokens that contain both letters and whitespaces should be handled as space" , ( ) => {
2504+ const code = "let jsx = <div>\n Hello\n</div>" ;
2505+ const ast = espree . parse ( code , { ...DEFAULT_CONFIG , ecmaFeatures : { jsx : true } } ) ;
2506+ const sourceCode = new SourceCode ( code , ast ) ;
2507+ const jsx = ast . body [ 0 ] . declarations [ 0 ] . init ;
2508+
2509+ assert . strictEqual (
2510+ sourceCode . isSpaceBetweenTokens ( jsx . openingElement , jsx . closingElement ) ,
2511+ true
2512+ ) ;
2513+
2514+ // Reversed order
2515+ assert . strictEqual (
2516+ sourceCode . isSpaceBetweenTokens ( jsx . closingElement , jsx . openingElement ) ,
2517+ true
2518+ ) ;
2519+ } ) ;
2520+
2521+ it ( "JSXText tokens that contain only letters should NOT be handled as space" , ( ) => {
2522+ const code = "let jsx = <div>Hello</div>" ;
2523+ const ast = espree . parse ( code , { ...DEFAULT_CONFIG , ecmaFeatures : { jsx : true } } ) ;
2524+ const sourceCode = new SourceCode ( code , ast ) ;
2525+ const jsx = ast . body [ 0 ] . declarations [ 0 ] . init ;
2526+
2527+ assert . strictEqual (
2528+ sourceCode . isSpaceBetweenTokens ( jsx . openingElement , jsx . closingElement ) ,
2529+ false
2530+ ) ;
2531+
2532+ // Reversed order
2533+ assert . strictEqual (
2534+ sourceCode . isSpaceBetweenTokens ( jsx . closingElement , jsx . openingElement ) ,
2535+ false
2536+ ) ;
2537+ } ) ;
24122538 } ) ;
24132539
24142540 describe ( "should return false either of the arguments' location is inside the other one" , ( ) => {
0 commit comments