Comparing version 0.8.2 to 0.8.3
var fs = require( 'fs' ); | ||
var path = require( 'path' ); | ||
var buble = require( '../' ); | ||
var buble = require( '../dist/buble.deps.js' ); | ||
var handleError = require( './handleError.js' ); | ||
@@ -5,0 +5,0 @@ var EOL = require('os').EOL; |
# buble changelog | ||
## 0.8.3 | ||
* Performance enhancements ([!23](https://gitlab.com/Rich-Harris/buble/merge_requests/23)) | ||
## 0.8.2 | ||
* More robust version of ([!22](https://gitlab.com/Rich-Harris/buble/merge_requests/22)) | ||
* More robust version of ([!22](https://gitlab.com/Rich-Harris/buble/merge_requests/22)) | ||
@@ -7,0 +11,0 @@ ## 0.8.1 |
{ | ||
"name": "buble", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"description": "The blazing fast, batteries-included ES2015 compiler", | ||
@@ -20,4 +20,4 @@ "main": "dist/buble.umd.js", | ||
"test": "mocha test/test.js --compilers js:buble/register", | ||
"pretest": "npm run build:umd", | ||
"prepublish": "npm test && npm run build:es && npm run build:browser" | ||
"pretest": "npm run build:umd && npm run build:browser", | ||
"prepublish": "npm test && npm run build:es" | ||
}, | ||
@@ -48,16 +48,16 @@ "bin": { | ||
"devDependencies": { | ||
"buble": "0.5.6", | ||
"eslint": "^2.6.0", | ||
"buble": "0.8.2", | ||
"eslint": "^2.10.1", | ||
"glob": "^7.0.3", | ||
"mocha": "^2.4.5", | ||
"rimraf": "^2.5.2", | ||
"rollup": "^0.25.8", | ||
"rollup-plugin-buble": "^0.5.0", | ||
"rollup": "^0.26.3", | ||
"rollup-plugin-buble": "^0.8.0", | ||
"rollup-plugin-json": "^2.0.0", | ||
"rollup-plugin-node-resolve": "^1.5.0", | ||
"source-map": "^0.5.3", | ||
"source-map": "^0.5.6", | ||
"source-map-support": "^0.4.0" | ||
}, | ||
"dependencies": { | ||
"acorn": "^3.0.4", | ||
"acorn": "^3.1.0", | ||
"chalk": "^1.1.3", | ||
@@ -64,0 +64,0 @@ "magic-string": "^0.13.1", |
import wrap from './wrap.js'; | ||
import keys from './keys.js'; | ||
const statementsWithBlocks = { | ||
IfStatement: 'consequent', | ||
ForStatement: 'body', | ||
ForInStatement: 'body', | ||
ForOfStatement: 'body', | ||
WhileStatement: 'body', | ||
DoWhileStatement: 'body', | ||
ArrowFunctionExpression: 'body' | ||
}; | ||
export default class Node { | ||
constructor ( raw, parent ) { | ||
Object.defineProperties( this, { | ||
parent: { value: parent }, | ||
program: { value: parent.program || parent }, | ||
depth: { value: parent.depth + 1 }, | ||
keys: { value: Object.keys( raw ) } | ||
}); | ||
raw.parent = parent; | ||
raw.program = parent.program || parent; | ||
raw.depth = parent.depth + 1; | ||
raw.keys = keys[ raw.type ]; | ||
raw.indentation = undefined; | ||
// special case – body-less if/for/while statements. TODO others? | ||
const type = statementsWithBlocks[ raw.type ]; | ||
if ( type && raw[ type ].type !== 'BlockStatement' ) { | ||
const nonBlock = raw[ type ]; | ||
// create a synthetic block statement, otherwise all hell | ||
// breaks loose when it comes to block scoping | ||
raw[ type ] = { | ||
start: nonBlock.start, | ||
end: nonBlock.end, | ||
type: 'BlockStatement', | ||
body: [ nonBlock ], | ||
synthetic: true | ||
}; | ||
for ( const key of keys[ raw.type ] ) { | ||
wrap( raw[ key ], raw ); | ||
} | ||
for ( const key of this.keys ) { | ||
this[ key ] = wrap( raw[ key ], this ); | ||
} | ||
this.program.magicString.addSourcemapLocation( this.start ); | ||
this.program.magicString.addSourcemapLocation( this.end ); | ||
raw.program.magicString.addSourcemapLocation( raw.start ); | ||
raw.program.magicString.addSourcemapLocation( raw.end ); | ||
} | ||
@@ -80,4 +54,20 @@ | ||
getIndentation () { | ||
const lastLine = /\n(.+)$/.exec( this.program.magicString.original.slice( 0, this.start ) ); | ||
return lastLine ? /^[ \t]*/.exec( lastLine[1] )[0] : ''; | ||
if ( this.indentation === undefined ) { | ||
const source = this.program.magicString.original; | ||
let c = this.start; | ||
while ( c && source[c] !== '\n' ) c -= 1; | ||
this.indentation = ''; | ||
while ( true ) { | ||
c += 1; | ||
const char = source[c]; | ||
if ( char !== ' ' && char !== '\t' ) break; | ||
this.indentation += char; | ||
} | ||
} | ||
return this.indentation; | ||
} | ||
@@ -84,0 +74,0 @@ |
import MagicString from 'magic-string'; | ||
import BlockStatement from './BlockStatement.js'; | ||
import wrap from './wrap.js'; | ||
@@ -13,3 +14,4 @@ export default function Program ( source, ast, transforms ) { | ||
this.body = new BlockStatement( ast, this ); | ||
wrap( this.body = ast, this ); | ||
this.body.__proto__ = BlockStatement.prototype; | ||
@@ -16,0 +18,0 @@ this.templateElements = []; |
import types from './types/index.js'; | ||
import BlockStatement from './BlockStatement.js'; | ||
import Node from './Node.js'; | ||
import keys from './keys.js'; | ||
const statementsWithBlocks = { | ||
IfStatement: 'consequent', | ||
ForStatement: 'body', | ||
ForInStatement: 'body', | ||
ForOfStatement: 'body', | ||
WhileStatement: 'body', | ||
DoWhileStatement: 'body', | ||
ArrowFunctionExpression: 'body' | ||
}; | ||
export default function wrap ( raw, parent ) { | ||
if ( Array.isArray( raw ) ) { | ||
return raw.map( value => wrap( value, parent ) ); | ||
if ( !raw ) return; | ||
if ( 'length' in raw ) { | ||
let i = raw.length; | ||
while ( i-- ) wrap( raw[i], parent ); | ||
return; | ||
} | ||
if ( raw && typeof raw === 'object' ) { | ||
if ( raw.type === 'BlockStatement' ) return new BlockStatement( raw, parent ); | ||
// with e.g. shorthand properties, key and value are | ||
// the same node. We don't want to wrap an object twice | ||
if ( raw.__wrapped ) return; | ||
raw.__wrapped = true; | ||
const Constructor = types[ raw.type ] || Node; | ||
return new Constructor( raw, parent ); | ||
if ( !keys[ raw.type ] ) { | ||
keys[ raw.type ] = Object.keys( raw ).filter( key => typeof raw[ key ] === 'object' ); | ||
} | ||
return raw; // scalar value | ||
// special case – body-less if/for/while statements. TODO others? | ||
const bodyType = statementsWithBlocks[ raw.type ]; | ||
if ( bodyType && raw[ bodyType ].type !== 'BlockStatement' ) { | ||
const expression = raw[ bodyType ]; | ||
// create a synthetic block statement, otherwise all hell | ||
// breaks loose when it comes to block scoping | ||
raw[ bodyType ] = { | ||
start: expression.start, | ||
end: expression.end, | ||
type: 'BlockStatement', | ||
body: [ expression ], | ||
synthetic: true | ||
}; | ||
} | ||
Node( raw, parent ); | ||
const type = ( raw.type === 'BlockStatement' ? BlockStatement : types[ raw.type ] ) || Node; | ||
raw.__proto__ = type.prototype; | ||
} |
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
1245832
66
11405
Updatedacorn@^3.1.0