Comparing version 0.10.0 to 0.10.1
# buble changelog | ||
## 0.10.1 | ||
* Fix handling of literals inside JSX | ||
## 0.10.0 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "buble", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"description": "The blazing fast, batteries-included ES2015 compiler", | ||
@@ -5,0 +5,0 @@ "main": "dist/buble.umd.js", |
import Node from '../Node.js'; | ||
function normalise ( str, removeTrailingWhitespace ) { | ||
str = str | ||
.replace( /^\s+/gm, '' ) // remove leading whitespace | ||
.replace( /\s+\n\r?/gm, ' ' ); // replace newlines with spaces | ||
if ( removeTrailingWhitespace ) { | ||
str = str.replace( /\s+$/, '' ); | ||
} | ||
// TODO prefer single quotes? | ||
return JSON.stringify( str ); | ||
} | ||
export default class JSXElement extends Node { | ||
transpile ( code, transforms ) { | ||
code.insertLeft( this.end, `)` ); | ||
super.transpile( code, transforms ); | ||
@@ -14,10 +25,22 @@ | ||
if ( children.length ) { | ||
code.insertLeft( this.openingElement.end, ',' ); | ||
let c = this.openingElement.end; | ||
for ( let i = 0; i < children.length - 1; i += 1 ) { | ||
let i; | ||
for ( i = 0; i < children.length; i += 1 ) { | ||
const child = children[i]; | ||
code.insertLeft( child.end, ',' ); | ||
const tail = code.original[ c ] === '\n' && child.type !== 'Literal' ? '' : ' '; | ||
code.insertLeft( c, `,${tail}` ); | ||
if ( child.type === 'Literal' ) { | ||
const str = normalise( child.value, i === children.length - 1 ); | ||
code.overwrite( child.start, child.end, str ); | ||
} | ||
c = child.end; | ||
} | ||
} | ||
code.insertLeft( this.end, this.children.length && code.original[ this.end ] !== '\n' ? ` )` : `)` ); | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1431413
13171