Comparing version 0.5.5 to 0.5.6
# buble changelog | ||
## 0.5.6 | ||
* Add `dangerousTaggedTemplateString` ([!2](https://gitlab.com/Rich-Harris/buble/merge_requests/2)) and `dangerousForOf` ([!3](https://gitlab.com/Rich-Harris/buble/merge_requests/3)) transforms | ||
* Prevent deindentation causing errors with removed whitespace in class methods | ||
* Use correct identifier with default destructured function parameters ([#23](https://gitlab.com/Rich-Harris/buble/issues/23)) | ||
## 0.5.5 | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "buble", | ||
"version": "0.5.5", | ||
"version": "0.5.6", | ||
"description": "The blazing fast, batteries-included ES2015 compiler", | ||
@@ -5,0 +5,0 @@ "main": "dist/buble.umd.js", |
@@ -6,2 +6,7 @@ import { parse } from 'acorn'; | ||
const dangerousTransforms = [ | ||
'dangerousTaggedTemplateString', | ||
'dangerousForOf' | ||
]; | ||
export function target ( target ) { | ||
@@ -29,2 +34,6 @@ const targets = Object.keys( target ); | ||
dangerousTransforms.forEach( name => { | ||
transforms[ name ] = false; | ||
}); | ||
return transforms; | ||
@@ -31,0 +40,0 @@ } |
@@ -131,5 +131,5 @@ import wrap from './wrap.js'; | ||
code | ||
.insert( start, `var ${ref}_${key} = ref.${key}, ${value} = ref_${key} === void 0 ? ` ) | ||
.insert( start, `var ${ref}_${key} = ${ref}.${key}, ${value} = ${ref}_${key} === void 0 ? ` ) | ||
.move( prop.value.right.start, prop.value.right.end, start ) | ||
.insert( start, ` : ref_${key};` ); | ||
.insert( start, ` : ${ref}_${key};` ); | ||
} | ||
@@ -136,0 +136,0 @@ |
@@ -7,2 +7,3 @@ import wrap from './wrap.js'; | ||
ForInStatement: 'body', | ||
ForOfStatement: 'body', | ||
WhileStatement: 'body', | ||
@@ -9,0 +10,0 @@ ArrowFunctionExpression: 'body' |
@@ -1,8 +0,46 @@ | ||
import Node from '../Node.js'; | ||
import LoopStatement from './shared/LoopStatement.js'; | ||
import CompileError from '../../utils/CompileError.js'; | ||
export default class ForOfStatement extends Node { | ||
export default class ForOfStatement extends LoopStatement { | ||
initialise ( transforms ) { | ||
if ( transforms.forOf ) throw new CompileError( this, 'for...of statements are not supported' ); | ||
if ( transforms.forOf && !transforms.dangerousForOf ) throw new CompileError( this, 'for...of statements are not supported' ); | ||
super.initialise( transforms ); | ||
} | ||
transpile ( code, transforms ) { | ||
if ( !transforms.dangerousForOf ) { | ||
super.transpile( code, transforms ); | ||
return; | ||
} | ||
const scope = this.findScope( true ); | ||
const i0 = this.getIndentation(); | ||
const i1 = i0 + code.getIndentString(); | ||
const key = scope.createIdentifier( 'i' ); | ||
const list = scope.createIdentifier( 'list' ); | ||
if ( this.body.synthetic ) { | ||
code.insert( this.body.body[0].start, `{\n${i1}` ); | ||
code.insert( this.body.body[0].end, `\n${i0}}` ); | ||
} | ||
// this is rather finicky, owing to magic-string's quirks | ||
const bodyStart = this.body.body[0].start; | ||
let startIndex = this.left.start; | ||
while ( code.original[ startIndex - 1 ] !== '(' ) startIndex -= 1; | ||
code.remove( this.left.end, this.right.start ); | ||
code.remove( startIndex, this.left.start ); | ||
code.remove( this.start + 3, startIndex ); | ||
code.insert( startIndex, ` ( var ${key} = 0, ${list} = ` ); | ||
code.move( this.left.start, this.left.end, bodyStart ); | ||
code.move( this.right.start, this.right.end, startIndex ); | ||
code.insert( startIndex, `; ${key} < ${list}.length; ${key} += 1` ); | ||
code.insert( bodyStart, ` = ${list}[${key}];\n\n${i1}` ); | ||
super.transpile( code, transforms ); | ||
} | ||
} |
@@ -6,4 +6,33 @@ import Node from '../Node.js'; | ||
initialise ( transforms ) { | ||
if ( transforms.templateString ) throw new CompileError( this.tag, 'Tagged template expressions are not supported' ); | ||
if ( transforms.templateString && !transforms.dangerousTaggedTemplateString ) { | ||
throw new CompileError( this, 'Tagged template strings are not supported' ); | ||
} | ||
super.initialise( transforms ); | ||
} | ||
transpile ( code, transforms ) { | ||
if ( transforms.templateString && transforms.dangerousTaggedTemplateString ) { | ||
const ordered = this.quasi.expressions.concat( this.quasi.quasis ).sort( ( a, b ) => a.start - b.start ); | ||
// insert strings at start | ||
const templateStrings = this.quasi.quasis.map( quasi => JSON.stringify( quasi.value.cooked ) ); | ||
code.overwrite( this.tag.end, ordered[0].start, `([${templateStrings.join(', ')}]` ); | ||
let lastIndex = ordered[0].start; | ||
ordered.forEach( node => { | ||
if ( node.type === 'TemplateElement' ) { | ||
code.remove( lastIndex, node.end ); | ||
} else { | ||
code.overwrite( lastIndex, node.start, ', ' ); | ||
} | ||
lastIndex = node.end; | ||
}); | ||
code.overwrite( lastIndex, this.end, ')' ); | ||
} | ||
super.transpile( code, transforms ); | ||
} | ||
} |
@@ -5,3 +5,3 @@ import Node from '../Node.js'; | ||
transpile ( code, transforms ) { | ||
if ( transforms.templateString ) { | ||
if ( transforms.templateString && this.parent.type !== 'TaggedTemplateExpression' ) { | ||
code.remove( this.start, this.start + 1 ); | ||
@@ -8,0 +8,0 @@ code.remove( this.end - 1, this.end ); |
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
1135937
10322